Index: diSlib64.py =================================================================== --- diSlib64.py (revision 919) +++ diSlib64.py (revision 927) @@ -85,9 +85,9 @@ class PEFile(object): def __init__(self, FileName, NewImageBase = None): """Filename can be either a file object or filename.""" - self.Imports = None - self.Exports = None - self.Relocs = None + self._Imports = None + self._Exports = None + self._Relocs = None # Holds the delta between the original ImageBase and the new one. self.Delta = 0 if isinstance(FileName, basestring): @@ -176,19 +176,32 @@ self.RelocationsSize = RelocationsSize self.RelocationsOff = RelocationsOff - if ImportsOff != 0: - self.ImportsOff = ImportsOff - self.Imports = self.LoadImports() + self.ImportsOff = ImportsOff + self.ExportsOff = ExportsOff - if ExportsOff != 0: - self.ExportsOff = ExportsOff - self.Exports = self.LoadExports() + def _GetImports(self): + if self._Imports != None or not self.ImportsOff: + return self._Imports + self._Imports = self.LoadImports() + return self._Imports - if RelocationsOff != 0: - self.Relocs = self.GetRelocations() - self.ApplyRelocations() + def _GetExports(self): + if self._Exports != None or not self.ExportsOff: + return self._Exports + self._Exports = self.LoadExports() + return self._Exports + def _GetRelocs(self): + if self._Relocs != None or not self.RelocationsOff: + return self._Relocs + self._Relocs = self.GetRelocations() + self.ApplyRelocations() + return self._Relocs + Imports = property(_GetImports) + Exports = property(_GetExports) + Relocs = property(_GetRelocs) + def GetSectionByVA(self, VA): for i in self.Sections: if (VA >= i.VA) and (VA < (i.VA + i.Size)): @@ -443,11 +456,11 @@ # Don't assume VA's are sorted properly. # We sort them out, because the algorithm for rebuilding the relocated section assumes # the relocation's addresses are from low to high addresses. - self.Relocs.sort(SortRelocCallback) + self._Relocs.sort(SortRelocCallback) # Hold relocations by their sections. Secs = [[] for i in xrange(len(self.Sections))] # Sort them into their corresponding section. - for i in self.Relocs: + for i in self._Relocs: Secs[i.Section.Index].append(i) # Eliminate empty sections (which don't have relocations). Secs = filter(lambda l: len(l), Secs)