📄 kernel32.c
字号:
fd32_log_printf("[WINB] res: %d\n", res);#endif if (res >= 0) { *lpNumberOfBytesWritten = res; return TRUE; } else { return FALSE; }}/* ______________________________ *\ *| |* *| Console Functions |*\*|______________________________|*/static HANDLE WINAPI fd32_imp__CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] CreateConsoleScreenBuffer: %lx %lx Scrbuf at %lx\n", dwDesiredAccess, dwShareMode, (DWORD)lpScreenBufferData);#endif return 0;}static BOOL WINAPI fd32_imp__FillConsoleOutputAttribute(HANDLE hConsoleOutput, WORD wAttribute, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] FillConsoleOutputAttribute: %lx %d %ld (%d %d)\n", (DWORD)hConsoleOutput, wAttribute, nLength, dwWriteCoord.X, dwWriteCoord.Y);#endif return FALSE;}static BOOL WINAPI fd32_imp__FillConsoleOutputCharacterA(HANDLE hConsoleOutput, CHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] FillConsoleOutputCharacterA: %lx %c %ld (%d %d)\n", (DWORD)hConsoleOutput, cCharacter, nLength, dwWriteCoord.X, dwWriteCoord.Y);#endif return FALSE;}static BOOL WINAPI fd32_imp__FlushConsoleInputBuffer(HANDLE hConsoleInput){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] FlushConsoleInputBuffer: %lx\n", (DWORD)hConsoleInput);#endif return fd32_imp__FlushFileBuffers(hConsoleInput);}static BOOL WINAPI fd32_imp__GetConsoleCursorInfo(HANDLE hConsoleOutput, PCONSOLE_CURSOR_INFO lpConsoleCursorInfo){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleCursorInfo: %lx (%ld %d)\n", (DWORD)hConsoleOutput, lpConsoleCursorInfo->dwSize, lpConsoleCursorInfo->bVisible);#endif return TRUE;}static BOOL WINAPI fd32_imp__GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] GetConsoleMode: %lx\n", (DWORD)hConsoleHandle);#endif *lpMode = ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT; /* WRAP_AT_EOL */ return TRUE;}static BOOL WINAPI fd32_imp__GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo){ /* TODO: Check if the display window size is correct */ lpConsoleScreenBufferInfo->dwSize.X = 80; lpConsoleScreenBufferInfo->dwSize.Y = 25; lpConsoleScreenBufferInfo->wAttributes = FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED; lpConsoleScreenBufferInfo->srWindow.Left = 0; lpConsoleScreenBufferInfo->srWindow.Top = 0; lpConsoleScreenBufferInfo->srWindow.Right = 79; lpConsoleScreenBufferInfo->srWindow.Bottom = 24; lpConsoleScreenBufferInfo->dwMaximumWindowSize.X = 80; lpConsoleScreenBufferInfo->dwMaximumWindowSize.Y = 25; return TRUE;}static DWORD WINAPI fd32_imp__GetConsoleTitleA(LPSTR lpConsoleTitle, DWORD nSize){ /* TODO: Set the title to the program's name */ if (lpConsoleTitle != NULL) return snprintf(lpConsoleTitle, nSize, "FD32-CONSOLE"); else return 0;}COORD WINAPI fd32_imp__GetLargestConsoleWindowSize(HANDLE hConsoleOutput){ COORD size = {80, 25}; return size;}BOOL WINAPI fd32_imp__GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons){ *lpNumberOfMouseButtons = 2; return TRUE;}/* The GetStdHandle function returns a handle for the standard input, standard output, or standard error device. * * Return Values * If the function succeeds, the return value is a handle of the specified device. * If the function fails, the return value is the INVALID_HANDLE_VALUE flag. To get extended error information, call GetLastError. */static HANDLE WINAPI fd32_imp__GetStdHandle(DWORD nStdHandle){ HANDLE handle;#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] GetStdHandle: %lx\n", nStdHandle);#endif switch(nStdHandle) { case STD_INPUT_HANDLE: handle = (HANDLE)0; break; case STD_OUTPUT_HANDLE: handle = (HANDLE)1; break; case STD_ERROR_HANDLE: handle = (HANDLE)2; break; default: handle = INVALID_HANDLE_VALUE; break; } return handle;}static BOOL WINAPI fd32_imp__ReadConsoleOutputA(HANDLE hConsoleOutput, PCHAR_INFO lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpReadRegion){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] ReadConsoleOutputA: %lx\n", (DWORD)hConsoleOutput);#endif return TRUE;}static BOOL WINAPI fd32_imp__ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, CONST SMALL_RECT *lpScrollRectangle, CONST SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, CONST CHAR_INFO *lpFill){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] ScrollConsoleScreenBufferA: %lx\n", (DWORD)hConsoleOutput);#endif /* NOTE: fake function return true */ return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleActiveScreenBuffer: %lx\n", (DWORD)hConsoleOutput);#endif /* NOTE: Support only one screen buffer return true directly */ return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleCursorInfo(HANDLE hConsoleOutput, CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleCursorInfo: %lx (%ld %d)\n", (DWORD)hConsoleOutput, lpConsoleCursorInfo->dwSize, lpConsoleCursorInfo->bVisible);#endif return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleCursorPosition(HANDLE hConsoleOutput, COORD dwCursorPosition){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleCursorPosition: %lx (%d %d)\n", (DWORD)hConsoleOutput, dwCursorPosition.X, dwCursorPosition.Y);#endif return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleMode: %lx, %lx\n", (DWORD)hConsoleHandle, dwMode);#endif return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize){ /* TODO: Support screen buffer size changing */ return FALSE;}static BOOL WINAPI fd32_imp__SetConsoleTitleA(LPCSTR lpConsoleTitle){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleTitleA: %s\n", lpConsoleTitle);#endif return TRUE;}static BOOL WINAPI fd32_imp__SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, CONST SMALL_RECT *lpConsoleWindow){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] SetConsoleWindowInfo: %lx, %x (%d, %d, %d, %d)\n", (DWORD)hConsoleOutput, bAbsolute, lpConsoleWindow->Left, lpConsoleWindow->Top, lpConsoleWindow->Right, lpConsoleWindow->Bottom);#endif /* NOTE: fake function return true */ return TRUE;}static BOOL WINAPI fd32_imp__WriteConsoleOutputA(HANDLE hConsoleOutput, CONST CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpWriteRegion){#ifdef __WINB_DEBUG__ fd32_log_printf("[WINB] WriteConsoleOutputA: %lx\n", (DWORD)hConsoleOutput);#endif return TRUE;}static char kernel32_name[] = "kernel32.dll";static struct symbol kernel32_symarray[] = { {"AddAtomA", (uint32_t)fd32_imp__AddAtomA}, {"CloseHandle", (uint32_t)fd32_imp__CloseHandle}, {"CreateConsoleScreenBuffer", (uint32_t)fd32_imp__CreateConsoleScreenBuffer}, {"CreateFileA", (uint32_t)fd32_imp__CreateFileA}, {"ExitProcess", (uint32_t)fd32_imp__ExitProcess}, {"FillConsoleOutputAttribute", (uint32_t)fd32_imp__FillConsoleOutputAttribute}, {"FillConsoleOutputCharacterA", (uint32_t)fd32_imp__FillConsoleOutputCharacterA}, {"FindAtomA", (uint32_t)fd32_imp__FindAtomA}, {"FlushConsoleInputBuffer", (uint32_t)fd32_imp__FlushConsoleInputBuffer}, {"FlushFileBuffers", (uint32_t)fd32_imp__FlushFileBuffers}, {"GetAtomNameA", (uint32_t)fd32_imp__GetAtomNameA}, {"GetCommandLineA", (uint32_t)fd32_imp__GetCommandLineA}, {"GetConsoleCursorInfo", (uint32_t)fd32_imp__GetConsoleCursorInfo}, {"GetConsoleMode", (uint32_t)fd32_imp__GetConsoleMode}, {"GetConsoleScreenBufferInfo", (uint32_t)fd32_imp__GetConsoleScreenBufferInfo}, {"GetConsoleTitleA", (uint32_t)fd32_imp__GetConsoleTitleA}, {"GetCurrentProcessId", (uint32_t)fd32_imp__GetCurrentProcessId}, {"GetCurrentThreadId", (uint32_t)fd32_imp__GetCurrentThreadId}, {"GetEnvironmentStringsA", (uint32_t)fd32_imp__GetEnvironmentStringsA}, {"GetLargestConsoleWindowSize", (uint32_t)fd32_imp__GetLargestConsoleWindowSize}, {"GetLastError", (uint32_t)fd32_imp__GetLastError}, {"GetModuleHandleA", (uint32_t)fd32_imp__GetModuleHandleA}, {"GetNumberOfConsoleMouseButtons", (uint32_t)fd32_imp__GetNumberOfConsoleMouseButtons}, {"GetStartupInfoA", (uint32_t)fd32_imp__GetStartupInfoA}, {"GetStdHandle", (uint32_t)fd32_imp__GetStdHandle}, {"GetSystemInfo", (uint32_t)fd32_imp__GetSystemInfo}, {"GetSystemTimeAsFileTime", (uint32_t)fd32_imp__GetSystemTimeAsFileTime}, {"GetTickCount", (uint32_t)fd32_imp__GetTickCount}, {"GetVersionExA", (uint32_t)fd32_imp__GetVersionExA}, {"GlobalAlloc", (uint32_t)fd32_imp__GlobalAlloc}, {"GlobalFree", (uint32_t)fd32_imp__GlobalFree}, {"LocalAlloc", (uint32_t)fd32_imp__LocalAlloc}, {"LocalFree", (uint32_t)fd32_imp__LocalFree}, {"PeekNamedPipe", (uint32_t)fd32_imp__PeekNamedPipe}, {"QueryPerformanceCounter", (uint32_t)fd32_imp__QueryPerformanceCounter}, {"ReadConsoleOutputA", (uint32_t)fd32_imp__ReadConsoleOutputA}, {"ReadFile", (uint32_t)fd32_imp__ReadFile}, {"ScrollConsoleScreenBufferA", (uint32_t)fd32_imp__ScrollConsoleScreenBufferA}, {"SetConsoleActiveScreenBuffer",(uint32_t)fd32_imp__SetConsoleActiveScreenBuffer}, {"SetConsoleCursorInfo", (uint32_t)fd32_imp__SetConsoleCursorInfo}, {"SetConsoleCursorPosition", (uint32_t)fd32_imp__SetConsoleCursorPosition}, {"SetConsoleMode", (uint32_t)fd32_imp__SetConsoleMode}, {"SetConsoleTitleA", (uint32_t)fd32_imp__SetConsoleTitleA}, {"SetConsoleScreenBufferSize", (uint32_t)fd32_imp__SetConsoleScreenBufferSize}, {"SetConsoleWindowInfo", (uint32_t)fd32_imp__SetConsoleWindowInfo}, {"SetEndOfFile", (uint32_t)fd32_imp__SetEndOfFile}, {"SetErrorMode", (uint32_t)fd32_imp__SetErrorMode}, {"SetFilePointer", (uint32_t)fd32_imp__SetFilePointer}, {"SetLastError", (uint32_t)fd32_imp__SetLastError}, {"SetUnhandledExceptionFilter", (uint32_t)fd32_imp__SetUnhandledExceptionFilter}, {"Sleep", (uint32_t)fd32_imp__Sleep}, {"VirtualAlloc", (uint32_t)fd32_imp__VirtualAlloc}, {"VirtualFree", (uint32_t)fd32_imp__VirtualFree}, {"WriteConsoleOutputA", (uint32_t)fd32_imp__WriteConsoleOutputA}, {"WriteFile", (uint32_t)fd32_imp__WriteFile},};static uint32_t kernel32_symnum = sizeof(kernel32_symarray)/sizeof(struct symbol);void install_kernel32(void){ add_dll_table(kernel32_name, HANDLE_OF_KERNEL32, kernel32_symnum, kernel32_symarray);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -