/** * Dumps the given array, interpreting it as a class file and dumping * methods with indications of block-level stuff. * * @param bytes {@code non-null;} bytes of the (alleged) class file * @param out {@code non-null;} where to dump to * @param filePath the file path for the class, excluding any base * directory specification * @param rop whether or not to registerize (make rop blocks) * @param args commandline parsedArgs */ public static void dump(byte[] bytes, PrintStream out, String filePath, boolean rop, Args args) { BlockDumper bd = new BlockDumper(bytes, out, filePath, rop, args); bd.dump(); }
/** {@inheritDoc} */ @Override public void startParsingMember(ByteArray bytes, int offset, String name, String descriptor) { if (descriptor.indexOf('(') < 0) { // It's a field, not a method return; } if (!shouldDumpMethod(name)) { return; } // Reset the dump cursor to the start of the method. setAt(bytes, offset); suppressDump = false; if (first) { first = false; } else { parsed(bytes, offset, 0, "\n"); } parsed(bytes, offset, 0, "method " + name + " " + descriptor); suppressDump = true; }
/** {@inheritDoc} */ @Override public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) { if (!(member instanceof Method)) { return; } if (!shouldDumpMethod(name)) { return; } ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true); if (rop) { ropDump(meth); } else { regularDump(meth); } }
/** {@inheritDoc} */ @Override public void startParsingMember(ByteArray bytes, int offset, String name, String descriptor) { if (descriptor.indexOf('(') < 0) { // It's a field, not a method return; } if (!shouldDumpMethod(name)) { return; } suppressDump = false; if (first) { first = false; } else { parsed(bytes, offset, 0, "\n"); } parsed(bytes, offset, 0, "method " + name + " " + descriptor); suppressDump = true; }
/** * Does the dumping. */ public void dump() { byte[] bytes = getBytes(); ByteArray ba = new ByteArray(bytes); /* * First, parse the file completely, so we can safely refer to * attributes, etc. */ classFile = new DirectClassFile(ba, getFilePath(), getStrictParse()); classFile.setAttributeFactory(StdAttributeFactory.THE_ONE); classFile.getMagic(); // Force parsing to happen. // Next, reparse it and observe the process. DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse()); liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE); liveCf.setObserver(this); liveCf.getMagic(); // Force parsing to happen. }
setAt(bytes, 0); parsed(bytes, byteAt, start - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(start)); parsed(bytes, start, 0, "block " + Hex.u2(bb.getLabel()) + ": " + Hex.u2(start) + ".." + Hex.u2(end)); changeIndent(1); int ssz = successors.size(); if (ssz == 0) { parsed(bytes, end, 0, "returns"); } else { for (int j = 0; j < ssz; j++) { int succ = successors.get(j); parsed(bytes, end, 0, "next " + Hex.u2(succ)); ByteCatchList.Item one = catches.get(j); CstType exceptionClass = one.getExceptionClass(); parsed(bytes, end, 0, "catch " + ((exceptionClass == CstType.OBJECT) ? "<any>" : changeIndent(-1); byteAt = end; parsed(bytes, byteAt, end - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); setAt(bytes, 0); parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true;
/** * Processes one file. * * @param name {@code non-null;} name of the file * @param bytes {@code non-null;} contents of the file */ private void processOne(String name, byte[] bytes) { if (parsedArgs.dotDump) { DotDumper.dump(bytes, name, parsedArgs); } else if (parsedArgs.basicBlocks) { BlockDumper.dump(bytes, System.out, name, false, parsedArgs); } else if (parsedArgs.ropBlocks) { BlockDumper.dump(bytes, System.out, name, true, parsedArgs); } else if (parsedArgs.ssaBlocks) { // --optimize ignored with --ssa-blocks parsedArgs.optimize = false; SsaDumper.dump(bytes, System.out, name, parsedArgs); } else { ClassDumper.dump(bytes, System.out, name, parsedArgs); } } }
int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true;
parsed(bytes, byteAt, start - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(start)); parsed(bytes, start, 0, "block " + Hex.u2(bb.getLabel()) + ": " + Hex.u2(start) + ".." + Hex.u2(end)); changeIndent(1); int ssz = successors.size(); if (ssz == 0) { parsed(bytes, end, 0, "returns"); } else { for (int j = 0; j < ssz; j++) { int succ = successors.get(j); parsed(bytes, end, 0, "next " + Hex.u2(succ)); ByteCatchList.Item one = catches.get(j); CstType exceptionClass = one.getExceptionClass(); parsed(bytes, end, 0, "catch " + ((exceptionClass == CstType.OBJECT) ? "<any>" : changeIndent(-1); byteAt = end; parsed(bytes, byteAt, end - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
/** * Does the dumping. */ public void dump() { byte[] bytes = getBytes(); ByteArray ba = new ByteArray(bytes); /* * First, parse the file completely, so we can safely refer to * attributes, etc. */ classFile = new DirectClassFile(ba, getFilePath(), getStrictParse()); classFile.setAttributeFactory(StdAttributeFactory.THE_ONE); classFile.getMagic(); // Force parsing to happen. // Next, reparse it and observe the process. DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse()); liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE); liveCf.setObserver(this); liveCf.getMagic(); // Force parsing to happen. }
setAt(bytes, 0); parsed(bytes, byteAt, start - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(start)); parsed(bytes, start, 0, "block " + Hex.u2(bb.getLabel()) + ": " + Hex.u2(start) + ".." + Hex.u2(end)); changeIndent(1); int ssz = successors.size(); if (ssz == 0) { parsed(bytes, end, 0, "returns"); } else { for (int j = 0; j < ssz; j++) { int succ = successors.get(j); parsed(bytes, end, 0, "next " + Hex.u2(succ)); ByteCatchList.Item one = catches.get(j); CstType exceptionClass = one.getExceptionClass(); parsed(bytes, end, 0, "catch " + ((exceptionClass == CstType.OBJECT) ? "<any>" : changeIndent(-1); byteAt = end; parsed(bytes, byteAt, end - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); setAt(bytes, 0); parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true;
/** * Processes one file. * * @param name {@code non-null;} name of the file * @param bytes {@code non-null;} contents of the file */ private static void processOne(String name, byte[] bytes) { if (parsedArgs.dotDump) { DotDumper.dump(bytes, name, parsedArgs); } else if (parsedArgs.basicBlocks) { BlockDumper.dump(bytes, System.out, name, false, parsedArgs); } else if (parsedArgs.ropBlocks) { BlockDumper.dump(bytes, System.out, name, true, parsedArgs); } else if (parsedArgs.ssaBlocks) { // --optimize ignored with --ssa-blocks parsedArgs.optimize = false; SsaDumper.dump(bytes, System.out, name, parsedArgs); } else { ClassDumper.dump(bytes, System.out, name, parsedArgs); } } }
/** {@inheritDoc} */ @Override public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) { if (!(member instanceof Method)) { return; } if (!shouldDumpMethod(name)) { return; } if ((member.getAccessFlags() & (AccessFlags.ACC_ABSTRACT | AccessFlags.ACC_NATIVE)) != 0) { return; } ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true); if (rop) { ropDump(meth); } else { regularDump(meth); } }
/** * Does the dumping. */ public void dump() { byte[] bytes = getBytes(); ByteArray ba = new ByteArray(bytes); /* * First, parse the file completely, so we can safely refer to * attributes, etc. */ classFile = new DirectClassFile(ba, getFilePath(), getStrictParse()); classFile.setAttributeFactory(StdAttributeFactory.THE_ONE); classFile.getMagic(); // Force parsing to happen. // Next, reparse it and observe the process. DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse()); liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE); liveCf.setObserver(this); liveCf.getMagic(); // Force parsing to happen. }
/** {@inheritDoc} */ @Override public void startParsingMember(ByteArray bytes, int offset, String name, String descriptor) { if (descriptor.indexOf('(') < 0) { // It's a field, not a method return; } if (!shouldDumpMethod(name)) { return; } // Reset the dump cursor to the start of the method. setAt(bytes, offset); suppressDump = false; if (first) { first = false; } else { parsed(bytes, offset, 0, "\n"); } parsed(bytes, offset, 0, "method " + name + " " + descriptor); suppressDump = true; }
setAt(bytes, 0); parsed(bytes, byteAt, start - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(start)); parsed(bytes, start, 0, "block " + Hex.u2(bb.getLabel()) + ": " + Hex.u2(start) + ".." + Hex.u2(end)); changeIndent(1); int ssz = successors.size(); if (ssz == 0) { parsed(bytes, end, 0, "returns"); } else { for (int j = 0; j < ssz; j++) { int succ = successors.get(j); parsed(bytes, end, 0, "next " + Hex.u2(succ)); ByteCatchList.Item one = catches.get(j); CstType exceptionClass = one.getExceptionClass(); parsed(bytes, end, 0, "catch " + ((exceptionClass == CstType.OBJECT) ? "<any>" : changeIndent(-1); byteAt = end; parsed(bytes, byteAt, end - byteAt, "dead code " + Hex.u2(byteAt) + ".." + Hex.u2(end));
int paramWidth = computeParamWidth(meth, isStatic); rmeth = Optimizer.optimize(rmeth, paramWidth, isStatic, true, advice); setAt(bytes, 0); parsed(bytes, 0, bytes.size(), sb.toString()); suppressDump = true;
/** * Dumps the given array, interpreting it as a class file and dumping * methods with indications of block-level stuff. * * @param bytes {@code non-null;} bytes of the (alleged) class file * @param out {@code non-null;} where to dump to * @param filePath the file path for the class, excluding any base * directory specification * @param rop whether or not to registerize (make rop blocks) * @param args commandline parsedArgs */ public static void dump(byte[] bytes, PrintStream out, String filePath, boolean rop, Args args) { BlockDumper bd = new BlockDumper(bytes, out, filePath, rop, args); bd.dump(); }