diff options
| author | Brian Potchik <brian@vector35.com> | 2019-03-14 17:48:10 -0400 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2019-03-14 17:48:10 -0400 |
| commit | 0b1529934c59645c895590997b919d2f0870f891 (patch) | |
| tree | dff5fcf27377f956625cff7bf61a7456b4237f1b /python/binaryview.py | |
| parent | 902750648579d32cc83fbd91181ecea2c9e0c9e5 (diff) | |
BinaryView API for entropy.
Diffstat (limited to 'python/binaryview.py')
| -rw-r--r-- | python/binaryview.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 6b373c27..361833d7 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2031,6 +2031,26 @@ class BinaryView(object): """ return core.BNRemoveViewData(self.handle, addr, length) + def get_entropy(self, addr, length, block_size=0): + """ + ``get_entropy`` returns the shannon entropy given the start ``addr``, ``length`` in bytes, and optionally in + ``block_size`` chunks. + + :param int addr: virtual address + :param int length: total length in bytes + :param int block_size: optional block size + :return: list of entropy values for each chunk` + :rtype: list of entropy values or an empty list + """ + if block_size == 0: + block_size = length + data = (ctypes.c_float * ((length // block_size) + 1))() + length = core.BNGetEntropy(self.handle, addr, length, block_size, data) + result = [] + for i in range(0, length): + result.append(float(data[i])) + return result + def get_modification(self, addr, length=None): """ ``get_modification`` returns the modified bytes of up to ``length`` bytes from virtual address ``addr``, or if |
