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 memory slicing #1151

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Conversation

wtdcode
Copy link
Member

@wtdcode wtdcode commented May 8, 2022

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added.
  • The reference of the new code is pointed out.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • [] This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing


This is one of several efforts to make the current wrapper more pythonic to fix unicorn-engine/unicorn#201.

This PR makes ql.mem support slicing.

Copy link
Member

@elicn elicn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

qiling/os/memory.py Outdated Show resolved Hide resolved
qiling/os/memory.py Outdated Show resolved Hide resolved
qiling/os/memory.py Show resolved Hide resolved
qiling/os/memory.py Outdated Show resolved Hide resolved
qiling/os/memory.py Outdated Show resolved Hide resolved
qiling/os/memory.py Outdated Show resolved Hide resolved
@wtdcode wtdcode mentioned this pull request May 10, 2022
15 tasks

return self.ql.mem.read(start, max(0, stop - start))
elif isinstance(key, int):
return self.ql.mem.read(key, 1)[0]
Copy link

@LukeSerne LukeSerne May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line returns an int, not bytearray, which is somewhat counterintuitive, inconsistent with the case where a slice is given as argument, and goes against the type annotation. I think you should remove the [0]. Also, I'm not sure why this code uses self.ql.mem instead of self. In this class, they reference / point to the same thing, right?

Suggested change
return self.ql.mem.read(key, 1)[0]
return self.read(key, 1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line returns an int, not bytearray, which is somewhat counterintuitive. I think you should remove the [0].

Because we (try to) provide the same interface as bytearray, e.g.:

In [1]: a = bytearray(b"\x01\x02")

In [2]: type(a[0])
Out[2]: int

In [3]:

Also, I'm not sure why this code uses self.ql.mem instead of self. In this class, they reference / point to the same thing, right?

Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants