Skip to content

Commit

Permalink
Merge pull request #189 from atlas0fd00m/arch_modva_hooks
Browse files Browse the repository at this point in the history
EASY: arch mod-va hooks
  • Loading branch information
invisig0th committed Jun 8, 2017
2 parents fd0db87 + ec20b6a commit ba48213
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
20 changes: 20 additions & 0 deletions envi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ def archGetRegisterGroups(self):
allr = [rname for rname in regctx.getRegisterNames()]
return [ ('all', allr), ]

def archModifyFuncAddr(self, va, info):
'''
Can modify the VA and context based on architecture-specific info.
Default: return the same va, info
This hook allows an architecture to correct VA and Architecture, such
as is necessary for ARM/Thumb.
'''
return va, {}

def archModifyXrefAddr(self, tova, reftype, rflags):
'''
Returns a potentially modified set of (tova, reftype, rflags).
Default: return the same tova, reftype, rflags
This hook allows an architecture to modify an Xref before it's set,
which can be helpful for ARM/Thumb.
'''
return tova, reftype, rflags

def archGetBadOps(self, byteslist=None):
'''
Returns a list of opcodes which are indicators of wrong disassembly.
Expand Down
11 changes: 11 additions & 0 deletions envi/archs/arm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def setEndian(self, endian):
self._arch_dis.setEndian(endian)
self._arch_thumb_dis.setEndian(endian)

def archModifyFuncAddr(self, va, info):
if va & 1:
return va & -2, {'arch' : envi.ARCH_THUMB2}
return va, {}

def archModifyXrefAddr(self, tova, reftype, rflags):
if tova & 1:
return tova & -2, reftype, rflags
return tova, reftype, rflags




from envi.archs.arm.emu import *
5 changes: 5 additions & 0 deletions envi/codeflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ def addEntryPoint(self, va, arch=envi.ARCH_DEFAULT):
cf.addEntryPoint( 0x77c70308 )
... callbacks flow along ...
'''
# Architecture gets to decide on actual final VA and Architecture (ARM/THUMB/etc...)
info = { 'arch' : arch }
va, info = self._mem.arch.archModifyFuncAddr(va, info)
arch = info.get('arch', envi.ARCH_DEFAULT)

# Check if this is already a known function.
if self._funcs.get(va) != None:
return
Expand Down
5 changes: 4 additions & 1 deletion vivisect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,10 @@ def addXref(self, fromva, tova, reftype, rflags=0):
(see REF_ macros). This will *not* trigger any analysis.
Callers are expected to do their own xref analysis (ie, makeCode() etc)
"""
ref = (fromva,tova,reftype,rflags)
# Architecture gets to decide on actual final VA (ARM/THUMB/etc...)
tova, reftype, rflags = self.arch.archModifyXrefAddr(tova, reftype, rflags)

ref = (fromva, tova, reftype, rflags)
if ref in self.getXrefsFrom(fromva):
return
self._fireEvent(VWE_ADDXREF, (fromva, tova, reftype, rflags))
Expand Down

0 comments on commit ba48213

Please sign in to comment.