1111
1212IDA_DEFAULT_PATH = os .environ ['HOME' ]+ "/seclab_ida/ida/idat"
1313if os .environ ['IDA_BASE_DIR' ]:
14- IDA_PATH = os .environ ['IDA_BASE_DIR' ]+ "/idat"
14+ IDA_PATH = os .environ ['IDA_BASE_DIR' ]+ "/idat"
1515else :
16- IDA_PATH = IDA_DEFAULT_PATH
16+ IDA_PATH = IDA_DEFAULT_PATH
1717
1818# path to defs.h
1919DEFS_PATH = os .path .dirname (os .path .realpath (__file__ ))+ "/refs/defs.h"
@@ -649,9 +649,24 @@ def get_data_declarations(self, lines):
649649 header = header [3 :] # handle commented out cases
650650
651651 dataType , dataName = self .getTypeAndLabel (header )
652- defLine = "%s *(p%s);\n " % (dataType , dataName )
653- dataName = dataName .split ("[" )[0 ] # handle arrays
654- defLine += "#define %s (*p%s)\n " % (dataName , dataName )
652+ array_size = len (re .findall ("\[\d*\]" ,dataName ))
653+ print ("Array Size:" , array_size )
654+ defLine = ""
655+ if array_size >= 2 :
656+ print ("// --- WARNING! Two-dimensional array objects are not yet supported" )
657+ defLine += "%s *(p%s);\n " % (dataType , dataName )
658+ dataName = dataName .split ("[" )[0 ] # handle arrays
659+ defLine += "#define %s (*p%s)\n " % (dataName , dataName )
660+ print (" // --- END OF WARNING!\n " )
661+ elif array_size == 1 and "*" not in dataType :
662+ dataName = dataName .split ("[" )[0 ] # handle arrays
663+ defLine = "%s *(p%s);\n " % (dataType , dataName )
664+ defLine += "#define %s (p%s)\n " % (dataName , dataName )
665+ else :
666+ defLine = "%s *(p%s);\n " % (dataType , dataName )
667+ dataName = dataName .split ("[" )[0 ] # handle arrays
668+ defLine += "#define %s (*p%s)\n " % (dataName , dataName )
669+
655670 if line .startswith ("//" ):
656671 defLine += "//"
657672 print (" ---->" , defLine )
@@ -859,7 +874,7 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
859874 wrapperStub += " my%s,\n " % self .get_stub_name (s )
860875 print (s )
861876 print (" - STUBNAME: " , self .get_stub_name (s ))
862-
877+
863878 # note from pdr: looks like when data declarations are included, the
864879 # function prototype and funcstubs order of symbol definitions
865880 # are not consistent
@@ -869,7 +884,17 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
869884 dataDef = d .split (";" )[0 ]
870885 dataDef = dataDef .split ("=" )[0 ].strip ()
871886 dataType , dataName = self .getTypeAndLabel (dataDef )
872- wrapperStub += "\t void* my%s,\n " % dataName
887+ array_size = len (re .findall ("\[\d*\]" ,dataName ))
888+ if array_size >= 2 :
889+ print ("SORRY: two-dimensional array objects just aren't working right now" )
890+ print (" ==> " + dataType + " " + dataName )
891+ wrapperStub += "// --- WARNING! Two-dimensional array objects are not yet supported"
892+ wrapperStub += "\t void* my%s,\n " % dataName
893+ elif array_size == 1 and "*" not in dataType :
894+ dataNamex = dataName .split ("[" )[0 ] # handle arrays
895+ wrapperStub += "\t void* my%s,\n " % dataNamex
896+ else :
897+ wrapperStub += "\t void* my%s,\n " % dataName
873898 print (" - DATA DECL: " , dataName )
874899
875900 for argTuple in args :
@@ -898,8 +923,16 @@ def generate_wrapper(self, target, funcs, stubMap, dataMap):
898923 dataDef = dataDef [3 :] # handle commented out cases
899924 dataDef = dataDef .split ("=" )[0 ].strip ()
900925 dataType , dataName = self .getTypeAndLabel (dataDef )
901- wrapperStub += "\t p%s = (%s*) my%s;\n " % (dataName , dataType , dataName )
902-
926+ array_size = len (re .findall ("\[\d*\]" ,dataName ))
927+ if array_size >= 2 :
928+ print ("// --- WARNING! Two-dimensional array objects are not yet supported\n " )
929+ wrapperStub += "\t p%s = (%s*) my%s;\n " % (dataName , dataType , dataName )
930+ print (" // --- END OF WARNING!\n " )
931+ elif array_size == 1 and "*" not in dataType :
932+ dataNamex = dataName .split ("[" )[0 ] # handle arrays
933+ wrapperStub += "\t p%s = (%s*) my%s;\n " % (dataNamex , dataType , dataNamex )
934+ else :
935+ wrapperStub += "\t p%s = (%s*) my%s;\n " % (dataName , dataType , dataName )
903936
904937 for s in stubMap .keys ():
905938 name = self .get_stub_name (s )
@@ -1101,7 +1134,10 @@ def run(self):
11011134
11021135
11031136def main ():
1104-
1137+ if not os .path .isfile (IDA_PATH ):
1138+ print ("ERROR: Environmental variable IDA_BASE_PATH is not set or '" + IDA_DEFAULT_PATH + "' does not exist" )
1139+ import sys
1140+ sys .exit (- 1 )
11051141 parser = argparse .ArgumentParser (description = '' )
11061142 parser .add_argument ('target_list' ,
11071143 help = 'path to the list of target binaries + paths' )
0 commit comments