0

I'm trying to fix an issue with a compiled executable that the original developers have long given up support for. Essentially, the executable is using the wrong graphics card, it uses an integrated graphics card over the dedicated one.

I know I can go into my Graphics Settings on Windows or even through the Graphics Card control panel to select what graphics card the game uses, but I was curious if I could also do it programmatically at an assembly level.

I found this article that explains how you can do it programmatically, but now I'm wondering how I could do this using assembly.

Forcing Machine to Use Dedicated Graphics Card?

It looks like I only need to add this bit of code to the executables assembly. Is this possible, or does it have to be done in C++ before the EXE is compiled...? Or perhaps using a PE editor that is able to edit the export table (if that's a thing)...

extern "C" 
{
  __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
}

extern "C"
{
  __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
Ricky
  • 823
  • 2
  • 14
  • 31
  • I would guess that it’s possible, but I haven’t personally done exactly this. – 500 - Internal Server Error Nov 16 '22 at 22:43
  • I'm guessing it is too, but can't find anywhere explaining how or if a tool exists to add exports to the export table. – Ricky Nov 16 '22 at 23:54
  • Are you asking if you can add `__declspec(dllexport)` to variables that already exist but aren't exported, so you can set them from another program? Or are you trying to also add new variable that didn't previous have any storage space reserved? Also, your title is weird, `__declspec` in general can do many things, not just export. (Many of them only make sense at compile time, like 32-byte alignment for an array or something.) – Peter Cordes Nov 17 '22 at 05:54
  • @PeterCordes I am trying to add those 2 new variables that didn't previously have any storage space reserved. I'd imagine these are added to the Export Table after compilation, and to my understanding the Export Table can be changed if you change the other related offsets. Just don't know how or if a tool for this exists... – Ricky Nov 17 '22 at 15:50
  • I assume these are read-only flags. You could try locating a byte somewhere that happens to have value `1` then add the symbols pointing there. Haven't checked whether objcopy can do this for PE executables but it does at least have an `-add-symbol` option. – Jester Nov 17 '22 at 22:44

0 Answers0