Code Monkey home page Code Monkey logo

coffi's People

Contributors

belissent avatar exoosh avatar serge1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coffi's Issues

Remove MS EULA, get a proper open-source license for PEDump

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 files taken from microsoft-pdb (cvinfo.h, cvexefmt.h) have been released under the MIT License, so no need for an EULA there
  • As for PEDump, the copyright headers indicate this was written by Matt Pietrek and that he is the sole copyright owner. The headers have copyright dates up to 2001, and this is before he joined Microsoft. He has the source code up on his website here, and it contains no Microsoft 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).

Question regarding C++ standard you aim for with this library.

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.

Write COFF files

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?

Calculate entry point

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.