use of jadx.api.plugins.input.data.ICodeReader in project jadx by skylot.
the class DexInputPluginTest method processFile.
private static void processFile(Path sample) throws IOException {
System.out.println("Input file: " + sample.toAbsolutePath());
long start = System.currentTimeMillis();
List<Path> files = Collections.singletonList(sample);
try (ILoadResult result = new DexInputPlugin().loadFiles(files)) {
AtomicInteger count = new AtomicInteger();
result.visitClasses(cls -> {
System.out.println();
System.out.println("Class: " + cls.getType());
System.out.println("AccessFlags: " + AccessFlags.format(cls.getAccessFlags(), AccessFlagsScope.CLASS));
System.out.println("SuperType: " + cls.getSuperType());
System.out.println("Interfaces: " + cls.getInterfacesTypes());
System.out.println("Attributes: " + cls.getAttributes());
count.getAndIncrement();
cls.visitFieldsAndMethods(System.out::println, mth -> {
System.out.println("---");
System.out.println(mth);
ICodeReader codeReader = mth.getCodeReader();
if (codeReader != null) {
codeReader.visitInstructions(insn -> {
insn.decode();
System.out.println(insn);
});
}
System.out.println("---");
System.out.println(mth.disassembleMethod());
System.out.println("---");
});
System.out.println("----");
System.out.println(cls.getDisassembledCode());
System.out.println("----");
});
assertThat(count.get()).isGreaterThan(0);
}
System.out.println("Time: " + (System.currentTimeMillis() - start) + "ms");
}
use of jadx.api.plugins.input.data.ICodeReader in project jadx by skylot.
the class Smali method writeMethod.
private void writeMethod(SmaliWriter smali, MethodNode methodNode, IMethodData mth, LineInfo line) {
if (insnDecoder == null) {
insnDecoder = new SmaliInsnDecoder(methodNode);
}
smali.startLine().startLine(".method ");
writeMethodDef(smali, mth, line);
ICodeReader codeReader = mth.getCodeReader();
if (codeReader != null) {
line.smaliMthNode.setParamRegStart(getParamStartRegNum(mth));
line.smaliMthNode.setRegCount(codeReader.getRegistersCount());
Map<Long, InsnNode> nodes = new HashMap<>(codeReader.getUnitsCount() / 2);
line.smaliMthNode.setInsnNodes(nodes, codeReader.getUnitsCount());
line.smaliMthNode.initRegInfoList(codeReader.getRegistersCount(), codeReader.getUnitsCount());
smali.incIndent();
smali.startLine(".registers ").add("" + codeReader.getRegistersCount()).startLine();
writeTries(codeReader, line);
if (formatMthParamInfo(mth, smali, codeReader, line)) {
smali.startLine();
}
smali.startLine();
if (codeReader.getDebugInfo() != null) {
formatDbgInfo(codeReader.getDebugInfo(), line);
}
codeReader.visitInstructions(insn -> {
InsnNode node = decodeInsn(insn, line);
nodes.put((long) insn.getOffset(), node);
});
line.write(smali);
insnMap.put(methodNode.getMethodInfo().getRawFullId(), line.smaliMthNode);
smali.decIndent();
}
smali.startLine(".end method");
}
use of jadx.api.plugins.input.data.ICodeReader in project jadx by skylot.
the class SmaliPrinter method printMethod.
public static String printMethod(DexMethodData mth) {
SmaliCodeWriter codeWriter = new SmaliCodeWriter();
codeWriter.startLine(".method ");
codeWriter.add(AccessFlags.format(mth.getAccessFlags(), METHOD));
DexMethodRef methodRef = mth.getMethodRef();
methodRef.load();
codeWriter.add(methodRef.getName());
codeWriter.add('(').addArgs(methodRef.getArgTypes()).add(')');
codeWriter.add(methodRef.getReturnType());
codeWriter.incIndent();
ICodeReader codeReader = mth.getCodeReader();
if (codeReader != null) {
codeWriter.startLine(".registers ").add(codeReader.getRegistersCount());
SmaliInsnFormat insnFormat = SmaliInsnFormat.getInstance();
InsnFormatterInfo formatterInfo = new InsnFormatterInfo(codeWriter, mth);
codeReader.visitInstructions(insn -> {
codeWriter.startLine();
formatterInfo.setInsn(insn);
insnFormat.format(formatterInfo);
});
codeWriter.decIndent();
}
codeWriter.startLine(".end method");
return codeWriter.getCode();
}
use of jadx.api.plugins.input.data.ICodeReader in project jadx by skylot.
the class UsageInfoVisitor method processInstructions.
private static void processInstructions(MethodNode mth, UsageInfo usageInfo) {
if (mth.isNoCode()) {
return;
}
ICodeReader codeReader = mth.getCodeReader();
if (codeReader == null) {
return;
}
RootNode root = mth.root();
codeReader.visitInstructions(insnData -> {
try {
processInsn(root, mth, insnData, usageInfo);
} catch (Exception e) {
mth.addError("Dependency scan failed at insn: " + insnData, e);
}
});
}
Aggregations