-1

I made a program in C using the Win32 API. I managed to modify some images and save them in a file. I'm trying to modify a string table but I can't. I only managed to display it as a normal string.

Image from Resource Tuner:

image

My C code:

#include <windows.h>

int main() {
    const char* dllPath = "path/to/your_dll.dll";

    const int resourceID = 296; 

    const char* newText = "Hello World";

    HANDLE hUpdate = BeginUpdateResource(dllPath, FALSE);
    if (hUpdate == NULL) {
        return 1;
    }

    BOOL result = UpdateResource(hUpdate, RT_STRING, MAKEINTRESOURCE(resourceID), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (LPVOID)newText, strlen(newText) + 1);
    if (result == FALSE) {
        EndUpdateResource(hUpdate, TRUE); 
        return 1;
    }

    result = EndUpdateResource(hUpdate, FALSE);
    if (result == FALSE) {
        return 1;
    }

    return 0;
}

My String is to address 296. After some work, I get this result, but it isn't recognized by the Software that uses this .dll file.

It was represented like this: 'Hello World' without any table indentation.

I tried to build the same as there, with the same structure, but it is still recognized as a single string, not as a string table.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    Can we see a [mcve], please? Make sure to read through [ask] as well. – IInspectable Jun 16 '23 at 06:22
  • This is the code as an example of what I did, I need advice, not a complete code. Later I will add in a function the code to modify that string. I have specified details such as the ID of the resource and the address of the string can be seen in the picture. – Cezar Catarau Jun 16 '23 at 06:27
  • The sample contains too much code that has nothing to do with the question. It looks like the function `changeTextFromIXtoGd()` is the only relevant part. Please remove all other code which distracts. – zett42 Jun 16 '23 at 09:42
  • 1
    I only put a program that contains the sequence used by me. – Cezar Catarau Jun 16 '23 at 11:14
  • 2
    Strings aren't stored as individual resource entries. Instead, they are stored in batches of 16. [Updating a string table with UpdateResource](https://stackoverflow.com/q/14088057/1889329) explains how this works. To replace a single string you'll have to read the full batch that contains it, copy the existing entries while modifying the single instance you're interested in, and then write the full batch back. – IInspectable Jun 16 '23 at 13:04

1 Answers1

0

I agree with the community: String resources are different from any other resource format. They are not stored as individual entries but packaged into groups of 16 strings each.

For more details, you could refer to the thread:updating a string table with UpdateResource

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20