@Nonnull public static DexBackedDexFile fromInputStream(@Nullable Opcodes opcodes, @Nonnull InputStream is) throws IOException { DexUtil.verifyDexHeader(is); byte[] buf = ByteStreams.toByteArray(is); return new DexBackedDexFile(opcodes, buf, 0, false); }
public static Set<String> classesOfDex(DexBackedDexFile dexFile) { Set<String> classes = new HashSet<String>(); for (ClassDef c : dexFile.getClasses()) { String name = Util.dottedClassName(c.getType()); classes.add(name); } return classes; }
@Nonnull @Override public String readItem(final int index) { return dexFile.getType(dexFile.readUshort(paramListStart + 2*index)); } @Override public int size() { return parameterCount; }
private int getProtoIdItemOffset() { if (protoIdItemOffset == 0) { protoIdItemOffset = dexFile.getProtoIdItemOffset( dexFile.readUshort(methodIdItemOffset + MethodIdItem.PROTO_OFFSET)); } return protoIdItemOffset; }
@Nonnull public String getType(int typeIndex) { int typeOffset = getTypeIdItemOffset(typeIndex); int stringIndex = readSmallUint(typeOffset); return getString(stringIndex); }
@Nonnull @Override public String getName() { return dexFile.getString(dexFile.readSmallUint(methodIdItemOffset + MethodIdItem.NAME_OFFSET)); }
for (DexBackedClassDef def : dex.getClasses()) { String type = def.getType(); System.out.println(type); DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next(); DexBackedClassDef def2 = new DexBackedDexFile(new Opcodes(14, false), data).getClasses().iterator().next();
public static String asString(DexBackedDexFile dexFile, int fieldIndex) { int fieldOffset = dexFile.getFieldIdItemOffset(fieldIndex); int classIndex = dexFile.readUshort(fieldOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int typeIndex = dexFile.readUshort(fieldOffset + TYPE_OFFSET); String fieldType = dexFile.getType(typeIndex); int nameIndex = dexFile.readSmallUint(fieldOffset + NAME_OFFSET); String fieldName = dexFile.getString(nameIndex); return String.format("%s->%s:%s", classType, fieldName, fieldType); }
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int methodIndex) { int methodOffset = dexFile.getMethodIdItemOffset(methodIndex); int classIndex = dexFile.readUshort(methodOffset + CLASS_OFFSET); String classType = dexFile.getType(classIndex); int protoIndex = dexFile.readUshort(methodOffset + PROTO_OFFSET); String protoString = ProtoIdItem.asString(dexFile, protoIndex); int nameIndex = dexFile.readSmallUint(methodOffset + NAME_OFFSET); String methodName = dexFile.getString(nameIndex); return String.format("%s->%s%s", classType, methodName, protoString); }
options.syntheticAccessorResolver = new SyntheticAccessorResolver(dexFile.getOpcodes(), dexFile.getClasses());
public void initialize() { for (ClassDef defItem : dexFile.getClasses()) { String forClassName = Util.dottedClassName(defItem.getType()); classesToDefItems.put(forClassName, new ClassInformation(dexFile, defItem)); for (int i = 0; i < dexFile.getTypeCount(); i++) { String t = dexFile.getType(i);
if(dexFile.isOdexFile()) { System.err.println("Odex not supported!"); return; List<? extends ClassDef> classDefs = Ordering.natural().sortedCopy(dexFile.getClasses());
@Nonnull @Override public String getReturnType() { return dexFile.getType(dexFile.readSmallUint(protoIdItemOffset + ProtoIdItem.RETURN_TYPE_OFFSET)); }
private VdexRewriterModule(Vdex.QuickenDex odex, VdexRewriterModule module) { mOdex = odex; mDex = new DexBackedDexFile(module.mDex.getOpcodes(), odex.getBytes()); mGiIter = module.mGiIter; mQiIter = module.mQiIter; }
/** * 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)); try { 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); } finally { writer.close(); } } }
public AnnotationIteratorImpl(int startOffset, int size) { this.startOffset = startOffset; this.size = size; this.currentItemIndex = dexFile.readSmallUint(startOffset); this.currentIndex = 0; }
@Nonnull public String getString(int stringIndex) { int stringOffset = getStringIdItemOffset(stringIndex); int stringDataOffset = readSmallUint(stringOffset); DexReader reader = readerAt(stringDataOffset); int utf16Length = reader.readSmallUleb128(); return reader.readString(utf16Length); }
return new DexBackedDexFile(opcodes, dexBytes); } catch (IOException ex) { return DexBackedDexFile.fromInputStream(opcodes, inputStream); } catch (DexBackedDexFile.NotADexFile ex) {
@Override public int getStartRegister() { return dexFile.readUshort(instructionStart + 4); }
@Nonnull public static String asString(@Nonnull DexBackedDexFile dexFile, int classIndex) { int offset = dexFile.getClassDefItemOffset(classIndex); int typeIndex = dexFile.readSmallUint(offset + CLASS_OFFSET); return dexFile.getType(typeIndex); }