def __getAllgadgets(self): if self.__checksBeforeManipulations() == False: return False G = Gadgets(self.__binary, self.__options, self.__offset) execSections = self.__binary.getExecSections() # Find ROP/JOP/SYS gadgets self.__gadgets = [] for section in execSections: if not self.__options.norop: self.__gadgets += G.addROPGadgets(section) if not self.__options.nojop: self.__gadgets += G.addJOPGadgets(section) if not self.__options.nosys: self.__gadgets += G.addSYSGadgets(section) # Pass clean single instruction and unknown instructions self.__gadgets = G.passClean(self.__gadgets, self.__options.multibr) # Delete duplicate gadgets if not self.__options.all: self.__gadgets = rgutils.deleteDuplicateGadgets(self.__gadgets) # Applicate some Options self.__gadgets = Options(self.__options, self.__binary, self.__gadgets).getGadgets() # Sorted alphabetically self.__gadgets = rgutils.alphaSortgadgets(self.__gadgets) return True
def __getGadgets(self): if self.__checksBeforeManipulations() == False: return False G = Gadgets(self.__binary, self.__options, self.__offset) execSections = self.__binary.getExecSections() # Find ROP/JOP/SYS gadgets self.__gadgets = [] for section in execSections: section = self._sectionInRange(section) if not section: continue if not self.__options.norop: self.__gadgets += G.addROPGadgets(section) if not self.__options.nojop: self.__gadgets += G.addJOPGadgets(section) if not self.__options.nosys: self.__gadgets += G.addSYSGadgets(section) # Delete duplicate gadgets if not self.__options.all and not self.__options.noinstr: self.__gadgets = rgutils.deleteDuplicateGadgets(self.__gadgets) # Applicate some Options self.__gadgets = Options(self.__options, self.__binary, self.__gadgets).getGadgets() # Sorted alphabetically if not self.__options.noinstr: self.__gadgets = rgutils.alphaSortgadgets(self.__gadgets) return True
config = [ '--binary', os.path.join(pe_dir, f), '--all', '--nojop', '--nosys', ] rg_args = Args(config).getArgs() rg_bin = Binary(rg_args) G = Gadgets(rg_bin, rg_args, rg_offset) exec_sections = rg_bin.getExecSections() rg_gadgets = [] for section in exec_sections: rg_gadgets += G.addROPGadgets(section) rg_gadgets = G.passClean(rg_gadgets, rg_args.multibr) rg_gadgets = Options(rg_args, rg_bin, rg_gadgets).getGadgets() # --------------------- if not ropper_parsing_error: rs.setArchitectureFor(name=f, arch='x86') rs.loadGadgetsFor(name=f) rp_gadgets = rs.getFileFor(f).gadgets rp_gadgets.sort(key=attrgetter('address')) print 'Found {} gadgets!'.format(len(rp_gadgets)) rs.setImageBaseFor(name=f, imagebase=0x0) else: rp_gadgets = [] rp_len = len(rp_gadgets) rg_len = len(rg_gadgets) rp = True