Advertisement
wandrake

Untitled

Nov 24th, 2012
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. from pymsasid import *
  2.  
  3. class DataFragment:
  4. def __init__(self, data):
  5. self.data = data
  6.  
  7. def __str__(self):
  8. out = []
  9.  
  10. for d in self.data:
  11. out.append('%4s' % 'db')
  12. out.append('0x%02x' % ord(d))
  13. if ord(d) > 31 and ord(d) < 127:
  14. out.append(d)
  15. out.append('\n')
  16.  
  17. return ''.join(out)
  18.  
  19. def getHtml(self):
  20. return self.__str__()
  21.  
  22. class CodeFragment:
  23. def __init__(self, data):
  24. self.data = data
  25. self.start = 0
  26. self.size = len(data)
  27.  
  28. def __str__(self):
  29. #out = [title, '-' * len(title), '']
  30. out = []
  31. prog = pymsasid.Pymsasid(hook = pymsasid.BufferHook,
  32. source = self.data,
  33. mode = 32)
  34.  
  35. prog.input.hook.base_address = self.start
  36. currentOffset = self.start
  37.  
  38. instructions = []
  39.  
  40. while currentOffset < self.start + self.size:
  41. instruction = prog.disassemble(currentOffset)
  42. currentOffset += instruction.size
  43. instructions.append(instruction)
  44.  
  45. for instruction in instructions:
  46. addr = instruction.pc - instruction.size
  47.  
  48. def operand_to_str(operand):
  49. address = None
  50.  
  51. if operand.type == 'OP_JIMM':
  52. address = operand.lval + operand.pc
  53.  
  54. if operand.type == 'OP_MEM' and operand.base is None:
  55. address = operand.lval + operand.pc
  56.  
  57. return repr(operand)
  58.  
  59.  
  60. out.append(' [%08x] %-8s\t%s' % (addr, str(instruction.operator), ', '.join(map(operand_to_str, instruction.operand))))
  61.  
  62. return '\n'.join(out) + '\n\n'
  63.  
  64. def getHtml(self):
  65. return self.__str__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement