Skip to content

Commit 6134af6

Browse files
committed
Fixed #2
2 parents dc4c7be + c9b357a commit 6134af6

14 files changed

Lines changed: 123 additions & 77 deletions

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ $ exeplot byte calc_packed.exe
2626

2727
![Byte plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_byte.png?raw=true)
2828

29+
Draw a simplified byte plot of `calc_packed.exe`:
30+
31+
```sh
32+
$ exeplot byte calc_packed.exe --no-title --no-legend
33+
```
34+
35+
![Simplified byte plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_byte2.png?raw=true)
36+
2937
Draw a pie plot of `calc_packed.exe`:
3038

3139
```sh
@@ -50,6 +58,14 @@ $ exeplot entropy calc_orig.exe calc_packed.exe
5058

5159
![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)
5260

61+
Draw a simplified entropy plot of `calc_packed.exe`:
62+
63+
```sh
64+
$ exeplot entropy calc_packed.exe --no-title --no-legend --no-label --no-entrypoint
65+
```
66+
67+
![Simplified entropy plot of `calc_packed.exe`](https://github.com/packing-box/python-exeplot/blob/main/docs/pages/img/calc_packed_entropy.png?raw=true)
68+
5369

5470
## :clap: Supporters
5571

docs/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading
1.99 MB
Loading
31.7 KB
Loading

docs/pages/img/upx_calc_byte.png

1.99 MB
Loading
31.7 KB
Loading

src/exeplot/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.2
1+
0.4.3

src/exeplot/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ def main():
3434
plot_func = globals()[plot]
3535
plot_parser = plot_func.__args__(plots.add_parser(plot, help=plot_func.__doc__.strip(), add_help=False))
3636
opt = plot_parser.add_argument_group("options")
37+
if plot == "diff":
38+
opt.add_argument("--no-colormap", action="store_true", help="do not display the color map (default: False)")
39+
if plot == "entropy":
40+
opt.add_argument("--no-entrypoint", action="store_true",
41+
help="do not display the entry point (default: False)")
42+
if plot in ["entropy", "pie"]:
43+
opt.add_argument("--no-label", action="store_true", help="do not display the labels (default: False)")
44+
opt.add_argument("--no-legend", action="store_true", help="do not display the legend (default: False)")
3745
opt.add_argument("--no-title", action="store_true", help="do not display the title (default: False)")
3846
extra = plot_parser.add_argument_group("extra arguments")
3947
extra.add_argument("-h", "--help", action="help", help="show this help message and exit")

src/exeplot/plots/byte.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,41 @@ def plot(executable, height=600, grayscale=False, **kwargs):
5353
pass
5454
max_w = sum(max_txt_w) + (n_cols - 1) * txt_spacing
5555
# draw a separator
56-
images.append(Image.new(m, (int(.05 * height), height), "white"))
56+
if not kwargs.get('no_legend', False):
57+
images.append(Image.new(m, (int(.05 * height), height), "white"))
5758
# draw a sections plot aside
5859
img = Image.new(m, (s, s), "white")
5960
# draw the legend with section names
60-
legend = Image.new(m, (max_w, height), "white")
61-
draw = ImageDraw.Draw(legend)
62-
_xy = lambda n, c: (txt_spacing + sum(max_txt_w[:c]) + len(max_txt_w[:c]) * txt_spacing, \
63-
txt_spacing + (n % n_lab_per_col) * (txt_spacing + txt_h))
64-
_c_func = [_rgb, _gs][grayscale]
65-
for i, name, start, end, color in binary:
66-
if start != end:
67-
x0, y0 = min(max(ceil(((start / factor) % s)) - 1, 0), s - 1), \
68-
min(max(ceil(start / s / factor) - 1, 0), s - 1)
69-
xN, yN = min(max(ceil(((end / factor) % s)) - 1, 0), s - 1), \
70-
min(max(ceil(end / s / factor) - 1, 0), s - 1)
71-
if y0 == yN:
72-
xN = min(max(x0 + 1, xN), s - 1)
73-
c = _c_func(color)
74-
for x in range(x0, s if y0 < yN else xN):
75-
img.putpixel((x, y0), c)
76-
for y in range(y0 + 1, yN):
77-
for x in range(0, s):
78-
img.putpixel((x, y), c)
79-
if yN > y0:
80-
for x in range(0, xN):
81-
img.putpixel((x, yN), c)
82-
# fill the legend with the current section name
83-
if name.startswith("TOTAL"):
84-
color = "black"
85-
draw.text(_xy(i, ceil((i + 1) / n_lab_per_col) - 1), name, fill=_c_func(color), font=font)
86-
images.append(img.resize((int(img.size[0] * sf * .2), height), resample=Image.Resampling.BOX))
87-
images.append(Image.new(m, (int(.03 * height), height), "white")) # draw another separator
88-
images.append(legend)
61+
if not kwargs.get('no_legend', False):
62+
legend = Image.new(m, (max_w, height), "white")
63+
draw = ImageDraw.Draw(legend)
64+
_xy = lambda n, c: (txt_spacing + sum(max_txt_w[:c]) + len(max_txt_w[:c]) * txt_spacing, \
65+
txt_spacing + (n % n_lab_per_col) * (txt_spacing + txt_h))
66+
_c_func = [_rgb, _gs][grayscale]
67+
for i, name, start, end, color in binary:
68+
if start != end:
69+
x0, y0 = min(max(ceil(((start / factor) % s)) - 1, 0), s - 1), \
70+
min(max(ceil(start / s / factor) - 1, 0), s - 1)
71+
xN, yN = min(max(ceil(((end / factor) % s)) - 1, 0), s - 1), \
72+
min(max(ceil(end / s / factor) - 1, 0), s - 1)
73+
if y0 == yN:
74+
xN = min(max(x0 + 1, xN), s - 1)
75+
c = _c_func(color)
76+
for x in range(x0, s if y0 < yN else xN):
77+
img.putpixel((x, y0), c)
78+
for y in range(y0 + 1, yN):
79+
for x in range(0, s):
80+
img.putpixel((x, y), c)
81+
if yN > y0:
82+
for x in range(0, xN):
83+
img.putpixel((x, yN), c)
84+
# fill the legend with the current section name
85+
if name.startswith("TOTAL"):
86+
color = "black"
87+
draw.text(_xy(i, ceil((i + 1) / n_lab_per_col) - 1), name, fill=_c_func(color), font=font)
88+
images.append(img.resize((int(img.size[0] * sf * .2), height), resample=Image.Resampling.BOX))
89+
images.append(Image.new(m, (int(.03 * height), height), "white")) # draw another separator
90+
images.append(legend)
8991
# combine images horizontally
9092
x, img = 0, Image.new(m, (sum(i.size[0] for i in images), height))
9193
for i in images:

src/exeplot/plots/diff.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ def byte_differences(bytes1, bytes2):
133133
va="center")
134134
# ---------------------------------------------- CONFIGURE THE FIGURE ----------------------------------------------
135135
logger.debug("> configuring the figure")
136-
cb = plt.colorbar(ScalarMappable(cmap=ListedColormap(colors, N=4)),
137-
location='bottom', ax=objs[-1], fraction=0.3, aspect=50, ticks=[0.125, 0.375, 0.625, 0.875])
138-
cb.set_ticklabels(['removed', 'modified', 'untouched', 'added'])
139-
cb.ax.tick_params(length=0)
140-
cb.outline.set_visible(False)
136+
if not kwargs.get('no_colorbar', False):
137+
cb = plt.colorbar(ScalarMappable(cmap=ListedColormap(colors, N=4)),
138+
location='bottom', ax=objs[-1], fraction=0.3, aspect=50, ticks=[0.125, 0.375, 0.625, 0.875])
139+
cb.set_ticklabels(['removed', 'modified', 'untouched', 'added'])
140+
cb.ax.tick_params(length=0)
141+
cb.outline.set_visible(False)
141142
plt.subplots_adjust(left=[.15, .02][legend1 == "" and legend2 == ""], bottom=.5/max(1.75, nf))
142143
h, l = (objs[int(title)] if nf+int(title) > 1 else objs).get_legend_handles_labels()
143-
if len(h) > 0:
144+
if len(h) > 0 and not kwargs.get('no_legend', False):
144145
plt.figlegend(h, l, loc=[.8, .135], ncol=1, prop={'size': fs_ref*.7})
145146

0 commit comments

Comments
 (0)