FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PrefLib/support/algorithm.cpp at master · PREF/PrefLib · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PREF
/
PrefLib
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
PrefLib
/
support
/
algorithm.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (44 loc) · 1.4 KB
Breadcrumbs
PrefLib
/
support
/
algorithm.cpp
Copy path
File metadata and controls
61 lines (44 loc) · 1.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
include
"
algorithm.h
"
#
define
logn
(
n, base
) (log(n) / log(base))
namespace
PrefLib
{
namespace
Support
{
Algorithm::Algorithm
()
{
}
Algorithm::~Algorithm
()
{
}
uint64_t
Algorithm::rebase
(
uint64_t
address,
uint64_t
oldbaseaddress,
uint64_t
newbaseaddress)
{
return
(address - oldbaseaddress) + newbaseaddress;
}
double
Algorithm::entropy
(
const
ByteElaborator::CountResult& cr,
uint64_t
size)
{
double
e =
0.0
;
uint64_t
base =
std::min
(size,
uint64_t
(
256
));
for
(
uint64_t
i =
0
; i < cr.
Counts
.
size
(); i++)
{
const
uintmax_t
& c = cr.
Counts
.
at
(i);
if
(!c)
continue
;
double
freq =
static_cast
<
double
>(c) /
static_cast
<
double
>(size);
e += freq *
logn
(freq, base);
}
return
-e;
}
double
Algorithm::entropy
(
IO
::DataBuffer *databuffer,
uint64_t
startoffset,
uint64_t
size,
volatile
bool
*cancontinue)
{
ByteElaborator::CountResult cr;
ByteElaborator::countBytes
(cr, databuffer, startoffset, startoffset + size, cancontinue);
return
Algorithm::entropy
(cr, size);
}
double
Algorithm::entropy
(
IO
::DataBuffer *databuffer,
uint64_t
size,
volatile
bool
*cancontinue)
{
return
Algorithm::entropy
(databuffer,
0
, size, cancontinue);
}
double
Algorithm::entropy
(
IO
::DataBuffer *databuffer,
volatile
bool
*cancontinue)
{
return
Algorithm::entropy
(databuffer, databuffer->
size
(), cancontinue);
}
}
//
namespace Support
}
//
namespace PrefLib
Back
|
FazBrowse Home
|
New Git URL