question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add a new import to a PE file?

See original GitHub issue

Hello,

Thanks for the library. I took a look at both the docs, the issues and the source code, but couldn’t find something similar to what I need to do: programatically add a new import to a PE file.

To read what are the current imports I use PeFile.ImportedFunctions, but I noticed it is read only. Any tips on how to achieve that?

My goal is to write an auto patcher that will be able to fetch a DLL from the internet and then patch it to load a custom DLL of mine. I’m able to do that manually using some software I found online called LordPE, but I need to do that programatically. Sadly there’s no source code available for it.

I’m also having a tough time grasping how to implement that from scratch myself. The general idea seems to be:

  • Parse the PE
  • Find the offset where the Import section starts
  • Add a new import
  • Update the offset
  • Probably something more that I might be missing

Then I found out about PeNet and think it might be able to really help me out.

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
secanacommented, Jun 5, 2020
1reaction
secanacommented, Jun 2, 2020

Happy to hear that it works. I’ll keep the alpha out for a few more day in the case that you stumble upon a bug. If not I’ll merge it into master and release 2.3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add an entry to the import table of PE
I'm looking for a command line program to add an entry to the import table of a PE file. My goal is to...
Read more >
Add an entry to the import table of PE - Programming
I'm looking for a command line program to add an entry to the import table of a PE file. My goal is to...
Read more >
Injecting Code using Imported Functions into Native PE Files
Open the input PE file and read its headers and import directories. · Inject a new section containing our new code. · Rebuild...
Read more >
Add Imports to any x86 PE Header for game hacking
#include "PEFile.h" int main(int argc, char* argv[]) { // Open the input file PEFile pe("1.exe"); // Add "MessageBoxA" & "ShowWindow" ...
Read more >
Digging into Import Tables in PE Files - YouTube
Import tables are essential for programs during execution, as they allow them to import the functionality they need to interact with the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found