use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DumpCommand method dump.
/**
* Writes an annotated hex dump of the given dex file to output.
*
* @param dexFile The dex file to dump
* @param output An OutputStream to write the annotated hex dump to. The caller is responsible for closing this
* when needed.
*
* @throws IOException
*/
public static void dump(@Nonnull DexBackedDexFile dexFile, @Nonnull OutputStream output) throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(output));
int consoleWidth = ConsoleUtil.getConsoleWidth();
if (consoleWidth <= 0) {
consoleWidth = 120;
}
RawDexFile rawDexFile = new RawDexFile(dexFile.getOpcodes(), dexFile);
DexAnnotator annotator = new DexAnnotator(rawDexFile, consoleWidth);
annotator.writeAnnotations(writer);
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class DisassemblyTest method runTest.
protected void runTest(@Nonnull String testName, @Nonnull BaksmaliOptions options) {
try {
DexBackedDexFile inputDex = getInputDexFile(testName, options);
Assert.assertEquals(1, inputDex.getClassCount());
ClassDef inputClass = Iterables.getFirst(inputDex.getClasses(), null);
Assert.assertNotNull(inputClass);
String input = BaksmaliTestUtils.getNormalizedSmali(inputClass, options, true);
String output = BaksmaliTestUtils.readResourceFully(getOutputFilename(testName));
output = BaksmaliTestUtils.normalizeSmali(output, true);
// Run smali, baksmali, and then compare strings are equal (minus comments/whitespace)
Assert.assertEquals(output, input);
} catch (IOException ex) {
Assert.fail();
}
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project smali by JesusFreke.
the class ListDexCommand method run.
@Override
public void run() {
if (help || inputList == null || inputList.isEmpty()) {
usage();
return;
}
if (inputList.size() > 1) {
System.err.println("Too many files specified");
usage();
return;
}
String input = inputList.get(0);
File file = new File(input);
if (!file.exists()) {
System.err.println(String.format("Could not find the file: %s", input));
System.exit(-1);
}
List<String> entries;
try {
MultiDexContainer<? extends DexBackedDexFile> container = DexFileFactory.loadDexContainer(file, Opcodes.getDefault());
entries = container.getDexEntryNames();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
for (String entry : entries) {
System.out.println(entry);
}
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.
the class DexParser method constructMethodRefTreeForDex.
@NotNull
static PackageTreeNode constructMethodRefTreeForDex(@NotNull DexBackedDexFile dexFile) {
PackageTreeNode root = new PackageTreeNode("", "root", PackageTreeNode.NodeType.PACKAGE, null);
Set<String> classesWithDefinition = dexFile.getClasses().stream().map(DexBackedClassDef::getType).collect(Collectors.toSet());
Multimap<String, MethodReference> methodsByClassName = getMethodsByClassName(dexFile);
for (String className : methodsByClassName.keySet()) {
Collection<MethodReference> methods = methodsByClassName.get(className);
for (MethodReference ref : methods) {
root.insert("", DebuggerUtilsEx.signatureToName(className), ref, classesWithDefinition.contains(className));
}
}
root.sortByCount();
return root;
}
use of org.jf.dexlib2.dexbacked.DexBackedDexFile in project android by JetBrains.
the class DexParser method getMethodsByClassName.
@NotNull
private static Multimap<String, MethodReference> getMethodsByClassName(@NotNull DexBackedDexFile dexFile) {
Multimap<String, MethodReference> methodsByClass = ArrayListMultimap.create();
for (int i = 0, m = dexFile.getMethodCount(); i < m; i++) {
MethodReference methodRef = new DexBackedMethodReference(dexFile, i);
methodsByClass.put(methodRef.getDefiningClass(), methodRef);
}
return methodsByClass;
}
Aggregations