waliedassar

DumpRTFObjects.py

May 3rd, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 KB | None | 0 0
  1. #link
  2.  
  3. import os, sys, time, hashlib
  4.  
  5.  
  6.  
  7.  
  8. def IsNonHexChar(CharX):
  9.     if CharX != "0" and CharX != "1" and CharX != "2" and CharX != "3" and CharX != "4" and CharX != "5" and CharX != "6" and CharX != "7" and CharX != "8" and CharX != "9" and CharX != "A" and CharX != "a" and CharX != "B" and CharX != "b" and CharX != "C" and CharX != "c" and CharX != "D" and CharX != "d" and CharX != "E" and CharX != "e" and CharX != "F" and CharX != "f":
  10.         return True
  11.     return False
  12.  
  13. def IsHexChar(CharX):
  14.     if CharX != "0" and CharX != "1" and CharX != "2" and CharX != "3" and CharX != "4" and CharX != "5" and CharX != "6" and CharX != "7" and CharX != "8" and CharX != "9" and CharX != "A" and CharX != "a" and CharX != "B" and CharX != "b" and CharX != "C" and CharX != "c" and CharX != "D" and CharX != "d" and CharX != "E" and CharX != "e" and CharX != "F" and CharX != "f":
  15.         return True
  16.     return False
  17.  
  18. def IsWhiteSpace(inC):
  19.     if inC == " " or inC == "\t" or inC == "\r" or inC == "\n":
  20.         return True
  21.     return False
  22.  
  23. def Hexify(contentX):
  24.     if len(contentX)==0:
  25.         print "Input content is empty\r\n"
  26.         return ""
  27.     else:
  28.         Second = False
  29.         SkipNext = False
  30.         FinalStr = ""
  31.         NewStr = ""
  32.         for X in contentX:
  33.             if SkipNext == True:
  34.                 SkipNext = False
  35.                 continue
  36.             if IsHexChar(X)==True:
  37.                 SkipNext = True
  38.                 continue
  39.             if Second == False:
  40.                 NewStr+=X
  41.                 Second = True
  42.             else:
  43.                 NewStr+=X
  44.                 FinalStr += "\\x"
  45.                 FinalStr += NewStr
  46.                 NewStr = ""
  47.                 Second = False
  48.        
  49.         #print FinalStr + "\r\n"
  50.         XXX = "\"" + FinalStr + "\""
  51.         outputX =  eval(XXX)
  52.         return outputX
  53.  
  54.        
  55. def DumpRTFObjects(input_file):
  56.     Min_Length = 20
  57.     fIn = open(input_file,"r")
  58.     fCon = fIn.read()
  59.     fIn.close()
  60.     Length = len(fCon)
  61.     if Length == 0:
  62.         print "Zero Length"
  63.         return -1
  64.  
  65.     print "Processing input file of Length: " + str(Length)
  66.    
  67.     filecounter = 0
  68.     Obj = ""
  69.     for i in range(0,Length):
  70.         if (IsNonHexChar(fCon[i])==True and fCon[i]!="\r" and fCon[i]!="\n") or (i== Length-1):
  71.             if len(Obj)>Min_Length:
  72.                 print "---Starts Here---\r\n"
  73.                 print Obj
  74.                 print "---Ends Here---\r\n"
  75.                 outfile = str(filecounter)+".dmp"
  76.                 fOut = open(outfile,"wb")
  77.                 fOut.write(Obj)
  78.                 fOut.close
  79.                 outfileX = str(filecounter)+".obj"
  80.                 fOutX = open(outfileX,"w")
  81.                 fOutX.write(Hexify(Obj))
  82.                 fOutX.close()
  83.                 filecounter = filecounter + 1
  84.             Obj = ""
  85.             continue
  86.         else:
  87.             if fCon[i]!="\r" and fCon[i]!="\n":
  88.                 Obj += fCon[i]
  89.  
  90. def main():
  91.     if len(sys.argv)!=2:
  92.         print "Usage: DumpRTFObjects.py input_rtf_here\r\n"
  93.         sys.exit(-1)
  94.     else:
  95.         retX = DumpRTFObjects(sys.argv[1])
  96.         sys.exit(retX)
  97.  
  98.  
  99. if __name__ == "__main__":
  100.     main()
Add Comment
Please, Sign In to add comment