akavel / rsrc

Tool for embedding .ico & manifest resources in Go programs for Windows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App can't run after using upx.

coolerfall opened this issue · comments

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.

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.

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

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.

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.

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.

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.

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.