def int_or_hex_cmp2(string): """ Returns an integer wheather the input string is a plain integer (123) or in hex format (0x123) """ try: if string.startswith("0x"): number = cmp2(int(string, 16)) else: number = int(string) & 0xffffffff except ValueError as ve: raise ArgumentTypeError("argument must be a number (hex or int)") return number
candidates = get_numbers(f, section_names, 0xffffffff, use_segment=use_segment, no_null_bytes=True) #candidates = get_numbers(f, section_names, slice_gaps[0][1], use_segment=True, no_null_bytes=True) f.close() coins = list(set(candidates.values())) pg = PayloadGenerator() if prologue: python_code += pg.add_prologue() first = True for gap in slice_gaps: # Not elegant, but for first element, remove the initial value of accumulator register if first: first_gap = list(gap) accumulator_value += first_gap[1] - 1 first_gap[1] = abs(cmp2(first_gap[1] - initial_reg_value)) print(first_gap[1]) gap = tuple(first_gap) first = False else: accumulator_value += gap[1] print(gap, hex(gap[1])) num_ops, nums = solve_gready(coins, gap[1]) print(num_ops, nums) print_results(candidates, nums) python_code += pg.add_payload(candidates, nums, stack_frame + gap[0]) python_code += '# Accumulator register has a final value of: %d => 0x%08x' % (accumulator_value, accumulator_value) print(python_code)
no_null_bytes=True) #candidates = get_numbers(f, section_names, slice_gaps[0][1], use_segment=True, no_null_bytes=True) f.close() coins = list(set(candidates.values())) pg = PayloadGenerator() if prologue: python_code += pg.add_prologue() first = True for gap in slice_gaps: # Not elegant, but for first element, remove the initial value of accumulator register if first: first_gap = list(gap) accumulator_value += first_gap[1] - 1 first_gap[1] = abs(cmp2(first_gap[1] - initial_reg_value)) print(first_gap[1]) gap = tuple(first_gap) first = False else: accumulator_value += gap[1] print(gap, hex(gap[1])) num_ops, nums = solve_gready(coins, gap[1]) print(num_ops, nums) print_results(candidates, nums) python_code += pg.add_payload(candidates, nums, stack_frame + gap[0]) python_code += '# Accumulator register has a final value of: %d => 0x%08x' % ( accumulator_value, accumulator_value) print(python_code)