Skip to content
This repository was archived by the owner on Mar 26, 2019. It is now read-only.

Commit a212887

Browse files
authored
Add files via upload
1 parent b5c725d commit a212887

File tree

91 files changed

+10709
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+10709
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
OBJS = entropy.o file_version_info.o message_table.o pe_base.o pe_bound_import.o pe_checksum.o pe_debug.o pe_directory.o pe_dotnet.o pe_exception_directory.o pe_exports.o pe_imports.o pe_load_config.o pe_properties.o pe_properties_generic.o pe_relocations.o pe_factory.o pe_resources.o pe_resource_manager.o pe_resource_viewer.o pe_rich_data.o pe_section.o pe_tls.o utils.o version_info_editor.o version_info_viewer.o pe_exception.o resource_message_list_reader.o resource_string_table_reader.o resource_version_info_reader.o resource_version_info_writer.o resource_cursor_icon_reader.o resource_cursor_icon_writer.o resource_bitmap_writer.o resource_bitmap_reader.o resource_data_info.o pe_rebuilder.o
2+
LIBNAME = pebliss
3+
LIBPATH = ../lib
4+
CXXFLAGS = -O2 -Wall -fPIC -DPIC -I.
5+
6+
ifdef PE_DEBUG
7+
CXXFLAGS += -g -O0
8+
endif
9+
10+
all: $(LIBPATH)/lib$(LIBNAME).a
11+
12+
clean:
13+
rm -f $(OBJS) lib$(LIBNAME).a
14+
rm -rf ../lib
15+
16+
lib$(LIBNAME).a: $(OBJS)
17+
ar -cvr lib$(LIBNAME).a $(OBJS)
18+
ranlib lib$(LIBNAME).a
19+
20+
$(LIBPATH):
21+
mkdir -p ../lib
22+
23+
$(LIBPATH)/lib$(LIBNAME).a: lib$(LIBNAME).a $(LIBPATH)
24+
cp -d lib$(LIBNAME).a ../lib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.15063.0
2+
Debug|Win32|C:\Users\rmt01\Dropbox\WindowsBox\Kodning\Fusk\Mutation\Polychaos-master\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
 version_info_viewer.cpp
2+
version_info_editor.cpp
3+
utils.cpp
4+
resource_version_info_writer.cpp
5+
resource_version_info_reader.cpp
6+
resource_string_table_reader.cpp
7+
resource_message_list_reader.cpp
8+
resource_cursor_icon_reader.cpp
9+
resource_data_info.cpp
10+
resource_cursor_icon_writer.cpp
11+
resource_bitmap_writer.cpp
12+
resource_bitmap_reader.cpp
13+
pe_rich_data.cpp
14+
pe_resources.cpp
15+
pe_relocations.cpp
16+
pe_resource_manager.cpp
17+
pe_factory.cpp
18+
pe_exception.cpp
19+
pe_base.cpp
20+
pe_imports.cpp
21+
Generating Code...
22+
Compiling...
23+
pe_exports.cpp
24+
pe_exception_directory.cpp
25+
pe_dotnet.cpp
26+
pe_debug.cpp
27+
pe_tls.cpp
28+
pe_section.cpp
29+
pe_resource_viewer.cpp
30+
pe_rebuilder.cpp
31+
pe_properties_generic.cpp
32+
pe_properties.cpp
33+
pe_load_config.cpp
34+
pe_directory.cpp
35+
pe_checksum.cpp
36+
pe_bound_import.cpp
37+
message_table.cpp
38+
file_version_info.cpp
39+
entropy.cpp
40+
Generating Code...
41+
pe_lib.vcxproj -> C:\Users\rmt01\Dropbox\WindowsBox\Kodning\Fusk\Mutation\Polychaos-master\build\Win32\Debug\pe_bliss.lib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <cmath>
2+
#include "entropy.h"
3+
#include "utils.h"
4+
5+
namespace pe_bliss
6+
{
7+
//Calculates entropy for PE image section
8+
double entropy_calculator::calculate_entropy(const section& s)
9+
{
10+
if(s.get_raw_data().empty()) //Don't count entropy for empty sections
11+
throw pe_exception("Section is empty", pe_exception::section_is_empty);
12+
13+
return calculate_entropy(s.get_raw_data().data(), s.get_raw_data().length());
14+
}
15+
16+
//Calculates entropy for istream (from current position of stream)
17+
double entropy_calculator::calculate_entropy(std::istream& file)
18+
{
19+
uint32_t byte_count[256] = {0}; //Byte count for each of 255 bytes
20+
21+
if(file.bad())
22+
throw pe_exception("Stream is bad", pe_exception::stream_is_bad);
23+
24+
std::streamoff pos = file.tellg();
25+
26+
std::streamoff length = pe_utils::get_file_size(file);
27+
length -= file.tellg();
28+
29+
if(!length) //Don't calculate entropy for empty buffers
30+
throw pe_exception("Data length is zero", pe_exception::data_is_empty);
31+
32+
//Count bytes
33+
for(std::streamoff i = 0; i != length; ++i)
34+
++byte_count[static_cast<unsigned char>(file.get())];
35+
36+
file.seekg(pos);
37+
38+
return calculate_entropy(byte_count, length);
39+
}
40+
41+
//Calculates entropy for data block
42+
double entropy_calculator::calculate_entropy(const char* data, size_t length)
43+
{
44+
uint32_t byte_count[256] = {0}; //Byte count for each of 255 bytes
45+
46+
if(!length) //Don't calculate entropy for empty buffers
47+
throw pe_exception("Data length is zero", pe_exception::data_is_empty);
48+
49+
//Count bytes
50+
for(size_t i = 0; i != length; ++i)
51+
++byte_count[static_cast<unsigned char>(data[i])];
52+
53+
return calculate_entropy(byte_count, length);
54+
}
55+
56+
//Calculates entropy for this PE file (only section data)
57+
double entropy_calculator::calculate_entropy(const pe_base& pe)
58+
{
59+
uint32_t byte_count[256] = {0}; //Byte count for each of 255 bytes
60+
61+
size_t total_data_length = 0;
62+
63+
//Count bytes for each section
64+
for(section_list::const_iterator it = pe.get_image_sections().begin(); it != pe.get_image_sections().end(); ++it)
65+
{
66+
const std::string& data = (*it).get_raw_data();
67+
size_t length = data.length();
68+
total_data_length += length;
69+
for(size_t i = 0; i != length; ++i)
70+
++byte_count[static_cast<unsigned char>(data[i])];
71+
}
72+
73+
return calculate_entropy(byte_count, total_data_length);
74+
}
75+
76+
//Calculates entropy from bytes count
77+
double entropy_calculator::calculate_entropy(const uint32_t byte_count[256], std::streamoff total_length)
78+
{
79+
double entropy = 0.; //Entropy result value
80+
//Calculate entropy
81+
for(uint32_t i = 0; i < 256; ++i)
82+
{
83+
double temp = static_cast<double>(byte_count[i]) / total_length;
84+
if(temp > 0.)
85+
entropy += std::abs(temp * (std::log(temp) * pe_utils::log_2));
86+
}
87+
88+
return entropy;
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
#include <istream>
3+
#include "pe_base.h"
4+
5+
namespace pe_bliss
6+
{
7+
class entropy_calculator
8+
{
9+
public:
10+
//Calculates entropy for PE image section
11+
static double calculate_entropy(const section& s);
12+
13+
//Calculates entropy for istream (from current position of stream)
14+
static double calculate_entropy(std::istream& file);
15+
16+
//Calculates entropy for data block
17+
static double calculate_entropy(const char* data, size_t length);
18+
19+
//Calculates entropy for this PE file (only section data)
20+
static double calculate_entropy(const pe_base& pe);
21+
22+
private:
23+
entropy_calculator();
24+
entropy_calculator(const entropy_calculator&);
25+
entropy_calculator& operator=(const entropy_calculator&);
26+
27+
//Calculates entropy from bytes count
28+
static double calculate_entropy(const uint32_t byte_count[256], std::streamoff total_length);
29+
};
30+
}

0 commit comments

Comments
 (0)