Hack Forums
[C] How do I correctly use String Tables, UpdateResource etc.? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] How do I correctly use String Tables, UpdateResource etc.? (/showthread.php?tid=6149011)



How do I correctly use String Tables, UpdateResource etc.? - lo0sr - Apr 12, 2021

Hello, I have now been for a few hours trying to update a String resource in another .exe file, but with no success so far.

Here is what I want to do:
IWantToUpdateAStringHere.exe (basically does: MessageBox(String1FromSt, String2FromST))

StringTable with 2 entries:
IDS_Hello 102 "Hello"
IDS_World 103 "World"

When I run this file I get a MessageBox that says has Hello as the title and World as the text.

Now I want to edit these resources by updating a string in the StringTable from another .exe, so that I could, for example, get the output Hello Test. But I always end up either creating a new StringTable and not updating the actual resource, or I overwrite the entire resource, and the actual program crashes.

I have been trying to find a proper example of how to do this, but I am not able to find a solution for String Tables.

Here is the code I use in the update.exe file:

Code
HANDLE hUpdateRes = BeginUpdateResource(TEXT("Test.exe"), FALSE);
TCHAR sz[] = TEXT("Test");
BOOL result = UpdateResource(hUpdateRes, RT_STRING, L"IDS_Hello", MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (void*)sz, (lstrlen(sz) + 4));
BOOL commit = EndUpdateResource(hUpdateRes, FALSE);

Thanks in advance for any help!


RE: How do I correctly use String Tables, UpdateResource etc.? - Sajuuk - Apr 12, 2021

Been a while since I've messed about with resources in general, but IIRC when replacing existing resource data in PEs the replacement has to be the same length as the original. Assuming the null terminator counts as the sixth character, you could just use "test \0" with the space (might have to use an identifier or typecast for it) along with the null terminator. Also, ensure type and encoding match both the original and replacement. (Just an idea. Don't know if that would cause any sort of issue, but just by how it sounds it very well may.)