-
Notifications
You must be signed in to change notification settings - Fork 0
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
lucascarvalhoroncoroni
committed
May 12, 2017
1 parent
70d1bbd
commit 1fc24a8
Showing
5 changed files
with
70 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#Hex Dump Program | ||
import argparse | ||
|
||
def HexDump(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("file", help="Specify File") | ||
parser.add_argument("-o", "--output", help="Print output to terminal"\ | ||
, action="store_true") | ||
args = parser.parse_args() | ||
|
||
if args.file: | ||
offset = 0 | ||
with open(args.file, 'rb') as infile: | ||
with open(args.file+".dump", 'w') as outfile: | ||
chunk = infile.read(16) | ||
while chunk != b'': | ||
if len(chunk) == 0: | ||
break | ||
|
||
text = '' | ||
for i in chunk: | ||
if i < 128 and i > 32: | ||
text = text + '' + chr(i) | ||
else: | ||
text = text + '.' | ||
|
||
output = "{:#08x}".format(offset) + ": " | ||
output += " ".join("{:02X}".format(ord('{}'.format(c)[0])) for c in chunk[:8]) | ||
output += " | " | ||
output += " ".join("{:02X}".format(ord('{}'.format(c)[0])) for c in chunk[8:]) | ||
if len(chunk) % 16 != 0: | ||
output += " "*(16 - len(chunk)) + text | ||
else: | ||
output += " " + text | ||
if args.output: | ||
print(output) | ||
outfile.write(output + '\n') | ||
|
||
offset += 16 | ||
chunk = infile.read(16) | ||
else: | ||
print(parser.usage) | ||
|
||
if __name__ == '__main__': | ||
HexDump() |
Binary file not shown.
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
Binary file not shown.