use of com.android.dex.Dex in project jadx by skylot.
the class ClassNode method loadStaticValues.
private void loadStaticValues(ClassDef cls, List<FieldNode> staticFields) throws DecodeException {
for (FieldNode f : staticFields) {
if (f.getAccessFlags().isFinal()) {
f.addAttr(FieldInitAttr.NULL_VALUE);
}
}
int offset = cls.getStaticValuesOffset();
if (offset == 0) {
return;
}
Dex.Section section = dex.openSection(offset);
StaticValuesParser parser = new StaticValuesParser(dex, section);
parser.processFields(staticFields);
// process const fields
root().getConstValues().processConstFields(this, staticFields);
}
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 bazel by bazelbuild.
the class DexFileAggregator method merge.
private Dex merge(Dex... dexes) throws IOException {
switch(dexes.length) {
case 0:
return new Dex(0);
case 1:
return dexes[0];
default:
try {
DexMerger dexMerger = new DexMerger(dexes, CollisionPolicy.FAIL);
dexMerger.setCompactWasteThreshold(wasteThresholdPerDex);
return dexMerger.merge();
} catch (BufferOverflowException e) {
// Bug in dx can cause this for ~1500 or more classes
Dex[] left = Arrays.copyOf(dexes, dexes.length / 2);
Dex[] right = Arrays.copyOfRange(dexes, left.length, dexes.length);
System.err.printf("Couldn't merge %d classes, trying %d%n", dexes.length, left.length);
try {
return merge(merge(left), merge(right));
} catch (RuntimeException e2) {
e2.addSuppressed(e);
throw e2;
}
}
}
}
use of com.android.dex.Dex in project buck by facebook.
the class Main method main.
public static void main(String[] args) throws IOException {
String dexFile = args[0];
String pattern = args[1];
Dex dex = new Dex(new File(dexFile));
int count = new Grep(dex, Pattern.compile(pattern), new PrintWriter(System.out)).grep();
System.exit((count > 0) ? 0 : 1);
}
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());
}
}
Aggregations