andriod 解包
使用 baksmali.jar 进行解包
命令 java -jar baksmail.jar -o classout/ classes.dex
public ArrayList<CheckSDK> check(String apkPath, String baksmaliPath, String cachDire) { ArrayList<CheckSDK> result = null; long currenTime = System.currentTimeMillis(); File cachDir = new File(cachDire, currenTime + ""); if (!cachDir.exists()) cachDir.mkdir();
//把文件拷贝到临时目录 List<File> listDex = moveDex(apkPath, cachDir); if (listDex == null) { return null; } for (int i = 0; i < listDex.size(); i++) { File dexFile = listDex.get(i); File newCachDir = new File(cachDir, System.currentTimeMillis()+ "_classout"); String cmdStr = String.format("java -jar %s -o %s %s",baksmaliPath, newCachDir.getAbsolutePath(), dexFile.getAbsolutePath()); String[] instructs = new String[] { cmdStr }; runTime(instructs); ArrayList<CheckSDK> checkResult = checkExits(newCachDir); if (checkResult != null) { if (result == null) result = new ArrayList<CheckSDK>(); for (int x = 0; x < checkResult.size(); x++) { result.add(checkResult.get(x)); } } } SDCatch(cachDir); return result; }
private List<File> moveDex(String apkPath, File cachDir) { List<File> listDexes = new ArrayList<File>(); try { ZipFile zipFile = new ZipFile(apkPath); Enumeration<?> en = zipFile.entries(); while (en.hasMoreElements()) { ZipEntry ze = (ZipEntry) en.nextElement(); if (ze.getName().endsWith(".dex")) { File dexFile = new File(cachDir, System.currentTimeMillis()+ "_class.dex"); if (!dexFile.exists()) dexFile.createNewFile(); BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream(dexFile)); BufferedInputStream input = new BufferedInputStream(zipFile.getInputStream(ze)); byte[] buffer = new byte[1024 * 1024]; int readLen = -1; while ((readLen = input.read(buffer)) != -1) { output.write(buffer, 0, readLen); } output.flush(); output.close(); input.close(); listDexes.add(dexFile); } } } catch (Exception e) { e.printStackTrace(); } return listDexes; }
用 smali.jar 打包
java -jar smali-1.4.1.jar classout/ -o classes.dex