use of com.android.dex.Dex in project buck by facebook.
the class DexMergeTest method mergeAndLoad.
public ClassLoader mergeAndLoad(String dexAResource, String dexBResource) throws Exception {
Dex dexA = resourceToDexBuffer(dexAResource);
Dex dexB = resourceToDexBuffer(dexBResource);
Dex merged = new DexMerger(dexA, dexB, CollisionPolicy.KEEP_FIRST).merge();
File mergedDex = File.createTempFile("DexMergeTest", ".classes.dex");
merged.writeTo(mergedDex);
File mergedJar = dexToJar(mergedDex);
// simplify the javac classpath by not depending directly on 'dalvik.system' classes
return (ClassLoader) Class.forName("dalvik.system.PathClassLoader").getConstructor(String.class, ClassLoader.class).newInstance(mergedJar.getPath(), getClass().getClassLoader());
}
use of com.android.dex.Dex in project buck by facebook.
the class MergeTest method main.
public static void main(String[] args) throws Throwable {
for (int i = 0; i < NUMBER_OF_TRIES; i++) {
String fileName1 = args[(int) (Math.random() * args.length)];
String fileName2 = args[(int) (Math.random() * args.length)];
try {
Dex toMerge = new Dex(new File(fileName1));
Dex toMerge2 = new Dex(new File(fileName2));
new DexMerger(toMerge, toMerge2, CollisionPolicy.KEEP_FIRST).merge();
} catch (DexIndexOverflowException e) {
// ignore index overflow
} catch (Throwable t) {
System.err.println("Problem merging those 2 dexes: \"" + fileName1 + "\" and \"" + fileName2 + "\"");
throw t;
}
}
}
use of com.android.dex.Dex in project buck by facebook.
the class DexMerger method mergeClassDefs.
private void mergeClassDefs() {
SortableType[] types = getSortedTypes();
contentsOut.classDefs.off = idsDefsOut.getPosition();
contentsOut.classDefs.size = types.length;
for (SortableType type : types) {
Dex in = type.getDex();
transformClassDef(in, type.getClassDef(), type.getIndexMap());
}
}
use of com.android.dex.Dex in project jadx by skylot.
the class InputFile method loadFromZip.
private boolean loadFromZip(String ext) throws IOException, DecodeException {
ZipFile zf = new ZipFile(file);
int index = 0;
while (true) {
String entryName = "classes" + (index == 0 ? "" : index) + ext;
ZipEntry entry = zf.getEntry(entryName);
if (entry == null) {
break;
}
InputStream inputStream = zf.getInputStream(entry);
try {
if (ext.equals(".dex")) {
addDexFile(entryName, new Dex(inputStream));
} else if (ext.equals(".jar")) {
File jarFile = FileUtils.createTempFile(entryName);
FileOutputStream fos = new FileOutputStream(jarFile);
try {
IOUtils.copy(inputStream, fos);
} finally {
close(fos);
}
addDexFile(entryName, loadFromJar(jarFile));
} else {
throw new JadxRuntimeException("Unexpected extension in zip: " + ext);
}
} finally {
close(inputStream);
}
index++;
if (index == 1) {
index = 2;
}
}
zf.close();
return index > 0;
}
use of com.android.dex.Dex in project J2ME-Loader by nikita36078.
the class Main method mergeLibraryDexBuffers.
/**
* Merges the dex files in library jars. If multiple dex files define the
* same type, this fails with an exception.
*/
private byte[] mergeLibraryDexBuffers(byte[] outArray) throws IOException {
ArrayList<Dex> dexes = new ArrayList<Dex>();
if (outArray != null) {
dexes.add(new Dex(outArray));
}
for (byte[] libraryDex : libraryDexBuffers) {
dexes.add(new Dex(libraryDex));
}
if (dexes.isEmpty()) {
return null;
}
Dex merged = new DexMerger(dexes.toArray(new Dex[dexes.size()]), CollisionPolicy.FAIL, context).merge();
return merged.getBytes();
}
Aggregations