org.benf.cfr.reader.util.bytestream.BaseByteData Java Examples

The following examples show how to use org.benf.cfr.reader.util.bytestream.BaseByteData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DCCommonState.java    From cfr with MIT License 5 votes vote down vote up
public ClassFile loadClassFileAtPath(final String path) {
    try {
        Pair<byte[], String> content = classFileSource.getClassFileContent(path);
        ByteData data = new BaseByteData(content.getFirst());
        return new ClassFile(data, content.getSecond(), this);
    } catch (Exception e) {
        couldNotLoadClasses.add(path);
        throw new CannotLoadClassException(path, e);
    }
}
 
Example #2
Source File: DecodedTableSwitch.java    From cfr with MIT License 5 votes vote down vote up
public DecodedTableSwitch(byte[] data, int offsetOfOriginalInstruction) {
    int curoffset = offsetOfOriginalInstruction + 1;
    int overflow = (curoffset % 4);
    int offset = overflow > 0 ? 4 - overflow : 0;

    ByteData bd = new BaseByteData(data);
    int defaultvalue = bd.getS4At(offset + OFFSET_OF_DEFAULT);
    int lowvalue = bd.getS4At(offset + OFFSET_OF_LOWBYTE);
    int highvalue = bd.getS4At(offset + OFFSET_OF_HIGHBYTE);
    int numoffsets = highvalue - lowvalue + 1;
    int defaultTarget = defaultvalue;
    int startValue = lowvalue;

    // Treemap so that targets are in bytecode order.
    Map<Integer, List<Integer>> uniqueTargets = MapFactory.newLazyMap(
            new TreeMap<Integer, List<Integer>>(),
            new UnaryFunction<Integer, List<Integer>>() {
                @Override
                public List<Integer> invoke(Integer arg) {
                    return ListFactory.newList();
                }
            });
    uniqueTargets.get(defaultTarget).add(null);
    for (int x = 0; x < numoffsets; ++x) {
        int target = bd.getS4At(offset + OFFSET_OF_OFFSETS + (x * 4));
        if (target != defaultTarget) {
            uniqueTargets.get(target).add(startValue + x);
        }
    }

    jumpTargets = ListFactory.newList();
    for (Map.Entry<Integer, List<Integer>> entry : uniqueTargets.entrySet()) {
        jumpTargets.add(new DecodedSwitchEntry(entry.getValue(), entry.getKey()));
    }

}
 
Example #3
Source File: DecodedLookupSwitch.java    From cfr with MIT License 5 votes vote down vote up
public DecodedLookupSwitch(byte[] data, int offsetOfOriginalInstruction) {
    int curoffset = offsetOfOriginalInstruction + 1;
    int overflow = (curoffset % 4);
    int offset = overflow > 0 ? 4 - overflow : 0;

    ByteData bd = new BaseByteData(data);
    int defaultvalue = bd.getS4At(offset + OFFSET_OF_DEFAULT);
    int numpairs = bd.getS4At(offset + OFFSET_OF_NUMPAIRS);
    // Treemap so that targets are in bytecode order.
    Map<Integer, List<Integer>> uniqueTargets = MapFactory.newLazyMap(
            new TreeMap<Integer, List<Integer>>(),
            new UnaryFunction<Integer, List<Integer>>() {
                @Override
                public List<Integer> invoke(Integer arg) {
                    return ListFactory.newList();
                }
            });
    uniqueTargets.get(defaultvalue).add(null);
    for (int x = 0; x < numpairs; ++x) {
        int value = bd.getS4At(offset + OFFSET_OF_PAIRS + (x * 8));
        int target = bd.getS4At(offset + OFFSET_OF_PAIRS + (x * 8) + 4);
        if (target != defaultvalue) {
            uniqueTargets.get(target).add(value);
        }
    }
    jumpTargets = ListFactory.newList();
    for (Map.Entry<Integer, List<Integer>> entry : uniqueTargets.entrySet()) {
        jumpTargets.add(new DecodedSwitchEntry(entry.getValue(), entry.getKey()));
    }
}
 
Example #4
Source File: CFRDecompiler.java    From java-disassembler with GNU General Public License v3.0 4 votes vote down vote up
public static String doClass(DCCommonState dcCommonState, byte[] content1) {
    Options options = dcCommonState.getOptions();
    IllegalIdentifierDump illegalIdentifierDump = IllegalIdentifierDump.Factory.get(options);
    Dumper d = new ToStringDumper();

    try {
        StackTraceElement[] arr$;
        int len$;
        int i$;
        StackTraceElement x;
        try {
            SummaryDumper summaryDumper = new NopSummaryDumper();
            BaseByteData data = new BaseByteData(content1);
            ClassFile c = new ClassFile(data, "", dcCommonState);

            dcCommonState.configureWith(c);

            try {
                c = dcCommonState.getClassFile(c.getClassType());
            } catch (CannotLoadClassException var20) {
            }

            if (options.getOption(OptionsImpl.DECOMPILE_INNER_CLASSES)) {
                c.loadInnerClasses(dcCommonState);
            }

            if (options.getOption(OptionsImpl.RENAME_DUP_MEMBERS)) {
                MemberNameResolver.resolveNames(dcCommonState, ListFactory.newList(dcCommonState.getClassCache().getLoadedTypes()));
            }

            c.analyseTop(dcCommonState);
            TypeUsageCollector collectingDumper = new TypeUsageCollector(c);
            c.collectTypeUsages(collectingDumper);
            String methname = options.getOption(OptionsImpl.METHODNAME);
            if (methname == null) {
                c.dump(d);
            } else {
                try {
                    Iterator i$$ = c.getMethodByName(methname).iterator();

                    while(i$$.hasNext()) {
                        Method method = (Method)i$$.next();
                        method.dump(d, true);
                    }
                } catch (NoSuchMethodException var21) {
                    throw new IllegalArgumentException("No such method '" + methname + "'.");
                }
            }

            d.print("");
            return d.toString();
        } catch (ConfusedCFRException var22) {
            System.err.println(var22.toString());
            arr$ = var22.getStackTrace();
            len$ = arr$.length;

            for(i$ = 0; i$ < len$; ++i$) {
                x = arr$[i$];
                System.err.println(x);
            }
        } catch (CannotLoadClassException var23) {
            System.out.println("Can't load the class specified:");
            System.out.println(var23.toString());
        } catch (RuntimeException var24) {
            System.err.println(var24.toString());
            arr$ = var24.getStackTrace();
            len$ = arr$.length;

            for(i$ = 0; i$ < len$; ++i$) {
                x = arr$[i$];
                System.err.println(x);
            }
        }
    } finally {
        if (d != null) {
            d.close();
        }
    }
    return "";
}
 
Example #5
Source File: Op02WithProcessedDataAndRefs.java    From cfr with MIT License 4 votes vote down vote up
private int getInstrArgShort(int index) {
    BaseByteData tmp = new BaseByteData(rawData);
    return tmp.getS2At(index);
}