Created
May 23, 2017 23:56
-
-
Save fuwac/36354c66dcb5649486aa884590ec22fa to your computer and use it in GitHub Desktop.
バイナリ走査するやつ
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
# coding: UTF-8 | |
import sys | |
import os | |
param = sys.argv # 引数とってくる | |
prg_start_addr = 3 # 探索開始アドレス | |
fin = open(param[1], "rb") # 引数1のファイル読み込み(読み込み専用バイナリ) | |
fin.seek(prg_start_addr) # 探索開始アドレスまで移動 | |
# 1Byteずつ読み込み | |
while True: | |
b = fin.read(1) # 1Byte読み込み(seek+=1) | |
if not b: break # ファイル終端と判断して終わり | |
print("{0:08X}:{1}".format(fin.tell(), hex(ord(b)) )) # アドレスとバイト値をデバッグ出力 | |
# ケツから遡上してみるパティーン | |
fin.seek(0, os.SEEK_END) # ファイルの一番ケツにseek | |
fin.seek(fin.tell() - 1) # 1個前に戻る | |
while True: | |
b = fin.read(1) # 1Byte読み込み(seek+=1) | |
if (fin.tell() <= prg_start_addr): break # 開始点に到達したので終わり! | |
print("{0:08X}:{1}".format(fin.tell(), hex(ord(b)) )) # アドレスとバイト値をデバッグ出力 | |
fin.seek(fin.tell() - 2) # seek -= 2 | |
fin.close() # おわり |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment