Skip to content

To update LICENSE #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f212336
translate pe_lib/readme.txt into English, update license in README
asinbow Nov 21, 2015
cc7aba1
rename project
asinbow Nov 21, 2015
ff41898
update Makefile: direct build outputs like *.a and executables to tar…
asinbow Nov 22, 2015
08dacdf
fix libiconv linkage unresolved on OSX
asinbow Nov 22, 2015
425dc63
add gitignore file
asinbow Nov 22, 2015
52c9b35
fix -liconv position for Linux
asinbow Nov 22, 2015
979a755
fix compile from OSX and Linux
asinbow Nov 23, 2015
c38ef89
fix compile for VS2013
zhuangxiu Nov 23, 2015
abdbc34
fix compile for VS2013 express without MFC dependency
zhuangxiu Nov 23, 2015
5e9b0e0
add gitignore item for visual studio
zhuangxiu Nov 23, 2015
15703ef
add license file
zhuangxiu Nov 23, 2015
fd02b78
update README.md about project information and todos
zhuangxiu Nov 23, 2015
1c9b528
update TODO
zhuangxiu Nov 23, 2015
f2f2101
update Makefile
zhuangxiu Nov 23, 2015
4960f04
update Visual Studio project file to 2013 express, discard 2008
zhuangxiu Nov 23, 2015
c37bba3
update .gitignore for Visual Studio
zhuangxiu Nov 23, 2015
a253e27
update README.md
zhuangxiu Nov 23, 2015
8ae14e7
Merge branch 'master' of github.com:asinbow/libpebliss
asinbow Nov 23, 2015
dc72a03
add endian detection
asinbow Nov 29, 2015
4eb6a40
fix checksum for x64 and big-endian
asinbow Nov 29, 2015
d00ac75
fix some compile warning
asinbow Nov 29, 2015
9937d1f
Merge branch 'master' of github.com:asinbow/libpebliss
asinbow Nov 29, 2015
76956f3
update test TODO
asinbow Nov 29, 2015
6faeec6
add features into README
zhuangxiu Nov 29, 2015
6d2d207
Merge branch 'master' of github.com:asinbow/libpebliss
zhuangxiu Nov 29, 2015
5479d0f
fix encoding for OSX
asinbow Nov 29, 2015
b311979
Merge branch 'master' of github.com:asinbow/libpebliss
asinbow Nov 29, 2015
c7c09b2
update TODO
asinbow Nov 29, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.o
*.a
*.swp
samples/out/
tests/bin/


*.exe
Debug/
Release/
*.sdf
*.opensdf
*.suo
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Library is free to use in both commertial and non-commertial projects. You can also modify and redistribute it. If you are using it, please, do not forget to specify the name or other copyright of PE Bliss somewhere in the description of your project.
71 changes: 53 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
# portable-executable-library
Automatically exported from code.google.com/p/portable-executable-library
libpebliss
---
Evolved from [portable-executable-library](https://code.google.com/p/portable-executable-library)

**Original Author:** rukaimi (kaimi.ru)

Thanks to his really great work!


### PE Bliss
Cross-Platform [PE](https://en.wikipedia.org/wiki/Portable_Executable)(Portable Executable) Manipulating Library
* C++
* Compatibility
* Little-endian systems only, might not support big-endian ones.
* Windows, tested on Visual Studio 2013 Express
* Linux, tested on GCC 4.8.4
* OSX, tested on LLVM 7.0.0

* Useful usage samples and well unit-tested.

### Features

* Read 32- and 64-bit PE files (PE, PE+) for Windows, work similar with both formats
* Create PE/PE+ binaries from scratch
* Rebuild 32- and 64-bit PE files
* Work with directories and headers
* Convert addresses
* Read and write PE sections
* Read and write imports
* Read and write exports (forwarders supported)
* Read and write relocations
* Read and write resources
* Read and write TLS (including callbacks and raw data)
* Read and write image config (including SE Handlers and Lock Prefix addresses)
* Read basic .NET information
* Read and write bound imports
* Read exception directory (PE+ only)
* Read debug directory and extended debug information
* Calculate entropy
* Change file alignment
* Change base address
* Work with DOS Stub and Rich overlay
* High-level resource reading: bitmaps, icons, cursors, version info, string and message tables
* High-level resource editing: bitmaps, icons, cursors, version info

Library doesn't use WinAPI and doesn't execute PE files, so it's safe to use it with suspicious binaries.

### TODO

* Unit-test
* test on big-endian

* use [CMake](http://cmake.org) instead ???

**Author:** rukaimi (kaimi.ru)

Just forked this to preserve it from the Google Code shutdown.

Didn't see a license, so if the author or any copyright holders want me to pull it down, let me know.

I make no claims to rights over this project. Awesome library though.

#PE Bliss

Cross-Platform Portable Executable C++ Library
Compatible with Windows and Linux (tested on MSVC++ 2008, 2010, GCC 4.4 on Linux). Currently tested on little-endian systems only and might not support big-endian ones.

Library has many usage samples and is well unit-tested.

Library is free to use in both commertial and non-commertial projects. You can also modify and redistribute it. If you are using it, please, do not forget to specify the name or other copyright of PE Bliss somewhere in the description of your project.
546 changes: 274 additions & 272 deletions pe_bliss_tests_vc10.sln → pe_bliss_tests_vc12.sln

Large diffs are not rendered by default.

272 changes: 0 additions & 272 deletions pe_bliss_tests_vc9.sln

This file was deleted.

836 changes: 419 additions & 417 deletions pe_bliss_vc10.sln → pe_bliss_vc12.sln

Large diffs are not rendered by default.

417 changes: 0 additions & 417 deletions pe_bliss_vc9.sln

This file was deleted.

14 changes: 6 additions & 8 deletions pe_lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
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
LIBNAME = pebliss
LIBPATH = ../lib
LIBPATH = ../lib/
CXXFLAGS = -O2 -Wall -fPIC -DPIC -I.

ifdef PE_DEBUG
CXXFLAGS += -g -O0
endif

all: $(LIBPATH)/lib$(LIBNAME).a
all: lib$(LIBNAME).a

clean:
rm -f $(OBJS) lib$(LIBNAME).a
rm -rf ../lib

lib$(LIBNAME).a: $(OBJS)
ar -cvr lib$(LIBNAME).a $(OBJS)
ranlib lib$(LIBNAME).a
lib$(LIBNAME).a: $(OBJS) $(LIBPATH)
ar -cvr $(LIBPATH)lib$(LIBNAME).a $(OBJS)
ranlib $(LIBPATH)lib$(LIBNAME).a

$(LIBPATH):
mkdir -p ../lib
mkdir -p $(LIBPATH)

$(LIBPATH)/lib$(LIBNAME).a: lib$(LIBNAME).a $(LIBPATH)
cp -d lib$(LIBNAME).a ../lib
16 changes: 14 additions & 2 deletions pe_lib/pe_checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,30 @@ uint32_t calculate_checksum(std::istream& file)

//"CheckSum" field position in optional PE headers - it's always 64 for PE and PE+
static const unsigned long checksum_pos_in_optional_headers = 64;
static const unsigned long dw_size = 4;
//Calculate real PE headers "CheckSum" field position
//Sum is safe here
unsigned long pe_checksum_pos = header.e_lfanew + sizeof(image_file_header) + sizeof(uint32_t) + checksum_pos_in_optional_headers;

//Calculate checksum for each byte of file
std::streamoff filesize = pe_utils::get_file_size(file);
for(long long i = 0; i < filesize; i += 4)
for(long long i = 0; i < filesize; i += dw_size)
{
unsigned long dw = 0;
char* pdw = reinterpret_cast<char*>(&dw);
char c;

//Read DWORD from file
file.read(reinterpret_cast<char*>(&dw), sizeof(unsigned long));
file.read(pdw, dw_size);
if (!pe_utils::is_little_endian()) {
c = pdw[0];
pdw[0] = pdw[3];
pdw[3] = c;

c = pdw[1];
pdw[1] = pdw[2];
pdw[2] = c;
}
//Skip "CheckSum" DWORD
if(i == pe_checksum_pos)
continue;
Expand Down
6 changes: 5 additions & 1 deletion pe_lib/pe_lib.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -116,23 +116,27 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
1 change: 1 addition & 0 deletions pe_lib/pe_section.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string.h>
#include "utils.h"
#include "pe_section.h"
#include <algorithm>

namespace pe_bliss
{
Expand Down
32 changes: 32 additions & 0 deletions pe_lib/readme-en.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!!!NOTICE translated from readme.txt

Open a free library for working with PE-file PE Bliss.
Free to use, modify, and distribute.
Author: DX
(c) DX 2011-2012, kaimi.ru

Compatibility: Windows, Linux

Capabilities:
[+] Creation of PE or PE + file from scratch
[+] Reading the 32-bit and 64-bit PE-file (PE, PE +) and uniform working with them
[+] Rebuild 32-bit and 64-bit PE-files
[+] Working with the directors and titles
[+] Converting addresses
[+] Reading and editing sections of PE-file
[+] Reading and editing the import table
[+] Reading and editing tables exports
[+] Reading and editing tables relocations
[+] Reading and editing resources
[+] Reading and editing TLS
[+] Reading and editing the configuration of the image (image config)
[+] Reading data base .NET
[+] Reading and editing information about tethered import
[+] Read the directory exceptions (only PE +)
[+] Read debug directories with extended information
[+] The calculation of entropy
[+] Changing file alignment
[+] Change the base load address
[+] Support of DOS Stub'om and Rich overlay
[+] High-level reading resources: images, icons, cursors, version information, string tables, message table
[+] High-level editing resources: images, icons, cursors, version information
9 changes: 7 additions & 2 deletions pe_lib/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ std::streamoff pe_utils::get_file_size(std::istream& file)
return filesize;
}

bool pe_utils::is_little_endian() {
uint16_t i = 1;
return *(char*)&i;
}

#ifndef PE_BLISS_WINDOWS
const u16string pe_utils::to_ucs2(const std::wstring& str)
{
Expand All @@ -31,7 +36,7 @@ const u16string pe_utils::to_ucs2(const std::wstring& str)

ret.resize(str.length());

iconv_t conv = iconv_open("UCS-2", "WCHAR_T");
iconv_t conv = iconv_open("UCS-2LE", "UCS-4LE");
if(conv == reinterpret_cast<iconv_t>(-1))
throw pe_exception("Error opening iconv", pe_exception::encoding_convertion_error);

Expand All @@ -57,7 +62,7 @@ const std::wstring pe_utils::from_ucs2(const u16string& str)

ret.resize(str.length());

iconv_t conv = iconv_open("WCHAR_T", "UCS-2");
iconv_t conv = iconv_open("UCS-4LE", "UCS-2LE");
if(conv == reinterpret_cast<iconv_t>(-1))
throw pe_exception("Error opening iconv", pe_exception::encoding_convertion_error);

Expand Down
3 changes: 3 additions & 0 deletions pe_lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class pe_utils

//Returns stream size
static std::streamoff get_file_size(std::istream& file);

static bool is_little_endian();

#ifndef PE_BLISS_WINDOWS
public:
Expand All @@ -77,6 +79,7 @@ class pe_utils
pe_utils();
pe_utils(pe_utils&);
pe_utils& operator=(const pe_utils&);

};

//Windows GUID comparison
Expand Down
6 changes: 5 additions & 1 deletion samples/address_convertions/address_convertions.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
6 changes: 5 additions & 1 deletion samples/basic_dotnet_viewer/basic_dotnet_viewer.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
6 changes: 5 additions & 1 deletion samples/basic_info_viewer/basic_info_viewer.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -28,23 +28,27 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
Loading