diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2026-07-12 23:26:58 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2026-07-12 23:26:58 +0200 |
| commit | cee4c6d1c8cbf898d6aa9ad555d8dfcece4c7d96 (patch) | |
| tree | a5c9710ca65e4bc1183d365a013d4494882e0eb3 /src/parser.c | |
| parent | 7b6964eb1bcf30a0ae7ed3391adce30565b262b4 (diff) | |
Fix runtime crashes due to loaded functions
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 300 |
1 files changed, 1 insertions, 299 deletions
diff --git a/src/parser.c b/src/parser.c index 40133a7..8dcbc76 100644 --- a/src/parser.c +++ b/src/parser.c @@ -4,6 +4,7 @@ #include "module.h" #include "stack_walk.h" #include "disasm.h" +#include "win_funcs.h" // ======================= // ====== windows.h ====== @@ -27,202 +28,6 @@ #define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x00000040L) #define CONTEXT_KERNEL_CET (CONTEXT_AMD64 | 0x00000080L) -// -// Define 128-bit 16-byte aligned xmm register type. -// - -typedef struct __declspec(align(16)) _M128A { - u64 Low; - i64 High; -} M128A, *PM128A; - -// -// Format of data for (F)XSAVE/(F)XRSTOR instruction -// - -typedef struct __declspec(align(16)) _XSAVE_FORMAT { - u16 ControlWord; - u16 StatusWord; - u8 TagWord; - u8 Reserved1; - u16 ErrorOpcode; - u32 ErrorOffset; - u16 ErrorSelector; - u16 Reserved2; - u32 DataOffset; - u16 DataSelector; - u16 Reserved3; - u32 MxCsr; - u32 MxCsr_Mask; - M128A FloatRegisters[8]; - -#if defined(_WIN64) - - M128A XmmRegisters[16]; - u8 Reserved4[96]; - -#else - - M128A XmmRegisters[8]; - BYTE Reserved4[224]; - -#endif - -} XSAVE_FORMAT, *PXSAVE_FORMAT; - -typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32; - -// -// Context Frame -// -// This frame has a several purposes: 1) it is used as an argument to -// NtContinue, 2) it is used to constuct a call frame for APC delivery, -// and 3) it is used in the user level thread creation routines. -// -// -// The flags field within this record controls the contents of a CONTEXT -// record. -// -// If the context record is used as an input parameter, then for each -// portion of the context record controlled by a flag whose value is -// set, it is assumed that that portion of the context record contains -// valid context. If the context record is being used to modify a threads -// context, then only that portion of the threads context is modified. -// -// If the context record is used as an output parameter to capture the -// context of a thread, then only those portions of the thread's context -// corresponding to set flags will be returned. -// -// CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags. -// -// CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15. -// -// CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs. -// -// CONTEXT_FLOATING_POINT specifies Xmm0-Xmm15. -// -// CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7. -// - -typedef struct __declspec(align(16)) _CONTEXT { - - // - // Register parameter home addresses. - // - // N.B. These fields are for convience - they could be used to extend the - // context record in the future. - // - - u64 P1Home; - u64 P2Home; - u64 P3Home; - u64 P4Home; - u64 P5Home; - u64 P6Home; - - // - // Control flags. - // - - u32 ContextFlags; - u32 MxCsr; - - // - // Segment Registers and processor flags. - // - - u16 SegCs; - u16 SegDs; - u16 SegEs; - u16 SegFs; - u16 SegGs; - u16 SegSs; - u32 EFlags; - - // - // Debug registers - // - - u64 Dr0; - u64 Dr1; - u64 Dr2; - u64 Dr3; - u64 Dr6; - u64 Dr7; - - // - // Integer registers. - // - - u64 Rax; - u64 Rcx; - u64 Rdx; - u64 Rbx; - u64 Rsp; - u64 Rbp; - u64 Rsi; - u64 Rdi; - u64 R8; - u64 R9; - u64 R10; - u64 R11; - u64 R12; - u64 R13; - u64 R14; - u64 R15; - - // - // Program counter. - // - - u64 Rip; - - // - // Floating point state. - // - - union { - XMM_SAVE_AREA32 FltSave; - struct { - M128A Header[2]; - M128A Legacy[8]; - M128A Xmm0; - M128A Xmm1; - M128A Xmm2; - M128A Xmm3; - M128A Xmm4; - M128A Xmm5; - M128A Xmm6; - M128A Xmm7; - M128A Xmm8; - M128A Xmm9; - M128A Xmm10; - M128A Xmm11; - M128A Xmm12; - M128A Xmm13; - M128A Xmm14; - M128A Xmm15; - }; - }; - - // - // Vector registers. - // - - M128A VectorRegister[26]; - u64 VectorControl; - - // - // Special debug control registers. - // - - u64 DebugControl; - u64 LastBranchToRip; - u64 LastBranchFromRip; - u64 LastExceptionToRip; - u64 LastExceptionFromRip; -} CONTEXT, *PCONTEXT; - #define THREAD_TERMINATE (0x0001) #define THREAD_SUSPEND_RESUME (0x0002) #define THREAD_GET_CONTEXT (0x0008) @@ -254,101 +59,8 @@ typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters -// -// Exception record definition. -// - -typedef struct _EXCEPTION_RECORD { - u32 ExceptionCode; - u32 ExceptionFlags; - struct _EXCEPTION_RECORD *ExceptionRecord; - void* ExceptionAddress; - u32 NumberParameters; - u64* ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; - } EXCEPTION_RECORD; - -typedef EXCEPTION_RECORD *PEXCEPTION_RECORD; - -typedef struct _EXCEPTION_DEBUG_INFO { - EXCEPTION_RECORD ExceptionRecord; - u32 dwFirstChance; -} EXCEPTION_DEBUG_INFO, *LPEXCEPTION_DEBUG_INFO; - -typedef struct _CREATE_THREAD_DEBUG_INFO { - void* hThread; - void* lpThreadLocalBase; - LPTHREAD_START_ROUTINE lpStartAddress; -} CREATE_THREAD_DEBUG_INFO, *LPCREATE_THREAD_DEBUG_INFO; - -typedef struct _CREATE_PROCESS_DEBUG_INFO { - void* hFile; - void* hProcess; - void* hThread; - void* lpBaseOfImage; - u32 dwDebugInfoFileOffset; - u32 nDebugInfoSize; - void* lpThreadLocalBase; - LPTHREAD_START_ROUTINE lpStartAddress; - void* lpImageName; - u16 fUnicode; -} CREATE_PROCESS_DEBUG_INFO, *LPCREATE_PROCESS_DEBUG_INFO; - -typedef struct _EXIT_THREAD_DEBUG_INFO { - u32 dwExitCode; -} EXIT_THREAD_DEBUG_INFO, *LPEXIT_THREAD_DEBUG_INFO; - -typedef struct _EXIT_PROCESS_DEBUG_INFO { - u32 dwExitCode; -} EXIT_PROCESS_DEBUG_INFO, *LPEXIT_PROCESS_DEBUG_INFO; - -typedef struct _LOAD_DLL_DEBUG_INFO { - void* hFile; - void* lpBaseOfDll; - u32 dwDebugInfoFileOffset; - u32 nDebugInfoSize; - void* lpImageName; - u16 fUnicode; -} LOAD_DLL_DEBUG_INFO, *LPLOAD_DLL_DEBUG_INFO; - -typedef struct _UNLOAD_DLL_DEBUG_INFO { - void* lpBaseOfDll; -} UNLOAD_DLL_DEBUG_INFO, *LPUNLOAD_DLL_DEBUG_INFO; - -typedef struct _OUTPUT_DEBUG_STRING_INFO { - char* lpDebugStringData; - u16 fUnicode; - u16 nDebugStringLength; -} OUTPUT_DEBUG_STRING_INFO, *LPOUTPUT_DEBUG_STRING_INFO; - -typedef struct _RIP_INFO { - u32 dwError; - u32 dwType; -} RIP_INFO, *LPRIP_INFO; - -typedef struct _DEBUG_EVENT { - u32 dwDebugEventCode; - u32 dwProcessId; - u32 dwThreadId; - union { - EXCEPTION_DEBUG_INFO Exception; - CREATE_THREAD_DEBUG_INFO CreateThread; - CREATE_PROCESS_DEBUG_INFO CreateProcessInfo; - EXIT_THREAD_DEBUG_INFO ExitThread; - EXIT_PROCESS_DEBUG_INFO ExitProcess; - LOAD_DLL_DEBUG_INFO LoadDll; - UNLOAD_DLL_DEBUG_INFO UnloadDll; - OUTPUT_DEBUG_STRING_INFO DebugString; - RIP_INFO RipInfo; - } u; -} DEBUG_EVENT, *LPDEBUG_EVENT; - -extern i32 ContinueDebugEvent(u32 dwProcessId, u32 dwThreadId, u32 dwContinueStatus); - typedef PCONTEXT LPCONTEXT; -extern i32 GetThreadContext(void* hThread, LPCONTEXT lpContext); -extern i32 SetThreadContext(void* hThread, const CONTEXT* lpContext); - #define SORT_DEFAULT 0x0 // sorting default #define LANG_NEUTRAL 0x00 @@ -368,8 +80,6 @@ extern i32 SetThreadContext(void* hThread, const CONTEXT* lpContext); #define CSTR_EQUAL 2 // string 1 equal to string 2 #define CSTR_GREATER_THAN 3 // string 1 greater than string 2 -extern i32 CompareStringA(u32 Locale, u32 dwCmpFlags, const i8* lpString1, i32 cchCount1, const i8* lpString2, i32 cchCount2); - #define PAGE_NOACCESS 0x01 #define PAGE_READONLY 0x02 #define PAGE_READWRITE 0x04 @@ -427,14 +137,6 @@ extern i32 CompareStringA(u32 Locale, u32 dwCmpFlags, const i8* lpString1, i32 c #define MEM_EXTENDED_PARAMETER_EC_CODE 0x00000040 #define MEM_EXTENDED_PARAMETER_NUMA_NODE_MANDATORY MINLONG64 -extern void* VirtualAlloc(void* lpAddress, size_t dwSize, u32 flAllocationType, u32 flProtect); -extern i32 VirtualFree(void* lpAddress, size_t dwSize, u32 dwFreeType); - -extern void* OpenThread(u32 dwDesiredAccess, i32 bInheritHandle, u32 dwThreadId); -extern i32 CloseHandle(void* hObject); - -extern u32 GetLastError(void); - // ======================== // ====== !windows.h ====== // ======================== |
