Search in sources :

Example 1 with Dex

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);
}
Also used : Dex(com.android.dex.Dex) StaticValuesParser(jadx.core.dex.nodes.parser.StaticValuesParser)

Example 2 with Dex

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;
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) Dex(com.android.dex.Dex) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 3 with Dex

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;
                }
            }
    }
}
Also used : Dex(com.android.dex.Dex) DexMerger(com.android.dx.merge.DexMerger) BufferOverflowException(java.nio.BufferOverflowException)

Example 4 with Dex

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);
}
Also used : Dex(com.android.dex.Dex) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 5 with Dex

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());
    }
}
Also used : Dex(com.android.dex.Dex)

Aggregations

Dex (com.android.dex.Dex)17 File (java.io.File)6 DexMerger (com.android.dx.merge.DexMerger)3 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 ZipEntry (java.util.zip.ZipEntry)2 DexException (com.android.dex.DexException)1 DexIndexOverflowException (com.android.dex.DexIndexOverflowException)1 DxContext (com.android.dx.command.dexer.DxContext)1 StaticValuesParser (jadx.core.dex.nodes.parser.StaticValuesParser)1 DecodeException (jadx.core.utils.exceptions.DecodeException)1 JadxException (jadx.core.utils.exceptions.JadxException)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 BufferOverflowException (java.nio.BufferOverflowException)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1