Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pymsasid import *
- class DataFragment:
- def __init__(self, data):
- self.data = data
- def __str__(self):
- out = []
- for d in self.data:
- out.append('%4s' % 'db')
- out.append('0x%02x' % ord(d))
- if ord(d) > 31 and ord(d) < 127:
- out.append(d)
- out.append('\n')
- return ''.join(out)
- def getHtml(self):
- return self.__str__()
- class CodeFragment:
- def __init__(self, data):
- self.data = data
- self.start = 0
- self.size = len(data)
- def __str__(self):
- #out = [title, '-' * len(title), '']
- out = []
- prog = pymsasid.Pymsasid(hook = pymsasid.BufferHook,
- source = self.data,
- mode = 32)
- prog.input.hook.base_address = self.start
- currentOffset = self.start
- instructions = []
- while currentOffset < self.start + self.size:
- instruction = prog.disassemble(currentOffset)
- currentOffset += instruction.size
- instructions.append(instruction)
- for instruction in instructions:
- addr = instruction.pc - instruction.size
- def operand_to_str(operand):
- address = None
- if operand.type == 'OP_JIMM':
- address = operand.lval + operand.pc
- if operand.type == 'OP_MEM' and operand.base is None:
- address = operand.lval + operand.pc
- return repr(operand)
- out.append(' [%08x] %-8s\t%s' % (addr, str(instruction.operator), ', '.join(map(operand_to_str, instruction.operand))))
- return '\n'.join(out) + '\n\n'
- def getHtml(self):
- return self.__str__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement