-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Implement fit.Label() and associated plumbing #1063
Conversation
Interestingly, the output is wrong in the second case. The format string is not at offset EDIT: Fixed |
pwnlib/util/packing.py
Outdated
for arg in args: | ||
address = address + out.tell() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me: Isn't out.tell()
the amount of data written since the beginning, but address
here is the address of the last written argument? I think it should be initial_address + out.tell()
where initial_address
is set to the value of the address
parameter at the start of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this explains the wrong output of the second sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! 👍
pwnlib/util/packing.py
Outdated
for arg in args: | ||
address = address + out.tell() | ||
|
||
while isinstance(arg, type(lambda:0)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to check for callable
here to support functions as well as lambdas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should give precendence to __flat_at__
/ __flat__
in that case though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callable
can't be used because we use __call__
on Label
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be used if we check for __flat__
/ __flat_at__
first, because Label has those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't check for __flat__
etc. first, since we have to evaluate the callable / lambda before the check (or check again).
I added a special case check for FitLabel
in 9358429
return int(self._address or 0) | ||
|
||
@address.setter | ||
def address(self, new): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a way to "manually" set the address of a label, without causing an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when constructing the Label
via __init__
pwnlib/util/packing.py
Outdated
for arg in args: | ||
address = address + out.tell() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this explains the wrong output of the second sample.
c0a35dd
to
62adf18
Compare
What's the state of this? |
Very stalled 😛! If you're interested in continuing this PR, feel free to create a new branch from 9358429 and submit a new PR. |
Closing this out since the PR is two+ years old and has merge conflicts. Please rebase your changes on top of the current |
Label Examples
Let's start by inspecting the three important attributes of a :class:
.Label
,address
,contents
, andlength
.When used inside of a
fit()
expression behind alambda
, these fieldscan be automatically updated.
After
fit
completes the packing, the values can be extracted from the label.The above example only makes use of one label, but you can build more complicated
constructs fairly easy.