Commits

Anonymous committed 666c65b

parsing whole procedure is done by declip.py instead of dp_stdout.py now

  • Participants
  • Parent commits 656a26d

Comments (0)

Files changed (3)

 #!/usr/bin/python -tt
 '''Library to parse and analyse summer'87 DOS executables'''
 __revision__ = '$Rev: 104 $'
-import string, sys
+import string, sys, re
 import pcodedata
 from pcodedata import binformat, OP_MNEMON, OP_WPAR, OP_PUSH, OP_POP, OP_STRING
 
     exestr = self.fp.read(cnt)
     return cnt, exestr
 
-  def buildGraph(self):
-    pass
-        
+  def buildGraph(self, buf):
+    result = []
+    for ii in buf:
+      cc = ord(ii)
+      if cc in pcodedata.op_dict.keys():
+        mn = pcodedata.op_dict[cc][OP_MNEMON]
+        result.append([ord(ii), mn])
+    print result
+    
+  def parseProcedure(self, procname, format):
+    print "LOOKING FOR:", procname, "..."
+    sd = self.symbdict
+    procdata = None
+    for ii in sd.keys():
+      for jj in sd[ii].keys():
+        if sd[ii][jj]["symbol"] == procname:
+          procdata = sd[ii][jj]
+          # print "DEBUG procdata", procdata
+          # TODO: too many times the same condition is evaluated
+          if procdata["class"]=="subprogram" or procdata["class"]=="module:main":
+            break
+      if procdata and (procdata["class"]=="subprogram" or procdata["class"]=="module:main"):
+        break
+    if procdata and (procdata["class"]=="subprogram" or procdata["class"]=="module:main"):
+      print "FOUND:", procdata
+      ii = 0
+      stopnow = None
+      startpos = self.firstfun + procdata["off1"] + procdata["off2"] + (0 if self.linker=='plink86' else -16)
+      while not stopnow:
+        delta, disass_line, declip_line = self.mkMnemoLine(startpos+ii, format)
+        stopnow = (re.search("FC_ENDSUB", disass_line))
+        if delta == -1:
+          self.closeFile() # MATUSZ: ??? closing file prematurely ?
+          return startpos+ii
+        print disass_line
+        if declip_line != '':
+          print "  " + declip_line
+        ii+=delta
+    else:
+      print "NOT FOUND"
+
 ########################################################################
 def isprint(ch):
     if (32<=ord(ch)<=126) or (161<=ord(ch)<=255) :

File dp_stdout.py

     
   # parse bytecode
   if params.get("ProcToParse"):
-    procname = params.get("ProcToParse").upper()
-    print "LOOKING FOR:", procname, "..."
-    sd = inputfile.symbdict
-    procdata = None
-    for ii in sd.keys():
-      for jj in sd[ii].keys():
-        if sd[ii][jj]["symbol"] == procname:
-          procdata = sd[ii][jj]
-          # print "DEBUG procdata", procdata
-          # TODO: too many times the same condition is evaluated
-          if procdata["class"]=="subprogram" or procdata["class"]=="module:main":
-            break
-      if procdata and (procdata["class"]=="subprogram" or procdata["class"]=="module:main"):
-        break
-    if procdata and (procdata["class"]=="subprogram" or procdata["class"]=="module:main"):
-      print "FOUND:", procdata
-      ii = 0
-      stopnow = None
-      startpos = inputfile.firstfun + procdata["off1"] + procdata["off2"] + (0 if params.get("Linker")=='plink86' else -16)
-      while not stopnow:
-        delta, disass_line, declip_line = inputfile.mkMnemoLine(startpos+ii, format)
-        stopnow = (re.search("FC_ENDSUB", disass_line))
-        if delta == -1:
-          inputfile.closeFile()
-          return startpos+ii
-        print disass_line
-        if declip_line != '':
-          print "  " + declip_line
-        ii+=delta
-    else:
-      print "NOT FOUND"
+    inputfile.parseProcedure( params.get("ProcToParse").upper() , format)
   else:
     if startpos >= 0 and bytecount > 0:
       ii = 0

File parameters.py

     parser.add_option("--dict-dump", "--dictdump", action="store_true", dest="DictDump", help=" (dp-stdout only)")
     parser.add_option("--symbol-table", "--symbol-dump", "--dump-symbols", "--symbol-table-dump",
             action="store_true", dest="ShowSymbols")
+    parser.add_option("--build-graph", action="store_true", dest="BuildGraph", help=" (digraph of the procedure)")
     parser.set_defaults(EndPos=-2, ByteCount=0, StartPos=-1, Format='disass', 
             Linker='plink86', Header=True, FileName='', DictDump = False)
     (self.opts, self.args) = parser.parse_args()