def do_asm(self, text): if not text: self.help_asm() return text = text.strip() format = 'H' if text[-2:] in (' H', ' R', ' S'): format = text[-1:] text = text[:-2] arch = None if text.startswith('-a'): text = text[3:] index = text.index(' ') arch = text[:index] text = text[index:] arch = getArchitecture(arch) if not arch: if self.__binary: arch = self.binary.arch else: arch = getArchitecture('x86') self.__asm(text, arch, format)
def setArchitectureFor(self, name, arch): file = self.getFileFor(name) if not file: raise RopperError('No such file opened: %s' % name) file.loader.arch = getArchitecture(arch) if file.loaded: self.loadGadgetsFor(name)
def asm(self, code, arch='x86', format='hex'): if format not in ('hex', 'string', 'raw'): raise RopperError( 'Invalid format: %s\n Valid formats are: hex, string, raw' % format) format = Format.HEX if format == 'hex' else Format.STRING if format == 'string' else Format.RAW return self.ropper.assemble(code, arch=getArchitecture(arch), format=format)
def addFile(self, name, bytes=None, arch=None, raw=False): if self._getFileFor(name): raise RopperError('file is already added: %s' % name) if arch: arch=getArchitecture(arch) loader = Loader.open(name, bytes=bytes, raw=raw, arch=arch) file = FileContainer(loader) self.__files.append(file)
def do_disasm(self, text): if not text: self.help_disasm() return arch = None if text.startswith('-a'): text = text[3:] index = text.index(' ') arch = text[:index] text = text[index:].strip() arch = getArchitecture(arch) if not arch: if self.__binary: arch = self.binary.arch else: arch = getArchitecture('x86') self.__disasm(text, arch)
def addFile(self, name, bytes=None, arch=None, raw=False): if self._getFileFor(name): raise RopperError('file is already added: %s' % name) if arch: arch=getArchitecture(arch) loader = Loader.open(name, bytes=bytes, raw=raw, arch=arch) if len(self.__files) > 0 and self.__files[0].loader.arch != loader.arch: raise RopperError('It is not supported to open file with different architectures! Loaded: %s; File to open: %s' % (str(self.__files[0].loader.arch), str(loader.arch))) file = FileContainer(loader) self.__files.append(file)
def addFile(self, name, bytes=None, arch=None, raw=False): if self._getFileFor(name): raise RopperError('file is already added: %s' % name) if arch: arch = getArchitecture(arch) loader = Loader.open(name, bytes=bytes, raw=raw, arch=arch) if len(self.__files ) > 0 and self.__files[0].loader.arch != loader.arch: raise RopperError( 'It is not supported to open file with different architectures! Loaded: %s; File to open: %s' % (str(self.__files[0].loader.arch), str(loader.arch))) file = FileContainer(loader) self.__files.append(file)
def do_disasm(self, text): if not text: self.help_disasm() return arch = None if text.startswith('-a'): text = text[3:] index = text.index(' ') arch = text[:index] text = text[index:].strip() arch = getArchitecture(arch) if not arch: if self.__currentFileName: arch = str(self.currentFile.arch) else: arch = 'x86' self.__disasm(text, arch)
def __setarch(self, arch): if self.binary: self.binary.arch = getArchitecture(arch) self.__options.arch = arch else: self.__printError('No file loaded')
def asm(self, code, arch='x86', format='hex'): if format not in ('hex', 'string', 'raw'): raise RopperError('Invalid format: %s\n Valid formats are: hex, string, raw' % format) format = Format.HEX if format=='hex' else Format.STRING if format=='string' else Format.RAW return self.ropper.assemble(code, arch=getArchitecture(arch), format=format)
def __handleOptions(self, options): if options.sections: self.__printData('sections') elif options.symbols: self.__printData('symbols') elif options.segments: self.__printData('segments') elif options.dllcharacteristics: self.__printData('dll_characteristics') elif options.imagebase: self.__printData('image_base') elif options.e: self.__printData('entry_point') elif options.imports: self.__printData('imports') elif options.asm: code = options.asm[0] format = 'H' if len(options.asm) == 2: code = options.asm[0] format = options.asm[1] arch = getArchitecture('x86') if options.arch: arch = getArchitecture(options.arch) self.__asm(code, arch, format) elif options.disasm: code = options.disasm arch = getArchitecture('x86') if options.arch: arch = getArchitecture(options.arch) self.__disasm(code, arch) elif options.set: self.__set(options.set, True) elif options.unset: self.__set(options.unset, False) elif options.info: self.__printData('informations') elif options.ppr: self.__searchPopPopRet() elif options.jmp: self.__searchJmpReg(options.jmp) elif options.stack_pivot: self.__loadGadgets() self.__printGadgets(self.__binary.gadgets, Category.STACK_PIVOT) elif options.opcode: self.__searchOpcode(self.__options.opcode) elif options.instructions: self.__searchInstructions(self.__options.instructions) elif options.string: self.__printStrings(options.string, options.section) elif options.hex and options.section: self.__printSectionInHex(options.section) elif options.disassemble_address: split = options.disassemble_address.split(':') length = 1 if not isHex(split[0]): raise RopperError('Number have to be in hex format 0x....') if len(split) > 1: if split[1][1:].isdigit() or (len(split[1]) >= 3 and split[1][1] == '-' and split[1][2:].isdigit()): # is L\d or L-\d length = int(split[1][1:]) else: raise RopperError('Length have to be in the following format L + Number e.g. L3') self.__disassembleAddress(int(split[0],16), length) #elif options.checksec: # self.__checksec() elif options.chain: self.__loadGadgets() self.__generateChain(self.__gadgets[self.binary], options.chain) elif options.db: self.__loaddb(options.db) self.__searchAndPrintGadgets() else: self.__loadGadgets() self.__searchAndPrintGadgets()
def disasm(self, opcode, arch='x86'): return self.ropper.disassemble(opcode, arch=getArchitecture(arch))