/** * Writes a DexFile out to disk * * @param path The path to write the dex file to * @param dexFile a DexFile to write */ public static void writeDexFile(@Nonnull String path, @Nonnull DexFile dexFile) throws IOException { DexPool.writeTo(path, dexFile); }
/** * Writes all built dex files to the given folder. * * @param folder * the output folder * @return File handles to all written dex files * @throws IOException * when failed to create {@link FileDataStore} */ public List<File> writeTo(String folder) throws IOException { final List<File> result = new ArrayList<>(dexPools.size()); for (DexPool dexPool : dexPools) { int count = result.size(); // name dex files: classes.dex, classes2.dex, classes3.dex, etc. File file = new File(folder, "classes" + (count == 0 ? "" : count + 1) + ".dex"); result.add(file); FileDataStore fds = new FileDataStore(file); dexPool.writeTo(fds); fds.close(); } return result; } }
public static void writeDexFile(String path, DexFile dexFile) throws IOException { DexPool.writeTo(path, dexFile); }
/** * Writes a DexFile out to disk * * @param path The path to write the dex file to * @param dexFile a DexFile to write */ public static void writeDexFile(@Nonnull String path, @Nonnull DexFile dexFile) throws IOException { DexPool.writeTo(path, dexFile); }
public static void writeTo(@Nonnull String path, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException { DexPool dexPool = makeDexPool(); for (ClassDef classDef: input.getClasses()) { ((ClassPool)dexPool.classSection).intern(classDef); } dexPool.writeTo(new FileDataStore(new File(path))); }
static void outputDex(@Nonnull DexFile dex, @Nonnull File output, boolean replace) throws IOException { if (output.exists()) { if (replace) { MiscUtil.delete(output); } else { final File old = output; output = MiscUtil.appendTail(output, "-deodex"); LLog.i(old + " already existed, use name " + output.getName()); } } DexPool.writeTo(output.getAbsolutePath(), dex); LLog.i("Output to " + output); }
public static void writeTo(@Nonnull String path, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException { DexPool dexPool = new DexPool(input.getOpcodes()); for (ClassDef classDef: input.getClasses()) { dexPool.internClass(classDef); } dexPool.writeTo(new FileDataStore(new File(path))); }
public static void writeTo(@Nonnull DexDataStore dataStore, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException { DexPool dexPool = new DexPool(input.getOpcodes()); for (ClassDef classDef: input.getClasses()) { dexPool.internClass(classDef); } dexPool.writeTo(dataStore); }
public static void writeTo(@Nonnull String path, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException { DexPool dexPool = new DexPool(input.getOpcodes()); for (ClassDef classDef: input.getClasses()) { dexPool.internClass(classDef); } dexPool.writeTo(new FileDataStore(new File(path))); }
public static void writeTo(@Nonnull DexDataStore dataStore, @Nonnull org.jf.dexlib2.iface.DexFile input) throws IOException { DexPool dexPool = new DexPool(input.getOpcodes()); for (ClassDef classDef: input.getClasses()) { dexPool.internClass(classDef); } dexPool.writeTo(dataStore); }
DexPool.writeTo(m, d); m.writeTo(jos); classesIdx = String.valueOf(++i);
static byte[] toBytecode(DexFile dexFile) throws IOException { MemoryDataStore dataStore = new MemoryDataStore(); DexPool.writeTo(dataStore, dexFile); return dataStore.getData(); }
public <C extends ClassDef> void writeClassesTo( List<C> classList, DexDataStoreFactory store) throws IOException { int dexNum = 0; DexPool dexPool = new DexPool(opcodes); ClassPool clsPool = dexPool.classSection; classList.sort(Comparator.comparing(ClassDef::getType)); for (ClassDef classDef : classList) { int numMethodIds = dexPool.methodSection.getItemCount(); int numFieldIds = dexPool.fieldSection.getItemCount(); int constantPoolSize = classDef.getDirectMethodCount() + classDef.getVirtualMethodCount() + classDef.getStaticFieldCount() + classDef.getInstanceFieldCount(); int maxMethodIdsInDex = numMethodIds + constantPoolSize + MAX_METHOD_ADDED_DURING_DEX_CREATION; int maxFieldIdsInDex = numFieldIds + constantPoolSize + MAX_FIELD_ADDED_DURING_DEX_CREATION; if (maxMethodIdsInDex > mMaxNumberOfIdxPerDex || maxFieldIdsInDex > mMaxNumberOfIdxPerDex) { dexPool.writeTo(store.getDataStore(dexNum)); dexNum++; dexPool = new DexPool(opcodes); clsPool = dexPool.classSection; } clsPool.intern(classDef); } dexPool.writeTo(store.getDataStore(dexNum)); }
@Test public void testAnnotationElementOrder() { // Elements are out of order wrt to the element name ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements); ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); try { DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex); } DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null); Assert.assertNotNull(dbAnnotation); List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements()); // Ensure that the elements were written out in sorted order Assert.assertEquals(2, dbElements.size()); Assert.assertEquals("blah", dbElements.get(0).getName()); Assert.assertEquals("zabaglione", dbElements.get(1).getName()); }
DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex);
dexPool.internClass(class2); dexPool.reset(); dexPool.writeTo(dataStore); dexFile1 = new RawDexFile(Opcodes.getDefault(), dataStore.getBuffer()); DexPool dexPool = new DexPool(Opcodes.getDefault()); dexPool.internClass(class1); dexPool.writeTo(dataStore); dexFile2 = new RawDexFile(Opcodes.getDefault(), dataStore.getBuffer());