def getBinstr(self, binstr): bval = e_bits.binary(binstr) return self.getInt(bval, len(bstr))
''' thumb_table = list(thumb_base) thumb_table.extend(thumb1_extension) thumb2_table = list(thumb_base) thumb2_table.extend(thumb2_extension) ttree = e_btree.BinaryTree() for binstr, opinfo in thumb_table: ttree.addBinstr(binstr, opinfo) ttree2 = e_btree.BinaryTree() for binstr, opinfo in thumb2_table: ttree2.addBinstr(binstr, opinfo) thumb32mask = binary('11111') thumb32min = binary('11100') def is_thumb32(val): ''' Take a 16 bit integer (opcode) value and determine if it is really the first 16 bits of a 32 bit instruction. ''' bval = val >> 11 return (bval & thumb32mask) > thumb32min class ThumbOpcode(ArmOpcode): _def_arch = envi.ARCH_THUMB16 pass
import envi.bits as e_bits from envi.bits import binary import envi.bintree as e_btree import envi.archs.arm.disasm as arm_dis import envi.archs.arm.regs as arm_reg thumb_32 = [ binary('11101'), binary('11110'), binary('11111'), ] O_REG = 0 O_IMM = 1 def shmaskval( value, shval, mask ): #FIXME: unnecessary to make this another fn call. will be called a bajillion times. return (value >> shval) & mask class simpleops: def __init__(self, *operdef): self.operdef = operdef def __call__(self, va, value): ret = [] for otype, shval, mask in self.operdef: oval = shmaskval(value, shval, mask)
def addBinstr(self, binstr, nodeinfo): bval = e_bits.binary(binstr) return self.addInt(bval, len(binstr), nodeinfo)
import envi.bits as e_bits import envi.bintree as e_btree from envi.bits import binary from envi.archs.arm.armdisasm import * thumb_32 = [binary("11101"), binary("11110"), binary("11111")] O_REG = 0 O_IMM = 1 OperType = (ArmRegOper, ArmImmOper) def shmaskval( value, shval, mask ): # FIXME: unnecessary to make this another fn call. will be called a bajillion times. return (value >> shval) & mask class simpleops: def __init__(self, *operdef): self.operdef = operdef def __call__(self, va, value): ret = [] for otype, shval, mask in self.operdef: oval = shmaskval(value, shval, mask) oper = OperType[otype]((value >> shval) & mask)
e = opcode & 0xf return (op1<<4)+d,(a,b,c,d,e) # FIXME this seems to be universal... def addrToName(mcanv, va): sym = mcanv.syms.getSymByAddr(va) if sym != None: return repr(sym) return "0x%.8x" % va # The keys in this table are made of the # concat of bits 27-21 and 7-4 (only when # ienc == mul! iencmul_codes = { # Basic multiplication opcodes binary("000000001001"): ("mul",(0,4,2), 0), binary("000000011001"): ("mul",(0,4,2), IF_PSR_S), binary("000000101001"): ("mla",(0,4,2,1), 0), binary("000000111001"): ("mla",(0,4,2,1), IF_PSR_S), binary("000001001001"): ("umaal",(1,0,4,2), 0), binary("000010001001"): ("umull",(1,0,4,2), 0), binary("000010011001"): ("umull",(1,0,4,2), IF_PSR_S), binary("000010101001"): ("umlal",(1,0,4,2), 0), binary("000010111001"): ("umlal",(1,0,4,2), IF_PSR_S), binary("000011001001"): ("smull",(1,0,4,2), 0), binary("000011011001"): ("smull",(1,0,4,2), IF_PSR_S), binary("000011101001"): ("smlal",(1,0,4,2), 0), binary("000011111001"): ("smlal",(1,0,4,2), IF_PSR_S), # multiplys with <x><y> # "B"
def thumb16row(binstr, func): bin = e_bits.binary(binstr)