Skip to content

Commit 69cf37a

Browse files
committed
Filled in README
1 parent 6ad307d commit 69cf37a

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,45 @@
1313
This library implements multiple plot types for illustrating executable samples. It currently supports the PE, ELF and Mach-O formats, relying on [`lief`](https://github.com/lief-project/LIEF) for abstracting them.
1414

1515
```sh
16-
pip install exeplot
16+
$ pip install exeplot
1717
```
1818

19-
## :sunglasses: Usage
19+
## :sunglasses: Usage Examples
2020

21-
TODO
21+
Draw a byte plot of `calc_packed.exe`:
22+
23+
```sh
24+
$ exeplot byte calc_packed.exe
25+
```
26+
27+
![Byte plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_byte.png?raw=true)
28+
29+
Draw a pie plot of `calc_packed.exe`:
30+
31+
```sh
32+
$ exeplot pie calc_packed.exe
33+
```
34+
35+
![Pie plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_pie.png?raw=true)
36+
37+
Draw a nested pie plot of `calc_packed.exe`:
38+
39+
```sh
40+
$ exeplot nested_pie calc_packed.exe
41+
```
42+
43+
![Nested pie plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_nested_pie.png?raw=true)
44+
45+
Draw a stacked and scaled entropy plot of `calc_orig.exe` and `calc_packed.exe`:
46+
47+
```sh
48+
$ exeplot entropy calc_orig.exe calc_packed.exe
49+
```
50+
51+
![Entropy plot of `calc_orig.exe` and `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_orig_entropy.png?raw=true)
2252

2353

24-
## :clap: Supporters
54+
## :clap: Supporters
2555

2656
[![Stargazers repo roster for @packing-box/python-exeplot](https://reporoster.com/stars/dark/packing-box/python-exeplot)](https://github.com/packing-box/python-exeplot/stargazers)
2757

173 KB
Loading
1.66 MB
Loading
99.9 KB
Loading

docs/pages/img/calc_packed_pie.png

91.8 KB
Loading

src/exeplot/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.3.3

src/exeplot/utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,38 @@ def human_readable_size(size, precision=0):
2828
return "%.*f%s" % (precision, size, units[i])
2929

3030

31-
def ngrams_counts(byte_obj, n=1):
31+
def ngrams_counts(byte_obj, n=1, step=1):
3232
""" Output the Counter instance for an input byte sequence or byte object based on n-grams.
3333
If the input is a byte object, cache the result.
3434
35+
:param byte_obj: byte sequence ('bytes') or byte object with "bytes" and "size" attributes (i.e. pathlib2.Path)
3536
:param n: n determining the size of n-grams, defaults to 1
37+
:param step: step for sliding the n-grams
3638
"""
3739
from collections import Counter
3840
if isinstance(byte_obj, (str, bytes)):
39-
return Counter(byte_obj[i:i+n] for i in range(0, len(byte_obj) - n + 1))
41+
return Counter(byte_obj[i:i+n] for i in range(0, len(byte_obj)-n+1, step))
4042
elif hasattr(byte_obj, "bytes") and hasattr(byte_obj, "size"):
4143
if not hasattr(byte_obj, "_ngram_counts_cache"):
4244
byte_obj._ngram_counts_cache = {}
4345
if n not in byte_obj._ngram_counts_cache.keys():
44-
byte_obj._ngram_counts_cache[n] = Counter(byte_obj.bytes[i:i+n] for i in range(0, byte_obj.size - n + 1))
46+
byte_obj._ngram_counts_cache[n] = Counter(byte_obj.bytes[i:i+n] for i in range(0, byte_obj.size-n+1, step))
4547
return byte_obj._ngram_counts_cache[n]
4648
raise TypeError("Bad input type ; should be a byte sequence or object")
4749

4850

49-
def ngrams_distribution(byte_obj, n=1, n_most_common=None, n_exclude_top=0, exclude=None):
51+
def ngrams_distribution(byte_obj, n=1, step=1, n_most_common=None, n_exclude_top=0, exclude=None):
5052
""" Compute the n-grams distribution of an input byte sequence or byte object given exclusions.
5153
54+
:param byte_obj: byte sequence ('bytes') or byte object with "bytes" and "size" attributes (i.e. pathlib2.Path)
5255
:param n: n determining the size of n-grams, defaults to 1
56+
:param step: step for sliding the n-grams
5357
:param n_most_common: number of n-grams to be kept in the result, keep all by default
5458
:param n_exclude_top: number of n-grams to be excluded from the top of the histogram, no exclusion by default
5559
:param exclude: list of specific n-grams to be excluded, no exclusion by default
5660
:return: list of n_most_common (n-gram, count) pairs
5761
"""
58-
c = ngrams_counts(byte_obj, n)
62+
c = ngrams_counts(byte_obj, n, step)
5963
r = c.most_common(len(c) if n_most_common is None else n_most_common + n_exclude_top + len(exclude or []))
6064
if exclude is not None:
6165
r = [(ngram, count) for ngram, count in r if ngram not in exclude]

0 commit comments

Comments
 (0)