Created
February 11, 2013 09:00
-
-
Save TyOverby/4753365 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/python | |
| # Documentation: | |
| # Takes a byte-stream on input and | |
| # produces the hex values that would | |
| # produce those bytes if ran through the | |
| # sendstring program. | |
| # | |
| # example usage: | |
| # cat smoke.bytes | python byte2str.python | |
| # cat smoke.bytes | python byte2str.python > smoke.txt | |
| # | |
| # This program is usefull if you have lost your original | |
| # text file, if you generate the bytes in an external | |
| # program, or if you just pipe stdin to a file like | |
| # a real programmer. | |
| import sys | |
| def conv(input): | |
| for c in input: | |
| h = hex(ord(c))[2:] | |
| if (len(h) < 2): | |
| h = "0" + h | |
| yield h | |
| arr = [x for x in conv(sys.stdin.read())] | |
| print " ".join(arr[:-1]) |
This file contains hidden or 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
| #!/bin/python | |
| # Documentation: | |
| # Takes a "stack" as produced by the gdb command | |
| # and makes a more readable one. | |
| # 'x/10xg $sp' prints the last 10 8-byte integers | |
| # on the stack, but it looks fairly ugly as you can | |
| # see. | |
| # (gdb) x/10xg $sp | |
| # 0x7fffffffb630: 0x1abzzzzzzzzzz848 0x230zzzzzzzzzzzzd | |
| # 0x7fffffffb640: 0xaaaazzzzzzzzzz60 0xaaaaaaaaaaaaaaaa | |
| # 0x7fffffffb650: 0xaaaaaaaaaaaaaaaa 0xaaaaaaaaaaaaaaaa | |
| # 0x7fffffffb660: 0xaaaaaaaaaaaaaaaa 0x0zzzzzzzzzzzzz30 | |
| # 0x7fffffffb670: 0x000000zzzzzzz050 0x00zzzzzzzzzzzeef | |
| # after being run through stackify.py, it would be | |
| # transformed into the following | |
| # $ python stackify.py | |
| # 0x0000zzzzzzzzzzef <- this stack looks like the stack | |
| # 0x00zzzzzzzzzzzz50 diagrams that we've been looking | |
| # 0x00007fffffffb630 at in class, unlike the above one | |
| # 0xaaaaaaaaaaaaaaaa produced by gdb. | |
| # 0xaaaaaaaaaaaaaaaa | |
| # 0xaaaaaaaaaaaaaaaa | |
| # 0xaaaaaaaaaaaaaaaa | |
| # 0xaaaaaaaazzzzzzz0 | |
| # 0x2zzzzzzzzzzzzzed | |
| # 0x1zzzzzzzzzzzzz48 | |
| # You can enter the gdb stack into stackify by pasting | |
| # the gdb stack into the stdin from stackify (remember to | |
| # hit [enter] and then [ctrl][d] to signal file end), or | |
| # you can save the stack into a file and then pipe | |
| # cat saved_stack.txt | python stackify.py | |
| import sys | |
| def stackify(input): | |
| lines = input.split("\n") | |
| individ = [] | |
| for section in lines: | |
| broken = section.split(" ") | |
| individ += broken[1:] | |
| return individ[::-1] | |
| want = filter(lambda x: len(x)> 0, stackify(sys.stdin.read())) | |
| print "\n".join(want) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment