4

I have a Windows native application that contain embedded resources and I'd like to access them using the native API. Are there native functions that handle resources (something similar to FindResource/LoadResource) or I will have to create my own PE reader to extract them?

Thiago Cardoso
  • 725
  • 1
  • 5
  • 19
  • If I may ask, why are you writing a native application? If the resources are mapped into the memory, and I presume they'd be or you can easily map the rest of the executable in, you can access them just by knowing their address, so no special APIs are needed. What kinds of embedded resources do you use? – Kuba hasn't forgotten Monica Apr 13 '16 at 18:58
  • 1
    @KubaOber: You need a native application, if you want to execute before the Win32 subsystem is loaded. *"You can access them just by knowing their address"* - `FindResource` would be the API to get to know the address. – IInspectable Apr 13 '16 at 19:55
  • Exactly, it is an application that needs to be executed before Win32 is loaded. If the rest of the executable containing the resources aren't mapped to memory, how can I do it? And how can I programmatically find the resource address once I don't define it beforehand (it is the linker job to put the resource inside the executable). – Thiago Cardoso Apr 13 '16 at 20:01
  • 1
    I imagine you'd use `cvtres` to get an object file from your `.res` file, then dump it to know the symbol names of each resource, then declare these as extern data for the compiler, and take their address from C code as needed. The linker will patch it all up, just as it does for all other addresses unknown at compile time. You can also tweak linking so that the .rsrc section is mapped (if it isn't). – Kuba hasn't forgotten Monica Apr 13 '16 at 22:05
  • That's a good suggestion. Let me see if anyone else has a less hackish way to solve it :) – Thiago Cardoso Apr 14 '16 at 12:38

1 Answers1

3

Ntdll exports LdrFindResource_U and LdrAccessResource that are almost counterparts of FindResource and LoadResource, respectively. You'll need in addition a counterpart of GetModuleHandle to use them. Wine source (specially resource.c and module.c) can be used as documentation of these functions.

Thiago Cardoso
  • 725
  • 1
  • 5
  • 19