Esempio n. 1
0
def loadExports(memBlock):
    addr = memBlock.getStart()
    while addr < memBlock.getEnd():
        print addr

        nfunc = memory.getShort(addr.add(0x6))

        func_libname = toAddr(memory.getInt(addr.add(0x10)))
        func_nidtable = toAddr(memory.getInt(addr.add(0x14)))
        func_table = toAddr(memory.getInt(addr.add(0x18)))

        try:
            listing.createData(func_libname, StringDataType())
        except:
            pass

        libname = listing.getDataAt(
            func_libname).getDefaultValueRepresentation().encode(
                'utf-8').strip("\"")
        print libname

        for x in xrange(nfunc):
            func_nid = memory.getInt(func_nidtable) & 0xffffffff
            func_ptr = toAddr(memory.getInt(func_table))

            try:
                listing.createData(func_nidtable, UnsignedIntegerDataType())
            except:
                pass
            try:
                listing.createData(func_table, Pointer32DataType())
            except:
                pass

            func_name = get_name_for_nid(func_nid, libname)
            print func_name
            if func_name != None:
                setEOLComment(func_nidtable, func_name)
                opd_func_ptr = toAddr(memory.getInt(func_ptr))
                func = listing.getFunctionAt(opd_func_ptr)
                if func != None:
                    func.setName(func_name, SourceType.ANALYSIS)
                else:
                    createFunction(opd_func_ptr, func_name)

            func_nidtable = func_nidtable.add(0x4)
            func_table = func_table.add(0x4)

        try:
            listing.createData(addr, libentstruc)
        except:
            pass

        addr = addr.add(0x1C)
Esempio n. 2
0
def addRegisters(peripheral_blk_struct, peripheral, min_size):
    for register in peripheral.registers:
        if (register._size >= min_size):
            print("register {:s} {:02X}".format(register.name, register._size))
            # check if the register is a member of the current addressBlock
            if ((register.address_offset >= adrBlock.offset) and
                (register.address_offset < adrBlock.offset + adrBlock.size)):
                register_size = 32 if not register._size else register._size
                r_type = UnsignedIntegerDataType()
                rs = register_size // 8
                if rs == 1:
                    r_type = ByteDataType()
                elif rs == 2:
                    r_type = UnsignedShortDataType()
                elif rs == 8:
                    r_type = UnsignedLongLongDataType()

                # please note: The address for registering here must be relative to the addressBlock address/offset
                peripheral_blk_struct.replaceAtOffset(
                    register.address_offset - adrBlock.offset, r_type,
                    register_size // 8, register.name, register.description)
    0x08: "Local Data",
    0x09: "Global Data",
    0x10: "Local BSS",
    0x11: "Global BSS",
    0x20: "Local Common symbol",
    0x21: "Global Common symbol",
    0x40: "Local Symbols",
    0x41: "Global Symbols"
}

# Init data type
ptr_data_type = PointerDataType()
byte_data_type = ByteDataType()
char_data_type = CharDataType()
void_data_type = VoidDataType()
unsigned_int_type = UnsignedIntegerDataType()
short_data_type = ShortDataType()
char_ptr_type = ptr_data_type.getPointer(char_data_type, 4)
void_ptr_type = ptr_data_type.getPointer(void_data_type, 4)
# Prepare VxWorks symbol types
vx_5_sym_enum = EnumDataType("Vx5symType", 1)
for flag in vx_5_symbol_type_enum:
    vx_5_sym_enum.add(vx_5_symbol_type_enum[flag], flag)
vx_6_sym_enum = EnumDataType("Vx6symType", 1)
for flag in vx_6_symbol_type_enum:
    vx_6_sym_enum.add(vx_6_symbol_type_enum[flag], flag)

# Init VxWorks symbol table structs
vx_5_symtbl_dt = StructureDataType("VX_5_SYMBOL_IN_TBL", 0x10)
vx_5_symtbl_dt.replaceAtOffset(0, unsigned_int_type, 4, "symHashNode", "")
vx_5_symtbl_dt.replaceAtOffset(4, char_ptr_type, 4, "symNamePtr", "")
Esempio n. 4
0
    # try:
    # Iterage registers to get size of peripheral
    # Most SVDs have an address-block that specifies the size, but
    # they are often far too large, leading to issues with overlaps.
    length = calculate_peripheral_size(peripheral, default_register_size)

    # Generate structure for the peripheral
    peripheral_struct = StructureDataType(peripheral.name, length)

    peripheral_start = peripheral.base_address
    peripheral_end = peripheral_start + length

    for register in peripheral.registers:
        register_size = default_register_size if not register._size else register._size

        r_type = UnsignedIntegerDataType()
        rs = register_size / 8
        if rs == 1:
            r_type = ByteDataType()
        elif rs == 2:
            r_type = UnsignedShortDataType()
        elif rs == 8:
            r_type = UnsignedLongLongDataType()

        peripheral_struct.replaceAtOffset(register.address_offset, r_type,
                                          register_size / 8, register.name,
                                          register.description)

    addr = space.getAddress(peripheral_start)

    dtm.addDataType(peripheral_struct, DataTypeConflictHandler.REPLACE_HANDLER)