Skip to content

Commit f1f1b05

Browse files
committed
simplify code
1 parent a225ecf commit f1f1b05

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

pwnlib/elf/elf.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,14 +1164,11 @@ def libc_start_main_return(self):
11641164
to list all calls inside __libc_start_main, find the call to exit
11651165
after the call to main and select the previous call.
11661166
"""
1167-
if '__libc_start_main' not in self.functions:
1167+
func = self.functions.get('__libc_start_main')
1168+
exit_addr = self.symbols.get('exit')
1169+
if not (func and exit_addr):
11681170
return 0
11691171

1170-
if 'exit' not in self.symbols:
1171-
return 0
1172-
1173-
func = self.functions['__libc_start_main']
1174-
exit_addr = self.symbols['exit']
11751172
# `__libc_start_call_main` is usually smaller than `__libc_start_main`,
11761173
# (except for powerpc which uses a bigger `generic_start_main`), so
11771174
# we might disassemble a bit too much, but it's a good dynamic estimate.
@@ -1184,9 +1181,8 @@ def libc_start_main_return(self):
11841181
call_return_offset = 1
11851182
call_instructions = set([cs.CS_GRP_CALL])
11861183
if self.arch in ['arm', 'thumb']:
1187-
if b'armhf' in self.linker:
1188-
# FIXME: I have no idea why setting self.arch = 'armhf' does not work
1189-
eabi = 'hf'
1184+
# FIXME: I have no idea why setting self.arch = 'armhf' does not work
1185+
if b'armhf' in self.linker: eabi = 'hf'
11901186
if exit_addr & 1: exit_addr -= 1
11911187
elif self.arch == 'aarch64':
11921188
pass
@@ -1197,9 +1193,8 @@ def libc_start_main_return(self):
11971193
pass
11981194
elif self.arch in ['ppc', 'powerpc', 'powerpc64']:
11991195
callee_size *= 2
1200-
if exit_addr & 1 == 0:
1201-
# powepc often jumps to the local entry point after TOC setup
1202-
exit_addr += 8
1196+
# powepc often jumps to the local entry point after TOC setup
1197+
if exit_addr & 1 == 0: exit_addr += 8
12031198
pass
12041199
elif self.arch in ['em_s390', 's390']:
12051200
imm_index = 1
@@ -1215,10 +1210,10 @@ def libc_start_main_return(self):
12151210
filter_calls = lambda dis: ((i, x) for i, x in enumerate(dis) if call_instructions & set(x.groups))
12161211

12171212
if self.arch in ['ppc', 'powerpc', 'powerpc64']:
1218-
filter_calls = lambda dis: ((i, x) for i, x in enumerate(dis) if set([x.mnemonic]) & set(['bctrl', 'bl']))
1213+
filter_calls = lambda dis: ((i, x) for i, x in enumerate(dis) if x.mnemonic in ['bctrl', 'bl'])
12191214
# FIXME: `bal` was not included in CS_GRP_CALL. This is fixed on capstone v6.alpha
12201215
elif self.arch in ['mips', 'mips64']:
1221-
filter_calls = lambda dis: ((i, x) for i, x in enumerate(dis) if set([x.mnemonic]) & set(['bal', 'jalr']))
1216+
filter_calls = lambda dis: ((i, x) for i, x in enumerate(dis) if x.mnemonic in ['bal', 'jalr'])
12221217

12231218
calls = list(filter_calls(dis))
12241219

0 commit comments

Comments
 (0)