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

Refactor pwndbg.commands.windbg.dX and pwndbg.hexdump.hexdump #1341

Merged
merged 17 commits into from
Oct 25, 2022

Conversation

ruijia-zhou
Copy link
Contributor

Replace the implementation of pwndbg.commands.windbg.dX with pwndbg.hexdump.hexdump, see issue #1280. The code in dX has been moved to dexdump. Some optional options have been added to the function signature of hexdump such that dX is implemented using a single call to hexdump.

@gsingh93
Copy link
Member

@ruijia-zhou, try running ./lint.sh -f to fix the lint issues, more details here: https://github.com/pwndbg/pwndbg/blob/dev/DEVELOPING.md#linting

@ruijia-zhou
Copy link
Contributor Author

Thanks for the information. Sorry for this. I am trying now.

@gsingh93 gsingh93 self-requested a review October 24, 2022 15:33
@gsingh93 gsingh93 self-assigned this Oct 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2022

Codecov Report

Merging #1341 (bc35e07) into dev (9411fc1) will decrease coverage by 0.05%.
The diff coverage is 61.90%.

❗ Current head bc35e07 differs from pull request most recent head 997c2dc. Consider uploading reports for the commit 997c2dc to get more accurate results

@@            Coverage Diff             @@
##              dev    #1341      +/-   ##
==========================================
- Coverage   54.87%   54.81%   -0.06%     
==========================================
  Files         153      153              
  Lines       19384    19423      +39     
  Branches     1815     1823       +8     
==========================================
+ Hits        10636    10646      +10     
- Misses       8298     8328      +30     
+ Partials      450      449       -1     
Impacted Files Coverage Δ
pwndbg/hexdump.py 68.99% <60.39%> (-22.82%) ⬇️
pwndbg/commands/windbg.py 85.33% <100.00%> (+0.68%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ruijia-zhou
Copy link
Contributor Author

@gsingh93 thanks a lot for the information. Just passed all checks.


if not to_string:
if not to_string and lines != []:
Copy link
Member

Choose a reason for hiding this comment

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

nit: the "Pythonic" way to do this is if not to_string and lines: https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty

I'd also accept len(lines) != 0, just because it'll catch type issues where lines is not a list (even though this isn't considered "Pythonic").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice, I will do it now


color_scheme = None
printable = None


def get_type(size):
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this function into pwndbg.gdblib.typeinfo? I think it makes more sense there and we probably want to use it in other places in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will do it now :)

address = int(address) & pwndbg.gdblib.arch.ptrmask
count = int(count)

type = get_type(size)
Copy link
Member

Choose a reason for hiding this comment

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

type is a built-in Python function. In the future we'll have a linter preventing names like this, so could you rename the variable to something else? If type really is the best name for this, we can go with something like type_.


else:

"""
Copy link
Member

Choose a reason for hiding this comment

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

Nit, generally these types of string comments only go at the top of a function, so in this case we should convert it to a normal comment with #.

for i in range(count):
try:
gval = pwndbg.gdblib.memory.poi(type, address + i * size)
# print(str(gval))
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove all the debugging code before merging this.

rows = [values[i * row_sz : (i + 1) * row_sz] for i in range(n_rows)]
lines = []

# sys.stdout.write(repr(rows) + '\n')
Copy link
Member

Choose a reason for hiding this comment

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

Same note about the debugging code.

@ruijia-zhou ruijia-zhou marked this pull request as draft October 24, 2022 17:03
@ruijia-zhou ruijia-zhou marked this pull request as ready for review October 24, 2022 17:11
@ruijia-zhou
Copy link
Contributor Author

Hi, @gsingh93 ,I have revised the code. Please have a look. Thanks!

@gsingh93 gsingh93 merged commit 45f8712 into pwndbg:dev Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants