Skip to content

Instantly share code, notes, and snippets.

@valinet
Last active December 18, 2024 08:54
Show Gist options
  • Select an option

  • Save valinet/67a70f1deffaec13840757d78c46f36c to your computer and use it in GitHub Desktop.

Select an option

Save valinet/67a70f1deffaec13840757d78c46f36c to your computer and use it in GitHub Desktop.

Revisions

  1. valinet revised this gist Oct 23, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions DumpStringTable.cpp
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #include <Windows.h>
    #include <iostream>
    #include <io.h>
    #include <fcntl.h>

    BOOL EnumresLang(HMODULE hModule, LPCWSTR lpType, LPCWSTR lpName, WORD wLanguage, LONG_PTR lParam)
    {
    @@ -95,6 +97,7 @@ void DumpStringTable(LPCWSTR filePath)

    int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
    {
    _setmode(_fileno(stdout), _O_U16TEXT);
    if (argc == 2)
    {
    DumpStringTable(argv[1]);
  2. valinet created this gist Oct 23, 2021.
    103 changes: 103 additions & 0 deletions DumpStringTable.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@
    #include <Windows.h>
    #include <iostream>

    BOOL EnumresLang(HMODULE hModule, LPCWSTR lpType, LPCWSTR lpName, WORD wLanguage, LONG_PTR lParam)
    {
    if (lpType == RT_STRING)
    {
    const HRSRC res = FindResourceEx(hModule, lpType, lpName, wLanguage);
    if (!res)
    {
    wprintf(L"FindResourceEx failed err: %u\n", GetLastError());
    return FALSE;
    }

    const DWORD size = SizeofResource(hModule, res);
    if (!size)
    {
    wprintf(L"SizeofResource failed err: %u\n", GetLastError());
    return FALSE;
    }

    HGLOBAL hMem = LoadResource(hModule, res);
    if (!hMem)
    {
    wprintf(L"LoadResource failed err: %u\n", GetLastError());
    return FALSE;
    }

    LPWORD data = (LPWORD)LockResource(hMem);
    if (!data)
    {
    wprintf(L"LockResource failed err: %u\n", GetLastError());
    return FALSE;
    }

    const WORD nameInt = (WORD)(((ULONG_PTR)lpName) & 0xFFFF);
    for (WORD i = 0; i < 16; i++)
    {
    const WORD len = *data;
    data++;
    if (len)
    {
    const WORD id = (nameInt - 1) * 16 + i;
    std::wstring str;
    str.append((const wchar_t*)data, len);
    data += len;
    wprintf(L"id:%u: %s\n", id, str.c_str());
    }
    }

    return TRUE;
    }
    return TRUE;
    }

    BOOL EnumResName(HMODULE hModule, LPCWSTR lpType, LPWSTR lpName, LONG_PTR lParam)
    {
    if (!EnumResourceLanguagesEx(hModule, lpType, lpName, (ENUMRESLANGPROCW)EnumresLang, 0, 0, 0))
    {
    wprintf(L"EnumResourceLanguagesEx failed err: %u\n", GetLastError());
    return FALSE;
    }

    return TRUE;
    }

    BOOL EnumResType(HMODULE hModule, LPWSTR lpType, LONG_PTR lParam)
    {
    if (!EnumResourceNamesEx(hModule, lpType, (ENUMRESNAMEPROCW)EnumResName, 0, 0, 0))
    {
    wprintf(L"EnumResourceNamesEx failed err: %u\n", GetLastError());
    return FALSE;
    }

    return TRUE;
    }

    void DumpStringTable(LPCWSTR filePath)
    {
    HMODULE hModule = LoadLibraryEx(filePath, nullptr, LOAD_LIBRARY_AS_DATAFILE);
    if (!hModule)
    {
    wprintf(L"LoadLibraryEx failed err: %u\n", GetLastError());
    return;
    }

    if (!EnumResourceTypesEx(hModule, (ENUMRESTYPEPROCW)EnumResType, 0, 0, 0))
    {
    wprintf(L"EnumResourceTypesEx failed err: %u\n", GetLastError());
    return;
    }

    FreeLibrary(hModule);
    }

    int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
    {
    if (argc == 2)
    {
    DumpStringTable(argv[1]);
    }
    return 0;
    }