Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Generators and Comprehension #771

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 20 additions & 22 deletions gef.py
Expand Up @@ -2310,7 +2310,7 @@ def is_conditional_branch(self, insn):
def is_branch_taken(self, insn):
mnemo = insn.mnemonic
# ref: http://www.davespace.co.uk/arm/introduction-to-arm/conditional.html
flags = dict((self.flags_table[k], k) for k in self.flags_table)
flags = {self.flags_table[k]: k for k in self.flags_table}
val = get_register(self.flag_register)
taken, reason = False, ""

Expand Down Expand Up @@ -2527,7 +2527,7 @@ def is_conditional_branch(self, insn):
def is_branch_taken(self, insn):
mnemo = insn.mnemonic
# all kudos to fG! (https://github.com/gdbinit/Gdbinit/blob/master/gdbinit#L1654)
flags = dict((self.flags_table[k], k) for k in self.flags_table)
flags = {self.flags_table[k]: k for k in self.flags_table}
val = get_register(self.flag_register)

taken, reason = False, ""
Expand Down Expand Up @@ -2692,7 +2692,7 @@ def is_conditional_branch(self, insn):

def is_branch_taken(self, insn):
mnemo = insn.mnemonic
flags = dict((self.flags_table[k], k) for k in self.flags_table)
flags = {self.flags_table[k]: k for k in self.flags_table}
val = get_register(self.flag_register)
taken, reason = False, ""
if mnemo == "beq": taken, reason = val&(1<<flags["equal[7]"]), "E"
Expand Down Expand Up @@ -2795,7 +2795,7 @@ def is_conditional_branch(self, insn):

def is_branch_taken(self, insn):
mnemo = insn.mnemonic
flags = dict((self.flags_table[k], k) for k in self.flags_table)
flags = {self.flags_table[k]: k for k in self.flags_table}
val = get_register(self.flag_register)
taken, reason = False, ""

Expand Down Expand Up @@ -3185,7 +3185,7 @@ def get_process_maps_linux(proc_map_file):
inode = rest[0]
pathname = rest[1].lstrip()

addr_start, addr_end = [int(x, 16) for x in addr.split("-")]
addr_start, addr_end = (int(x, 16) for x in addr.split("-"))
off = int(off, 16)
perm = Permission.from_process_maps(perm)

Expand Down Expand Up @@ -3222,7 +3222,7 @@ def get_info_sections():

try:
parts = [x for x in line.split()]
addr_start, addr_end = [int(x, 16) for x in parts[1].split("->")]
addr_start, addr_end = (int(x, 16) for x in parts[1].split("->"))
off = int(parts[3][:-1], 16)
path = parts[4]
inode = ""
Expand Down Expand Up @@ -3346,7 +3346,7 @@ def xor(data, key):
"""Return `data` xor-ed with `key`."""
key = key.lstrip("0x")
key = binascii.unhexlify(key)
return bytearray([x ^ y for x, y in zip(data, itertools.cycle(key))])
return bytearray(x ^ y for x, y in zip(data, itertools.cycle(key)))


def is_hex(pattern):
Expand Down Expand Up @@ -3855,13 +3855,11 @@ def db(t, p):
yield alphabet[a[j]]
else:
a[t] = a[t - p]
for c in db(t + 1, p):
yield c
yield from db(t + 1, p)

for j in range(a[t - p] + 1, k):
a[t] = j
for c in db(t + 1, t):
yield c
yield from db(t + 1, t)

return db(1, 1)

Expand Down Expand Up @@ -4760,7 +4758,7 @@ def do_invoke(self, argv, *args, **kwargs):
# When the process is already on, set real breakpoints immediately
if is_alive():
vmmap = get_process_maps()
base_address = [x.page_start for x in vmmap if x.path == get_filepath()][0]
base_address = next(x.page_start for x in vmmap if x.path == get_filepath())
for bp_ins in __pie_breakpoints__.values():
bp_ins.instantiate(base_address)
return
Expand Down Expand Up @@ -4860,7 +4858,7 @@ def do_invoke(self, argv):
unhide_context()
gdb.execute("set stop-on-solib-events 0")
vmmap = get_process_maps()
base_address = [x.page_start for x in vmmap if x.path == get_filepath()][0]
base_address = next(x.page_start for x in vmmap if x.path == get_filepath())
info("base address {}".format(hex(base_address)))

# modify all breakpoints
Expand Down Expand Up @@ -4891,7 +4889,7 @@ def do_invoke(self, argv):
# after attach, we are stopped so that we can
# get base address to modify our breakpoint
vmmap = get_process_maps()
base_address = [x.page_start for x in vmmap if x.path == get_filepath()][0]
base_address = next(x.page_start for x in vmmap if x.path == get_filepath())

for bp_ins in __pie_breakpoints__.values():
bp_ins.instantiate(base_address)
Expand All @@ -4915,7 +4913,7 @@ def do_invoke(self, argv):
# after remote attach, we are stopped so that we can
# get base address to modify our breakpoint
vmmap = get_process_maps()
base_address = [x.page_start for x in vmmap if x.realpath == get_filepath()][0]
base_address = next(x.page_start for x in vmmap if x.realpath == get_filepath())

for bp_ins in __pie_breakpoints__.values():
bp_ins.instantiate(base_address)
Expand Down Expand Up @@ -5730,8 +5728,8 @@ def parsed_arglist(arglist):
main_base_address = main_end_address = 0
else:
vmmap = get_process_maps()
main_base_address = min([x.page_start for x in vmmap if x.realpath == get_filepath()])
main_end_address = max([x.page_end for x in vmmap if x.realpath == get_filepath()])
main_base_address = min(x.page_start for x in vmmap if x.realpath == get_filepath())
main_end_address = max(x.page_end for x in vmmap if x.realpath == get_filepath())

try:
if method_name == "sync":
Expand Down Expand Up @@ -5761,8 +5759,8 @@ def synchronize(self):
"""Submit all active breakpoint addresses to IDA/BN."""
pc = gef.arch.pc
vmmap = get_process_maps()
base_address = min([x.page_start for x in vmmap if x.path == get_filepath()])
end_address = max([x.page_end for x in vmmap if x.path == get_filepath()])
base_address = min(x.page_start for x in vmmap if x.path == get_filepath())
end_address = max(x.page_end for x in vmmap if x.path == get_filepath())
if not (base_address <= pc < end_address):
# do not sync in library
return
Expand Down Expand Up @@ -8105,7 +8103,7 @@ def set_init_tbreak_pie(self, addr, argv):
unhide_context()
gdb.execute("set stop-on-solib-events 0")
vmmap = get_process_maps()
base_address = [x.page_start for x in vmmap if x.path == get_filepath()][0]
base_address = next(x.page_start for x in vmmap if x.path == get_filepath())
return self.set_init_tbreak(base_address + addr)


Expand Down Expand Up @@ -9980,8 +9978,8 @@ def do_invoke(self, argv):
# getting vmmap to understand the boundaries of the main binary
# we will use this info to understand if a function has been resolved or not.
vmmap = get_process_maps()
base_address = min([x.page_start for x in vmmap if x.path == get_filepath()])
end_address = max([x.page_end for x in vmmap if x.path == get_filepath()])
base_address = min(x.page_start for x in vmmap if x.path == get_filepath())
end_address = max(x.page_end for x in vmmap if x.path == get_filepath())

# get the checksec output.
checksec_status = checksec(get_filepath())
Expand Down