Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
binwalk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
binwalk
Commits
a51332af
Commit
a51332af
authored
Dec 20, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --carve option
parent
2492b1c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
17 deletions
+22
-17
entropy.py
src/binwalk/modules/entropy.py
+22
-17
No files found.
src/binwalk/modules/entropy.py
View file @
a51332af
...
...
@@ -27,7 +27,7 @@ class Entropy(Module):
Option
(
short
=
'J'
,
long
=
'save-plot'
,
kwargs
=
{
'save_plot'
:
True
},
description
=
'Save plot as a PNG
(implied if multiple files are specified)
'
),
description
=
'Save plot as a PNG'
),
Option
(
short
=
'N'
,
long
=
'no-plot'
,
kwargs
=
{
'do_plot'
:
False
},
...
...
@@ -35,7 +35,7 @@ class Entropy(Module):
Option
(
short
=
'Q'
,
long
=
'no-legend'
,
kwargs
=
{
'show_legend'
:
False
},
description
=
'Omit the legend from the entropy plot graph
(implied if multiple files are specified)
'
),
description
=
'Omit the legend from the entropy plot graph'
),
]
KWARGS
=
[
...
...
@@ -54,30 +54,32 @@ class Entropy(Module):
self
.
algorithm
=
self
.
shannon
self
.
display_results
=
True
self
.
max_description_length
=
0
self
.
markers
=
[]
# Automatically save plots if there is more than one file specified
if
len
(
self
.
config
.
target_files
)
>
1
:
self
.
save_plot
=
True
self
.
show_legend
=
False
self
.
file_markers
=
{}
# Get a list of all other module's results to mark on the entropy graph
for
(
module
,
obj
)
in
iterator
(
self
.
modules
):
for
result
in
obj
.
results
:
if
result
.
description
:
if
result
.
file
and
result
.
description
:
description
=
result
.
description
.
split
(
','
)[
0
]
if
not
has_key
(
self
.
file_markers
,
result
.
file
.
name
):
self
.
file_markers
[
result
.
file
.
name
]
=
[]
if
len
(
description
)
>
self
.
max_description_length
:
self
.
max_description_length
=
len
(
description
)
self
.
markers
.
append
((
result
.
offset
,
description
))
self
.
file_markers
[
result
.
file
.
name
]
.
append
((
result
.
offset
,
description
))
# If other modules have been run and they produced results, don't spam the terminal with entropy results
if
self
.
markers
:
if
self
.
file_
markers
:
self
.
display_results
=
False
if
self
.
config
.
block
:
self
.
block_size
=
self
.
config
.
block
def
run
(
self
):
from
pyqtgraph.Qt
import
QtGui
for
fp
in
self
.
config
.
target_files
:
if
self
.
display_results
:
...
...
@@ -87,6 +89,9 @@ class Entropy(Module):
if
self
.
display_results
:
self
.
footer
()
if
not
self
.
save_plot
:
QtGui
.
QApplication
.
instance
()
.
exec_
()
def
calculate_file_entropy
(
self
,
fp
):
# Clear results from any previously analyzed files
...
...
@@ -138,7 +143,6 @@ class Entropy(Module):
def
plot_entropy
(
self
,
fname
):
import
numpy
as
np
import
pyqtgraph
as
pg
from
pyqtgraph.Qt
import
QtCore
,
QtGui
i
=
0
x
=
[]
...
...
@@ -151,12 +155,10 @@ class Entropy(Module):
plt
=
pg
.
plot
(
title
=
fname
,
clear
=
True
)
plt
.
plot
(
x
,
y
,
pen
=
'y'
)
if
self
.
show_legend
and
self
.
markers
:
if
self
.
show_legend
and
has_key
(
self
.
file_markers
,
fname
):
plt
.
addLegend
(
size
=
(
self
.
max_description_length
*
10
,
0
))
for
(
offset
,
description
)
in
self
.
markers
:
for
(
offset
,
description
)
in
self
.
file_markers
[
fname
]
:
# If this description has already been plotted at a different offset, we need to
# use the same color for the marker, but set the description to None to prevent
# duplicate entries in the graph legend.
...
...
@@ -175,6 +177,10 @@ class Entropy(Module):
plt
.
plot
(
x
=
[
offset
,
offset
],
y
=
[
0
,
1.1
],
name
=
description
,
pen
=
pg
.
mkPen
(
color
,
width
=
2.5
))
# Plot data points
plt
.
plot
(
x
,
y
,
pen
=
'y'
)
# TODO: legend is not displayed properly when saving plots to disk
if
self
.
save_plot
:
exporter
=
pg
.
exporters
.
ImageExporter
.
ImageExporter
(
plt
.
plotItem
)
exporter
.
parameters
()[
'width'
]
=
self
.
FILE_WIDTH
...
...
@@ -182,5 +188,4 @@ class Entropy(Module):
else
:
plt
.
setLabel
(
'left'
,
self
.
YLABEL
,
units
=
self
.
YUNITS
)
plt
.
setLabel
(
'bottom'
,
self
.
XLABEL
,
units
=
self
.
XUNITS
)
QtGui
.
QApplication
.
instance
()
.
exec_
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment