PeNet icon indicating copy to clipboard operation
PeNet copied to clipboard

Unable to add a Import using the AddImport method

Open skul377 opened this issue 2 years ago • 1 comments

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.

skul377 avatar Apr 14 '22 21:04 skul377

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());

superewald avatar May 10 '22 09:05 superewald