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
b771ae0d
Commit
b771ae0d
authored
Dec 20, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --no-plot and --save-plot to entropy.py.
parent
4ae41878
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
6 deletions
+33
-6
entropy.py
src/binwalk/modules/entropy.py
+33
-6
No files found.
src/binwalk/modules/entropy.py
View file @
b771ae0d
import
os
import
math
import
math
import
binwalk.core.common
from
binwalk.core.module
import
Module
,
Option
,
Kwarg
from
binwalk.core.module
import
Module
,
Option
,
Kwarg
class
Entropy
(
Module
):
class
Entropy
(
Module
):
...
@@ -9,6 +11,9 @@ class Entropy(Module):
...
@@ -9,6 +11,9 @@ class Entropy(Module):
XUNITS
=
'B'
XUNITS
=
'B'
YUNITS
=
'E'
YUNITS
=
'E'
FILE_WIDTH
=
1024
FILE_FORMAT
=
'png'
TITLE
=
"Entropy"
TITLE
=
"Entropy"
CLI
=
[
CLI
=
[
...
@@ -16,16 +21,32 @@ class Entropy(Module):
...
@@ -16,16 +21,32 @@ class Entropy(Module):
long
=
'entropy'
,
long
=
'entropy'
,
kwargs
=
{
'enabled'
:
True
},
kwargs
=
{
'enabled'
:
True
},
description
=
'Calculate file entropy'
),
description
=
'Calculate file entropy'
),
Option
(
short
=
'J'
,
long
=
'save-plot'
,
kwargs
=
{
'save_plot'
:
True
},
description
=
'Save plot as a PNG (implied if multiple files are specified)'
),
Option
(
short
=
'N'
,
long
=
'no-plot'
,
kwargs
=
{
'do_plot'
:
False
},
description
=
'Do not generate an entropy plot graph'
),
]
]
KWARGS
=
[
KWARGS
=
[
Kwarg
(
name
=
'enabled'
,
default
=
False
),
Kwarg
(
name
=
'enabled'
,
default
=
False
),
Kwarg
(
name
=
'save_plot'
,
default
=
False
),
Kwarg
(
name
=
'do_plot'
,
default
=
True
),
Kwarg
(
name
=
'block_size'
,
default
=
1024
),
Kwarg
(
name
=
'block_size'
,
default
=
1024
),
]
]
def
init
(
self
):
def
init
(
self
):
self
.
HEADER
[
-
1
]
=
"ENTROPY"
self
.
entropy_results
=
{}
self
.
entropy_results
=
{}
self
.
algorithm
=
self
.
shannon
self
.
algorithm
=
self
.
shannon
if
len
(
self
.
config
.
target_files
)
>
1
:
self
.
save_plot
=
True
if
self
.
config
.
block
:
if
self
.
config
.
block
:
self
.
block_size
=
self
.
config
.
block
self
.
block_size
=
self
.
config
.
block
...
@@ -52,7 +73,8 @@ class Entropy(Module):
...
@@ -52,7 +73,8 @@ class Entropy(Module):
r
=
self
.
result
(
offset
=
(
file_offset
+
i
),
file
=
fp
,
entropy
=
entropy
,
description
=
(
"
%
f"
%
entropy
))
r
=
self
.
result
(
offset
=
(
file_offset
+
i
),
file
=
fp
,
entropy
=
entropy
,
description
=
(
"
%
f"
%
entropy
))
i
+=
self
.
block_size
i
+=
self
.
block_size
self
.
plot_entropy
(
fp
.
name
)
if
self
.
do_plot
:
self
.
plot_entropy
(
fp
.
name
)
def
shannon
(
self
,
data
):
def
shannon
(
self
,
data
):
'''
'''
...
@@ -81,7 +103,7 @@ class Entropy(Module):
...
@@ -81,7 +103,7 @@ class Entropy(Module):
return
e
return
e
def
plot_entropy
(
self
,
titl
e
):
def
plot_entropy
(
self
,
fnam
e
):
import
numpy
as
np
import
numpy
as
np
import
pyqtgraph
as
pg
import
pyqtgraph
as
pg
from
pyqtgraph.Qt
import
QtCore
,
QtGui
from
pyqtgraph.Qt
import
QtCore
,
QtGui
...
@@ -93,11 +115,16 @@ class Entropy(Module):
...
@@ -93,11 +115,16 @@ class Entropy(Module):
x
.
append
(
r
.
offset
)
x
.
append
(
r
.
offset
)
y
.
append
(
r
.
entropy
)
y
.
append
(
r
.
entropy
)
plt
=
pg
.
plot
(
title
=
titl
e
,
clear
=
True
)
plt
=
pg
.
plot
(
title
=
fnam
e
,
clear
=
True
)
plt
.
plot
(
x
,
y
,
pen
=
'y'
)
#pen='b'
plt
.
plot
(
x
,
y
,
pen
=
'y'
)
#pen='b'
plt
.
setLabel
(
'left'
,
self
.
YLABEL
,
units
=
self
.
YUNITS
)
if
self
.
save_plot
:
plt
.
setLabel
(
'bottom'
,
self
.
XLABEL
,
units
=
self
.
XUNITS
)
exporter
=
pg
.
exporters
.
ImageExporter
.
ImageExporter
(
plt
.
plotItem
)
QtGui
.
QApplication
.
instance
()
.
exec_
()
exporter
.
parameters
()[
'width'
]
=
self
.
FILE_WIDTH
exporter
.
export
(
binwalk
.
core
.
common
.
unique_file_name
(
os
.
path
.
basename
(
fname
),
self
.
FILE_FORMAT
))
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