Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created August 11, 2019 04:49
Show Gist options
  • Save kohnakagawa/aa37f1385f06805964cf840dfe2050a7 to your computer and use it in GitHub Desktop.
Save kohnakagawa/aa37f1385f06805964cf840dfe2050a7 to your computer and use it in GitHub Desktop.
r2pipe を使ってセクションのエントロピーを計算し、パックされているものがあった場合には表示する
import r2pipe
import glob
import os
target_path = "data/malware"
def is_packed(entropy):
return any(filter(lambda x: x > 6.8, entropy))
cnt = 0
cnt_pck = 0
for f in glob.glob(os.path.join(target_path, "*")):
r = r2pipe.open(f)
entropy = list(map(lambda x: float(x[8:]), filter(lambda x: "entropy" in x, r.cmd("iS entropy").split())))
print(entropy)
if is_packed(entropy):
cnt_pck += 1
cnt += 1
print(f"{cnt} {cnt_pck}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment