/** * Get instruction handle for instruction at byte code position pos. * This only works properly, if the list is freshly initialized from a byte array or * setPositions() has been called before this method. * * @param pos byte code position to search for * @return target position's instruction handle if available */ public InstructionHandle findHandle(int pos) { InstructionHandle[] ihs = getInstructionHandles(); return findHandle(ihs, byte_positions, length, pos); }
/** * A Control Flow Graph. */ public ControlFlowGraph(MethodGen method_gen){ subroutines = new Subroutines(method_gen); exceptionhandlers = new ExceptionHandlers(method_gen); InstructionHandle[] instructionhandles = method_gen.getInstructionList().getInstructionHandles(); for (int i=0; i<instructionhandles.length; i++){ instructionContexts.put(instructionhandles[i], new InstructionContextImpl(instructionhandles[i])); } this.method_gen = method_gen; }
/** * Reread the instruction list, e.g., after you've altered the list upon a match. */ public final void reread() { int size = il.getLength(); char[] buf = new char[size]; // Create a string with length equal to il length handles = il.getInstructionHandles(); // Map opcodes to characters for(int i=0; i < size; i++) buf[i] = makeChar(handles[i].getInstruction().getOpcode()); il_string = new String(buf); }
InstructionHandle generateLabel(SourceOfRandomness r, InstructionList code) { InstructionHandle handles[] = code.getInstructionHandles(); // If no instructions generated so far, emit a NOP to get some label if (handles.length == 0) { handles = new InstructionHandle[]{ code.append(new NOP()) }; } return r.choose(handles); }
/** * Reread the instruction list, e.g., after you've altered the list upon a * match. */ public final void reread() { final int size = il.getLength(); final char[] buf = new char[size]; // Create a string with length equal to il length handles = il.getInstructionHandles(); // Map opcodes to characters for (int i = 0; i < size; i++) { buf[i] = makeChar(handles[i].getInstruction().getOpcode()); } il_string = new String(buf); }
/** * A Control Flow Graph. * @param method_gen the method generator instance * @param enableJustIceCheck if true, additional JustIce checks are performed * @since 6.0 */ public ControlFlowGraph(final MethodGen method_gen, final boolean enableJustIceCheck) { subroutines = new Subroutines(method_gen, enableJustIceCheck); exceptionhandlers = new ExceptionHandlers(method_gen); final InstructionHandle[] instructionhandles = method_gen.getInstructionList().getInstructionHandles(); for (final InstructionHandle instructionhandle : instructionhandles) { instructionContexts.put(instructionhandle, new InstructionContextImpl(instructionhandle)); } //this.method_gen = method_gen; }
private void dumpCode() InstructionHandle[] handles= il.getInstructionHandles();
private InstructionHandle[] getInstructionHandles(final JavaClass clazz, final ConstantPoolGen cp, final Method method) { final MethodGen methodGen = new MethodGen(method, clazz.getClassName(), cp); final InstructionList instructionList = methodGen.getInstructionList(); return instructionList.getInstructionHandles(); } }
public void getStringsFromZKM() { for (ClassGen cg : cgs.values()) { char[] key = findKey(cg); for (Method method : cg.getMethods()) { MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); InstructionList list = mg.getInstructionList(); if (list == null) { continue; } InstructionHandle[] handles = list.getInstructionHandles(); ArrayList<String> all = new ArrayList<String>(); if (method.getName().contains("clinit")) { for (int i = 0; i < handles.length; i++) { if (handles[i].getInstruction() instanceof LDC) { LDC orig = ((LDC) handles[i].getInstruction()); if (!orig.getType(cg.getConstantPool()).getSignature().contains("String")) continue; String enc = orig.getValue(cg.getConstantPool()).toString(); String dec = decrypt(enc, key); all.add(dec); logger.debug(cg.getClassName() + " -> " + dec); } } zkStrings.put(cg.getClassName(), all); logger.debug("Decrypted and stored " + all.size() + " strings from " + cg.getClassName()); } } } }
public void grabStrings() { for (ClassGen cg : cgs.values()) { for (Method m : cg.getMethods()) { int key = 0; MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool()); InstructionList list = mg.getInstructionList(); if (list == null) { return; } InstructionHandle[] handles = list.getInstructionHandles(); for (int x = 0; x < handles.length; x++) { if (x + 3 < handles.length) { if (handles[x].getInstruction() instanceof LDC && handles[x + 1].getInstruction() instanceof ASTORE && GenericMethods.isNumber(handles[x + 2].getInstruction()) && handles[x + 3].getInstruction() instanceof ISTORE) { key = GenericMethods.getValueOfNumber(handles[x + 2].getInstruction(), cg.getConstantPool()); LDC tx = (LDC) handles[x].getInstruction(); String encryptedContent = tx.getValue(cg.getConstantPool()).toString(); String decryptedContent = decrypt(encryptedContent, key); logger.debug("Found key for " + cg.getClassName() + ": " + key); logger.debug("Strings for class: " + decryptedContent); ssStrings.put(cg.getClassName(), decryptedContent); continue; } } } } } }
InstructionHandle[] handles; if (list != null && list.size() > 0) { handles = list.getInstructionHandles(); } else { break;
MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool()); InstructionList il = mg.getInstructionList(); InstructionHandle[] handles = il.getInstructionHandles(); for (int i = 1; i < handles.length; i++) { if ((handles[i].getInstruction() instanceof LDC)
continue; InstructionHandle[] handles = list.getInstructionHandles(); for (InstructionHandle handle : handles) { if (GenericMethods.isCall(handle.getInstruction())) {
if (m.getName().contains("clinit")) { MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool()); InstructionHandle[] handles = mg.getInstructionList().getInstructionHandles(); char[] keyAsChars = new char[5]; int found = 0;
public void fixPOPs() { for (ClassGen cg : cgs.values()) { int replaced = 0; for (Method method : cg.getMethods()) { //logger.debug("in method " + method.getName()); MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); InstructionList list = mg.getInstructionList(); if (list == null) { continue; } InstructionHandle[] handles = list.getInstructionHandles(); if (handles[0].getInstruction() instanceof DUP || handles[0].getInstruction() instanceof ASTORE || handles[0].getInstruction() instanceof POP) { handles[0].setInstruction(new NOP()); replaced++; } mg.setInstructionList(list); mg.removeNOPs(); mg.setMaxLocals(); mg.setMaxStack(); cg.replaceMethod(method, mg.getMethod()); } if (replaced > 0) { logger.debug("Removed " + replaced + " invalid POPs in " + cg.getClassName()); } } }
if (list == null) continue; InstructionHandle[] handles = list.getInstructionHandles();
continue; InstructionHandle[] handles = list.getInstructionHandles(); for (int i = 1; i < handles.length; i++) { if (handles[i].getInstruction() instanceof INVOKESTATIC && handles[i - 1].getInstruction() instanceof LDC) {
continue; InstructionHandle[] handles = list.getInstructionHandles(); for (int i = 1; i < handles.length; i++) { if (handles[i].getInstruction() instanceof INVOKESTATIC && GenericMethods.isNumber(handles[i - 1].getInstruction())) {
public void testSearch() { final InstructionList il = new InstructionList(); il.append(new ILOAD(1)); il.append(new ILOAD(2)); il.append(new IADD()); il.append(new ISTORE(3)); final InstructionFinder finder = new InstructionFinder(il); final Iterator<?> it = finder.search("ILOAD IADD", il.getInstructionHandles()[0], null ); final InstructionHandle[] ihs = (InstructionHandle[])it.next(); assertEquals(2, ihs.length); assertEquals(ihs[0].getInstruction(), new ILOAD(2)); assertEquals(ihs[1].getInstruction(), new IADD()); } }
return; InstructionHandle[] handles = list.getInstructionHandles(); for (int x = 0; x < handles.length; x++) { if (x + 3 < handles.length) {