From 02709686f0d31d1553c58226b1f049cf6f5482a0 Mon Sep 17 00:00:00 2001 From: rukaimi <rukaimi@985867f9-ca9c-e1f6-822d-e8a4186388af> Date: Sun, 14 Oct 2012 20:51:09 +0000 Subject: [PATCH] 1. All windows.h-related stuff moved to pe_win namespace. Now pe_bliss namespace is clean. 2. Small fixes --- pe_lib/pe_32_64.cpp | 2 ++ pe_lib/pe_32_64.h | 19 ++++++++++--- pe_lib/pe_base.cpp | 4 ++- pe_lib/pe_base.h | 36 ++++++++++++------------- pe_lib/pe_resource_manager.cpp | 2 ++ pe_lib/pe_resource_manager.h | 2 +- pe_lib/pe_structures.h | 7 +++-- samples/resource_editor/main.cpp | 2 +- samples/sections_and_addresses/main.cpp | 2 +- 9 files changed, 49 insertions(+), 27 deletions(-) diff --git a/pe_lib/pe_32_64.cpp b/pe_lib/pe_32_64.cpp index 561dbe8..9c578b4 100644 --- a/pe_lib/pe_32_64.cpp +++ b/pe_lib/pe_32_64.cpp @@ -4,6 +4,8 @@ namespace pe_bliss { +using namespace pe_win; + //Constructor of empty PE file template<typename PEClassType> pe<PEClassType>::pe(uint32_t section_alignment, bool dll, uint16_t subsystem) diff --git a/pe_lib/pe_32_64.h b/pe_lib/pe_32_64.h index 488f6f4..fcfa43b 100644 --- a/pe_lib/pe_32_64.h +++ b/pe_lib/pe_32_64.h @@ -43,7 +43,7 @@ public: explicit pe(std::istream& file, bool read_bound_import_raw_data = true, bool read_debug_raw_data = true); //Constructor of empty PE file - explicit pe(uint32_t section_alignment = 0x1000, bool dll = false, uint16_t subsystem = image_subsystem_windows_gui); + explicit pe(uint32_t section_alignment = 0x1000, bool dll = false, uint16_t subsystem = pe_win::image_subsystem_windows_gui); //Destructor virtual ~pe(); @@ -286,6 +286,19 @@ protected: }; //Two used typedefs for PE32 (PE) and PE64 (PE+) -typedef pe<pe_class_type<image_nt_headers32, image_optional_header32, image_nt_optional_hdr32_magic, uint32_t, image_ordinal_flag32, image_tls_directory32, image_load_config_directory32> > pe32; -typedef pe<pe_class_type<image_nt_headers64, image_optional_header64, image_nt_optional_hdr64_magic, uint64_t, image_ordinal_flag64, image_tls_directory64, image_load_config_directory64> > pe64; +typedef pe<pe_class_type<pe_win::image_nt_headers32, + pe_win::image_optional_header32, + pe_win::image_nt_optional_hdr32_magic, + uint32_t, + pe_win::image_ordinal_flag32, + pe_win::image_tls_directory32, + pe_win::image_load_config_directory32> > pe32; + +typedef pe<pe_class_type<pe_win::image_nt_headers64, + pe_win::image_optional_header64, + pe_win::image_nt_optional_hdr64_magic, + uint64_t, + pe_win::image_ordinal_flag64, + pe_win::image_tls_directory64, + pe_win::image_load_config_directory64> > pe64; } diff --git a/pe_lib/pe_base.cpp b/pe_lib/pe_base.cpp index 436b98a..ada3630 100644 --- a/pe_lib/pe_base.cpp +++ b/pe_lib/pe_base.cpp @@ -15,6 +15,8 @@ namespace pe_bliss { +using namespace pe_win; + const double pe_base::log_2 = 1.44269504088896340736; //instead of using M_LOG2E //Destructor @@ -5130,7 +5132,7 @@ uint32_t pe_base::basic_dotnet_info::get_size_of_managed_native_header() const const pe_base::basic_dotnet_info pe_base::get_basic_dotnet_info() const { //If there's no debug directory, return empty list - if(!has_debug()) + if(!is_dotnet()) throw pe_exception("Image does not have managed code", pe_exception::image_does_not_have_managed_code); //Return basic .NET information diff --git a/pe_lib/pe_base.h b/pe_lib/pe_base.h index 9f3caa8..018fa16 100644 --- a/pe_lib/pe_base.h +++ b/pe_lib/pe_base.h @@ -11,7 +11,7 @@ #include "pe_structures.h" //Please don't remove this information from header -//PEBliss 0.2.1 +//PEBliss 0.2.2 //(c) DX 2011 - 2012, http://kaimi.ru //Free to use, modify and distribute @@ -45,7 +45,7 @@ public: //STUB OVERLAY uint32_t get_version() const; uint32_t get_times() const; - public: //Setters, user by PE library only + public: //Setters, used by PE library only void set_number(uint32_t number); void set_version(uint32_t version); void set_times(uint32_t times); @@ -133,7 +133,7 @@ public: //SECTIONS private: //Section header - image_section_header header_; + pe_win::image_section_header header_; //Aligned sizes of section uint32_t raw_size_aligned_; @@ -260,8 +260,8 @@ public: //DIRECTORIES public: //PE HEADER //Returns DOS header - const image_dos_header& get_dos_header() const; - image_dos_header& get_dos_header(); + const pe_win::image_dos_header& get_dos_header() const; + pe_win::image_dos_header& get_dos_header(); //returns PE header start (e_lfanew) int32_t get_pe_header_start() const; @@ -1444,7 +1444,7 @@ public: //RESOURCES //Default constructor resource_directory(); //Constructor from data - explicit resource_directory(const image_resource_directory& dir); + explicit resource_directory(const pe_win::image_resource_directory& dir); //Returns characteristics of directory uint32_t get_characteristics() const; @@ -1556,7 +1556,7 @@ public: //EXCEPTION DIRECTORY (exists on PE+ only) //Default constructor exception_entry(); //Constructor from data - exception_entry(const image_runtime_function_entry& entry, const unwind_info& unwind_info); + exception_entry(const pe_win::image_runtime_function_entry& entry, const pe_win::unwind_info& unwind_info); //Returns starting address of function, affected by exception unwinding uint32_t get_begin_address() const; @@ -1618,10 +1618,10 @@ public: //DEBUG //Default constructor pdb_7_0_info(); //Constructor from data - explicit pdb_7_0_info(const CV_INFO_PDB70* info); + explicit pdb_7_0_info(const pe_win::CV_INFO_PDB70* info); //Returns debug PDB 7.0 structure GUID - const guid get_guid() const; + const pe_win::guid get_guid() const; //Returns age of build uint32_t get_age() const; //Returns PDB file name / path @@ -1629,7 +1629,7 @@ public: //DEBUG private: uint32_t age_; - guid guid_; + pe_win::guid guid_; std::string pdb_file_name_; }; @@ -1640,7 +1640,7 @@ public: //DEBUG //Default constructor pdb_2_0_info(); //Constructor from data - explicit pdb_2_0_info(const CV_INFO_PDB20* info); + explicit pdb_2_0_info(const pe_win::CV_INFO_PDB20* info); //Returns debug PDB 2.0 structure signature uint32_t get_signature() const; @@ -1662,7 +1662,7 @@ public: //DEBUG //Default constructor misc_debug_info(); //Constructor from data - explicit misc_debug_info(const image_debug_misc* info); + explicit misc_debug_info(const pe_win::image_debug_misc* info); //Returns debug data type uint32_t get_data_type() const; @@ -1742,7 +1742,7 @@ public: //DEBUG //Default constructor coff_debug_info(); //Constructor from data - explicit coff_debug_info(const image_coff_symbols_header* info); + explicit coff_debug_info(const pe_win::image_coff_symbols_header* info); //Returns number of symbols uint32_t get_number_of_symbols() const; @@ -1822,7 +1822,7 @@ public: //DEBUG //Default constructor debug_info(); //Constructor from data - explicit debug_info(const image_debug_directory& debug); + explicit debug_info(const pe_win::image_debug_directory& debug); //Copy constructor debug_info(const debug_info& info); //Copy assignment operator @@ -1916,7 +1916,7 @@ public: //.NET //Default constructor basic_dotnet_info(); //Constructor from data - explicit basic_dotnet_info(const image_cor20_header& header); + explicit basic_dotnet_info(const pe_win::image_cor20_header& header); //Returns major runtime version uint16_t get_major_runtime_version() const; @@ -1972,7 +1972,7 @@ public: //.NET uint32_t get_size_of_managed_native_header() const; private: - image_cor20_header header_; + pe_win::image_cor20_header header_; }; //Returns basic .NET information @@ -2054,7 +2054,7 @@ public: //UTILS // ========== END OF PUBLIC MEMBERS AND STRUCTURES ========== // protected: //Image DOS header - image_dos_header dos_header_; + pe_win::image_dos_header dos_header_; //Rich (stub) overlay data (for MSVS) std::string rich_overlay_; //List of image sections @@ -2075,7 +2075,7 @@ protected: //Reads and checks DOS header void read_dos_header(std::istream& file); //Reads and checks DOS header - static void read_dos_header(std::istream& file, image_dos_header& header); + static void read_dos_header(std::istream& file, pe_win::image_dos_header& header); //Returns stream size static std::streamoff get_file_size(std::istream& file); diff --git a/pe_lib/pe_resource_manager.cpp b/pe_lib/pe_resource_manager.cpp index 1b5c913..d033df2 100644 --- a/pe_lib/pe_resource_manager.cpp +++ b/pe_lib/pe_resource_manager.cpp @@ -8,6 +8,8 @@ namespace pe_bliss { +using namespace pe_win; + //Root version info block key value const u16string pe_resource_viewer::version_info_key(U16TEXT("V\0S\0_\0V\0E\0R\0S\0I\0O\0N\0_\0I\0N\0F\0O\0\0")); //Default process language, UNICODE diff --git a/pe_lib/pe_resource_manager.h b/pe_lib/pe_resource_manager.h index 5b51b65..2ec28bf 100644 --- a/pe_lib/pe_resource_manager.h +++ b/pe_lib/pe_resource_manager.h @@ -251,7 +251,7 @@ public: //VERSION INFO //Default constructor file_version_info(); //Constructor from Windows fixed version info structure - explicit file_version_info(const vs_fixedfileinfo& info); + explicit file_version_info(const pe_win::vs_fixedfileinfo& info); public: //Getters //Returns true if file is debug-built diff --git a/pe_lib/pe_structures.h b/pe_lib/pe_structures.h index 80ba042..ba37fc5 100644 --- a/pe_lib/pe_structures.h +++ b/pe_lib/pe_structures.h @@ -8,6 +8,8 @@ namespace pe_bliss { +namespace pe_win +{ const uint32_t image_numberof_directory_entries = 16; const uint32_t image_nt_optional_hdr32_magic = 0x10b; const uint32_t image_nt_optional_hdr64_magic = 0x20b; @@ -973,7 +975,7 @@ struct image_load_config_directory64 }; #pragma pack(pop) - +} //namespace pe_win #ifdef PE_BLISS_WINDOWS typedef wchar_t unicode16_t; @@ -983,4 +985,5 @@ typedef std::basic_string<unicode16_t> u16string; typedef unsigned short unicode16_t; typedef std::basic_string<unicode16_t> u16string; #endif -} + +} //namespace pe_bliss diff --git a/samples/resource_editor/main.cpp b/samples/resource_editor/main.cpp index bfacdb2..a83df57 100644 --- a/samples/resource_editor/main.cpp +++ b/samples/resource_editor/main.cpp @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) //ОÑталоÑÑŒ переименовать Ñтарую Ñекцию реÑурÑов //Она называетÑÑ .rsrc //Переименование необходимо Ð´Ð»Ñ Ñ‚Ð¾Ð³Ð¾, чтобы Windows Explorer Ñмог Ñчитать из новой Ñекции иконку - image->section_from_directory(image_directory_entry_resource).set_name("oldres"); + image->section_from_directory(pe_win::image_directory_entry_resource).set_name("oldres"); //ПереÑоберем реÑурÑÑ‹ //Они будет иметь больший размер, чем до нашего редактированиÑ, diff --git a/samples/sections_and_addresses/main.cpp b/samples/sections_and_addresses/main.cpp index e62fec8..dccf36f 100644 --- a/samples/sections_and_addresses/main.cpp +++ b/samples/sections_and_addresses/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) //ЕÑли у PE-файла еÑÑ‚ÑŒ импорты, выведем Ð¸Ð¼Ñ Ñекции, в которой они находÑÑ‚ÑÑ if(image->has_imports()) - std::cout << "Import section name: " << image->section_from_directory(image_directory_entry_import).get_name() << std::endl; + std::cout << "Import section name: " << image->section_from_directory(pe_win::image_directory_entry_import).get_name() << std::endl; } catch(const pe_exception& e) { -- GitLab