Last active
October 23, 2021 15:30
-
-
Save valinet/67a70f1deffaec13840757d78c46f36c to your computer and use it in GitHub Desktop.
DumpStringTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
#include <io.h> | |
#include <fcntl.h> | |
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[]) | |
{ | |
_setmode(_fileno(stdout), _O_U16TEXT); | |
if (argc == 2) | |
{ | |
DumpStringTable(argv[1]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment