コード例 #1
0
ファイル: LibManager.py プロジェクト: thorfdbg/amitools
  def _create_native_lib(self, lib, load_name, ctx, tr):
    """load native lib from binary file and allocate memory"""

    # use seg_loader to load lib
    self.lib_log("load_lib","loading native lib: %s" % load_name)
    lib.seg_list = ctx.seg_loader.load_seg(None,load_name,local_path=True)
    if lib.seg_list == None:
      self.lib_log("load_lib","Can't load library file '%s'" % load_name, level=logging.ERROR)
      return None

    # check seg list for resident library struct
    seg0 = lib.seg_list.segments[0]
    ar = AmigaResident(seg0.addr, seg0.size, ctx.mem)
    start = time.clock()
    res_list = ar.find_residents()
    end = time.clock()
    delta = end - start;
    if res_list == None or len(res_list) != 1:
      self.lib_log("load_lib","No single resident in %s found!" % load_name, level=logging.ERROR)
      return None

    # make sure its a library
    res = res_list[0]
    if res['type'] != AmigaResident.NT_DEVICE and res['type'] != AmigaResident.NT_LIBRARY:
      self.lib_log("load_lib","Resident is not a library nor a device!", level=logging.ERROR)
      return None

    # resident is ok
    lib_name = res['name']
    lib_id = res['id']
    lib.mem_version = res['version']
    lib.auto_init = res['auto_init']
    init_ptr = res['init_ptr']
    self.lib_log("load_lib", "found resident: name='%s' id='%s' auto_init=%s init_ptr=%08x in %.4fs"
      % (lib_name, lib_id, lib.auto_init, init_ptr, delta), level=logging.DEBUG)

    # has RTF_AUTOINIT?
    if lib.auto_init:
      if not self._auto_init_native_lib(lib, ar, res, ctx, tr):
        return None
    # or has RT_INIT?
    elif init_ptr != 0:
      self._rtinit_native_lib(lib, ctx, tr, init_ptr)
    # hmm, no RTF_AUTOINIT and no RT_INIT?
    else:
      self.lib_log("load_lib", "neither RTF_AUTOINIT nor RT_INIT found!", level=logging.ERROR)
      return None

    return lib
コード例 #2
0
ファイル: LibManager.py プロジェクト: BSzili/amitools
  def _create_native_lib(self, lib, load_name, ctx, tr):
    """load native lib from binary file and allocate memory"""

    # use seg_loader to load lib
    self.lib_log("load_lib","loading native lib: %s" % load_name)
    lib.seg_list = ctx.seg_loader.load_seg(None,load_name)
    if lib.seg_list == None:
      self.lib_log("load_lib","Can't load library file '%s'" % load_name, level=logging.ERROR)
      return None

    # check seg list for resident library struct
    seg0 = lib.seg_list.segments[0]
    ar = AmigaResident(seg0.addr, seg0.size, ctx.mem)
    start = time.clock()
    res_list = ar.find_residents()
    end = time.clock()
    delta = end - start;
    if res_list == None or len(res_list) != 1:
      self.lib_log("load_lib","No single resident in %s found found!" % load_name, level=logging.ERROR)
      return None

    # make sure its a library
    res = res_list[0]
    if res['type'] != AmigaResident.NT_LIBRARY:
      self.lib_log("load_lib","Resident is not a library!", level=logging.ERROR)
      return None

    # resident is ok
    lib_name = res['name']
    lib_id = res['id']
    lib.mem_version = res['version']
    lib.auto_init = res['auto_init']
    init_ptr = res['init_ptr']
    self.lib_log("load_lib", "found resident: name='%s' id='%s' auto_init=%s init_ptr=%08x in %.4fs"
      % (lib_name, lib_id, lib.auto_init, init_ptr, delta), level=logging.DEBUG)

    # has RTF_AUTOINIT?
    if lib.auto_init:
      if not self._auto_init_native_lib(lib, ar, res, ctx, tr):
        return None
    # or has RT_INIT?
    elif init_ptr != 0:
      self._rtinit_native_lib(lib, ctx, tr, init_ptr)
    # hmm, no RTF_AUTOINIT and no RT_INIT?
    else:
      self.lib_log("load_lib", "neither RTF_AUTOINIT nor RT_INIT found!", level=logging.ERROR)
      return None

    return lib
コード例 #3
0
ファイル: LibManager.py プロジェクト: ilibz2012/amitools
  def load_native_lib(self, name, ver, context, tr):
    # use seg_loader to load lib
    self.lib_log("load_lib","Trying to load native lib: %s" % name)
    seg_list = context.seg_loader.load_seg(name)
    if seg_list == None:
      self.lib_log("load_lib","Can't load library file '%s'" % name, level=logging.ERROR)
      return None
    
    # check seg list for resident library struct
    seg0 = seg_list.segments[0]
    ar = AmigaResident(seg0.addr, seg0.size, context.mem)
    start = time.clock()
    res_list = ar.find_residents()
    end = time.clock()
    delta = end - start;
    if res_list == None or len(res_list) != 1:
      self.lib_log("load_lib","No single resident found!", level=logging.ERROR)
      return None
    
    # make sure its a library
    res = res_list[0]
    if res['type'] != AmigaResident.NT_LIBRARY:
      self.lib_log("load_lib","Resident is not a library!", level=logging.ERROR)
      return None
    
    # resident is ok
    lib_name = res['name']
    lib_id = res['id']
    lib_version = res['version']
    auto_init = res['auto_init']
    self.lib_log("load_lib", "found resident: name='%s' id='%s' in %.4fs" % (lib_name, lib_id, delta), level=logging.DEBUG)
    
    # read auto init infos
    if not ar.read_auto_init_data(res, context.mem):
      self.lib_log("load_lib","Error reading auto_init!", level=logging.ERROR)
      return None
    
    # get library base info
    vectors  = res['vectors']
    pos_size = res['dataSize']
    total_size = pos_size + len(vectors) * 6

    # now create a memory lib instance
    lib_mem = context.alloc.alloc_memory(lib_name, total_size, add_label=False)
    lib_addr = lib_mem.addr
    entry = LibEntry(lib_name, lib_version, lib_addr, len(vectors), pos_size, context.mem, self.label_mgr)
    entry.vectors = vectors
    lib_base = entry.lib_base

    # create a memory label
    label = LabelLib(lib_name, lib_addr, entry.size, lib_base, LibraryDef, entry)
    entry.label = label
    self.label_mgr.add_label(label)
  
    # setup lib instance memory
    hex_vec = map(lambda x:"%06x" % x, res['vectors'])
    self.lib_log("load_lib", "setting up vectors=%s" % hex_vec, level=logging.DEBUG)
    self.set_all_vectors(context.mem, lib_base, vectors)
    self.lib_log("load_lib", "setting up struct=%s and lib" % res['struct'], level=logging.DEBUG)
    ar.init_lib(res, entry, lib_base)
    self.lib_log("load_lib", "init_code=%06x dataSize=%06x" % (res['init_code_ptr'],res['dataSize']), level=logging.DEBUG)

    # do we need to call init code of lib?
    init_addr = res['init_code_ptr']
    if init_addr != 0:
      # now prepare to execute library init code
      # setup trampoline to call init routine of library
      # D0 = lib_base, A0 = seg_list, A6 = exec base
      exec_base = context.mem.read_mem(2,4)
      tr.save_all()
      tr.set_dx_l(0, lib_base)
      tr.set_ax_l(0, seg0.addr)
      tr.set_ax_l(6, exec_base)
      tr.jsr(init_addr)
      tr.restore_all()
      self.lib_log("load_lib", "trampoline: init @%06x (lib_base/d0=%06x seg_list/a0=%06x exec_base/a6=%06x)" % \
        (init_addr, lib_base, seg0.addr, exec_base), level=logging.DEBUG)
      
    # store native components
    entry.seg_list = seg_list

    # register lib
    self.native_libs[entry.name] = entry
    self.native_addr_map[lib_base] = entry

    # try to load fd file for library
    fd = self.load_fd(name)
    entry.fd = fd

    # return MemoryLib instance
    self.lib_log("load_lib", "Loaded native '%s' V%d: base=%06x label=%s" % (lib_name, lib_version, lib_base, label))
    return entry
コード例 #4
0
    def load_native_lib(self, name, ver, context, tr):
        # use seg_loader to load lib
        self.lib_log("load_lib", "Trying to load native lib: %s" % name)
        seg_list = context.seg_loader.load_seg(name)
        if seg_list == None:
            self.lib_log("load_lib",
                         "Can't load library file '%s'" % name,
                         level=logging.ERROR)
            return None

        # check seg list for resident library struct
        seg0 = seg_list.segments[0]
        ar = AmigaResident(seg0.addr, seg0.size, context.mem)
        start = time.clock()
        res_list = ar.find_residents()
        end = time.clock()
        delta = end - start
        if res_list == None or len(res_list) != 1:
            self.lib_log("load_lib",
                         "No single resident found!",
                         level=logging.ERROR)
            return None

        # make sure its a library
        res = res_list[0]
        if res['type'] != AmigaResident.NT_LIBRARY:
            self.lib_log("load_lib",
                         "Resident is not a library!",
                         level=logging.ERROR)
            return None

        # resident is ok
        lib_name = res['name']
        lib_id = res['id']
        lib_version = res['version']
        auto_init = res['auto_init']
        self.lib_log("load_lib",
                     "found resident: name='%s' id='%s' in %.4fs" %
                     (lib_name, lib_id, delta),
                     level=logging.DEBUG)

        # read auto init infos
        if not ar.read_auto_init_data(res, context.mem):
            self.lib_log("load_lib",
                         "Error reading auto_init!",
                         level=logging.ERROR)
            return None

        # get library base info
        vectors = res['vectors']
        pos_size = res['dataSize']
        total_size = pos_size + len(vectors) * 6

        # now create a memory lib instance
        lib_mem = context.alloc.alloc_memory(lib_name,
                                             total_size,
                                             add_label=False)
        lib_addr = lib_mem.addr
        entry = LibEntry(lib_name, lib_version, lib_addr, len(vectors),
                         pos_size, context.mem, self.label_mgr)
        entry.vectors = vectors
        lib_base = entry.lib_base

        # create a memory label
        label = LabelLib(lib_name, lib_addr, entry.size, lib_base, LibraryDef)
        entry.label = label
        self.label_mgr.add_label(label)

        # setup lib instance memory
        hex_vec = map(lambda x: "%06x" % x, res['vectors'])
        self.lib_log("load_lib",
                     "setting up vectors=%s" % hex_vec,
                     level=logging.DEBUG)
        self.set_all_vectors(context.mem, lib_base, vectors)
        self.lib_log("load_lib",
                     "setting up struct=%s and lib" % res['struct'],
                     level=logging.DEBUG)
        ar.init_lib(res, entry, lib_base)
        self.lib_log("load_lib",
                     "init_code=%06x dataSize=%06x" %
                     (res['init_code_ptr'], res['dataSize']),
                     level=logging.DEBUG)

        # do we need to call init code of lib?
        init_addr = res['init_code_ptr']
        if init_addr != 0:
            # now prepare to execute library init code
            # setup trampoline to call init routine of library
            # D0 = lib_base, A0 = seg_list, A6 = exec base
            exec_base = context.mem.read_mem(2, 4)
            tr.save_all()
            tr.set_dx_l(0, lib_base)
            tr.set_ax_l(0, seg0.addr)
            tr.set_ax_l(6, exec_base)
            tr.jsr(init_addr)
            tr.restore_all()
            self.lib_log("load_lib", "trampoline: init @%06x (lib_base/d0=%06x seg_list/a0=%06x exec_base/a6=%06x)" % \
              (init_addr, lib_base, seg0.addr, exec_base), level=logging.DEBUG)

        # store native components
        entry.seg_list = seg_list

        # register lib
        self.native_libs[entry.name] = entry
        self.native_addr_map[lib_base] = entry

        # return MemoryLib instance
        self.lib_log(
            "load_lib", "Loaded native '%s' V%d: base=%06x label=%s" %
            (lib_name, lib_version, lib_base, label))
        return entry
コード例 #5
0
ファイル: LibManager.py プロジェクト: rmtew/amitools
    def _create_native_lib(self, lib, load_name, ctx, tr):
        """load native lib from binary file and allocate memory"""

        # use seg_loader to load lib
        self.lib_log("load_lib", "loading native lib: %s" % load_name)
        lib.seg_list = ctx.seg_loader.load_seg(load_name)
        if lib.seg_list == None:
            self.lib_log("load_lib", "Can't load library file '%s'" % load_name, level=logging.ERROR)
            return None

        # check seg list for resident library struct
        seg0 = lib.seg_list.segments[0]
        ar = AmigaResident(seg0.addr, seg0.size, ctx.mem)
        start = time.clock()
        res_list = ar.find_residents()
        end = time.clock()
        delta = end - start
        if res_list == None or len(res_list) != 1:
            self.lib_log("load_lib", "No single resident found!", level=logging.ERROR)
            return None

        # make sure its a library
        res = res_list[0]
        if res["type"] != AmigaResident.NT_LIBRARY:
            self.lib_log("load_lib", "Resident is not a library!", level=logging.ERROR)
            return None

        # resident is ok
        lib_name = res["name"]
        lib_id = res["id"]
        lib.mem_version = res["version"]
        auto_init = res["auto_init"]
        self.lib_log(
            "load_lib", "found resident: name='%s' id='%s' in %.4fs" % (lib_name, lib_id, delta), level=logging.DEBUG
        )

        # read auto init infos
        if not ar.read_auto_init_data(res, ctx.mem):
            self.lib_log("load_lib", "Error reading auto_init!", level=logging.ERROR)
            return None

        # get library base info
        lib.vectors = res["vectors"]
        lib.mem_pos_size = res["dataSize"]
        lib.mem_neg_size = len(lib.vectors) * 6
        lib.is_native = True

        # allocate lib base
        lib.alloc_lib_base(ctx)
        self.lib_log("load_lib", "allocated %s" % lib)

        # setup lib instance memory
        hex_vec = map(lambda x: "%06x" % x, res["vectors"])
        self.lib_log("load_lib", "setting up vectors=%s" % hex_vec, level=logging.DEBUG)
        self._set_all_vectors(ctx.mem, lib.addr_base, lib.vectors)
        self.lib_log("load_lib", "setting up struct=%s and lib" % res["struct"], level=logging.DEBUG)
        ar.init_lib(res, lib, lib.addr_base)
        self.lib_log(
            "load_lib", "init_code=%06x dataSize=%06x" % (res["init_code_ptr"], res["dataSize"]), level=logging.DEBUG
        )

        # do we need to call init code of lib?
        init_addr = res["init_code_ptr"]
        if init_addr != 0:
            # now prepare to execute library init code
            # setup trampoline to call init routine of library
            # D0 = lib_base, A0 = seg_list, A6 = exec base
            exec_base = ctx.mem.read_mem(2, 4)
            tr.save_all()
            tr.set_dx_l(0, lib.addr_base)
            tr.set_ax_l(0, lib.seg_list.b_addr)  # baddr!
            tr.set_ax_l(6, exec_base)
            tr.jsr(init_addr)
            tr.restore_all()

            def trap_create_native_lib():
                self._create_native_lib_part2(lib, ctx)

            tr.trap(trap_create_native_lib)
            self.lib_log(
                "load_lib",
                "trampoline: init @%06x (lib_base/d0=%06x seg_list/a0=%06x exec_base/a6=%06x)"
                % (init_addr, lib.addr_base, seg0.addr, exec_base),
                level=logging.DEBUG,
            )
        else:
            self._create_native_lib_part2(lib, ctx)

        return lib