Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. import re
  2. import struct
  3. import random
  4.  
  5.  
  6. def junk():
  7. HJISDUF = random.randint(1,1000)
  8. if HJISDUF < 2:
  9. IUDSF = ((HJISDUF * 4)/2)
  10.  
  11.  
  12. def re_to_unicode(s):
  13. newstring = ''
  14. for c in s:
  15. newstring += re.escape(c) + '\\x00'
  16. junk()
  17. return newstring
  18.  
  19.  
  20.  
  21. def type_unpack(type):
  22. """ return the struct and the len of a particular type """
  23. type = type.lower()
  24. s = None
  25. junk()
  26. l = None
  27. if type == 'short':
  28. junk()
  29. s = 'h'
  30. l = 2
  31. elif type == 'bool':
  32. junk()
  33. s = 'c'
  34. l = 1
  35. elif type == 'ushort':
  36. junk()
  37. s = 'H'
  38. l = 2
  39. elif type == 'int':
  40. junk()
  41. s = 'i'
  42. l = 4
  43. elif type == 'uint':
  44. junk()
  45. s = 'I'
  46. l = 4
  47. elif type == 'long':
  48. junk()
  49. s = 'l'
  50. l = 4
  51. elif type == 'ulong':
  52. junk()
  53. s = 'L'
  54. l = 4
  55. elif type == 'float':
  56. junk()
  57. s = 'f'
  58. l = 4
  59. elif type == 'double':
  60. junk()
  61. s = 'd'
  62. l = 8
  63. else:
  64. raise TypeError('Unknown type %s' % type)
  65. junk()
  66. return ('<' + s, l)
  67.  
  68.  
  69. def hex_dump(data, addr = 0, prefix = '', ftype = 'bytes'):
  70. """
  71. function originally from pydbg, modified to display other types
  72. """
  73. junk()
  74. dump = prefix
  75. slice = ''
  76. if ftype != 'bytes':
  77. junk()
  78. structtype, structlen = type_unpack(ftype)
  79. for i in range(0, len(data), structlen):
  80. if addr % 16 == 0:
  81. junk()
  82. dump += ' '
  83. for char in slice:
  84. if ord(char) >= 32 and ord(char) <= 126:
  85. dump += char
  86. else:
  87. junk()
  88. dump += '.'
  89.  
  90. dump += '\n%s%08X: ' % (prefix, addr)
  91. slice = ''
  92. tmpval = 'NaN'
  93. try:
  94. junk()
  95. packedval = data[i:i + structlen]
  96. tmpval = struct.unpack(structtype, packedval)[0]
  97. except Exception as e:
  98. print e
  99.  
  100. if tmpval == 'NaN':
  101. junk()
  102. dump += '{:<15} '.format(tmpval)
  103. elif ftype == 'float':
  104. junk()
  105. dump += '{:<15.4f} '.format(tmpval)
  106. else:
  107. junk()
  108. dump += '{:<15} '.format(tmpval)
  109. addr += structlen
  110. junk()
  111. else:
  112. for byte in data:
  113. junk()
  114. if addr % 16 == 0:
  115. dump += ' '
  116. for char in slice:
  117. junk()
  118. if ord(char) >= 32 and ord(char) <= 126:
  119. dump += char
  120. else:
  121. junk()
  122. dump += '.'
  123.  
  124. dump += '\n%s%08X: ' % (prefix, addr)
  125. slice = ''
  126. dump += '%02X ' % ord(byte)
  127. junk()
  128. slice += byte
  129. addr += 1
  130.  
  131. remainder = addr % 16
  132. if remainder != 0:
  133. junk()
  134. dump += ' ' * (16 - remainder) + ' '
  135. for char in slice:
  136. junk()
  137. if ord(char) >= 32 and ord(char) <= 126:
  138. dump += char
  139. else:
  140. junk()
  141. dump += '.'
  142.  
  143. return dump + '\n'
  144.  
  145. junk()
  146. junk()
  147. junk()
  148. class ProcessException(Exception):
  149. junk()
  150. pass
  151.  
  152. class BaseProcess(object):
  153. junk()
  154. def __init__(self, *args, **kwargs):
  155. junk()
  156. """ Create and Open a process object from its pid or from its name """
  157. self.h_process = None
  158. self.pid = None
  159. self.isProcessOpen = False
  160. self.buffer = None
  161. self.bufferlen = 0
  162.  
  163. def __del__(self):
  164. junk()
  165. self.close()
  166.  
  167. def close(self):
  168. junk()
  169. pass
  170. def iter_region(self, *args, **kwargs):
  171. junk()
  172. raise NotImplementedError
  173. def write_bytes(self, address, data):
  174. junk()
  175. raise NotImplementedError
  176.  
  177. def read_bytes(self, address, bytes = 4):
  178. junk()
  179. raise NotImplementedError
  180.  
  181. def get_symbolic_name(self, address):
  182. junk()
  183. return '0x%08X' % int(address)
  184.  
  185. def read(self, address, type = 'uint', maxlen = 50, errors='raise'):
  186. junk()
  187. if type == 's' or type == 'string':
  188. junk()
  189. s = self.read_bytes(int(address), bytes=maxlen)
  190. news = ''
  191. for c in s:
  192. junk()
  193. if c == '\x00':
  194. junk()
  195. return news
  196. news += c
  197. if errors=='ignore':
  198. junk()
  199. return news
  200. raise ProcessException('string > maxlen')
  201. else:
  202. if type == 'bytes' or type == 'b':
  203. junk()
  204. return self.read_bytes(int(address), bytes=1)
  205. s, l = type_unpack(type)
  206. return struct.unpack(s, self.read_bytes(int(address), bytes=l))[0]
  207.  
  208. def write(self, address, data, type = 'uint'):
  209. junk()
  210. if type != 'bytes':
  211. junk()
  212. s, l = type_unpack(type)
  213. return self.write_bytes(int(address), struct.pack(s, data))
  214. else:
  215. junk()
  216. return self.write_bytes(int(address), data)
  217. junk()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement