@Test public void testPutStatic1() throws IOException { ArrayList<Byte> classFile = new ArrayList<>(); TestClassFileCreator.appendMagic(classFile); TestClassFileCreator.appendVersions(classFile); TestClassFileCreator.appendCount(classFile, (short) 7); TestClassFileCreator.appendFieldRef(classFile, (short) 2, (short)3); TestClassFileCreator.appendClass(classFile, (short) 4); TestClassFileCreator.appendNameAndType(classFile, (short) 5, (short) 6); TestClassFileCreator.appendUtf8(classFile, "className"); TestClassFileCreator.appendUtf8(classFile, "fieldName"); TestClassFileCreator.appendUtf8(classFile,"I"); byte[] classFileBytes = TestClassFileCreator.getByteArray(classFile); AbstractConstantPoolInfoJava[] constantPool = TestClassFileCreator.getConstantPoolFromBytes(classFileBytes); String pCode = ReferenceMethods.getPcodeForPutStatic(1, constantPool); StringBuilder expected = new StringBuilder(); PcodeTextEmitter.emitPopCat1Value(expected, ReferenceMethods.NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(expected, ReferenceMethods.STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", "1", ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(expected, PcodeTextEmitter.RAM, 4, ReferenceMethods.STATIC_OFFSET, ReferenceMethods.NEW_VALUE); assertEquals(pCode,expected.toString()); }
public static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool){ StringBuilder pCode = new StringBuilder(); String descriptor = getDescriptorForFieldRef(constantPool, index); switch (descriptor.charAt(0)){ case DescriptorDecoder.BASE_TYPE_BYTE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_BOOLEAN: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_CHAR: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_SHORT: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_ARRAY: case DescriptorDecoder.BASE_TYPE_FLOAT: case DescriptorDecoder.BASE_TYPE_INT: case DescriptorDecoder.BASE_TYPE_REFERENCE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 4, STATIC_OFFSET, NEW_VALUE); break; case DescriptorDecoder.BASE_TYPE_DOUBLE: case DescriptorDecoder.BASE_TYPE_LONG: PcodeTextEmitter.emitPopCat2Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 8, STATIC_OFFSET, NEW_VALUE); break; default: throw new IllegalArgumentException("Invalid descriptor: " + descriptor); } return pCode.toString(); }
ReferenceMethods { public static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool){ StringBuilder pCode = new StringBuilder(); String descriptor = getDescriptorForFieldRef(constantPool, index); switch (descriptor.charAt(0)){ case DescriptorDecoder.BASE_TYPE_BYTE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_BOOLEAN: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_CHAR: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_SHORT: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_ARRAY: case DescriptorDecoder.BASE_TYPE_FLOAT: case DescriptorDecoder.BASE_TYPE_INT: case DescriptorDecoder.BASE_TYPE_REFERENCE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 4, STATIC_OFFSET, NEW_VALUE); break; case DescriptorDecoder.BASE_TYPE_DOUBLE: case DescriptorDecoder.BASE_TYPE_LONG: PcodeTextEmitter.emitPopCat2Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 8, STATIC_OFFSET, NEW_VALUE); break; default: throw new IllegalArgumentException("Invalid descriptor: " + descriptor); } return pCode.toString(); } }
ReferenceMethods { public static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool){ StringBuilder pCode = new StringBuilder(); String descriptor = getDescriptorForFieldRef(constantPool, index); switch (descriptor.charAt(0)){ case DescriptorDecoder.BASE_TYPE_BYTE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_BOOLEAN: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_CHAR: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_SHORT: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_ARRAY: case DescriptorDecoder.BASE_TYPE_FLOAT: case DescriptorDecoder.BASE_TYPE_INT: case DescriptorDecoder.BASE_TYPE_REFERENCE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 4, STATIC_OFFSET, NEW_VALUE); break; case DescriptorDecoder.BASE_TYPE_DOUBLE: case DescriptorDecoder.BASE_TYPE_LONG: PcodeTextEmitter.emitPopCat2Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 8, STATIC_OFFSET, NEW_VALUE); break; default: throw new IllegalArgumentException("Invalid descriptor: " + descriptor); } return pCode.toString(); } private  ReferenceMethods(); }
ReferenceMethods { public static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool){ StringBuilder pCode = new StringBuilder(); String descriptor = getDescriptorForFieldRef(constantPool, index); switch (descriptor.charAt(0)){ case DescriptorDecoder.BASE_TYPE_BYTE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_BOOLEAN: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_CHAR: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_SHORT: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_ARRAY: case DescriptorDecoder.BASE_TYPE_FLOAT: case DescriptorDecoder.BASE_TYPE_INT: case DescriptorDecoder.BASE_TYPE_REFERENCE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 4, STATIC_OFFSET, NEW_VALUE); break; case DescriptorDecoder.BASE_TYPE_DOUBLE: case DescriptorDecoder.BASE_TYPE_LONG: PcodeTextEmitter.emitPopCat2Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 8, STATIC_OFFSET, NEW_VALUE); break; default: throw new IllegalArgumentException("Invalid descriptor: " + descriptor); } return pCode.toString(); } private  ReferenceMethods(); static String getPcodeForGetStatic(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForGetField(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForPutField(int index, AbstractConstantPoolInfoJava[] constantPool); }
ReferenceMethods { public static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool){ StringBuilder pCode = new StringBuilder(); String descriptor = getDescriptorForFieldRef(constantPool, index); switch (descriptor.charAt(0)){ case DescriptorDecoder.BASE_TYPE_BYTE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_BOOLEAN: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 1, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 1, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_CHAR: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_SHORT: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitTruncate(pCode, TEMP, 2, NEW_VALUE); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 2, STATIC_OFFSET, TEMP); break; case DescriptorDecoder.BASE_TYPE_ARRAY: case DescriptorDecoder.BASE_TYPE_FLOAT: case DescriptorDecoder.BASE_TYPE_INT: case DescriptorDecoder.BASE_TYPE_REFERENCE: PcodeTextEmitter.emitPopCat1Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 4, STATIC_OFFSET, NEW_VALUE); break; case DescriptorDecoder.BASE_TYPE_DOUBLE: case DescriptorDecoder.BASE_TYPE_LONG: PcodeTextEmitter.emitPopCat2Value(pCode, NEW_VALUE); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, STATIC_OFFSET, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(index), ConstantPoolJava.CPOOL_PUTSTATIC); PcodeTextEmitter.emitWriteToMemory(pCode, PcodeTextEmitter.RAM, 8, STATIC_OFFSET, NEW_VALUE); break; default: throw new IllegalArgumentException("Invalid descriptor: " + descriptor); } return pCode.toString(); } private  ReferenceMethods(); static String getPcodeForGetStatic(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForPutStatic(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForGetField(int index, AbstractConstantPoolInfoJava[] constantPool); static String getPcodeForPutField(int index, AbstractConstantPoolInfoJava[] constantPool);  }