Created
July 17, 2023 03:31
-
-
Save danielpyon/875c43b5e66c74c19ab206fbc2e8e740 to your computer and use it in GitHub Desktop.
ImagePrc Solution
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
#ifndef UNICODE | |
#define UNICODE | |
#endif | |
#define PIXELDATA_SIZE 90000 | |
#include <windows.h> | |
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | |
static BYTE* pixeldata; | |
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) | |
{ | |
// Register the window class. | |
const wchar_t CLASS_NAME[] = L"Window Class"; | |
WNDCLASS wc = { }; | |
wc.lpfnWndProc = WindowProc; | |
wc.hInstance = hInstance; | |
wc.lpszClassName = CLASS_NAME; | |
RegisterClass(&wc); | |
// Initialize pixeldata. | |
OutputDebugString(L"Loading pixeldata...\n"); | |
pixeldata = (BYTE*)HeapAlloc(GetProcessHeap(), 0, PIXELDATA_SIZE); | |
HANDLE hFile = CreateFile(L"C:\\Users\\pyond\\Documents\\Reversing.kr\\ImagePrc\\solve\\flag.bmp", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
if (hFile != INVALID_HANDLE_VALUE) { | |
DWORD dwBytesRead = 0; | |
if (ReadFile(hFile, (LPVOID)pixeldata, PIXELDATA_SIZE, &dwBytesRead, NULL) == FALSE) { | |
OutputDebugString(L"Could not read file!\n"); | |
} | |
else { | |
OutputDebugString(L"Success reading pixel data!\n"); | |
} | |
} | |
else { | |
OutputDebugString(L"Could not open file!\n"); | |
} | |
// Create the window. | |
HWND hwnd = CreateWindowEx( | |
0, // Optional window styles. | |
CLASS_NAME, // Window class | |
L"solve ImagePrc", // Window text | |
WS_OVERLAPPEDWINDOW, // Window style | |
// Size and position | |
CW_USEDEFAULT, CW_USEDEFAULT, 200, 150, | |
NULL, // Parent window | |
NULL, // Menu | |
hInstance, // Instance handle | |
NULL // Additional application data | |
); | |
if (hwnd == NULL) | |
{ | |
return 0; | |
} | |
ShowWindow(hwnd, nCmdShow); | |
// Run the message loop. | |
MSG msg = { }; | |
while (GetMessage(&msg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
OutputDebugString(L"Freeing memory for pixel data..."); | |
HeapFree(GetProcessHeap(), 0, pixeldata); | |
return 0; | |
} | |
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (uMsg) | |
{ | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
return 0; | |
case WM_PAINT: | |
{ | |
PAINTSTRUCT ps; | |
struct tagBITMAPINFO bmi; | |
memset(&bmi, 0, 0x28u); | |
bmi.bmiHeader.biHeight = 0x96; | |
bmi.bmiHeader.biWidth = 0xc8; | |
bmi.bmiHeader.biSize = 40; | |
bmi.bmiHeader.biPlanes = 1; | |
bmi.bmiHeader.biBitCount = 24; | |
bmi.bmiHeader.biCompression = 0; | |
RECT rc; | |
GetClientRect(hwnd, &rc); | |
HDC hdc = BeginPaint(hwnd, &ps); | |
// All painting occurs here, between BeginPaint and EndPaint. | |
// Get window width, height | |
WINDOWINFO info; | |
if (::GetWindowInfo(hwnd, &info)) { | |
LONG width = info.rcWindow.right - info.rcWindow.left; | |
LONG height = info.rcWindow.bottom - info.rcWindow.top; | |
StretchDIBits(hdc, 0, 0, rc.right, rc.bottom, 0, 0, width, height, pixeldata, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, SRCCOPY); | |
} | |
EndPaint(hwnd, &ps); | |
} | |
return 0; | |
} | |
return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment