Skip to content
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

Unable to add a Import using the AddImport method #234

Open
skul377 opened this issue Apr 14, 2022 · 1 comment
Open

Unable to add a Import using the AddImport method #234

skul377 opened this issue Apr 14, 2022 · 1 comment

Comments

@skul377
Copy link

skul377 commented Apr 14, 2022

I tried using the stock templat as given below to add an import to a file. However, I am not able to see the import added to the binary.
Please let me know where I am going wrong.

            PeNet.PeFile peFile = new PeNet.PeFile(@"D:\Sample\7z.exe");
            peFile.AddImport("gdi32.dll", "StartPage");

I imported the package via NuGet and compiled the code.
The code exits as expected but doesn't provide the expected results.

@superewald
Copy link

Had the same issue and worked around it by saving the rawFile buffer to file (it seems like AddImport doesn't apply changes to the binary).

So in your case do this:

// add import
PeNet.PeFile peFile = new PeNet.PeFile(@"D:\Sample\7z.exe");
peFile.AddImport("gdi32.dll", "StartPage");
// save binary to disk
File.WriteAllBytes(@"D:\Sample\7z.exe", peFile.rawFile.ToArray());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants