提交 c97e5046 编写于 作者: J Jan S 提交者: skylot

fix: additionally show smali code of inner classes (PR #824)

上级 02213802
package jadx.core.dex.nodes;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
......@@ -533,11 +534,24 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
public String getSmali() {
if (smali == null) {
smali = SmaliUtils.getSmaliCode(dex, clsDefOffset);
StringWriter stringWriter = new StringWriter(4096);
getSmali(this, stringWriter);
stringWriter.append(System.lineSeparator());
for (ClassNode innerClass : innerClasses) {
getSmali(innerClass, stringWriter);
stringWriter.append(System.lineSeparator());
}
smali = stringWriter.toString();
}
return smali;
}
protected static boolean getSmali(ClassNode classNode, StringWriter stringWriter) {
stringWriter.append(String.format("###### Class %s (%s)", classNode.getFullName(), classNode.getRawName()));
stringWriter.append(System.lineSeparator());
return SmaliUtils.getSmaliCode(classNode.dex, classNode.clsDefOffset, stringWriter);
}
public ProcessState getState() {
return state;
}
......
......@@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
import org.jetbrains.annotations.NotNull;
import org.jf.baksmali.Adaptors.ClassDefinition;
import org.jf.baksmali.BaksmaliOptions;
import org.jf.dexlib2.DexFileFactory;
......@@ -34,24 +33,25 @@ public class SmaliUtils {
}
}
@NotNull
public static String getSmaliCode(DexNode dex, int clsDefOffset) {
public static boolean getSmaliCode(DexNode dex, int clsDefOffset, StringWriter stringWriter) {
try {
Path path = dex.getDexFile().getPath();
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(path.toFile(), null);
DexBackedClassDef dexBackedClassDef = new DexBackedClassDef(dexFile, clsDefOffset);
return getSmaliCode(dexBackedClassDef);
getSmaliCode(dexBackedClassDef, stringWriter);
return true;
} catch (Exception e) {
LOG.error("Error generating smali", e);
return "Error generating smali code: " + e.getMessage()
+ '\n' + Utils.getStackTrace(e);
stringWriter.append("Error generating smali code: ");
stringWriter.append(e.getMessage());
stringWriter.append(System.lineSeparator());
stringWriter.append(Utils.getStackTrace(e));
return false;
}
}
private static String getSmaliCode(DexBackedClassDef classDef) throws IOException {
private static void getSmaliCode(DexBackedClassDef classDef, StringWriter stringWriter) throws IOException {
ClassDefinition classDefinition = new ClassDefinition(new BaksmaliOptions(), classDef);
StringWriter sw = new StringWriter();
classDefinition.writeTo(new IndentingWriter(sw));
return sw.toString();
classDefinition.writeTo(new IndentingWriter(stringWriter));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册