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

Support asm/disasm on Windows #2437

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2427][2427] Document behaviour of remote()'s sni argument as string.
- [#2382][2382] added optional port, gdb_args and gdbserver_args parameters to gdb.debug()
- [#2435][2435] Speed up gdbserver handshake in gdb.debug()
- [#2437][2437] Support asm/disasm on Windows

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

## 4.13.0 (`beta`)

Expand Down
6 changes: 6 additions & 0 deletions docs/source/install/binutils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ repo <https://github.com/Gallopsled/pwntools-binutils/>`__.
$ wget https://raw.githubusercontent.com/Gallopsled/pwntools-binutils/master/macos/binutils-$ARCH.rb
$ brew install ./binutils-$ARCH.rb

Windows
^^^^^^^^^^^^^^^^

Windows support is experimental. You can try installing a prebuilt version of binutils
for your desired architecture from the `GNU Toolchains <https://gnutoolchains.com/>`__ project.

Alternate OSes
^^^^^^^^^^^^^^^^

Expand Down
13 changes: 10 additions & 3 deletions pwnlib/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def which_binutils(util, check_version=False):
if platform.system() == 'Darwin':
utils = ['g'+util, util]

if platform.system() == 'Windows':
utils = [util + '.exe']
Arusekk marked this conversation as resolved.
Show resolved Hide resolved

for arch in arches:
for gutil in utils:
# e.g. objdump
Expand All @@ -220,7 +223,7 @@ def which_binutils(util, check_version=False):
'%s-%s' % (arch, gutil)]

for pattern in patterns:
for dir in environ['PATH'].split(':'):
for dir in environ['PATH'].split(os.pathsep):
for res in sorted(glob(path.join(dir, pattern))):
if check_version:
ver = check_binutils_version(res)
Expand Down Expand Up @@ -457,15 +460,19 @@ def cpp(shellcode):
>>> cpp("SYS_setresuid", os = "freebsd")
'311\n'
"""
if platform.system() == 'Windows':
peace-maker marked this conversation as resolved.
Show resolved Hide resolved
cpp = which_binutils('cpp')
else:
cpp = 'cpp'

code = _include_header() + shellcode
cmd = [
'cpp',
cpp,
'-C',
'-nostdinc',
'-undef',
'-P',
'-I' + _incdir,
'/dev/stdin'
]
return _run(cmd, code).strip('\n').rstrip() + '\n'

Expand Down