I want to write a script to extract the entropy of each sections of an EXE file. What is the best tool that I can use to do this? I tried Ghidra but it doesn't have an entropy API which I can use.
You can use
r2 to get the data and
r2pipe to script it.
iS entropy produce the entropy values for each section. Adding
j will produce it in JSON format and scripting it with
r2pipe is easy.
import r2pipe p = r2pipe.open('<path_to_exe>') res = p.cmdj('iSj entropy') print([(x['name'],x['entropy']) for x in res['sections']])
[('.text', '6.00602992'), ('.rdata', '3.94265366'), ('.data', '6.85876398'), ('.pdata', '3.46591559'), ('.rsrc', '4.70150326'), ('.reloc', '4.96848447')]