예제 #1
0
def cat_section(orc, section, offset=0):
    base = section.offset.int_value()

    program = ""
    for i in range(section.size.int_value() - offset):
        b = orc.data[base + offset + i]
        program += b.bin_str(padded=True)

    bs = BitStream(program)

    bs.cat()
예제 #2
0
def parse(filename):
    stream = BitStream.from_filename(filename)

    orc_header = read_text(stream)
    assert(orc_header == "orc")

    filetype, = stream.read_int(7)
    has_entry_point = read_bool(stream)

    # print(filetype)
    # print(has_entry_point)

    if has_entry_point == 1:
        entry_point = read_word(stream)
        # print("entry point:", entry_point, entry_point.hex_str(), entry_point.int_value())
    else:
        entry_point = None

    symbol_table = read_symbol_table(stream)
    relocation_table = read_relocation_table(stream)
    section_table = read_section_table(stream)
    segment_table = read_segment_table(stream)

    data = read_all(stream)

    orc = Orc(
        entry_point,
        symbol_table,
        relocation_table,
        section_table,
        segment_table,
        data
    )

    return orc
예제 #3
0
 def next_instruction(self):
     base_address = self.registers[Register.pc].int_value()
     bin_str = "".join([
         self.memory.read_byte(base_address + offset).bin_str(padded=True)
         for offset in range(6)  # max instruction size
     ])
     stream = BitStream(bin_str)
     return disassembler.disassemble_instruction(stream, strict=False)
예제 #4
0
def disassemble(filename):
    stream = BitStream.from_filename(filename)

    while not stream.is_empty():
        next_instruction = disassemble_instruction(stream)
        if not next_instruction: break

        print(next_instruction.human())
예제 #5
0
def disassemble(orc_path, segment_index):
    orc = orc_parser.parse(orc_path)
    segment = orc.segments[segment_index]

    base = segment.offset.int_value()
    program = ""
    for i in range(segment.size.int_value()):
        b1 = orc.data[base + i]
        program += b1.bin_str(padded=True)

    bs = BitStream(program)
    instruction = disassembler.disassemble_instruction(bs)
    while instruction:
        print(instruction.human())
        instruction = disassembler.disassemble_instruction(bs)
예제 #6
0
    def glob_instructions(self, base_address=None):
        if base_address is None:
            base_address = self.registers[Register.pc].int_value()

        failed = False
        instructions = []
        while not failed:
            bin_str = "".join([
                self.memory.read_byte(base_address +
                                      offset).bin_str(padded=True)
                for offset in range(6)  # max instruction size
            ])
            stream = BitStream(bin_str)
            instruction = disassembler.disassemble_instruction(stream,
                                                               strict=False)
            if instruction:
                instructions.append((base_address, instruction))
                base_address += instruction.size
            else:
                failed = True

        return instructions
예제 #7
0
def parse_to_instruction(text):
    bin_str = assemble_line(text)
    stream = BitStream(bin_str)
    instruction = disassembler.disassemble_instruction(stream)
    return instruction
예제 #8
0
def disassemble_hex(hex_str):
    bin_str = hex_parser.parse_hex_str(hex_str)
    instruction = disassemble_instruction(BitStream(bin_str))
    if instruction:
        print(instruction.human())