def load(args): global helpStr global loaded # Parse arguments and filename filename = None user_arch = None i = 0 seenArch = False if (not args): print(helpStr) return while i < len(args): if (args[i] in [OPTION_ARCH, OPTION_ARCH_SHORT]): if (seenArch): error("Option {} can be used only one time"\ .format(args[i])) return seenArch = True if (i + 1 == len(args)): error("Missing argument after {}.\n\tType 'load -h' for help"\ .format(args[i])) return elif (args[i + 1] == Arch.ArchX86.name): user_arch = Arch.ArchX86 elif (args[i + 1] == Arch.ArchX64.name): user_arch = Arch.ArchX64 else: error("Unknown architecture: {}".format(args[i + 1])) return i += 2 elif (args[i] in [OPTION_HELP, OPTION_HELP_SHORT]): print(helpStr) return else: filename = args[i] break if (not filename): error("Missing filename.\n\tType 'load help' for help") return # Test if the file exists if (not os.path.isfile(filename)): error("Error. Could not find file '{}'".format(filename)) return print('') info(string_bold("Extracting gadgets from file") + " '" + filename + "'\n") # Cleaning the data structures initDB() Arch.reinit() # Get architecture and OS info arch = getPlatformInfo(filename) if (arch == user_arch == None): error("Error. Could not determine architecture") return elif (arch and user_arch and (arch != user_arch)): error("Error. Conflicting architectures") print("\tUser supplied: " + user_arch.name) print("\tFound: " + arch.name) return elif (arch): Arch.setArch(arch) else: Arch.setArch(user_arch) # Init the binary scanner initScanner(filename) # Extract the gadget list gadgetList = getGadgets(filename) if (not gadgetList): return # Build the gadget database # (we mix the list so that charging bar # appears to grow steadily ) r = random() shuffle(gadgetList, lambda: r) build(gadgetList) # Init engine initEngine() loaded = True
def load(args): global helpStr global loaded # Parse arguments and filename filename = None user_arch = None i = 0 seenArch = False seenRopgadget = False ropgadget_options = '' if (not args): print(helpStr) return while i < len(args): if (args[i] in [OPTION_ARCH, OPTION_ARCH_SHORT]): if (seenArch): error("Option {} can be used only one time"\ .format(args[i])) return seenArch = True if (i + 1 == len(args)): error("Missing argument after {}.\n\tType 'load -h' for help"\ .format(args[i])) return elif (args[i + 1] == Arch.ArchX86.name): user_arch = Arch.ArchX86 elif (args[i + 1] == Arch.ArchX64.name): user_arch = Arch.ArchX64 else: error("Unknown architecture: {}".format(args[i + 1])) return i += 2 elif (args[i] in [OPTION_ROPGADGET_OPTIONS, OPTION_ROPGADGET_OPTIONS_SHORT]): if (seenRopgadget): error("Option {} can be used only one time"\ .format(args[i])) return seenRopgadget = True ropgadget_options = '' if (i + 1 == len(args)): error("Missing argument after {}.\n\tType 'load -h' for help"\ .format(args[i])) return j = i + 1 # Read the argments if (args[j][0] != "'"): error("ROPgadget options must be given between '' ") return if (args[j][-1] == "'" and len(args[j]) != 1): ropgadget_options += args[j][1:-1] else: ropgadget_options += args[j][1:] j += 1 closed_ok = False while (j < len(args)): if (args[j][0] != "'"): if (args[j][-1] == "'"): ropgadget_options += " " + args[j][0:-1] closed_ok = True break elif ("'" in args[j]): error( "ROPgadget options: You must leave a space after the closing '" ) return else: ropgadget_options += " " + args[j] else: if (len(args[j]) > 1): error( "ROPgadget options: You must leave a space after the closing \'" ) return else: closed_ok = True break j += 1 if (not closed_ok): error("ROPgadget options: missing closing \'") return i = j + 1 elif (args[i] in [OPTION_HELP, OPTION_HELP_SHORT]): print(helpStr) return else: filename = args[i] break if (not filename): error("Missing filename.\n\tType 'load help' for help") return # Test if the file exists if (not os.path.isfile(filename)): error("Error. Could not find file '{}'".format(filename)) return print('') info(string_bold("Extracting gadgets from file") + " '" + filename + "'\n") # Cleaning the data structures initDB() Arch.reinit() # Get architecture and OS info arch = getPlatformInfo(filename) if (arch == user_arch == None): error("Error. Could not determine architecture") return elif (arch and user_arch and (arch != user_arch)): error("Error. Conflicting architectures") print("\tUser supplied: " + user_arch.name) print("\tFound: " + arch.name) return elif (arch): Arch.setArch(arch) else: Arch.setArch(user_arch) # Init the binary scanner initScanner(filename) # Extract the gadget list gadgetList = getGadgets(filename, ropgadget_options) if (not gadgetList): return # Build the gadget database # (we mix the list so that charging bar # appears to grow steadily ) r = random() shuffle(gadgetList, lambda: r) build(gadgetList) # Init engine initEngine() loaded = True