Skip to content

Commit 248f451

Browse files
authored
Support asm/disasm on Windows (#2437)
* Support asm/disasm on Windows Find binutils toolchains like https://gnutoolchains.com/ if they exist in the PATH. * Update CHANGELOG * Update binutils install docs * cpp reads from stdin when no infile is given No need for a tempfile here.
1 parent de67c86 commit 248f451

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ The table below shows which release corresponds to each branch, and what date th
9090
- [#2427][2427] Document behaviour of remote()'s sni argument as string.
9191
- [#2382][2382] added optional port, gdb_args and gdbserver_args parameters to gdb.debug()
9292
- [#2435][2435] Speed up gdbserver handshake in gdb.debug()
93+
- [#2437][2437] Support asm/disasm on Windows
9394

9495
[2371]: https://github.com/Gallopsled/pwntools/pull/2371
9596
[2360]: https://github.com/Gallopsled/pwntools/pull/2360
@@ -109,6 +110,7 @@ The table below shows which release corresponds to each branch, and what date th
109110
[2427]: https://github.com/Gallopsled/pwntools/pull/2405
110111
[2382]: https://github.com/Gallopsled/pwntools/pull/2382
111112
[2435]: https://github.com/Gallopsled/pwntools/pull/2435
113+
[2437]: https://github.com/Gallopsled/pwntools/pull/2437
112114

113115
## 4.13.0 (`beta`)
114116

docs/source/install/binutils.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ repo <https://github.com/Gallopsled/pwntools-binutils/>`__.
4242
$ wget https://raw.githubusercontent.com/Gallopsled/pwntools-binutils/master/macos/binutils-$ARCH.rb
4343
$ brew install ./binutils-$ARCH.rb
4444
45+
Windows
46+
^^^^^^^^^^^^^^^^
47+
48+
Windows support is experimental. You can try installing a prebuilt version of binutils
49+
for your desired architecture from the `GNU Toolchains <https://gnutoolchains.com/>`__ project.
50+
4551
Alternate OSes
4652
^^^^^^^^^^^^^^^^
4753

pwnlib/asm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ def which_binutils(util, check_version=False):
206206
if platform.system() == 'Darwin':
207207
utils = ['g'+util, util]
208208

209+
if platform.system() == 'Windows':
210+
utils = [util + '.exe']
211+
209212
for arch in arches:
210213
for gutil in utils:
211214
# e.g. objdump
@@ -220,7 +223,7 @@ def which_binutils(util, check_version=False):
220223
'%s-%s' % (arch, gutil)]
221224

222225
for pattern in patterns:
223-
for dir in environ['PATH'].split(':'):
226+
for dir in environ['PATH'].split(os.pathsep):
224227
for res in sorted(glob(path.join(dir, pattern))):
225228
if check_version:
226229
ver = check_binutils_version(res)
@@ -457,15 +460,19 @@ def cpp(shellcode):
457460
>>> cpp("SYS_setresuid", os = "freebsd")
458461
'311\n'
459462
"""
463+
if platform.system() == 'Windows':
464+
cpp = which_binutils('cpp')
465+
else:
466+
cpp = 'cpp'
467+
460468
code = _include_header() + shellcode
461469
cmd = [
462-
'cpp',
470+
cpp,
463471
'-C',
464472
'-nostdinc',
465473
'-undef',
466474
'-P',
467475
'-I' + _incdir,
468-
'/dev/stdin'
469476
]
470477
return _run(cmd, code).strip('\n').rstrip() + '\n'
471478

0 commit comments

Comments
 (0)