Files
James Gross a7b5f8deef Py3 cutover (try number: who knows?) (#328)
Massive cutover to python3 (baseline is 3.9.1, but is also tested/working on 3.7.x). This merge is a breaking change for any downstream consumers, as the python 2->3 strings/bytes change is central. Most APIs should still work roughly as intended, as I didn't majorly re-organize the codebase, so most APIs live where they lived before. But a changelog/migration guide will be included in the next PR for this.

This PR will constitute most if not all of the v1.0.0 release that is forthcoming soon.
2021-02-03 14:37:09 -05:00

76 lines
2.0 KiB
Python

'''
Calling convention and API definitions for various APIs/archs.
'''
import sys
class ImportApi:
def __init__(self):
self._api_lookup = {}
self._apitype_lookup = {}
def getImpApiType(self, tname):
return self._apitype_lookup.get(tname)
def updateApiDef(self, apidict):
self._api_lookup.update(apidict)
def getImpApi(self, funcname):
'''
An API definition consists of the following:
( rettype, retname, callconv, funcname, ( (argtype, argname), ...) )
'''
return self._api_lookup.get(funcname.lower())
def getImpApiCallConv(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return ret[2]
def getImpApiArgs(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return ret[4]
def getImpApiRetType(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return ret[0]
def getImpApiRetName(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return ret[1]
def getImpApiArgTypes(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return [argt for (argt, argn) in ret[4]]
def getImpApiArgNames(self, funcname):
ret = self._api_lookup.get(funcname.lower())
if ret is None:
return None
return [argn for (argt, argn) in ret[4]]
def addImpApi(self, api, arch):
api = api.lower()
arch = arch.lower()
modname = 'vivisect.impapi.%s.%s' % (api, arch)
__import__(modname)
mod = sys.modules[modname]
self._api_lookup.update(mod.api)
self._apitype_lookup.update(mod.apitypes)
def getImportApi(api, arch):
impapi = ImportApi()
impapi.addImpApi(api, arch)
return impapi