-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from string import ascii_letters, digits, punctuation | ||
|
||
def bufferToHex(buffer, start, count): | ||
accumulator = '' | ||
for item in range(count): | ||
accumulator += '%02X' % buffer[start + item] + ' ' | ||
return accumulator | ||
|
||
def bufferToAscii(buffer, start, count): | ||
accumulator = '' | ||
for item in range(count): | ||
char = chr(buffer[start + item]) | ||
if char in ascii_letters or \ | ||
char in digits or \ | ||
char in punctuation or \ | ||
char == ' ': | ||
accumulator += char | ||
else: | ||
accumulator += '.' | ||
return accumulator | ||
|
||
def dump(data, size = 16): | ||
bytesRead = len(data) | ||
index = 0 | ||
hexFormat = '{:'+str(size*3)+'}' | ||
asciiFormat = '{:'+str(size)+'}' | ||
|
||
print() | ||
while index < bytesRead: | ||
|
||
hex = bufferToHex(data, index, size) | ||
ascii = bufferToAscii(data, index, size) | ||
|
||
print(hexFormat.format(hex), end='') | ||
print('|',asciiFormat.format(ascii),'|') | ||
|
||
index += size | ||
if bytesRead - index < size: | ||
size = bytesRead - index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters