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

App can't run after using upx. #12

Closed
coolerfall opened this issue Nov 10, 2015 · 7 comments · Fixed by #32
Closed

App can't run after using upx. #12

coolerfall opened this issue Nov 10, 2015 · 7 comments · Fixed by #32
Labels

Comments

@coolerfall
Copy link

I want to compress the binary file, so I try upx. But app can't run after using upx if the generated .syso file contains icon resource. However, the app run correctly if the generated .syso file only contains manifest.

@akavel akavel added the bug label Nov 10, 2015
@josephspurrier
Copy link

Interesting. In my project, https://github.com/josephspurrier/goversioninfo, the icon resource looks like it messes up the version information when viewed in a resource editor, but still appears fine in the file properties. I wonder if the icon code has a bug that's screwing up the other resources.

@tmm1
Copy link
Contributor

tmm1 commented Jan 27, 2017

It seems like the icon is not being embedded correctly. Using https://github.com/zed-0xff/pedump on a generated binary, I see the error:

=== SECTIONS ===

  NAME          RVA      VSZ   RAW_SZ  RAW_PTR  nREL  REL_PTR nLINE LINE_PTR     FLAGS
  .text        1000   5149e3   514a00      600     0        0     0        0  60000060  R-X CODE IDATA
  .data      516000    4b720    22c00   515000     0        0     0        0  c0000040  RW- IDATA
  .idata     562000      536      600   537c00     0        0     0        0  c0000040  RW- IDATA
  .symtab    563000        4      200   538200     0        0     0        0  42000000  R-- DISCARDABLE
  .rsrc      564000     a340     a400   538400     0        0     0        0  c0000040  RW- IDATA
[?] ignoring invalid PEdump::BITMAPINFOHEADER

@akavel
Copy link
Owner

akavel commented Jan 29, 2017

Sorry, I totally don't have time to explore this issue now, and won't have for quite some time in the future :/ If anyone would be able to debug this and send a PR with a fix, I'd be very happy to merge; though please note you must be prepared for some back and forth of passing through my review, which may potentially require some refactoring. Anyone wanting to try a dab at this is also welcome to ask me here any questions about the codebase or talk about his/her ideas. Also any further debugging info trying to pinpoint the cause of the issue is welcome here (thanks @tmm1 for starting this!).

It may be especially interesting and valuable to find out what exactly is pedump complaining about. Maybe I could even fix it myself then, if it was simple enough. My method for building this app was, after I built the main features, mostly to compare my generated .so files with ones generated by windres in hex editor, and try to pinpoint any differences, then find what they mean and which can be important, and try fixing them until Go linker stops complaining. Pedump could be a nice tool to add to this checking phase.

@tmm1
Copy link
Contributor

tmm1 commented Jan 30, 2017

Looks like this is actually a bug with pedump, and presumably rsrc is creating valid EXEs. I had a separate issue with lxn/walk not using the icon for its windows (lxn/walk#236), which I was wrongly blaming on the generated syso file.

@tc-hib
Copy link
Contributor

tc-hib commented May 18, 2020

Hello, i think resource data must be aligned on 4 bytes.

So, in resource data entry you should only find offsets that are multiples of 4.

goversioninfo produces an invalid resource section when, because of the icon, it writes its data misaligned.

I wanted to provide a PR, but the code in rsrc is a little too clever for me. I think it'd be easier for me to rewrite it from scratch, or write a syso fixer.

I've fixed my own syso with an hex editor, and it suddenly produced a valid exe file according to Resource Hacker, before and after UPX compression.
I tried more padding: as long as it's aligned it's OK, otherwise it's not.

@tc-hib
Copy link
Contributor

tc-hib commented May 18, 2020

I tried misaligned icon pictures, and aligned version info.
After UPX compression, Windows couldn't draw the icon, while version info was fine.
So I think you really have to align every resource data.

@tc-hib
Copy link
Contributor

tc-hib commented May 21, 2020

You can try with this fork : https://github.com/tc-hib/rsrc
I'm not sure at all my fork is valid, I took a huge shortcut by aligning every data written from a byte array. It seems to work for my needs.

@akavel akavel closed this as completed in 9547050 Dec 10, 2020
akavel added a commit that referenced this issue Dec 10, 2020
Simpler approach to achieve the main goal of #32. Based esp. on a comment by
@tc-hib:

 > in [resource data entry](
 > https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#resource-data-entry)
 > you should only find offsets that are multiples of 4.

(#12 (comment))

HUUUUUUGE THANKS to @tc-hib, for his work with PR #32, for his patience,
perseverance and replies, and for the invaluable comment quoted above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants