Skip to content

Commit 362c2d3

Browse files
committed
fix: asm() using the incorrect assembler for amd64 architecture
1 parent 8b30517 commit 362c2d3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

pwnlib/asm.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,37 @@ def which_binutils(util, check_version=False):
177177
Exception: Could not find 'as' installed for ContextType(arch = 'msp430')
178178
"""
179179
arch = context.arch
180+
machine = platform.machine()
181+
182+
if arch == "amd64":
183+
pattern = "*86*64*-*-{}".format(util)
184+
185+
for dir in environ["PATH"].split(os.pathsep):
186+
for res in sorted(glob(path.join(dir, pattern))):
187+
if check_version:
188+
ver = check_binutils_version(res)
189+
return res, ver
190+
return res
191+
192+
# if target is native, try native command (e.g. "as")
193+
if machine in ("x86_64", "amd64"):
194+
for dir in environ["PATH"].split(os.pathsep):
195+
res = path.join(dir, util)
196+
if os.path.exists(res) and os.access(res, os.X_OK):
197+
if check_version:
198+
ver = check_binutils_version(res)
199+
return res, ver
200+
return res
201+
202+
pattern = "i*86*-*-{}".format(util)
203+
for dir in environ["PATH"].split(os.pathsep):
204+
for res in sorted(glob(path.join(dir, pattern))):
205+
if check_version:
206+
ver = check_binutils_version(res)
207+
return res, ver
208+
return res
209+
210+
print_binutils_instructions(util, context)
180211

181212
# Fix up pwntools vs Debian triplet naming, and account
182213
# for 'thumb' being its own pwntools architecture.
@@ -195,7 +226,6 @@ def which_binutils(util, check_version=False):
195226

196227
# If one of the candidate architectures matches the native
197228
# architecture, use that as a last resort.
198-
machine = platform.machine()
199229
machine = 'i386' if machine == 'i686' else machine
200230
try:
201231
with context.local(arch = machine):

0 commit comments

Comments
 (0)