Пример #1
0
def make_chunk(words, mem_type):
    s = ""
    bs = byte_size(mem_type)
    for w in words:
        if not ishex(w):
            idaapi.error("Not a hex number: %s" % w)
        num = int(w, 16)
        # use little-endian byte order
        s += chr((num) & 0xFF)
        if bs > 1:
            s += chr((num >> 8) & 0xFF)
        if bs > 2:
            s += chr((num >> 16) & 0xFF)
        if bs > 3:
            s += chr((num >> 24) & 0xFF)
    return s
Пример #2
0
def make_chunk(words, mem_type):
    s = ""
    bs = byte_size(mem_type)
    for w in words:
      if not ishex(w):
        idaapi.error("Not a hex number: %s" % w)
      num = int(w, 16)
      # use little-endian byte order
      s += chr((num) & 0xFF)
      if bs > 1:
        s += chr((num>>8) & 0xFF)
      if bs > 2:
        s += chr((num>>16) & 0xFF)
      if bs > 3:
        s += chr((num>>24) & 0xFF)
    return s
Пример #3
0
def load_file(li, neflags, format):

    """
    Load the file into database

    @param li: a file-like object which can be used to access the input data
    @param neflags: options selected by the user, see loader.hpp
    @return: 0-failure, 1-ok
    """

    if format == FormatName:
        idaapi.set_processor_type("dsp56k", SETPROC_ALL | SETPROC_FATAL)
        li.seek(0)
        s = gets(li)
        minprog = BADADDR
        maxprog = 0
        start_addr = 0
        chunk = ""
        clist = ChunkList()
        while True:
            if s == None:
                break
            s = s.strip()
            if len(s) == 0 or s.startswith(" "):
                s = gets(li)
                continue
            words = s.split()
            if s.startswith("_START "):
                # skip
                s = gets(li)
                continue
            elif s.startswith("_DATA"):
                # _DATA <Memory space> <Address> <Code/data> ...
                if len(words) < 3:
                    idaapi.error("Bad _DATA record: %s" % s)
                # we handle only P (program) memory
                if not words[1] in ("P", "X", "Y"):
                    idaapi.error("Unhandled _DATA memory space: %s" % words[1])
                if not ishex(words[2]):
                    idaapi.error("Bad _DATA starting address: %s" % words[2])

                if len(chunk):
                    # append current chunk to the list
                    clist.add_chunk(start_addr, chunk, cur_mem)

                # start a new chunk
                cur_mem = words[1]
                start_addr = int(words[2], 16)
                chunk = make_chunk(words[3:], cur_mem)

                s = gets(li)
                continue
            elif s.startswith("_END"):
                if len(words) < 2 or not ishex(words[1]):
                    idaapi.error("Bad _END record: %s" % s)

                # append current chunk to the list
                clist.add_chunk(start_addr, chunk, cur_mem)

                # load all
                clist.load_to_idb()

                # add the entrypoint
                entry_ea = int(words[1], 16)
                idaapi.add_entry(entry_ea, entry_ea, "start", 1)
                break
            elif s.startswith("_"):
                idaapi.error("Unhandled record type: %s" % words[0])

            # we're inside a _DATA record
            chunk += make_chunk(words, cur_mem)
            s = gets(li)

        print "Load OK"
        return 1

    Warning("Unknown format name: '%s'" % format)
    return 0
Пример #4
0
def load_file(li, neflags, format):
    
    """
    Load the file into database

    @param li: a file-like object which can be used to access the input data
    @param neflags: options selected by the user, see loader.hpp
    @return: 0-failure, 1-ok
    """
    
    if format == FormatName:
        idaapi.set_processor_type("dsp56k", SETPROC_ALL|SETPROC_FATAL)
        li.seek(0)
        s = gets(li)
        minprog = BADADDR
        maxprog = 0
        start_addr = 0
        chunk = ""
        clist = ChunkList()
        while True:
            if s == None:
                break
            s = s.strip()
            if len(s) == 0 or s.startswith(" "):
                s = gets(li)
                continue
            words = s.split()
            if s.startswith("_START "):
                # skip
                s = gets(li)
                continue
            elif s.startswith("_DATA"):
                #_DATA <Memory space> <Address> <Code/data> ...
                if len(words) < 3:
                    idaapi.error("Bad _DATA record: %s" % s)
                # we handle only P (program) memory
                if not words[1] in ('P', 'X', 'Y'):
                    idaapi.error("Unhandled _DATA memory space: %s" % words[1])
                if not ishex(words[2]):
                    idaapi.error("Bad _DATA starting address: %s" % words[2])

                if len(chunk):
                  # append current chunk to the list
                  clist.add_chunk(start_addr, chunk, cur_mem)

                # start a new chunk
                cur_mem = words[1]
                start_addr = int(words[2], 16)
                chunk = make_chunk(words[3:], cur_mem)

                s = gets(li)
                continue
            elif s.startswith("_END"):
                if len(words) < 2 or not ishex(words[1]):
                    idaapi.error("Bad _END record: %s" % s)
                
                # append current chunk to the list
                clist.add_chunk(start_addr, chunk, cur_mem)

                # load all
                clist.load_to_idb()

                # add the entrypoint
                entry_ea = int(words[1], 16)
                idaapi.add_entry(entry_ea, entry_ea, "start", 1)
                break
            elif s.startswith("_"):
                idaapi.error("Unhandled record type: %s" % words[0])

            # we're inside a _DATA record
            chunk += make_chunk(words, cur_mem)
            s = gets(li)

        print "Load OK"
        return 1

    Warning("Unknown format name: '%s'" % format)
    return 0
Пример #5
0
 def handle_5x(brutal_self):
     idaapi.error('bTree error: Brutal. Just like the good ol\' days!')