-
Notifications
You must be signed in to change notification settings - Fork 156
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
pecopy on PE executables built by mingw not working #691
Comments
What's the reason you showed this? It seems fine to me.
The first problem here is that this is using long section names, which requires writing the symbol table and string table, but For the assertions, I'm not 100% sure because I don't have your binary to look at, but for the binary I tested on here, the problem is that the You could maybe fix that with a patch like this: --- a/crates/examples/src/bin/pecopy.rs
+++ b/crates/examples/src/bin/pecopy.rs
@@ -114,6 +114,11 @@ fn copy_file<Pe: ImageNtHeaders>(in_data: &[u8]) -> Result<Vec<u8>, Box<dyn Erro
let mut in_sections_data = Vec::new();
for index in &in_sections_index {
let in_section = in_sections.section(*index)?;
+ let offset = in_section.pointer_to_raw_data.get(LE);
+ if offset != 0 {
+ writer.reserve_until(offset);
+ }
+ writer.reserve_virtual_until(in_section.virtual_address.get(LE));
let range = writer.reserve_section(
in_section.name,
in_section.characteristics.get(LE), but that still doesn't produce a working executable, and I haven't debugged further to find out why. So, the If we were to provide support for being able to copy any file, what needs to be done is to add In the meantime, you may want to look at using |
I've added The main.exe in question can be found at https://nixcloud.io/mini-main.zip and it also contains the source code. It creates some files in your windows temp for testing std::filesystem on windows with symlinks. It requires c:\nix to exist. Don't run it but if you do it probably won't damage anything. This is how I compile it: https://lastlog.de/blog/libnix_mingw_status.html and I provide this since you might be curious what I'm doing. Can you please explain why I'll need to have a closer look into the goblin link you provided, thanks! running main.exe, the original
For me, using your patch and reenabling assertions, it produces a working executable! running the pecopy main.exe copy
|
It's not useful as is because it doesn't do any modifications to the data, and it doesn't claim to support everything possible in a PE file. However, if you can get it to work for what you need then that's great. The mini-main.zip doesn't appear to be the same file that you were using in your initial report, because it doesn't contain any sections with long names, and pecopy works on it without the need for any patch. |
I think I uploaded the original binary to https://nixcloud.io/nix.exe but know it is rather big. Thanks for your explanation. PE modifications are indeed very hard as there are so many compiler/linker specific details which are easy to miss when doing rewrites. I looked at the ifrit link you pointed me to, looks promising but bails out for main.exe and nix.exe with:
I'll have to re-consider possible solutions to my dll name patching with this knowledge. Seems it does not like mingw/ld binaries. |
I've tried to use pecopy (commit aa2f5ad) on Windows using:
This works nicely!
But using it on nix.exe, which i built using mingw from linux in a cross compiler setup, it hits all 3 assertions:
I removed the asserts and added the !virtual_address and !pointer_to_raw_data print instead, this is what it looks like for the segments:
This is the output of the relevant data points:
And .bss section looks like this from the PE header:
Ideas how this could be fixed?
The text was updated successfully, but these errors were encountered: