反编译apk文件,查找jar文件中字符串
Posted 陳英傑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了反编译apk文件,查找jar文件中字符串相关的知识,希望对你有一定的参考价值。
package com.lzxx.testdemo.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class FindStrInJar
public String condition; //查询的条件
public ArrayList<String> jarFiles = new ArrayList<String>();
public FindStrInJar()
public FindStrInJar(String condition)
this.condition = condition;
public FindStrInJar(String condition, String exclude)
this.condition = condition;
public void setCondition(String condition)
this.condition = condition;
public List<String> find(String dir, boolean recurse)
searchDir(dir, recurse);
return this.jarFiles;
public List<String> getFilenames()
return this.jarFiles;
protected String getClassName(ZipEntry entry)
StringBuffer className = new StringBuffer(entry.getName().replace("/", "."));
return className.toString();
protected void searchDir(String dir, boolean recurse)
try
File d = new File(dir);
if (!d.isDirectory())
return;
File[] files = d.listFiles();
for (int i = 0; i < files.length; i++)
if (recurse && files[i].isDirectory())
searchDir(files[i].getAbsolutePath(), true);
else
String filename = files[i].getAbsolutePath();
if (filename.endsWith(".jar") || filename.endsWith(".zip"))
ZipFile zip = new ZipFile(filename);
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements())
ZipEntry entry = entries.nextElement();
String thisClassName = getClassName(entry);
//按照文件内容搜索文件。搜索扩展名为.class的文件
if (thisClassName.lastIndexOf(".class") != -1)
BufferedReader r = new BufferedReader(new InputStreamReader(zip.getInputStream(entry)));
while (r.read() != -1)
String tempStr = r.readLine();
if (null != tempStr && tempStr.indexOf(condition) > -1)
this.jarFiles.add(filename + " ---> " + thisClassName);
break;
//按照文件名搜索文件
// if (thisClassName.contains(condition))
// this.jarFiles.add(filename + " ---> " + thisClassName);
//
//获取扩展名为properties的文件
// if(thisClassName.lastIndexOf("properties")>-1)
// this.jarFiles.add(filename + " ---> " + thisClassName);
//
zip.close();
catch (Exception e)
e.printStackTrace();
public static void main(String args[])
FindStrInJar findInJar = new FindStrInJar("example"); //要寻找的字符串
// windows
// List<String> jarFiles = findInJar.find("E:/workspace/AccountServiceCenter/lib", true);
// mac
List<String> jarFiles = findInJar.find("/Users/xxx/jar文件所在文件夹路径", true);
if (jarFiles.size() == 0)
System.out.println("Not Found");
else
for (int i = 0; i < jarFiles.size(); i++)
System.out.println(jarFiles.get(i));
以上是关于反编译apk文件,查找jar文件中字符串的主要内容,如果未能解决你的问题,请参考以下文章