-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add __repr__ for capstone.CsInsn #1625
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
Conversation
Currently, a `print(instruction)` displays a not very useful string like `<capstone.CsInsn object at 0x7f3759d88128>`. This PR enhances adds a `__repr__` magic method to the `capstone.CsInsn` class so it displays as follows: ``` <cs.CsInsn: address=0x5555555545fa, size=1, mnemonic=push, op_str=rbp> ```
|
Let me know if you want any other/better format there. The one I choose here explicitly shows the properties one could use. Some other ideas:
|
|
nice, the second idea looks fine to me, but maybe we can also print all bytes in bytes field? |
Yup, that's a good idea. Below are some example outputs. Version AlphaThis version shows hex bytes. def __repr__(self):
return '<CsInsn 0x%x [%dB]: %s %s %s>' % (self.address, self.size, self.bytes.hex(), self.mnemonic, self.op_str)That gives: Version BravoThis version displays the hex bytes in def __repr__(self):
return '<CsInsn 0x%x [%dB] [%s]: %s %s>' % (self.address, self.size, self.bytes.hex(), self.mnemonic, self.op_str)Version CharlieThis version skips displaying the size in bytes. def __repr__(self):
return '<CsInsn 0x%x [%s]: %s %s>' % (self.address, self.bytes.hex(), self.mnemonic, self.op_str) |
|
@aquynh see some proposals above :) |
|
looks nice now, but why do you want to print the size? and with "B", which
seems abundant?
|
I initially printed the size to give more context but since we go towards displaying hex encoded bytes of the instruction, I don't think it is relevant anymore to do that. So, shall we go with version charlie? (I updated the PR to contain the charlie version). |
|
merged, thanks. |
* Add __repr__ for capstone.CsInsn Currently, a `print(instruction)` displays a not very useful string like `<capstone.CsInsn object at 0x7f3759d88128>`. This PR enhances adds a `__repr__` magic method to the `capstone.CsInsn` class so it displays as follows: ``` <cs.CsInsn: address=0x5555555545fa, size=1, mnemonic=push, op_str=rbp> ``` * Update __init__.py
* Add __repr__ for capstone.CsInsn Currently, a `print(instruction)` displays a not very useful string like `<capstone.CsInsn object at 0x7f3759d88128>`. This PR enhances adds a `__repr__` magic method to the `capstone.CsInsn` class so it displays as follows: ``` <cs.CsInsn: address=0x5555555545fa, size=1, mnemonic=push, op_str=rbp> ``` * Update __init__.py
We will e.g. have capstone-engine/capstone#1625 which is useful for debugging Pwndbg capstone related features
Currently, a
print(instruction)displays a not very useful string like:This PR enhances the display by adding a
__repr__magic method to thecapstone.CsInsnclass so it displays as follows: