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

Fix hexdump_iter for actual file objects, like those used by phd #846

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pwnlib/util/fiddling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import base64
import random
import os
import re
import string
import StringIO
Expand Down Expand Up @@ -615,14 +616,15 @@ def hexdump_iter(fd, width=16, skip=True, hexii=False, begin=0, style=None,
total = fd.len
else:
# Save the current file offset
cur = fd.seek(0, os.SEEK_CUR)
cur = fd.tell()

# Determine the total size of the file
fd.seek(0, os.SEEK_END)
total = fd.tell()
total = fd.tell() - cur

# Restore the file offset, and
Copy link
Contributor

Choose a reason for hiding this comment

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

And what?

Copy link
Member Author

Choose a reason for hiding this comment

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

No "and", just a dangling lost thought in a comment.

This commit is cherry-picked from dev (f46112e), which has the same dangling comment -- but also has tests which pass.

fd.seek(cur or 0, os.SEEK_SET)

# Restore the file offset
fd.seek(cur, os.SEEK_SET)

if hexii:
column_sep = ''
Expand Down