diff --git a/.gitattributes b/.gitattributes index 744bbaafd5658922f472f44e7c0f644c9be9cbbd..9e2ff2e433aa87490a2ea74391219ab1bdb911f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -201,6 +201,7 @@ libIRDB/LICENSE.txt -text libIRDB/Makefile.in -text libIRDB/SConscript -text libIRDB/SConstruct -text +libIRDB/include/bea_deprecated.hpp -text libIRDB/include/cfg/BasicBlock.hpp -text libIRDB/include/cfg/CFG.hpp -text libIRDB/include/cfg/callgraph.hpp -text @@ -1009,7 +1010,6 @@ third_party/do_bea_update.sh -text third_party/elfio-2.2.tar.gz -text third_party/elfio.hpp -text third_party/sqlite-autoconf-3071300.tar.gz -text -tools/Makefile.in -text tools/SConscript -text tools/SConstruct -text tools/absolutify/SConscript -text @@ -1119,7 +1119,6 @@ tools/inferfn/SConstruct -text tools/inferfn/inferfn.cpp -text tools/inferfn/inferfn.hpp -text tools/inferfn/inferfn_driver.cpp -text -tools/meds2pdb/Makefile.in -text tools/meds2pdb/SConscript -text tools/meds2pdb/SConstruct -text tools/meds2pdb/meds2pdb.cpp -text diff --git a/SConstruct b/SConstruct index ba6529c53d1501b0a951fa85f950b6e4b231c579..d83d889a3cea93658f447d0b970c98d80ead75ba 100644 --- a/SConstruct +++ b/SConstruct @@ -27,9 +27,9 @@ env.Replace(build_cgc=ARGUMENTS.get("build_cgc", 0)) if int(env['debug']) == 1: print "Setting debug mode" - env.Append(CFLAGS=" -g ") - env.Append(CXXFLAGS=" -g ") - env.Append(LINKFLAGS=" -g ") + env.Append(CFLAGS=" -Og -g ") + env.Append(CXXFLAGS=" -Og -g ") + env.Append(LINKFLAGS=" -Og -g ") else: print "Setting release mode" env.Append(CFLAGS=" -O3 ") diff --git a/beaengine/beaengineSources/Includes/instr_set/Data_opcode.h b/beaengine/beaengineSources/Includes/instr_set/Data_opcode.h index bc6437996bb440ae252b07fe6fd5764649a049db..7d482a4f04c3fcf5c0b84130521ef345e1c575e2 100644 --- a/beaengine/beaengineSources/Includes/instr_set/Data_opcode.h +++ b/beaengine/beaengineSources/Includes/instr_set/Data_opcode.h @@ -92,10 +92,10 @@ void (__bea_callspec__ *opcode_map2[])(PDISASM) = { /*9*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, fmaddsub132p,fmsubadd132p,fmadd132p, fmadd132s , fmsub132p, fmsub132s, fnmadd132p, fnmadd132s, fnmsub132p, fnmsub132s, /*a*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, fmaddsub213p,fmsubadd213p,fmadd213p, fmadd213s , fmsub213p, fmsub213s, fnmadd213p, fnmadd213s, fnmsub213p, fnmsub213s, /*b*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, fmaddsub231p,fmsubadd231p,fmadd231p, fmadd231s , fmsub231p, fmsub231s, fnmadd231p, fnmadd231s, fnmsub231p, fnmsub231s, -/*c*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*c*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, sha1nexte, sha1msg1, sha1msg2, sha256rnds2,sha256msg1, sha256msg2, FailDecode, FailDecode, /*d*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, aesimc , aesenc , aesenclast, aesdec , aesdeclast, /*e*/FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, -/*e*/crc32_GvEb, crc32_GvEv, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*f*/crc32_GvEb, crc32_GvEv, andn , blsi , FailDecode, bzhi , mulx , bextr , FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, }; /* =============================================================================== */ @@ -110,7 +110,7 @@ void (__bea_callspec__ *opcode_map2[])(PDISASM) = { /*0*/ FailDecode, FailDecode, FailDecode, FailDecode, vpermilps2, FailDecode, vperm2f128, FailDecode, roundps_ , roundpd_ , roundss_ , roundsd_ , blendps_ , blendpd_ , pblendw_ , palignr_ , /*1*/ FailDecode, FailDecode, FailDecode, FailDecode, pextrb_ , pextrw2_ , pextrd_ , extractps_, vinsrtf128, vextraf128, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, /*2*/ pinsrb_ , insertps_ , pinsrd_ , FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, -/*3*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*3*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, vinsrti128, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, /*4*/ dpps_ , dppd_ , mpsadbw_ , FailDecode, pclmulqdq_, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, vblendvpd , FailDecode, FailDecode, FailDecode, FailDecode, /*5*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, vfmaddsubps,vfmaddsubpd,vfmsubaddps,vfmsubaddpd, /*6*/ pcmpestrm_, pcmpestri_, pcmpistrm_, pcmpistri_, FailDecode, FailDecode, FailDecode, FailDecode, vfmaddps , vfmaddpd , vfmaddss , vfmaddsd , vfmsubps , vfmsubpd , vfmsubss , vfmsubsd , @@ -119,10 +119,39 @@ void (__bea_callspec__ *opcode_map2[])(PDISASM) = { /*9*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, /*a*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, /*b*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, -/*c*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*c*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, sha1rnds4, FailDecode, FailDecode, FailDecode, /*d*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, aeskeygen , /*e*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, -/*f*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*f*/ rorx , FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, sarx, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, + }; + +// =============================================================================== +// +// +// opcode map for XOP extensions that start with a "xop" prefix (identical to vex, +// except first byte is 8f). +// where XOP.mmmmm==8 +// +// +// =============================================================================== + void (__bea_callspec__ *opcode_map_xop_mm8[])(PDISASM) = { +// 0 1 2 3 4 5 6 7 8 9 a b c d e f +/*0*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*1*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*2*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*3*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*4*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*5*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*6*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*7*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*8*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*9*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*a*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*b*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*c*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*d*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*e*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, +/*f*/ FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode, FailDecode }; diff --git a/beaengine/beaengineSources/Includes/instr_set/opcodes_A_M.c b/beaengine/beaengineSources/Includes/instr_set/opcodes_A_M.c index c821f0583bd9c6d27862853c41cce0e7794daa4f..a82e6987eee5ad661ff563aa5626f0756e13d660 100644 --- a/beaengine/beaengineSources/Includes/instr_set/opcodes_A_M.c +++ b/beaengine/beaengineSources/Includes/instr_set/opcodes_A_M.c @@ -990,12 +990,23 @@ void __bea_callspec__ bswap_edi(PDISASM pMyDisasm) * ======================================= */ void __bea_callspec__ bsf_GvEv(PDISASM pMyDisasm) { - (*pMyDisasm).Instruction.Category = GENERAL_PURPOSE_INSTRUCTION+BIT_UInt8; - #ifndef BEA_LIGHT_DISASSEMBLY - (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "bsf "); - #endif - GvEv(pMyDisasm); - FillFlags(pMyDisasm,9); + if ((*pMyDisasm).Prefix.RepPrefix == InUsePrefix) + { + (*pMyDisasm).Prefix.RepPrefix = InvalidPrefix; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "tzcnt "); + #endif + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + } + else + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "bsf "); + #endif + (*pMyDisasm).Instruction.Category = GENERAL_PURPOSE_INSTRUCTION+BIT_UInt8; + } + GvEv(pMyDisasm); + FillFlags(pMyDisasm,9); } /* ======================================= diff --git a/beaengine/beaengineSources/Includes/instr_set/opcodes_N_Z.c b/beaengine/beaengineSources/Includes/instr_set/opcodes_N_Z.c index 66d7c1cf62ffe7977099b3c12606d16d8caecf0b..64a8995b37377a9a0bfd94cc9720a1f047c1f72b 100644 --- a/beaengine/beaengineSources/Includes/instr_set/opcodes_N_Z.c +++ b/beaengine/beaengineSources/Includes/instr_set/opcodes_N_Z.c @@ -455,7 +455,7 @@ void __bea_callspec__ pop_Ev(PDISASM pMyDisasm) } } else { - FailDecode(pMyDisasm); + HandleXop3(pMyDisasm); } } diff --git a/beaengine/beaengineSources/Includes/instr_set/opcodes_VEX.c b/beaengine/beaengineSources/Includes/instr_set/opcodes_VEX.c index a7510e31a799c8c797bf742bfbafe483a1a77c51..d9cc1435f65d7b86c02d4b34223f06789b6d0d58 100644 --- a/beaengine/beaengineSources/Includes/instr_set/opcodes_VEX.c +++ b/beaengine/beaengineSources/Includes/instr_set/opcodes_VEX.c @@ -151,7 +151,7 @@ Byte 0 1 1 0 0 0 1 0 0 Byte 1 RÌ… XÌ… BÌ… m4 m3 m2 m1 m0 Byte 2 W vÌ…3 vÌ…2 vÌ…1 vÌ…0 L p1 p0 * ==================================================================== */ -void __bea_callspec__ HandleVex3(PDISASM pMyDisasm) +void __bea_callspec__ ParseVex3(PDISASM pMyDisasm) { UInt8 byte1=0, byte2=0; @@ -196,7 +196,11 @@ void __bea_callspec__ HandleVex3(PDISASM pMyDisasm) finish_vex(pMyDisasm); +} +void __bea_callspec__ HandleVex3(PDISASM pMyDisasm) +{ + ParseVex3(pMyDisasm); /* dispatch to the right table, depending on the vex opcode_escape value */ switch(GV.VEX.opcode_escape) @@ -218,6 +222,23 @@ void __bea_callspec__ HandleVex3(PDISASM pMyDisasm) } } +void __bea_callspec__ HandleXop3(PDISASM pMyDisasm) +{ + ParseVex3(pMyDisasm); + + /* dispatch to the right table, depending on the vex opcode_escape value */ + (*pMyDisasm).Instruction.Opcode = *((UInt8*) (UIntPtr)GV.EIP_)+0x8f00+GV.VEX.opcode_escape; + switch(GV.VEX.opcode_escape) + { + case 8: + opcode_map_xop_mm8[*((UInt8*) (UIntPtr)GV.EIP_)](pMyDisasm); + break; + default: + assert(0); + FailDecode(pMyDisasm); + } +} + /* ==================================================================== * 0x c5 @@ -285,17 +306,31 @@ void V_reg(ARGTYPE* arg, PDISASM pMyDisasm) if(GV.OperandSize==128 || GV.SSE_) { - #ifndef BEA_LIGHT_DISASSEMBLY - (void) strcpy((char*) arg->ArgMnemonic, RegistersSSE[reg]); - #endif - arg->ArgType+=SSE_REG; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy((char*) arg->ArgMnemonic, RegistersSSE[reg]); + #endif + arg->ArgType+=SSE_REG; } else if(GV.OperandSize==256 || GV.AVX_) { - #ifndef BEA_LIGHT_DISASSEMBLY - (void) strcpy((char*) arg->ArgMnemonic, RegistersAVX[reg]); - #endif - arg->ArgType+=AVX_REG; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy((char*) arg->ArgMnemonic, RegistersAVX[reg]); + #endif + arg->ArgType+=AVX_REG; + } + else if(GV.OperandSize==32) + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy((char*) arg->ArgMnemonic, Registers32Bits[reg]); + #endif + arg->ArgType+=GENERAL_REG; + } + else if(GV.OperandSize==64) + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy((char*) arg->ArgMnemonic, Registers64Bits[reg]); + #endif + arg->ArgType+=GENERAL_REG; } else { @@ -635,7 +670,12 @@ void vextraf128 (PDISASM pMyDisasm) /* 0f 3a 18 */ void vinsrtf128 (PDISASM pMyDisasm) { - helperf128(pMyDisasm, "vinsertf128 ", 0); + helperf128(pMyDisasm, "vinsertf128 ", 0); +} + +void vinsrti128 (PDISASM pMyDisasm) +{ + helperf128(pMyDisasm, "vinserti128 ", 0); } /* 0f 3a 06 */ @@ -970,3 +1010,378 @@ void vfnmsubss(PDISASM pMyDisasm) } +// VEX.NDS.LZ.0F38.W0 F5 /r BZHI r32a, r/m32, r32b +void __bea_callspec__ bzhi(PDISASM pMyDisasm) // bzhi +{ + + if(GV.REX.W_==0) + { + GV.MemDecoration=Arg2dword; + } + else + { + GV.MemDecoration=Arg2qword; + } + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "mulx "); + #endif + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + V_reg( &(*pMyDisasm).Argument1, pMyDisasm); + MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm); + Reg_Opcode(&(*pMyDisasm).Argument3, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; + GV.third_arg=1; + + +} + +void __bea_callspec__ mulx(PDISASM pMyDisasm) +{ + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "mulx "); + #endif + + GV.OperandSize=32+32*GV.REX.W_; + GV.MemDecoration = GV.OperandSize==32 ? Arg3dword : Arg3qword; + + V_reg(&(*pMyDisasm).Argument2, pMyDisasm); + GV.OperandSize=GV.OriginalOperandSize; + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.third_arg=1; + Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; +} + +// VEX.NDS.LZ.F2.0F38.W0 F5 /r PDEP r32a, r32b, r/m32 +void __bea_callspec__ pdep(PDISASM pMyDisasm) // pdep +{ + if(GV.PrefRepe == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==2) ) // f3 prefix + return pext(pMyDisasm); + else if(GV.PrefRepne == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==3)) // f2 prefix + { + + if(GV.REX.W_==0) + { + GV.MemDecoration=Arg3dword; + } + else + { + GV.MemDecoration=Arg3qword; + } + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "pdep "); + #endif + V_reg( &(*pMyDisasm).Argument1, pMyDisasm); + Reg_Opcode(&(*pMyDisasm).Argument2, pMyDisasm); + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; + GV.third_arg=1; + + } + else + FailDecode(pMyDisasm); + + +} +void __bea_callspec__ pext(PDISASM pMyDisasm) // pext +{ + if(GV.PrefRepe == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==2) ) // f3 prefix + { + // OK + if(GV.REX.W_==0) + { + GV.MemDecoration=Arg3dword; + } + else + { + GV.MemDecoration=Arg3qword; + } + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "pext "); + #endif + V_reg( &(*pMyDisasm).Argument1, pMyDisasm); + Reg_Opcode(&(*pMyDisasm).Argument2, pMyDisasm); + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; + GV.third_arg=1; + } + else + FailDecode(pMyDisasm); + +} + +void __bea_callspec__ rorx(PDISASM pMyDisasm) // rorx +{ + if(GV.PrefRepne == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==3)) // f2 prefix + { + if(GV.REX.W_==0) + { + GV.OperandSize = 32; + GV.MemDecoration=Arg2dword; + } + else + { + GV.OperandSize = 64; + GV.MemDecoration=Arg2qword; + } + (*pMyDisasm).Prefix.RepnePrefix = MandatoryPrefix; + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "rorx "); + #endif + Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm); + MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2+1; + GV.third_arg=1; + if (!Security(0, pMyDisasm)) { FailDecode(pMyDisasm); return; } + GV.third_arg = 1; + (*pMyDisasm).Instruction.Immediat = *((UInt8*)(UIntPtr) (GV.EIP_- 1)); + #ifndef BEA_LIGHT_DISASSEMBLY + (void) CopyFormattedNumber(pMyDisasm, (char*) (*pMyDisasm).Argument3.ArgMnemonic, "%.2X",(Int64) *((UInt8*)(UIntPtr) (GV.EIP_- 1))); + #endif + (*pMyDisasm).Argument3.ArgType = CONSTANT_TYPE+ABSOLUTE_; + (*pMyDisasm).Argument3.ArgSize = 8; + } + else + FailDecode(pMyDisasm); +} +void __bea_callspec__ sarx(PDISASM pMyDisasm) // sarx +{ + if ((*pMyDisasm).Prefix.OperandSize == InUsePrefix || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==1)) // 66 prefix + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "sarx "); + #endif + } + else if(GV.PrefRepne == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==3)) // f2 prefix + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "shlx "); + #endif + } + else if(GV.PrefRepe == 1 || (GV.VEX.has_vex && GV.VEX.implicit_prefixes==2)) // f3 prefix + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "shrx "); + #endif + } + else + FailDecode(pMyDisasm); + + + if(GV.REX.W_==0) + { + GV.MemDecoration=Arg2dword; + } + else + { + GV.MemDecoration=Arg2qword; + } + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + V_reg( &(*pMyDisasm).Argument1, pMyDisasm); + MOD_RM(&(*pMyDisasm).Argument2, pMyDisasm); + Reg_Opcode(&(*pMyDisasm).Argument3, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; + GV.third_arg=1; + +} +void __bea_callspec__ shrx(PDISASM pMyDisasm) // shrx +{ + assert(0); +} +void __bea_callspec__ shlx(PDISASM pMyDisasm) // shlx +{ + assert(0); +} + +void __bea_callspec__ sha1rnds4(PDISASM pMyDisasm) // sha1rnds4 +{ + GV.OperandSize = GV.OriginalOperandSize; + (*pMyDisasm).Prefix.OperandSize = MandatoryPrefix; + GV.MemDecoration = Arg2dqword; + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "sha1rnds4 "); + #endif + GV.ImmediatSize = 8; + GV.SSE_ = 1; + GxEx(pMyDisasm); + GV.SSE_ = 0; + GV.EIP_++; + if (!Security(0, pMyDisasm)) return; + GV.third_arg = 1; + (*pMyDisasm).Instruction.Immediat = *((UInt8*)(UIntPtr) (GV.EIP_- 1)); + #ifndef BEA_LIGHT_DISASSEMBLY + (void) CopyFormattedNumber(pMyDisasm, (char*) (*pMyDisasm).Argument3.ArgMnemonic, "%.2X",(Int64) *((UInt8*)(UIntPtr) (GV.EIP_- 1))); + #endif + (*pMyDisasm).Argument3.ArgType = CONSTANT_TYPE+ABSOLUTE_; + (*pMyDisasm).Argument3.ArgSize = 8; +} +void __bea_callspec__ sha1_helper(PDISASM pMyDisasm, const char* mnemonic) // sha1nextE +{ + GV.OperandSize = GV.OriginalOperandSize; + (*pMyDisasm).Prefix.OperandSize = MandatoryPrefix; + GV.MemDecoration = Arg2dqword; + (*pMyDisasm).Instruction.Category = SSE41_INSTRUCTION+PACKED_BLENDING_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, mnemonic); + #endif + GV.SSE_ = 1; + GxEx(pMyDisasm); + GV.SSE_ = 0; +} +void __bea_callspec__ sha1nexte(PDISASM pMyDisasm) // sha1nextE +{ + sha1_helper(pMyDisasm,"sha1nexte "); +} +void __bea_callspec__ sha1msg1(PDISASM pMyDisasm) // sha1msg1 +{ + sha1_helper(pMyDisasm,"sha1msg1 "); +} +void __bea_callspec__ sha1msg2(PDISASM pMyDisasm) // sha1msg2 +{ + sha1_helper(pMyDisasm,"sha1msg2 "); +} +void __bea_callspec__ sha256rnds2(PDISASM pMyDisasm) // ha256rnds2 +{ + sha1_helper(pMyDisasm,"sha256rnds2 "); + GV.third_arg=1; + GV.SSE_ = 1; + implicit_xmm0(&(*pMyDisasm).Argument3,pMyDisasm); + GV.SSE_ = 0; +} +void __bea_callspec__ sha256msg1(PDISASM pMyDisasm) // sha256msg1 +{ + sha1_helper(pMyDisasm,"sha256msg1 "); +} +void __bea_callspec__ sha256msg2(PDISASM pMyDisasm) // sha256msg2 +{ + sha1_helper(pMyDisasm,"sha256msg2 "); +} + + +// BMI1 (bit manip. instr set 1) + + +//VEX.NDS.LZ.0F38.W0 F2 /r ANDN r32a, r32b, r/m32 RVM V/V BMI1 Bitwise AND of inverted r32b with r/m32, store result in r32a. +//VEX.NDS.LZ.0F38.W1 F2 /r ANDN r64a, r64b, r/m64 RVM V/NE BMI1 Bitwise AND of inverted r64b with r/m64, store result in r64a. +void __bea_callspec__ andn(PDISASM pMyDisasm) +{ + if(GV.VEX.length != 0) + { + FailDecode(pMyDisasm); + return; + } + + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "andn "); + #endif + + GV.OperandSize=32+32*GV.REX.W_; + GV.MemDecoration = GV.OperandSize==32 ? Arg3dword : Arg3qword; + + V_reg(&(*pMyDisasm).Argument2, pMyDisasm); + GV.OperandSize=GV.OriginalOperandSize; + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.third_arg=1; + Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; + +} + +// VEX.NDS.LZ.0F38.W0 F7 /r BEXTR r32a, r/m32, r32b RMV V/V BMI1 Contiguous bitwise extract from r/m32 using r32b as control; store result in r32a. +// VEX.NDS.LZ.0F38.W1 F7 /r BEXTR r64a, r/m64, r64b +void __bea_callspec__ bextr(PDISASM pMyDisasm) +{ + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "bextr "); + #endif + + if(GV.VEX.length != 0) + { + FailDecode(pMyDisasm); + return; + } + + GV.OperandSize=32+32*GV.REX.W_; + GV.MemDecoration = GV.OperandSize==32 ? Arg3dword : Arg3qword; + + V_reg(&(*pMyDisasm).Argument2, pMyDisasm); + GV.OperandSize=GV.OriginalOperandSize; + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.third_arg=1; + Reg_Opcode(&(*pMyDisasm).Argument1, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; +} + +//VEX.NDD.LZ.0F38.W0 F3 /3 BLSI r32, r/m32 VM V/V BMI1 Extract lowest set bit from r/m32 and set that bit in r32. +//VEX.NDD.LZ.0F38.W1 F3 /3 BLSI r64, r/m64 +void __bea_callspec__ blsi(PDISASM pMyDisasm) +{ + if (GV.REGOPCODE == 1) // blsr + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "blsr "); + #endif + } + else if (GV.REGOPCODE == 2) // blsmsk + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "blsmsk "); + #endif + } + else if (GV.REGOPCODE == 3) // blsi + { + #ifndef BEA_LIGHT_DISASSEMBLY + (void) strcpy ((*pMyDisasm).Instruction.Mnemonic, "blsi "); + #endif + } + else + { + FailDecode(pMyDisasm); + return; + } + + (*pMyDisasm).Instruction.Category = AVX_INSTRUCTION; + + if(GV.VEX.length != 0) + { + FailDecode(pMyDisasm); + return; + } + + GV.OperandSize=32+32*GV.REX.W_; + GV.MemDecoration = GV.OperandSize==32 ? Arg2dword : Arg2qword; + V_reg(&(*pMyDisasm).Argument1, pMyDisasm); + GV.OperandSize=GV.OriginalOperandSize; + MOD_RM(&(*pMyDisasm).Argument3, pMyDisasm); + GV.EIP_ += GV.DECALAGE_EIP+2; +} + +//VEX.NDD.LZ.0F38.W0 F3 /2 BLSMSK r32, r/m32 VM V/V BMI1 Set all lower bits in r32 to “1†starting from bit 0 to lowest set bit in r/m32. +//VEX.NDD.LZ.0F38.W1 F3 /2 BLSMSK r64, r/m64 VM V/N.E. BMI1 Set all lower bits in r64 to “1†starting from bit 0 to lowest set bit in r/m64. +void __bea_callspec__ blsmsk(PDISASM pMyDisasm) +{ + assert (0); // see blsi +} + +//VEX.NDD.LZ.0F38.W0 F3 /1 BLSR r32, r/m32 VM V/V BMI1 Reset lowest set bit of r/m32, keep all other bits of r/m32 and write result to r32. +//VEX.NDD.LZ.0F38.W1 F3 /1 BLSR r64, r/m64 VM V/N.E. BMI1 Reset lowest set bit of r/m64, keep all other bits of r/m64 and write result to r64. +void __bea_callspec__ blsr(PDISASM pMyDisasm) +{ + assert (0); // see blsi +} + +//F3 0F BC /r TZCNT r16, r/m16 RM V/V BMI1 Count the number of trailing zero bits in r/m16, return result in r16. +//F3 0F BC /r TZCNT r32, r/m32 RM V/V BMI1 Count the number of trailing zero bits in r/m32, return result in r32. +//F3 REX.W 0F BC /r TZCNT r64, r/m64 RM V/N.E. BMI1 Count the number of trailing zero bits in r/m64, return result in r64. +void __bea_callspec__ tzcnt(PDISASM pMyDisasm) +{ + // see bsf +} + diff --git a/beaengine/beaengineSources/Includes/protos.h b/beaengine/beaengineSources/Includes/protos.h index 512688bcf797c4b357886ef4ac0f1757ab4387f8..701f1feec87a53dd3304e826dcefc359f4ac1a61 100644 --- a/beaengine/beaengineSources/Includes/protos.h +++ b/beaengine/beaengineSources/Includes/protos.h @@ -713,22 +713,61 @@ void __bea_callspec__ pclmulqdq_(PDISASM); /* prefixes */ void __bea_callspec__ HandleVex2(PDISASM); void __bea_callspec__ HandleVex3(PDISASM); +void __bea_callspec__ HandleXop3(PDISASM); /* useful helpers */ void V_reg(ARGTYPE* arg, PDISASM pMyDisasm); void L_imm(ARGTYPE* arg, PDISASM pMyDisasm); -/* actual opcodes */ + + +// AVX (part 1, aka AVX-128) +void vbrdcstss (PDISASM pMyDisasm); // vbroadcastss +void vbrdcstsd (PDISASM pMyDisasm); // vbroadcastsd +// vbroadcastf128 +void vinsrtf128 (PDISASM pMyDisasm); // vinsertf128 +void vextraf128 (PDISASM pMyDisasm); +// vmaskmovps +// vmaskmovpd +void vpermilps1 (PDISASM pMyDisasm); // vpermilps +void vpermilps2 (PDISASM pMyDisasm); // vpermilps +// vpermilpd +void vperm2f128 (PDISASM pMyDisasm); // vperm2f128 +// vzeroall +// vzeroupper + + +// avx (part 2, aka avx2 aka avx 256?) +// vbroadcastss +// vbroadcastsd +// vpbroadcastb +// vpbroadcastw +// vpbroadcastd +// vpbroadcastq +// vpbroadcastI128 +void vinsrti128 (PDISASM pMyDisasm); // vinserti128 +// vgatherdpd +// vgatherqpd +// vgatherrqd +// vgatherdqq +// vmaskmovd +// vmaskmovq +// vpermps +// vpermd +// vpermpd +// vpermq +// vperm2i128 +// vblendd +// vpsllvd +// vpsllvq +// vpsrlvd +// vpsrlvq +// vpsravd + + void vblendvpd /*VxHxWxLx */ (PDISASM pMyDisasm); void three_dnow_ (PDISASM pMyDisasm); -void vbrdcstss (PDISASM pMyDisasm); -void vbrdcstsd (PDISASM pMyDisasm); -void vextraf128 (PDISASM pMyDisasm); -void vinsrtf128 (PDISASM pMyDisasm); -void vperm2f128 (PDISASM pMyDisasm); -void vpermilps1 (PDISASM pMyDisasm); -void vpermilps2 (PDISASM pMyDisasm); void fmadd132sd(PDISASM pMyDisasm); void fmadd213sd(PDISASM pMyDisasmd); void fmadd231sd(PDISASM pMyDisasmd); @@ -795,3 +834,53 @@ void fnmadd231s(PDISASM pMyDisasm); void fnmsub132s(PDISASM pMyDisasm); void fnmsub213s(PDISASM pMyDisasm); void fnmsub231s(PDISASM pMyDisasm); + + +// Intel ADX +// adcx +// ad0x + +//ABM (advance bit manipulation) +// popcnt +// lzcnt + +// BMI1 (bit manip. instr set 1) +void __bea_callspec__ andn(PDISASM pMyDisasm); // andn +void __bea_callspec__ bextr(PDISASM pMyDisasm); // blsi +void __bea_callspec__ blsi(PDISASM pMyDisasm); // blsi +void __bea_callspec__ blsmsk(PDISASM pMyDisasm); // blsmsk +void __bea_callspec__ blsr(PDISASM pMyDisasm); // blsr +void __bea_callspec__ tzcnt(PDISASM pMyDisasm); // tzcnt + +// BMI2 +void __bea_callspec__ bzhi(PDISASM pMyDisasm); // bzhi +void __bea_callspec__ mulx(PDISASM pMyDisasm); // mulx +void __bea_callspec__ pdep(PDISASM pMyDisasm); // pdep +void __bea_callspec__ pext(PDISASM pMyDisasm); // pext +void __bea_callspec__ rorx(PDISASM pMyDisasm); // rorx +void __bea_callspec__ sarx(PDISASM pMyDisasm); // sarx +void __bea_callspec__ shrx(PDISASM pMyDisasm); // shrx +void __bea_callspec__ shlx(PDISASM pMyDisasm); // shlx + + +// TBM (trailing bit manipulation +// bextr +// blcfill +// blci +// blcic +// blcmsk +// blcs +// blsfill +// blsic +// t1mskc +// tzmsk + + +// SHA extensions +void __bea_callspec__ sha1rnds4(PDISASM pMyDisasm); // sha1rnds4 +void __bea_callspec__ sha1nexte(PDISASM pMyDisasm); // sha1nextE +void __bea_callspec__ sha1msg1(PDISASM pMyDisasm); // sha1msg1 +void __bea_callspec__ sha1msg2(PDISASM pMyDisasm); // sha1msg2 +void __bea_callspec__ sha256rnds2(PDISASM pMyDisasm); // ha256rnds2 +void __bea_callspec__ sha256msg1(PDISASM pMyDisasm); // sha256msg1 +void __bea_callspec__ sha256msg2(PDISASM pMyDisasm); // sha256msg2 diff --git a/libIRDB/include/bea_deprecated.hpp b/libIRDB/include/bea_deprecated.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6868f1cd1118fe8b01c7c972a49f5191157192cd --- /dev/null +++ b/libIRDB/include/bea_deprecated.hpp @@ -0,0 +1,52 @@ +#ifndef bea_deprecated_h +#define bea_deprecated_h + + +#include <libIRDB-core.hpp> +#include <beaengine/BeaEngine.h> + + +static inline int Disassemble(const libIRDB::Instruction_t* const insn, DISASM &disasm) +{ + assert(insn); + memset(&disasm, 0, sizeof(DISASM)); + disasm.Options = NasmSyntax + PrefixedNumeral; + disasm.Archi = libIRDB::FileIR_t::GetArchitectureBitWidth(); + disasm.EIP = (UIntPtr) insn->GetDataBits().c_str(); + disasm.VirtualAddr = insn->GetAddress()->GetVirtualOffset(); + int instr_len = Disasm(&disasm); + return instr_len; +} + +static inline bool SetsStackPointer(const ARGTYPE* arg) +{ + if((arg->AccessMode & WRITE ) == 0) + return false; + int access_type=arg->ArgType; + + if(access_type==REGISTER_TYPE + GENERAL_REG +REG4) + return true; + return false; + +} + +static inline bool SetsStackPointer(const DISASM* disasm) +{ + if(strstr(disasm->Instruction.Mnemonic, "push")!=NULL) + return true; + if(strstr(disasm->Instruction.Mnemonic, "pop")!=NULL) + return true; + if(strstr(disasm->Instruction.Mnemonic, "call")!=NULL) + return true; + if(disasm->Instruction.ImplicitModifiedRegs==REGISTER_TYPE+GENERAL_REG+REG4) + return true; + + if(SetsStackPointer(&disasm->Argument1)) return true; + if(SetsStackPointer(&disasm->Argument2)) return true; + if(SetsStackPointer(&disasm->Argument3)) return true; + + return false; + +} + +#endif diff --git a/libIRDB/include/cfg/callgraph.hpp b/libIRDB/include/cfg/callgraph.hpp index ea9a6c1e506b3bfdc6da4dd22ba300b91d6f83db..7403cfdd4f6da77c985b4ee206a3cd7d34d156e3 100644 --- a/libIRDB/include/cfg/callgraph.hpp +++ b/libIRDB/include/cfg/callgraph.hpp @@ -21,8 +21,6 @@ #ifndef irdb_cfg_callgraph_h #define irdb_cfg_callgraph_h -#include <sstream> - // only one type of hell node for now, but leave // open the possibilty for multiple hell nodes typedef enum { DEFAULT_HELL_NODE = 0 } HellNodeType; diff --git a/libIRDB/include/core/address.hpp b/libIRDB/include/core/address.hpp index b1e0da67da7ddfb6a24184712078c02581438f0e..e0f7e17dff225861985c5293155f10a3f7874b93 100644 --- a/libIRDB/include/core/address.hpp +++ b/libIRDB/include/core/address.hpp @@ -18,7 +18,6 @@ * */ -#include <stdint.h> // // An address in a variant. diff --git a/libIRDB/include/core/baseobj.hpp b/libIRDB/include/core/baseobj.hpp index 20b41051039dfb63eb4d71cce46dd8589b257c4b..05f690020fe95b0a6395900bfd73399e1c961ad6 100644 --- a/libIRDB/include/core/baseobj.hpp +++ b/libIRDB/include/core/baseobj.hpp @@ -19,9 +19,6 @@ */ -#include <stdint.h> -#include <set> - typedef uintptr_t virtual_offset_t; typedef int db_id_t; diff --git a/libIRDB/include/core/basetypes.hpp b/libIRDB/include/core/basetypes.hpp index c458d202f4f11ee16a6691d57b3acd3dffabe9e3..d47084900d2c1bf6e2dc5faad42bd02d4cc680e8 100644 --- a/libIRDB/include/core/basetypes.hpp +++ b/libIRDB/include/core/basetypes.hpp @@ -18,8 +18,6 @@ * */ -#include <stdint.h> - typedef uintptr_t virtual_offset_t; typedef int db_id_t; typedef int schema_version_t; diff --git a/libIRDB/include/core/instruction.hpp b/libIRDB/include/core/instruction.hpp index e9e771652bb50b11c5cb7b83a9465bd61ebe3861..52d67b746180b7af60409dbd343c6896c2fefd01 100644 --- a/libIRDB/include/core/instruction.hpp +++ b/libIRDB/include/core/instruction.hpp @@ -65,14 +65,14 @@ class Instruction_t : public BaseObj_t void WriteToDB() { assert(0); } std::vector<std::string> WriteToDB(File_t *fid, db_id_t newid); - int Disassemble(DISASM &d) const; + // int Disassemble(DISASM &d) const; std::string getDisassembly() const; bool Assemble(std::string assembly); bool IsFunctionExit() const; - static bool SetsStackPointer(DISASM *disasm); - static bool SetsStackPointer(ARGTYPE* arg); + //static bool SetsStackPointer(DISASM *disasm); + //static bool SetsStackPointer(ARGTYPE* arg); bool IsSyscall() { return getDisassembly().find("int 0x80") != std::string::npos; } diff --git a/libIRDB/include/libIRDB-core.hpp b/libIRDB/include/libIRDB-core.hpp index 42ee966f8eafc1315e39de3b52c3f4b3532c6caf..921894014214e6692ad4d71482d06d7b161f7672 100644 --- a/libIRDB/include/libIRDB-core.hpp +++ b/libIRDB/include/libIRDB-core.hpp @@ -28,8 +28,8 @@ #include <string.h> #include <iostream> #include <pqxx/pqxx> -#include <beaengine/BeaEngine.h> #include <ctime> +#include <stdint.h> namespace libIRDB { diff --git a/libIRDB/include/libIRDB-syscall.hpp b/libIRDB/include/libIRDB-syscall.hpp index 5eb8ba381484c5a8751b8e14e1f2bb307c40dee4..e97d812316fd07b23b465aadcc2ed79ee24913e9 100644 --- a/libIRDB/include/libIRDB-syscall.hpp +++ b/libIRDB/include/libIRDB-syscall.hpp @@ -33,9 +33,8 @@ namespace libIRDB { - #include <syscall/syscall.hpp> - }; + #endif diff --git a/libIRDB/src/cfg/BasicBlock.cpp b/libIRDB/src/cfg/BasicBlock.cpp index fc60fda3bd5273ef06f5401a0e29afc87caa671c..995873eb074718a11b661cc2b2497917daaa86d3 100644 --- a/libIRDB/src/cfg/BasicBlock.cpp +++ b/libIRDB/src/cfg/BasicBlock.cpp @@ -23,6 +23,7 @@ #include <libIRDB-core.hpp> #include <libIRDB-cfg.hpp> #include <utils.hpp> +#include <bea_deprecated.hpp> using namespace libIRDB; using namespace std; @@ -168,7 +169,7 @@ bool BasicBlock_t::EndsInBranch() assert(branch); - branch->Disassemble(d); + Disassemble(branch,d); if(d.Instruction.BranchType!=0) return true; @@ -183,7 +184,7 @@ bool BasicBlock_t::EndsInIndirectBranch() assert(branch); - branch->Disassemble(d); + Disassemble(branch,d); if(d.Instruction.BranchType==RetType) return true; @@ -207,6 +208,7 @@ bool BasicBlock_t::EndsInConditionalBranch() DISASM d; Instruction_t *branch=instructions[instructions.size()-1]; assert(branch); + Disassemble(branch,d); if(d.Instruction.BranchType==RetType || d.Instruction.BranchType==JmpType || d.Instruction.BranchType==CallType) return false; diff --git a/libIRDB/src/cfg/callgraph.cpp b/libIRDB/src/cfg/callgraph.cpp index 4495e529e52a1f39b4eb3447b64810e8eb6aab7e..f5475d3907a0a6bef3fe234fbad2832eb3463cec 100644 --- a/libIRDB/src/cfg/callgraph.cpp +++ b/libIRDB/src/cfg/callgraph.cpp @@ -24,6 +24,7 @@ #include <libIRDB-core.hpp> #include <libIRDB-cfg.hpp> #include <utils.hpp> +#include <bea_deprecated.hpp> using namespace libIRDB; using namespace std; @@ -47,14 +48,14 @@ Callgraph_t::~Callgraph_t() static bool IsCallSite(Instruction_t* insn) { DISASM insnd; - insn->Disassemble(insnd); + Disassemble(insn,insnd); return NULL!=(strstr(insnd.Instruction.Mnemonic,"call")); } static bool IsTailJmpSite(Instruction_t* insn) { DISASM insnd; - insn->Disassemble(insnd); + Disassemble(insn,insnd); if(strstr(insnd.Instruction.Mnemonic,"jmp")==NULL) return false; @@ -69,14 +70,14 @@ static bool IsTailJmpSite(Instruction_t* insn) static bool IsPushJmpSite(Instruction_t* insn) { DISASM insnd; - insn->Disassemble(insnd); + Disassemble(insn,insnd); if(strstr(insnd.Instruction.Mnemonic,"push")==NULL || insn->GetFallthrough()==NULL) return false; if(insn->GetRelocations().size()==0) return false; - insn->GetFallthrough()->Disassemble(insnd); + Disassemble(insn->GetFallthrough(), insnd); if(strstr(insnd.Instruction.Mnemonic,"jmp")==NULL) return false; diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp index 80b5042ea5ebf4d2193993af37f4bb2c145ee74a..0b29e4d96c3bcf44eea6fa7445f5ad4ee3180608 100644 --- a/libIRDB/src/core/fileir.cpp +++ b/libIRDB/src/core/fileir.cpp @@ -28,6 +28,7 @@ #include <stdlib.h> #include <sys/wait.h> #include <iomanip> +#include <bea_deprecated.hpp> @@ -769,7 +770,7 @@ void FileIR_t::WriteToDB() { Instruction_t const * const insnp=*i; DISASM disasm; - insnp->Disassemble(disasm); + Disassemble(insnp,disasm); if(insnp->GetOriginalAddressID() == NOT_IN_DATABASE) { diff --git a/libIRDB/src/core/generate_spri.cpp b/libIRDB/src/core/generate_spri.cpp index c141f4f9a588589d9c459f907193d14ae054f12b..df71a8cf922fbac983d5df548209e74852fbf759 100644 --- a/libIRDB/src/core/generate_spri.cpp +++ b/libIRDB/src/core/generate_spri.cpp @@ -26,9 +26,9 @@ #include <fstream> #include <stdlib.h> #include <map> -#include "beaengine/BeaEngine.h" #include <string.h> #include <assert.h> +#include <bea_deprecated.hpp> #undef EIP @@ -394,7 +394,7 @@ static string emit_spri_instruction(FileIR_t* fileIRp, Instruction_t *newinsn, o DISASM disasm; /* Disassemble the instruction */ - int instr_len = newinsn->Disassemble(disasm); + int instr_len = Disassemble(newinsn,disasm); /* if this instruction has a prefix, re-disassemble it showing the segment regs */ diff --git a/libIRDB/src/core/instruction.cpp b/libIRDB/src/core/instruction.cpp index 1fab1950ef81e9eece8e12748affdb0f4a98f253..f574953f9496160e573398f3dc8b4948a0e1d5d0 100644 --- a/libIRDB/src/core/instruction.cpp +++ b/libIRDB/src/core/instruction.cpp @@ -24,6 +24,7 @@ #include <fstream> #include <sstream> #include <iomanip> +#include <bea_deprecated.hpp> #undef EIP @@ -75,6 +76,7 @@ Instruction_t::Instruction_t(db_id_t id, SetBaseID(id); } +/* int Instruction_t::Disassemble(DISASM &disasm) const { @@ -88,11 +90,12 @@ int Instruction_t::Disassemble(DISASM &disasm) const return instr_len; } +*/ std::string Instruction_t::getDisassembly() const { DISASM disasm; - Disassemble(disasm); + Disassemble(this,disasm); return std::string(disasm.CompleteInstr); } @@ -237,6 +240,7 @@ bool Instruction_t::IsFunctionExit() const } +/* bool Instruction_t::SetsStackPointer(ARGTYPE* arg) { if((arg->AccessMode & WRITE ) == 0) @@ -267,3 +271,4 @@ bool Instruction_t::SetsStackPointer(DISASM* disasm) return false; } +*/ diff --git a/libIRDB/src/syscall/syscall.cpp b/libIRDB/src/syscall/syscall.cpp index f5c2469f3a81df15e5dd997280a154f48fae5928..42a6745e870cd7ff45002091568580a2124ea01a 100644 --- a/libIRDB/src/syscall/syscall.cpp +++ b/libIRDB/src/syscall/syscall.cpp @@ -20,8 +20,8 @@ //#include <libIRDB-core.hpp> //#include <libIRDB-util.hpp> +#include <stdlib.h> #include <libIRDB-syscall.hpp> -#include <cstdlib> using namespace std; using namespace libIRDB; diff --git a/libIRDB/src/util/params.cpp b/libIRDB/src/util/params.cpp index b17b531bc3a24f977c43137a851ac800001a8ad4..a434ef49c10ba773112d90fa3d049b593e8f8aa8 100644 --- a/libIRDB/src/util/params.cpp +++ b/libIRDB/src/util/params.cpp @@ -22,6 +22,7 @@ #include <libIRDB-core.hpp> #include <libIRDB-util.hpp> #include <utils.hpp> +#include <bea_deprecated.hpp> using namespace libIRDB; using namespace std; @@ -30,7 +31,7 @@ using namespace std; bool libIRDB::IsParameterWrite(const FileIR_t *firp, Instruction_t* insn, string& output_dst) { auto d=DISASM({0}); - insn->Disassemble(d); + Disassemble(insn,d); if(d.Argument1.AccessMode!=WRITE) { return false; @@ -104,7 +105,7 @@ static Instruction_t* IsOrWasCall(const FileIR_t *firp, Instruction_t* insn) return NULL; auto d=DISASM({0}); - insn->Disassemble(d); + Disassemble(insn,d); if(d.Instruction.Mnemonic == string("call ")) { return insn->GetTarget(); @@ -142,7 +143,7 @@ bool libIRDB::CallFollows(const FileIR_t *firp, Instruction_t* insn, const strin for(Instruction_t* ptr=insn->GetFallthrough(); ptr!=NULL; ptr=ptr->GetFallthrough()) { auto d=DISASM({0}); - ptr->Disassemble(d); + Disassemble(ptr,d); long long vo = 0; if (ptr->GetAddress()) vo = ptr->GetAddress()->GetVirtualOffset(); @@ -219,7 +220,7 @@ bool libIRDB::CallFollows(const FileIR_t *firp, Instruction_t* insn, const strin bool libIRDB::FlowsIntoCall(const FileIR_t *firp, Instruction_t* insn) { auto d=DISASM({0}); - insn->Disassemble(d); + Disassemble(insn,d); string param_write; if (!libIRDB::IsParameterWrite(firp, insn, param_write)) @@ -231,7 +232,7 @@ bool libIRDB::FlowsIntoCall(const FileIR_t *firp, Instruction_t* insn) bool libIRDB::LeaFlowsIntoCall(const FileIR_t *firp, Instruction_t* insn) { auto d=DISASM({0}); - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)!="lea ") return false; @@ -242,7 +243,7 @@ bool libIRDB::LeaFlowsIntoCall(const FileIR_t *firp, Instruction_t* insn) bool libIRDB::LeaFlowsIntoPrintf(const FileIR_t *firp, Instruction_t* insn) { auto d=DISASM({0}); - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)!="lea ") return false; diff --git a/libIRDB/test/check_thunks.cpp b/libIRDB/test/check_thunks.cpp index 531fc738a20aa4f9daf14fad068761b5d50595d3..15846a547d729e5c2baef66620e451f68af6e20c 100644 --- a/libIRDB/test/check_thunks.cpp +++ b/libIRDB/test/check_thunks.cpp @@ -35,6 +35,7 @@ #include "check_thunks.hpp" #include "fill_in_indtargs.hpp" +#include <bea_deprecated.hpp> using namespace libIRDB; @@ -60,7 +61,7 @@ void check_for_thunk_offsets(FileIR_t* firp, virtual_offset_t thunk_base) // if it has a targ and fallthrough (quick test) it might be a call Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)==string("add ")) { @@ -146,7 +147,7 @@ void check_func_for_thunk_offsets(Function_t *func, Instruction_t* thunk_insn, // if it has a targ and fallthrough (quick test) it might be a call Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)==string("add ")) { @@ -198,7 +199,7 @@ void check_func_for_thunk_offsets(Function_t *func, Instruction_t* thunk_insn, bool is_thunk_load(Instruction_t* insn, string ®) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)!=string("mov ")) return false; @@ -216,7 +217,7 @@ bool is_thunk_load(Instruction_t* insn, string ®) bool is_ret(Instruction_t* insn) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(d.Instruction.BranchType!=RetType) return false; @@ -230,7 +231,7 @@ bool is_ret(Instruction_t* insn) bool is_pop(Instruction_t* insn, string ®) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic)!=string("pop ")) return false; @@ -248,7 +249,7 @@ bool is_pop(Instruction_t* insn, string ®) bool is_thunk_call(Instruction_t* insn, string ®) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); /* not a call */ if(d.Instruction.BranchType!=CallType) @@ -276,7 +277,7 @@ bool is_thunk_call(Instruction_t* insn, string ®) bool is_thunk_call_type2(Instruction_t* insn, string ®, Instruction_t** newinsn) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); /* not a call */ if(d.Instruction.BranchType!=CallType) @@ -305,7 +306,7 @@ bool is_thunk_call_type2(Instruction_t* insn, string ®, Instruction_t** newin bool is_thunk_add(Instruction_t *insn, string reg, string &offset) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); // make sure it's an add instruction if(string(d.Instruction.Mnemonic)!=string("add ")) diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp index 41599c3c3478e599295d2d6bfeff4ab9f8c168d4..9326b23fd141ca960f674c16040bf1371c537dca 100644 --- a/libIRDB/test/fill_in_cfg.cpp +++ b/libIRDB/test/fill_in_cfg.cpp @@ -32,6 +32,7 @@ #include "elfio/elfio_dump.hpp" #include "beaengine/BeaEngine.h" #include "eh_frame.hpp" +#include <bea_deprecated.hpp> int odd_target_count=0; int bad_target_count=0; @@ -367,7 +368,7 @@ void fill_in_cfg(FileIR_t *firp) DISASM disasm; memset(&disasm, 0, sizeof(DISASM)); - int instr_len = insn->Disassemble(disasm); + int instr_len = Disassemble(insn,disasm); assert(instr_len==insn->GetDataBits().size()); diff --git a/libIRDB/test/fill_in_indtargs.cpp b/libIRDB/test/fill_in_indtargs.cpp index 0d9bf59efcc3ad884694cea504bc0926f152bbcc..cbc8aa6f4bb890294844f3cecb070b43e3066d6c 100644 --- a/libIRDB/test/fill_in_indtargs.cpp +++ b/libIRDB/test/fill_in_indtargs.cpp @@ -42,6 +42,7 @@ #include "check_thunks.hpp" #include "fill_in_indtargs.hpp" #include "libMEDSAnnotation.h" +#include <bea_deprecated.hpp> using namespace libIRDB; using namespace std; @@ -286,7 +287,7 @@ void mark_targets(FileIR_t *firp) bool IsParameterWrite(FileIR_t *firp,Instruction_t* insn, string& output_dst) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(d.Argument1.AccessMode!=WRITE) { return false; @@ -357,7 +358,7 @@ bool CallToPrintfFollows(FileIR_t *firp, Instruction_t* insn, const string& arg_ for(Instruction_t* ptr=insn->GetFallthrough(); ptr!=NULL; ptr=ptr->GetFallthrough()) { DISASM d; - ptr->Disassemble(d); + Disassemble(ptr,d); if(d.Instruction.Mnemonic == string("call ")) { // check we have a target @@ -406,7 +407,7 @@ void get_instruction_targets(FileIR_t *firp, EXEIO::exeio* elfiop, const set<vir { Instruction_t *insn=*it; DISASM disasm; - virtual_offset_t instr_len = insn->Disassemble(disasm); + virtual_offset_t instr_len = Disassemble(insn,disasm); assert(instr_len==insn->GetDataBits().size()); @@ -576,7 +577,7 @@ set<Instruction_t*> find_in_function(string needle, Function_t *haystack) for (fit; fit != haystack->GetInstructions().end(); fit++) { Instruction_t *candidate = *fit; - candidate->Disassemble(disasm); + Disassemble(candidate,disasm); // check it's the requested type if(regexec(&preg, disasm.CompleteInstr, 0, NULL, 0) == 0) @@ -605,7 +606,7 @@ bool backup_until(const char* insn_type_regex, Instruction_t *& prev, Instructio // get I7's disassembly - prev->Disassemble(disasm); + Disassemble(prev,disasm); // check it's the requested type if(regexec(&preg, disasm.CompleteInstr, 0, NULL, 0) == 0) @@ -625,7 +626,7 @@ bool backup_until(const char* insn_type_regex, Instruction_t *& prev, Instructio { Instruction_t* pred=*it; - pred->Disassemble(disasm); + Disassemble(pred,disasm); // check it's the requested type if(regexec(&preg, disasm.CompleteInstr, 0, NULL, 0) == 0) { @@ -713,7 +714,7 @@ I7: 08069391 <_gedit_app_ready+0x91> ret else { DISASM dcmp; - Icmp->Disassemble(dcmp); + Disassemble(Icmp,dcmp); table_size = dcmp.Instruction.Immediat; if(table_size<=0) table_size=std::numeric_limits<int>::max(); @@ -721,7 +722,7 @@ I7: 08069391 <_gedit_app_ready+0x91> ret // grab the offset out of the lea. DISASM d2; - I3->Disassemble(d2); + Disassemble(I3,d2); // get the offset from the thunk virtual_offset_t table_offset=d2.Instruction.AddrValue; @@ -852,7 +853,7 @@ I5: 0x809900e <text_handler+51>: jmp ecx // grab the offset out of the lea. DISASM d2; - I3->Disassemble(d2); + Disassemble(I3,d2); // get the offset from the thunk virtual_offset_t table_offset=d2.Instruction.AddrValue; @@ -1249,7 +1250,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding if(!backup_until(table_index_str.c_str(), I7, I8)) return; - I7->Disassemble(disasm); + Disassemble(I7,disasm); // Check if lea instruction is being used as add (scale=1, disp=0) if(strstr(disasm.Instruction.Mnemonic, "lea")) @@ -1269,7 +1270,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding string lea_string="lea "; - I6->Disassemble(disasm); + Disassemble(I6,disasm); if( (disasm.Argument2.ArgType&MEMORY_TYPE) == MEMORY_TYPE) { // try to be smarter for memory types. @@ -1351,7 +1352,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding for (found_leas_it; found_leas_it != found_leas.end(); found_leas_it++) { Instruction_t *I5_cur = *found_leas_it; - I5_cur->Disassemble(disasm); + Disassemble(I5_cur,disasm); if(!(disasm.Argument2.ArgType&MEMORY_TYPE)) //return; @@ -1385,7 +1386,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding if(backup_until(cmp_str.c_str(), I1, I8)) { DISASM d1; - I1->Disassemble(d1); + Disassemble(I1,d1); table_size = d1.Instruction.Immediat; if (table_size <= 0) { @@ -1397,7 +1398,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding else if(backup_until(cmp_str2.c_str(), I1, I8)) { DISASM d1; - I1->Disassemble(d1); + Disassemble(I1,d1); table_size = d1.Instruction.Immediat; if (table_size <= 0) { @@ -1532,7 +1533,7 @@ static void check_for_nonPIC_switch_table_pattern2(FileIR_t* firp, Instruction_t // extract size off the comparison // make sure not off by one DISASM d1; - I1->Disassemble(d1); + Disassemble(I1,d1); virtual_offset_t table_size = d1.Instruction.Immediat; if (table_size <= 0) return; @@ -1630,7 +1631,7 @@ static void check_for_nonPIC_switch_table(FileIR_t* firp, Instruction_t* insn, D // extract start of jmp table DISASM d4; - I4->Disassemble(d4); + Disassemble(I4,d4); // make sure there's a scaling factor if (d4.Argument2.Memory.Scale < 4) @@ -1652,7 +1653,7 @@ static void check_for_nonPIC_switch_table(FileIR_t* firp, Instruction_t* insn, D // extract size off the comparison // make sure not off by one DISASM d1; - I1->Disassemble(d1); + Disassemble(I1,d1); virtual_offset_t table_size = d1.Instruction.Immediat; if (table_size <= 0) return; @@ -2114,7 +2115,7 @@ void mark_return_points(FileIR_t* firp) { Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string("call ")==d.Instruction.Mnemonic && insn->GetFallthrough()) { targets[insn->GetFallthrough()->GetAddress()->GetVirtualOffset()].add(ibt_provenance_t::ibtp_ret); @@ -2226,7 +2227,7 @@ void setup_icfs(FileIR_t* firp, EXEIO::exeio* elfiop) // disassemble the instruction, and figure out which type of hell node we need. DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string("ret ")==d.Instruction.Mnemonic || string("retn ")==d.Instruction.Mnemonic) { if(getenv("IB_VERBOSE")!=0) diff --git a/libIRDB/test/find_strings.cpp b/libIRDB/test/find_strings.cpp index 656fff09b9bb52c4616c59ed7329a7fcf6ae87cc..47f10025833438c4b05ff21e3b406b7bf84c6efb 100644 --- a/libIRDB/test/find_strings.cpp +++ b/libIRDB/test/find_strings.cpp @@ -35,6 +35,7 @@ #include "targ-config.h" #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" +#include <bea_deprecated.hpp> @@ -299,7 +300,7 @@ void find_strings_in_instructions(FileIR_t* firp, elf_info_t& ei) DISASM disasm; char *str = NULL; - int res=insn->Disassemble(disasm); + int res=Disassemble(insn,disasm); assert(res); // Concatenate printable strings from consecutive store immediates to SP-relative stack addresses @@ -374,7 +375,7 @@ void find_strings_in_instructions(FileIR_t* firp, elf_info_t& ei) newdisp += argsize; else newdisp = disp + argsize; - res=insn->Disassemble(disasm); + res=Disassemble(insn,disasm); assert(res); } @@ -409,7 +410,7 @@ void find_strings_in_instructions(FileIR_t* firp, elf_info_t& ei) Instruction_t *insn=*it; DISASM disasm; - int res=insn->Disassemble(disasm); + int res=Disassemble(insn,disasm); assert(res); // cout<<"Pass 2: Checking insn: "<<disasm.CompleteInstr<<" id: "<<insn->GetBaseID()<<endl; diff --git a/libIRDB/test/fix_calls.cpp b/libIRDB/test/fix_calls.cpp index 9689794cd803ea786f13824122af2b85d3799a07..4d34cf9850d7da90d7d922f6556a0cef36b9b21e 100644 --- a/libIRDB/test/fix_calls.cpp +++ b/libIRDB/test/fix_calls.cpp @@ -33,6 +33,7 @@ #include <exeio.h> #include "fill_in_indtargs.hpp" +#include <bea_deprecated.hpp> using namespace libIRDB; @@ -106,8 +107,8 @@ bool check_entry(bool &found, ControlFlowGraph_t* cfg) { DISASM disasm; Instruction_t* insn=*it; - insn->Disassemble(disasm); - if(Instruction_t::SetsStackPointer(&disasm)) { + Disassemble(insn,disasm); + if(SetsStackPointer(&disasm)) { return false; } else { if(getenv("VERBOSE_FIX_CALLS")) @@ -202,7 +203,7 @@ bool call_needs_fix(Instruction_t* insn) if(!target) { /* call 0's aren't to real locations */ - insn->Disassemble(disasm); + Disassemble(insn,disasm); if(strcmp(disasm.CompleteInstr, "call 0x00000000")==0) { return false; @@ -306,7 +307,7 @@ bool call_needs_fix(Instruction_t* insn) Instruction_t* itrinsn=*it; /* if the disassembly contains the string mentioned */ DISASM disasm; - itrinsn->Disassemble(disasm); + Disassemble(itrinsn,disasm); if(strstr(disasm.CompleteInstr, pattern.c_str())!=NULL) { found_pattern++; @@ -460,7 +461,7 @@ static void convert_to_jump(Instruction_t* insn, int offset) { string newbits=insn->GetDataBits(); DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); /* this case is odd, handle it specially (and more easily to understand) */ if(strcmp(d.CompleteInstr, "call qword [rsp]")==0) { @@ -547,7 +548,7 @@ void fix_call(Instruction_t* insn, FileIR_t *firp, bool can_unpin) DISASM disasm; /* Disassemble the instruction */ - int instr_len = insn->Disassemble(disasm); + int instr_len = Disassemble(insn,disasm); /* if this instruction is an inserted call instruction than we don't need to @@ -705,7 +706,7 @@ bool is_call(Instruction_t* insn) #endif /* Disassemble the instruction */ - int instr_len = insn->Disassemble(disasm); + int instr_len = Disassemble(insn,disasm); return (disasm.Instruction.BranchType==CallType); @@ -891,7 +892,7 @@ bool arg_has_relative(const ARGTYPE &arg) void fix_other_pcrel(FileIR_t* firp, Instruction_t *insn, UIntPtr virt_offset) { DISASM disasm; - insn->Disassemble(disasm); + Disassemble(insn,disasm); int is_rel= arg_has_relative(disasm.Argument1) || arg_has_relative(disasm.Argument2) || arg_has_relative(disasm.Argument3); /* if this has already been fixed, we can skip it */ @@ -966,7 +967,7 @@ void fix_other_pcrel(FileIR_t* firp, Instruction_t *insn, UIntPtr virt_offset) insn->GetRelocations().insert(reloc); firp->GetRelocations().insert(reloc); - insn->Disassemble(disasm); + Disassemble(insn,disasm); if(getenv("VERBOSE_FIX_CALLS")) cout<<" Converted to: "<<disasm.CompleteInstr<<endl; } diff --git a/libIRDB/test/ilr.cpp b/libIRDB/test/ilr.cpp index 805ea9ba0db4adabda66cc911337c114738283ce..c247a15f722165c115e2418a54305ba028dcdac6 100644 --- a/libIRDB/test/ilr.cpp +++ b/libIRDB/test/ilr.cpp @@ -23,6 +23,7 @@ #include <libIRDB-core.hpp> #include <iostream> #include <stdlib.h> +#include <bea_deprecated.hpp> using namespace libIRDB; using namespace std; @@ -70,7 +71,7 @@ void do_ilr(VariantID_t *pidp, FileIR_t* firp) if(getenv("ILR_NUMINSNSTOTRANSFORM") && ilrd_instructions==atoi(getenv("ILR_NUMINSNSTOTRANSFORM"))) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); cout<<"Aborting after insn #"<<std::dec<<ilrd_instructions<<": "<<d.CompleteInstr << " at " <<std::hex<<insn->GetAddress()->GetVirtualOffset()<<std::dec<<endl; } diff --git a/libtransform/src/transform.cpp b/libtransform/src/transform.cpp index 230d8f0c77db24cac2b825d07161eaa29dc333d3..e91b41145ba33d712739c8fbaec5b0d3b05a59fb 100644 --- a/libtransform/src/transform.cpp +++ b/libtransform/src/transform.cpp @@ -20,6 +20,7 @@ #include "transform.hpp" #include "Rewrite_Utility.hpp" +#include <bea_deprecated.hpp> /* * Find the first occurrence of find in s, ignore case. @@ -505,7 +506,7 @@ bool Transform::hasTargetRegister(Instruction_t *p_instruction, int p_argNo) return false; DISASM disasm; - p_instruction->Disassemble(disasm); + Disassemble(p_instruction,disasm); if (p_argNo == 1) return disasm.Argument1.ArgType & 0xFFFF0000 & REGISTER_TYPE; @@ -522,7 +523,7 @@ RegisterName Transform::getTargetRegister(Instruction_t *p_instruction, int p_ar if (hasTargetRegister(p_instruction, p_argNo)) { DISASM disasm; - p_instruction->Disassemble(disasm); + Disassemble(p_instruction,disasm); if (p_argNo == 1) return Register::getRegister(disasm.Argument1.ArgMnemonic); @@ -550,7 +551,7 @@ bool Transform::isMultiplyInstruction(Instruction_t *p_instruction) } DISASM disasm; - p_instruction->Disassemble(disasm); + Disassemble(p_instruction,disasm); // beaengine adds space at the end of the mnemonic string return my_strcasestr(disasm.Instruction.Mnemonic, "MUL ") != NULL; @@ -572,7 +573,7 @@ bool Transform::isMovInstruction(Instruction_t *p_instruction) } DISASM disasm; - p_instruction->Disassemble(disasm); + Disassemble(p_instruction,disasm); // nb: beaengine adds space at the end of the mnemonic string return my_strcasestr(disasm.Instruction.Mnemonic, "MOV") != NULL; @@ -587,8 +588,7 @@ bool Transform::isAddSubNonEspInstruction(Instruction_t *p_instruction) return false; DISASM disasm; - - p_instruction->Disassemble(disasm); + Disassemble(p_instruction,disasm); // beaengine adds space at the end of the mnemonic string if (my_strcasestr(disasm.Instruction.Mnemonic, "ADD ")) diff --git a/tools/Makefile.in b/tools/Makefile.in deleted file mode 100644 index 51723fb6c2aadf1c1540bd984ad174c44a784f20..0000000000000000000000000000000000000000 --- a/tools/Makefile.in +++ /dev/null @@ -1,13 +0,0 @@ -DIRS=safefr transforms spasm meds2pdb cover ret_shadow_stack selective_cfi fix_rets -CGC_DIRS=cgclibc cinderella prince watch_syscall cgc_hlx c2e cgc_rigrandom - -BUILD_CGC=@BUILD_CGC@ - -all: - for i in $(DIRS); do cd $$i; make all; cd ..;done - if [ $(BUILD_CGC) ]; then for i in $(CGC_DIRS); do cd $$i; make all; cd ..; done; fi - -clean: - for i in $(DIRS); do cd $$i; make clean; cd ..;done - if [ $(BUILD_CGC) ]; then for i in $(CGC_DIRS); do cd $$i; make clean; cd ..; done; fi - diff --git a/tools/fix_rets/fix_rets.cpp b/tools/fix_rets/fix_rets.cpp index 38e5ca49f1f36fc7df9b410924cc7f2d3bc38064..87182062ecdc6eea4236efd819ed1ad582607fa1 100644 --- a/tools/fix_rets/fix_rets.cpp +++ b/tools/fix_rets/fix_rets.cpp @@ -21,6 +21,7 @@ #include "fix_rets.hpp" #include <assert.h> +#include <bea_deprecated.hpp> using namespace libTransform; @@ -72,7 +73,7 @@ int FixRets::execute() if (insn!=NULL) { DISASM disasm; - insn->Disassemble(disasm); + Disassemble(insn,disasm); string stack_pointer; string stack_offset_size; diff --git a/tools/meds2pdb/Makefile.in b/tools/meds2pdb/Makefile.in deleted file mode 100644 index 49c1e28a1b5ddc92b802da38d544cd6cae144e3a..0000000000000000000000000000000000000000 --- a/tools/meds2pdb/Makefile.in +++ /dev/null @@ -1,22 +0,0 @@ -CC=@CC@ -CXX=@CXX@ - -CFLAGS= -g -INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libMEDSannotation/include -I../../libIRDB/include -LIBS=-L../../lib -lxform -lBeaEngine_s_d -lpq -lpqxx -lIRDB-core -lMEDSannotation -lpq - -.SUFFIXES: .o .c .cpp - -.cpp.o .c.o: - $(CXX) $(CFLAGS) $(INCLUDE) -c $< - - -all: meds2pdb - echo meds2pdb build complete - -clean: - rm -f *.o core meds2pdb - -meds2pdb: $(OBJS) meds2pdb.cpp ../../lib/*.a - $(CXX) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS) - diff --git a/tools/meds2pdb/meds2pdb.cpp b/tools/meds2pdb/meds2pdb.cpp index d1a358d4a71f916191b54c6dbe2db1518b09ecc0..71c57ba46196ced53763eaaaf56df49ad67de37f 100644 --- a/tools/meds2pdb/meds2pdb.cpp +++ b/tools/meds2pdb/meds2pdb.cpp @@ -257,6 +257,7 @@ void update_functions(int fileID, const vector<wahoo::Function*> &functions ) if(functionAddress!=0 && address_to_instructionid_map.find(functionAddress)==address_to_instructionid_map.end()) { +abort(); // remove the function from the list of valid functions. query+="delete from "+functionTable; query+=" where function_id = " + txn.quote(my_to_string(function_id)); diff --git a/tools/memcover/memcover.cpp b/tools/memcover/memcover.cpp index 71f5247ee1d71e7ed44281002559f4ea2e46ca05..d1fc70fd43ce56ddab9411b6eb59055a4c12b39c 100644 --- a/tools/memcover/memcover.cpp +++ b/tools/memcover/memcover.cpp @@ -23,11 +23,11 @@ #include <cstdio> #include <string> #include <fstream> -#include <beaengine/BeaEngine.h> #include <libIRDB-core.hpp> #include "General_Utility.hpp" #include "Rewrite_Utility.hpp" #include <sstream> +#include <bea_deprecated.hpp> #define ARG_CNT 3 @@ -282,7 +282,7 @@ void process_instructions(FileIR_t *fir_p) assert(instr); DISASM disasm; - instr->Disassemble(disasm); //calls memset for me, no worries + Disassemble(instr,disasm); //calls memset for me, no worries string instr_mn = disasm.Instruction.Mnemonic; trim(instr_mn); PREFIXINFO prefix = disasm.Prefix; @@ -334,7 +334,7 @@ void process_instructions(FileIR_t *fir_p) Instruction_t *first_instr = func->GetEntryPoint(); DISASM disasm; - first_instr->Disassemble(disasm); //calls memset for me, no worries + Disassemble(first_instr,disasm); //calls memset for me, no worries func_entries[first_instr] = disasm; } diff --git a/tools/ret_shadow_stack/rss_instrument.cpp b/tools/ret_shadow_stack/rss_instrument.cpp index c8ee2a97260ae200ca217eb29bed01cecff278e2..e37d18d31ee6e8271ba64fe09746283e79bb8922 100644 --- a/tools/ret_shadow_stack/rss_instrument.cpp +++ b/tools/ret_shadow_stack/rss_instrument.cpp @@ -25,6 +25,7 @@ #include "MEDS_ProblemFuncAnnotation.hpp" #include "Rewrite_Utility.hpp" #include <stdlib.h> +#include <bea_deprecated.hpp> @@ -276,7 +277,7 @@ bool RSS_Instrument::add_rss_push(FileIR_t* firp, Instruction_t* insn) if(getenv("RSS_VERBOSE")!=NULL) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); cout<<"Adding push instrumentation at 0x"<<std::hex<<insn->GetAddress()->GetVirtualOffset() << " disasm="<<d.CompleteInstr <<endl; } @@ -319,7 +320,7 @@ bool RSS_Instrument::add_rss_pop(FileIR_t* firp, Instruction_t* insn) if(getenv("RSS_VERBOSE")!=NULL) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); cout<<"Adding pop instrumentation at 0x"<<std::hex<<insn->GetAddress()->GetVirtualOffset() << " disasm="<<d.CompleteInstr <<endl; } @@ -392,7 +393,7 @@ bool RSS_Instrument::add_rss_pop(FileIR_t* firp, Instruction_t* insn) static bool is_exit_instruction(Instruction_t *insn, MEDS_AnnotationParser *meds_ap) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(strstr(d.CompleteInstr,"ret")!=0) return true; diff --git a/tools/selective_cfi/scfi_instr.cpp b/tools/selective_cfi/scfi_instr.cpp index b5030542bf5bd75a0808f91c2eefc318c43b0407..c5768eed85abd944d699da9ea4d765780985fbde 100644 --- a/tools/selective_cfi/scfi_instr.cpp +++ b/tools/selective_cfi/scfi_instr.cpp @@ -30,6 +30,7 @@ #include <elf.h> #include "elfio/elfio.hpp" #include "elfio/elfio_dump.hpp" +#include <bea_deprecated.hpp> @@ -358,7 +359,7 @@ static string change_to_push(Instruction_t *insn) string newbits=insn->GetDataBits(); DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); int opcode_offset=0; @@ -534,7 +535,7 @@ void SCFI_Instrument::AddReturnCFIForExeNonce(Instruction_t* insn, ColoredSlotVa DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(d.Argument1.ArgType!=NO_ARGUMENT) { unsigned int sp_adjust=d.Instruction.Immediat-firp->GetArchitectureBitWidth()/8; @@ -627,7 +628,7 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v) DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(d.Argument1.ArgType!=NO_ARGUMENT) { unsigned int sp_adjust=d.Instruction.Immediat-firp->GetArchitectureBitWidth()/8; @@ -754,7 +755,7 @@ static void display_histogram(std::ostream& out, std::string attr_label, std::ma bool SCFI_Instrument::is_plt_style_jmp(Instruction_t* insn) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if((d.Argument1.ArgType&MEMORY_TYPE)==MEMORY_TYPE) { if(d.Argument1.Memory.BaseRegister == 0 && d.Argument1.Memory.IndexRegister == 0) @@ -807,7 +808,7 @@ bool SCFI_Instrument::instrument_jumps() { Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); // we always have to protect the zestcfi dispatcher, that we just added. diff --git a/tools/simple_cdi/scdi_instr.cpp b/tools/simple_cdi/scdi_instr.cpp index e8765e58faa1084b08f493416b1f016fb90e3775..d4c48ba22847cb4e7e4c20d751e60a9ab699c50e 100644 --- a/tools/simple_cdi/scdi_instr.cpp +++ b/tools/simple_cdi/scdi_instr.cpp @@ -25,6 +25,7 @@ #include "utils.hpp" #include "scdi_instr.hpp" #include "Rewrite_Utility.hpp" +#include <bea_deprecated.hpp> using namespace std; using namespace libIRDB; @@ -224,7 +225,7 @@ bool SimpleCDI_Instrument::add_scdi_instrumentation(Instruction_t* insn) ICFS_t* ibts=insn->GetIBTargets(); DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(getenv("SimpleCDI_VERBOSE")!=NULL && ibts) { @@ -310,7 +311,7 @@ bool SimpleCDI_Instrument::is_return(Instruction_t* insn) if (insn) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); return string(d.Instruction.Mnemonic) == string("ret "); // FIXME: handle retn immd, but this means the instrumentation should pop/lea immd diff --git a/tools/transforms/OffsetInference.cpp b/tools/transforms/OffsetInference.cpp index eac562491b77e0b572ef0c18028627421ba36d28..a79797d8dea4cedfe4a162e77d3d5a26d7c71259 100644 --- a/tools/transforms/OffsetInference.cpp +++ b/tools/transforms/OffsetInference.cpp @@ -28,6 +28,7 @@ #include <set> #include <fstream> #include "globals.h" +#include <bea_deprecated.hpp> using namespace std; using namespace libIRDB; @@ -164,7 +165,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) Instruction_t* instr = entry; DISASM disasm; - instr->Disassemble(disasm); + Disassemble(instr,disasm); disasm_str = disasm.CompleteInstr; if(verbose_log) @@ -244,7 +245,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) // Instruction_t* next=*(it+1); Instruction_t* next = entry->GetFallthrough(); DISASM next_disasm; - next->Disassemble(next_disasm); + Disassemble(next,next_disasm); //cerr<<"DEBUG DEBUG: Disasm next match: "<<next_disasm.CompleteInstr<<endl; @@ -482,7 +483,7 @@ assert(instructions.size() != 0); string disasm_str; DISASM disasm; - instr->Disassemble(disasm); + Disassemble(instr,disasm); disasm_str = disasm.CompleteInstr; if(verbose_log) diff --git a/tools/transforms/PNTransformDriver.cpp b/tools/transforms/PNTransformDriver.cpp index 9f16f67648698c80df154913aee33525f18f5433..79defabd87535d471630d36e72b2a8b4d880301d 100644 --- a/tools/transforms/PNTransformDriver.cpp +++ b/tools/transforms/PNTransformDriver.cpp @@ -560,7 +560,7 @@ static pair<int,int> get_prologue_data(Function_t *func) for(i=0,insn=func->GetEntryPoint(); insn!=NULL && i<MAX_JUMPS_TO_FOLLOW; ++i,insn=GetNextInstruction(prev,insn, func)) { DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if(string(d.Instruction.Mnemonic) == "sub " && d.Argument1.ArgType==REGISTER_TYPE+GENERAL_REG+REG4) { subs++; @@ -593,7 +593,7 @@ static bool is_exit_insn(Instruction_t* prev) if(prev->GetFallthrough()==NULL && prev->GetTarget()==NULL) { DISASM d; - prev->Disassemble(d); + Disassemble(prev,d); if(string(d.CompleteInstr) == "ret ") return true; @@ -651,7 +651,7 @@ static bool check_for_cond_frame(Function_t *func, ControlFlowGraph_t* cfg) const auto is_rsp_sub_insn= [&](const Instruction_t* i) -> bool { DISASM d; - i->Disassemble(d); + Disassemble(i,d); return is_rsp_sub(d); }; @@ -714,7 +714,7 @@ static bool check_for_push_pop_coherence(Function_t *func) { Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); if((string(d.Instruction.Mnemonic) == "add " || string(d.Instruction.Mnemonic) == "lea ") && d.Argument1.ArgType==REGISTER_TYPE+GENERAL_REG+REG4) { Instruction_t *exit_insn=find_exit_insn(insn,func); @@ -734,7 +734,7 @@ static bool check_for_push_pop_coherence(Function_t *func) if(exit_insn) { DISASM d2; - exit_insn->Disassemble(d2); + Disassemble(exit_insn,d2); //cerr<<"Found exit insn ("<< d2.CompleteInstr << ") for pop ("<< d.CompleteInstr << ")"<<endl; map<Instruction_t*, int>::iterator mit; mit=pop_count_per_exit.find(exit_insn); @@ -770,7 +770,7 @@ static bool check_for_push_pop_coherence(Function_t *func) Instruction_t* insn=map_pair.first; assert(insn); DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); //cerr<<"Found "<<map_pair.second<<" pops in exit: \""<< d.CompleteInstr <<"\" func:"<<func->GetName()<<endl; @@ -874,7 +874,7 @@ bool check_for_bad_variadic_funcs(Function_t *func, const ControlFlowGraph_t* cf { Instruction_t* insn=*it; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); /* found the suspicious move insn first */ if(strcmp(d.CompleteInstr,"movzx eax, al")==0) @@ -926,7 +926,7 @@ bool PNTransformDriver::check_jump_tables(Instruction_t* insn) return true; DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); /* only look at jumps */ int branch_type = d.Instruction.BranchType; @@ -1018,7 +1018,7 @@ bool PNTransformDriver::backup_until(const char* insn_type, Instruction_t *& pre prev=*(preds[prev].begin()); // get I7's disassembly - prev->Disassemble(disasm); + Disassemble(prev,disasm); // check it's the requested type if(strstr(disasm.Instruction.Mnemonic, insn_type)!=NULL) @@ -1110,7 +1110,7 @@ DN: 0x4824e0: .long 0x4824e0-LN if(!backup_until("lea", I5, I6)) return true; - I5->Disassemble(disasm); + Disassemble(I5,disasm); if(!(disasm.Argument2.ArgType&MEMORY_TYPE)) return true; @@ -1187,7 +1187,7 @@ void PNTransformDriver::SanitizeFunctions() if(instr == NULL) continue; - instr->Disassemble(disasm); + Disassemble(instr,disasm); string disasm_str = disasm.CompleteInstr; /* @@ -2244,7 +2244,7 @@ bool PNTransformDriver::Canary_Rewrite(PNStackLayout *orig_layout, Function_t *f string disasm_str = ""; DISASM disasm; - instr->Disassemble(disasm); + Disassemble(instr,disasm); disasm_str = disasm.CompleteInstr; if(verbose_log) @@ -2401,7 +2401,7 @@ bool PNTransformDriver::Sans_Canary_Rewrite(PNStackLayout *layout, Function_t *f Instruction_t* instr=*it; string disasm_str = ""; DISASM disasm; - instr->Disassemble(disasm); + Disassemble(instr,disasm); disasm_str = disasm.CompleteInstr; if(verbose_log) @@ -2463,7 +2463,7 @@ int PNTransformDriver::prologue_offset_to_actual_offset(ControlFlowGraph_t* cfg, { assert(insn); DISASM d; - insn->Disassemble(d); + Disassemble(insn,d); string disasm_str=d.CompleteInstr; if(strstr(d.CompleteInstr, "push")!=NULL) @@ -2533,7 +2533,7 @@ inline bool PNTransformDriver::Instruction_Rewrite(PNStackLayout *layout, Instru string disasm_str = ""; DISASM disasm; - instr->Disassemble(disasm); + Disassemble(instr,disasm); disasm_str = disasm.CompleteInstr; //the disassmebly of lea has extra tokens not accepted by nasm, remove those tokens diff --git a/tools/transforms/PNTransformDriver.hpp b/tools/transforms/PNTransformDriver.hpp index 070d1a6614ab798e816960e969023825f3a38e23..83fe0bb5b39b83a1c09940c41d93506cf79755a5 100644 --- a/tools/transforms/PNTransformDriver.hpp +++ b/tools/transforms/PNTransformDriver.hpp @@ -32,6 +32,7 @@ #include <libIRDB-cfg.hpp> #include "canary.h" #include <libIRDB-core.hpp> +#include <bea_deprecated.hpp> //TODO: I should use the types defined by beaengine diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp index c5cb6a8c769202239e8a7775e057a48811583d64..40424be8b86b759a1c01757f8d198e95a5311dff 100644 --- a/xform/rewriter.cpp +++ b/xform/rewriter.cpp @@ -623,8 +623,8 @@ any esp access outside this region (esp + K) >= (esp + size) can be xformed after_loop: - // for each instruction in a function, dissassemble and stash away assembly string - dissassemble(); + // for each instruction in a function, disassemble and stash away assembly string + disassemble(); } @@ -655,14 +655,14 @@ void Rewriter::readElfFile(char p_filename[]) pclose(pin); - dissassemble(); + disassemble(); } /* -* for all instructions, dissassemble them using the BeaEngine +* for all instructions, disassemble them using the BeaEngine */ -void Rewriter::dissassemble() +void Rewriter::disassemble() { // for every instruction, grab from ELF // disassemble diff --git a/xform/rewriter.h b/xform/rewriter.h index 2d83667133c5de46d5f6a20bd5b06f2e97d1cf80..b7c00f75467f471b7f364c51fc5e0f8d7fdb3d92 100644 --- a/xform/rewriter.h +++ b/xform/rewriter.h @@ -31,8 +31,8 @@ class Rewriter FILE* getAsmSpri() { return m_spri; }; void setAsmSpri(FILE *p_spri) { m_spri = p_spri; }; - // dissassemble all functions - void dissassemble(); + // disassemble all functions + void disassemble(); // one instruction modification void addSimpleRewriteRule(wahoo::Function* p_func, char *p_origInstr, int p_origSize, app_iaddr_t p_origAddress, char *p_newInstr);