@Test public void testLdcLong() throws IOException{ ArrayList<Byte> classFile = new ArrayList<>(); TestClassFileCreator.appendMagic(classFile); TestClassFileCreator.appendVersions(classFile); TestClassFileCreator.appendCount(classFile, (short) 3); TestClassFileCreator.appendLong(classFile, 0x123456789l); byte[] classFileBytes = TestClassFileCreator.getByteArray(classFile); AbstractConstantPoolInfoJava[] constantPool = TestClassFileCreator.getConstantPoolFromBytes(classFileBytes); String pCode = LdcMethods.getPcodeForLdc(1, constantPool); StringBuilder expectedPcode = new StringBuilder(); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(expectedPcode, LdcMethods.VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", "1", ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(expectedPcode, LdcMethods.VALUE); assertTrue(pCode.equals(expectedPcode.toString())); classFile.set(COUNT_LOW_BYTE, (byte) 5); TestClassFileCreator.appendLong(classFile, 0x1111111111l); classFileBytes = TestClassFileCreator.getByteArray(classFile); constantPool = TestClassFileCreator.getConstantPoolFromBytes(classFileBytes); pCode = LdcMethods.getPcodeForLdc(3, constantPool); expectedPcode = new StringBuilder(); PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(expectedPcode, LdcMethods.VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", "3", ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(expectedPcode, LdcMethods.VALUE); assertTrue(pCode.equals(expectedPcode.toString())); }
public static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool){ byte tag = constantPool[constantPoolIndex].getTag(); StringBuilder pCode = new StringBuilder(); switch (tag){ case ConstantPoolTagsJava.CONSTANT_Class: case ConstantPoolTagsJava.CONSTANT_Float: case ConstantPoolTagsJava.CONSTANT_Integer: case ConstantPoolTagsJava.CONSTANT_MethodHandle: case ConstantPoolTagsJava.CONSTANT_MethodType: case ConstantPoolTagsJava.CONSTANT_String: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC); PcodeTextEmitter.emitPushCat1Value(pCode,VALUE); break; case ConstantPoolTagsJava.CONSTANT_Double: case ConstantPoolTagsJava.CONSTANT_Long: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(pCode,VALUE); break; default: throw new IllegalArgumentException("Invalid load from constant pool: tag " + tag); } return pCode.toString(); }
LdcMethods { public static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool){ byte tag = constantPool[constantPoolIndex].getTag(); StringBuilder pCode = new StringBuilder(); switch (tag){ case ConstantPoolTagsJava.CONSTANT_Class: case ConstantPoolTagsJava.CONSTANT_Float: case ConstantPoolTagsJava.CONSTANT_Integer: case ConstantPoolTagsJava.CONSTANT_MethodHandle: case ConstantPoolTagsJava.CONSTANT_MethodType: case ConstantPoolTagsJava.CONSTANT_String: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC); PcodeTextEmitter.emitPushCat1Value(pCode,VALUE); break; case ConstantPoolTagsJava.CONSTANT_Double: case ConstantPoolTagsJava.CONSTANT_Long: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(pCode,VALUE); break; default: throw new IllegalArgumentException("Invalid load from constant pool: tag " + tag); } return pCode.toString(); } }
LdcMethods { public static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool){ byte tag = constantPool[constantPoolIndex].getTag(); StringBuilder pCode = new StringBuilder(); switch (tag){ case ConstantPoolTagsJava.CONSTANT_Class: case ConstantPoolTagsJava.CONSTANT_Float: case ConstantPoolTagsJava.CONSTANT_Integer: case ConstantPoolTagsJava.CONSTANT_MethodHandle: case ConstantPoolTagsJava.CONSTANT_MethodType: case ConstantPoolTagsJava.CONSTANT_String: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC); PcodeTextEmitter.emitPushCat1Value(pCode,VALUE); break; case ConstantPoolTagsJava.CONSTANT_Double: case ConstantPoolTagsJava.CONSTANT_Long: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(pCode,VALUE); break; default: throw new IllegalArgumentException("Invalid load from constant pool: tag " + tag); } return pCode.toString(); } private  LdcMethods(); }
LdcMethods { public static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool){ byte tag = constantPool[constantPoolIndex].getTag(); StringBuilder pCode = new StringBuilder(); switch (tag){ case ConstantPoolTagsJava.CONSTANT_Class: case ConstantPoolTagsJava.CONSTANT_Float: case ConstantPoolTagsJava.CONSTANT_Integer: case ConstantPoolTagsJava.CONSTANT_MethodHandle: case ConstantPoolTagsJava.CONSTANT_MethodType: case ConstantPoolTagsJava.CONSTANT_String: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC); PcodeTextEmitter.emitPushCat1Value(pCode,VALUE); break; case ConstantPoolTagsJava.CONSTANT_Double: case ConstantPoolTagsJava.CONSTANT_Long: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(pCode,VALUE); break; default: throw new IllegalArgumentException("Invalid load from constant pool: tag " + tag); } return pCode.toString(); } private  LdcMethods(); static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool); }
LdcMethods { public static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool){ byte tag = constantPool[constantPoolIndex].getTag(); StringBuilder pCode = new StringBuilder(); switch (tag){ case ConstantPoolTagsJava.CONSTANT_Class: case ConstantPoolTagsJava.CONSTANT_Float: case ConstantPoolTagsJava.CONSTANT_Integer: case ConstantPoolTagsJava.CONSTANT_MethodHandle: case ConstantPoolTagsJava.CONSTANT_MethodType: case ConstantPoolTagsJava.CONSTANT_String: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 4, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC); PcodeTextEmitter.emitPushCat1Value(pCode,VALUE); break; case ConstantPoolTagsJava.CONSTANT_Double: case ConstantPoolTagsJava.CONSTANT_Long: PcodeTextEmitter.emitAssignVarnodeFromPcodeOpCall(pCode, VALUE, 8, ConstantPoolJava.CPOOL_OP, "0", Integer.toString(constantPoolIndex),ConstantPoolJava.CPOOL_LDC2_W); PcodeTextEmitter.emitPushCat2Value(pCode,VALUE); break; default: throw new IllegalArgumentException("Invalid load from constant pool: tag " + tag); } return pCode.toString(); } private  LdcMethods(); static String getPcodeForLdc(int constantPoolIndex, AbstractConstantPoolInfoJava[] constantPool);  }