Gallopsled / Gallopsled/pwntools

`context.bits` will not automatically switch when setting `context.arch` twice.

Open
#2,498 4 comments 0 reactions 0 assignees Claimed by @danstam View on GitHub
backport-required bug good first issue
Dominant language
Python
Stars
13.7k
Forks
1.9k
Avg merge
6d 23h
Merged PRs (30d)
3

Description

> I was using IPython to do some quick poc work that time, first I switched `context.arch` to `'amd64'` and assembled `cdqe` and then I suddenly would like to try what if I assemble `cdqe` in 32-bit mode. So I switched `context.arch` back to `'i386'` and wanted to assemble, only to find an error: `AttributeError: Invalid arch/bits combination: i386/64`

Pwntools may can not handle `context.arch` correctly, it could change `context.bits` accordingly when first setting it. However, when setting `context.arch` the second time, `context.bits` left unchanged. I guess this bug is related to `self._tls`?

poc:

![屏幕截图_20241111_003054](https://github.com/user-attachments/assets/f4d816a8-40fc-4935-a20c-9dc20e596387)

one more poc:

```py
from pwn import *
print(f"{context.arch}/{context.bits}")
context.arch = 'amd64'
print(f"{context.arch}/{context.bits}")
context.arch = 'i386'
print(f"{context.arch}/{context.bits}")
```

Contributor guide

Open the contributing guide

Research direction

Start by running the two Python reproductions in the issue and inspect the handling of context.arch and context.bits, including the suspected self._tls state. Done means switching from amd64 to i386 updates the displayed bits to 32 and allows cdqe-related assembly without an invalid arch/bits error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.