ifisinstance(arch, str): self.arch = archinfo.arch_from_id(arch) # may raise ArchError, let the user see this elifisinstance(arch, archinfo.Arch): self.arch = arch elif arch isNone: self.arch = self.loader.main_object.arch else: raise ValueError("Invalid arch specification.")
第三步:获得默认信息,初始化一些属性
1 2 3 4 5
...... self.entry = self.loader.main_object.entry self.storage = defaultdict(list) self.store_function = store_function or self._store self.load_function = load_function or self._load
def_load_object_isolated(self, spec): ''' Given a partial specification of a dependency, this will return the loaded object as a backend instance. It will not touch any loader-global data.(没看懂) ''' #1. 验证文件backend(PE,ELF等等) full_spec = spec if 输入的spec是字符串(表示文件名): #单纯地 获取完整路径,没有别的操作 full_spec = self._search_load_path(spec) #2. 收集options 信息 options = ... ... #3. 验证 backend (判断是静态编译还是动态编译???没看懂) #(选择二进制的文件类型???) backend_spec = options.pop('backend', None) backend_cls = self._backend_resolver(backend_spec)#[^1] if backend_cls isNone: backend_cls = self._static_backend(full_spec) if backend_cls isNone: raise CLECompatibilityError("Unable to find a loader backend for %s. Perhaps try the 'blob' loader?" % spec) #4. 装载 return backend_cls(full_spec, is_main_bin=self.main_object isNone, loader=self, **options)#[^2] #返回值是,一个类的对象(ELF类等)
def_register_object(self, obj): """ Insert this object's clerical information into the loader 将对象的clerical information(????)插入到 loader中(???) """ self.requested_names.update(obj.deps) #deps是ELF类的一个列表属性,可能表示obj的依赖文件名 for ident in self._possible_idents(obj):#没看懂 self._satisfied_deps[ident] = obj
if obj.provides isnotNone: self.shared_objects[obj.provides] = obj
def_map_object(self, obj): """ This will integrate the object into the global address space, but will not perform relocations. 将对象集合到全局地址空间中,但是并不会处理重定位项(加载文件到内存) """ #以ELF文件为例,obj一般是backends.elf文件夹中 ELF类的对象