mirror of
https://github.com/revanced/Apktool.git
synced 2024-11-11 06:59:24 +01:00
Readded smali debugging feature.
This commit is contained in:
parent
70deba0c5d
commit
59da5db05f
@ -193,7 +193,7 @@ public class DebugInjector {
|
||||
}
|
||||
|
||||
private String next() {
|
||||
return mIt.next().trim();
|
||||
return mIt.next().split("//", 2)[1].trim();
|
||||
}
|
||||
|
||||
private String nextAndAppend() {
|
||||
|
@ -76,17 +76,16 @@ public class SmaliBuilder {
|
||||
|
||||
if (!mFlags.containsKey("debug")) {
|
||||
final String[] linesArray = lines.toArray(new String[0]);
|
||||
for (int i = 2; i < linesArray.length - 2; i++) {
|
||||
out.append(linesArray[i]).append('\n');
|
||||
for (int i = 1; i < linesArray.length - 1; i++) {
|
||||
out.append(linesArray[i].split("//", 2)[1]).append('\n');
|
||||
}
|
||||
} else {
|
||||
lines.remove(lines.size() - 1);
|
||||
lines.remove(lines.size() - 1);
|
||||
ListIterator<String> it = lines.listIterator(2);
|
||||
ListIterator<String> it = lines.listIterator(1);
|
||||
|
||||
out.append(".source \"").append(inFile.getName()).append("\"\n");
|
||||
while (it.hasNext()) {
|
||||
String line = it.next().trim();
|
||||
String line = it.next().split("//", 2)[1].trim();
|
||||
if (line.isEmpty() || line.charAt(0) == '#'
|
||||
|| line.startsWith(".source")) {
|
||||
continue;
|
||||
|
@ -17,10 +17,20 @@
|
||||
package brut.androlib.src;
|
||||
|
||||
import brut.androlib.AndrolibException;
|
||||
import org.jf.baksmali.baksmali;
|
||||
import org.jf.dexlib.Code.Analysis.ClassPath;
|
||||
import org.jf.dexlib.DexFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.jf.baksmali.baksmali;
|
||||
import org.jf.dexlib.DexFile;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
/**
|
||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
@ -35,24 +45,62 @@ public class SmaliDecoder {
|
||||
private SmaliDecoder(File apkFile, File outDir, boolean debug,
|
||||
boolean bakdeb) {
|
||||
mApkFile = apkFile;
|
||||
mOutDir = outDir;
|
||||
mOutDir = outDir.toPath();
|
||||
mDebug = debug;
|
||||
mBakDeb = bakdeb;
|
||||
}
|
||||
|
||||
private void decode() throws AndrolibException {
|
||||
try {
|
||||
ClassPath.dontLoadClassPath = mDebug;
|
||||
baksmali.disassembleDexFile(mApkFile.getAbsolutePath(),
|
||||
new DexFile(mApkFile), false, mOutDir.getAbsolutePath(),
|
||||
new DexFile(mApkFile), false, mOutDir.toAbsolutePath().toString(),
|
||||
null, null, null, false, true, true, mBakDeb, false, false,
|
||||
0, false, false, null, false);
|
||||
mDebug ? org.jf.baksmali.main.DIFFPRE : 0, false, false, null, false);
|
||||
|
||||
if (mDebug) {
|
||||
Files.walkFileTree(mOutDir, new SmaliFileVisitor());
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private final File mApkFile;
|
||||
private final File mOutDir;
|
||||
private final Path mOutDir;
|
||||
private final boolean mDebug;
|
||||
private final boolean mBakDeb;
|
||||
|
||||
|
||||
private class SmaliFileVisitor extends SimpleFileVisitor<Path> {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
String fileName = file.getFileName().toString();
|
||||
if (! fileName.endsWith(".smali")) {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
fileName = fileName.substring(0, fileName.length() - 6);
|
||||
try (
|
||||
BufferedReader in = Files.newBufferedReader(file, Charset.defaultCharset());
|
||||
BufferedWriter out = Files.newBufferedWriter(
|
||||
file.resolveSibling(fileName + ".java"), Charset.defaultCharset())
|
||||
) {
|
||||
TypeName type = TypeName.fromPath(mOutDir.relativize(file.resolveSibling(fileName)));
|
||||
out.write("package " + type.package_ + "; class " + type.getName(true, true) + " {");
|
||||
out.newLine();
|
||||
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
out.write("// ");
|
||||
out.write(line);
|
||||
out.newLine();
|
||||
}
|
||||
|
||||
out.write("}");
|
||||
out.newLine();
|
||||
}
|
||||
Files.delete(file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user