Loading ropperapp/loaders/mach_intern/mach_gen.py +15 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,19 @@ from ctypes import * from ropperapp.disasm.arch import * class VM_PROT(Enum): READ = 0x1 WRITE = 0x2 EXEC = 0x4 def shortString(self, perm): toReturn = '' toReturn += 'R' if perm & int(self.READ) > 0 else ' ' toReturn += 'W' if perm & int(self.WRITE) > 0 else ' ' toReturn += 'E' if perm & int(self.EXEC) > 0 else ' ' return toReturn class TypeFlags(Enum): MASK = 0xff000000 Loading Loading @@ -125,10 +138,12 @@ class S_ATTR(Enum): SOME_INSTRUCTIONS = 0x00000400 PURE_INSTRUCTIONS = 0x80000000 class LoadCommand(LittleEndianStructure): _fields_ = [('cmd', c_uint), ('cmdsize', c_uint)] class UuidCommand(LittleEndianStructure): _fields_ = [('cmd', c_uint), ('cmdsize', c_uint), Loading ropperapp/loaders/mach_o.py +10 −3 Original line number Diff line number Diff line Loading @@ -24,14 +24,20 @@ import importlib class SegmentData(DataContainer): """ struct = SectionHeader struct = SegmentCommand name = string (section name) bytes = c_byte_array (section bytes) """ class LoaderData(DataContainer): """ struct = SectionHeader struct = LoaderCommand """ class SectionData(DataContainer): """ struct = Section """ Loading Loading @@ -79,6 +85,7 @@ class MachO(Loader): for loaderCommand in self.loaderCommands: if loaderCommand.struct.cmd == LC.SEGMENT or loaderCommand.struct.cmd == LC.SEGMENT_64: for section in loaderCommand.sections: section = section.struct if section.flags & S_ATTR.SOME_INSTRUCTIONS > 0 or section.flags & S_ATTR.PURE_INSTRUCTIONS: sectbytes_p = c_void_p(self._bytes_p.value + section.offset) sectbytes = cast(sectbytes_p, POINTER(c_ubyte * section.size)).contents Loading @@ -104,7 +111,7 @@ class MachO(Loader): p_tmp.value += sizeof(self.__module.Section) sections.append(sec) sections.append(SectionData(struct=sec)) return sections Loading ropperapp/printer/machprinter.py +47 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,53 @@ class MachOPrinter(FileDataPrinter): self._printTable('Mach-O Header', ('Name', 'Value'), data) def printSegments(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: lc = lc.struct if lc.cmd == LC.SEGMENT or lc.cmd == LC.SEGMENT_64: data.append((lc.segname, self._toHex(lc.vmaddr, binary.arch.addressLength), self._toHex(lc.vmsize), self._toHex(lc.fileoff), self._toHex(lc.filesize), VM_PROT.shortString(lc.maxprot), VM_PROT.shortString(lc.initprot))) self._printTable('Segment Commands',('Name', 'VAddr', 'VSize', 'FOffset', 'FSize','Maxprot', 'Initprot'), data) def printSections(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: if lc.struct.cmd == LC.SEGMENT or lc.struct.cmd == LC.SEGMENT_64: for section in lc.sections: section = section.struct data.append((section.sectname, section.segname, self._toHex(section.addr, binary.arch.addressLength), self._toHex(section.size), self._toHex(section.offset), self._toHex(section.align), self._toHex(section.nreloc), self._toHex(section.reloff))) self._printTable('Sections', ('Name','Segment', 'Address','Size','Offset','Align','Nr. of Relocs','RelocOffset'), data) def printLoaderCommands(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: lc = lc.struct data.append((LC[lc.cmd], self._toHex(lc.cmdsize))) self._printTable('Loader Commands', ('Type', 'Size'), data) def printEntryPoint(self, binary): self._printLine(self._toHex(binary.entryPoint, binary.arch.addressLength)) Loading Loading
ropperapp/loaders/mach_intern/mach_gen.py +15 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,19 @@ from ctypes import * from ropperapp.disasm.arch import * class VM_PROT(Enum): READ = 0x1 WRITE = 0x2 EXEC = 0x4 def shortString(self, perm): toReturn = '' toReturn += 'R' if perm & int(self.READ) > 0 else ' ' toReturn += 'W' if perm & int(self.WRITE) > 0 else ' ' toReturn += 'E' if perm & int(self.EXEC) > 0 else ' ' return toReturn class TypeFlags(Enum): MASK = 0xff000000 Loading Loading @@ -125,10 +138,12 @@ class S_ATTR(Enum): SOME_INSTRUCTIONS = 0x00000400 PURE_INSTRUCTIONS = 0x80000000 class LoadCommand(LittleEndianStructure): _fields_ = [('cmd', c_uint), ('cmdsize', c_uint)] class UuidCommand(LittleEndianStructure): _fields_ = [('cmd', c_uint), ('cmdsize', c_uint), Loading
ropperapp/loaders/mach_o.py +10 −3 Original line number Diff line number Diff line Loading @@ -24,14 +24,20 @@ import importlib class SegmentData(DataContainer): """ struct = SectionHeader struct = SegmentCommand name = string (section name) bytes = c_byte_array (section bytes) """ class LoaderData(DataContainer): """ struct = SectionHeader struct = LoaderCommand """ class SectionData(DataContainer): """ struct = Section """ Loading Loading @@ -79,6 +85,7 @@ class MachO(Loader): for loaderCommand in self.loaderCommands: if loaderCommand.struct.cmd == LC.SEGMENT or loaderCommand.struct.cmd == LC.SEGMENT_64: for section in loaderCommand.sections: section = section.struct if section.flags & S_ATTR.SOME_INSTRUCTIONS > 0 or section.flags & S_ATTR.PURE_INSTRUCTIONS: sectbytes_p = c_void_p(self._bytes_p.value + section.offset) sectbytes = cast(sectbytes_p, POINTER(c_ubyte * section.size)).contents Loading @@ -104,7 +111,7 @@ class MachO(Loader): p_tmp.value += sizeof(self.__module.Section) sections.append(sec) sections.append(SectionData(struct=sec)) return sections Loading
ropperapp/printer/machprinter.py +47 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,53 @@ class MachOPrinter(FileDataPrinter): self._printTable('Mach-O Header', ('Name', 'Value'), data) def printSegments(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: lc = lc.struct if lc.cmd == LC.SEGMENT or lc.cmd == LC.SEGMENT_64: data.append((lc.segname, self._toHex(lc.vmaddr, binary.arch.addressLength), self._toHex(lc.vmsize), self._toHex(lc.fileoff), self._toHex(lc.filesize), VM_PROT.shortString(lc.maxprot), VM_PROT.shortString(lc.initprot))) self._printTable('Segment Commands',('Name', 'VAddr', 'VSize', 'FOffset', 'FSize','Maxprot', 'Initprot'), data) def printSections(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: if lc.struct.cmd == LC.SEGMENT or lc.struct.cmd == LC.SEGMENT_64: for section in lc.sections: section = section.struct data.append((section.sectname, section.segname, self._toHex(section.addr, binary.arch.addressLength), self._toHex(section.size), self._toHex(section.offset), self._toHex(section.align), self._toHex(section.nreloc), self._toHex(section.reloff))) self._printTable('Sections', ('Name','Segment', 'Address','Size','Offset','Align','Nr. of Relocs','RelocOffset'), data) def printLoaderCommands(self, binary): lcs = binary.loaderCommands data = [] for lc in lcs: lc = lc.struct data.append((LC[lc.cmd], self._toHex(lc.cmdsize))) self._printTable('Loader Commands', ('Type', 'Size'), data) def printEntryPoint(self, binary): self._printLine(self._toHex(binary.entryPoint, binary.arch.addressLength)) Loading