serge1 / coffi Goto Github PK
View Code? Open in Web Editor NEWA header-only C++ library for accessing files in COFF binary format. (Including Windows PE/PE+ formats)
License: MIT License
A header-only C++ library for accessing files in COFF binary format. (Including Windows PE/PE+ formats)
License: MIT License
I wanted to include this library in my MIT-licensed project, but I noticed that there is a Microsoft EULA that is in the PE source code folder, indicating that part of this library is proprietary and precludes me from using it. However, after investigating further, I do not think it's actually appropriate to include the EULA:
The only issue I see here is that PEDump wasn't released with an open-source license. This could probably be solved by just talking to Matt and asking nicely. His current contact info is here. I have double-checked to make sure this is the same Matt Pietrek, he just changed careers to be a cocktail connoisseur (jealous tbh).
Hi @serge1,
I may have missed that part somewhere in the comments or documentation, but I was wondering if there is a minimum C++ standard you would like the library to work against?
That is, for PRs submitted to you, what C++ standard version would you like to be tested?
VS2022 can only be set down to C++14 if I saw that correctly, but of course nothing prevents anyone from acquiring and installing older compiler versions.
The reason I ask is that there are currently two potential memory leaks in the code and std::unique_ptr
would be the straightforward way to fix them. But that was only introduced in C++11.
The potential leaks can be addressed as follows:
diff --git a/coffi/coffi.hpp b/coffi/coffi.hpp
index 36cb6a4..d2a4156 100644
--- a/coffi/coffi.hpp
+++ b/coffi/coffi.hpp
@@ -646,24 +646,24 @@ class coffi : public coffi_strings,
{
std::streampos pos = stream.tellg();
for (int i = 0; i < coff_header_->get_sections_count(); ++i) {
- section* sec;
+ std::unique_ptr<section> sec;
switch (architecture_) {
case COFFI_ARCHITECTURE_PE:
case COFFI_ARCHITECTURE_CEVA:
- sec = new section_impl(this, this, this);
+ sec = std::make_unique<section_impl>(this, this, this);
break;
case COFFI_ARCHITECTURE_TI:
- sec = new section_impl_ti(this, this, this);
+ sec = std::make_unique<section_impl_ti>(this, this, this);
break;
default:
- sec = new section_impl(this, this, this);
+ sec = std::make_unique<section_impl>(this, this, this);
break;
}
if (!(sec->load(stream, i * sec->get_sizeof() + pos))) {
return false;
}
sec->set_index(i);
- sections_.push_back(sec);
+ sections_.push_back(sec.release());
}
return true;
diff --git a/coffi/coffi_directory.hpp b/coffi/coffi_directory.hpp
index 3cde467..0999b05 100644
--- a/coffi/coffi_directory.hpp
+++ b/coffi/coffi_directory.hpp
@@ -196,11 +196,11 @@ class directories : public std::vector<directory*>
{
for (uint32_t i = 0;
i < scn_->get_win_header()->get_number_of_rva_and_sizes(); ++i) {
- directory* d = new directory(i);
+ std::unique_ptr<directory> d = std::make_unique< directory>(i);
if (!d->load(stream)) {
return false;
}
- push_back(d);
+ push_back(d.release());
}
return true;
}
Of course one could take it even further by using unique_ptr
everywhere.
Additionally the following minor issues could be addressed as well with C++11 and newer using unified initialization for structs that are class members:
diff --git a/coffi/coffi_relocation.hpp b/coffi/coffi_relocation.hpp
index 7cbec1f..d604f52 100644
--- a/coffi/coffi_relocation.hpp
+++ b/coffi/coffi_relocation.hpp
@@ -167,7 +167,7 @@ class relocation
const symbol_provider* sym_;
const architecture_provider* arch_;
std::string symbol_name;
- rel_entry_generic header;
+ rel_entry_generic header{};
};
} // namespace COFFI
diff --git a/coffi/coffi_section.hpp b/coffi/coffi_section.hpp
index 39de317..b92117d 100644
--- a/coffi/coffi_section.hpp
+++ b/coffi/coffi_section.hpp
@@ -354,7 +354,7 @@ template <class T> class section_impl_tmpl : public section
//------------------------------------------------------------------------------
T header;
- uint32_t index;
+ uint32_t index{};
std::string name;
char* data_;
uint32_t data_reserved_;
diff --git a/coffi/coffi_directory.hpp b/coffi/coffi_directory.hpp
index 3cde467..6780b5f 100644
--- a/coffi/coffi_directory.hpp
+++ b/coffi/coffi_directory.hpp
@@ -163,7 +163,7 @@ class directory
}
private:
- image_data_directory header;
+ image_data_directory header{};
const char* data_;
uint32_t index_;
};
For index
arguably it could be added to the initializer list of the ctor.
I am thinking of extending COFFI in order to be able to create, modify and write COFF files.
I already have a small prototype partially working.
What do you think of this idea?
I was wondering, is there a way to calculate the entry point of a PE executable in file offset form. Like for example...
; Entry at 0x1000 or 4096
mov rsp, rbp
How would I go about that?
error: use of deleted function 'COFFI::coffi_strings::coffi_strings(const COFFI::coffi_strings&)'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.