use of org.jf.dexlib2.writer.pool.DexPool in project atlas by alibaba.
the class PatchDexTool method writeDex.
public void writeDex(File outDexFolder, Set<ClassDef> classDefs) throws IOException {
int i = 0;
File outDexFile = getDexFile(outDexFolder, i);
if (!outDexFile.getParentFile().exists()) {
outDexFile.getParentFile().mkdirs();
}
if (mainBundle) {
List<ClassDef> sortClassDefs = sort(classDefs);
DexPool dexPool = new DexPool(Opcodes.getDefault());
Iterator<ClassDef> iterator = sortClassDefs.iterator();
while (iterator.hasNext()) {
ClassDef classDef = iterator.next();
dexPool.internClass(classDef);
if (((BasePool) dexPool.methodSection).getItemCount() > MAX_COUNT || ((BasePool) dexPool.fieldSection).getItemCount() > MAX_COUNT) {
dexPool.writeTo(new FileDataStore(outDexFile));
outDexFile = getDexFile(outDexFolder, ++i);
dexPool = new DexPool(Opcodes.getDefault());
}
}
dexPool.writeTo(new FileDataStore(outDexFile));
} else {
DexFileFactory.writeDexFile(outDexFile.getAbsolutePath(), new DexFile() {
@Nonnull
@Override
public Set<? extends ClassDef> getClasses() {
return new AbstractSet<ClassDef>() {
@Nonnull
@Override
public Iterator<ClassDef> iterator() {
return classDefs.iterator();
}
@Override
public int size() {
return classDefs.size();
}
};
}
@Nonnull
@Override
public Opcodes getOpcodes() {
return Opcodes.getDefault();
}
});
}
}
use of org.jf.dexlib2.writer.pool.DexPool in project smali by JesusFreke.
the class DexPool method writeTo.
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);
}
use of org.jf.dexlib2.writer.pool.DexPool in project smali by JesusFreke.
the class RollbackTest method testRollback.
@Test
public void testRollback() throws IOException {
ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls1;", "field1", "I", AccessFlags.PUBLIC.getValue(), null, null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls1;", "method1", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("I", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, null)));
ClassDef class2 = new ImmutableClassDef("Lcls2;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation2;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls2;", "field2", "D", AccessFlags.PUBLIC.getValue(), null, null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls2;", "method2", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("D", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, null)));
DexBackedDexFile dexFile1;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.mark();
dexPool.internClass(class2);
dexPool.reset();
dexPool.writeTo(dataStore);
dexFile1 = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
}
DexBackedDexFile dexFile2;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.writeTo(dataStore);
dexFile2 = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
}
List<MapItem> mapItems1 = dexFile1.getMapItems();
List<MapItem> mapItems2 = dexFile2.getMapItems();
for (int i = 0; i < mapItems1.size(); i++) {
Assert.assertEquals(mapItems1.get(i).getType(), mapItems2.get(i).getType());
Assert.assertEquals(mapItems1.get(i).getItemCount(), mapItems2.get(i).getItemCount());
}
}
use of org.jf.dexlib2.writer.pool.DexPool in project soot by Sable.
the class MultiDexBuilder method newDexPool.
protected void newDexPool() {
curPool = new DexPool(opcodes);
dexPools.add(curPool);
}
use of org.jf.dexlib2.writer.pool.DexPool in project soot by Sable.
the class MultiDexBuilder method writeTo.
/**
* 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;
}
Aggregations