private boolean isStringClassB(ClassGen cg) { if (cg.getMethods().length == 1 && cg.getMethods()[0].isStatic()) { if (cg.getMethods()[0].getReturnType().toString().equals("java.lang.String")) { return true; } } return false; }
public boolean isLoader(ClassGen cg) { return cg.getMethods().length == 3 && cg.getMethods()[1].isStatic() && cg.getMethods()[1].isFinal() && cg.getMethods()[1].isPublic() && cg.getMethods()[1].isSynchronized() && cg.getMethods()[1].getReturnType().toString().equals("java.lang.String"); }
public boolean isAuthClass(ClassGen cg) { if (cg.getMethods().length == 2 && cg.getMethods()[0].getArgumentTypes().length == 1) { if (cg.getMethods()[0].getArgumentTypes()[0].getSignature().contains("String")) { if (cg.getMethods()[0].getReturnType().toString().contains("boolean")) { return true; } } } return false; }
private boolean isStringClass(ClassGen cg) { if (cg.getMethods().length == 2 && cg.getMethods()[0].isStatic() && cg.getMethods()[1].isStatic()) { if (cg.getMethods()[0].getReturnType().toString().equals( "java.lang.String") && cg.getMethods()[1].getReturnType().toString().equals( "java.lang.String")) { return true; } } return false; }
public static boolean typeA(ClassGen cg) { for (Method m : cg.getMethods()) { if (m.getArgumentTypes().length == 1 && m.getArgumentTypes()[0].equals(Type.getType(char[].class))) { return true; } } return false; }
/** * @return the (finally) built up Java class object. */ public JavaClass getJavaClass() { final int[] interfaces = getInterfaces(); final Field[] fields = getFields(); final Method[] methods = getMethods(); Attribute[] attributes = null; if (annotation_vec.isEmpty()) { attributes = getAttributes(); } else { // TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations' final Attribute[] annAttributes = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries()); attributes = new Attribute[attribute_vec.size()+annAttributes.length]; attribute_vec.toArray(attributes); System.arraycopy(annAttributes,0,attributes,attribute_vec.size(),annAttributes.length); } // Must be last since the above calls may still add something to it final ConstantPool _cp = this.cp.getFinalConstantPool(); return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor, super.getAccessFlags(), _cp, interfaces, fields, methods, attributes); }
/** * @return the (finally) built up Java class object. */ public JavaClass getJavaClass() { int[] interfaces = getInterfaces(); Field[] fields = getFields(); Method[] methods = getMethods(); Attribute[] attributes = getAttributes(); // Must be last since the above calls may still add something to it ConstantPool cp = this.cp.getFinalConstantPool(); return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor, access_flags, cp, interfaces, fields, methods, attributes); }
public void fixStack() { for (ClassGen cg : cgs.values()) { for (Method method : cg.getMethods()) { MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); mg.removeNOPs(); mg.setMaxLocals(); mg.setMaxStack(); cg.replaceMethod(method, mg.getMethod()); logger.debug(String.format("Reset MaxStack and MaxLocals in %s.%s", cg.getClassName(), mg.getName())); } } }
public void setDecryptor() { for (ClassGen cg : cgs.values()) { for (Method m : cg.getMethods()) { try { if (m.isPublic() && m.isStatic() && m.getArgumentTypes()[0].toString().equals("java.lang.String") && m.getReturnType().toString().equals("java.lang.String")) { String dc = cg.getClassName() + "." + m.getName(); decryptor = m.getName(); decryptorclass = cg.getClassName(); logger.debug("Found String Decryptor! " + dc); return; } } catch (Exception e) { continue; } } } logger.error("String decrypt not found!"); }
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()); } } } }
for (Method m : cg.getMethods()) { if (m.getName().equalsIgnoreCase("<clinit>") || m.getName().equalsIgnoreCase("<init>")
field.setAttributes(cleanupAttributes(field.getAttributes())); for (Method method : aGen.getMethods()) { method.setAttributes(cleanupAttributes(method.getAttributes()));
public void replaceCheckMethod() { ClassGen cg = cgs.get(AuthClass); Method method = cg.getMethods()[0]; MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); InstructionList list = new InstructionList(); list.append(new ICONST(1)); list.append(new IRETURN()); mg.removeExceptionHandlers(); mg.removeLineNumbers(); mg.removeLocalVariables(); mg.removeExceptions(); mg.setInstructionList(list); mg.setMaxLocals(); mg.setMaxStack(); cg.replaceMethod(method, mg.getMethod()); }
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; } } } } } }
public void searchConstantPool() { for (ClassGen cg : cgs.values()) { for (Method m : cg.getMethods()) { MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool()); InstructionList list = mg.getInstructionList();
public void removeStringEncryption() { for (ClassGen cg : cgs.values()) { for (Method m : cg.getMethods()) { MethodGen mg = new MethodGen(m, cg.getClassName(), cg.getConstantPool()); InstructionList il = mg.getInstructionList();
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()); } } }
public void replaceStrings() throws TargetLostException { for (ClassGen cg : cgs.values()) { int replaced = 0; for (Method method : cg.getMethods()) { MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); InstructionList list = mg.getInstructionList();
buildClassContentsWithAnnotatedMethods(cg, cp, il); int i = cg.getMethods()[0].getAnnotationEntries().length; assertTrue( "Prior to dumping, main method should have 1 annotation but has " final ClassGen cg2 = new ClassGen(jc2); final Method[] m = cg2.getMethods(); i = m[0].getAnnotationEntries().length; assertTrue("The main 'Method' should have one annotation but has " + i,
final JavaClass jc3 = getClassFrom("temp3", "HelloWorld"); final ClassGen cg3 = new ClassGen(jc3); final Method mainMethod3 = cg3.getMethods()[1]; final int i = mainMethod3.getAnnotationEntries().length; assertTrue("The 'Method' should now have two annotations but has " + i,