From 37a1eb8f2321cb5469f1622e539171c03ee79e54 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Sep 2016 04:36:44 +0100 Subject: [PATCH 01/39] Initial commit. --- .gitignore | 1 + CAPE/CAPE.c | 55 ++++++------ CAPE/CAPE.h | 7 ++ CAPE/Debugger.c | 9 ++ CAPE/Debugger.h | 3 + CAPE/ScyllaHarness.cpp | 161 +++++++++++++++++++++++++++++++++++ cuckoomon.c | 6 +- cuckoomon.vcxproj | 7 +- hook_process.c | 112 ++++++++++++++++++++++-- hook_special.c | 12 ++- hook_thread.c | 23 +++++ loader/loader/Loader.c | 8 +- loader/loader/Loader.h | 2 + loader/loader/loader.vcxproj | 4 +- misc.c | 37 ++++++++ misc.h | 2 + ntapi.h | 9 +- unhook.c | 5 +- 18 files changed, 408 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index 4a48ed0..00415bc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ cuckoomon.opensdf cuckoomon.sdf cuckoomon.v11.suo cuckoomon.v12.suo +cuckoomon.VC.db bson/bson.sdf bson/bson.v11.suo bson/bson.v12.suo diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index abfa75b..025aa02 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -37,6 +37,7 @@ extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern void CapeOutputFile(LPCTSTR lpOutputFile); extern int ScyllaDumpCurrentProcess(DWORD NewOEP); extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); +extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); extern int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP); static HMODULE s_hInst = NULL; @@ -54,7 +55,7 @@ void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned in for (i=0; i SIZE_OF_LARGEST_IMAGE) { - DoOutputDebugString("MapFile: File too big"); + DoOutputDebugString(TEXT("MapFile: File too big")); return FALSE; } *FileSize = LargeFileSize.LowPart; - DoOutputDebugString("File size: 0x%x", *FileSize); + DoOutputDebugString(TEXT("File size: 0x%x"), *FileSize); *Buffer = malloc(*FileSize); if (SetFilePointer(hFile, 0, 0, FILE_BEGIN)) { - DoOutputErrorString("MapFile: Failed to set file pointer"); + DoOutputErrorString(TEXT("MapFile: Failed to set file pointer")); return FALSE; } if (*Buffer == NULL) { - DoOutputErrorString("MapFile: Memory allocation error in MapFile"); + DoOutputErrorString(TEXT("MapFile: Memory allocation error in MapFile")); return FALSE; } if (FALSE == ReadFile(hFile, (LPVOID)*Buffer, *FileSize, &dwBytesRead, NULL)) { - DoOutputErrorString("ReadFile error"); + DoOutputErrorString(TEXT("ReadFile error")); free(Buffer); return FALSE; } if (dwBytesRead > 0 && dwBytesRead < *FileSize) { - DoOutputErrorString("MapFile: Unexpected size read in."); + DoOutputErrorString(TEXT("MapFile: Unexpected size read in.")); free(Buffer); return FALSE; } else if (dwBytesRead == 0) { - DoOutputErrorString("MapFile: No data read from file"); + DoOutputErrorString(TEXT("MapFile: No data read from file")); free(Buffer); return FALSE; } @@ -183,7 +184,7 @@ char* GetHashFromHandle(HANDLE hFile) if (!MapFile(hFile, &Buffer, &FileSize)) { - DoOutputErrorString("MapFile error - check path!"); + DoOutputErrorString(TEXT("MapFile error - check path!")); return 0; } @@ -191,7 +192,7 @@ char* GetHashFromHandle(HANDLE hFile) if (OutputFilenameBuffer == NULL) { - DoOutputErrorString("Error allocating memory for hash string."); + DoOutputErrorString(TEXT("Error allocating memory for hash string.")); return 0; } @@ -494,7 +495,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (OutputFilename == NULL || FullPathName == NULL) { - DoOutputErrorString("DumpMemory: Error allocating memory for strings"); + DoOutputErrorString(TEXT("DumpMemory: Error allocating memory for strings")); return 0; } @@ -511,7 +512,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) { - DoOutputDebugString("Error, CAPE destination path too long."); + DoOutputDebugString(TEXT("Error, CAPE destination path too long.")); free(OutputFilename); free(FullPathName); return 0; } @@ -522,7 +523,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) { - DoOutputDebugString("Error creating output directory"); + DoOutputDebugString(TEXT("Error creating output directory")); free(OutputFilename); free(FullPathName); return 0; } @@ -533,24 +534,24 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) hOutputFile = CreateFile(FullPathName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); - DoOutputDebugString("CreateFile returned: 0x%x", hOutputFile); + DoOutputDebugString(TEXT("CreateFile returned: 0x%x"), hOutputFile); if (hOutputFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) { - DoOutputDebugString("CAPE output filename exists already: %s", FullPathName); + DoOutputDebugString(TEXT("CAPE output filename exists already: %s"), FullPathName); free(OutputFilename); free(FullPathName); return 0; } - DoOutputDebugString("Passed file_exists check"); + DoOutputDebugString(TEXT("Passed file_exists check")); if (hOutputFile == INVALID_HANDLE_VALUE) { - DoOutputErrorString("Could not create CAPE output file"); + DoOutputErrorString(TEXT("Could not create CAPE output file")); free(OutputFilename); free(FullPathName); return 0; } - DoOutputDebugString("Passed invalid_handle check"); + DoOutputDebugString(TEXT("Passed invalid_handle check")); dwBytesWritten = 0; @@ -558,12 +559,12 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (FALSE == WriteFile(hOutputFile, Buffer, Size, &dwBytesWritten, NULL)) { - DoOutputDebugString("WriteFile error on CAPE output file"); + DoOutputDebugString(TEXT("WriteFile error on CAPE output file")); free(OutputFilename); free(FullPathName); return 0; } - DoOutputDebugString("CAPE output filename: %s", FullPathName); + DoOutputDebugString(TEXT("CAPE output filename: %s"), FullPathName); CloseHandle(hOutputFile); @@ -592,6 +593,7 @@ int DumpCurrentProcessNewEP(DWORD NewEP) //************************************************************************************** { if (ScyllaDumpCurrentProcess(NewEP)) + { return 1; } @@ -617,7 +619,7 @@ int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase) { if (ScyllaDumpProcess(hProcess, ImageBase, 0)) { - return 1; + return 1; } return 0; @@ -638,12 +640,11 @@ int DumpPE(LPCVOID Buffer) void init_CAPE() { // Initialise CAPE global variables - // -#ifndef _WIN64 - // Start the debugger thread if required - //launch_debugger(); -#endif + RunPE_Handle = NULL; + RunPE_ImageBase = 0; + RunPE_EntryPoint = (DWORD_PTR)NULL; + RunPE_ProcessWriteDetected = FALSE; return; } \ No newline at end of file diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 50d378b..6bfce27 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -8,6 +8,13 @@ extern int DumpPE(LPCVOID Buffer); extern int ScyllaDumpPE(DWORD_PTR Buffer); unsigned int DumpSize; +HANDLE RunPE_Handle; +DWORD_PTR RunPE_ImageBase; + +DWORD_PTR RunPE_EntryPoint; +BOOL RunPE_ProcessWriteDetected; +BOOL RunPE_ImageDumped; + // // MessageId: STATUS_SUCCESS // diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 874fcd5..cc052c0 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -76,6 +76,7 @@ DWORD WINAPI PipeThread(LPVOID lpParam); DWORD RemoteFuncAddress; HANDLE hParentPipe; +extern BOOL StackWriteCallback(PBREAKPOINTINFO pBreakpointInfo, struct _EXCEPTION_POINTERS* ExceptionInfo); extern unsigned int address_is_in_stack(DWORD Address); extern BOOL WoW64fix(void); extern BOOL WoW64PatchBreakpoint(unsigned int Register); @@ -1198,6 +1199,14 @@ __declspec (naked dllexport) void DebuggerInit(void) // Target specific code +// StackWriteCallback implemented in CAPE_UPX.c + if (SetHardwareBreakpoint(MainThreadId, 3, 1, (BYTE*)StackPointer, BP_WRITE, StackWriteCallback)) + { + DoOutputDebugString("SetHardwareBreakpoint (3) returned successfully!\n"); + } + else + DoOutputDebugString("SetHardwareBreakpoint (3) failed\n"); + // End of target specific code DoOutputDebugString("Debugger initialised, about to execute OEP.\n"); diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index d089e41..1ca1fca 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -5,6 +5,8 @@ #define BP_RESERVED 0x02 #define BP_READWRITE 0x03 +DWORD Injection_ProcessId; + typedef struct BreakpointInfo { HANDLE ThreadHandle; @@ -31,6 +33,7 @@ typedef BOOL (cdecl *SINGLE_STEP_HANDLER)(struct _EXCEPTION_POINTERS*); extern "C" { #endif + BOOL SetHardwareBreakpoint ( DWORD ThreadId, diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 25da76a..de54560 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -387,3 +387,164 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) return 1; } + +extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) +{ + BOOL isAfter; + DWORD sizeIAT; + DWORD_PTR addressIAT; + BOOL IAT_Found, AdvancedIATSearch = FALSE; + + IATSearch iatSearch; + ApiReader apiReader; + IATReferenceScan iatReferenceScan; + ImportsHandling importsHandling; + + DWORD_PTR entrypointRVA = 0; + PeParser * peFile = 0; + + //Clear stuff first + apiReader.clearAll(); + importsHandling.clearAllImports(); + + NativeWinApi::initialize(); + + ProcessAccessHelp::ownModuleList.clear(); + ProcessAccessHelp::hProcess = hProcess; + ProcessAccessHelp::getProcessModules(ProcessAccessHelp::hProcess, ProcessAccessHelp::moduleList); + ProcessAccessHelp::targetImageBase = (DWORD_PTR)modBase; + + //ProcessAccessHelp::moduleList = ProcessAccessHelp::ownModuleList; + //ProcessAccessHelp::getSizeOfImageCurrentProcess(); + + apiReader.readApisFromModuleList(); + + DoOutputDebugString(TEXT("Instantiating PeParser with address: 0x%x"), modBase); + + peFile = new PeParser((DWORD_PTR)modBase, true); + + if (peFile->isValidPeFile()) + { + if (NewOEP) + entrypointRVA = NewOEP - (DWORD)modBase; + else + entrypointRVA = peFile->getEntryPoint(); + + DoOutputDebugString(TEXT("Module entry point VA is 0x%x"), (DWORD)modBase + entrypointRVA); + + // Let's try dumping then fixing the dump + // We can maybe then try doing it all in memory if this works + if (peFile->dumpProcess((DWORD_PTR)modBase, (DWORD)modBase + entrypointRVA, SCYLLA_OUTPUT_FILE)) + { + DoOutputDebugString("Module image dump success %s", ScyllaOutputPath); + } + + // We'll try the simple search first + IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, &addressIAT, &sizeIAT, FALSE); + + // Let's try the advanced search now + if (IAT_Found == FALSE) + IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, &addressIAT, &sizeIAT, TRUE); + + if (addressIAT && sizeIAT) + { + DoOutputDebugString(TEXT("Found IAT: 0x%x, size: 0x%x"), addressIAT, sizeIAT); + + apiReader.readAndParseIAT(addressIAT, sizeIAT, importsHandling.moduleList); + importsHandling.scanAndFixModuleList(); + + if (SCAN_DIRECT_IMPORTS) + { + iatReferenceScan.ScanForDirectImports = true; + iatReferenceScan.ScanForNormalImports = false; + + iatReferenceScan.apiReader = &apiReader; + iatReferenceScan.startScan(ProcessAccessHelp::targetImageBase, (DWORD)ProcessAccessHelp::targetSizeOfImage, addressIAT, sizeIAT); + + DoOutputDebugString("Direct imports - Found %d possible direct imports with %d unique APIs", iatReferenceScan.numberOfFoundDirectImports(), iatReferenceScan.numberOfFoundUniqueDirectImports()); + + if (iatReferenceScan.numberOfFoundDirectImports() > 0) + { + if (iatReferenceScan.numberOfDirectImportApisNotInIat() > 0) + { + DoOutputDebugString("Direct imports - Found %d additional api addresses", iatReferenceScan.numberOfDirectImportApisNotInIat()); + DWORD sizeIatNew = iatReferenceScan.addAdditionalApisToList(); + DoOutputDebugString("Direct imports - Old IAT size 0x%08x new IAT size 0x%08x", sizeIAT, sizeIatNew); + importsHandling.scanAndFixModuleList(); + } + + iatReferenceScan.printDirectImportLog(); + + if (FIX_DIRECT_IMPORTS_NORMAL && FIX_DIRECT_IMPORTS_UNIVERSAL) + { + //"Direct Imports found. I can patch only direct imports by JMP/CALL (use universal method if you don't like this) but where is the junk byte?\r\n\r\nYES = After Instruction\r\nNO = Before the Instruction\r\nCancel = Do nothing", L"Information", MB_YESNOCANCEL|MB_ICONINFORMATION); + + isAfter = false; + isAfter = true; + + iatReferenceScan.patchDirectImportsMemory(isAfter); + DoOutputDebugString("DIRECT IMPORTS - Patched! Please dump target."); + } + } + } + + if (isIATOutsidePeImage(addressIAT)) + { + DoOutputDebugString("WARNING! IAT is not inside the PE image, requires rebasing!"); + } + + ImportRebuilder importRebuild(SCYLLA_OUTPUT_FILE); + + if (OFT_SUPPORT) + { + importRebuild.enableOFTSupport(); + DoOutputDebugString("importRebuild: OFT support enabled.\n"); + } + + if (SCAN_DIRECT_IMPORTS && FIX_DIRECT_IMPORTS_UNIVERSAL) + { + if (iatReferenceScan.numberOfFoundDirectImports() > 0) + { + importRebuild.iatReferenceScan = &iatReferenceScan; + importRebuild.BuildDirectImportsJumpTable = true; + DoOutputDebugString("importRebuild: iatReferenceScan: 0x%x, BuildDirectImportsJumpTable true.\n", importRebuild.iatReferenceScan); + } + } + + if (CREATE_NEW_IAT_IN_SECTION) + { + importRebuild.iatReferenceScan = &iatReferenceScan; + importRebuild.enableNewIatInSection(addressIAT, sizeIAT); + DoOutputDebugString("importRebuild: new IAT to be created.\n"); + } + + DoOutputDebugString("About to rebuild import table.\n"); + + if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList)) + { + DoOutputDebugString("Import Rebuild success.\n"); + delete peFile; + return 1; + } + else + { + DoOutputDebugString("Import Rebuild failed.\n"); + } + } + else + { + DoOutputDebugString("Warning: Unable to find IAT in scan.\n"); + } + + } + else + { + DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + delete peFile; + return 0; + } + + delete peFile; + + return 1; +} diff --git a/cuckoomon.c b/cuckoomon.c index ad21d4c..f69c6e5 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -348,9 +348,8 @@ static hook_t g_hooks[] = { // Misc Hooks // - //HOOK(ntdll, memcpy), - HOOK(msvcrt, memcpy), - HOOK(msvcrt, srand), + //HOOK(msvcrt, memcpy), + //HOOK(ntdll, memcpy), // for debugging only //HOOK(kernel32, GetLastError), @@ -923,7 +922,6 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) #ifdef STANDALONE // initialise CAPE - resolve_runtime_apis(); init_CAPE(); return TRUE; #endif diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index 6f3dc2f..f38cc72 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -47,7 +47,7 @@ DynamicLibrary false v140_xp - NotSet + MultiByte true @@ -78,15 +78,14 @@ true AllRules.ruleset false - CAPE + CAPE_Injection $(VC_IncludePath);$(WindowsSdk_71A_IncludePath);C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\WTL91\Include; true AllRules.ruleset false - CAPE_x64 - .dll + CAPE_Injection_x64 $(VC_IncludePath);$(WindowsSdk_71A_IncludePath);C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\WTL91\Include; diff --git a/hook_process.c b/hook_process.c index c75edb2..d57632e 100644 --- a/hook_process.c +++ b/hook_process.c @@ -27,8 +27,10 @@ along with this program. If not, see . #include "hook_sleep.h" #include "unhook.h" #include "config.h" +#include "CAPE\CAPE.h" -extern int DumpCurrentProcessFixImports(DWORD NewEP); +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern int DumpMemory(LPCVOID Buffer, unsigned int Size); HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -296,6 +298,15 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); + + if (NT_SUCCESS(ret) && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ + RunPE_Handle = ProcessHandle; + RunPE_ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + RunPE_EntryPoint = (DWORD)NULL; + RunPE_ImageDumped = FALSE; + DoOutputDebugString("NtOpenProcess: Open process handle set: 0x%x, ImageBase: 0x%x, DesiredAccess: 0x%x", RunPE_Handle, RunPE_ImageBase, DesiredAccess); + } + LOQ_ntstatus("process", "Phi", "ProcessHandle", ProcessHandle, "DesiredAccess", DesiredAccess, "ProcessIdentifier", pid); @@ -310,6 +321,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); + if (RunPE_Handle && RunPE_ImageBase && RunPE_ProcessWriteDetected) + { + if (RunPE_ImageDumped == FALSE) + { + DoOutputDebugString("Dumping RunPE process image, handle 0x%x, image base 0x%x.", RunPE_Handle, RunPE_ImageBase); + DumpProcess(RunPE_Handle, RunPE_ImageBase); + RunPE_ImageDumped = TRUE; + } + } + ret = Old_NtResumeProcess(ProcessHandle); LOQ_ntstatus("process", "p", "ProcessHandle", ProcessHandle); return ret; @@ -331,12 +352,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, // we mark this here as this termination type will kill all threads but ours, including // the logging thread. By setting this, we'll switch into a direct logging mode // for the subsequent call to NtTerminateProcess against our own process handle - DumpCurrentProcessFixImports(0); process_shutting_down = 1; LOQ_ntstatus("process", "ph", "ProcessHandle", ProcessHandle, "ExitCode", ExitStatus); } else if (GetCurrentProcessId() == our_getprocessid(ProcessHandle)) { - DumpCurrentProcessFixImports(0); process_shutting_down = 1; LOQ_ntstatus("process", "ph", "ProcessHandle", ProcessHandle, "ExitCode", ExitStatus); pipe("KILL:%d", GetCurrentProcessId()); @@ -453,6 +472,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); + + if (RunPE_Handle && (ProcessHandle == RunPE_Handle)) + { + RunPE_ProcessWriteDetected = TRUE; + } if ((pid != GetCurrentProcessId()) || Win32Protect != PAGE_READWRITE) LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, @@ -516,7 +540,8 @@ HOOKDEF(BOOL, WINAPI, ReadProcessMemory, _In_ SIZE_T nSize, _Out_ PSIZE_T lpNumberOfBytesRead ) { - BOOL ret; + //long e_lfanew; + BOOL ret; ENSURE_SIZET(lpNumberOfBytesRead); ret = Old_ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, @@ -539,11 +564,44 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, ) { NTSTATUS ret; DWORD pid; + long e_lfanew; ENSURE_SIZET(NumberOfBytesWritten); ret = Old_NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten); + if (NT_SUCCESS(ret) && *NumberOfBytesWritten > 0) + { + // Check if we have a valid DOS and PE header at the beginning of Buffer + if (*(WORD*)Buffer == IMAGE_DOS_SIGNATURE) + { + DoOutputDebugString("Executable binary detected in NtWriteVirtualMemory buffer."); + + e_lfanew = *(long*)((unsigned char*)Buffer+0x3c); + + if ((unsigned int)e_lfanew>PE_HEADER_LIMIT) + { + // This check is possibly not appropriate here + // As long as we've got what's been compressed + } + + if (*(DWORD*)((unsigned char*)Buffer+e_lfanew) == IMAGE_NT_SIGNATURE) + { + RunPE_ImageBase = (DWORD_PTR)BaseAddress; + DoOutputDebugString("RunPE ImageBase reset to: 0x%x (process handle: 0x%x)", RunPE_ImageBase, RunPE_Handle); + + DoOutputDebugString("About to attempt to dump PE from memory."); + if (DumpPE(Buffer)) + RunPE_ImageDumped = TRUE; + } + } + } + + if (RunPE_Handle && (ProcessHandle == RunPE_Handle)) + { + RunPE_ProcessWriteDetected = TRUE; + } + pid = pid_from_process_handle(ProcessHandle); if (pid != GetCurrentProcessId()) { @@ -556,7 +614,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, } } - return ret; } @@ -569,12 +626,55 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, ) { BOOL ret; DWORD pid; + long e_lfanew; ENSURE_SIZET(lpNumberOfBytesWritten); ret = Old_WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); - pid = pid_from_process_handle(hProcess); + if (hProcess == RunPE_Handle && ret != 0 && *lpNumberOfBytesWritten > 0) + { + // Check if we have a valid DOS and PE header at the beginning of lpBuffer + if (*(WORD*)lpBuffer == IMAGE_DOS_SIGNATURE) + { + DoOutputDebugString("Executable binary detected in WriteProcessMemory buffer."); + + e_lfanew = *(long*)((unsigned char*)lpBuffer+0x3c); + + if ((unsigned int)e_lfanew>PE_HEADER_LIMIT) + { + // This check is possibly not appropriate here + // As long as we've got what's been compressed + } + + if (*(DWORD*)((unsigned char*)lpBuffer+e_lfanew) == IMAGE_NT_SIGNATURE) + { + RunPE_ImageBase = (DWORD_PTR)lpBaseAddress; + DoOutputDebugString("RunPE ImageBase reset to: 0x%x (process handle: 0x%x)", RunPE_ImageBase, RunPE_Handle); + + DoOutputDebugString("About to attempt to dump PE from memory."); + if (DumpPE(lpBuffer)) + RunPE_ImageDumped = TRUE; + } + } + else + { + if (RunPE_Handle && (hProcess == RunPE_Handle)) + { + RunPE_ProcessWriteDetected = TRUE; + } + //else if (*lpNumberOfBytesWritten > 0x10) + //{ + // // dump injected code to .bin file + // if (DumpMemory(lpBuffer, nSize)) + // DoOutputDebugString("Dumped remotely injected code from memory."); + // else + // DoOutputDebugString("Failed to dump remotely injected code from memory."); + //} + } + } + + pid = pid_from_process_handle(hProcess); if (pid != GetCurrentProcessId()) { LOQ_bool("process", "ppBhs", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, diff --git a/hook_special.c b/hook_special.c index 39bd639..24b51a8 100644 --- a/hook_special.c +++ b/hook_special.c @@ -24,6 +24,9 @@ along with this program. If not, see . #include "hook_sleep.h" #include "misc.h" #include "config.h" +#include "CAPE\CAPE.h" + +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, __in_opt PWCHAR PathToFile, @@ -153,7 +156,14 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, if((dwCreationFlags & CREATE_SUSPENDED) == 0) { ResumeThread(lpProcessInformation->hThread); } - + else if (!called_by_hook()){ + RunPE_Handle = lpProcessInformation->hProcess; + RunPE_ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); + RunPE_EntryPoint = (DWORD)NULL; + RunPE_ImageDumped = FALSE; + DoOutputDebugString("RunPE process handle set: 0x%x, ImageBase: 0x%x", RunPE_Handle, RunPE_ImageBase); + } + disable_sleep_skip(); } diff --git a/hook_thread.c b/hook_thread.c index 1c00795..1979b56 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -25,6 +25,9 @@ along with this program. If not, see . #include "hook_sleep.h" #include "unhook.h" #include "lookup.h" +#include "CAPE\CAPE.h" + +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); static lookup_t g_ignored_threads; @@ -246,6 +249,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); ret = Old_NtSetContextThread(ThreadHandle, Context); + + if (RunPE_Handle && RunPE_ImageBase) + { +#ifdef _WIN64 + RunPE_EntryPoint = Context->Rax - RunPE_ImageBase; +#else + RunPE_EntryPoint = Context->Eax - RunPE_ImageBase; +#endif + DoOutputDebugString("Set RunPE entry point via NtSetContextThread: 0x%x", RunPE_EntryPoint); + } if (Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); @@ -295,6 +308,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, ENSURE_ULONG(SuspendCount); pipe("RESUME:%d,%d", pid, tid); + if (RunPE_Handle && RunPE_ImageBase && RunPE_ProcessWriteDetected) + { + if (RunPE_ImageDumped == FALSE) + { + DoOutputDebugString("Dumping RunPE process image, handle 0x%x, image base 0x%x.", RunPE_Handle, RunPE_ImageBase); + DumpProcess(RunPE_Handle, RunPE_ImageBase); + RunPE_ImageDumped = TRUE; + } + } + ret = Old_NtResumeThread(ThreadHandle, SuspendCount); LOQ_ntstatus("threading", "pI", "ThreadHandle", ThreadHandle, "SuspendCount", SuspendCount); return ret; diff --git a/loader/loader/Loader.c b/loader/loader/Loader.c index 8cefa0b..a4012cf 100644 --- a/loader/loader/Loader.c +++ b/loader/loader/Loader.c @@ -693,6 +693,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine _stprintf_s(DebugOutput, MAX_PATH, TEXT("Successfully received debugger init address: 0x%x.\n"), RemoteFuncAddress); OutputDebugString(DebugOutput); + //ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_DEBUG_REGISTERS; ctx.ContextFlags = CONTEXT_ALL; if (!GetThreadContext(hThread, &ctx)) { @@ -746,7 +747,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine _stprintf_s(DebugOutput, MAX_PATH, TEXT("Loader: Child process created, suspended, DLL successfully injected\n")); OutputDebugString(DebugOutput); - ctx.ContextFlags = CONTEXT_ALL; + ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS; #ifndef _WIN64 ctx.Eax = RemoteFuncAddress; // eax holds new entry point #else @@ -773,8 +774,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine CloseHandle(hProcess); CloseHandle(hThread); - return 1; - } else if (!strcmp(__argv[1], "test")) { // usage: loader.exe test @@ -908,6 +907,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine _stprintf_s(DebugOutput, MAX_PATH, TEXT("Successfully received debugger init address: 0x%x.\n"), RemoteFuncAddress); OutputDebugString(DebugOutput); + //ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_DEBUG_REGISTERS; ctx.ContextFlags = CONTEXT_ALL; if (!GetThreadContext(pi.hThread, &ctx)) { @@ -962,6 +962,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine _stprintf_s(DebugOutput, MAX_PATH, TEXT("Loader: Child process created, suspended, DLL successfully injected\n")); OutputDebugString(DebugOutput); + //ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_DEBUG_REGISTERS; ctx.ContextFlags = CONTEXT_ALL; #ifndef _WIN64 ctx.Eax = RemoteFuncAddress; // eax holds new entry point @@ -1001,7 +1002,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine OutputDebugString(DebugOutput); } - return 1; } else if (!strcmp(__argv[1], "dump")) { diff --git a/loader/loader/Loader.h b/loader/loader/Loader.h index 750e0d9..aae9420 100644 --- a/loader/loader/Loader.h +++ b/loader/loader/Loader.h @@ -9,6 +9,8 @@ enum { INJECT_CREATEREMOTETHREAD, INJECT_QUEUEUSERAPC + //INJECT_NTCREATETHREADEX, + //INJECT_RTLCREATEUSERTHREAD }; #define SystemProcessInformation 5 diff --git a/loader/loader/loader.vcxproj b/loader/loader/loader.vcxproj index 34ca643..95dc696 100644 --- a/loader/loader/loader.vcxproj +++ b/loader/loader/loader.vcxproj @@ -29,7 +29,7 @@ Application true v140_xp - Unicode + NotSet Application @@ -49,7 +49,7 @@ false v140_xp true - Unicode + NotSet diff --git a/misc.c b/misc.c index 01367f6..f352387 100644 --- a/misc.c +++ b/misc.c @@ -1794,3 +1794,40 @@ unsigned int address_is_in_stack(DWORD Address) } #endif } + +PVOID get_process_image_base(HANDLE process_handle) +{ + PROCESS_BASIC_INFORMATION pbi; + ULONG ulSize; + HANDLE dup_handle = process_handle; + PVOID pPEB = 0, ImageBase = 0; + PEB Peb; + SIZE_T dwBytesRead; + lasterror_t lasterror; + + get_lasterrors(&lasterror); + + if (process_handle == GetCurrentProcess()) + { + ImageBase = GetModuleHandle(NULL); + goto out; + } + + memset(&pbi, 0, sizeof(pbi)); + + if(pNtQueryInformationProcess(process_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) + { + pPEB = pbi.PebBaseAddress; + + if (ReadProcessMemory(process_handle, pPEB, &Peb, sizeof(Peb), &dwBytesRead)) + { + ImageBase = Peb.ImageBaseAddress; + } + else return NULL; + } + +out: + set_lasterrors(&lasterror); + + return ImageBase; +} diff --git a/misc.h b/misc.h index 2f57996..5d78999 100644 --- a/misc.h +++ b/misc.h @@ -198,3 +198,5 @@ wchar_t *ascii_to_unicode_dup(char *str); int is_stack_pivoted(void); LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); + +PVOID get_process_image_base(HANDLE process_handle); \ No newline at end of file diff --git a/ntapi.h b/ntapi.h index 9d62ab3..0dc34ca 100644 --- a/ntapi.h +++ b/ntapi.h @@ -476,9 +476,12 @@ typedef struct _LDR_MODULE { #ifdef _WIN64 typedef struct _PEB { - BYTE Reserved1[2]; - BYTE BeingDebugged; - BYTE Reserved2[21]; + BOOLEAN InheritedAddressSpace; + BOOLEAN ReadImageFileExecOptions; + BOOLEAN BeingDebugged; + BOOLEAN Spare; + HANDLE Mutant; + PVOID ImageBaseAddress; PPEB_LDR_DATA LoaderData; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; BYTE Reserved3[520]; diff --git a/unhook.c b/unhook.c index 8bc443f..91597bb 100644 --- a/unhook.c +++ b/unhook.c @@ -28,8 +28,6 @@ along with this program. If not, see . #define UNHOOK_MAXCOUNT 2048 #define UNHOOK_BUFSIZE 32 -extern int DumpCurrentProcessFixImports(DWORD NewEP); - static HANDLE g_unhook_thread_handle, g_watcher_thread_handle; // Index for adding new hooks and iterating all existing hooks. @@ -249,11 +247,10 @@ static HANDLE g_terminate_event_handle; static DWORD WINAPI _terminate_event_thread(LPVOID param) { - hook_disable(); + hook_disable(); while (1) { WaitForSingleObject(g_terminate_event_handle, INFINITE); - DumpCurrentProcessFixImports(0); log_flush(); } From 88d1baa3044a9b3ff3959e97dcd70a402400d535 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Nov 2016 11:32:17 +0000 Subject: [PATCH 02/39] Upgraded with metadata mechanism and package improvements. --- CAPE/CAPE.c | 499 ++++++++++++++++++++++++++---- CAPE/CAPE.h | 59 +++- CAPE/Debugger.c | 456 +++++++++++++++++++++------ CAPE/Debugger.h | 13 +- CAPE/GetThreadId.c | 2 +- CAPE/Output.c | 139 ++++++++- CAPE/Scylla/ImportRebuilder.cpp | 11 +- CAPE/Scylla/ImportRebuilder.h | 1 + CAPE/Scylla/PeParser.cpp | 78 +++-- CAPE/Scylla/PeParser.h | 6 +- CAPE/Scylla/ProcessAccessHelp.cpp | 2 +- CAPE/ScyllaHarness.cpp | 111 +++---- config.c | 23 ++ config.h | 6 + hook_process.c | 276 +++++++++++------ hook_special.c | 46 ++- hook_thread.c | 37 ++- misc.c | 2 +- 18 files changed, 1419 insertions(+), 348 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 025aa02..af189af 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -21,6 +21,8 @@ along with this program.If not, see . #include #include #include +#include +#include #include "CAPE.h" #include "Debugger.h" @@ -31,19 +33,32 @@ along with this program.If not, see . #define BUFSIZE 1024 // For hashing #define MD5LEN 16 +#define DUMP_MAX 100 +#define CAPE_OUTPUT_FILE "CapeOutput.bin" + +static unsigned int DumpCount; + +extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buffer_len); + +#define CAPE_OUTPUT_FILE "CapeOutput.bin" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern void CapeOutputFile(LPCTSTR lpOutputFile); extern int ScyllaDumpCurrentProcess(DWORD NewOEP); extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); -extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); extern int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP); +extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); + +extern wchar_t *our_process_path; +extern ULONG_PTR base_of_dll_of_interest; static HMODULE s_hInst = NULL; static WCHAR s_wzDllPath[MAX_PATH]; CHAR s_szDllPath[MAX_PATH]; +BOOL ProcessDumped; + //************************************************************************************** void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned int Count) //************************************************************************************** @@ -55,12 +70,67 @@ void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned in for (i=0; iDumpType = DumpType; + + if (DumpType == INJECTION_PE || DumpType == INJECTION_SHELLCODE) + { + if (!TargetPid) + { + DoOutputDebugString("SetCapeMetaData: Injection type with no PID - error.\n"); + return FALSE; + } + + if (!hTargetProcess) + { + DoOutputDebugString("SetCapeMetaData: Injection type with no process handle - error.\n"); + return FALSE; + } + + CapeMetaData->TargetPid = TargetPid; + + if (CapeMetaData->TargetProcess == NULL) + { + DoOutputDebugString("SetCapeMetaData: failed to allocate memory for target process string.\n"); + return FALSE; + } + + if (CapeMetaData->TargetProcess == NULL && !GetModuleFileNameEx(hTargetProcess, NULL, CapeMetaData->TargetProcess, MAX_PATH)) + { + CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); + DoOutputErrorString("SetCapeMetaData: GetModuleFileNameEx failed on target process, handle 0x%x", hTargetProcess); + return FALSE; + } + } + else if (DumpType == EXTRACTION_PE || DumpType == EXTRACTION_SHELLCODE) + { + if (!Address) + { + DoOutputDebugString("SetCapeMetaData: Extraction type with no PID - error.\n"); + return FALSE; + } + + CapeMetaData->Address = Address; + } + + return TRUE; +} + //************************************************************************************** BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) //************************************************************************************** @@ -70,51 +140,57 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) if (!GetFileSizeEx(hFile, &LargeFileSize)) { - DoOutputErrorString(TEXT("Cannot get file size")); + DoOutputErrorString("MapFile: Cannot get file size"); return FALSE; } if (LargeFileSize.HighPart || LargeFileSize.LowPart > SIZE_OF_LARGEST_IMAGE) { - DoOutputDebugString(TEXT("MapFile: File too big")); + DoOutputDebugString("MapFile: File too big"); + return FALSE; + } + + if (LargeFileSize.LowPart == 0) + { + DoOutputDebugString("MapFile: File is zero in size."); return FALSE; } *FileSize = LargeFileSize.LowPart; - DoOutputDebugString(TEXT("File size: 0x%x"), *FileSize); + DoOutputDebugString("File size: 0x%x", *FileSize); *Buffer = malloc(*FileSize); if (SetFilePointer(hFile, 0, 0, FILE_BEGIN)) { - DoOutputErrorString(TEXT("MapFile: Failed to set file pointer")); + DoOutputErrorString("MapFile: Failed to set file pointer"); return FALSE; } if (*Buffer == NULL) { - DoOutputErrorString(TEXT("MapFile: Memory allocation error in MapFile")); + DoOutputErrorString("MapFile: Memory allocation error in MapFile"); return FALSE; } if (FALSE == ReadFile(hFile, (LPVOID)*Buffer, *FileSize, &dwBytesRead, NULL)) { - DoOutputErrorString(TEXT("ReadFile error")); + DoOutputErrorString("ReadFile error"); free(Buffer); return FALSE; } if (dwBytesRead > 0 && dwBytesRead < *FileSize) { - DoOutputErrorString(TEXT("MapFile: Unexpected size read in.")); + DoOutputErrorString("MapFile: Unexpected size read in"); free(Buffer); return FALSE; } else if (dwBytesRead == 0) { - DoOutputErrorString(TEXT("MapFile: No data read from file")); + DoOutputErrorString("MapFile: No data read from file"); free(Buffer); return FALSE; } @@ -122,6 +198,113 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) return TRUE; } +//************************************************************************************** +PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) +//************************************************************************************** +{ + DWORD CurrentProcessId; + + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; + + while (CurrentInjectionInfo) + { + CurrentProcessId = CurrentInjectionInfo->ProcessId; + + if (CurrentProcessId == ProcessId) + return CurrentInjectionInfo; + else + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return NULL; +} + +//************************************************************************************** +PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) +//************************************************************************************** +{ + PINJECTIONINFO CurrentInjectionInfo, PreviousInjectionInfo; + + PreviousInjectionInfo = NULL; + + if (InjectionInfoList == NULL) + { + InjectionInfoList = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); + + if (InjectionInfoList == NULL) + { + DoOutputDebugString("CreateInjectionInfo: failed to allocate memory for initial injection info list.\n"); + return NULL; + } + + memset(InjectionInfoList, 0, sizeof(struct InjectionInfo)); + + InjectionInfoList->ProcessId = ProcessId; + } + + CurrentInjectionInfo = InjectionInfoList; + + while (CurrentInjectionInfo) + { + //if (CurrentInjectionInfo->ProcessId && CurrentInjectionInfo->ProcessId == ProcessId) + //{ + // //It already exists - shouldn't happen + // DoOutputDebugString("CreateInjectionInfo error: found an existing injection info struct for ProcessId 0x%x\n", ProcessId); + // return NULL; + //} + + if ((CurrentInjectionInfo->ProcessId) == ProcessId) + { + // We have our injection info struct + break; + } + + PreviousInjectionInfo = CurrentInjectionInfo; + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + if (!CurrentInjectionInfo) + { + // We haven't found it in the linked list, so create a new one + CurrentInjectionInfo = PreviousInjectionInfo; + + CurrentInjectionInfo->NextInjectionInfo = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); + + if (CurrentInjectionInfo->NextInjectionInfo == NULL) + { + DoOutputDebugString("CreateInjectionInfo: Failed to allocate new thread breakpoints.\n"); + return NULL; + } + + memset(CurrentInjectionInfo->NextInjectionInfo, 0, sizeof(struct InjectionInfo)); + + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return CurrentInjectionInfo; +} + +//************************************************************************************** +char* GetName() +//************************************************************************************** +{ + char *OutputFilename; + SYSTEMTIME Time; + + OutputFilename = (char*)malloc(MAX_PATH); + + if (OutputFilename == NULL) + { + DoOutputErrorString("GetName: failed to allocate memory"); + return 0; + } + + GetSystemTime(&Time); + sprintf_s(OutputFilename, MAX_PATH*sizeof(char), "%d_%d%d%d%d%d%d%d%d", GetCurrentProcessId(), Time.wMilliseconds, Time.wSecond, Time.wMinute, Time.wHour, Time.wDay, Time.wDayOfWeek, Time.wMonth, Time.wYear); + + return OutputFilename; +} + //************************************************************************************** BOOL GetHash(unsigned char* Buffer, unsigned int Size, char* OutputFilenameBuffer) //************************************************************************************** @@ -184,7 +367,7 @@ char* GetHashFromHandle(HANDLE hFile) if (!MapFile(hFile, &Buffer, &FileSize)) { - DoOutputErrorString(TEXT("MapFile error - check path!")); + DoOutputErrorString("MapFile error - check the path is valid and the file has size."); return 0; } @@ -192,11 +375,15 @@ char* GetHashFromHandle(HANDLE hFile) if (OutputFilenameBuffer == NULL) { - DoOutputErrorString(TEXT("Error allocating memory for hash string.")); + DoOutputErrorString("Error allocating memory for hash string"); return 0; } - GetHash(Buffer, FileSize, (char*)OutputFilenameBuffer); + if (!GetHash(Buffer, FileSize, (char*)OutputFilenameBuffer)) + { + DoOutputErrorString("GetHashFromHandle: GetHash function failed"); + return 0; + } DoOutputDebugString("GetHash returned: %s", OutputFilenameBuffer); @@ -287,7 +474,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) if (DecryptedBuffer == NULL) { - DoOutputErrorString(TEXT("Error allocating memory for decrypted PE binary.")); + DoOutputErrorString("Error allocating memory for decrypted PE binary"); return FALSE; } @@ -308,6 +495,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) } } } + #ifndef _WIN64 for (i=0; i<=0xffff; i++) { @@ -358,7 +546,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) if (DecryptedBuffer == NULL) { - DoOutputErrorString(TEXT("Error allocating memory for decrypted PE binary.")); + DoOutputErrorString("Error allocating memory for decrypted PE binary"); return FALSE; } @@ -402,7 +590,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) if (DecryptedBuffer == NULL) { - DoOutputErrorString(TEXT("Error allocating memory for decrypted PE binary.")); + DoOutputErrorString("Error allocating memory for decrypted PE binary"); return FALSE; } @@ -458,7 +646,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) if (DecryptedBuffer == NULL) { - DoOutputErrorString(TEXT("Error allocating memory for decrypted PE binary.")); + DoOutputErrorString("Error allocating memory for decrypted PE binary"); return FALSE; } @@ -475,6 +663,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) } } } + #endif // We free can free DecryptedBuffer as it's no longer needed free(DecryptedBuffer); @@ -482,6 +671,80 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) return FALSE; } +//************************************************************************************** +int ScanForNonZero(LPCVOID Buffer, unsigned int Size) +//************************************************************************************** +{ + unsigned int p; + + for (p=0; pe_lfanew == 0) + { + // e_lfanew is zero + continue; + } + + if ((ULONG)pDosHeader->e_lfanew > Size-p) + { + // e_lfanew points beyond end of region + continue; + } + + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) + { + // No 'PE' header + continue; + } + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0)) + { + // Basic requirements + DoOutputDebugString("ScanForPE: Basic requirements failure.\n"); + continue; + } + + if (Offset) + { + *Offset = (LPCVOID)((char*)Buffer+p); + } + + DoOutputDebugString("ScanForPE: success!\n"); + + return 1; + } + } + + return 0; +} + //************************************************************************************** int DumpMemory(LPCVOID Buffer, unsigned int Size) //************************************************************************************** @@ -489,22 +752,18 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) char *OutputFilename, *FullPathName; DWORD RetVal, dwBytesWritten; HANDLE hOutputFile; + LPVOID BufferCopy; - OutputFilename = (char*) malloc(MAX_PATH); FullPathName = (char*) malloc(MAX_PATH); - if (OutputFilename == NULL || FullPathName == NULL) + if (FullPathName == NULL) { - DoOutputErrorString(TEXT("DumpMemory: Error allocating memory for strings")); + DoOutputErrorString("DumpMemory: Error allocating memory for strings"); return 0; } - GetHash((LPVOID)Buffer, Size, (char*)OutputFilename); + OutputFilename = GetName(); - DoOutputDebugString("GetHash returned: %s", OutputFilename); - - sprintf_s((OutputFilename+2*MD5LEN), MAX_PATH*sizeof(char)-2*MD5LEN, ".bin"); - // We want to dump CAPE output to the 'analyzer' directory memset(FullPathName, 0, MAX_PATH); @@ -512,7 +771,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) { - DoOutputDebugString(TEXT("Error, CAPE destination path too long.")); + DoOutputDebugString("DumpMemory: Error, CAPE destination path too long."); free(OutputFilename); free(FullPathName); return 0; } @@ -523,55 +782,58 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) { - DoOutputDebugString(TEXT("Error creating output directory")); + DoOutputDebugString("DumpMemory: Error creating output directory"); free(OutputFilename); free(FullPathName); return 0; } PathAppend(FullPathName, OutputFilename); - DoOutputDebugString("DEBUG: FullPathName = %s", FullPathName); + DoOutputDebugString("DumpMemory: FullPathName = %s", FullPathName); hOutputFile = CreateFile(FullPathName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); - DoOutputDebugString(TEXT("CreateFile returned: 0x%x"), hOutputFile); - if (hOutputFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) { - DoOutputDebugString(TEXT("CAPE output filename exists already: %s"), FullPathName); + DoOutputDebugString("DumpMemory: CAPE output filename exists already: %s", FullPathName); free(OutputFilename); free(FullPathName); return 0; } - DoOutputDebugString(TEXT("Passed file_exists check")); - if (hOutputFile == INVALID_HANDLE_VALUE) { - DoOutputErrorString(TEXT("Could not create CAPE output file")); + DoOutputErrorString("DumpMemory: Could not create CAPE output file"); free(OutputFilename); free(FullPathName); return 0; } - DoOutputDebugString(TEXT("Passed invalid_handle check")); dwBytesWritten = 0; - DoOutputDebugString("CAPE output file succssfully created:%s", FullPathName); + DoOutputDebugString("DumpMemory: CAPE output file succssfully created: %s", FullPathName); - if (FALSE == WriteFile(hOutputFile, Buffer, Size, &dwBytesWritten, NULL)) + BufferCopy = (LPVOID)((BYTE*)malloc(Size)); + + if (BufferCopy == NULL) + { + DoOutputDebugString("DumpMemory: Failed to allocate memory for buffer copy.\n"); + return FALSE; + } + + memcpy(BufferCopy, Buffer, Size); + + if (FALSE == WriteFile(hOutputFile, BufferCopy, Size, &dwBytesWritten, NULL)) { - DoOutputDebugString(TEXT("WriteFile error on CAPE output file")); - free(OutputFilename); free(FullPathName); + DoOutputErrorString("DumpMemory: WriteFile error on CAPE output file"); + free(OutputFilename); free(FullPathName); free(BufferCopy); return 0; } - DoOutputDebugString(TEXT("CAPE output filename: %s"), FullPathName); - CloseHandle(hOutputFile); CapeOutputFile(FullPathName); // We can free the filename buffers - free(OutputFilename); free(FullPathName); + free(OutputFilename); free(FullPathName); free(BufferCopy); return 1; } @@ -580,8 +842,9 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) int DumpCurrentProcessFixImports(DWORD NewEP) //************************************************************************************** { - if (ScyllaDumpCurrentProcessFixImports(NewEP)) + if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcessFixImports(NewEP)) { + DumpCount++; return 1; } @@ -592,9 +855,9 @@ int DumpCurrentProcessFixImports(DWORD NewEP) int DumpCurrentProcessNewEP(DWORD NewEP) //************************************************************************************** { - if (ScyllaDumpCurrentProcess(NewEP)) - + if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcess(NewEP)) { + DumpCount++; return 1; } @@ -605,21 +868,113 @@ int DumpCurrentProcessNewEP(DWORD NewEP) int DumpCurrentProcess() //************************************************************************************** { - if (ScyllaDumpCurrentProcess(0)) + if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcess(0)) + { + DumpCount++; + return 1; + } + + return 0; +} + +//************************************************************************************** +int DumpModuleInCurrentProcess(DWORD ModuleBase) +//************************************************************************************** +{ + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), ModuleBase, 0)) { + DumpCount++; return 1; } return 0; } +//************************************************************************************** +int DumpImageInCurrentProcess(DWORD ImageBase) +//************************************************************************************** +{ + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; + + pDosHeader = (PIMAGE_DOS_HEADER)ImageBase; + + if (DumpCount >= DUMP_MAX) + { + DoOutputDebugString("DumpImageInCurrentProcess: CAPE dump limit reached.\n"); + return 0; + } + + if (*(WORD*)ImageBase != IMAGE_DOS_SIGNATURE) + { + DoOutputDebugString("DumpImageInCurrentProcess: No DOS signature in header.\n"); + return 0; + } + + if (!pDosHeader->e_lfanew || pDosHeader->e_lfanew > PE_HEADER_LIMIT) + { + DoOutputDebugString("DumpImageInCurrentProcess: bad e_lfanew.\n"); + return 0; + } + + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) + { + // No 'PE' header + DoOutputDebugString("DumpImageInCurrentProcess: Invalid PE signature in header.\n"); + return 0; + } + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + { + // Basic requirements + DoOutputDebugString("DumpImageInCurrentProcess: PE image invalid.\n"); + return 0; + } + + // we perform a couple of tests to determine whether this is a 'raw' or 'virtual' image + // first we check if the SizeOfHeaders is a multiple of FileAlignment + if (pNtHeader->OptionalHeader.SizeOfHeaders % pNtHeader->OptionalHeader.FileAlignment + // let's also check if section 1 actually begins after the headers, i.e. raw image + || (*((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders - 1) == 0 // end of header is zero + && *((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders) != 0)) // beginning of raw section 1 is non-zero + { + // looks like a 'raw'/'file' image, i.e. not loaded + if (ScyllaDumpPE(ImageBase)) + { + DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump 'raw' PE image.\n"); + DumpCount++; + return 1; + } + else + { + // failed to dump pe image + DoOutputDebugString("DumpImageInCurrentProcess: Failed to dump 'raw' PE image.\n"); + return 0; + } + } + + // we should be dealing with a 'loaded' module image now, + // not a 'raw' file image, so try dumping this way first + DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump virtual PE image.\n"); + + if (!ScyllaDumpProcess(GetCurrentProcess(), ImageBase, 0)) + // if this fails, let's try dumping 'raw' just in case + if (!ScyllaDumpPE(ImageBase)) + return 0; + + DumpCount++; + return 1; +} //************************************************************************************** int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase) //************************************************************************************** { - if (ScyllaDumpProcess(hProcess, ImageBase, 0)) + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(hProcess, ImageBase, 0)) { - return 1; + DumpCount++; + return 1; } return 0; @@ -629,22 +984,58 @@ int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase) int DumpPE(LPCVOID Buffer) //************************************************************************************** { - if (ScyllaDumpPE((DWORD_PTR)Buffer)) + if (DumpCount < DUMP_MAX && ScyllaDumpPE((DWORD_PTR)Buffer)) { - return 1; + DumpCount++; + return 1; } return 0; } +//************************************************************************************** +int RoutineProcessDump() +//************************************************************************************** +{ + if (g_config.procmemdump && ProcessDumped == FALSE) + { + ProcessDumped = TRUE; // this prevents a second call before the first is complete + if (g_config.import_reconstruction) + { + if (base_of_dll_of_interest) + ProcessDumped = ScyllaDumpProcessFixImports(GetCurrentProcess(), base_of_dll_of_interest, 0); + else + ProcessDumped = ScyllaDumpCurrentProcessFixImports(0); + } + else + { + if (base_of_dll_of_interest) + ProcessDumped = ScyllaDumpProcess(GetCurrentProcess(), base_of_dll_of_interest, 0); + else + ProcessDumped = ScyllaDumpCurrentProcess(0); + } + } + + return ProcessDumped; +} + void init_CAPE() { // Initialise CAPE global variables + // + CapeMetaData = (PCAPEMETADATA)malloc(sizeof(CAPEMETADATA)); + CapeMetaData->Pid = GetCurrentProcessId(); + CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); + + DumpCount = 0; - RunPE_Handle = NULL; - RunPE_ImageBase = 0; - RunPE_EntryPoint = (DWORD_PTR)NULL; - RunPE_ProcessWriteDetected = FALSE; +#ifndef _WIN64 + // Start the debugger thread + // if required by package + if (DEBUGGER_ENABLED) + launch_debugger(); +#endif return; } \ No newline at end of file diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 6bfce27..6ee2aa5 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -8,12 +8,25 @@ extern int DumpPE(LPCVOID Buffer); extern int ScyllaDumpPE(DWORD_PTR Buffer); unsigned int DumpSize; -HANDLE RunPE_Handle; -DWORD_PTR RunPE_ImageBase; +//Global switch for debugger +#define DEBUGGER_ENABLED 0 -DWORD_PTR RunPE_EntryPoint; -BOOL RunPE_ProcessWriteDetected; -BOOL RunPE_ImageDumped; +typedef struct InjectionInfo +{ + int ProcessId; + HANDLE ProcessHandle; + DWORD_PTR ImageBase; + DWORD_PTR EntryPoint; + BOOL ImageDumped; + LPCVOID BufferBase; + unsigned int BufferSizeOfImage; + struct InjectionInfo *NextInjectionInfo; +} INJECTIONINFO, *PINJECTIONINFO; + +struct InjectionInfo *InjectionInfoList; + +PINJECTIONINFO GetInjectionInfo(DWORD ProcessId); +PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId); // // MessageId: STATUS_SUCCESS @@ -41,3 +54,39 @@ BOOL RunPE_ImageDumped; #define DATA 0 #define EXECUTABLE 1 +#define DLL 2 + +#define PLUGX_SIGNATURE 0x5658 // 'XV' +#define PE_HEADER_LIMIT 0x200 // Range to look for PE header within candidate buffer + +typedef struct CapeMetadata +{ + char* ProcessPath; + char* ModulePath; + DWORD Pid; + DWORD DumpType; + char* TargetProcess; // For injection + DWORD TargetPid; // " + PVOID Address; // For shellcode + SIZE_T Size; // " +} CAPEMETADATA, *PCAPEMETADATA; + +struct CapeMetadata *CapeMetaData; + +BOOL SetCapeMetaData(DWORD DumpType, DWORD TargetPid, HANDLE hTargetProcess, PVOID Address); + +enum { + PROCDUMP = 0, + + COMPRESSION = 1, + + INJECTION_PE = 3, + INJECTION_SHELLCODE = 4, + //INJECTION_RUNPE = 5, + + EXTRACTION_PE = 8, + EXTRACTION_SHELLCODE = 9, + + PLUGX_PAYLOAD = 0x10, + PLUGX_CONFIG = 0x11 +}; \ No newline at end of file diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index cc052c0..5ceebd2 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -65,6 +65,18 @@ typedef struct _DR7 #define DEBUG_REGISTER_DATA_SIZES {1, 2, 4} #define DEBUG_REGISTER_LENGTH_MASKS {0xFFFFFFFF, 0, 1, 0xFFFFFFFF, 3} +typedef struct _LSA_UNICODE_STRING { + USHORT Length; + USHORT MaximumLength; + PWSTR Buffer; +} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING; + +typedef struct _INJECT_STRUCT { + ULONG_PTR LdrLoadDllAddress; + UNICODE_STRING DllName; + HANDLE OutHandle; +} INJECT_STRUCT, *PINJECT_STRUCT; + DWORD LengthMask[MAX_DEBUG_REGISTER_DATA_SIZE + 1] = DEBUG_REGISTER_LENGTH_MASKS; DWORD MainThreadId; @@ -197,6 +209,8 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) } } + CurrentThreadBreakpoint->ThreadId = ThreadId; + for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) { CurrentThreadBreakpoint->BreakpointInfo[Register].Register = Register; @@ -206,19 +220,94 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) return CurrentThreadBreakpoint; } +//************************************************************************************** +BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register) +//************************************************************************************** +{ + DWORD CurrentThreadId; + unsigned int i; + + PTHREADBREAKPOINTS CurrentThreadBreakpoint = MainThreadBreakpointList; + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("GetNextAvailableBreakpoint: MainThreadBreakpointList NULL.\n"); + return FALSE; + } + + while (CurrentThreadBreakpoint) + { + CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); + + DoOutputDebugString("GetNextAvailableBreakpoint: CurrentThreadId = 0x%x.\n", CurrentThreadId); + + if (CurrentThreadId == ThreadId) + { + for (i=0; i<4; i++) + { + if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) + { + *Register = i; + return TRUE; + } + else + DoOutputDebugString("GetNextAvailableBreakpoint: CurrentThreadBreakpoint->BreakpointInfo[%d].Address = 0x%x.\n", i, CurrentThreadBreakpoint->BreakpointInfo[i].Address); + + } + } + + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; + } + + return FALSE; +} + +//************************************************************************************** +BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) +//************************************************************************************** +{ + unsigned int i; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextGetNextAvailableBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", GetCurrentThreadId()); + CurrentThreadBreakpoint = CreateThreadBreakpoints(GetCurrentThreadId()); + } + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextGetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); + return FALSE; + } + + for (i=0; i<4; i++) + { + if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) + { + *Register = i; + return TRUE; + } + } + + return FALSE; +} + //************************************************************************************** void DebugOutputThreadBreakpoints() //************************************************************************************** { unsigned int Register; - PTHREADBREAKPOINTS CurrentThreadBreakpoints; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; PBREAKPOINTINFO pBreakpointInfo; - CurrentThreadBreakpoints = GetThreadBreakpoints(GetCurrentThreadId()); + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) { - pBreakpointInfo = &(CurrentThreadBreakpoints->BreakpointInfo[Register]); + pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[Register]); if (pBreakpointInfo == NULL) { @@ -247,18 +336,8 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { BOOL BreakpointFlag; PBREAKPOINTINFO pBreakpointInfo; - PTHREADBREAKPOINTS CurrentThreadBreakpoints; - - DoOutputDebugString("Entering CAPEExceptionFilter: breakpoint hit: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); + PTHREADBREAKPOINTS CurrentThreadBreakpoint; - CurrentThreadBreakpoints = GetThreadBreakpoints(GetCurrentThreadId()); - - if (CurrentThreadBreakpoints == NULL) - { - DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); - return EXCEPTION_CONTINUE_SEARCH; - } - // Test Dr6 to see if this is a breakpoint BreakpointFlag = FALSE; for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) @@ -272,16 +351,25 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) // If not it's a single-step if (BreakpointFlag == FALSE) { - //if (SingleStepHandler(ExceptionInfo)) SingleStepHandler(ExceptionInfo); return EXCEPTION_CONTINUE_EXECUTION; } + DoOutputDebugString("Entering CAPEExceptionFilter: breakpoint hit: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); + return EXCEPTION_CONTINUE_SEARCH; + } + for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) { if (ExceptionInfo->ContextRecord->Dr6 & (1 << bp)) { - pBreakpointInfo = &(CurrentThreadBreakpoints->BreakpointInfo[bp]); + pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[bp]); if (pBreakpointInfo == NULL) { @@ -309,7 +397,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - SetExceptionHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -323,7 +411,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - SetExceptionHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -337,7 +425,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on stack breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - SetExceptionHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -351,7 +439,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - SetExceptionHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -382,7 +470,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } //************************************************************************************** -BOOL SetExceptionDebugRegister +BOOL ContextSetDebugRegister //************************************************************************************** ( PCONTEXT Context, @@ -402,25 +490,25 @@ BOOL SetExceptionDebugRegister if ((unsigned int)Type > 3) { - DoOutputDebugString("SetExceptionDebugRegister: %d is an invalid breakpoint type, must be 0-3.\n", Type); + DoOutputDebugString("ContextSetDebugRegister: %d is an invalid breakpoint type, must be 0-3.\n", Type); return FALSE; } if (Type == 2) { - DoOutputDebugString("SetExceptionDebugRegister: The value 2 is a 'reserved' breakpoint type, ultimately invalid.\n"); + DoOutputDebugString("ContextSetDebugRegister: The value 2 is a 'reserved' breakpoint type, ultimately invalid.\n"); return FALSE; } if (Register < 0 || Register > 3) { - DoOutputDebugString("SetExceptionDebugRegister: %d is an invalid register, must be 0-3.\n", Register); + DoOutputDebugString("ContextSetDebugRegister: %d is an invalid register, must be 0-3.\n", Register); return FALSE; } if (Size < 0 || Size > 8) { - DoOutputDebugString("SetExceptionDebugRegister: %d is an invalid Size, must be 1, 2, 4 or 8.\n", Size); + DoOutputDebugString("ContextSetDebugRegister: %d is an invalid Size, must be 1, 2, 4 or 8.\n", Size); return FALSE; } @@ -572,6 +660,20 @@ BOOL SetDebugRegister return TRUE; } +//************************************************************************************** +BOOL ContextClearAllDebugRegisters(PCONTEXT Context) +//************************************************************************************** +{ + Context->Dr0 = 0; + Context->Dr1 = 0; + Context->Dr2 = 0; + Context->Dr3 = 0; + Context->Dr6 = 0; + Context->Dr7 = 0; + + return TRUE; +} + //************************************************************************************** BOOL ClearAllDebugRegisters(HANDLE hThread) //************************************************************************************** @@ -637,7 +739,7 @@ BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext) } //************************************************************************************** -BOOL ClearExceptionHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) +BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) //************************************************************************************** { PDWORD Dr0, Dr1, Dr2, Dr3; @@ -834,14 +936,14 @@ BOOL ClearDebugRegister } //************************************************************************************** -int CheckExceptionDebugRegister(CONTEXT Context, int Register) +int ContextCheckDebugRegister(CONTEXT Context, int Register) //************************************************************************************** { PDR7 Dr7; if (Register < 0 || Register > 3) { - DoOutputDebugString("CheckExceptionDebugRegister: %d is an invalid register, must be 0-3.\n", Register); + DoOutputDebugString("ContextCheckDebugRegister: %d is an invalid register, must be 0-3.\n", Register); return FALSE; } @@ -897,7 +999,7 @@ int CheckDebugRegister(HANDLE hThread, int Register) } //************************************************************************************** -BOOL SetExceptionHardwareBreakpoint +BOOL ContextSetHardwareBreakpoint //************************************************************************************** ( PCONTEXT Context, @@ -912,17 +1014,17 @@ BOOL SetExceptionHardwareBreakpoint if (Register > 3 || Register < 0) { - DoOutputDebugString("SetExceptionHardwareBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("ContextSetHardwareBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } - if (SetExceptionDebugRegister(Context, Register, Size, Address, Type) == FALSE) + if (ContextSetDebugRegister(Context, Register, Size, Address, Type) == FALSE) { - DoOutputDebugString("Call to SetExceptionDebugRegister failed.\n"); + DoOutputDebugString("Call to ContextSetDebugRegister failed.\n"); } else { - DoOutputDebugString("Call to SetExceptionDebugRegister succeeded.\n"); + DoOutputDebugString("Call to ContextSetDebugRegister succeeded.\n"); CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); @@ -938,7 +1040,91 @@ BOOL SetExceptionHardwareBreakpoint CurrentThreadBreakpoint->BreakpointInfo[Register].Type = Type; } - return 1; + return TRUE; +} + +//************************************************************************************** +BOOL ContextSetNextAvailableBreakpoint +//************************************************************************************** +( + PCONTEXT Context, + unsigned int* Register, + int Size, + LPVOID Address, + DWORD Type, + PVOID Callback +) +{ + if (ContextGetNextAvailableBreakpoint(Context, Register) == FALSE) + { + DoOutputDebugString("ContextSetNextAvailableBreakpoint: ContextGetNextAvailableBreakpoint failed\n"); + return FALSE; + } + + return ContextSetHardwareBreakpoint(Context, *Register, Size, Address, Type, Callback); +} + +//************************************************************************************** +BOOL ContextUpdateCurrentBreakpoint +//************************************************************************************** +( + PCONTEXT Context, + int Size, + LPVOID Address, + DWORD Type, + PVOID Callback +) +{ + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + PBREAKPOINTINFO pBreakpointInfo; + unsigned int bp; + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextUpdateCurrentBreakpoint: Error - Failed to acquire thread breakpoints.\n"); + return FALSE; + } + + for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) + { + if (Context->Dr6 & (1 << bp)) + { + pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[bp]); + + if (pBreakpointInfo == NULL) + { + DoOutputDebugString("ContextUpdateCurrentBreakpoint: Can't get BreakpointInfo.\n"); + return FALSE; + } + + if (pBreakpointInfo->Register == bp) + { + if (bp == 0 && ((DWORD)pBreakpointInfo->Address == Context->Dr0) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE0)) + { + return ContextSetHardwareBreakpoint(Context, 0, Size, Address, Type, Callback); + } + + if (bp == 1 && ((DWORD)pBreakpointInfo->Address == Context->Dr1) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE1)) + { + return ContextSetHardwareBreakpoint(Context, 1, Size, Address, Type, Callback); + } + + if (bp == 2 && ((DWORD)pBreakpointInfo->Address == Context->Dr2) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE2)) + { + return ContextSetHardwareBreakpoint(Context, 2, Size, Address, Type, Callback); + } + + if (bp == 3 && ((DWORD)pBreakpointInfo->Address == Context->Dr3) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE3)) + { + return ContextSetHardwareBreakpoint(Context, 3, Size, Address, Type, Callback); + } + } + } + } + + return FALSE; } //************************************************************************************** @@ -953,7 +1139,7 @@ DWORD WINAPI SetBreakpointThread(LPVOID lpParam) DoOutputDebugString("SetBreakpointThread: Current thread suspended.\n"); //debug - DoOutputDebugString("SetBreakpointThread: ABbout to call SetDebugRegister.\n"); + DoOutputDebugString("SetBreakpointThread: About to call SetDebugRegister.\n"); if (SetDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) { @@ -989,7 +1175,7 @@ DWORD WINAPI ClearBreakpointThread(LPVOID lpParam) ResumeThread(pBreakpointInfo->ThreadHandle); - return 1; + return TRUE; } //************************************************************************************** @@ -1005,7 +1191,7 @@ BOOL SetHardwareBreakpoint ) { PBREAKPOINTINFO pBreakpointInfo; - PTHREADBREAKPOINTS CurrentThreadBreakpoints; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; HANDLE hSetBreakpointThread; if (Register > 3 || Register < 0) @@ -1014,29 +1200,29 @@ BOOL SetHardwareBreakpoint return FALSE; } - CurrentThreadBreakpoints = GetThreadBreakpoints(ThreadId); + CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - if (CurrentThreadBreakpoints == NULL) + if (CurrentThreadBreakpoint == NULL) { DoOutputDebugString("Creating new thread breakpoints for thread 0x%x.\n", ThreadId); - CurrentThreadBreakpoints = CreateThreadBreakpoints(ThreadId); + CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } - if (CurrentThreadBreakpoints == NULL) + if (CurrentThreadBreakpoint == NULL) { DoOutputDebugString("Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } - pBreakpointInfo = &CurrentThreadBreakpoints->BreakpointInfo[Register]; + pBreakpointInfo = &CurrentThreadBreakpoint->BreakpointInfo[Register]; - if (CurrentThreadBreakpoints->ThreadHandle == NULL) + if (CurrentThreadBreakpoint->ThreadHandle == NULL) { DoOutputDebugString("SetHardwareBreakpoint: There is no thread handle in the threadbreakpoint!! FATAL ERROR.\n"); return FALSE; } - pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoints->ThreadHandle; + pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; pBreakpointInfo->Register = Register; pBreakpointInfo->Size = Size; pBreakpointInfo->Address = Address; @@ -1058,9 +1244,10 @@ BOOL SetHardwareBreakpoint if (hSetBreakpointThread == NULL) { - DoOutputDebugString("Failed to create SetBreakpointThread thread\n"); + DoOutputErrorString("Failed to create SetBreakpointThread thread"); return 0; } + DoOutputDebugString("SetHardwareBreakpoint: SetBreakpointThread called, beginning wait\n"); // Wait until thread has terminated @@ -1076,19 +1263,15 @@ BOOL SetHardwareBreakpoint pBreakpointInfo->ThreadHandle, pBreakpointInfo->Type); - return 1; + return TRUE; } //************************************************************************************** -BOOL ClearHardwareBreakpoint +BOOL ClearHardwareBreakpoint(DWORD ThreadId, int Register) //************************************************************************************** -( - DWORD ThreadId, - int Register -) { PBREAKPOINTINFO pBreakpointInfo; - PTHREADBREAKPOINTS CurrentThreadBreakpoints; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; HANDLE hClearBreakpointThread; if (Register > 3 || Register < 0) @@ -1097,26 +1280,26 @@ BOOL ClearHardwareBreakpoint return FALSE; } - CurrentThreadBreakpoints = GetThreadBreakpoints(ThreadId); + CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - if (CurrentThreadBreakpoints == NULL) + if (CurrentThreadBreakpoint == NULL) { DoOutputDebugString("Cannot find thread breakpoints - failed to clear.\n"); return FALSE; } - pBreakpointInfo = &CurrentThreadBreakpoints->BreakpointInfo[Register]; + pBreakpointInfo = &CurrentThreadBreakpoint->BreakpointInfo[Register]; - if (CurrentThreadBreakpoints->ThreadHandle == NULL) + if (CurrentThreadBreakpoint->ThreadHandle == NULL) { DoOutputDebugString("ClearHardwareBreakpoint: There is no thread handle in the threadbreakpoint!! FATAL ERROR.\n"); return FALSE; } - else DoOutputDebugString("ClearHardwareBreakpoint: Thread handle 0x%x found in BreakpointInfo struct.\n", CurrentThreadBreakpoints->ThreadHandle); + else DoOutputDebugString("ClearHardwareBreakpoint: Thread handle 0x%x found in BreakpointInfo struct.\n", CurrentThreadBreakpoint->ThreadHandle); DoOutputDebugString("About to create ClearBreakpointThread thread\n"); - pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoints->ThreadHandle; + pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; hClearBreakpointThread = CreateThread(NULL, 0, ClearBreakpointThread, pBreakpointInfo, 0, &ThreadId); @@ -1140,7 +1323,42 @@ BOOL ClearHardwareBreakpoint CheckDebugRegisters(pBreakpointInfo->ThreadHandle, 0); - return 1; + return TRUE; +} + +//************************************************************************************** +BOOL SetNextAvailableBreakpoint +//************************************************************************************** +( + DWORD ThreadId, + unsigned int* Register, + int Size, + LPVOID Address, + DWORD Type, + PVOID Callback +) +{ + PTHREADBREAKPOINTS CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("SetNextAvailableBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); + } + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("SetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); + return FALSE; + } + + if (GetNextAvailableBreakpoint(ThreadId, Register) == FALSE) + { + DoOutputDebugString("SetNextAvailableBreakpoint: GetNextAvailableBreakpoint failed\n"); + return FALSE; + } + + return SetHardwareBreakpoint(ThreadId, *Register, Size, Address, Type, Callback); } //************************************************************************************** @@ -1172,6 +1390,7 @@ BOOL InitialiseDebugger(void) } // Initialise any global variables + Injection_ProcessId = 0; // Ensure wow64 patch is installed if needed WoW64fix(); @@ -1199,14 +1418,6 @@ __declspec (naked dllexport) void DebuggerInit(void) // Target specific code -// StackWriteCallback implemented in CAPE_UPX.c - if (SetHardwareBreakpoint(MainThreadId, 3, 1, (BYTE*)StackPointer, BP_WRITE, StackWriteCallback)) - { - DoOutputDebugString("SetHardwareBreakpoint (3) returned successfully!\n"); - } - else - DoOutputDebugString("SetHardwareBreakpoint (3) failed\n"); - // End of target specific code DoOutputDebugString("Debugger initialised, about to execute OEP.\n"); @@ -1221,6 +1432,43 @@ __declspec (naked dllexport) void DebuggerInit(void) } +BOOL SendDebuggerMessage(DWORD Input) +{ + BOOL fSuccess; + DWORD cbReplyBytes, cbWritten; + //struct DEBUGGER_DATA DebuggerData; + + //memset(&DebuggerData, 0, sizeof(struct DEBUGGER_DATA)); + + cbReplyBytes = sizeof(DWORD); + + if (hParentPipe == NULL) + { + DoOutputErrorString("SendDebuggerMessage: hParentPipe NULL."); + return FALSE; + } + + // Write the reply to the pipe. + fSuccess = WriteFile + ( + hParentPipe, // handle to pipe + &Input, // buffer to write from + cbReplyBytes, // number of bytes to write + &cbWritten, // number of bytes written + NULL // not overlapped I/O + ); + + if (!fSuccess || cbReplyBytes != cbWritten) + { + DoOutputErrorString("SendDebuggerMessage: Failed to send message via pipe"); + return FALSE; + } + + DoOutputDebugString("SendDebuggerMessage: Sent message via pipe.\n"); + + return TRUE; +} + //************************************************************************************** DWORD WINAPI DebuggerThread(LPVOID lpParam) //************************************************************************************** @@ -1254,13 +1502,13 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) if (GetLastError() != ERROR_PIPE_BUSY) { - DoOutputErrorString("Could not open pipe"); + DoOutputErrorString("DebuggerThread: Could not open pipe"); return -1; } if (!WaitNamedPipe(lpszPipename, 20)) { - DoOutputDebugString("Could not open pipe: 20 ms wait timed out.\n"); + DoOutputDebugString("DebuggerThread: Could not open pipe: 20 ms wait timed out.\n"); return -1; } } @@ -1276,7 +1524,7 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) ); if (!fSuccess) { - DoOutputDebugString("SetNamedPipeHandleState failed.\n"); + DoOutputDebugString("DebuggerThread: SetNamedPipeHandleState failed.\n"); return -1; } @@ -1295,11 +1543,11 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) ); if (!fSuccess) { - DoOutputErrorString("WriteFile to pipe failed"); + DoOutputErrorString("DebuggerThread: WriteFile to pipe failed"); return -1; } - DoOutputDebugString("DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); + DoOutputDebugString("DebuggerThread: DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); fSuccess = ReadFile( hPipe, @@ -1310,22 +1558,48 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) if (!fSuccess && GetLastError() == ERROR_MORE_DATA) { - DoOutputDebugString("ReadFile on Pipe: ERROR_MORE_DATA\n"); + DoOutputDebugString("DebuggerThread: ReadFile on Pipe: ERROR_MORE_DATA\n"); CloseHandle(hPipe); return -1; } if (!fSuccess) { - DoOutputErrorString("ReadFile from pipe failed"); + DoOutputErrorString("DebuggerThread: ReadFile (OEP) from pipe failed"); CloseHandle(hPipe); return -1; } DoOutputDebugString("Read OEP from pipe: 0x%x\n", OEP); - //CloseHandle(hPipe); + fSuccess = ReadFile( + hPipe, + &OEP, + sizeof(DWORD), + &cbRead, + NULL); + + if (!fSuccess && GetLastError() == ERROR_MORE_DATA) + { + DoOutputDebugString("DebuggerThread: ReadFile on Pipe: ERROR_MORE_DATA\n"); + CloseHandle(hPipe); + return -1; + } + if (!fSuccess && GetLastError() == ERROR_BROKEN_PIPE) + { + DoOutputDebugString("DebuggerThread: Pipe closed, no further updates to OEP\n"); + CloseHandle(hPipe); + } + else if (!fSuccess) + { + DoOutputErrorString("ReadFile from pipe failed"); + CloseHandle(hPipe); + return -1; + } + else + DoOutputDebugString("Read thread EP from pipe: 0x%x\n", OEP); + ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO)); VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&VersionInfo); @@ -1389,15 +1663,12 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati if (hParentPipe == INVALID_HANDLE_VALUE) { - DoOutputErrorString("CreateNamedPipe failed"); + DoOutputErrorString("DebugNewProcess: CreateNamedPipe failed"); return FALSE; } -#ifndef STANDALONE - //pipe("PROCESS:%d:%d,%d", 0, ProcessId, 0); // we need CreateRemoteThread injection - pipe("PROCESS:%d:%d,%d", (CreationFlags & CREATE_SUSPENDED) ? 1 : 0, ProcessId, ThreadId); - DoOutputDebugString("DebugNewProcess: Announcing new process to Cuckoo.\n"); -#endif + DoOutputDebugString("DebugNewProcess: Announcing new process to Cuckoo, pid: %d\n", ProcessId); + pipe("DEBUGGER:%d,%d", ProcessId, ThreadId); fConnected = ConnectNamedPipe(hParentPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); fSuccess = FALSE; @@ -1405,14 +1676,12 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati if (!fConnected) { - DoOutputDebugString("The client could not connect, closing pipe.\n"); - + DoOutputDebugString("DebugNewProcess: The client could not connect, closing pipe.\n"); CloseHandle(hParentPipe); - - return -15; + return FALSE; } - DoOutputDebugString("Client connected\n"); + DoOutputDebugString("DebugNewProcess: Client connected\n"); fSuccess = ReadFile ( @@ -1427,24 +1696,24 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati { if (GetLastError() == ERROR_BROKEN_PIPE) { - DoOutputErrorString("Client disconnected."); + DoOutputErrorString("DebugNewProcess: Client disconnected."); } else { - DoOutputErrorString("ReadFile failed."); + DoOutputErrorString("DebugNewProcess: ReadFile failed."); } } if (!RemoteFuncAddress) { - DoOutputErrorString("Successfully read from pipe, however RemoteFuncAddress = 0."); + DoOutputErrorString("DebugNewProcess: Successfully read from pipe, however RemoteFuncAddress = 0."); return FALSE; } Context.ContextFlags = CONTEXT_ALL; if (!GetThreadContext(hThread, &Context)) { - DoOutputDebugString("GetThreadContext failed - FATAL\n"); + DoOutputDebugString("DebugNewProcess: GetThreadContext failed - FATAL\n"); return FALSE; } @@ -1464,7 +1733,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati ); if (!fSuccess || cbReplyBytes != cbWritten) { - DoOutputErrorString("Failed to send OEP via pipe."); + DoOutputErrorString("DebugNewProcess: Failed to send OEP via pipe."); return FALSE; } @@ -1476,13 +1745,12 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati if (!SetThreadContext(hThread, &Context)) { - DoOutputDebugString("Failed to set new EP\n"); + DoOutputDebugString("DebugNewProcess: Failed to set new EP\n"); return FALSE; } - DoOutputDebugString("Set new EP to DebuggerInit: 0x%x\n", Context.Eax); + DoOutputDebugString("DebugNewProcess: Set new EP to DebuggerInit: 0x%x\n", Context.Eax); - //CloseHandle(hParentPipe); CloseHandle(hProcess); CloseHandle(hThread); diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 1ca1fca..89544cc 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -1,11 +1,14 @@ #pragma once +void* CAPE_var; + #define BP_EXEC 0x00 #define BP_WRITE 0x01 #define BP_RESERVED 0x02 #define BP_READWRITE 0x03 DWORD Injection_ProcessId; +DWORD RemoteFuncAddress; typedef struct BreakpointInfo { @@ -46,7 +49,7 @@ BOOL SetHardwareBreakpoint BOOL ClearHardwareBreakpoint(DWORD ThreadId, int Register); -BOOL SetExceptionHardwareBreakpoint +BOOL ContextSetHardwareBreakpoint ( PCONTEXT Context, int Register, @@ -56,9 +59,15 @@ BOOL SetExceptionHardwareBreakpoint PVOID Callback ); -BOOL ClearExceptionHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); +BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register); +BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register); +BOOL ContextUpdateCurrentBreakpoint(PCONTEXT Context, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL SetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL ContextSetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL ClearSingleStepMode(PCONTEXT Context); +BOOL ContextClearAllDebugRegisters(PCONTEXT Context); BOOL ClearAllDebugRegisters(HANDLE hThread); BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); BOOL InitialiseDebugger(void); diff --git a/CAPE/GetThreadId.c b/CAPE/GetThreadId.c index 360a104..727bf75 100644 --- a/CAPE/GetThreadId.c +++ b/CAPE/GetThreadId.c @@ -117,5 +117,5 @@ DWORD MyGetThreadId FreeLibrary(hModule); - return (DWORD)ThreadBasicInfo.ClientId.UniqueThread; + return (DWORD)(UINT_PTR)ThreadBasicInfo.ClientId.UniqueThread; } diff --git a/CAPE/Output.c b/CAPE/Output.c index fb805a4..4ff7297 100644 --- a/CAPE/Output.c +++ b/CAPE/Output.c @@ -18,13 +18,19 @@ along with this program.If not, see . #include #include #include - +#include "cape.h" #include "..\pipe.h" +#include "..\config.h" + +#define MAX_INT_STRING_LEN 10 // 4294967294 TCHAR DebugOutput[MAX_PATH]; TCHAR PipeOutput[MAX_PATH]; TCHAR ErrorOutput[MAX_PATH]; +extern struct CapeMetadata *CapeMetaData; +extern ULONG_PTR base_of_dll_of_interest; + //************************************************************************************** void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...) //************************************************************************************** @@ -89,14 +95,129 @@ void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...) void CapeOutputFile(_In_ LPCTSTR lpOutputFile) //************************************************************************************** { - memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); - _sntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, "CAPE Output file: %s", lpOutputFile); - OutputDebugString(DebugOutput); - - memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); - _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "FILE_CAPE:%s", lpOutputFile); + char MetadataPath[MAX_PATH]; + HANDLE hMetadata; + SIZE_T BufferSize; + char *Buffer; + DWORD dwBytesWritten; + + if (CapeMetaData && CapeMetaData->DumpType == PROCDUMP) + { + memset(MetadataPath, 0, MAX_PATH * sizeof(TCHAR)); + _sntprintf_s(MetadataPath, MAX_PATH, MAX_PATH, "%s_info.txt", lpOutputFile); + hMetadata = CreateFile(MetadataPath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hMetadata == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) + { + DoOutputDebugString("CAPE metadata filename exists already: %s", MetadataPath); + return; + } + + if (hMetadata == INVALID_HANDLE_VALUE) + { + DoOutputErrorString("Could not create CAPE metadata file"); + return; + } + + BufferSize = 3 * (MAX_PATH + MAX_INT_STRING_LEN + 2) + 2; //// max size string can be + + Buffer = malloc(BufferSize); + + // if our file of interest is a dll, we need to update cape module path now + if (base_of_dll_of_interest) + { + if (g_config.file_of_interest == NULL) + { + DoOutputDebugString("CAPE Error: g_config.file_of_interest is NULL.\n", g_config.file_of_interest); + return; + } + + CapeMetaData->ModulePath = (char*)malloc(MAX_PATH); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)g_config.file_of_interest, wcslen(g_config.file_of_interest)+1, CapeMetaData->ModulePath, MAX_PATH, NULL, NULL); + } + else + CapeMetaData->ModulePath = CapeMetaData->ProcessPath; + + // This metadata format is specific to process dumps + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath); + + if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) + { + DoOutputDebugString("WriteFile error on CAPE metadata file %s\n"); + CloseHandle(hMetadata); + free(Buffer); + return; + } + + CloseHandle(hMetadata); + + memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); + _sntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, "Process dump output file: %s", lpOutputFile); + OutputDebugString(DebugOutput); + + memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); + _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "FILE_DUMP:%s", lpOutputFile); #ifndef STANDALONE - pipe(PipeOutput, strlen(PipeOutput)); + pipe(PipeOutput, strlen(PipeOutput)); +#endif + } + else if (CapeMetaData && CapeMetaData->DumpType != PROCDUMP) + { + memset(MetadataPath, 0, MAX_PATH * sizeof(TCHAR)); + _sntprintf_s(MetadataPath, MAX_PATH, MAX_PATH, "%s_info.txt", lpOutputFile); + hMetadata = CreateFile(MetadataPath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hMetadata == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) + { + DoOutputDebugString("CAPE metadata filename exists already: %s", MetadataPath); + return; + } + + if (hMetadata == INVALID_HANDLE_VALUE) + { + DoOutputErrorString("Could not create CAPE metadata file"); + return; + } + + BufferSize = 3 * (MAX_PATH + MAX_INT_STRING_LEN + 2) + 2; //// max size string can be + + Buffer = malloc(BufferSize); + + CapeMetaData->ModulePath = CapeMetaData->ProcessPath; + + if (CapeMetaData->DumpType == EXTRACTION_PE || CapeMetaData->DumpType == EXTRACTION_SHELLCODE) + { + // Extraction-specific format + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n0x%x\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, (DWORD)CapeMetaData->Address); + } + else if (CapeMetaData->DumpType == INJECTION_PE || CapeMetaData->DumpType == INJECTION_SHELLCODE) + { + // Injection-specific format + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n%s\n%d\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->TargetProcess, CapeMetaData->TargetPid); + } + + if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) + { + DoOutputDebugString("WriteFile error on CAPE metadata file %s\n"); + CloseHandle(hMetadata); + free(Buffer); + return; + } + + CloseHandle(hMetadata); + + memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); + _sntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, "CAPE Output file: %s", lpOutputFile); + OutputDebugString(DebugOutput); + + memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); + _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "FILE_CAPE:%s", lpOutputFile); +#ifndef STANDALONE + pipe(PipeOutput, strlen(PipeOutput)); #endif + } + else + DoOutputDebugString("No CAPE metadata (or wrong type) for file: %s\n", lpOutputFile); + return; -} \ No newline at end of file +} diff --git a/CAPE/Scylla/ImportRebuilder.cpp b/CAPE/Scylla/ImportRebuilder.cpp index 464913d..c9fd324 100644 --- a/CAPE/Scylla/ImportRebuilder.cpp +++ b/CAPE/Scylla/ImportRebuilder.cpp @@ -17,7 +17,7 @@ New Scylla section contains: extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList) +bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList, BOOL CapeFile) { bool retValue = false; @@ -52,7 +52,7 @@ bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList) +{ + return rebuildImportTable(newFilePath, moduleList, TRUE); +} + bool ImportRebuilder::buildNewImportTable(std::map & moduleList) { createNewImportSection(moduleList); diff --git a/CAPE/Scylla/ImportRebuilder.h b/CAPE/Scylla/ImportRebuilder.h index e9806ec..034de02 100644 --- a/CAPE/Scylla/ImportRebuilder.h +++ b/CAPE/Scylla/ImportRebuilder.h @@ -42,6 +42,7 @@ class ImportRebuilder : public PeParser { sizeOfJumpTable = 0; } + bool rebuildImportTable(const CHAR * newFilePath, std::map & moduleList, BOOL CapeFile); bool rebuildImportTable(const CHAR * newFilePath, std::map & moduleList); void enableOFTSupport(); void enableNewIatInSection(DWORD_PTR iatAddress, DWORD iatSize); diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 079ea8d..95d8422 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -1,4 +1,3 @@ - #include "PeParser.h" #include "ProcessAccessHelp.h" #include @@ -9,8 +8,9 @@ extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern "C" void CapeOutputFile(LPCTSTR lpOutputFile); +extern "C" void ProcessDumpOutputFile(LPCTSTR lpOutputFile); -char ScyllaOutputPath[MAX_PATH]; +char CapeOutputPath[MAX_PATH]; PeParser::PeParser() { @@ -517,7 +517,7 @@ bool PeParser::openWriteFileHandle( const CHAR * newFile ) else { // If no name was specified, let's give it a temporary name to allow it to be renamed later with its hash value - hFile = CreateFile(SCYLLA_OUTPUT_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + hFile = CreateFile(CAPE_OUTPUT_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); } return (hFile != INVALID_HANDLE_VALUE); @@ -662,7 +662,7 @@ DWORD PeParser::isMemoryNotNull( BYTE * data, int dataSize ) return 0; } -bool PeParser::savePeFileToDisk( const CHAR * newFile ) +bool PeParser::savePeFileToDisk(const CHAR *newFile, BOOL CapeFile) { bool retValue = true; char *HashString; @@ -787,36 +787,36 @@ bool PeParser::savePeFileToDisk( const CHAR * newFile ) closeFileHandle(); else { - HashString = GetHashFromHandle(hFile); - closeFileHandle(); - if (!GetFullPathName(SCYLLA_OUTPUT_FILE, MAX_PATH, ScyllaOutputPath, NULL)) + if (!GetFullPathName(CAPE_OUTPUT_FILE, MAX_PATH, CapeOutputPath, NULL)) { DoOutputErrorString("There was a problem obtaining the full file path"); return 0; } - if (MoveFile(ScyllaOutputPath, HashString)) + HashString = GetName(); + + if (MoveFile(CapeOutputPath, HashString)) { - memset(ScyllaOutputPath, 0, MAX_PATH); + memset(CapeOutputPath, 0, MAX_PATH); - if (!GetFullPathName(HashString, MAX_PATH, ScyllaOutputPath, NULL)) + if (!GetFullPathName(HashString, MAX_PATH, CapeOutputPath, NULL)) { DoOutputErrorString("There was a problem obtaining the full file path"); return 0; } - CapeOutputFile(ScyllaOutputPath); + CapeOutputFile(CapeOutputPath); return 1; } else { DoOutputErrorString("There was a problem renaming the file"); - if (!DeleteFile(ScyllaOutputPath)) + if (!DeleteFile(CapeOutputPath)) { - DoOutputErrorString("There was a problem deleting the file: %s", ScyllaOutputPath); + DoOutputErrorString("There was a problem deleting the file: %s", CapeOutputPath); } return 0; @@ -827,6 +827,11 @@ bool PeParser::savePeFileToDisk( const CHAR * newFile ) return retValue; } +bool PeParser::savePeFileToDisk(const CHAR *newFile) +{ + return savePeFileToDisk(newFile, TRUE); +} + bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) { bool retValue = true; @@ -838,6 +843,12 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) return false; } + if (!listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData || !listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData) + { + DoOutputDebugString("PE Parser: Error - image seems incomplete: (%d sections, PointerToRawData: 0x%x, SizeOfRawData: 0x%x) - dump failed.\n", getNumberOfSections(), listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData, listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData); + return false; + } + if (openWriteFileHandle(newFile)) { DoOutputDebugString("Number of sections: %d, PointerToRawData: 0x%x, SizeOfRawData: 0x%x\n", getNumberOfSections(), listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData, listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData); @@ -856,42 +867,42 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) closeFileHandle(); else { - HashString = GetHashFromHandle(hFile); - closeFileHandle(); - if (!GetFullPathName(SCYLLA_OUTPUT_FILE, MAX_PATH, ScyllaOutputPath, NULL)) + if (!GetFullPathName(CAPE_OUTPUT_FILE, MAX_PATH, CapeOutputPath, NULL)) { DoOutputErrorString("There was a problem obtaining the full file path"); return 0; } - if (MoveFile(ScyllaOutputPath, HashString)) + HashString = GetName(); + + if (MoveFile(CapeOutputPath, HashString)) { - memset(ScyllaOutputPath, 0, MAX_PATH); + memset(CapeOutputPath, 0, MAX_PATH); - if (!GetFullPathName(HashString, MAX_PATH, ScyllaOutputPath, NULL)) + if (!GetFullPathName(HashString, MAX_PATH, CapeOutputPath, NULL)) { DoOutputErrorString("There was a problem obtaining the full file path"); return 0; } - CapeOutputFile(ScyllaOutputPath); + CapeOutputFile(CapeOutputPath); return 1; } else { DoOutputErrorString("There was a problem renaming the file"); - if (!DeleteFile(ScyllaOutputPath)) + if (!DeleteFile(CapeOutputPath)) { - DoOutputErrorString("There was a problem deleting the file: %s", ScyllaOutputPath); + DoOutputErrorString("There was a problem deleting the file: %s", CapeOutputPath); } return 0; } } - } + } return retValue; } @@ -1208,6 +1219,27 @@ void PeParser::alignAllSectionHeaders() std::sort(listPeSection.begin(), listPeSection.end(), PeFileSectionSortByVirtualAddress); //sort by VirtualAddress ascending } +bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath, BOOL CapeFile) +{ + moduleBaseAddress = modBase; + + if (readPeSectionsFromProcess()) + { + setDefaultFileAlignment(); + + setEntryPointVa(entryPoint); + + alignAllSectionHeaders(); + fixPeHeader(); + + getFileOverlay(); + + return savePeFileToDisk(dumpFilePath, CapeFile); + } + + return false; +} + bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath) { moduleBaseAddress = modBase; diff --git a/CAPE/Scylla/PeParser.h b/CAPE/Scylla/PeParser.h index fd8ff74..4db23ae 100644 --- a/CAPE/Scylla/PeParser.h +++ b/CAPE/Scylla/PeParser.h @@ -4,9 +4,10 @@ #include //#include "DumpSectionGui.h" -#define SCYLLA_OUTPUT_FILE "ScyllaOutput.bin" +#define CAPE_OUTPUT_FILE "CapeOutput.bin" extern "C" char* GetHashFromHandle(HANDLE hFile); +extern "C" char* GetName(); class PeFileSection { public: @@ -71,12 +72,14 @@ class PeParser bool readPeSectionsFromProcess(); bool readPeSectionsFromFile(); bool savePeFileToDisk(const CHAR * newFile); + bool savePeFileToDisk(const CHAR * newFile, BOOL CapeFile); bool saveCompletePeToDisk(const CHAR * newFile); void removeDosStub(); void alignAllSectionHeaders(); void fixPeHeader(); void setDefaultFileAlignment(); bool dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath); + bool dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath, BOOL CapeFile); bool dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath, std::vector & sectionList); void setEntryPointVa(DWORD_PTR entryPoint); @@ -124,6 +127,7 @@ class PeParser BYTE * headerMemory; HANDLE hFile; + HANDLE hInfoFile; DWORD fileSize; bool readPeHeaderFromFile(bool readSectionHeaders); diff --git a/CAPE/Scylla/ProcessAccessHelp.cpp b/CAPE/Scylla/ProcessAccessHelp.cpp index 6bc7680..9efa57f 100644 --- a/CAPE/Scylla/ProcessAccessHelp.cpp +++ b/CAPE/Scylla/ProcessAccessHelp.cpp @@ -83,7 +83,7 @@ HANDLE ProcessAccessHelp::NativeOpenProcess(DWORD dwDesiredAccess, DWORD dwProce NTSTATUS ntStatus = 0; InitializeObjectAttributes(&ObjectAttributes, 0, 0, 0, 0); - cid.UniqueProcess = (HANDLE)dwProcessId; + cid.UniqueProcess = (HANDLE)(UINT_PTR)dwProcessId; ntStatus = NativeWinApi::NtOpenProcess(&hProcess,dwDesiredAccess,&ObjectAttributes, &cid); diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index de54560..6257375 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -22,6 +22,8 @@ along with this program.If not, see . #include "Scylla\ImportRebuilder.h" #include "Scylla\ImportsHandling.h" +typedef unsigned __int64 QWORD; + #define USE_PE_HEADER_FROM_DISK FALSE #define SCAN_DIRECT_IMPORTS FALSE #define FIX_DIRECT_IMPORTS_NORMAL FALSE @@ -29,11 +31,11 @@ along with this program.If not, see . #define CREATE_NEW_IAT_IN_SECTION FALSE #define OFT_SUPPORT FALSE -#define SCYLLA_OUTPUT_FILE "ScyllaOutput.bin" +#define CAPE_OUTPUT_FILE "CapeOutput.bin" extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -extern char ScyllaOutputPath[MAX_PATH]; +extern char CapeOutputPath[MAX_PATH]; //************************************************************************************** void ScyllaInitCurrentProcess() @@ -49,30 +51,30 @@ void ScyllaInitCurrentProcess() } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) +extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP, BOOL CapeFile) //************************************************************************************** { DWORD_PTR entrypoint = 0; PeParser * peFile = 0; - void* modBase; + DWORD modBase; - modBase = GetModuleHandle(NULL); + modBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); ScyllaInitCurrentProcess(); DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); - peFile = new PeParser((DWORD_PTR)modBase, TRUE); + peFile = new PeParser(modBase, TRUE); if (peFile->isValidPeFile()) { if (NewOEP) entrypoint = NewOEP; else - entrypoint = peFile->getEntryPoint() + (DWORD)modBase; - + entrypoint = peFile->getEntryPoint() + modBase; + DoOutputDebugString("Module entry point VA is 0x%x", entrypoint); - if (peFile->dumpProcess((DWORD_PTR)modBase, entrypoint, NULL)) + if (peFile->dumpProcess(modBase, entrypoint, NULL)) { DoOutputDebugString("Module image dump success.\n"); } @@ -109,7 +111,7 @@ void ScyllaInit(HANDLE hProcess) } //************************************************************************************** -extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) +extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP, BOOL CapeFile) //************************************************************************************** { DWORD_PTR entrypoint = 0; @@ -119,7 +121,7 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOE DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); - peFile = new PeParser((DWORD_PTR)modBase, TRUE); + peFile = new PeParser(modBase, TRUE); if (peFile->isValidPeFile()) { @@ -127,11 +129,11 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOE entrypoint = NewOEP; else entrypoint = peFile->getEntryPoint(); - entrypoint = entrypoint + (DWORD)modBase; + entrypoint = entrypoint + modBase; DoOutputDebugString("Module entry point VA is 0x%x", entrypoint); - if (peFile->dumpProcess((DWORD_PTR)modBase, entrypoint, NULL)) + if (peFile->dumpProcess(modBase, entrypoint, NULL)) { DoOutputDebugString("Module image dump success"); } @@ -222,12 +224,13 @@ bool isIATOutsidePeImage (DWORD_PTR addressIAT) } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) +extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP, BOOL CapeFile) //************************************************************************************** { DWORD addressIAT, sizeIAT; BOOL IAT_Found, AdvancedIATSearch = FALSE; bool isAfter; + DWORD modBase; IATSearch iatSearch; ApiReader apiReader; @@ -237,7 +240,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) DWORD_PTR entrypointRVA = 0; PeParser * peFile = 0; - void* modBase = GetModuleHandle(NULL); + modBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); //Clear stuff first ProcessAccessHelp::ownModuleList.clear(); @@ -251,7 +254,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) ProcessAccessHelp::getProcessModules(ProcessAccessHelp::hProcess, ProcessAccessHelp::ownModuleList); ProcessAccessHelp::moduleList = ProcessAccessHelp::ownModuleList; - ProcessAccessHelp::targetImageBase = (DWORD_PTR)modBase; + ProcessAccessHelp::targetImageBase = modBase; ProcessAccessHelp::getSizeOfImageCurrentProcess(); // Enumerate DLLs and imported functions @@ -259,29 +262,29 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); - peFile = new PeParser((DWORD_PTR)modBase, TRUE); + peFile = new PeParser(modBase, TRUE); if (peFile->isValidPeFile()) { if (NewOEP) - entrypointRVA = NewOEP - (DWORD)modBase; + entrypointRVA = NewOEP - modBase; else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString("Module entry point VA is 0x%x", (DWORD)modBase + entrypointRVA); + DoOutputDebugString("Module entry point VA is 0x%x", modBase + entrypointRVA); // Let's dump then fix the dump on disk - if (peFile->dumpProcess((DWORD_PTR)modBase, (DWORD)modBase + entrypointRVA, SCYLLA_OUTPUT_FILE)) + if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE)) { - DoOutputDebugString("Module image dump success %s", ScyllaOutputPath); + DoOutputDebugString("Module image dump success %s", CapeOutputPath); } // IAT search - we'll try the simple search first - IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, FALSE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, FALSE); // Let's try the advanced search now if (IAT_Found == FALSE) - IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, TRUE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, TRUE); if (addressIAT && sizeIAT) { @@ -334,7 +337,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) DoOutputDebugString("Warning, IAT is not inside the PE image, requires rebasing."); } - ImportRebuilder importRebuild(SCYLLA_OUTPUT_FILE); + ImportRebuilder importRebuild(CAPE_OUTPUT_FILE); if (OFT_SUPPORT) { @@ -388,7 +391,9 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) return 1; } -extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) +//************************************************************************************** +extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP, BOOL CapeFile) +//************************************************************************************** { BOOL isAfter; DWORD sizeIAT; @@ -412,7 +417,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D ProcessAccessHelp::ownModuleList.clear(); ProcessAccessHelp::hProcess = hProcess; ProcessAccessHelp::getProcessModules(ProcessAccessHelp::hProcess, ProcessAccessHelp::moduleList); - ProcessAccessHelp::targetImageBase = (DWORD_PTR)modBase; + ProcessAccessHelp::targetImageBase = modBase; //ProcessAccessHelp::moduleList = ProcessAccessHelp::ownModuleList; //ProcessAccessHelp::getSizeOfImageCurrentProcess(); @@ -421,30 +426,29 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D DoOutputDebugString(TEXT("Instantiating PeParser with address: 0x%x"), modBase); - peFile = new PeParser((DWORD_PTR)modBase, true); + peFile = new PeParser(modBase, true); if (peFile->isValidPeFile()) { if (NewOEP) - entrypointRVA = NewOEP - (DWORD)modBase; + entrypointRVA = NewOEP - modBase; else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString(TEXT("Module entry point VA is 0x%x"), (DWORD)modBase + entrypointRVA); + DoOutputDebugString(TEXT("Module entry point VA is 0x%x"), modBase + entrypointRVA); - // Let's try dumping then fixing the dump - // We can maybe then try doing it all in memory if this works - if (peFile->dumpProcess((DWORD_PTR)modBase, (DWORD)modBase + entrypointRVA, SCYLLA_OUTPUT_FILE)) + // Let's dump then fix the dump on disk + if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE, CapeFile)) { - DoOutputDebugString("Module image dump success %s", ScyllaOutputPath); + DoOutputDebugString("Module image dump success %s", CapeOutputPath); } // We'll try the simple search first - IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, &addressIAT, &sizeIAT, FALSE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, &addressIAT, &sizeIAT, FALSE); // Let's try the advanced search now if (IAT_Found == FALSE) - IAT_Found = iatSearch.searchImportAddressTableInProcess((DWORD)modBase + entrypointRVA, &addressIAT, &sizeIAT, TRUE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, &addressIAT, &sizeIAT, TRUE); if (addressIAT && sizeIAT) { @@ -475,28 +479,33 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D iatReferenceScan.printDirectImportLog(); - if (FIX_DIRECT_IMPORTS_NORMAL && FIX_DIRECT_IMPORTS_UNIVERSAL) + if (FIX_DIRECT_IMPORTS_NORMAL) { - //"Direct Imports found. I can patch only direct imports by JMP/CALL (use universal method if you don't like this) but where is the junk byte?\r\n\r\nYES = After Instruction\r\nNO = Before the Instruction\r\nCancel = Do nothing", L"Information", MB_YESNOCANCEL|MB_ICONINFORMATION); - - isAfter = false; - isAfter = true; + // From the Scylla source: + // "Direct Imports found. I can patch only direct imports by JMP/CALL + // (use universal method if you don't like this) + // but where is the junk byte?\r\n\r\nYES = After Instruction\r\nNO = + // Before the Instruction\r\nCancel = Do nothing", L"Information", MB_YESNOCANCEL|MB_ICONINFORMATION); + + // This hasn't yet been tested! + isAfter = 1; iatReferenceScan.patchDirectImportsMemory(isAfter); - DoOutputDebugString("DIRECT IMPORTS - Patched! Please dump target."); + DoOutputDebugString("Direct imports patched."); } } } if (isIATOutsidePeImage(addressIAT)) { - DoOutputDebugString("WARNING! IAT is not inside the PE image, requires rebasing!"); + DoOutputDebugString("WARNING! IAT is not inside the PE image, requires rebasing."); } - ImportRebuilder importRebuild(SCYLLA_OUTPUT_FILE); + ImportRebuilder importRebuild(CAPE_OUTPUT_FILE); if (OFT_SUPPORT) { + // Untested importRebuild.enableOFTSupport(); DoOutputDebugString("importRebuild: OFT support enabled.\n"); } @@ -505,9 +514,9 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D { if (iatReferenceScan.numberOfFoundDirectImports() > 0) { + // Untested importRebuild.iatReferenceScan = &iatReferenceScan; - importRebuild.BuildDirectImportsJumpTable = true; - DoOutputDebugString("importRebuild: iatReferenceScan: 0x%x, BuildDirectImportsJumpTable true.\n", importRebuild.iatReferenceScan); + importRebuild.BuildDirectImportsJumpTable = TRUE; } } @@ -515,21 +524,19 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D { importRebuild.iatReferenceScan = &iatReferenceScan; importRebuild.enableNewIatInSection(addressIAT, sizeIAT); - DoOutputDebugString("importRebuild: new IAT to be created.\n"); } - - DoOutputDebugString("About to rebuild import table.\n"); - if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList)) + if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList, CapeFile)) { - DoOutputDebugString("Import Rebuild success.\n"); + DoOutputDebugString("Import table rebuild success.\n"); delete peFile; return 1; } else { - DoOutputDebugString("Import Rebuild failed.\n"); - } + DoOutputDebugString("Import table rebuild failed, falling back to unfixed dump.\n"); + peFile->savePeFileToDisk(NULL, CapeFile); + } } else { diff --git a/config.c b/config.c index 7130d0f..db55fd6 100644 --- a/config.c +++ b/config.c @@ -23,6 +23,9 @@ along with this program. If not, see . #include "log.h" #include "hooking.h" +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void* CAPE_var; + int read_config(void) { // TODO unicode support @@ -47,6 +50,7 @@ int read_config(void) #else g_config.hook_type = HOOK_HOTPATCH_JMP_INDIRECT; #endif + g_config.procmemdump = 0; memset(buf, 0, sizeof(buf)); while (fgets(buf, sizeof(buf), fp) != NULL) @@ -214,6 +218,25 @@ int read_config(void) p = p2 + 1; } } + else if (!strcmp(key, "breakpoint")) { + CAPE_var = (void*)strtoul(value, NULL, 10); + DoOutputDebugString("CAPE_var set to 0x%x", CAPE_var); + } + else if (!strcmp(key, "procmemdump")) { + g_config.procmemdump = value[0] == '1'; + if (g_config.procmemdump) + DoOutputDebugString("Process memory dumps enabled.\n"); + else + DoOutputDebugString("Process memory dumps disabled.\n"); + } + else if (!strcmp(key, "import_reconstruction")) { + g_config.import_reconstruction = value[0] == '1'; + if (g_config.import_reconstruction) + DoOutputDebugString("Import reconstruction of process dumps enabled.\n"); + else + DoOutputDebugString("Import reconstruction of process dumps disabled.\n"); + } + } } diff --git a/config.h b/config.h index 931bf76..b92e851 100644 --- a/config.h +++ b/config.h @@ -104,6 +104,12 @@ struct _g_config { char *excluded_apinames[EXCLUSION_MAX]; wchar_t *excluded_dllnames[EXCLUSION_MAX]; + + // should we dump each process on exit/analysis timeout? + int procmemdump; + + // should we attempt import reconstruction on each process dump? (slow) + int import_reconstruction; }; extern struct _g_config g_config; diff --git a/hook_process.c b/hook_process.c index d57632e..47218b7 100644 --- a/hook_process.c +++ b/hook_process.c @@ -277,8 +277,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, // although the documentation on msdn is a bit vague, this seems correct // for both XP and Vista (the ClientId->UniqueProcess part, that is) - int pid = 0; NTSTATUS ret; + struct InjectionInfo *CurrentInjectionInfo; + + int pid = 0; if(ClientId != NULL) { __try { @@ -300,11 +302,26 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, ObjectAttributes, ClientId); if (NT_SUCCESS(ret) && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ - RunPE_Handle = ProcessHandle; - RunPE_ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); - RunPE_EntryPoint = (DWORD)NULL; - RunPE_ImageDumped = FALSE; - DoOutputDebugString("NtOpenProcess: Open process handle set: 0x%x, ImageBase: 0x%x, DesiredAccess: 0x%x", RunPE_Handle, RunPE_ImageBase, DesiredAccess); + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo == NULL) + { // First call for this process, create new info + CurrentInjectionInfo = CreateInjectionInfo(pid); + DoOutputDebugString("NtOpenProcess: Injection info created for pid 0x%x.\n", pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("NtOpenProcess: Cannot create new injection info - FATAL ERROR.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = ProcessHandle; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + } + } + // else... Some samples call this multiple times for the same process, we can ignore } LOQ_ntstatus("process", "Phi", "ProcessHandle", ProcessHandle, @@ -318,16 +335,29 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, __in HANDLE ProcessHandle ) { NTSTATUS ret; - DWORD pid = pid_from_process_handle(ProcessHandle); + struct InjectionInfo *CurrentInjectionInfo; + + DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); - if (RunPE_Handle && RunPE_ImageBase && RunPE_ProcessWriteDetected) + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo && CurrentInjectionInfo->ImageBase) { - if (RunPE_ImageDumped == FALSE) + if (CurrentInjectionInfo->ImageDumped == FALSE) { - DoOutputDebugString("Dumping RunPE process image, handle 0x%x, image base 0x%x.", RunPE_Handle, RunPE_ImageBase); - DumpProcess(RunPE_Handle, RunPE_ImageBase); - RunPE_ImageDumped = TRUE; + DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); + SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); + CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtResumeProcess hook: Dumped PE image from buffer.\n"); + CurrentInjectionInfo->ImageBase = 0; + CurrentInjectionInfo->EntryPoint = 0; + } + else + DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); } } @@ -472,12 +502,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); - - if (RunPE_Handle && (ProcessHandle == RunPE_Handle)) - { - RunPE_ProcessWriteDetected = TRUE; - } - + if ((pid != GetCurrentProcessId()) || Win32Protect != PAGE_READWRITE) LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, @@ -540,7 +565,6 @@ HOOKDEF(BOOL, WINAPI, ReadProcessMemory, _In_ SIZE_T nSize, _Out_ PSIZE_T lpNumberOfBytesRead ) { - //long e_lfanew; BOOL ret; ENSURE_SIZET(lpNumberOfBytesRead); @@ -564,46 +588,90 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, ) { NTSTATUS ret; DWORD pid; - long e_lfanew; + struct InjectionInfo *CurrentInjectionInfo; + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; ENSURE_SIZET(NumberOfBytesWritten); ret = Old_NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten); - if (NT_SUCCESS(ret) && *NumberOfBytesWritten > 0) + pid = pid_from_process_handle(ProcessHandle); + + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { - // Check if we have a valid DOS and PE header at the beginning of Buffer - if (*(WORD*)Buffer == IMAGE_DOS_SIGNATURE) + if (NT_SUCCESS(ret) && *NumberOfBytesWritten > 0) { - DoOutputDebugString("Executable binary detected in NtWriteVirtualMemory buffer."); - - e_lfanew = *(long*)((unsigned char*)Buffer+0x3c); - - if ((unsigned int)e_lfanew>PE_HEADER_LIMIT) + // Check if we have a valid DOS and PE header at the beginning of Buffer + if (*(WORD*)Buffer == IMAGE_DOS_SIGNATURE) { - // This check is possibly not appropriate here - // As long as we've got what's been compressed - } + pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer); - if (*(DWORD*)((unsigned char*)Buffer+e_lfanew) == IMAGE_NT_SIGNATURE) - { - RunPE_ImageBase = (DWORD_PTR)BaseAddress; - DoOutputDebugString("RunPE ImageBase reset to: 0x%x (process handle: 0x%x)", RunPE_ImageBase, RunPE_Handle); - - DoOutputDebugString("About to attempt to dump PE from memory."); - if (DumpPE(Buffer)) - RunPE_ImageDumped = TRUE; + if (pDosHeader->e_lfanew && (unsigned int)pDosHeader->e_lfanew < PE_HEADER_LIMIT) + pNtHeader = (PIMAGE_NT_HEADERS)((char*)Buffer + pDosHeader->e_lfanew); + + if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) + { + CurrentInjectionInfo->ImageBase = (DWORD_PTR)BaseAddress; + DoOutputDebugString("NtWriteVirtualMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); + CurrentInjectionInfo->ImageDumped = DumpPE(Buffer); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtWriteVirtualMemory hook: Dumped PE image from buffer.\n"); + CurrentInjectionInfo->BufferBase = Buffer; + CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; + } + else + DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump PE image from buffer.\n"); + } + } + else + { + DoOutputDebugString("NtWriteVirtualMemory hook: invalid PE file in buffer, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = pid; + if (DumpMemory(Buffer, *NumberOfBytesWritten)) + DoOutputDebugString("NtWriteVirtualMemory hook: Dumped malformed PE image from buffer."); + else + DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump malformed PE image from buffer."); + } + } + else + { + if (*NumberOfBytesWritten > 0x10) + { + if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && + Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) + { + // Looks like a previously dumped PE image is being written a section at a time to the target process. + // We don't want to dump these writes. + DoOutputDebugString("NtWriteVirtualMemory hook: injection of section of PE image which has already been dumped.\n"); + } + else + { + DoOutputDebugString("NtWriteVirtualMemory hook: Shellcode injected into process %d.\n", pid); + + // dump injected code to .bin file + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = pid; + if (DumpMemory(Buffer, *NumberOfBytesWritten)) + DoOutputDebugString("NtWriteVirtualMemory hook: Dumped injected code from buffer."); + else + DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump injected code from buffer."); + } + } } } - } - - if (RunPE_Handle && (ProcessHandle == RunPE_Handle)) - { - RunPE_ProcessWriteDetected = TRUE; } - pid = pid_from_process_handle(ProcessHandle); - if (pid != GetCurrentProcessId()) { LOQ_ntstatus("process", "ppBhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "Buffer", NumberOfBytesWritten, Buffer, "BufferLength", *NumberOfBytesWritten, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); @@ -626,55 +694,89 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, ) { BOOL ret; DWORD pid; - long e_lfanew; + struct InjectionInfo *CurrentInjectionInfo; + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; ENSURE_SIZET(lpNumberOfBytesWritten); ret = Old_WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); - if (hProcess == RunPE_Handle && ret != 0 && *lpNumberOfBytesWritten > 0) + pid = pid_from_process_handle(hProcess); + + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { - // Check if we have a valid DOS and PE header at the beginning of lpBuffer - if (*(WORD*)lpBuffer == IMAGE_DOS_SIGNATURE) + if (NT_SUCCESS(ret) && *lpNumberOfBytesWritten > 0) { - DoOutputDebugString("Executable binary detected in WriteProcessMemory buffer."); - - e_lfanew = *(long*)((unsigned char*)lpBuffer+0x3c); - - if ((unsigned int)e_lfanew>PE_HEADER_LIMIT) + // Check if we have a valid DOS and PE header at the beginning of Buffer + if (*(WORD*)lpBuffer == IMAGE_DOS_SIGNATURE) { - // This check is possibly not appropriate here - // As long as we've got what's been compressed - } + pDosHeader = (PIMAGE_DOS_HEADER)((char*)lpBuffer); - if (*(DWORD*)((unsigned char*)lpBuffer+e_lfanew) == IMAGE_NT_SIGNATURE) - { - RunPE_ImageBase = (DWORD_PTR)lpBaseAddress; - DoOutputDebugString("RunPE ImageBase reset to: 0x%x (process handle: 0x%x)", RunPE_ImageBase, RunPE_Handle); - - DoOutputDebugString("About to attempt to dump PE from memory."); - if (DumpPE(lpBuffer)) - RunPE_ImageDumped = TRUE; + if (pDosHeader->e_lfanew && (unsigned int)pDosHeader->e_lfanew < PE_HEADER_LIMIT) + pNtHeader = (PIMAGE_NT_HEADERS)((char*)lpBuffer + pDosHeader->e_lfanew); + + if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) + { + CurrentInjectionInfo->ImageBase = (DWORD_PTR)lpBaseAddress; + DoOutputDebugString("WriteProcessMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); + CurrentInjectionInfo->ImageDumped = DumpPE(lpBuffer); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer.\n"); + CurrentInjectionInfo->BufferBase = lpBuffer; + CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; + } + else + DoOutputDebugString("WriteProcessMemory hook: Failed to dump PE image from buffer.\n"); + } + } + else + { + DoOutputDebugString("WriteProcessMemory hook: invalid PE file in buffer, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = pid; + if (DumpMemory(lpBuffer, *lpNumberOfBytesWritten)) + DoOutputDebugString("WriteProcessMemory hook: Dumped malformed PE image from buffer."); + else + DoOutputDebugString("WriteProcessMemory hook: Failed to dump malformed PE image from buffer."); + } } - } - else - { - if (RunPE_Handle && (hProcess == RunPE_Handle)) - { - RunPE_ProcessWriteDetected = TRUE; + else + { + if (*lpNumberOfBytesWritten > 0x10) + { + if (CurrentInjectionInfo->BufferBase && lpBuffer > CurrentInjectionInfo->BufferBase && + lpBuffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) + { + // Looks like a previously dumped PE image is being written a section at a time to the target process. + // We don't want to dump these writes. + DoOutputDebugString("WriteProcessMemory hook: injection of section of PE image which has already been dumped.\n"); + } + else + { + DoOutputDebugString("WriteProcessMemory hook: Shellcode injected into process %d.\n", pid); + + // dump injected code to .bin file + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = pid; + if (DumpMemory(lpBuffer, *lpNumberOfBytesWritten)) + DoOutputDebugString("WriteProcessMemory hook: Dumped injected code from buffer."); + else + DoOutputDebugString("WriteProcessMemory hook: Failed to dump injected code from buffer."); + } + } } - //else if (*lpNumberOfBytesWritten > 0x10) - //{ - // // dump injected code to .bin file - // if (DumpMemory(lpBuffer, nSize)) - // DoOutputDebugString("Dumped remotely injected code from memory."); - // else - // DoOutputDebugString("Failed to dump remotely injected code from memory."); - //} } - } - - pid = pid_from_process_handle(hProcess); + } if (pid != GetCurrentProcessId()) { LOQ_bool("process", "ppBhs", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, @@ -760,8 +862,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection); /* Don't log an uninteresting case */ - if (OldAccessProtection && *OldAccessProtection == NewAccessProtection) - return ret; + //if (OldAccessProtection && *OldAccessProtection == NewAccessProtection) + // return ret; memset(&meminfo, 0, sizeof(meminfo)); if (NT_SUCCESS(ret)) { @@ -807,8 +909,8 @@ HOOKDEF(BOOL, WINAPI, VirtualProtectEx, lpflOldProtect); /* Don't log an uninteresting case */ - if (lpflOldProtect && *lpflOldProtect == flNewProtect) - return ret; + //if (lpflOldProtect && *lpflOldProtect == flNewProtect) + // return ret; memset(&meminfo, 0, sizeof(meminfo)); if (ret) { diff --git a/hook_special.c b/hook_special.c index 24b51a8..2cea4a4 100644 --- a/hook_special.c +++ b/hook_special.c @@ -133,9 +133,11 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, __in_opt LPVOID lpUnknown2 ) { BOOL ret; + struct InjectionInfo *CurrentInjectionInfo; hook_info_t saved_hookinfo; + WCHAR TargetProcess[MAX_PATH]; - memcpy(&saved_hookinfo, hook_info(), sizeof(saved_hookinfo)); + memcpy(&saved_hookinfo, hook_info(), sizeof(saved_hookinfo)); ret = Old_CreateProcessInternalW(lpUnknown1, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, @@ -157,11 +159,43 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, ResumeThread(lpProcessInformation->hThread); } else if (!called_by_hook()){ - RunPE_Handle = lpProcessInformation->hProcess; - RunPE_ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); - RunPE_EntryPoint = (DWORD)NULL; - RunPE_ImageDumped = FALSE; - DoOutputDebugString("RunPE process handle set: 0x%x, ImageBase: 0x%x", RunPE_Handle, RunPE_ImageBase); + + CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("CreateProcessInternal hook: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + } + else + { + CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); + CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + + CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); + memset(TargetProcess, 0, MAX_PATH*sizeof(WCHAR)); + + if (lpApplicationName) + _snwprintf(TargetProcess, MAX_PATH, L"%s", lpApplicationName); + else if (lpCommandLine) + { + DoOutputDebugString("CreateProcessInternal hook: using lpCommandLine: %ws.\n", lpCommandLine); + if (*lpCommandLine == L'\"') + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); + else + { + if (wcschr(lpCommandLine, ' ')) + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); + else + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); + } + } + + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); + + DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + } } disable_sleep_skip(); diff --git a/hook_thread.c b/hook_thread.c index 1979b56..4c6515b 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -244,21 +244,25 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, __in const CONTEXT *Context ) { NTSTATUS ret; + struct InjectionInfo *CurrentInjectionInfo; DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); ret = Old_NtSetContextThread(ThreadHandle, Context); - if (RunPE_Handle && RunPE_ImageBase) + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { #ifdef _WIN64 - RunPE_EntryPoint = Context->Rax - RunPE_ImageBase; + CurrentInjectionInfo->EntryPoint = Context->Rax - CurrentInjectionInfo->ImageBase; #else - RunPE_EntryPoint = Context->Eax - RunPE_ImageBase; + CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; #endif - DoOutputDebugString("Set RunPE entry point via NtSetContextThread: 0x%x", RunPE_EntryPoint); + DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } + if (Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); @@ -302,19 +306,34 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, __in HANDLE ThreadHandle, __out_opt ULONG *SuspendCount ) { + struct InjectionInfo *CurrentInjectionInfo; DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; ENSURE_ULONG(SuspendCount); pipe("RESUME:%d,%d", pid, tid); - if (RunPE_Handle && RunPE_ImageBase && RunPE_ProcessWriteDetected) + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { - if (RunPE_ImageDumped == FALSE) + if (CurrentInjectionInfo->ProcessHandle && CurrentInjectionInfo->ImageBase) { - DoOutputDebugString("Dumping RunPE process image, handle 0x%x, image base 0x%x.", RunPE_Handle, RunPE_ImageBase); - DumpProcess(RunPE_Handle, RunPE_ImageBase); - RunPE_ImageDumped = TRUE; + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + DoOutputDebugString("NtResumeThread hook: Dumping hollowed process image, process %d 0x%x, image base 0x%x.", pid, CurrentInjectionInfo->ImageBase); + SetCapeMetaData(INJECTION_PE, pid, CurrentInjectionInfo->ProcessHandle, NULL); + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); + CurrentInjectionInfo->ImageBase = 0; + CurrentInjectionInfo->EntryPoint = 0; + } + else + DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); + } } } diff --git a/misc.c b/misc.c index f352387..f0b05d7 100644 --- a/misc.c +++ b/misc.c @@ -594,7 +594,7 @@ BOOL is_in_dll_range(ULONG_PTR addr) return FALSE; } -static ULONG_PTR base_of_dll_of_interest; +ULONG_PTR base_of_dll_of_interest; void set_dll_of_interest(ULONG_PTR BaseAddress) { From 0ca3dfce69c4a7b870c94283b654fc62e672f7de Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Nov 2016 11:02:46 +0000 Subject: [PATCH 03/39] Bugfix for x64 process hollowing. --- hook_thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hook_thread.c b/hook_thread.c index 4c6515b..79f91e5 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -256,9 +256,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { #ifdef _WIN64 - CurrentInjectionInfo->EntryPoint = Context->Rax - CurrentInjectionInfo->ImageBase; + CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds rip on 64-bit #else - CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; + CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds eip on 32-bit #endif DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } From f739ef25daf198be28e825837e790ab763514fe9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Dec 2016 16:43:55 +0000 Subject: [PATCH 04/39] Improved handling of section view-based process hollowing. --- CAPE/CAPE.c | 239 ++++++++++++++++++++++++++++++++++++++----------- CAPE/CAPE.h | 36 ++++++-- hook_process.c | 132 +++++++++++++++++++++++---- hook_thread.c | 82 ++++++++++++++--- 4 files changed, 399 insertions(+), 90 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index af189af..ba597ac 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -246,18 +246,8 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) while (CurrentInjectionInfo) { - //if (CurrentInjectionInfo->ProcessId && CurrentInjectionInfo->ProcessId == ProcessId) - //{ - // //It already exists - shouldn't happen - // DoOutputDebugString("CreateInjectionInfo error: found an existing injection info struct for ProcessId 0x%x\n", ProcessId); - // return NULL; - //} - if ((CurrentInjectionInfo->ProcessId) == ProcessId) - { - // We have our injection info struct break; - } PreviousInjectionInfo = CurrentInjectionInfo; CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; @@ -284,6 +274,122 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) return CurrentInjectionInfo; } +//************************************************************************************** +PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + + DoOutputDebugString("GetSectionView: Global section view list 0x%x, looking for handle 0x%x\n", CurrentSectionView, SectionHandle); + + while (CurrentSectionView) + { + DoOutputDebugString("GetSectionView: looking at section handle 0x%x.\n", CurrentSectionView->SectionHandle); + if (CurrentSectionView->SectionHandle == SectionHandle) + { + DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); + return CurrentSectionView; + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + return NULL; +} + +//************************************************************************************** +PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; + + PreviousSectionView = NULL; + + if (SectionViewList == NULL) + { + SectionViewList = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); + + if (SectionViewList == NULL) + { + DoOutputDebugString("InjectionAddSectionView: failed to allocate memory for initial section view list.\n"); + return NULL; + } + + memset(SectionViewList, 0, sizeof(struct InjectionSectionView)); + + SectionViewList->SectionHandle = SectionHandle; + SectionViewList->LocalView = LocalView; + SectionViewList->ViewSize = ViewSize; + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if ((CurrentSectionView->SectionHandle) == SectionHandle) + break; + + PreviousSectionView = CurrentSectionView; + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (!CurrentSectionView) + { + // We haven't found it in the linked list, so create a new one + CurrentSectionView = PreviousSectionView; + + CurrentSectionView->NextSectionView = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); + + if (CurrentSectionView->NextSectionView == NULL) + { + DoOutputDebugString("CreateSectionView: Failed to allocate new injection sectionview structure.\n"); + return NULL; + } + + memset(CurrentSectionView->NextSectionView, 0, sizeof(struct InjectionSectionView)); + + CurrentSectionView = CurrentSectionView->NextSectionView; + CurrentSectionView->SectionHandle = SectionHandle; + CurrentSectionView->LocalView = LocalView; + CurrentSectionView->ViewSize = ViewSize; + } + + return CurrentSectionView; +} + +//************************************************************************************** +BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; + + PreviousSectionView = NULL; + + if (SectionViewList == NULL) + { + DoOutputDebugString("DropSectionView: failed to obtain initial section view list.\n"); + return FALSE; + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView == SectionView) + { + // Unlink this from the list and free the memory + PreviousSectionView->NextSectionView = CurrentSectionView->NextSectionView; + free(CurrentSectionView); + return TRUE; + } + + PreviousSectionView = CurrentSectionView; + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + return FALSE; +} + //************************************************************************************** char* GetName() //************************************************************************************** @@ -677,9 +783,17 @@ int ScanForNonZero(LPCVOID Buffer, unsigned int Size) { unsigned int p; - for (p=0; pe_lfanew == 0) + __try + { + if (*((char*)Buffer+p) == 'M' && *((char*)Buffer+p+1) == 'Z') { - // e_lfanew is zero - continue; - } + DoOutputDebugString("ScanForPE: MZ detected at 0x%x\n", p); + + pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer+p); - if ((ULONG)pDosHeader->e_lfanew > Size-p) - { - // e_lfanew points beyond end of region - continue; - } - - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - - if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) - { - // No 'PE' header - continue; - } - - if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0)) - { - // Basic requirements - DoOutputDebugString("ScanForPE: Basic requirements failure.\n"); - continue; - } - - if (Offset) - { - *Offset = (LPCVOID)((char*)Buffer+p); + if ((ULONG)pDosHeader->e_lfanew == 0) + { + // e_lfanew is zero + continue; + } + + //if ((ULONG)pDosHeader->e_lfanew > Size-p) + //{ + // // e_lfanew points beyond end of region + // continue; + //} + + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) + { + // No 'PE' header + continue; + } + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + { + // Basic requirements + DoOutputDebugString("ScanForPE: Basic requirements failure.\n"); + continue; + } + + if (Offset) + { + *Offset = (LPCVOID)((char*)Buffer+p); + } + + DoOutputDebugString("ScanForPE: PE image located at: 0x%x\n", p); + + return 1; } - - DoOutputDebugString("ScanForPE: success!\n"); - - return 1; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); + return 0; } } + DoOutputDebugString("ScanForPE: No PE image located\n"); return 0; } @@ -819,7 +946,15 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) return FALSE; } - memcpy(BufferCopy, Buffer, Size); + __try + { + memcpy(BufferCopy, Buffer, Size); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("DumpMemory: Exception occured reading memory address 0x%x\n", Buffer); + return 0; + } if (FALSE == WriteFile(hOutputFile, BufferCopy, Size, &dwBytesWritten, NULL)) { @@ -936,8 +1071,8 @@ int DumpImageInCurrentProcess(DWORD ImageBase) // first we check if the SizeOfHeaders is a multiple of FileAlignment if (pNtHeader->OptionalHeader.SizeOfHeaders % pNtHeader->OptionalHeader.FileAlignment // let's also check if section 1 actually begins after the headers, i.e. raw image - || (*((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders - 1) == 0 // end of header is zero - && *((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders) != 0)) // beginning of raw section 1 is non-zero + || (*(DWORD*)((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders - 4) == 0) // end of header is zero + && (*(DWORD*)((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders) != 0)) // beginning of raw section 1 is non-zero { // looks like a 'raw'/'file' image, i.e. not loaded if (ScyllaDumpPE(ImageBase)) diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 6ee2aa5..2b1403a 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -11,16 +11,28 @@ unsigned int DumpSize; //Global switch for debugger #define DEBUGGER_ENABLED 0 +typedef struct InjectionSectionView +{ + HANDLE SectionHandle; + PVOID LocalView; + SIZE_T ViewSize; + int TargetProcessId; + struct InjectionSectionView *NextSectionView; +} INJECTIONSECTIONVIEW, *PINJECTIONSECTIONVIEW; + typedef struct InjectionInfo { - int ProcessId; - HANDLE ProcessHandle; - DWORD_PTR ImageBase; - DWORD_PTR EntryPoint; - BOOL ImageDumped; - LPCVOID BufferBase; - unsigned int BufferSizeOfImage; - struct InjectionInfo *NextInjectionInfo; + int ProcessId; + HANDLE ProcessHandle; + DWORD_PTR ImageBase; + DWORD_PTR EntryPoint; + BOOL WriteDetected; + BOOL ImageDumped; + LPCVOID BufferBase; + unsigned int BufferSizeOfImage; + HANDLE SectionHandle; +// struct InjectionSectionView *SectionViewList; + struct InjectionInfo *NextInjectionInfo; } INJECTIONINFO, *PINJECTIONINFO; struct InjectionInfo *InjectionInfoList; @@ -28,6 +40,8 @@ struct InjectionInfo *InjectionInfoList; PINJECTIONINFO GetInjectionInfo(DWORD ProcessId); PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId); +struct InjectionSectionView *SectionViewList; + // // MessageId: STATUS_SUCCESS // @@ -89,4 +103,8 @@ enum { PLUGX_PAYLOAD = 0x10, PLUGX_CONFIG = 0x11 -}; \ No newline at end of file +}; + +PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); +PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); +BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); diff --git a/hook_process.c b/hook_process.c index 47218b7..1136d37 100644 --- a/hook_process.c +++ b/hook_process.c @@ -31,6 +31,8 @@ along with this program. If not, see . extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern int DumpMemory(LPCVOID Buffer, unsigned int Size); +extern int DumpImageInCurrentProcess(DWORD ImageBase); +extern int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -336,30 +338,82 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, ) { NTSTATUS ret; struct InjectionInfo *CurrentInjectionInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); CurrentInjectionInfo = GetInjectionInfo(pid); - if (CurrentInjectionInfo && CurrentInjectionInfo->ImageBase) + if (CurrentInjectionInfo && (CurrentInjectionInfo->WriteDetected)) { if (CurrentInjectionInfo->ImageDumped == FALSE) { - DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); + + DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); + CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped) { DoOutputDebugString("NtResumeProcess hook: Dumped PE image from buffer.\n"); - CurrentInjectionInfo->ImageBase = 0; - CurrentInjectionInfo->EntryPoint = 0; } else DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); } } + else if (CurrentInjectionInfo) + { + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId == pid) + { + if (CurrentSectionView->LocalView) + { + if (ScanForPE(CurrentSectionView->LocalView, 1, NULL)) + { + DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d (by section view), local view at 0x%x.\n", pid, CurrentSectionView->LocalView); + + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); + + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(CurrentSectionView->LocalView); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtResumeProcess hook: Dumped PE image from buffer.\n"); + DropSectionView(CurrentSectionView); + } + else + DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); + } + } + else + { + DoOutputDebugString("NtResumeProcess hook: invalid PE file in buffer, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = pid; + + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) + { + DoOutputDebugString("NtResumeProcess hook: Dumped shared section view."); + DropSectionView(CurrentSectionView); + } + else + DoOutputDebugString("NtResumeProcess hook: Failed to dump shared section view."); + } + } + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + } ret = Old_NtResumeProcess(ProcessHandle); LOQ_ntstatus("process", "p", "ProcessHandle", ProcessHandle); @@ -466,6 +520,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, _In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress ) { + PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; SIZE_T map_size = 0; MEMORY_BASIC_INFORMATION mbi; DWORD pid = pid_from_process_handle(ProcessHandle); DWORD protect = PAGE_READWRITE; @@ -476,12 +531,28 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, map_size = mbi.RegionSize; protect = mbi.Protect; } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->LocalView == BaseAddress) + { + DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view, faking.\n"); + + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "RegionSize", map_size); + + return STATUS_SUCCESS; + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + ret = Old_NtUnmapViewOfSection(ProcessHandle, BaseAddress); - if (pid != GetCurrentProcessId() || protect != PAGE_READWRITE) { - LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "RegionSize", map_size); - } + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "RegionSize", map_size); return ret; } @@ -498,15 +569,40 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, __in ULONG AllocationType, __in ULONG Win32Protect ) { - NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, + struct InjectionInfo *CurrentInjectionInfo; + struct InjectionSectionView *CurrentSectionViewInfo; + + NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); - if ((pid != GetCurrentProcessId()) || Win32Protect != PAGE_READWRITE) - LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, - "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (!CurrentInjectionInfo && pid == GetCurrentProcessId()) + { + AddSectionView(SectionHandle, *BaseAddress, *ViewSize); + DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); + } + else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + { + DoOutputDebugString("NtMapViewOfSection hook: Section view with handle 0x%x and target process %d.\n", SectionHandle, pid); + + CurrentSectionViewInfo = GetSectionView(SectionHandle); + + if (CurrentSectionViewInfo) + { + CurrentSectionViewInfo->TargetProcessId = pid; + DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); + } + else + DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); + + } + + LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, + "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); if (NT_SUCCESS(ret)) { if (pid != GetCurrentProcessId()) { @@ -602,6 +698,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { + CurrentInjectionInfo->WriteDetected = TRUE; + if (NT_SUCCESS(ret) && *NumberOfBytesWritten > 0) { // Check if we have a valid DOS and PE header at the beginning of Buffer @@ -615,12 +713,13 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) { CurrentInjectionInfo->ImageBase = (DWORD_PTR)BaseAddress; + DoOutputDebugString("NtWriteVirtualMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpPE(Buffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(Buffer); if (CurrentInjectionInfo->ImageDumped) { @@ -708,6 +807,8 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { + CurrentInjectionInfo->WriteDetected = TRUE; + if (NT_SUCCESS(ret) && *lpNumberOfBytesWritten > 0) { // Check if we have a valid DOS and PE header at the beginning of Buffer @@ -721,12 +822,13 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) { CurrentInjectionInfo->ImageBase = (DWORD_PTR)lpBaseAddress; + DoOutputDebugString("WriteProcessMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); - CurrentInjectionInfo->ImageDumped = DumpPE(lpBuffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(lpBuffer); if (CurrentInjectionInfo->ImageDumped) { diff --git a/hook_thread.c b/hook_thread.c index 79f91e5..855d0a3 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -28,6 +28,9 @@ along with this program. If not, see . #include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern int DumpMemory(LPCVOID Buffer, unsigned int Size); +extern int DumpImageInCurrentProcess(DWORD ImageBase); +extern int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); static lookup_t g_ignored_threads; @@ -306,7 +309,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, __in HANDLE ThreadHandle, __out_opt ULONG *SuspendCount ) { - struct InjectionInfo *CurrentInjectionInfo; + struct InjectionInfo *CurrentInjectionInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; @@ -315,25 +319,75 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, CurrentInjectionInfo = GetInjectionInfo(pid); - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + if (CurrentInjectionInfo && (CurrentInjectionInfo->WriteDetected)) { - if (CurrentInjectionInfo->ProcessHandle && CurrentInjectionInfo->ImageBase) + if (CurrentInjectionInfo->ImageDumped == FALSE) { - if (CurrentInjectionInfo->ImageDumped == FALSE) - { - DoOutputDebugString("NtResumeThread hook: Dumping hollowed process image, process %d 0x%x, image base 0x%x.", pid, CurrentInjectionInfo->ImageBase); - SetCapeMetaData(INJECTION_PE, pid, CurrentInjectionInfo->ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, CurrentInjectionInfo->ImageBase); + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = pid; + + DoOutputDebugString("NtResumeThread hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); + + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, CurrentInjectionInfo->ImageBase); - if (CurrentInjectionInfo->ImageDumped) + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); + } + else + DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); + } + } + else if (CurrentInjectionInfo) + { + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId == pid) + { + DoOutputDebugString("NtResumeThread hook: Mapped section view in target process %d at 0x%x, about to scan.\n", CurrentSectionView->LocalView); + + if (CurrentSectionView->LocalView) { - DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); - CurrentInjectionInfo->ImageBase = 0; - CurrentInjectionInfo->EntryPoint = 0; + if (ScanForPE(CurrentSectionView->LocalView, CurrentSectionView->ViewSize, NULL)) + { + DoOutputDebugString("NtResumeThread hook: Dumping hollowed process %d (by section view), local view at 0x%x.\n", pid, CurrentSectionView->LocalView); + + CapeMetaData->DumpType = INJECTION_PE; + + CapeMetaData->TargetPid = pid; + + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(CurrentSectionView->LocalView); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); + DropSectionView(CurrentSectionView); + } + else + DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); + } + else + { + DoOutputDebugString("NtResumeThread hook: invalid PE file in buffer, attempting raw dump at 0x%x size 0x%x.\n", CurrentSectionView->LocalView, CurrentSectionView->ViewSize); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = pid; + + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) + { + DoOutputDebugString("NtResumeThread hook: Dumped shared section view."); + DropSectionView(CurrentSectionView); + } + else + DoOutputDebugString("NtResumeThread hook: Failed to dump shared section view."); + } } - else - DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); } + + CurrentSectionView = CurrentSectionView->NextSectionView; } } From d93291b6847bb9836dac4d5714b80761df4012ca Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Feb 2017 15:40:15 +0000 Subject: [PATCH 05/39] Fixed bug in CreateInjectionInfo function. --- CAPE/CAPE.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index ba597ac..79207e5 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -205,7 +205,7 @@ PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) DWORD CurrentProcessId; PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; - + while (CurrentInjectionInfo) { CurrentProcessId = CurrentInjectionInfo->ProcessId; @@ -269,6 +269,8 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) memset(CurrentInjectionInfo->NextInjectionInfo, 0, sizeof(struct InjectionInfo)); CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + + CurrentInjectionInfo->ProcessId = ProcessId; } return CurrentInjectionInfo; From bbedb8d6514f9bb11fd594d6bbe8149907ac3e26 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Feb 2017 14:23:39 +0000 Subject: [PATCH 06/39] Fixed bug with missing metadata from NtOpenProcess. --- CAPE/CAPE.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++- CAPE/CAPE.h | 1 + CAPE/Debugger.h | 1 + CAPE/Output.c | 5 ++-- cuckoomon.c | 9 +++++++ hook_process.c | 27 ++++++++++++++----- 6 files changed, 106 insertions(+), 9 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 79207e5..6faab4c 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -22,7 +22,9 @@ along with this program.If not, see . #include #include #include -#include +#include +#include +#include #include "CAPE.h" #include "Debugger.h" @@ -75,6 +77,62 @@ void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned in return; } +//********************************************************************************************************************************* +BOOL TranslatePathFromDeviceToLetter(__in char *DeviceFilePath, __out char* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize) +//********************************************************************************************************************************* + +{ + char DriveStrings[BUFSIZE]; + DriveStrings[0] = '\0'; + + if (DriveLetterFilePath == NULL || *lpdwBufferSize < MAX_PATH) + { + *lpdwBufferSize = MAX_PATH; + return FALSE; + } + + if (GetLogicalDriveStrings(BUFSIZE-1, DriveStrings)) + { + char DeviceName[MAX_PATH]; + char szDrive[3] = " :"; + BOOL FoundDevice = FALSE; + char* p = DriveStrings; + + do + { + *szDrive = *p; + + if (QueryDosDevice(szDrive, DeviceName, MAX_PATH)) + { + size_t DeviceNameLength = strlen(DeviceName); + + if (DeviceNameLength < MAX_PATH) + { + FoundDevice = _strnicmp(DeviceFilePath, DeviceName, DeviceNameLength) == 0; + + if (FoundDevice && *(DeviceFilePath + DeviceNameLength) == ('\\')) + { + // Construct DriveLetterFilePath replacing device path with DOS path + char NewPath[MAX_PATH]; + StringCchPrintf(NewPath, MAX_PATH, TEXT("%s%s"), szDrive, DeviceFilePath+DeviceNameLength); + StringCchCopyN(DriveLetterFilePath, MAX_PATH, NewPath, strlen(NewPath)); + } + } + } + + // Go to the next NULL character. + while (*p++); + } + while (!FoundDevice && *p); // end of string + } + else + { + DoOutputErrorString("TranslatePathFromDeviceToLetter: GetLogicalDriveStrings failed"); + return FALSE; + } + + return TRUE; +} //************************************************************************************** BOOL SetCapeMetaData(DWORD DumpType, DWORD TargetPid, HANDLE hTargetProcess, PVOID Address) @@ -947,6 +1005,9 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) DoOutputDebugString("DumpMemory: Failed to allocate memory for buffer copy.\n"); return FALSE; } + else DoOutputDebugString("DumpMemory: DEBUG: Allocated space for buffer copy at 0x%x size 0x%x.\n", BufferCopy, Size); + + DoOutputDebugString("DumpMemory: DEBUG: About to create copy of buffer 0x%x size 0x%x.\n", Buffer, Size); __try { @@ -1166,6 +1227,15 @@ void init_CAPE() WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); DumpCount = 0; + + // This flag controls whether a dump is automatically + // made at the end of a process' lifetime. + // It is normally only set in the base packages, + // or upon submission. (This overrides submission.) + g_config.procmemdump = 0; + + // Cuckoo debug output level for development (0=none, 2=max) + g_config.debug = 2; #ifndef _WIN64 // Start the debugger thread diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 2b1403a..3922b1b 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -1,6 +1,7 @@ extern HMODULE s_hInst; extern WCHAR s_wzDllPath[MAX_PATH]; extern CHAR s_szDllPath[MAX_PATH]; +BOOL TranslatePathFromDeviceToLetter(__in TCHAR *DeviceFilePath, __out TCHAR* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize); extern int DumpCurrentProcessNewEP(DWORD NewEP); extern int DumpCurrentProcess(); extern int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 89544cc..8963b62 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -36,6 +36,7 @@ typedef BOOL (cdecl *SINGLE_STEP_HANDLER)(struct _EXCEPTION_POINTERS*); extern "C" { #endif +LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); BOOL SetHardwareBreakpoint ( diff --git a/CAPE/Output.c b/CAPE/Output.c index 4ff7297..0145527 100644 --- a/CAPE/Output.c +++ b/CAPE/Output.c @@ -184,7 +184,7 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) Buffer = malloc(BufferSize); CapeMetaData->ModulePath = CapeMetaData->ProcessPath; - + if (CapeMetaData->DumpType == EXTRACTION_PE || CapeMetaData->DumpType == EXTRACTION_SHELLCODE) { // Extraction-specific format @@ -192,8 +192,9 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) } else if (CapeMetaData->DumpType == INJECTION_PE || CapeMetaData->DumpType == INJECTION_SHELLCODE) { + if (CapeMetaData->TargetProcess && CapeMetaData->ProcessPath) // Injection-specific format - _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n%s\n%d\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->TargetProcess, CapeMetaData->TargetPid); + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n%s\n%d\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->TargetProcess, CapeMetaData->TargetPid); } if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) diff --git a/cuckoomon.c b/cuckoomon.c index f69c6e5..45af4a6 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -30,6 +30,8 @@ along with this program. If not, see . #include "config.h" #include "unhook.h" #include "bson.h" +#include "CAPE\CAPE.h" +#include "CAPE\Debugger.h" volatile int dummy_val; @@ -771,6 +773,13 @@ LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *Excepti if (g_config.debug == 1 && ExceptionInfo->ExceptionRecord->ExceptionCode < 0xc0000000) return EXCEPTION_CONTINUE_SEARCH; + if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) + return EXCEPTION_CONTINUE_SEARCH; +#ifndef _WIN64 + if (DEBUGGER_ENABLED && ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) + return CAPEExceptionFilter(ExceptionInfo); +#endif + hook_disable(); get_lasterrors(&lasterror); diff --git a/hook_process.c b/hook_process.c index 1136d37..53e471f 100644 --- a/hook_process.c +++ b/hook_process.c @@ -19,6 +19,7 @@ along with this program. If not, see . #include #include "ntapi.h" #include +#include #include "hooking.h" #include "log.h" #include "pipe.h" @@ -281,8 +282,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, NTSTATUS ret; struct InjectionInfo *CurrentInjectionInfo; - + DWORD BufferSize = MAX_PATH; + char DevicePath[MAX_PATH]; + unsigned int PathLength; int pid = 0; + if(ClientId != NULL) { __try { @@ -317,10 +321,19 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, } else { - CurrentInjectionInfo->ProcessHandle = ProcessHandle; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + CurrentInjectionInfo->ProcessHandle = *ProcessHandle; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); CurrentInjectionInfo->EntryPoint = (DWORD)NULL; CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); + + if (!PathLength) + DoOutputErrorString("NtOpenProcess: Error obtaining target process name"); + + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("NtOpenProcess: Error translating target process path"); } } // else... Some samples call this multiple times for the same process, we can ignore @@ -540,10 +553,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, { DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view, faking.\n"); + ret = STATUS_SUCCESS; + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", map_size); - return STATUS_SUCCESS; + return ret; } CurrentSectionView = CurrentSectionView->NextSectionView; @@ -576,7 +591,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); - +/* CurrentInjectionInfo = GetInjectionInfo(pid); if (!CurrentInjectionInfo && pid == GetCurrentProcessId()) @@ -599,7 +614,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); } - +*/ LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); From 7d39313836e02c28540e828d36b0bb97a63bc174 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Feb 2017 16:42:26 +0000 Subject: [PATCH 07/39] Restored code accidentally left commented out during testing. --- CAPE/CAPE.c | 2 +- hook_process.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 6faab4c..13fbabd 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -996,7 +996,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) dwBytesWritten = 0; - DoOutputDebugString("DumpMemory: CAPE output file succssfully created: %s", FullPathName); + DoOutputDebugString("DumpMemory: CAPE output file successfully created: %s", FullPathName); BufferCopy = (LPVOID)((BYTE*)malloc(Size)); diff --git a/hook_process.c b/hook_process.c index 53e471f..c65f6f7 100644 --- a/hook_process.c +++ b/hook_process.c @@ -591,7 +591,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); -/* + CurrentInjectionInfo = GetInjectionInfo(pid); if (!CurrentInjectionInfo && pid == GetCurrentProcessId()) @@ -612,9 +612,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, } else DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); - } -*/ + LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); From 3fce889398e31c70af24634afd3a751a57c7ae22 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Feb 2017 11:32:19 +0000 Subject: [PATCH 08/39] Bug fixes for section view-based injection. --- CAPE/CAPE.c | 49 ++++++++++++++++++++++++++++++------------------- CAPE/CAPE.h | 1 + hook_process.c | 9 +++++---- hook_thread.c | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 13fbabd..983f48a 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -371,7 +371,7 @@ PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE if (SectionViewList == NULL) { - DoOutputDebugString("InjectionAddSectionView: failed to allocate memory for initial section view list.\n"); + DoOutputDebugString("AddSectionView: failed to allocate memory for initial section view list.\n"); return NULL; } @@ -438,8 +438,24 @@ BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) if (CurrentSectionView == SectionView) { // Unlink this from the list and free the memory - PreviousSectionView->NextSectionView = CurrentSectionView->NextSectionView; + if (PreviousSectionView && CurrentSectionView->NextSectionView) + { + PreviousSectionView->NextSectionView = CurrentSectionView->NextSectionView; + DoOutputDebugString("DropSectionView: removed a view from section view list.\n"); + } + else if (PreviousSectionView && CurrentSectionView->NextSectionView == NULL) + { + PreviousSectionView->NextSectionView = NULL; + DoOutputDebugString("DropSectionView: removed the view from the end of the section view list.\n"); + } + else if (!PreviousSectionView) + { + SectionViewList = NULL; + DoOutputDebugString("DropSectionView: removed the head of the section view list.\n"); + } + free(CurrentSectionView); + return TRUE; } @@ -649,10 +665,10 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) for (k=0; ke_lfanew > Size-p) - //{ - // // e_lfanew points beyond end of region - // continue; - //} + if ((ULONG)pDosHeader->e_lfanew > Size-p) + { + // e_lfanew points beyond end of region + continue; + } pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); @@ -923,7 +937,7 @@ int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset) } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputErrorString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); + DoOutputDebugString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); return 0; } } @@ -1005,9 +1019,6 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) DoOutputDebugString("DumpMemory: Failed to allocate memory for buffer copy.\n"); return FALSE; } - else DoOutputDebugString("DumpMemory: DEBUG: Allocated space for buffer copy at 0x%x size 0x%x.\n", BufferCopy, Size); - - DoOutputDebugString("DumpMemory: DEBUG: About to create copy of buffer 0x%x size 0x%x.\n", Buffer, Size); __try { diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 3922b1b..6b02226 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -7,6 +7,7 @@ extern int DumpCurrentProcess(); extern int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); extern int DumpPE(LPCVOID Buffer); extern int ScyllaDumpPE(DWORD_PTR Buffer); +int DumpImageInCurrentProcess(DWORD ImageBase); unsigned int DumpSize; //Global switch for debugger diff --git a/hook_process.c b/hook_process.c index c65f6f7..9c10c1d 100644 --- a/hook_process.c +++ b/hook_process.c @@ -31,6 +31,7 @@ along with this program. If not, see . #include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern int DumpMemory(LPCVOID Buffer, unsigned int Size); extern int DumpImageInCurrentProcess(DWORD ImageBase); extern int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); @@ -394,7 +395,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(CurrentSectionView->LocalView); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)CurrentSectionView->LocalView); if (CurrentInjectionInfo->ImageDumped) { @@ -533,7 +534,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, _In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress ) { - PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; + PINJECTIONSECTIONVIEW CurrentSectionView; SIZE_T map_size = 0; MEMORY_BASIC_INFORMATION mbi; DWORD pid = pid_from_process_handle(ProcessHandle); DWORD protect = PAGE_READWRITE; @@ -733,7 +734,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(Buffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)Buffer); if (CurrentInjectionInfo->ImageDumped) { @@ -842,7 +843,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(lpBuffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)lpBuffer); if (CurrentInjectionInfo->ImageDumped) { diff --git a/hook_thread.c b/hook_thread.c index 855d0a3..c6a07f5 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -358,7 +358,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, CapeMetaData->TargetPid = pid; - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess(CurrentSectionView->LocalView); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)CurrentSectionView->LocalView); if (CurrentInjectionInfo->ImageDumped) { From db84e2f5e60ef60f821cb72a2336580c70abd0e9 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Mar 2017 15:54:01 +0000 Subject: [PATCH 09/39] Added support for SetWindowLong-based injection. --- CAPE/CAPE.c | 173 ++++-- CAPE/CAPE.h | 4 + CAPE/Debugger.c | 1001 +++++++++++++++++++++++-------- CAPE/Debugger.h | 23 +- CAPE/Scylla/ImportRebuilder.cpp | 4 +- CAPE/Scylla/PeParser.cpp | 93 +-- CAPE/Scylla/PeParser.h | 2 - CAPE/ScyllaHarness.cpp | 14 +- cuckoomon.c | 8 +- hook_process.c | 119 ++-- hook_thread.c | 62 +- hook_window.c | 58 +- hooks.h | 14 + 13 files changed, 1102 insertions(+), 473 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 983f48a..a6d5789 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -340,10 +340,12 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) { PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + //TODO remove debug DoOutputDebugString("GetSectionView: Global section view list 0x%x, looking for handle 0x%x\n", CurrentSectionView, SectionHandle); while (CurrentSectionView) { + //TODO remove debug DoOutputDebugString("GetSectionView: looking at section handle 0x%x.\n", CurrentSectionView->SectionHandle); if (CurrentSectionView->SectionHandle == SectionHandle) { @@ -466,25 +468,139 @@ BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) return FALSE; } +//************************************************************************************** +void DumpSectionViewsForPid(DWORD Pid) +//************************************************************************************** +{ + struct InjectionInfo *CurrentInjectionInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; + DWORD BufferSize = MAX_PATH; + LPVOID PEPointer = NULL; + BOOL Dumped = FALSE; + + DoOutputDebugString("DumpSectionViewsForPid: DEEEEEEEEEEEEEEEEEEEBUG.\n"); + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("DumpSectionViewsForPid: No injection info for pid %d.\n", Pid); + return; + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId == Pid) + { + DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d.\n", Pid); + + if (CurrentSectionView->LocalView) + { + PEPointer = CurrentSectionView->LocalView; + + while (ScanForPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%x.\n", PEPointer); + + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + + if (DumpImageInCurrentProcess((DWORD)PEPointer)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); + + ((BYTE*)PEPointer)++; + } + + if (Dumped == FALSE) + { + DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = Pid; + + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); + } + } + } + + //DropSectionView(CurrentSectionView); + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (Dumped == FALSE) + DoOutputDebugString("DumpSectionViewsForPid: no shared section views found for pid %d.\n", Pid); + + return; +} + //************************************************************************************** char* GetName() //************************************************************************************** { - char *OutputFilename; + char *OutputFilename, *FullPathName; SYSTEMTIME Time; + DWORD RetVal; + + FullPathName = (char*) malloc(MAX_PATH); + if (FullPathName == NULL) + { + DoOutputErrorString("GetName: Error allocating memory for full path string"); + return 0; + } + OutputFilename = (char*)malloc(MAX_PATH); if (OutputFilename == NULL) { - DoOutputErrorString("GetName: failed to allocate memory"); + DoOutputErrorString("GetName: failed to allocate memory for file name string"); return 0; } GetSystemTime(&Time); sprintf_s(OutputFilename, MAX_PATH*sizeof(char), "%d_%d%d%d%d%d%d%d%d", GetCurrentProcessId(), Time.wMilliseconds, Time.wSecond, Time.wMinute, Time.wHour, Time.wDay, Time.wDayOfWeek, Time.wMonth, Time.wYear); - return OutputFilename; + // We want to dump CAPE output to the 'analyzer' directory + memset(FullPathName, 0, MAX_PATH); + + strncpy_s(FullPathName, MAX_PATH, g_config.analyzer, strlen(g_config.analyzer)+1); + + if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) + { + DoOutputDebugString("GetName: Error, CAPE destination path too long."); + free(OutputFilename); free(FullPathName); + return 0; + } + + PathAppend(FullPathName, "CAPE"); + + RetVal = CreateDirectory(FullPathName, NULL); + + if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) + { + DoOutputDebugString("GetName: Error creating output directory"); + free(OutputFilename); free(FullPathName); + return 0; + } + + PathAppend(FullPathName, OutputFilename); + + return FullPathName; } //************************************************************************************** @@ -950,61 +1066,26 @@ int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset) int DumpMemory(LPCVOID Buffer, unsigned int Size) //************************************************************************************** { - char *OutputFilename, *FullPathName; - DWORD RetVal, dwBytesWritten; + char *FullPathName; + DWORD dwBytesWritten; HANDLE hOutputFile; LPVOID BufferCopy; - FullPathName = (char*) malloc(MAX_PATH); - - if (FullPathName == NULL) - { - DoOutputErrorString("DumpMemory: Error allocating memory for strings"); - return 0; - } - - OutputFilename = GetName(); - - // We want to dump CAPE output to the 'analyzer' directory - memset(FullPathName, 0, MAX_PATH); - - strncpy_s(FullPathName, MAX_PATH, g_config.analyzer, strlen(g_config.analyzer)+1); - - if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) - { - DoOutputDebugString("DumpMemory: Error, CAPE destination path too long."); - free(OutputFilename); free(FullPathName); - return 0; - } - - PathAppend(FullPathName, "CAPE"); - - RetVal = CreateDirectory(FullPathName, NULL); - - if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) - { - DoOutputDebugString("DumpMemory: Error creating output directory"); - free(OutputFilename); free(FullPathName); - return 0; - } - - PathAppend(FullPathName, OutputFilename); - - DoOutputDebugString("DumpMemory: FullPathName = %s", FullPathName); - + FullPathName = GetName(); + hOutputFile = CreateFile(FullPathName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (hOutputFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) { DoOutputDebugString("DumpMemory: CAPE output filename exists already: %s", FullPathName); - free(OutputFilename); free(FullPathName); + free(FullPathName); return 0; } if (hOutputFile == INVALID_HANDLE_VALUE) { DoOutputErrorString("DumpMemory: Could not create CAPE output file"); - free(OutputFilename); free(FullPathName); + free(FullPathName); return 0; } @@ -1033,7 +1114,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (FALSE == WriteFile(hOutputFile, BufferCopy, Size, &dwBytesWritten, NULL)) { DoOutputErrorString("DumpMemory: WriteFile error on CAPE output file"); - free(OutputFilename); free(FullPathName); free(BufferCopy); + free(FullPathName); free(BufferCopy); return 0; } @@ -1042,7 +1123,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) CapeOutputFile(FullPathName); // We can free the filename buffers - free(OutputFilename); free(FullPathName); free(BufferCopy); + free(FullPathName); free(BufferCopy); return 1; } diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 6b02226..c7fcac7 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -2,12 +2,16 @@ extern HMODULE s_hInst; extern WCHAR s_wzDllPath[MAX_PATH]; extern CHAR s_szDllPath[MAX_PATH]; BOOL TranslatePathFromDeviceToLetter(__in TCHAR *DeviceFilePath, __out TCHAR* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize); +int DumpMemory(LPCVOID Buffer, unsigned int Size); extern int DumpCurrentProcessNewEP(DWORD NewEP); extern int DumpCurrentProcess(); extern int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); extern int DumpPE(LPCVOID Buffer); extern int ScyllaDumpPE(DWORD_PTR Buffer); +int ScanForNonZero(LPCVOID Buffer, unsigned int Size); +int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); int DumpImageInCurrentProcess(DWORD ImageBase); +void DumpSectionViewsForPid(DWORD Pid); unsigned int DumpSize; //Global switch for debugger diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 5ceebd2..39cab35 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -15,7 +15,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.If not, see . */ -#ifndef _WIN64 #include #include #include @@ -49,7 +48,7 @@ typedef struct _DR7 DWORD PAD1 : 3; DWORD GD : 1; //General Detect Enable DWORD PAD2 : 1; - DWORD Pad3 : 1; + DWORD PAD3 : 1; DWORD RWE0 : 2; //Read/Write/Execute bp0 DWORD LEN0 : 2; //Length bp0 DWORD RWE1 : 2; //Read/Write/Execute bp1 @@ -82,13 +81,11 @@ DWORD LengthMask[MAX_DEBUG_REGISTER_DATA_SIZE + 1] = DEBUG_REGISTER_LENGTH_MASKS DWORD MainThreadId; struct ThreadBreakpoints *MainThreadBreakpointList; LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; -LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); SINGLE_STEP_HANDLER SingleStepHandler; DWORD WINAPI PipeThread(LPVOID lpParam); -DWORD RemoteFuncAddress; HANDLE hParentPipe; -extern BOOL StackWriteCallback(PBREAKPOINTINFO pBreakpointInfo, struct _EXCEPTION_POINTERS* ExceptionInfo); +extern LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); extern unsigned int address_is_in_stack(DWORD Address); extern BOOL WoW64fix(void); extern BOOL WoW64PatchBreakpoint(unsigned int Register); @@ -98,14 +95,14 @@ extern DWORD MyGetThreadId(HANDLE hThread); extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; - -PVOID OEP; +typedef void (WINAPI *PWIN32ENTRY)(); +PWIN32ENTRY OEP; void DebugOutputThreadBreakpoints(); -BOOL RestoreExecutionBreakpoint(PCONTEXT Context); +BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL ClearSingleStepMode(PCONTEXT Context); +unsigned int TrapIndex; //************************************************************************************** PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId) @@ -239,20 +236,15 @@ BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register) { CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); - DoOutputDebugString("GetNextAvailableBreakpoint: CurrentThreadId = 0x%x.\n", CurrentThreadId); - if (CurrentThreadId == ThreadId) { - for (i=0; i<4; i++) + for (i=0; i < NUMBER_OF_DEBUG_REGISTERS; i++) { if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) { *Register = i; return TRUE; - } - else - DoOutputDebugString("GetNextAvailableBreakpoint: CurrentThreadBreakpoint->BreakpointInfo[%d].Address = 0x%x.\n", i, CurrentThreadBreakpoint->BreakpointInfo[i].Address); - + } } } @@ -282,8 +274,8 @@ BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) DoOutputDebugString("ContextGetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } - - for (i=0; i<4; i++) + + for (i=0; i < NUMBER_OF_DEBUG_REGISTERS; i++) { if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) { @@ -311,7 +303,7 @@ void DebugOutputThreadBreakpoints() if (pBreakpointInfo == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Can't get BreakpointInfo - FATAL.\n"); + DoOutputDebugString("DebugOutputThreadBreakpoints: Can't get BreakpointInfo - FATAL.\n"); } DoOutputDebugString("Callback = 0x%x, Address = 0x%x, Size = 0x%x, Register = %i, ThreadHandle = 0x%x, Type = 0x%x\n", @@ -324,6 +316,16 @@ void DebugOutputThreadBreakpoints() } } +//************************************************************************************** +void ShowStack(DWORD_PTR StackPointer, unsigned int NumberOfRecords) +//************************************************************************************** +{ + unsigned int i; + + for (i=0; iContextRecord->Dr6 & (1 << bp)) + if (ExceptionInfo->ContextRecord->Dr6 & (DWORD_PTR)(1 << bp)) { BreakpointFlag = TRUE; } @@ -351,7 +353,20 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) // If not it's a single-step if (BreakpointFlag == FALSE) { - SingleStepHandler(ExceptionInfo); + if (SingleStepHandler) + SingleStepHandler(ExceptionInfo); + else if (TrapIndex) + // this is from StepOverExecutionBreakpoint + { + DoOutputDebugString("CAPEExceptionFilter: Stepping over execution breakpoint to: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); + ResumeAfterExecutionBreakpoint(ExceptionInfo->ContextRecord); + } + else + { + DoOutputDebugString("CAPEExceptionFilter: Error, unhandled single-step exception at: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); + return EXCEPTION_CONTINUE_SEARCH; + } + return EXCEPTION_CONTINUE_EXECUTION; } @@ -367,7 +382,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) { - if (ExceptionInfo->ContextRecord->Dr6 & (1 << bp)) + if (ExceptionInfo->ContextRecord->Dr6 & (DWORD_PTR)(1 << bp)) { pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[bp]); @@ -379,25 +394,25 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (pBreakpointInfo->Register == bp) { - if (bp == 0 && ((DWORD)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr0)) + if (bp == 0 && ((DWORD_PTR)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr0)) DoOutputDebugString("CAPEExceptionFilter: Anomaly detected! bp0 address (0x%x) different to BreakpointInfo (0x%x)!\n", ExceptionInfo->ContextRecord->Dr0, pBreakpointInfo->Address); - if (bp == 1 && ((DWORD)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr1)) + if (bp == 1 && ((DWORD_PTR)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr1)) DoOutputDebugString("CAPEExceptionFilter: Anomaly detected! bp1 address (0x%x) different to BreakpointInfo (0x%x)!\n", ExceptionInfo->ContextRecord->Dr1, pBreakpointInfo->Address); - if (bp == 2 && ((DWORD)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr2)) + if (bp == 2 && ((DWORD_PTR)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr2)) DoOutputDebugString("CAPEExceptionFilter: Anomaly detected! bp2 address (0x%x) different to BreakpointInfo (0x%x)!\n", ExceptionInfo->ContextRecord->Dr2, pBreakpointInfo->Address); - if (bp == 3 && ((DWORD)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr3)) + if (bp == 3 && ((DWORD_PTR)pBreakpointInfo->Address != ExceptionInfo->ContextRecord->Dr3)) DoOutputDebugString("CAPEExceptionFilter: Anomaly detected! bp3 address (0x%x) different to BreakpointInfo (0x%x)!\n", ExceptionInfo->ContextRecord->Dr3, pBreakpointInfo->Address); - - if (bp == 0 && ((DWORD)pBreakpointInfo->Type != ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE0)) +#ifndef _WIN64 + if (bp == 0 && ((DWORD_PTR)pBreakpointInfo->Type != ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE0)) { - if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE0 == BP_WRITE && address_is_in_stack((DWORD)pBreakpointInfo->Address)) + if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE0 == BP_WRITE && address_is_in_stack((DWORD_PTR)pBreakpointInfo->Address)) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -407,11 +422,11 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } if (bp == 1 && ((DWORD)pBreakpointInfo->Type != ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE1)) { - if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE1 == BP_WRITE && address_is_in_stack((DWORD)pBreakpointInfo->Address)) + if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE1 == BP_WRITE && address_is_in_stack((DWORD_PTR)pBreakpointInfo->Address)) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -421,11 +436,11 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } if (bp == 2 && ((DWORD)pBreakpointInfo->Type != ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE2)) { - if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE2 == BP_WRITE && address_is_in_stack((DWORD)pBreakpointInfo->Address)) + if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE2 == BP_WRITE && address_is_in_stack((DWORD_PTR)pBreakpointInfo->Address)) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on stack breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -435,11 +450,11 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } if (bp == 3 && ((DWORD)pBreakpointInfo->Type != ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE3)) { - if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE3 == BP_WRITE && address_is_in_stack((DWORD)pBreakpointInfo->Address)) + if (pBreakpointInfo->Type == BP_READWRITE && ((PDR7)&(ExceptionInfo->ContextRecord->Dr7))->RWE3 == BP_WRITE && address_is_in_stack((DWORD_PTR)pBreakpointInfo->Address)) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetHardwareBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -447,6 +462,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) CheckDebugRegisters(0, ExceptionInfo->ContextRecord); } } +#endif // !_WIN64 } } } @@ -464,9 +480,33 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) return EXCEPTION_CONTINUE_EXECUTION; } - + else if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) + { + // This is likely our own DoOutputDebugString function! + // So we let Windows handle this so we get our output. + return EXCEPTION_CONTINUE_SEARCH; + } + else if (OriginalExceptionHandler) + { + // As it's not a bp, and the sample has registered its own handler + // we return EXCEPTION_EXECUTE_HANDLER + DoOutputDebugString("CAPEExceptionFilter: Non-breakpoint exception caught, re-registering sample's handler.\n"); + SetUnhandledExceptionFilter(OriginalExceptionHandler); + return EXCEPTION_EXECUTE_HANDLER; + } + else if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION) + { + // We want to know more about this class of crash + DoOutputDebugString("CAPEExceptionFilter: Access violation caught, turning up debug level to capture info.\n"); + g_config.debug = 2; + return cuckoomon_exception_handler(ExceptionInfo); + } + // Some other exception occurred. Pass it to next handler - return EXCEPTION_CONTINUE_SEARCH; + DoOutputDebugString("CAPEExceptionFilter: Passing non-breakpoint exception: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionCode); + + return cuckoomon_exception_handler(ExceptionInfo); + //return EXCEPTION_CONTINUE_SEARCH; } //************************************************************************************** @@ -482,10 +522,10 @@ BOOL ContextSetDebugRegister { DWORD Length; - PDWORD Dr0 = &(Context->Dr0); - PDWORD Dr1 = &(Context->Dr1); - PDWORD Dr2 = &(Context->Dr2); - PDWORD Dr3 = &(Context->Dr3); + PDWORD_PTR Dr0 = &(Context->Dr0); + PDWORD_PTR Dr1 = &(Context->Dr1); + PDWORD_PTR Dr2 = &(Context->Dr2); + PDWORD_PTR Dr3 = &(Context->Dr3); PDR7 Dr7 = (PDR7)&(Context->Dr7); if ((unsigned int)Type > 3) @@ -512,7 +552,7 @@ BOOL ContextSetDebugRegister return FALSE; } - DoOutputDebugString("Setting breakpoint %i within Context, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, Size, Address, Type); + DoOutputDebugString("ContextSetDebugRegister: Setting breakpoint %i within Context, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, Size, Address, Type); Length = LengthMask[Size]; @@ -520,33 +560,35 @@ BOOL ContextSetDebugRegister if (Type == BP_EXEC) Length = 0; - if (Type == BP_READWRITE && address_is_in_stack((DWORD)Address)) +#ifndef _WIN64 + if (Type == BP_READWRITE && address_is_in_stack((DWORD_PTR)Address)) WoW64PatchBreakpoint(Register); +#endif if (Register == 0) { - *Dr0 = (DWORD)Address; + *Dr0 = (DWORD_PTR)Address; Dr7->LEN0 = Length; Dr7->RWE0 = Type; Dr7->L0 = 1; } else if (Register == 1) { - *Dr1 = (DWORD)Address; + *Dr1 = (DWORD_PTR)Address; Dr7->LEN1 = Length; Dr7->RWE1 = Type; Dr7->L1 = 1; } else if (Register == 2) { - *Dr2 = (DWORD)Address; + *Dr2 = (DWORD_PTR)Address; Dr7->LEN2 = Length; Dr7->RWE2 = Type; Dr7->L2 = 1; } else if (Register == 3) { - *Dr3 = (DWORD)Address; + *Dr3 = (DWORD_PTR)Address; Dr7->LEN3 = Length; Dr7->RWE3 = Type; Dr7->L3 = 1; @@ -572,10 +614,10 @@ BOOL SetDebugRegister DWORD Length; CONTEXT Context; - PDWORD Dr0 = &Context.Dr0; - PDWORD Dr1 = &Context.Dr1; - PDWORD Dr2 = &Context.Dr2; - PDWORD Dr3 = &Context.Dr3; + PDWORD_PTR Dr0 = &Context.Dr0; + PDWORD_PTR Dr1 = &Context.Dr1; + PDWORD_PTR Dr2 = &Context.Dr2; + PDWORD_PTR Dr3 = &Context.Dr3; PDR7 Dr7 = (PDR7)&(Context.Dr7); if ((unsigned int)Type > 3) @@ -602,12 +644,13 @@ BOOL SetDebugRegister return FALSE; } - DoOutputDebugString("Setting breakpoint %i hThread=0x%x, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, hThread, Size, Address, Type); + DoOutputDebugString("SetDebugRegister: Setting breakpoint %i hThread=0x%x, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, hThread, Size, Address, Type); Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; if (!GetThreadContext(hThread, &Context)) { + DoOutputErrorString("SetDebugRegister: GetThreadContext failed"); return FALSE; } @@ -617,33 +660,35 @@ BOOL SetDebugRegister if (Type == BP_EXEC) Length = 0; - if (Type == BP_READWRITE && address_is_in_stack((DWORD)Address)) +#ifndef _WIN64 + if (Type == BP_READWRITE && address_is_in_stack((DWORD_PTR)Address)) WoW64PatchBreakpoint(Register); +#endif if (Register == 0) { - *Dr0 = (DWORD)Address; + *Dr0 = (DWORD_PTR)Address; Dr7->LEN0 = Length; Dr7->RWE0 = Type; Dr7->L0 = 1; } else if (Register == 1) { - *Dr1 = (DWORD)Address; + *Dr1 = (DWORD_PTR)Address; Dr7->LEN1 = Length; Dr7->RWE1 = Type; Dr7->L1 = 1; } else if (Register == 2) { - *Dr2 = (DWORD)Address; + *Dr2 = (DWORD_PTR)Address; Dr7->LEN2 = Length; Dr7->RWE2 = Type; Dr7->L2 = 1; } else if (Register == 3) { - *Dr3 = (DWORD)Address; + *Dr3 = (DWORD_PTR)Address; Dr7->LEN3 = Length; Dr7->RWE3 = Type; Dr7->L3 = 1; @@ -655,45 +700,35 @@ BOOL SetDebugRegister Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; if (!SetThreadContext(hThread, &Context)) - return FALSE; - - return TRUE; -} - -//************************************************************************************** -BOOL ContextClearAllDebugRegisters(PCONTEXT Context) -//************************************************************************************** -{ - Context->Dr0 = 0; - Context->Dr1 = 0; - Context->Dr2 = 0; - Context->Dr3 = 0; - Context->Dr6 = 0; - Context->Dr7 = 0; - + { + DoOutputErrorString("SetDebugRegister: SetThreadContext failed"); + return FALSE; + } + return TRUE; } //************************************************************************************** -BOOL ClearAllDebugRegisters(HANDLE hThread) +BOOL ContextCheckDebugRegisters(PCONTEXT Context) //************************************************************************************** -{ - CONTEXT Context; - Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; - - if (!GetThreadContext(hThread, &Context)) - return FALSE; +{ + PDR7 Dr7; + + if (!Context) + { + DoOutputDebugString("CheckDebugRegisters - no context supplied.\n"); + return FALSE; + } + + Dr7 = (PDR7)&(Context->Dr7); + + DoOutputDebugString("Checking breakpoints\n"); + DoOutputDebugString("Dr0 0x%x, Dr7->LEN0 %i, Dr7->RWE0 %i, Dr7->L0 %i\n", Context->Dr0, Dr7->LEN0, Dr7->RWE0, Dr7->L0); + DoOutputDebugString("Dr1 0x%x, Dr7->LEN1 %i, Dr7->RWE1 %i, Dr7->L1 %i\n", Context->Dr1, Dr7->LEN1, Dr7->RWE1, Dr7->L1); + DoOutputDebugString("Dr2 0x%x, Dr7->LEN2 %i, Dr7->RWE2 %i, Dr7->L2 %i\n", Context->Dr2, Dr7->LEN2, Dr7->RWE2, Dr7->L2); + DoOutputDebugString("Dr3 0x%x, Dr7->LEN3 %i, Dr7->RWE3 %i, Dr7->L3 %i\n", Context->Dr3, Dr7->LEN3, Dr7->RWE3, Dr7->L3); + DoOutputDebugString("Dr6 0x%x\n", Context->Dr6); - Context.Dr0 = 0; - Context.Dr1 = 0; - Context.Dr2 = 0; - Context.Dr3 = 0; - Context.Dr6 = 0; - Context.Dr7 = 0; - - if (!SetThreadContext(hThread, &Context)) - return FALSE; - return TRUE; } @@ -702,15 +737,15 @@ BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext) //************************************************************************************** { CONTEXT Context; - PDWORD Dr0 = &Context.Dr0; - PDWORD Dr1 = &Context.Dr1; - PDWORD Dr2 = &Context.Dr2; - PDWORD Dr3 = &Context.Dr3; + PDWORD_PTR Dr0 = &Context.Dr0; + PDWORD_PTR Dr1 = &Context.Dr1; + PDWORD_PTR Dr2 = &Context.Dr2; + PDWORD_PTR Dr3 = &Context.Dr3; PDR7 Dr7 = (PDR7)&(Context.Dr7); if (!hThread && !pContext) { - DoOutputDebugString("CheckDebugRegisters - no arguments supplied.\n"); + DoOutputDebugString("CheckDebugRegisters - reqruied arguments missing.\n"); return FALSE; } @@ -739,10 +774,100 @@ BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext) } //************************************************************************************** -BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) +BOOL ContextClearAllBreakpoints(PCONTEXT Context) //************************************************************************************** { - PDWORD Dr0, Dr1, Dr2, Dr3; + unsigned int i; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextClearAllBreakpoints: No breakpoints found for current thread 0x%x.\n", GetCurrentThreadId()); + return FALSE; + } + + for (i=0; i < NUMBER_OF_DEBUG_REGISTERS; i++) + { + CurrentThreadBreakpoint->BreakpointInfo[i].Register = 0; + CurrentThreadBreakpoint->BreakpointInfo[i].Size = 0; + CurrentThreadBreakpoint->BreakpointInfo[i].Address = NULL; + CurrentThreadBreakpoint->BreakpointInfo[i].Type = 0; + CurrentThreadBreakpoint->BreakpointInfo[i].Callback = NULL; + } + + Context->Dr0 = 0; + Context->Dr1 = 0; + Context->Dr2 = 0; + Context->Dr3 = 0; + Context->Dr6 = 0; + Context->Dr7 = 0; + + return TRUE; +} + +//************************************************************************************** +BOOL ClearAllBreakpoints(DWORD ThreadId) +//************************************************************************************** +{ + CONTEXT Context; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + unsigned int Register; + DWORD CurrentThreadId; + + CurrentThreadBreakpoint = MainThreadBreakpointList; + + while (CurrentThreadBreakpoint) + { + CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); + + if (CurrentThreadId == ThreadId) + { + for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) + { + CurrentThreadBreakpoint->BreakpointInfo[Register].Register = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Size = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Address = NULL; + CurrentThreadBreakpoint->BreakpointInfo[Register].Type = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = NULL; + } + + Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!GetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) + { + DoOutputDebugString("ClearAllBreakpoints: Error getting thread context (thread %d).\n", CurrentThreadId); + return FALSE; + } + + Context.Dr0 = 0; + Context.Dr1 = 0; + Context.Dr2 = 0; + Context.Dr3 = 0; + Context.Dr6 = 0; + Context.Dr7 = 0; + + if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) + { + DoOutputDebugString("ClearAllBreakpoints: Error setting thread context (thread %d).\n", CurrentThreadId); + return FALSE; + } + + return TRUE; + } + else + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; + } + + return FALSE; +} + +//************************************************************************************** +BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) +//************************************************************************************** +{ + PDWORD_PTR Dr0, Dr1, Dr2, Dr3; PDR7 Dr7; if (Context == NULL) @@ -754,7 +879,7 @@ BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpoin Dr3 = &(Context->Dr3); Dr7 = (PDR7)&(Context->Dr7); - DoOutputDebugString("Clearing Context breakpoint %i\n", pBreakpointInfo->Register); + DoOutputDebugString("ContextClearBreakpoint: Clearing Context breakpoint %i\n", pBreakpointInfo->Register); if (pBreakpointInfo->Register == 0) { @@ -785,8 +910,10 @@ BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpoin Dr7->L3 = 0; } - if (pBreakpointInfo->Type == BP_READWRITE && address_is_in_stack((DWORD)pBreakpointInfo->Address)) +#ifndef _WIN64 + if (pBreakpointInfo->Type == BP_READWRITE && address_is_in_stack((DWORD_PTR)pBreakpointInfo->Address)) WoW64UnpatchBreakpoint(pBreakpointInfo->Register); +#endif Context->Dr6 = 0; @@ -798,6 +925,54 @@ BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpoin return TRUE; } +//************************************************************************************** +BOOL ClearBreakpointsInRange(DWORD ThreadId, PVOID BaseAddress, SIZE_T Size) +//************************************************************************************** +{ + unsigned int Register; + DWORD CurrentThreadId; + + PTHREADBREAKPOINTS CurrentThreadBreakpoint = MainThreadBreakpointList; + + if (BaseAddress == NULL) + { + DoOutputDebugString("ClearBreakpointsInRange: No address supplied (may have already been cleared).\n"); + return FALSE; + } + + if (Size == 0) + { + DoOutputDebugString("ClearBreakpointsInRange: Size supplied is zero.\n"); + return FALSE; + } + + DoOutputDebugString("ClearBreakpointsInRange: Clearing breakpoints in range 0x%x - 0x%x.\n", BaseAddress, (BYTE*)BaseAddress + Size); + + while (CurrentThreadBreakpoint) + { + CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); + + if (CurrentThreadId == ThreadId) + { + for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) + { + if ((DWORD_PTR)CurrentThreadBreakpoint->BreakpointInfo[Register].Address >= (DWORD_PTR)BaseAddress + && (DWORD_PTR)CurrentThreadBreakpoint->BreakpointInfo[Register].Address < (DWORD_PTR)((BYTE*)BaseAddress + Size)) + { + DoOutputDebugString("ClearBreakpointsInRange: Clearing breakpoint %d address 0x%x.\n", Register, CurrentThreadBreakpoint->BreakpointInfo[Register].Address); + ClearBreakpoint(CurrentThreadBreakpoint->ThreadId, Register); + } + } + + return TRUE; + } + else + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; + } + + return FALSE; +} + //************************************************************************************** BOOL SetResumeFlag(PCONTEXT Context) //************************************************************************************** @@ -840,6 +1015,82 @@ BOOL ClearSingleStepMode(PCONTEXT Context) return TRUE; } +//************************************************************************************** +BOOL StepOverExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) +//************************************************************************************** +// This function allows us to get past an execution breakpoint while leaving it set. It +// diaables the breakpoint, sets single-step mode to step over the instruction, whereupon +// the breakpoint is restored in ResumeAfterExecutionBreakpoint and execution resumed. +{ + PDR7 Dr7; + + if (Context == NULL) + return FALSE; + + Dr7 = (PDR7)&(Context->Dr7); + + switch(pBreakpointInfo->Register) + { + case 0: + Dr7->L0 = 0; + break; + case 1: + Dr7->L1 = 0; + break; + case 2: + Dr7->L2 = 0; + break; + case 3: + Dr7->L3 = 0; + break; + } + + // set the trap flag + Context->EFlags |= FL_TF; + + // set the 'trap index' so we know which 'register' we're skipping + // (off by one to allow 'set'/'unset' to be signified by !0/0) + TrapIndex = pBreakpointInfo->Register + 1; + + return TRUE; +} + +//************************************************************************************** +BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context) +//************************************************************************************** +{ + PDR7 Dr7; + + if (Context == NULL) + return FALSE; + + Dr7 = (PDR7)&(Context->Dr7); + + switch(TrapIndex-1) + { + case 0: + Dr7->L0 = 1; + break; + case 1: + Dr7->L1 = 1; + break; + case 2: + Dr7->L2 = 1; + break; + case 3: + Dr7->L3 = 1; + break; + } + + // Clear the trap flag + Context->EFlags &= ~FL_TF; + + // clear the 'trap index' + TrapIndex = 0; + + return TRUE; +} + //************************************************************************************** BOOL ClearDebugRegister //************************************************************************************** @@ -849,14 +1100,13 @@ BOOL ClearDebugRegister int Size, LPVOID Address, DWORD Type -) -{ +){ CONTEXT Context; BOOL DoCloseHandle = FALSE; - PDWORD Dr0 = &Context.Dr0; - PDWORD Dr1 = &Context.Dr1; - PDWORD Dr2 = &Context.Dr2; - PDWORD Dr3 = &Context.Dr3; + PDWORD_PTR Dr0 = &Context.Dr0; + PDWORD_PTR Dr1 = &Context.Dr1; + PDWORD_PTR Dr2 = &Context.Dr2; + PDWORD_PTR Dr3 = &Context.Dr3; PDR7 Dr7 = (PDR7)&(Context.Dr7); if ((unsigned int)Type > 3) @@ -877,8 +1127,6 @@ BOOL ClearDebugRegister return FALSE; } - DoOutputDebugString("Clearing breakpoint %i\n", Register); - Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; if (!GetThreadContext(hThread, &Context)) @@ -916,8 +1164,10 @@ BOOL ClearDebugRegister Dr7->L3 = 0; } - if (Type == BP_READWRITE && address_is_in_stack((DWORD)Address)) +#ifndef _WIN64 + if (Type == BP_READWRITE && address_is_in_stack((DWORD_PTR)Address)) WoW64UnpatchBreakpoint(Register); +#endif Context.Dr6 = 0; @@ -936,7 +1186,7 @@ BOOL ClearDebugRegister } //************************************************************************************** -int ContextCheckDebugRegister(CONTEXT Context, int Register) +int ContextCheckDebugRegister(CONTEXT Context, int Register) //************************************************************************************** { PDR7 Dr7; @@ -999,7 +1249,7 @@ int CheckDebugRegister(HANDLE hThread, int Register) } //************************************************************************************** -BOOL ContextSetHardwareBreakpoint +BOOL ContextSetBreakpoint //************************************************************************************** ( PCONTEXT Context, @@ -1014,17 +1264,17 @@ BOOL ContextSetHardwareBreakpoint if (Register > 3 || Register < 0) { - DoOutputDebugString("ContextSetHardwareBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("ContextSetBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } if (ContextSetDebugRegister(Context, Register, Size, Address, Type) == FALSE) { - DoOutputDebugString("Call to ContextSetDebugRegister failed.\n"); + DoOutputDebugString("ContextSetBreakpoint: Call to ContextSetDebugRegister failed.\n"); } else { - DoOutputDebugString("Call to ContextSetDebugRegister succeeded.\n"); + DoOutputDebugString("ContextSetBreakpoint: Call to ContextSetDebugRegister succeeded.\n"); CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); @@ -1034,10 +1284,12 @@ BOOL ContextSetHardwareBreakpoint return FALSE; } - CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = Callback; - CurrentThreadBreakpoint->BreakpointInfo[Register].Address = Address; - CurrentThreadBreakpoint->BreakpointInfo[Register].Size = Size; - CurrentThreadBreakpoint->BreakpointInfo[Register].Type = Type; + CurrentThreadBreakpoint->BreakpointInfo[Register].ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; + CurrentThreadBreakpoint->BreakpointInfo[Register].Register = Register; + CurrentThreadBreakpoint->BreakpointInfo[Register].Size = Size; + CurrentThreadBreakpoint->BreakpointInfo[Register].Address = Address; + CurrentThreadBreakpoint->BreakpointInfo[Register].Type = Type; + CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = Callback; } return TRUE; @@ -1061,7 +1313,7 @@ BOOL ContextSetNextAvailableBreakpoint return FALSE; } - return ContextSetHardwareBreakpoint(Context, *Register, Size, Address, Type, Callback); + return ContextSetBreakpoint(Context, *Register, Size, Address, Type, Callback); } //************************************************************************************** @@ -1089,7 +1341,7 @@ BOOL ContextUpdateCurrentBreakpoint for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) { - if (Context->Dr6 & (1 << bp)) + if (Context->Dr6 & (DWORD_PTR)(1 << bp)) { pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[bp]); @@ -1101,24 +1353,24 @@ BOOL ContextUpdateCurrentBreakpoint if (pBreakpointInfo->Register == bp) { - if (bp == 0 && ((DWORD)pBreakpointInfo->Address == Context->Dr0) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE0)) + if (bp == 0 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr0) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE0)) { - return ContextSetHardwareBreakpoint(Context, 0, Size, Address, Type, Callback); + return ContextSetBreakpoint(Context, 0, Size, Address, Type, Callback); } - if (bp == 1 && ((DWORD)pBreakpointInfo->Address == Context->Dr1) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE1)) + if (bp == 1 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr1) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE1)) { - return ContextSetHardwareBreakpoint(Context, 1, Size, Address, Type, Callback); + return ContextSetBreakpoint(Context, 1, Size, Address, Type, Callback); } - if (bp == 2 && ((DWORD)pBreakpointInfo->Address == Context->Dr2) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE2)) + if (bp == 2 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr2) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE2)) { - return ContextSetHardwareBreakpoint(Context, 2, Size, Address, Type, Callback); + return ContextSetBreakpoint(Context, 2, Size, Address, Type, Callback); } - if (bp == 3 && ((DWORD)pBreakpointInfo->Address == Context->Dr3) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE3)) + if (bp == 3 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr3) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE3)) { - return ContextSetHardwareBreakpoint(Context, 3, Size, Address, Type, Callback); + return ContextSetBreakpoint(Context, 3, Size, Address, Type, Callback); } } } @@ -1131,24 +1383,31 @@ BOOL ContextUpdateCurrentBreakpoint DWORD WINAPI SetBreakpointThread(LPVOID lpParam) //************************************************************************************** { + DWORD RetVal; + PBREAKPOINTINFO pBreakpointInfo = (PBREAKPOINTINFO)lpParam; if (SuspendThread(pBreakpointInfo->ThreadHandle) == 0xFFFFFFFF) DoOutputErrorString("SetBreakpointThread: Call to SuspendThread failed"); - else - DoOutputDebugString("SetBreakpointThread: Current thread suspended.\n"); - - //debug - DoOutputDebugString("SetBreakpointThread: About to call SetDebugRegister.\n"); if (SetDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) { - DoOutputErrorString("Call to SetDebugRegister failed"); + DoOutputErrorString("SetBreakpointThread: Call to SetDebugRegister failed"); } - DoOutputDebugString("SetBreakpointThread: Breakpoint set, about to resume thread.\n"); - - ResumeThread(pBreakpointInfo->ThreadHandle); + RetVal = ResumeThread(pBreakpointInfo->ThreadHandle); + if (RetVal == -1) + { + DoOutputErrorString("SetBreakpointThread: ResumeThread failed.\n"); + } + else if (RetVal == 0) + { + DoOutputDebugString("SetBreakpointThread: Error - Sample thread was not suspended.\n"); + } + else if (g_config.debug) + { + DoOutputDebugString("SetBreakpointThread: Sample thread was suspended, now resumed.\n"); + } return 1; } @@ -1157,29 +1416,86 @@ DWORD WINAPI SetBreakpointThread(LPVOID lpParam) DWORD WINAPI ClearBreakpointThread(LPVOID lpParam) //************************************************************************************** { + DWORD RetVal; PBREAKPOINTINFO pBreakpointInfo = (PBREAKPOINTINFO)lpParam; - DoOutputDebugString("Inside ClearBreakpointThread.\n"); - if (SuspendThread(pBreakpointInfo->ThreadHandle) == 0xFFFFFFFF) DoOutputErrorString("ClearBreakpointThread: Call to SuspendThread failed"); - else - DoOutputDebugString("ClearBreakpointThread: Current thread suspended.\n"); if (ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) { DoOutputDebugString("ClearBreakpointThread: Call to ClearDebugRegister failed.\n"); } - DoOutputDebugString("ClearBreakpointThread: Breakpoint cleared, about to resume thread.\n"); + RetVal = ResumeThread(pBreakpointInfo->ThreadHandle); + if (RetVal == -1) + { + DoOutputErrorString("ClearBreakpointThread: ResumeThread failed.\n"); + } + else if (RetVal == 0) + { + DoOutputDebugString("ClearBreakpointThread: Error - Sample thread was not suspended.\n"); + } + else if (g_config.debug) + { + DoOutputDebugString("ClearBreakpointThread: Sample thread was suspended, now resumed.\n"); + } + DebugOutputThreadBreakpoints(); + + return TRUE; +} + +//************************************************************************************** +BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) +//************************************************************************************** +{ + PBREAKPOINTINFO pBreakpointInfo; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + + if (Register > 3 || Register < 0) + { + DoOutputDebugString("ClearBreakpointWithoutThread: Error - register value %d, can only have value 0-3.\n", Register); + return FALSE; + } - ResumeThread(pBreakpointInfo->ThreadHandle); + CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - return TRUE; + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ClearBreakpointWithoutThread: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); + } + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ClearBreakpointWithoutThread: Cannot create new thread breakpoints - FATAL.\n"); + return FALSE; + } + + pBreakpointInfo = &CurrentThreadBreakpoint->BreakpointInfo[Register]; + + if (CurrentThreadBreakpoint->ThreadHandle == NULL) + { + DoOutputDebugString("ClearBreakpointWithoutThread: There is no thread handle in the thread breakpoint - Error.\n"); + return FALSE; + } + + if (ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) + { + DoOutputDebugString("ClearBreakpointWithoutThread: Call to ClearDebugRegister failed.\n"); + } + + //pBreakpointInfo->Register = 0; + pBreakpointInfo->Size = 0; + pBreakpointInfo->Address = 0; + pBreakpointInfo->Type = 0; + pBreakpointInfo->Callback = NULL; + + return TRUE; } //************************************************************************************** -BOOL SetHardwareBreakpoint +BOOL SetBreakpointWithoutThread //************************************************************************************** ( DWORD ThreadId, @@ -1192,25 +1508,25 @@ BOOL SetHardwareBreakpoint { PBREAKPOINTINFO pBreakpointInfo; PTHREADBREAKPOINTS CurrentThreadBreakpoint; - HANDLE hSetBreakpointThread; - + BOOL RetVal; + if (Register > 3 || Register < 0) { - DoOutputDebugString("SetHardwareBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("SetBreakpointWithoutThread: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - + if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + DoOutputDebugString("SetBreakpointWithoutThread: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("Cannot create new thread breakpoints - FATAL.\n"); + DoOutputDebugString("SetBreakpointWithoutThread: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } @@ -1218,65 +1534,180 @@ BOOL SetHardwareBreakpoint if (CurrentThreadBreakpoint->ThreadHandle == NULL) { - DoOutputDebugString("SetHardwareBreakpoint: There is no thread handle in the threadbreakpoint!! FATAL ERROR.\n"); + DoOutputDebugString("SetBreakpointWithoutThread: There is no thread handle in the thread breakpoint - Error.\n"); return FALSE; } - - pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; - pBreakpointInfo->Register = Register; - pBreakpointInfo->Size = Size; - pBreakpointInfo->Address = Address; - pBreakpointInfo->Type = Type; - pBreakpointInfo->Callback = Callback; - - OriginalExceptionHandler = SetUnhandledExceptionFilter(CAPEExceptionFilter); - //AddVectoredContinueHandler(1, CAPEExceptionFilter); + + pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; + pBreakpointInfo->Register = Register; + pBreakpointInfo->Size = Size; + pBreakpointInfo->Address = Address; + pBreakpointInfo->Type = Type; + pBreakpointInfo->Callback = Callback; - DoOutputDebugString("SetHardwareBreakpoint: about to call SetBreakpointThread\n"); + __try + { + RetVal = (SetDebugRegister(pBreakpointInfo->ThreadHandle, Register, Size, Address, Type)); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("SetBreakpointWithoutThread: Exception calling SetDebugRegister"); + return FALSE; + } + + // Debug + DoOutputDebugString("SetBreakpointWithoutThread: bp set with register %d\n", Register); - hSetBreakpointThread = CreateThread( - NULL, - 0, - SetBreakpointThread, - pBreakpointInfo, - 0, - &ThreadId); + return TRUE; +} - if (hSetBreakpointThread == NULL) - { - DoOutputErrorString("Failed to create SetBreakpointThread thread"); - return 0; - } +//************************************************************************************** +BOOL SetBreakpoint +//************************************************************************************** +( + DWORD ThreadId, + int Register, + int Size, + LPVOID Address, + DWORD Type, + PVOID Callback +) +{ + //if (DisableThreadSuspend) + // return SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); + + PBREAKPOINTINFO pBreakpointInfo; + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + HANDLE hSetBreakpointThread; + DWORD SetBreakpointThreadId; + BOOL RetVal; - DoOutputDebugString("SetHardwareBreakpoint: SetBreakpointThread called, beginning wait\n"); + if (Register > 3 || Register < 0) + { + DoOutputDebugString("SetBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + return FALSE; + } + + CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - // Wait until thread has terminated - WaitForSingleObject(hSetBreakpointThread, INFINITE); + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("SetBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); + } + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("SetBreakpoint: Cannot create new thread breakpoints - error.\n"); + return FALSE; + } - CloseHandle(hSetBreakpointThread); + pBreakpointInfo = &CurrentThreadBreakpoint->BreakpointInfo[Register]; - DoOutputDebugString("SetHardwareBreakpoint: Callback = 0x%x, Address = 0x%x, Size = 0x%x, Register = %i, ThreadHandle = 0x%x, Type = 0x%x\n", - pBreakpointInfo->Callback, - pBreakpointInfo->Address, - pBreakpointInfo->Size, - pBreakpointInfo->Register, - pBreakpointInfo->ThreadHandle, - pBreakpointInfo->Type); + if (CurrentThreadBreakpoint->ThreadHandle == NULL) + { + DoOutputDebugString("SetBreakpoint: There is no thread handle in the thread breakpoint - Error.\n"); + return FALSE; + } + + pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; + pBreakpointInfo->Register = Register; + pBreakpointInfo->Size = Size; + pBreakpointInfo->Address = Address; + pBreakpointInfo->Type = Type; + pBreakpointInfo->Callback = Callback; + + if (VECTORED_HANDLER) + AddVectoredExceptionHandler(1, CAPEExceptionFilter); + else + OriginalExceptionHandler = SetUnhandledExceptionFilter(CAPEExceptionFilter); + + __try + { + hSetBreakpointThread = CreateThread( + NULL, + 0, + SetBreakpointThread, + pBreakpointInfo, + 0, + &SetBreakpointThreadId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("SetBreakpoint: Unable to create SetBreakpointThread thread"); + } - return TRUE; + if (hSetBreakpointThread) + { + // If this hasn't happened in under a second, we bail + // and set without creating a thread + RetVal = WaitForSingleObject(hSetBreakpointThread, 1000); + + if (RetVal != WAIT_OBJECT_0) + { + TerminateThread(hSetBreakpointThread, 0); + DoOutputDebugString("SetBreakpoint: SetBreakpointThread timeout, thread killed.\n"); + + RetVal = ResumeThread(CurrentThreadBreakpoint->ThreadHandle); + if (RetVal == -1) + { + DoOutputErrorString("SetBreakpoint: ResumeThread failed. About to set breakpoint without thread.\n"); + } + else if (RetVal == 0) + { + DoOutputDebugString("SetBreakpoint: Sample thread was not suspended. About to set breakpoint without thread.\n"); + } + else + { + DoOutputDebugString("SetBreakpoint: Sample thread was suspended, now resumed. About to set breakpoint without thread.\n"); + } + + return SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); + } + + DoOutputDebugString("SetBreakpoint: Set bp %d type %d at address 0x%x, size %d with Callback 0x%x, ThreadHandle = 0x%x.\n", + pBreakpointInfo->Register, + pBreakpointInfo->Type, + pBreakpointInfo->Address, + pBreakpointInfo->Size, + pBreakpointInfo->Callback, + pBreakpointInfo->ThreadHandle + ); + + CloseHandle(hSetBreakpointThread); + + return TRUE; + } + else + { + __try + { + RetVal = SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("SetBreakpoint: Error calling SetBreakpointWithoutThread"); + return FALSE; + } + + return RetVal; + } } //************************************************************************************** -BOOL ClearHardwareBreakpoint(DWORD ThreadId, int Register) +BOOL ClearBreakpoint(DWORD ThreadId, int Register) //************************************************************************************** { + return ClearBreakpointWithoutThread(ThreadId, Register); +/* PBREAKPOINTINFO pBreakpointInfo; PTHREADBREAKPOINTS CurrentThreadBreakpoint; HANDLE hClearBreakpointThread; + BOOL RetVal; if (Register > 3 || Register < 0) { - DoOutputDebugString("ClearHardwareBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("ClearBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } @@ -1292,38 +1723,66 @@ BOOL ClearHardwareBreakpoint(DWORD ThreadId, int Register) if (CurrentThreadBreakpoint->ThreadHandle == NULL) { - DoOutputDebugString("ClearHardwareBreakpoint: There is no thread handle in the threadbreakpoint!! FATAL ERROR.\n"); + DoOutputDebugString("ClearBreakpoint: There is no thread handle in the thread breakpoint - Error.\n"); return FALSE; } - else DoOutputDebugString("ClearHardwareBreakpoint: Thread handle 0x%x found in BreakpointInfo struct.\n", CurrentThreadBreakpoint->ThreadHandle); - - DoOutputDebugString("About to create ClearBreakpointThread thread\n"); pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; - - hClearBreakpointThread = CreateThread(NULL, 0, ClearBreakpointThread, pBreakpointInfo, 0, &ThreadId); - if (hClearBreakpointThread == NULL) - { - DoOutputDebugString("Failed to create ClearBreakpointThread thread\n"); - return 0; - } + __try + { + hClearBreakpointThread = CreateThread(NULL, 0, ClearBreakpointThread, pBreakpointInfo, 0, &ThreadId); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ClearBreakpoint: Unable to create ClearBreakpointThread thread"); + } - DoOutputDebugString("Successfully created ClearBreakpointThread thread\n"); + if (hClearBreakpointThread) + { + DoOutputDebugString("ClearBreakpoint: thread created, handle 0x%x.\n", hClearBreakpointThread); + + // If this hasn't happened in under a second, we bail + // and clear without creating a thread + RetVal = WaitForSingleObject(hClearBreakpointThread, 1000); - // Wait until thread has terminated. - WaitForSingleObject(hClearBreakpointThread, INFINITE); + DoOutputDebugString("ClearBreakpoint: Aboot tae close handle.\n"); + //CloseHandle(hClearBreakpointThread); + + if (RetVal != WAIT_OBJECT_0) + { + DoOutputDebugString("ClearBreakpoint: thread timeout, falling back to clearing without thread.\n"); + + return ClearBreakpointWithoutThread(ThreadId, Register); + } + + DoOutputDebugString("ClearBreakpoint: Cleared breakpoint %d.\n", pBreakpointInfo->Register); - // Close thread handle and free memory allocations. - pBreakpointInfo->Register = 0; + return TRUE; + } + else + { + __try + { + RetVal = ClearBreakpointWithoutThread(ThreadId, Register); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ClearBreakpoint: Error calling ClearBreakpointWithoutThread"); + return FALSE; + } + + return RetVal; + } + + //pBreakpointInfo->Register = 0; pBreakpointInfo->Size = 0; pBreakpointInfo->Address = 0; pBreakpointInfo->Type = 0; pBreakpointInfo->Callback = NULL; - CheckDebugRegisters(pBreakpointInfo->ThreadHandle, 0); - return TRUE; +*/ } //************************************************************************************** @@ -1358,7 +1817,7 @@ BOOL SetNextAvailableBreakpoint return FALSE; } - return SetHardwareBreakpoint(ThreadId, *Register, Size, Address, Type, Callback); + return SetBreakpoint(ThreadId, *Register, Size, Address, Type, Callback); } //************************************************************************************** @@ -1390,20 +1849,40 @@ BOOL InitialiseDebugger(void) } // Initialise any global variables - Injection_ProcessId = 0; - + ChildProcessId = 0; + SingleStepHandler = NULL; + VECTORED_HANDLER = FALSE; + +#ifndef _WIN64 // Ensure wow64 patch is installed if needed WoW64fix(); +#endif return TRUE; } +//************************************************************************************** +DWORD_PTR GetNestedStackPointer(void) +//************************************************************************************** +{ + CONTEXT context; + + RtlCaptureContext(&context); + +#ifdef _WIN64 + return (DWORD_PTR)context.Rsp; +#else + return (DWORD_PTR)context.Esp; +#endif +} + +#ifndef _WIN64 //************************************************************************************** __declspec (naked dllexport) void DebuggerInit(void) //************************************************************************************** { DWORD StackPointer; - + _asm { push ebp @@ -1414,13 +1893,16 @@ __declspec (naked dllexport) void DebuggerInit(void) pushad } - InitialiseDebugger(); + if (InitialiseDebugger() == FALSE) + DoOutputDebugString("Debugger initialisation failure!\n"); // Target specific code - +#ifdef STANDALONE + SetNtAllocateVirtualMemoryBP(); +#endif // End of target specific code - DoOutputDebugString("Debugger initialised, about to execute OEP.\n"); + DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); _asm { @@ -1429,8 +1911,32 @@ __declspec (naked dllexport) void DebuggerInit(void) pop ebp jmp OEP } +} +#else +#pragma optimize("", off) +//************************************************************************************** +void DebuggerInit(void) +//************************************************************************************** +{ + DWORD_PTR StackPointer; + + StackPointer = GetNestedStackPointer() - 8; // this offset has been determined experimentally - TODO: tidy + + if (InitialiseDebugger() == FALSE) + DoOutputDebugString("Debugger initialisation failure!\n"); + else + DoOutputDebugString("Debugger initialised, ESP = 0x%x\n", StackPointer); + +// Target specific code + +// End of target specific code + DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); + + OEP(); } +#pragma optimize("", on) +#endif BOOL SendDebuggerMessage(DWORD Input) { @@ -1440,7 +1946,7 @@ BOOL SendDebuggerMessage(DWORD Input) //memset(&DebuggerData, 0, sizeof(struct DEBUGGER_DATA)); - cbReplyBytes = sizeof(DWORD); + cbReplyBytes = sizeof(DWORD_PTR); if (hParentPipe == NULL) { @@ -1470,7 +1976,7 @@ BOOL SendDebuggerMessage(DWORD Input) } //************************************************************************************** -DWORD WINAPI DebuggerThread(LPVOID lpParam) +DWORD WINAPI DebuggerLaunch(LPVOID lpParam) //************************************************************************************** { HANDLE hPipe; @@ -1481,7 +1987,7 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) char lpszPipename[MAX_PATH]; OSVERSIONINFO VersionInfo; - DoOutputDebugString("DebuggerThread: About to connect to CAPEpipe.\n"); + DoOutputDebugString("DebuggerLaunch: About to connect to CAPEpipe.\n"); memset(lpszPipename, 0, MAX_PATH*sizeof(CHAR)); sprintf_s(lpszPipename, MAX_PATH, "\\\\.\\pipe\\CAPEpipe_%x", GetCurrentProcessId()); @@ -1502,13 +2008,13 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) if (GetLastError() != ERROR_PIPE_BUSY) { - DoOutputErrorString("DebuggerThread: Could not open pipe"); + DoOutputErrorString("DebuggerLaunch: Could not open pipe"); return -1; } if (!WaitNamedPipe(lpszPipename, 20)) { - DoOutputDebugString("DebuggerThread: Could not open pipe: 20 ms wait timed out.\n"); + DoOutputDebugString("DebuggerLaunch: Could not open pipe: 20 ms wait timed out.\n"); return -1; } } @@ -1524,7 +2030,7 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) ); if (!fSuccess) { - DoOutputDebugString("DebuggerThread: SetNamedPipeHandleState failed.\n"); + DoOutputDebugString("DebuggerLaunch: SetNamedPipeHandleState failed.\n"); return -1; } @@ -1543,29 +2049,29 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) ); if (!fSuccess) { - DoOutputErrorString("DebuggerThread: WriteFile to pipe failed"); + DoOutputErrorString("DebuggerLaunch: WriteFile to pipe failed"); return -1; } - DoOutputDebugString("DebuggerThread: DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); + DoOutputDebugString("DebuggerLaunch: DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); fSuccess = ReadFile( hPipe, &OEP, - sizeof(DWORD), + sizeof(DWORD_PTR), &cbRead, NULL); if (!fSuccess && GetLastError() == ERROR_MORE_DATA) { - DoOutputDebugString("DebuggerThread: ReadFile on Pipe: ERROR_MORE_DATA\n"); + DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); CloseHandle(hPipe); return -1; } if (!fSuccess) { - DoOutputErrorString("DebuggerThread: ReadFile (OEP) from pipe failed"); + DoOutputErrorString("DebuggerLaunch: ReadFile (OEP) from pipe failed"); CloseHandle(hPipe); return -1; } @@ -1575,20 +2081,20 @@ DWORD WINAPI DebuggerThread(LPVOID lpParam) fSuccess = ReadFile( hPipe, &OEP, - sizeof(DWORD), + sizeof(DWORD_PTR), &cbRead, NULL); if (!fSuccess && GetLastError() == ERROR_MORE_DATA) { - DoOutputDebugString("DebuggerThread: ReadFile on Pipe: ERROR_MORE_DATA\n"); + DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); CloseHandle(hPipe); return -1; } if (!fSuccess && GetLastError() == ERROR_BROKEN_PIPE) { - DoOutputDebugString("DebuggerThread: Pipe closed, no further updates to OEP\n"); + DoOutputDebugString("DebuggerLaunch: Pipe closed, no further updates to OEP\n"); CloseHandle(hPipe); } else if (!fSuccess) @@ -1636,14 +2142,14 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, ProcessId); if (hProcess == NULL) { - DoOutputErrorString("CAPE debug pipe: OpenProcess failed"); + DoOutputErrorString("DebugNewProcess: OpenProcess failed"); return FALSE; } hThread = OpenThread(THREAD_ALL_ACCESS, TRUE, ThreadId); if (hThread == NULL) { - DoOutputErrorString("CAPE debug pipe: OpenThread failed"); + DoOutputErrorString("DebugNewProcess: OpenThread failed"); return FALSE; } @@ -1687,7 +2193,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati ( hParentPipe, &RemoteFuncAddress, - sizeof(DWORD), + sizeof(DWORD_PTR), &cbBytesRead, NULL ); @@ -1717,10 +2223,14 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati return FALSE; } +#ifdef _WIN64 + OEP = (PVOID)Context.Rcx; +#else OEP = (PVOID)Context.Eax; +#endif cbWritten = 0; - cbReplyBytes = sizeof(DWORD); + cbReplyBytes = sizeof(DWORD_PTR); // Write the reply to the pipe. fSuccess = WriteFile @@ -1741,7 +2251,11 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati Context.ContextFlags = CONTEXT_ALL; +#ifdef _WIN64 + Context.Rcx = RemoteFuncAddress; // eax holds new entry point +#else Context.Eax = RemoteFuncAddress; // eax holds new entry point +#endif if (!SetThreadContext(hThread, &Context)) { @@ -1749,7 +2263,11 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati return FALSE; } +#ifdef _WIN64 + DoOutputDebugString("DebugNewProcess: Set new EP to DebuggerInit: 0x%x\n", Context.Rcx); +#else DoOutputDebugString("DebugNewProcess: Set new EP to DebuggerInit: 0x%x\n", Context.Eax); +#endif CloseHandle(hProcess); CloseHandle(hThread); @@ -1762,30 +2280,27 @@ int launch_debugger() //************************************************************************************** { DWORD NewThreadId; - HANDLE hDebuggerThread; - - DoOutputDebugString("CAPE: Launching debugger.\n"); + HANDLE hDebuggerLaunch; - hDebuggerThread = CreateThread( + hDebuggerLaunch = CreateThread( NULL, 0, - DebuggerThread, + DebuggerLaunch, NULL, 0, &NewThreadId); - if (hDebuggerThread == NULL) + if (hDebuggerLaunch == NULL) { - DoOutputDebugString("CAPE: Failed to create debug pipe thread.\n"); + DoOutputDebugString("CAPE: Failed to create debugger launch thread.\n"); return 0; } else { - DoOutputDebugString("CAPE: Successfully created debug pipe thread.\n"); + DoOutputDebugString("CAPE: Launching debugger.\n"); } - CloseHandle(hDebuggerThread); + CloseHandle(hDebuggerLaunch); return 1; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 8963b62..6bdb222 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -7,8 +7,12 @@ void* CAPE_var; #define BP_RESERVED 0x02 #define BP_READWRITE 0x03 -DWORD Injection_ProcessId; -DWORD RemoteFuncAddress; +LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; +LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); +BOOL VECTORED_HANDLER; + +DWORD ChildProcessId; +DWORD_PTR RemoteFuncAddress; typedef struct BreakpointInfo { @@ -36,9 +40,8 @@ typedef BOOL (cdecl *SINGLE_STEP_HANDLER)(struct _EXCEPTION_POINTERS*); extern "C" { #endif -LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); -BOOL SetHardwareBreakpoint +BOOL SetBreakpoint ( DWORD ThreadId, int Register, @@ -48,9 +51,9 @@ BOOL SetHardwareBreakpoint PVOID Callback ); -BOOL ClearHardwareBreakpoint(DWORD ThreadId, int Register); +BOOL ClearBreakpoint(DWORD ThreadId, int Register); -BOOL ContextSetHardwareBreakpoint +BOOL ContextSetBreakpoint ( PCONTEXT Context, int Register, @@ -65,14 +68,16 @@ BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) BOOL ContextUpdateCurrentBreakpoint(PCONTEXT Context, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL SetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL ContextSetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); -BOOL ContextClearHardwareBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); +BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); +BOOL ClearBreakpointsInRange(DWORD ThreadId, PVOID BaseAddress, SIZE_T Size); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL ClearSingleStepMode(PCONTEXT Context); -BOOL ContextClearAllDebugRegisters(PCONTEXT Context); -BOOL ClearAllDebugRegisters(HANDLE hThread); +BOOL ContextClearAllBreakpoints(PCONTEXT Context); +BOOL ClearAllBreakpoints(DWORD ThreadId); BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); BOOL InitialiseDebugger(void); BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD CreationFlags); +BOOL SendDebuggerMessage(DWORD Input); int launch_debugger(void); #ifdef __cplusplus diff --git a/CAPE/Scylla/ImportRebuilder.cpp b/CAPE/Scylla/ImportRebuilder.cpp index c9fd324..ca0906e 100644 --- a/CAPE/Scylla/ImportRebuilder.cpp +++ b/CAPE/Scylla/ImportRebuilder.cpp @@ -52,7 +52,7 @@ bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & sectionList); void setEntryPointVa(DWORD_PTR entryPoint); diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 6257375..9d42178 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -51,7 +51,7 @@ void ScyllaInitCurrentProcess() } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP, BOOL CapeFile) +extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) //************************************************************************************** { DWORD_PTR entrypoint = 0; @@ -111,7 +111,7 @@ void ScyllaInit(HANDLE hProcess) } //************************************************************************************** -extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP, BOOL CapeFile) +extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) //************************************************************************************** { DWORD_PTR entrypoint = 0; @@ -224,7 +224,7 @@ bool isIATOutsidePeImage (DWORD_PTR addressIAT) } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP, BOOL CapeFile) +extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) //************************************************************************************** { DWORD addressIAT, sizeIAT; @@ -392,7 +392,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP, BOOL CapeFile) } //************************************************************************************** -extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP, BOOL CapeFile) +extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) //************************************************************************************** { BOOL isAfter; @@ -438,7 +438,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D DoOutputDebugString(TEXT("Module entry point VA is 0x%x"), modBase + entrypointRVA); // Let's dump then fix the dump on disk - if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE, CapeFile)) + if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE)) { DoOutputDebugString("Module image dump success %s", CapeOutputPath); } @@ -526,7 +526,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D importRebuild.enableNewIatInSection(addressIAT, sizeIAT); } - if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList, CapeFile)) + if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList)) { DoOutputDebugString("Import table rebuild success.\n"); delete peFile; @@ -535,7 +535,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D else { DoOutputDebugString("Import table rebuild failed, falling back to unfixed dump.\n"); - peFile->savePeFileToDisk(NULL, CapeFile); + peFile->savePeFileToDisk(NULL); } } else diff --git a/cuckoomon.c b/cuckoomon.c index 45af4a6..f28128b 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -270,6 +270,8 @@ static hook_t g_hooks[] = { // won't end up logging. We need another hook type which logs the hook and then every function // called by that hook (modulo perhaps some blacklisted functions for this specific hook type) //HOOK(user32, EnumWindows), + HOOK(user32, PostMessageA), + HOOK(user32, PostMessageW), HOOK(user32, SendNotifyMessageA), HOOK(user32, SendNotifyMessageW), HOOK(user32, SetWindowLongA), @@ -632,7 +634,7 @@ VOID CALLBACK DllLoadNotification( _In_opt_ PVOID Context) { PWCHAR dllname; - COPY_UNICODE_STRING(library, NotificationData->Loaded.BaseDllName); + COPY_UNICODE_STRING(library, NotificationData->Loaded.FullDllName); if (g_config.debug) { int ret = 0; @@ -775,10 +777,9 @@ LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *Excepti if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) return EXCEPTION_CONTINUE_SEARCH; -#ifndef _WIN64 + if (DEBUGGER_ENABLED && ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) return CAPEExceptionFilter(ExceptionInfo); -#endif hook_disable(); @@ -931,6 +932,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) #ifdef STANDALONE // initialise CAPE + resolve_runtime_apis(); init_CAPE(); return TRUE; #endif diff --git a/hook_process.c b/hook_process.c index 9c10c1d..8d8a96d 100644 --- a/hook_process.c +++ b/hook_process.c @@ -287,7 +287,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, char DevicePath[MAX_PATH]; unsigned int PathLength; int pid = 0; - if(ClientId != NULL) { __try { @@ -308,13 +307,13 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); - if (NT_SUCCESS(ret) && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ + if (NT_SUCCESS(ret)){// && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ CurrentInjectionInfo = GetInjectionInfo(pid); if (CurrentInjectionInfo == NULL) { // First call for this process, create new info CurrentInjectionInfo = CreateInjectionInfo(pid); - DoOutputDebugString("NtOpenProcess: Injection info created for pid 0x%x.\n", pid); + DoOutputDebugString("NtOpenProcess: Injection info created for pid %d.\n", pid); if (CurrentInjectionInfo == NULL) { @@ -330,9 +329,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); - if (!PathLength) + if (!PathLength) + { DoOutputErrorString("NtOpenProcess: Error obtaining target process name"); - + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) DoOutputErrorString("NtOpenProcess: Error translating target process path"); } @@ -352,16 +353,15 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, ) { NTSTATUS ret; struct InjectionInfo *CurrentInjectionInfo; - PINJECTIONSECTIONVIEW CurrentSectionView; - + DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); CurrentInjectionInfo = GetInjectionInfo(pid); - if (CurrentInjectionInfo && (CurrentInjectionInfo->WriteDetected)) + if (CurrentInjectionInfo) { - if (CurrentInjectionInfo->ImageDumped == FALSE) + if (CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); @@ -376,57 +376,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, else DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); } - } - else if (CurrentInjectionInfo) - { - CurrentSectionView = SectionViewList; - while (CurrentSectionView) - { - if (CurrentSectionView->TargetProcessId == pid) - { - if (CurrentSectionView->LocalView) - { - if (ScanForPE(CurrentSectionView->LocalView, 1, NULL)) - { - DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d (by section view), local view at 0x%x.\n", pid, CurrentSectionView->LocalView); - - if (CurrentInjectionInfo->ImageDumped == FALSE) - { - SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)CurrentSectionView->LocalView); - - if (CurrentInjectionInfo->ImageDumped) - { - DoOutputDebugString("NtResumeProcess hook: Dumped PE image from buffer.\n"); - DropSectionView(CurrentSectionView); - } - else - DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); - } - } - else - { - DoOutputDebugString("NtResumeProcess hook: invalid PE file in buffer, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = pid; - - if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) - { - DoOutputDebugString("NtResumeProcess hook: Dumped shared section view."); - DropSectionView(CurrentSectionView); - } - else - DoOutputDebugString("NtResumeProcess hook: Failed to dump shared section view."); - } - } - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } + DumpSectionViewsForPid(pid); } ret = Old_NtResumeProcess(ProcessHandle); @@ -584,14 +535,18 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, __in UINT InheritDisposition, __in ULONG AllocationType, __in ULONG Win32Protect - ) { +) { struct InjectionInfo *CurrentInjectionInfo; struct InjectionSectionView *CurrentSectionViewInfo; + char DevicePath[MAX_PATH]; + unsigned int PathLength; + DWORD BufferSize = MAX_PATH; NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); - DWORD pid = pid_from_process_handle(ProcessHandle); + + DWORD pid = pid_from_process_handle(ProcessHandle); CurrentInjectionInfo = GetInjectionInfo(pid); @@ -612,9 +567,51 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); } else + { DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); + } } + else if (!CurrentInjectionInfo && pid != GetCurrentProcessId()) + { + CurrentInjectionInfo = CreateInjectionInfo(pid); + + DoOutputDebugString("NtMapViewOfSection hook: Injection info created for pid %d.\n", pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("NtMapViewOfSection hook: Cannot create new injection info - FATAL ERROR.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = ProcessHandle; + CurrentInjectionInfo->ProcessId = pid; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); + + if (!PathLength) + { + DoOutputErrorString("NtMapViewOfSection hook: Error obtaining target process name"); + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("NtMapViewOfSection hook: Error translating target process path"); + + CurrentSectionViewInfo = AddSectionView(SectionHandle, *BaseAddress, *ViewSize); + if (CurrentSectionViewInfo) + { + CurrentSectionViewInfo->TargetProcessId = pid; + DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); + } + else + DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); + } + } + LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); diff --git a/hook_thread.c b/hook_thread.c index c6a07f5..c5c07f0 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -310,7 +310,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, __out_opt ULONG *SuspendCount ) { struct InjectionInfo *CurrentInjectionInfo; - PINJECTIONSECTIONVIEW CurrentSectionView; + DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; @@ -319,9 +319,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, CurrentInjectionInfo = GetInjectionInfo(pid); - if (CurrentInjectionInfo && (CurrentInjectionInfo->WriteDetected)) + DoOutputDebugString("NtResumeThread hook: CurrentInjectionInfo 0x%x (pid %d).\n", CurrentInjectionInfo, pid); + + if (CurrentInjectionInfo) { - if (CurrentInjectionInfo->ImageDumped == FALSE) + if (CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = pid; @@ -337,58 +339,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, else DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); } - } - else if (CurrentInjectionInfo) - { - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - if (CurrentSectionView->TargetProcessId == pid) - { - DoOutputDebugString("NtResumeThread hook: Mapped section view in target process %d at 0x%x, about to scan.\n", CurrentSectionView->LocalView); - - if (CurrentSectionView->LocalView) - { - if (ScanForPE(CurrentSectionView->LocalView, CurrentSectionView->ViewSize, NULL)) - { - DoOutputDebugString("NtResumeThread hook: Dumping hollowed process %d (by section view), local view at 0x%x.\n", pid, CurrentSectionView->LocalView); - - CapeMetaData->DumpType = INJECTION_PE; - - CapeMetaData->TargetPid = pid; - - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)CurrentSectionView->LocalView); - - if (CurrentInjectionInfo->ImageDumped) - { - DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); - DropSectionView(CurrentSectionView); - } - else - DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); - } - else - { - DoOutputDebugString("NtResumeThread hook: invalid PE file in buffer, attempting raw dump at 0x%x size 0x%x.\n", CurrentSectionView->LocalView, CurrentSectionView->ViewSize); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = pid; - - if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) - { - DoOutputDebugString("NtResumeThread hook: Dumped shared section view."); - DropSectionView(CurrentSectionView); - } - else - DoOutputDebugString("NtResumeThread hook: Failed to dump shared section view."); - } - } - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } + + DumpSectionViewsForPid(pid); } ret = Old_NtResumeThread(ThreadHandle, SuspendCount); diff --git a/hook_window.c b/hook_window.c index fef4853..2a0644c 100644 --- a/hook_window.c +++ b/hook_window.c @@ -22,6 +22,10 @@ along with this program. If not, see . #include "misc.h" #include "pipe.h" #include "log.h" +#include "CAPE\CAPE.h" + +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); typedef DWORD (WINAPI * __GetWindowThreadProcessId)( __in HWND hWnd, @@ -140,6 +144,54 @@ HOOKDEF(HWND, WINAPI, FindWindowExW, return ret; } +HOOKDEF(BOOL, WINAPI, PostMessageA, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +) { + BOOL ret; + /* + DWORD pid; + lasterror_t lasterror; + + get_lasterrors(&lasterror); + GetWindowThreadProcessId(hWnd, &pid); + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + set_lasterrors(&lasterror); + */ + ret = Old_PostMessageA(hWnd, Msg, wParam, lParam); + + LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); + + return ret; +} + +HOOKDEF(BOOL, WINAPI, PostMessageW, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +) { + BOOL ret; + /* + DWORD pid; + lasterror_t lasterror; + + get_lasterrors(&lasterror); + GetWindowThreadProcessId(hWnd, &pid); + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + set_lasterrors(&lasterror); + */ + ret = Old_PostMessageW(hWnd, Msg, wParam, lParam); + + LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); + + return ret; +} + HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, _In_ HWND hWnd, _In_ UINT Msg, @@ -169,7 +221,7 @@ HOOKDEF(BOOL, WINAPI, SendNotifyMessageW, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam - ) { +) { BOOL ret; /* DWORD pid; @@ -206,6 +258,7 @@ HOOKDEF(LONG, WINAPI, SetWindowLongA, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; + DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -236,6 +289,7 @@ HOOKDEF(LONG_PTR, WINAPI, SetWindowLongPtrA, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; + DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -266,6 +320,7 @@ HOOKDEF(LONG, WINAPI, SetWindowLongW, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; + DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -297,6 +352,7 @@ HOOKDEF(LONG_PTR, WINAPI, SetWindowLongPtrW, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; + DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); diff --git a/hooks.h b/hooks.h index f144ec1..f2921c5 100644 --- a/hooks.h +++ b/hooks.h @@ -761,6 +761,20 @@ extern HOOKDEF(BOOL, WINAPI, EnumWindows, _In_ LPARAM lParam ); +extern HOOKDEF(BOOL, WINAPI, PostMessageA, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +); + +extern HOOKDEF(BOOL, WINAPI, PostMessageW, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +); + extern HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, _In_ HWND hWnd, _In_ UINT Msg, From 6ca2a17cd29f632738924257d9b4b1d923f615ff Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Apr 2017 16:17:43 +0000 Subject: [PATCH 10/39] Updates merged from other branches, including removal of OutputDebugString calls in Output.c. --- CAPE/CAPE.c | 333 ++++++++++++++++++++++++---- CAPE/CAPE.h | 44 ++-- CAPE/Debugger.c | 379 +++++++++++++++++++++++++++++--- CAPE/Debugger.h | 35 +++ CAPE/Output.c | 22 +- CAPE/Scylla/ImportRebuilder.cpp | 7 +- CAPE/Scylla/ImportRebuilder.h | 1 - CAPE/Scylla/ImportsHandling.cpp | 4 +- CAPE/Scylla/ImportsHandling.h | 8 +- CAPE/Scylla/PeParser.cpp | 20 +- CAPE/Scylla/PeParser.h | 5 +- CAPE/ScyllaHarness.cpp | 301 +++++++++++++++++++------ config.c | 2 +- cuckoomon.vcxproj | 4 +- hook_file.c | 3 - hook_process.c | 26 +-- hook_special.c | 2 +- hook_sync.c | 40 ++++ hook_thread.c | 27 ++- hooks.h | 58 ++++- log.h | 3 + ntapi.h | 8 +- 22 files changed, 1115 insertions(+), 217 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index a6d5789..0ab9a87 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -47,6 +47,7 @@ extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buf extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern void CapeOutputFile(LPCTSTR lpOutputFile); +extern int IsPeImageVirtual(DWORD_PTR Buffer); extern int ScyllaDumpCurrentProcess(DWORD NewOEP); extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); extern int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP); @@ -77,10 +78,10 @@ void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned in return; } + //********************************************************************************************************************************* BOOL TranslatePathFromDeviceToLetter(__in char *DeviceFilePath, __out char* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize) //********************************************************************************************************************************* - { char DriveStrings[BUFSIZE]; DriveStrings[0] = '\0'; @@ -263,7 +264,6 @@ PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) DWORD CurrentProcessId; PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; - while (CurrentInjectionInfo) { CurrentProcessId = CurrentInjectionInfo->ProcessId; @@ -478,8 +478,6 @@ void DumpSectionViewsForPid(DWORD Pid) LPVOID PEPointer = NULL; BOOL Dumped = FALSE; - DoOutputDebugString("DumpSectionViewsForPid: DEEEEEEEEEEEEEEEEEEEBUG.\n"); - CurrentInjectionInfo = GetInjectionInfo(Pid); if (CurrentInjectionInfo == NULL) @@ -506,8 +504,9 @@ void DumpSectionViewsForPid(DWORD Pid) CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = Pid; + CapeMetaData->Address = PEPointer; - if (DumpImageInCurrentProcess((DWORD)PEPointer)) + if (DumpImageInCurrentProcess((DWORD_PTR)PEPointer)) { DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); Dumped = TRUE; @@ -583,7 +582,8 @@ char* GetName() if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) { DoOutputDebugString("GetName: Error, CAPE destination path too long."); - free(OutputFilename); free(FullPathName); + free(OutputFilename); + free(FullPathName); return 0; } @@ -594,7 +594,8 @@ char* GetName() if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) { DoOutputDebugString("GetName: Error creating output directory"); - free(OutputFilename); free(FullPathName); + free(OutputFilename); + free(FullPathName); return 0; } @@ -781,6 +782,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) for (k=0; kAddress = DecryptedBuffer; DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); free(DecryptedBuffer); @@ -853,6 +855,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) for (k=0; kAddress = DecryptedBuffer; DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); free(DecryptedBuffer); @@ -896,7 +899,8 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) for (k=0; kAddress = DecryptedBuffer; DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); free(DecryptedBuffer); @@ -953,6 +957,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) for (k=0; kAddress = DecryptedBuffer; DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); free(DecryptedBuffer); @@ -970,7 +975,40 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) } //************************************************************************************** -int ScanForNonZero(LPCVOID Buffer, unsigned int Size) +int ScanPageForNonZero(LPVOID Address) +//************************************************************************************** +{ + unsigned int p; + DWORD_PTR AddressOfPage; + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("Failed to obtain system page size.\n"); + return 0; + } + + AddressOfPage = ((DWORD_PTR)Address/SystemInfo.dwPageSize)*SystemInfo.dwPageSize; + + __try + { + for (p=0; pe_lfanew == 0) @@ -1043,27 +1079,228 @@ int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset) if (Offset) { - *Offset = (LPCVOID)((char*)Buffer+p); + *Offset = (LPVOID)((char*)Buffer+p); } - DoOutputDebugString("ScanForPE: PE image located at: 0x%x\n", p); + DoOutputDebugString("ScanForPE: PE image located at: 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); return 1; } } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputDebugString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); + DoOutputDebugString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); + return 0; + } + } + + DoOutputDebugString("ScanForPE: No PE image located at 0x%x.\n", Buffer); + return 0; +} + +//************************************************************************************** +int ScanForDisguisedPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset) +//************************************************************************************** +{ + unsigned int p; + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; + + if (Size == 0) + { + DoOutputDebugString("ScanForDisguisedPE: Error, zero size given\n"); + return 0; + } + + for (p=0; p < Size - 0x41; p++) // we want to stop short of the look-ahead to e_lfanew + { + __try + { + pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer+p); + + if (!pDosHeader->e_lfanew || (ULONG)pDosHeader->e_lfanew > Size-p || pDosHeader->e_lfanew > PE_HEADER_LIMIT) + { + continue; + } + + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) + { + continue; + } + + // Basic requirements + if + ( + pNtHeader->FileHeader.Machine == 0 || + pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || + pNtHeader->OptionalHeader.SizeOfHeaders == 0 || + pNtHeader->OptionalHeader.FileAlignment == 0 + ) + { + DoOutputDebugString("ScanForDisguisedPE: Basic requirements failure.\n"); + continue; + } + + if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) + { + DoOutputDebugString("IsDisguisedPE: Characteristics bad."); + continue; + } + + if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) + { + DoOutputDebugString("IsDisguisedPE: SizeOfOptionalHeader bad."); + continue; + } + + if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) + { + DoOutputDebugString("IsDisguisedPE: FileAlignment invalid."); + continue; + } + + if (Offset) + { + *Offset = (LPVOID)((char*)Buffer+p); + } + + DoOutputDebugString("ScanForDisguisedPE: PE image located at: 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); + + return 1; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("ScanForDisguisedPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); + return 0; + } + } + + DoOutputDebugString("ScanForDisguisedPE: No PE image located in range 0x%x-0x%x.\n", Buffer, (DWORD_PTR)Buffer + Size); + return 0; +} + +//************************************************************************************** +int IsDisguisedPE(LPVOID Buffer, unsigned int Size) +//************************************************************************************** +{ + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; + + if (Size == 0) + { + DoOutputDebugString("IsDisguisedPE: Error, zero size given\n"); + return 0; + } + + __try + { + pDosHeader = (PIMAGE_DOS_HEADER)Buffer; + + if (!pDosHeader->e_lfanew || pDosHeader->e_lfanew > PE_HEADER_LIMIT) + { + //DoOutputDebugString("IsDisguisedPE: e_lfanew bad."); + return 0; + } + + // more tests to establish it's PE + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + { + // Basic requirements + DoOutputDebugString("IsDisguisedPE: Basic requirements bad."); + return 0; + } + + if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) + { + DoOutputDebugString("IsDisguisedPE: Characteristics bad."); + return 0; + } + + if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) + { + DoOutputDebugString("IsDisguisedPE: SizeOfOptionalHeader bad."); return 0; } + + if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) + { + DoOutputDebugString("IsDisguisedPE: OptionalHeader.Magic bad."); + return 0; + } + + // To pass the above tests it should now be safe to assume it's a PE image + return 1; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("IsDisguisedPE: Exception occured reading region at 0x%x\n", (DWORD_PTR)(Buffer)); + return 0; } - DoOutputDebugString("ScanForPE: No PE image located\n"); + DoOutputDebugString("IsDisguisedPE: No PE image located\n"); return 0; } //************************************************************************************** -int DumpMemory(LPCVOID Buffer, unsigned int Size) +BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) +//************************************************************************************** +{ + PBYTE PEImage; + PIMAGE_DOS_HEADER pDosHeader; + + BOOL RetVal = FALSE; + LPVOID PEPointer = Buffer; + + DoOutputDebugString("DumpPEsInRange: Scanning range 0x%x - 0x%x.\n", Buffer, (BYTE*)Buffer + Size); + + while (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) + { + pDosHeader = (PIMAGE_DOS_HEADER)PEPointer; + if (*(WORD*)PEPointer != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) + { + // We want to fix the PE header in the dump (for e.g. disassembly etc) + PEImage = (BYTE*)malloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); + memcpy(PEImage, PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); + pDosHeader = (PIMAGE_DOS_HEADER)PEImage; + + *(WORD*)PEImage = IMAGE_DOS_SIGNATURE; + *(DWORD*)(PEImage + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; + + SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); + + if (DumpImageInCurrentProcess((DWORD)PEImage)) + { + DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); + RetVal = TRUE; + } + else + DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); + } + else + { + SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); + + if (DumpImageInCurrentProcess((DWORD)PEPointer)) + { + DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); + RetVal = TRUE; + } + else + DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); + } + + ((BYTE*)PEPointer)++; + } + + return RetVal; +} + +//************************************************************************************** +int DumpMemory(LPVOID Buffer, unsigned int Size) //************************************************************************************** { char *FullPathName; @@ -1072,7 +1309,7 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) LPVOID BufferCopy; FullPathName = GetName(); - + hOutputFile = CreateFile(FullPathName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (hOutputFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) @@ -1114,16 +1351,21 @@ int DumpMemory(LPCVOID Buffer, unsigned int Size) if (FALSE == WriteFile(hOutputFile, BufferCopy, Size, &dwBytesWritten, NULL)) { DoOutputErrorString("DumpMemory: WriteFile error on CAPE output file"); - free(FullPathName); free(BufferCopy); + free(FullPathName); + free(BufferCopy); return 0; } CloseHandle(hOutputFile); + + CapeMetaData->Address = Buffer; + CapeMetaData->Size = Size; CapeOutputFile(FullPathName); // We can free the filename buffers - free(FullPathName); free(BufferCopy); + free(FullPathName); + free(BufferCopy); return 1; } @@ -1168,10 +1410,12 @@ int DumpCurrentProcess() } //************************************************************************************** -int DumpModuleInCurrentProcess(DWORD ModuleBase) +int DumpModuleInCurrentProcess(DWORD_PTR ModuleBase) //************************************************************************************** { - if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), ModuleBase, 0)) + SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); + + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), ModuleBase, 0)) { DumpCount++; return 1; @@ -1179,8 +1423,9 @@ int DumpModuleInCurrentProcess(DWORD ModuleBase) return 0; } + //************************************************************************************** -int DumpImageInCurrentProcess(DWORD ImageBase) +int DumpImageInCurrentProcess(DWORD_PTR ImageBase) //************************************************************************************** { PIMAGE_DOS_HEADER pDosHeader; @@ -1222,17 +1467,12 @@ int DumpImageInCurrentProcess(DWORD ImageBase) return 0; } - // we perform a couple of tests to determine whether this is a 'raw' or 'virtual' image - // first we check if the SizeOfHeaders is a multiple of FileAlignment - if (pNtHeader->OptionalHeader.SizeOfHeaders % pNtHeader->OptionalHeader.FileAlignment - // let's also check if section 1 actually begins after the headers, i.e. raw image - || (*(DWORD*)((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders - 4) == 0) // end of header is zero - && (*(DWORD*)((BYTE*)ImageBase + pNtHeader->OptionalHeader.SizeOfHeaders) != 0)) // beginning of raw section 1 is non-zero + if (IsPeImageVirtual(ImageBase) == FALSE) { - // looks like a 'raw'/'file' image, i.e. not loaded + DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump 'raw' PE image.\n"); + if (ScyllaDumpPE(ImageBase)) { - DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump 'raw' PE image.\n"); DumpCount++; return 1; } @@ -1244,14 +1484,13 @@ int DumpImageInCurrentProcess(DWORD ImageBase) } } - // we should be dealing with a 'loaded' module image now, - // not a 'raw' file image, so try dumping this way first DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump virtual PE image.\n"); if (!ScyllaDumpProcess(GetCurrentProcess(), ImageBase, 0)) - // if this fails, let's try dumping 'raw' just in case - if (!ScyllaDumpPE(ImageBase)) - return 0; + { + DoOutputDebugString("DumpImageInCurrentProcess: Failed to dump PE as virtual image.\n"); + return 0; + } DumpCount++; return 1; @@ -1271,9 +1510,11 @@ int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase) } //************************************************************************************** -int DumpPE(LPCVOID Buffer) +int DumpPE(LPVOID Buffer) //************************************************************************************** { + SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)Buffer); + if (DumpCount < DUMP_MAX && ScyllaDumpPE((DWORD_PTR)Buffer)) { DumpCount++; @@ -1313,27 +1554,37 @@ void init_CAPE() { // Initialise CAPE global variables // +#ifndef STANDALONE CapeMetaData = (PCAPEMETADATA)malloc(sizeof(CAPEMETADATA)); CapeMetaData->Pid = GetCurrentProcessId(); CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); + // Specific to Injection package: + CapeMetaData->DumpType = INJECTION_SHELLCODE; // default value for now, may be changed to INJECTION_PE + CapeMetaData->Address = NULL; + DumpCount = 0; // This flag controls whether a dump is automatically // made at the end of a process' lifetime. // It is normally only set in the base packages, // or upon submission. (This overrides submission.) - g_config.procmemdump = 0; + // g_config.procmemdump = 0; // Cuckoo debug output level for development (0=none, 2=max) - g_config.debug = 2; - -#ifndef _WIN64 + // g_config.debug = 2; +#endif + // Start the debugger thread // if required by package if (DEBUGGER_ENABLED) launch_debugger(); + +#ifdef _WIN64 + DoOutputDebugString("CAPE initialised (64-bit).\n"); +#else + DoOutputDebugString("CAPE initialised (32-bit).\n"); #endif return; diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index c7fcac7..8a510a5 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -2,20 +2,26 @@ extern HMODULE s_hInst; extern WCHAR s_wzDllPath[MAX_PATH]; extern CHAR s_szDllPath[MAX_PATH]; BOOL TranslatePathFromDeviceToLetter(__in TCHAR *DeviceFilePath, __out TCHAR* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize); -int DumpMemory(LPCVOID Buffer, unsigned int Size); -extern int DumpCurrentProcessNewEP(DWORD NewEP); -extern int DumpCurrentProcess(); -extern int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); -extern int DumpPE(LPCVOID Buffer); -extern int ScyllaDumpPE(DWORD_PTR Buffer); -int ScanForNonZero(LPCVOID Buffer, unsigned int Size); -int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); -int DumpImageInCurrentProcess(DWORD ImageBase); +int DumpMemory(LPVOID Buffer, SIZE_T Size); +BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size); +int DumpCurrentProcessNewEP(DWORD NewEP); +int DumpCurrentProcess(); +int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); +int DumpPE(LPVOID Buffer); +int ScyllaDumpPE(DWORD_PTR Buffer); +int ScanForNonZero(LPVOID Buffer, unsigned int Size); +int ScanPageForNonZero(LPVOID Address); +int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); +int ScanForDisguisedPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); +int IsDisguisedPE(LPVOID Buffer, unsigned int Size); +int DumpImageInCurrentProcess(DWORD_PTR ImageBase); void DumpSectionViewsForPid(DWORD Pid); unsigned int DumpSize; +SYSTEM_INFO SystemInfo; //Global switch for debugger -#define DEBUGGER_ENABLED 0 +#define DEBUGGER_ENABLED 0 +#define GUARD_PAGES_ENABLED 0 typedef struct InjectionSectionView { @@ -26,6 +32,10 @@ typedef struct InjectionSectionView struct InjectionSectionView *NextSectionView; } INJECTIONSECTIONVIEW, *PINJECTIONSECTIONVIEW; +PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); +PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); +BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); + typedef struct InjectionInfo { int ProcessId; @@ -34,7 +44,7 @@ typedef struct InjectionInfo DWORD_PTR EntryPoint; BOOL WriteDetected; BOOL ImageDumped; - LPCVOID BufferBase; + LPVOID BufferBase; unsigned int BufferSizeOfImage; HANDLE SectionHandle; // struct InjectionSectionView *SectionViewList; @@ -87,7 +97,7 @@ typedef struct CapeMetadata DWORD DumpType; char* TargetProcess; // For injection DWORD TargetPid; // " - PVOID Address; // For shellcode + PVOID Address; // For shellcode/modules SIZE_T Size; // " } CAPEMETADATA, *PCAPEMETADATA; @@ -108,9 +118,11 @@ enum { EXTRACTION_SHELLCODE = 9, PLUGX_PAYLOAD = 0x10, - PLUGX_CONFIG = 0x11 + PLUGX_CONFIG = 0x11, + + EVILGRAB_PAYLOAD = 0x14, + EVILGRAB_DATA = 0x15 }; -PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); -PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); -BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); +HANDLE EvilGrabRegHandle; + diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 39cab35..64b2dd1 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -82,10 +82,13 @@ DWORD MainThreadId; struct ThreadBreakpoints *MainThreadBreakpointList; LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; SINGLE_STEP_HANDLER SingleStepHandler; -DWORD WINAPI PipeThread(LPVOID lpParam); +GUARD_PAGE_HANDLER GuardPageHandler; HANDLE hParentPipe; +extern ULONG_PTR g_our_dll_base; +extern DWORD g_our_dll_size; extern LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); + extern unsigned int address_is_in_stack(DWORD Address); extern BOOL WoW64fix(void); extern BOOL WoW64PatchBreakpoint(unsigned int Register); @@ -104,6 +107,302 @@ BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL ClearSingleStepMode(PCONTEXT Context); unsigned int TrapIndex; +//************************************************************************************** +BOOL IsInGuardPages(PVOID Address) +//************************************************************************************** +{ + PGUARDPAGES CurrentGuardPages = GuardPageList; + + if (GuardPageList == NULL) + return FALSE; + + while (CurrentGuardPages) + { + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) + return TRUE; + + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + return FALSE; +} + +//************************************************************************************** +PGUARDPAGES GetGuardPages(PVOID Address) +//************************************************************************************** +{ + PGUARDPAGES CurrentGuardPages = GuardPageList; + + if (Address == NULL) + { + DoOutputDebugString("GetGuardPages: NULL passed as argument - error.\n"); + return FALSE; + } + + if (GuardPageList == NULL) + { + DoOutputDebugString("GetGuardPages: failed to obtain initial guard page list.\n"); + return FALSE; + } + + while (CurrentGuardPages) + { + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) + return CurrentGuardPages; + + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + DoOutputDebugString("GetGuardPages: failed to find guard pages in list.\n"); + + return NULL; +} + +//************************************************************************************** +BOOL DropGuardPages(PGUARDPAGES GuardPages) +//************************************************************************************** +{ + // DEBUG + DoOutputDebugString("DropGuardPages entry.\n"); + + PGUARDPAGES CurrentGuardPages, PreviousGuardPages; + + if (GuardPages == NULL) + { + DoOutputDebugString("DropGuardPages: NULL passed as argument - error.\n"); + return FALSE; + } + + PreviousGuardPages = NULL; + + if (GuardPageList == NULL) + { + DoOutputDebugString("DropGuardPages: failed to obtain initial guard page list.\n"); + return FALSE; + } + + CurrentGuardPages = GuardPageList; + + while (CurrentGuardPages) + { + DoOutputDebugString("DropGuardPages: CurrentGuardPages 0x%x.\n", CurrentGuardPages); + + if (CurrentGuardPages == GuardPages) + { + DoOutputDebugString("DropGuardPages: About to unlink.\n"); + // Unlink this from the list and free the memory + if (PreviousGuardPages && CurrentGuardPages->NextGuardPages) + { + DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + PreviousGuardPages->NextGuardPages = CurrentGuardPages->NextGuardPages; + } + else if (PreviousGuardPages && CurrentGuardPages->NextGuardPages == NULL) + { + DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from the end of the guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + PreviousGuardPages->NextGuardPages = NULL; + } + else if (!PreviousGuardPages) + { + DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from the head of the guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + GuardPageList = NULL; + } + + DoOutputDebugString("DropGuardPages: about to free the memory!\n"); + free(CurrentGuardPages); + + return TRUE; + } + + PreviousGuardPages = CurrentGuardPages; + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + DoOutputDebugString("DropGuardPages: failed to find guard pages in list.\n"); + + return FALSE; +} + +//************************************************************************************** +BOOL ReinstateGuardPages(PGUARDPAGES GuardPages) +//************************************************************************************** +{ + DWORD OldProtect; + BOOL GuardPagesFound = FALSE; + PGUARDPAGES CurrentGuardPages = GuardPageList; + MEMORY_BASIC_INFORMATION MemInfo; + SIZE_T MatchingRegionSize; + + if (GuardPageList == NULL) + return FALSE; + + while (CurrentGuardPages) + { + if (GuardPages->BaseAddress == CurrentGuardPages->BaseAddress) + GuardPagesFound = TRUE; + + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + if (GuardPagesFound == FALSE) + { + DoOutputDebugString("ReinstateGuardPages: failed to locate guard page(s) in guard page list.\n"); + return FALSE; + } + + MatchingRegionSize = VirtualQuery(GuardPages->BaseAddress, &MemInfo, GuardPages->RegionSize); + + if (!MatchingRegionSize) + { + DoOutputErrorString("ReinstateGuardPages: failed to query guard page(s) status in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + return FALSE; + } + + if (MatchingRegionSize == GuardPages->RegionSize && MemInfo.Protect & PAGE_GUARD) + { + DoOutputDebugString("ReinstateGuardPages: guard page(s) already set in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + return FALSE; + } + + if (!VirtualProtect(GuardPages->BaseAddress, GuardPages->RegionSize, GuardPages->Protect | PAGE_GUARD, &OldProtect)) + { + DoOutputErrorString("ReinstateGuardPages: failed to reinstate guard page(s) on region 0x%x size 0x%x", GuardPages->BaseAddress, GuardPages->RegionSize); + return FALSE; + } + + // This is unreliable if some pages no longer have PAGE_GUARD, + // i.e. they have been touched, while others haven't + //if (OldProtect != GuardPages->Protect) + //{ + // DoOutputDebugString("ReinstateGuardPages error: inconsistency in protecton flags for region 0x%x-0x%x - OldProtect = 0x%x, GuardPages->Protect = 0x%x\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize, OldProtect, GuardPages->Protect); + //} + + return TRUE; +} + +//************************************************************************************** +BOOL DisableGuardPages(PGUARDPAGES GuardPages) +//************************************************************************************** +{ + DWORD OldProtect; + BOOL GuardPagesFound = FALSE; + PGUARDPAGES CurrentGuardPages = GuardPageList; + MEMORY_BASIC_INFORMATION MemInfo; + SIZE_T MatchingRegionSize; + + if (GuardPageList == NULL) + return FALSE; + + while (CurrentGuardPages) + { + if (GuardPages->BaseAddress == CurrentGuardPages->BaseAddress) + GuardPagesFound = TRUE; + + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + if (GuardPagesFound == FALSE) + { + DoOutputDebugString("DisableGuardPages: failed to locate guard page(s) in guard page list.\n"); + return FALSE; + } + + MatchingRegionSize = VirtualQuery(GuardPages->BaseAddress, &MemInfo, GuardPages->RegionSize); + + if (!MatchingRegionSize) + { + DoOutputErrorString("DisableGuardPages: failed to query guard page(s) status in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + return FALSE; + } + + if (MatchingRegionSize == GuardPages->RegionSize && !(MemInfo.Protect & PAGE_GUARD)) + { + DoOutputDebugString("DisableGuardPages: guard page(s) not set in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + return FALSE; + } + + if (!VirtualProtect(GuardPages->BaseAddress, GuardPages->RegionSize, GuardPages->Protect, &OldProtect)) + { + DoOutputErrorString("DisableGuardPages: failed to disable guard page(s) on region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + return FALSE; + } + + //if (OldProtect != (GuardPages->Protect & PAGE_GUARD)) + //{ + // DoOutputDebugString("DisableGuardPages error: inconsistency in protecton flags for region 0x%x-0x%x - OldProtect = 0x%x, GuardPages->Protect = 0x%x\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize, OldProtect, GuardPages->Protect); + //} + + return TRUE; +} + +//************************************************************************************** +PGUARDPAGES CreateGuardPages() +//************************************************************************************** +{ + if (GuardPageList == NULL) + { + GuardPageList = ((struct GuardPages*)malloc(sizeof(struct GuardPages))); + + if (GuardPageList == NULL) + { + DoOutputDebugString("CreateGuardPages: failed to allocate memory for initial thread breakpoint list.\n"); + return NULL; + } + memset(GuardPageList, 0, sizeof(struct GuardPages)); + } + + return GuardPageList; +} + +//************************************************************************************** +BOOL AddGuardPages(PVOID Address, SIZE_T RegionSize, ULONG Protect) +//************************************************************************************** +{ + BOOL PageAlreadyGuarded; + PGUARDPAGES CurrentGuardPages, PreviousGuardPages; + + PreviousGuardPages = NULL; + + if (GuardPageList == NULL) + CreateGuardPages(); + + CurrentGuardPages = GuardPageList; + + while (CurrentGuardPages) + { + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) + PageAlreadyGuarded = TRUE; + else + PageAlreadyGuarded = FALSE; + + PreviousGuardPages = CurrentGuardPages; + CurrentGuardPages = CurrentGuardPages->NextGuardPages; + } + + if (PageAlreadyGuarded == FALSE) + { + // We haven't found it in the linked list, so create a new one + CurrentGuardPages = PreviousGuardPages; + + CurrentGuardPages->NextGuardPages = ((struct GuardPages*)malloc(sizeof(struct GuardPages))); + + if (CurrentGuardPages->NextGuardPages == NULL) + { + DoOutputDebugString("AddGuardPages: Failed to allocate new guard page struct.\n"); + return FALSE; + } + memset(CurrentGuardPages->NextGuardPages, 0, sizeof(struct GuardPages)); + + CurrentGuardPages->BaseAddress = Address; + CurrentGuardPages->RegionSize = RegionSize; + CurrentGuardPages->Protect = Protect; + CurrentGuardPages->WriteDetected = FALSE; + CurrentGuardPages->LastWriteAddress = NULL; + CurrentGuardPages->PagesDumped = FALSE; + } + + return TRUE; +} + //************************************************************************************** PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId) //************************************************************************************** @@ -480,6 +779,38 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) return EXCEPTION_CONTINUE_EXECUTION; } + // Page guard violations generate STATUS_GUARD_PAGE_VIOLATION + else if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION) + { + if (ExceptionInfo->ExceptionRecord->NumberParameters < 2) + { + DoOutputDebugString("CAPEExceptionFilter: Guard page exception with missing parameters, passing.\n"); + return EXCEPTION_CONTINUE_SEARCH; + } + + //DoOutputDebugString("Entering CAPEExceptionFilter: guarded page access at 0x%x by 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionInformation[1], ExceptionInfo->ExceptionRecord->ExceptionAddress); + + if (IsInGuardPages((PVOID)ExceptionInfo->ExceptionRecord->ExceptionInformation[1])) + { + if (GuardPageHandler) + { + if (GuardPageHandler(ExceptionInfo)) + return EXCEPTION_CONTINUE_EXECUTION; + else + return EXCEPTION_CONTINUE_SEARCH; + } + else + { + DoOutputDebugString("CAPEExceptionFilter: Error, no page guard handler for CAPE guard page exception.\n"); + return EXCEPTION_CONTINUE_EXECUTION; + } + } + else + { + DoOutputDebugString("CAPEExceptionFilter: exception at 0x%x not within CAPE guarded page.\n", ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); + return EXCEPTION_CONTINUE_SEARCH; + } + } else if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) { // This is likely our own DoOutputDebugString function! @@ -488,25 +819,21 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } else if (OriginalExceptionHandler) { + if ((ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress >= g_our_dll_base && (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress < (g_our_dll_base + g_our_dll_size)) + { + // This is a CAPE exception, likely from the try/catch blocks in buffer scans + return EXCEPTION_EXECUTE_HANDLER; + } + // As it's not a bp, and the sample has registered its own handler // we return EXCEPTION_EXECUTE_HANDLER - DoOutputDebugString("CAPEExceptionFilter: Non-breakpoint exception caught, re-registering sample's handler.\n"); + DoOutputDebugString("CAPEExceptionFilter: Non-breakpoint exception caught, passing to sample's handler.\n"); SetUnhandledExceptionFilter(OriginalExceptionHandler); return EXCEPTION_EXECUTE_HANDLER; } - else if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION) - { - // We want to know more about this class of crash - DoOutputDebugString("CAPEExceptionFilter: Access violation caught, turning up debug level to capture info.\n"); - g_config.debug = 2; - return cuckoomon_exception_handler(ExceptionInfo); - } - - // Some other exception occurred. Pass it to next handler - DoOutputDebugString("CAPEExceptionFilter: Passing non-breakpoint exception: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionCode); - return cuckoomon_exception_handler(ExceptionInfo); - //return EXCEPTION_CONTINUE_SEARCH; + // Some other exception occurred. Pass it to next handler. + return EXCEPTION_CONTINUE_SEARCH; } //************************************************************************************** @@ -1180,7 +1507,7 @@ BOOL ClearDebugRegister } if (DoCloseHandle == TRUE) - CloseHandle(hThread); + CloseHandle(hThread); return TRUE; } @@ -1440,6 +1767,7 @@ DWORD WINAPI ClearBreakpointThread(LPVOID lpParam) { DoOutputDebugString("ClearBreakpointThread: Sample thread was suspended, now resumed.\n"); } + DebugOutputThreadBreakpoints(); return TRUE; @@ -1483,6 +1811,7 @@ BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) if (ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) { DoOutputDebugString("ClearBreakpointWithoutThread: Call to ClearDebugRegister failed.\n"); + return FALSE; } //pBreakpointInfo->Register = 0; @@ -1621,7 +1950,7 @@ BOOL SetBreakpoint AddVectoredExceptionHandler(1, CAPEExceptionFilter); else OriginalExceptionHandler = SetUnhandledExceptionFilter(CAPEExceptionFilter); - + __try { hSetBreakpointThread = CreateThread( @@ -1851,7 +2180,7 @@ BOOL InitialiseDebugger(void) // Initialise any global variables ChildProcessId = 0; SingleStepHandler = NULL; - VECTORED_HANDLER = FALSE; + VECTORED_HANDLER = TRUE; #ifndef _WIN64 // Ensure wow64 patch is installed if needed @@ -1896,11 +2225,11 @@ __declspec (naked dllexport) void DebuggerInit(void) if (InitialiseDebugger() == FALSE) DoOutputDebugString("Debugger initialisation failure!\n"); -// Target specific code +// Package specific code #ifdef STANDALONE - SetNtAllocateVirtualMemoryBP(); + #endif -// End of target specific code +// End of package specific code DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); @@ -1927,9 +2256,9 @@ void DebuggerInit(void) else DoOutputDebugString("Debugger initialised, ESP = 0x%x\n", StackPointer); -// Target specific code +// Package specific code -// End of target specific code +// End of package specific code DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); @@ -2232,7 +2561,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati cbWritten = 0; cbReplyBytes = sizeof(DWORD_PTR); - // Write the reply to the pipe. + // Send the OEP to the new process fSuccess = WriteFile ( hParentPipe, @@ -2252,9 +2581,9 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati Context.ContextFlags = CONTEXT_ALL; #ifdef _WIN64 - Context.Rcx = RemoteFuncAddress; // eax holds new entry point + Context.Rcx = RemoteFuncAddress; // set the new EP to debugger_init #else - Context.Eax = RemoteFuncAddress; // eax holds new entry point + Context.Eax = RemoteFuncAddress; #endif if (!SetThreadContext(hThread, &Context)) diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 6bdb222..7e0fa41 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -7,6 +7,16 @@ void* CAPE_var; #define BP_RESERVED 0x02 #define BP_READWRITE 0x03 +#define EXTRACTION_MIN_SIZE 0x1001 + +typedef struct _EXCEPTION_REGISTRATION_RECORD { + struct _EXCEPTION_REGISTRATION_RECORD *Next; + PEXCEPTION_ROUTINE Handler; +} EXCEPTION_REGISTRATION_RECORD; + +typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD; + +PEXCEPTION_ROUTINE SEH_TopLevelHandler; LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); BOOL VECTORED_HANDLER; @@ -34,7 +44,23 @@ typedef struct ThreadBreakpoints struct ThreadBreakpoints *NextThreadBreakpoints; } THREADBREAKPOINTS, *PTHREADBREAKPOINTS; +typedef struct GuardPages +{ + PVOID BaseAddress; + SIZE_T RegionSize; + ULONG Protect; + BOOL WriteDetected; + PVOID LastWriteAddress; + BOOL ReadDetected; + PVOID LastReadBy; + BOOL PagesDumped; + struct GuardPages *NextGuardPages; +} GUARDPAGES, *PGUARDPAGES; + +struct GuardPages *GuardPageList; + typedef BOOL (cdecl *SINGLE_STEP_HANDLER)(struct _EXCEPTION_POINTERS*); +typedef BOOL (cdecl *GUARD_PAGE_HANDLER)(struct _EXCEPTION_POINTERS*); #ifdef __cplusplus extern "C" { @@ -75,10 +101,19 @@ BOOL ClearSingleStepMode(PCONTEXT Context); BOOL ContextClearAllBreakpoints(PCONTEXT Context); BOOL ClearAllBreakpoints(DWORD ThreadId); BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); +int CheckDebugRegister(HANDLE hThread, int Register); +int ContextCheckDebugRegister(CONTEXT Context, int Register); BOOL InitialiseDebugger(void); BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD CreationFlags); BOOL SendDebuggerMessage(DWORD Input); int launch_debugger(void); +BOOL IsInGuardPages(PVOID Address); +PGUARDPAGES GetGuardPages(PVOID Address); +BOOL DropGuardPages(PGUARDPAGES GuardPages); +PGUARDPAGES CreateGuardPagess(); +BOOL AddGuardPages(PVOID Address, SIZE_T RegionSize, ULONG Protect); +BOOL ReinstateGuardPages(PGUARDPAGES GuardPages); +BOOL DisableGuardPages(PGUARDPAGES GuardPages); #ifdef __cplusplus } diff --git a/CAPE/Output.c b/CAPE/Output.c index 0145527..80b7d10 100644 --- a/CAPE/Output.c +++ b/CAPE/Output.c @@ -41,11 +41,11 @@ void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...) memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); _vsntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, lpOutputString, args); +#ifdef STANDALONE OutputDebugString(DebugOutput); - +#else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "DEBUG:%s", DebugOutput); -#ifndef STANDALONE pipe(PipeOutput, strlen(PipeOutput)); #endif va_end(args); @@ -78,11 +78,11 @@ void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...) memset(ErrorOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(ErrorOutput, MAX_PATH, MAX_PATH, "Error %d (0x%x) - %s: %s", ErrorCode, ErrorCode, DebugOutput, (char*)lpMsgBuf); +#ifdef STANDALONE OutputDebugString(ErrorOutput); - +#else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "DEBUG:%s", ErrorOutput); -#ifndef STANDALONE pipe(PipeOutput, strlen(PipeOutput)); #endif @@ -153,13 +153,14 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, "Process dump output file: %s", lpOutputFile); +#ifdef STANDALONE OutputDebugString(DebugOutput); - +#else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "FILE_DUMP:%s", lpOutputFile); -#ifndef STANDALONE pipe(PipeOutput, strlen(PipeOutput)); #endif + } else if (CapeMetaData && CapeMetaData->DumpType != PROCDUMP) { @@ -190,12 +191,15 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) // Extraction-specific format _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n0x%x\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, (DWORD)CapeMetaData->Address); } - else if (CapeMetaData->DumpType == INJECTION_PE || CapeMetaData->DumpType == INJECTION_SHELLCODE) + else if (CapeMetaData->DumpType == INJECTION_PE || CapeMetaData->DumpType == INJECTION_SHELLCODE || CapeMetaData->DumpType == EVILGRAB_PAYLOAD || CapeMetaData->DumpType == EVILGRAB_DATA) { if (CapeMetaData->TargetProcess && CapeMetaData->ProcessPath) // Injection-specific format _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n%s\n%d\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->TargetProcess, CapeMetaData->TargetPid); } + else + if (CapeMetaData->ProcessPath) + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath); if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) { @@ -209,11 +213,11 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, "CAPE Output file: %s", lpOutputFile); +#ifdef STANDALONE OutputDebugString(DebugOutput); - +#else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "FILE_CAPE:%s", lpOutputFile); -#ifndef STANDALONE pipe(PipeOutput, strlen(PipeOutput)); #endif } diff --git a/CAPE/Scylla/ImportRebuilder.cpp b/CAPE/Scylla/ImportRebuilder.cpp index ca0906e..464913d 100644 --- a/CAPE/Scylla/ImportRebuilder.cpp +++ b/CAPE/Scylla/ImportRebuilder.cpp @@ -17,7 +17,7 @@ New Scylla section contains: extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList, BOOL CapeFile) +bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList) { bool retValue = false; @@ -97,11 +97,6 @@ bool ImportRebuilder::rebuildImportTable(const CHAR * newFilePath, std::map & moduleList) -{ - return rebuildImportTable(newFilePath, moduleList, TRUE); -} - bool ImportRebuilder::buildNewImportTable(std::map & moduleList) { createNewImportSection(moduleList); diff --git a/CAPE/Scylla/ImportRebuilder.h b/CAPE/Scylla/ImportRebuilder.h index 034de02..e9806ec 100644 --- a/CAPE/Scylla/ImportRebuilder.h +++ b/CAPE/Scylla/ImportRebuilder.h @@ -42,7 +42,6 @@ class ImportRebuilder : public PeParser { sizeOfJumpTable = 0; } - bool rebuildImportTable(const CHAR * newFilePath, std::map & moduleList, BOOL CapeFile); bool rebuildImportTable(const CHAR * newFilePath, std::map & moduleList); void enableOFTSupport(); void enableNewIatInSection(DWORD_PTR iatAddress, DWORD iatSize); diff --git a/CAPE/Scylla/ImportsHandling.cpp b/CAPE/Scylla/ImportsHandling.cpp index ba791f0..17c9cda 100644 --- a/CAPE/Scylla/ImportsHandling.cpp +++ b/CAPE/Scylla/ImportsHandling.cpp @@ -5,7 +5,7 @@ #include #include -#include "multitree.h" // CMultiSelectTreeViewCtrl +//#include "multitree.h" // CMultiSelectTreeViewCtrl //#include "resource.h" @@ -59,7 +59,7 @@ ImportsHandling::ImportsHandling() ImportsHandling::~ImportsHandling() { - TreeIcons.Destroy(); + //TreeIcons.Destroy(); } bool ImportsHandling::isModule(CTreeItem item) diff --git a/CAPE/Scylla/ImportsHandling.h b/CAPE/Scylla/ImportsHandling.h index 75299ed..8a7fcb4 100644 --- a/CAPE/Scylla/ImportsHandling.h +++ b/CAPE/Scylla/ImportsHandling.h @@ -74,10 +74,10 @@ class ImportsHandling CHAR stringBuffer[600]; //CMultiSelectTreeViewCtrl& TreeImports; - CImageList TreeIcons; - CIcon hIconCheck; - CIcon hIconWarning; - CIcon hIconError; + //CImageList TreeIcons; + //CIcon hIconCheck; + //CIcon hIconWarning; + //CIcon hIconError; // They have to be added to the image list in that order! enum Icon { diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index a427ca2..0c81e80 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -5,6 +5,8 @@ #pragma comment(lib, "Imagehlp.lib") +//#define DEBUG_COMMENTS + extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern "C" void CapeOutputFile(LPCTSTR lpOutputFile); @@ -307,9 +309,15 @@ bool PeParser::readPeSectionsFromProcess() if (!readSectionFromProcess(readOffset, listPeSection[i])) { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess failed offset 0x%x, section %d\n", readOffset, i+1); +#endif retValue = false; } } +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess success.\n"); +#endif return retValue; } @@ -519,7 +527,6 @@ bool PeParser::openWriteFileHandle( const CHAR * newFile ) // If no name was specified, let's give it a temporary name to allow it to be renamed later with its hash value hFile = CreateFile(CAPE_OUTPUT_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); } - return (hFile != INVALID_HANDLE_VALUE); } @@ -667,10 +674,17 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) bool retValue = true; char *CapeName; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::savePeFileToDisk: Function entry.\n"); +#endif + DWORD dwFileOffset = 0, dwWriteSize = 0; if (getNumberOfSections() != listPeSection.size()) { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::savePeFileToDisk: Number of sections mismatch error.\n"); +#endif return false; } @@ -877,7 +891,9 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) if (openWriteFileHandle(newFile)) { - //DoOutputDebugString("Number of sections: %d, PointerToRawData: 0x%x, SizeOfRawData: 0x%x\n", getNumberOfSections(), listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData, listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("Number of sections: %d, PointerToRawData: 0x%x, SizeOfRawData: 0x%x\n", getNumberOfSections(), listPeSection[getNumberOfSections() - 1].sectionHeader.PointerToRawData, listPeSection[getNumberOfSections() - 1].sectionHeader.SizeOfRawData); +#endif dwWriteSize = listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData + listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData; diff --git a/CAPE/Scylla/PeParser.h b/CAPE/Scylla/PeParser.h index 62bdc36..0be9a92 100644 --- a/CAPE/Scylla/PeParser.h +++ b/CAPE/Scylla/PeParser.h @@ -5,8 +5,6 @@ //#include "DumpSectionGui.h" #define CAPE_OUTPUT_FILE "CapeOutput.bin" - -extern "C" char* GetHashFromHandle(HANDLE hFile); extern "C" char* GetName(); class PeFileSection { @@ -93,6 +91,8 @@ class PeParser DWORD getSectionAddressRVAByIndex( int index ); PIMAGE_NT_HEADERS getCurrentNtHeader(); + std::vector listPeSection; + protected: PeParser(); @@ -116,7 +116,6 @@ class PeParser DWORD dosStubSize; PIMAGE_NT_HEADERS32 pNTHeader32; PIMAGE_NT_HEADERS64 pNTHeader64; - std::vector listPeSection; BYTE * overlayData; DWORD overlaySize; /************************************************************************/ diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 9d42178..135827d 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -6,7 +6,7 @@ This program is free software : you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the @@ -32,9 +32,12 @@ typedef unsigned __int64 QWORD; #define OFT_SUPPORT FALSE #define CAPE_OUTPUT_FILE "CapeOutput.bin" +//#define DEBUG_COMMENTS extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); +extern "C" int ScanForNonZero(LPVOID Buffer, unsigned int Size); + extern char CapeOutputPath[MAX_PATH]; //************************************************************************************** @@ -56,38 +59,38 @@ extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) { DWORD_PTR entrypoint = 0; PeParser * peFile = 0; - DWORD modBase; + DWORD ModuleBase; - modBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); + ModuleBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); ScyllaInitCurrentProcess(); - DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); + DoOutputDebugString("DumpCurrentProcess: Instantiating PeParser with address: 0x%x", ModuleBase); - peFile = new PeParser(modBase, TRUE); + peFile = new PeParser(ModuleBase, TRUE); if (peFile->isValidPeFile()) { if (NewOEP) entrypoint = NewOEP; else - entrypoint = peFile->getEntryPoint() + modBase; + entrypoint = peFile->getEntryPoint() + ModuleBase; - DoOutputDebugString("Module entry point VA is 0x%x", entrypoint); + DoOutputDebugString("DumpCurrentProcess: Module entry point VA is 0x%x", entrypoint); - if (peFile->dumpProcess(modBase, entrypoint, NULL)) + if (peFile->dumpProcess(ModuleBase, entrypoint, NULL)) { - DoOutputDebugString("Module image dump success.\n"); + DoOutputDebugString("DumpCurrentProcess: Module image dump success.\n"); } else { - DoOutputDebugString("Error: Cannot dump image."); + DoOutputErrorString("DumpCurrentProcess: Error - Cannot dump image"); delete peFile; return 0; } } else { - DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("DumpCurrentProcess: Invalid PE file or invalid PE header."); delete peFile; return 0; } @@ -111,7 +114,7 @@ void ScyllaInit(HANDLE hProcess) } //************************************************************************************** -extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) +extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD NewOEP) //************************************************************************************** { DWORD_PTR entrypoint = 0; @@ -119,9 +122,9 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOE ScyllaInit(hProcess); - DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); + DoOutputDebugString("DumpProcess: Instantiating PeParser with address: 0x%x", ModuleBase); - peFile = new PeParser(modBase, TRUE); + peFile = new PeParser(ModuleBase, TRUE); if (peFile->isValidPeFile()) { @@ -129,24 +132,25 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOE entrypoint = NewOEP; else entrypoint = peFile->getEntryPoint(); - entrypoint = entrypoint + modBase; + + entrypoint = entrypoint + ModuleBase; - DoOutputDebugString("Module entry point VA is 0x%x", entrypoint); + DoOutputDebugString("DumpProcess: Module entry point VA is 0x%x", entrypoint); - if (peFile->dumpProcess(modBase, entrypoint, NULL)) + if (peFile->dumpProcess(ModuleBase, entrypoint, NULL)) { - DoOutputDebugString("Module image dump success"); + DoOutputDebugString("DumpProcess: Module image dump success"); } else { - DoOutputDebugString("Error: Cannot dump image."); + DoOutputErrorString("DumpProcess: Error - Cannot dump image"); delete peFile; return 0; } } else { - DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("DumpProcess: Invalid PE file or invalid PE header."); delete peFile; return 0; } @@ -156,43 +160,203 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOE return 1; } +//************************************************************************************** +DWORD SafeGetDword(PVOID Address) +//************************************************************************************** +{ + DWORD RetVal = NULL; + + __try + { + RetVal = *(DWORD*)Address; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("SafeGetDword: Exception occured reading memory address 0x%x\n", Address); + return NULL; + } + + return RetVal; +} + //************************************************************************************** extern "C" int ScyllaDumpPE(DWORD_PTR Buffer) //************************************************************************************** { - DWORD_PTR entrypoint = 0; + DWORD_PTR PointerToLastSection, entrypoint = 0; PeParser * peFile = 0; - + unsigned int SizeOfLastSection, NumberOfSections = 0; + NativeWinApi::initialize(); ProcessAccessHelp::setCurrentProcessAsTarget(); - DoOutputDebugString("Instantiating PeParser with address: 0x%x", Buffer); - - peFile = new PeParser((DWORD_PTR)Buffer, TRUE); + DoOutputDebugString("DumpPE: Instantiating PeParser with address: 0x%x", Buffer); + peFile = new PeParser((DWORD_PTR)Buffer, TRUE); + if (peFile->isValidPeFile()) { + NumberOfSections = peFile->getNumberOfSections(); + + if (NumberOfSections == 0) + { + DoOutputDebugString("DumpPE: no sections in PE image, ignoring.\n"); + return 0; + } + + PointerToLastSection = SafeGetDword(&(peFile->listPeSection[NumberOfSections - 1].sectionHeader.PointerToRawData)); + + if (!PointerToLastSection) + { + DoOutputDebugString("DumpPE: failed to obtain pointer to last section.\n"); + return 0; + } + + PointerToLastSection += (DWORD_PTR)Buffer; + + SizeOfLastSection = SafeGetDword(&(peFile->listPeSection[NumberOfSections - 1].sectionHeader.SizeOfRawData)); + + if (!SizeOfLastSection) + { + DoOutputDebugString("DumpPE: failed to obtain size of last section.\n"); + return 0; + } + + if (!ScanForNonZero((LPVOID)PointerToLastSection, SizeOfLastSection)) + { + DoOutputDebugString("DumpPE: Empty last section, file image seems incomplete (from 0x%x to 0x%x).\n", PointerToLastSection, (DWORD_PTR)PointerToLastSection + SizeOfLastSection); + return 0; + } + + entrypoint = peFile->getEntryPoint(); + if (peFile->saveCompletePeToDisk(NULL)) { - DoOutputDebugString("PE file in memory dumped successfully."); + DoOutputDebugString("DumpPE: PE file in memory dumped successfully."); } else { - DoOutputDebugString("Error: Cannot dump PE file from memory."); + DoOutputDebugString("DumpPE: Error: Cannot dump PE file from memory."); delete peFile; return 0; } } else { - DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("DumpPE: Error: Invalid PE file or invalid PE header."); delete peFile; return 0; } delete peFile; + + return 1; +} +//************************************************************************************** +extern "C" int LooksLikeSectionBoundary(DWORD_PTR Buffer) +//************************************************************************************** +{ + __try + { + if + ( + (*(DWORD*)((BYTE*)Buffer - 4) == 0) && // end of previous section has zeros + (*(DWORD*)((BYTE*)Buffer) != 0) // beginning of section is non-zero + ) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("LooksLikeSectionBoundary: Yes - end of previous candidate section zero, beginning of candidate section at 0x%x non-zero.\n", Buffer); +#endif + return 1; + } + else + { +#ifdef DEBUG_COMMENTS + if (*(DWORD*)((BYTE*)Buffer - 4) != 0) + DoOutputDebugString("LooksLikeSectionBoundary: No - end of previous candidate section 0x%x not zero.\n", Buffer); + + if (*(DWORD*)((BYTE*)Buffer) == 0) + DoOutputDebugString("LooksLikeSectionBoundary: No - beginning of candidate section 0x%x zero.\n", Buffer); +#endif + return 0; + } + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("LooksLikeSectionBoundary: Exception occured reading around suspected boundary at 0x%x\n", Buffer); + return 0; + } +} + +//************************************************************************************** +extern "C" int IsPeImageVirtual(DWORD_PTR Buffer) +//************************************************************************************** +{ + PeParser * peFile = 0; + unsigned int NumberOfSections = 0; + DWORD SectionBasedFileSize; + + NativeWinApi::initialize(); + + ProcessAccessHelp::setCurrentProcessAsTarget(); + + peFile = new PeParser((DWORD_PTR)Buffer, TRUE); + + if (peFile->isValidPeFile()) + { + NumberOfSections = peFile->getNumberOfSections(); + SectionBasedFileSize = peFile->getSectionHeaderBasedFileSize(); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: NumberOfSections %d, SectionBasedFileSize 0x%x.\n", NumberOfSections, SectionBasedFileSize); +#endif + if (NumberOfSections == 0) + // makes no difference in this case + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: zero sections, therefore meaningless.\n"); +#endif + delete peFile; + return 1; + } + + for (unsigned int SectionIndex = 0; SectionIndex < NumberOfSections; SectionIndex++) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString + ( + "IsPeImageVirtual: Section %d, PointerToRawData 0x%x, VirtualAddress 0x%x, SizeOfRawData 0x%x, VirtualSize 0x%x.\n", + SectionIndex+1, + peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData, + peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress, + peFile->listPeSection[SectionIndex].sectionHeader.SizeOfRawData, + peFile->listPeSection[SectionIndex].sectionHeader.Misc.VirtualSize + ); +#endif + if (peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData != peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress) + { + if (LooksLikeSectionBoundary((DWORD_PTR)Buffer + peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData)) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: Found what looks like a 'raw' section boundary - image looks raw.\n"); +#endif + delete peFile; + return 0; + } + else if (LooksLikeSectionBoundary((DWORD_PTR)Buffer + peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress)) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: Found what looks like a virtual section boundary - image looks virtual.\n"); +#endif + delete peFile; + return 1; + } + } + } + } + + delete peFile; return 1; } @@ -230,7 +394,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) DWORD addressIAT, sizeIAT; BOOL IAT_Found, AdvancedIATSearch = FALSE; bool isAfter; - DWORD modBase; + DWORD ModuleBase; IATSearch iatSearch; ApiReader apiReader; @@ -240,7 +404,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) DWORD_PTR entrypointRVA = 0; PeParser * peFile = 0; - modBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); + ModuleBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); //Clear stuff first ProcessAccessHelp::ownModuleList.clear(); @@ -254,62 +418,62 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) ProcessAccessHelp::getProcessModules(ProcessAccessHelp::hProcess, ProcessAccessHelp::ownModuleList); ProcessAccessHelp::moduleList = ProcessAccessHelp::ownModuleList; - ProcessAccessHelp::targetImageBase = modBase; + ProcessAccessHelp::targetImageBase = ModuleBase; ProcessAccessHelp::getSizeOfImageCurrentProcess(); // Enumerate DLLs and imported functions apiReader.readApisFromModuleList(); - DoOutputDebugString("Instantiating PeParser with address: 0x%x", modBase); + DoOutputDebugString("DumpCurrentProcessFixImports: Instantiating PeParser with address: 0x%x", ModuleBase); - peFile = new PeParser(modBase, TRUE); + peFile = new PeParser(ModuleBase, TRUE); if (peFile->isValidPeFile()) { if (NewOEP) - entrypointRVA = NewOEP - modBase; + entrypointRVA = NewOEP - ModuleBase; else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString("Module entry point VA is 0x%x", modBase + entrypointRVA); + DoOutputDebugString(TEXT("DumpCurrentProcessFixImports: Module entry point VA is 0x%x"), ModuleBase + entrypointRVA); // Let's dump then fix the dump on disk - if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE)) + if (peFile->dumpProcess(ModuleBase, ModuleBase + entrypointRVA, CAPE_OUTPUT_FILE)) { - DoOutputDebugString("Module image dump success %s", CapeOutputPath); + DoOutputDebugString("DumpCurrentProcessFixImports: Module image dump success %s", CapeOutputPath); } // IAT search - we'll try the simple search first - IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, FALSE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(ModuleBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, FALSE); // Let's try the advanced search now if (IAT_Found == FALSE) - IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, TRUE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(ModuleBase + entrypointRVA, (DWORD_PTR*)&addressIAT, &sizeIAT, TRUE); if (addressIAT && sizeIAT) { - DoOutputDebugString("Found IAT: 0x%x, size: 0x%x", addressIAT, sizeIAT); + DoOutputDebugString(TEXT("DumpCurrentProcessFixImports: Found IAT: 0x%x, size: 0x%x"), addressIAT, sizeIAT); apiReader.readAndParseIAT(addressIAT, sizeIAT, importsHandling.moduleList); importsHandling.scanAndFixModuleList(); if (SCAN_DIRECT_IMPORTS) { - iatReferenceScan.ScanForDirectImports = TRUE; - iatReferenceScan.ScanForNormalImports = FALSE; + iatReferenceScan.ScanForDirectImports = true; + iatReferenceScan.ScanForNormalImports = false; iatReferenceScan.apiReader = &apiReader; iatReferenceScan.startScan(ProcessAccessHelp::targetImageBase, (DWORD)ProcessAccessHelp::targetSizeOfImage, addressIAT, sizeIAT); - DoOutputDebugString("Direct imports - Found %d possible direct imports with %d unique APIs", iatReferenceScan.numberOfFoundDirectImports(), iatReferenceScan.numberOfFoundUniqueDirectImports()); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Found %d possible direct imports with %d unique APIs", iatReferenceScan.numberOfFoundDirectImports(), iatReferenceScan.numberOfFoundUniqueDirectImports()); if (iatReferenceScan.numberOfFoundDirectImports() > 0) { if (iatReferenceScan.numberOfDirectImportApisNotInIat() > 0) { - DoOutputDebugString("Direct imports - Found %d additional api addresses", iatReferenceScan.numberOfDirectImportApisNotInIat()); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Found %d additional api addresses", iatReferenceScan.numberOfDirectImportApisNotInIat()); DWORD sizeIatNew = iatReferenceScan.addAdditionalApisToList(); - DoOutputDebugString("Direct imports - Old IAT size 0x%08x new IAT size 0x%08x", sizeIAT, sizeIatNew); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Old IAT size 0x%08x new IAT size 0x%08x", sizeIAT, sizeIatNew); importsHandling.scanAndFixModuleList(); } @@ -327,14 +491,14 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) isAfter = 1; iatReferenceScan.patchDirectImportsMemory(isAfter); - DoOutputDebugString("Direct imports patched."); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports patched."); } } } if (isIATOutsidePeImage(addressIAT)) { - DoOutputDebugString("Warning, IAT is not inside the PE image, requires rebasing."); + DoOutputDebugString("DumpCurrentProcessFixImports: Warning - IAT is not inside the PE image, requires rebasing."); } ImportRebuilder importRebuild(CAPE_OUTPUT_FILE); @@ -343,7 +507,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) { // Untested importRebuild.enableOFTSupport(); - DoOutputDebugString("importRebuild: OFT support enabled.\n"); + DoOutputDebugString("DumpCurrentProcessFixImports: OFT support enabled.\n"); } if (SCAN_DIRECT_IMPORTS && FIX_DIRECT_IMPORTS_UNIVERSAL) @@ -364,24 +528,25 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) if (importRebuild.rebuildImportTable(NULL, importsHandling.moduleList)) { - DoOutputDebugString("Import table rebuild success.\n"); + DoOutputDebugString("DumpCurrentProcessFixImports: Import table rebuild success.\n"); delete peFile; return 1; } else { - DoOutputDebugString("Import table rebuild failed.\n"); - } + DoOutputDebugString("DumpCurrentProcessFixImports: Import table rebuild failed, falling back to unfixed dump.\n"); + peFile->savePeFileToDisk(NULL); + } } else { - DoOutputDebugString("Warning: Unable to find IAT in scan.\n"); + DoOutputDebugString("DumpCurrentProcessFixImports: Warning - Unable to find IAT in scan.\n"); } } else { - DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("DumpCurrentProcessFixImports: Error - Invalid PE file or invalid PE header. Try reading PE header from disk/process."); delete peFile; return 0; } @@ -392,10 +557,10 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) } //************************************************************************************** -extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP) +extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD NewOEP) //************************************************************************************** { - BOOL isAfter; + bool isAfter; DWORD sizeIAT; DWORD_PTR addressIAT; BOOL IAT_Found, AdvancedIATSearch = FALSE; @@ -417,42 +582,39 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D ProcessAccessHelp::ownModuleList.clear(); ProcessAccessHelp::hProcess = hProcess; ProcessAccessHelp::getProcessModules(ProcessAccessHelp::hProcess, ProcessAccessHelp::moduleList); - ProcessAccessHelp::targetImageBase = modBase; - - //ProcessAccessHelp::moduleList = ProcessAccessHelp::ownModuleList; - //ProcessAccessHelp::getSizeOfImageCurrentProcess(); + ProcessAccessHelp::targetImageBase = ModuleBase; apiReader.readApisFromModuleList(); - DoOutputDebugString(TEXT("Instantiating PeParser with address: 0x%x"), modBase); + DoOutputDebugString(TEXT("DumpProcessFixImports: Instantiating PeParser with address: 0x%x"), ModuleBase); - peFile = new PeParser(modBase, true); + peFile = new PeParser(ModuleBase, true); if (peFile->isValidPeFile()) { if (NewOEP) - entrypointRVA = NewOEP - modBase; + entrypointRVA = NewOEP - ModuleBase; else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString(TEXT("Module entry point VA is 0x%x"), modBase + entrypointRVA); + DoOutputDebugString(TEXT("DumpProcessFixImports: Module entry point VA is 0x%x"), ModuleBase + entrypointRVA); // Let's dump then fix the dump on disk - if (peFile->dumpProcess(modBase, modBase + entrypointRVA, CAPE_OUTPUT_FILE)) + if (peFile->dumpProcess(ModuleBase, ModuleBase + entrypointRVA, CAPE_OUTPUT_FILE)) { DoOutputDebugString("Module image dump success %s", CapeOutputPath); } // We'll try the simple search first - IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, &addressIAT, &sizeIAT, FALSE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(ModuleBase + entrypointRVA, &addressIAT, &sizeIAT, FALSE); // Let's try the advanced search now if (IAT_Found == FALSE) - IAT_Found = iatSearch.searchImportAddressTableInProcess(modBase + entrypointRVA, &addressIAT, &sizeIAT, TRUE); + IAT_Found = iatSearch.searchImportAddressTableInProcess(ModuleBase + entrypointRVA, &addressIAT, &sizeIAT, TRUE); if (addressIAT && sizeIAT) { - DoOutputDebugString(TEXT("Found IAT: 0x%x, size: 0x%x"), addressIAT, sizeIAT); + DoOutputDebugString(TEXT("DumpProcessFixImports: Found IAT - 0x%x, size: 0x%x"), addressIAT, sizeIAT); apiReader.readAndParseIAT(addressIAT, sizeIAT, importsHandling.moduleList); importsHandling.scanAndFixModuleList(); @@ -498,10 +660,10 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D if (isIATOutsidePeImage(addressIAT)) { - DoOutputDebugString("WARNING! IAT is not inside the PE image, requires rebasing."); + DoOutputDebugString("Warning - IAT is not inside the PE image, requires rebasing."); } - ImportRebuilder importRebuild(CAPE_OUTPUT_FILE); + ImportRebuilder importRebuild(CapeOutputPath); if (OFT_SUPPORT) { @@ -542,7 +704,6 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, D { DoOutputDebugString("Warning: Unable to find IAT in scan.\n"); } - } else { diff --git a/config.c b/config.c index db55fd6..a2216fe 100644 --- a/config.c +++ b/config.c @@ -219,7 +219,7 @@ int read_config(void) } } else if (!strcmp(key, "breakpoint")) { - CAPE_var = (void*)strtoul(value, NULL, 10); + CAPE_var = (void*)(DWORD_PTR)strtoul(value, NULL, 10); DoOutputDebugString("CAPE_var set to 0x%x", CAPE_var); } else if (!strcmp(key, "procmemdump")) { diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index f38cc72..e91b5ce 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -78,14 +78,14 @@ true AllRules.ruleset false - CAPE_Injection + Injection $(VC_IncludePath);$(WindowsSdk_71A_IncludePath);C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\WTL91\Include; true AllRules.ruleset false - CAPE_Injection_x64 + Injection_x64 $(VC_IncludePath);$(WindowsSdk_71A_IncludePath);C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\WTL91\Include; diff --git a/hook_file.c b/hook_file.c index cf165fa..c718804 100644 --- a/hook_file.c +++ b/hook_file.c @@ -1222,9 +1222,6 @@ HOOKDEF(BOOL, WINAPI, GetVolumeInformationA, *lpVolumeSerialNumber = 0x46e70ca9; debug_message("Changed Volume Serial Number."); } - - - } #endif return ret; diff --git a/hook_process.c b/hook_process.c index 8d8a96d..3370442 100644 --- a/hook_process.c +++ b/hook_process.c @@ -32,9 +32,9 @@ along with this program. If not, see . extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -extern int DumpMemory(LPCVOID Buffer, unsigned int Size); -extern int DumpImageInCurrentProcess(DWORD ImageBase); -extern int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); +extern int DumpMemory(LPVOID Buffer, SIZE_T Size); +extern int DumpImageInCurrentProcess(DWORD_PTR ImageBase); +extern int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -323,7 +323,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, { CurrentInjectionInfo->ProcessHandle = *ProcessHandle; CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(BufferSize); @@ -586,7 +586,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, CurrentInjectionInfo->ProcessHandle = ProcessHandle; CurrentInjectionInfo->ProcessId = pid; CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); - CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(BufferSize); @@ -731,12 +731,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)Buffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD_PTR)Buffer); if (CurrentInjectionInfo->ImageDumped) { DoOutputDebugString("NtWriteVirtualMemory hook: Dumped PE image from buffer.\n"); - CurrentInjectionInfo->BufferBase = Buffer; + CurrentInjectionInfo->BufferBase = (LPVOID)Buffer; CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; } else @@ -749,7 +749,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = pid; - if (DumpMemory(Buffer, *NumberOfBytesWritten)) + if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) DoOutputDebugString("NtWriteVirtualMemory hook: Dumped malformed PE image from buffer."); else DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump malformed PE image from buffer."); @@ -773,7 +773,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, // dump injected code to .bin file CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = pid; - if (DumpMemory(Buffer, *NumberOfBytesWritten)) + if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) DoOutputDebugString("NtWriteVirtualMemory hook: Dumped injected code from buffer."); else DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump injected code from buffer."); @@ -840,12 +840,12 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD)lpBuffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD_PTR)lpBuffer); if (CurrentInjectionInfo->ImageDumped) { DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer.\n"); - CurrentInjectionInfo->BufferBase = lpBuffer; + CurrentInjectionInfo->BufferBase = (LPVOID)lpBuffer; CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; } else @@ -858,7 +858,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = pid; - if (DumpMemory(lpBuffer, *lpNumberOfBytesWritten)) + if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) DoOutputDebugString("WriteProcessMemory hook: Dumped malformed PE image from buffer."); else DoOutputDebugString("WriteProcessMemory hook: Failed to dump malformed PE image from buffer."); @@ -882,7 +882,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, // dump injected code to .bin file CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = pid; - if (DumpMemory(lpBuffer, *lpNumberOfBytesWritten)) + if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) DoOutputDebugString("WriteProcessMemory hook: Dumped injected code from buffer."); else DoOutputDebugString("WriteProcessMemory hook: Failed to dump injected code from buffer."); diff --git a/hook_special.c b/hook_special.c index 2cea4a4..c430d57 100644 --- a/hook_special.c +++ b/hook_special.c @@ -170,7 +170,7 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, { CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); - CurrentInjectionInfo->EntryPoint = (DWORD)NULL; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); diff --git a/hook_sync.c b/hook_sync.c index 81ed723..762a3b1 100644 --- a/hook_sync.c +++ b/hook_sync.c @@ -104,3 +104,43 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateNamedPipeFile, "ShareAccess", ShareAccess); return ret; } + +HOOKDEF(NTSTATUS, WINAPI, NtAddAtom, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom +) { + NTSTATUS ret = Old_NtAddAtom(AtomName, AtomNameLength, Atom); + LOQ_ntstatus("synchronization", "uh", "AtomName", AtomName, "Atom", *Atom); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtDeleteAtom, + IN RTL_ATOM Atom +) { + NTSTATUS ret = Old_NtDeleteAtom(Atom); + LOQ_ntstatus("synchronization", "h", "Atom", Atom); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtFindAtom, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom OPTIONAL +) { + ENSURE_RTL_ATOM(Atom); + NTSTATUS ret = Old_NtFindAtom(AtomName, AtomNameLength, Atom); + LOQ_ntstatus("synchronization", "uh", "AtomName", AtomName, "Atom", *Atom); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtAddAtomEx, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom, + IN PVOID Unknown +) { + NTSTATUS ret = Old_NtAddAtomEx(AtomName, AtomNameLength, Atom, Unknown); + LOQ_ntstatus("synchronization", "uh", "AtomName", AtomName, "Atom", *Atom); + return ret; +} diff --git a/hook_thread.c b/hook_thread.c index c5c07f0..b93e86c 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -28,9 +28,9 @@ along with this program. If not, see . #include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern int DumpMemory(LPCVOID Buffer, unsigned int Size); -extern int DumpImageInCurrentProcess(DWORD ImageBase); -extern int ScanForPE(LPCVOID Buffer, unsigned int Size, LPCVOID* Offset); +extern int DumpMemory(LPVOID Buffer, SIZE_T Size); +extern int DumpImageInCurrentProcess(DWORD_PTR ImageBase); +extern int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); static lookup_t g_ignored_threads; @@ -255,23 +255,22 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, ret = Old_NtSetContextThread(ThreadHandle, Context); CurrentInjectionInfo = GetInjectionInfo(pid); - - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + + if (Context->ContextFlags & CONTEXT_CONTROL) { #ifdef _WIN64 - CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds rip on 64-bit + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds rip on 64-bit + + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); #else - CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds eip on 32-bit + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds eip on 32-bit + + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eip); #endif DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } - - if (Context->ContextFlags & CONTEXT_CONTROL) -#ifdef _WIN64 - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); -#else - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eip); -#endif else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); diff --git a/hooks.h b/hooks.h index f2921c5..0f667ff 100644 --- a/hooks.h +++ b/hooks.h @@ -248,7 +248,7 @@ extern HOOKDEF(BOOL, WINAPI, CopyFileW, __in BOOL bFailIfExists ); -extern HOOKDEF(BOOL, WINAPI, CopyFileExW, +extern HOOKDEF_NOTAIL(WINAPI, CopyFileExW, _In_ LPWSTR lpExistingFileName, _In_ LPWSTR lpNewFileName, _In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine, @@ -257,6 +257,15 @@ extern HOOKDEF(BOOL, WINAPI, CopyFileExW, _In_ DWORD dwCopyFlags ); +extern HOOKDEF_ALT(BOOL, WINAPI, CopyFileExW, + _In_ LPWSTR lpExistingFileName, + _In_ LPWSTR lpNewFileName, + _In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine, + _In_opt_ LPVOID lpData, + _In_opt_ LPBOOL pbCancel, + _In_ DWORD dwCopyFlags +); + extern HOOKDEF(BOOL, WINAPI, DeleteFileA, __in LPCSTR lpFileName ); @@ -862,6 +871,29 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtCreateNamedPipeFile, IN PLARGE_INTEGER DefaultTimeOut ); +extern HOOKDEF(NTSTATUS, WINAPI, NtAddAtom, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtDeleteAtom, + IN RTL_ATOM Atom +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtFindAtom, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom OPTIONAL +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtAddAtomEx, + IN PWCHAR AtomName, + IN ULONG AtomNameLength, + OUT PRTL_ATOM Atom, + IN PVOID Unknown +); + // // Process Hooks // @@ -1373,6 +1405,11 @@ extern HOOKDEF(LPTOP_LEVEL_EXCEPTION_FILTER, WINAPI, SetUnhandledExceptionFilter _In_ LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter ); +extern HOOKDEF(PVOID, WINAPI, RtlAddVectoredExceptionHandler, + __in ULONG First, + __out PVECTORED_EXCEPTION_HANDLER Handler +); + extern HOOKDEF(UINT, WINAPI, SetErrorMode, _In_ UINT uMode ); @@ -1557,6 +1594,16 @@ extern HOOKDEF(void, WINAPIV, memcpy, size_t count ); +extern HOOKDEF(HANDLE, WINAPI, GetProcessHeap, + void +); + +extern HOOKDEF(LPVOID, WINAPI, HeapAlloc, + _In_ HANDLE hHeap, + _In_ DWORD dwFlags, + _In_ SIZE_T dwBytes +); + extern HOOKDEF(HDEVINFO, WINAPI, SetupDiGetClassDevsA, _In_opt_ const GUID *ClassGuid, _In_opt_ PCSTR Enumerator, @@ -1801,6 +1848,15 @@ extern HOOKDEF(HRESULT, WINAPI, URLDownloadToFileW, LPVOID lpfnCB ); +extern HOOKDEF(HRESULT, WINAPI, URLDownloadToCacheFileW, + _In_ LPUNKNOWN lpUnkcalled, + _In_ LPCWSTR szURL, + _Out_ LPWSTR szFilename, + _In_ DWORD cchFilename, + _Reserved_ DWORD dwReserved, + _In_opt_ VOID *pBSC +); + extern HOOKDEF(BOOL, WINAPI, InternetGetConnectedState, _Out_ LPDWORD lpdwFlags, _In_ DWORD dwReserved diff --git a/log.h b/log.h index b5dbe69..a211632 100644 --- a/log.h +++ b/log.h @@ -126,6 +126,9 @@ do { \ #define ENSURE_LARGE_INTEGER(param) \ LARGE_INTEGER _##param; _##param.QuadPart = 0; if(param == NULL) param = &_##param +#define ENSURE_RTL_ATOM(param) \ + RTL_ATOM _##param = 0; if(param == NULL) param = &_##param + #define ENSURE_DWORD(param) \ DWORD _##param = 0; if(param == NULL) param = &_##param diff --git a/ntapi.h b/ntapi.h index 0dc34ca..ba9dc3d 100644 --- a/ntapi.h +++ b/ntapi.h @@ -480,8 +480,8 @@ typedef struct _PEB { BOOLEAN ReadImageFileExecOptions; BOOLEAN BeingDebugged; BOOLEAN Spare; - HANDLE Mutant; - PVOID ImageBaseAddress; + BYTE Reserved2[12]; + PVOID ImageBaseAddress; PPEB_LDR_DATA LoaderData; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; BYTE Reserved3[520]; @@ -496,7 +496,7 @@ typedef struct _PEB { BOOLEAN BeingDebugged; BOOLEAN Spare; HANDLE Mutant; - PVOID ImageBaseAddress; + PVOID ImageBaseAddress; PPEB_LDR_DATA LoaderData; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; PVOID SubSystemData; @@ -664,6 +664,8 @@ static inline void __writefsdword(unsigned int index, unsigned int value) (( HKEY ) (ULONG_PTR)((LONG)0x80000007) ) #endif +typedef unsigned short RTL_ATOM, *PRTL_ATOM; + typedef struct _SECTION_IMAGE_INFORMATION { VOID* TransferAddress; uint32_t ZeroBits; From 99b16723ce2aef64ae07d0fcee023c0728d0b4cb Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jun 2017 12:43:17 +0000 Subject: [PATCH 11/39] Switch to tracking all created processes with 'injection info' for improved coverage of rare cases. --- hook_process.c | 8 +++--- hook_special.c | 75 +++++++++++++++++++++++++------------------------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/hook_process.c b/hook_process.c index 3370442..0c99f29 100644 --- a/hook_process.c +++ b/hook_process.c @@ -735,9 +735,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (CurrentInjectionInfo->ImageDumped) { - DoOutputDebugString("NtWriteVirtualMemory hook: Dumped PE image from buffer.\n"); CurrentInjectionInfo->BufferBase = (LPVOID)Buffer; CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; + DoOutputDebugString("NtWriteVirtualMemory hook: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", Buffer, CurrentInjectionInfo->BufferSizeOfImage); } else DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump PE image from buffer.\n"); @@ -768,7 +768,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, } else { - DoOutputDebugString("NtWriteVirtualMemory hook: Shellcode injected into process %d.\n", pid); + DoOutputDebugString("NtWriteVirtualMemory hook: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, *NumberOfBytesWritten, pid); // dump injected code to .bin file CapeMetaData->DumpType = INJECTION_SHELLCODE; @@ -844,9 +844,9 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (CurrentInjectionInfo->ImageDumped) { - DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer.\n"); CurrentInjectionInfo->BufferBase = (LPVOID)lpBuffer; CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; + DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", lpBuffer, CurrentInjectionInfo->BufferSizeOfImage); } else DoOutputDebugString("WriteProcessMemory hook: Failed to dump PE image from buffer.\n"); @@ -877,7 +877,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, } else { - DoOutputDebugString("WriteProcessMemory hook: Shellcode injected into process %d.\n", pid); + DoOutputDebugString("WriteProcessMemory hook: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", lpBuffer, *lpNumberOfBytesWritten, pid); // dump injected code to .bin file CapeMetaData->DumpType = INJECTION_SHELLCODE; diff --git a/hook_special.c b/hook_special.c index c430d57..cc3e669 100644 --- a/hook_special.c +++ b/hook_special.c @@ -152,50 +152,49 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, if (!dont_monitor) pipe("PROCESS:%d:%d,%d", (dwCreationFlags & CREATE_SUSPENDED) ? 1 : 0, lpProcessInformation->dwProcessId, lpProcessInformation->dwThreadId); - - // if the CREATE_SUSPENDED flag was not set, then we have to resume - // the main thread ourself - if((dwCreationFlags & CREATE_SUSPENDED) == 0) { - ResumeThread(lpProcessInformation->hThread); - } - else if (!called_by_hook()){ - CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); - - if (CurrentInjectionInfo == NULL) - { - DoOutputDebugString("CreateProcessInternal hook: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); - } - else + // CAPE: Create 'injection info' struct for the newly created process + CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("CreateProcessInternal hook: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + } + else + { + CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + + CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); + memset(TargetProcess, 0, MAX_PATH*sizeof(WCHAR)); + + if (lpApplicationName) + _snwprintf(TargetProcess, MAX_PATH, L"%s", lpApplicationName); + else if (lpCommandLine) { - CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); - CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; - CurrentInjectionInfo->ImageDumped = FALSE; - - CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); - memset(TargetProcess, 0, MAX_PATH*sizeof(WCHAR)); - - if (lpApplicationName) - _snwprintf(TargetProcess, MAX_PATH, L"%s", lpApplicationName); - else if (lpCommandLine) + DoOutputDebugString("CreateProcessInternal hook: using lpCommandLine: %ws.\n", lpCommandLine); + if (*lpCommandLine == L'\"') + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); + else { - DoOutputDebugString("CreateProcessInternal hook: using lpCommandLine: %ws.\n", lpCommandLine); - if (*lpCommandLine == L'\"') - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); + if (wcschr(lpCommandLine, ' ')) + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); else - { - if (wcschr(lpCommandLine, ' ')) - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); - else - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); - } + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); } - - WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); - - DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); } + + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); + + DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + } + + // if the CREATE_SUSPENDED flag was not set, then we have to resume + // the main thread ourself + if((dwCreationFlags & CREATE_SUSPENDED) == 0) { + ResumeThread(lpProcessInformation->hThread); } disable_sleep_skip(); From 03e459f30652be6235ea76ccfee6a6908ce1d43a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Jun 2017 12:16:40 +0000 Subject: [PATCH 12/39] Fix 'instruction pointer' log value in Get/SetContextThread hooks. --- hook_thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hook_thread.c b/hook_thread.c index b93e86c..e9c5b8b 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -233,9 +233,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); if (Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); #else - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); #endif else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); @@ -262,12 +262,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds rip on 64-bit - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); #else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds eip on 32-bit - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); #endif DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } From 3593fa2a5bbd21c4008ed793db843fae8d60a5fa Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Oct 2017 15:58:43 +0100 Subject: [PATCH 13/39] Improve log output for NtGet/SetContextThread. --- hook_thread.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hook_thread.c b/hook_thread.c index e9c5b8b..40d336f 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -233,9 +233,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); if (Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); #else - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); #endif else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); @@ -260,14 +260,14 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, { #ifdef _WIN64 if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds rip on 64-bit + CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds ep on 64-bit - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); #else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds eip on 32-bit + CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds ep on 32-bit - LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); #endif DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } From 1f7d4ea39538df5ae6ca7b70bbf5ec43e543f68d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Oct 2017 15:45:20 +0000 Subject: [PATCH 14/39] Fixed issues with getting ImageBase in InjectionInfo and tracking all shared views. --- hook_process.c | 20 +++++++++++++++++--- hook_thread.c | 2 +- misc.c | 26 +++++++++++--------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/hook_process.c b/hook_process.c index 0c99f29..8f73640 100644 --- a/hook_process.c +++ b/hook_process.c @@ -322,11 +322,17 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, else { CurrentInjectionInfo->ProcessHandle = *ProcessHandle; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); + + if (!CurrentInjectionInfo->ImageBase) + DoOutputDebugString("NtOpenProcess: Error obtaining target process image base for process %d (handle 0x%x).\n", pid, *ProcessHandle); + else + DoOutputDebugString("NtOpenProcess: Image base for process %d (handle 0x%x): 0x%p.\n", pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); + PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); if (!PathLength) @@ -338,7 +344,15 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, DoOutputErrorString("NtOpenProcess: Error translating target process path"); } } - // else... Some samples call this multiple times for the same process, we can ignore + else if (CurrentInjectionInfo->ImageBase == (DWORD_PTR)NULL) + { + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); + + if (!CurrentInjectionInfo->ImageBase) + DoOutputDebugString("NtOpenProcess: Unable to obtain target process image base for process %d (handle 0x%x).\n", pid, *ProcessHandle); + else + DoOutputDebugString("NtOpenProcess: Image base for process %d (handle 0x%x): 0x%p.\n", pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); + } } LOQ_ntstatus("process", "Phi", "ProcessHandle", ProcessHandle, @@ -550,7 +564,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, CurrentInjectionInfo = GetInjectionInfo(pid); - if (!CurrentInjectionInfo && pid == GetCurrentProcessId()) + if (pid == GetCurrentProcessId()) { AddSectionView(SectionHandle, *BaseAddress, *ViewSize); DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); diff --git a/hook_thread.c b/hook_thread.c index 40d336f..a150e12 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -322,7 +322,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, if (CurrentInjectionInfo) { - if (CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = pid; diff --git a/misc.c b/misc.c index f0b05d7..a20a5f0 100644 --- a/misc.c +++ b/misc.c @@ -28,6 +28,7 @@ along with this program. If not, see . #include "config.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); static _NtQueryInformationProcess pNtQueryInformationProcess; static _NtQueryInformationThread pNtQueryInformationThread; @@ -1799,34 +1800,29 @@ PVOID get_process_image_base(HANDLE process_handle) { PROCESS_BASIC_INFORMATION pbi; ULONG ulSize; - HANDLE dup_handle = process_handle; - PVOID pPEB = 0, ImageBase = 0; PEB Peb; SIZE_T dwBytesRead; lasterror_t lasterror; + PVOID pPEB = 0, ImageBase = 0; get_lasterrors(&lasterror); - if (process_handle == GetCurrentProcess()) - { - ImageBase = GetModuleHandle(NULL); - goto out; - } - memset(&pbi, 0, sizeof(pbi)); - if(pNtQueryInformationProcess(process_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) + if (process_handle == GetCurrentProcess()) + ImageBase = GetModuleHandle(NULL); + else if (pNtQueryInformationProcess(process_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) { pPEB = pbi.PebBaseAddress; - if (ReadProcessMemory(process_handle, pPEB, &Peb, sizeof(Peb), &dwBytesRead)) - { + if (!pPEB) + DoOutputDebugString("get_process_image_base: Failed to obtain address of PEB in target process.\n"); + else if (ReadProcessMemory(process_handle, pPEB, &Peb, sizeof(Peb), &dwBytesRead)) ImageBase = Peb.ImageBaseAddress; - } - else return NULL; + else + DoOutputErrorString("get_process_image_base: ReadProcessMemory failed to read from 0x%p", pPEB); } - -out: + set_lasterrors(&lasterror); return ImageBase; From 2a088ef9827a1d0c7e20a5b431aedc2a68f43b0a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Oct 2017 16:25:59 +0000 Subject: [PATCH 15/39] Small fix to NtResumeProcess hook in line with previous fix/commit. --- hook_process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hook_process.c b/hook_process.c index 8f73640..10f32ca 100644 --- a/hook_process.c +++ b/hook_process.c @@ -375,7 +375,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, if (CurrentInjectionInfo) { - if (CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); @@ -399,7 +399,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, return ret; } - int process_shutting_down; HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, From bd99230803c825e8454d5779d7518279ceed85e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Nov 2017 18:47:36 +0000 Subject: [PATCH 16/39] Added support for variation of process hollowing where NtMapViewOfSection is invoked in hollow process by NtSetContextThread (e.g. QtBot) --- CAPE/CAPE.h | 3 ++- hook_process.c | 22 ++++++++++++++++++++++ hook_thread.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 8a510a5..b199af7 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -44,7 +44,8 @@ typedef struct InjectionInfo DWORD_PTR EntryPoint; BOOL WriteDetected; BOOL ImageDumped; - LPVOID BufferBase; + LPVOID BufferBase; + LPVOID StackPointer; unsigned int BufferSizeOfImage; HANDLE SectionHandle; // struct InjectionSectionView *SectionViewList; diff --git a/hook_process.c b/hook_process.c index 10f32ca..ee03a9c 100644 --- a/hook_process.c +++ b/hook_process.c @@ -834,6 +834,28 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, { CurrentInjectionInfo->WriteDetected = TRUE; + if ((unsigned int)((PUCHAR)CurrentInjectionInfo->StackPointer - (PUCHAR)lpBaseAddress) < 0x100) + { + PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + + DoOutputDebugString("WriteProcessMemory hook: Target address is stack of target process %d.\n", pid); + + while (CurrentSectionView) + { +#ifdef _WIN64 + if (CurrentSectionView->SectionHandle == (HANDLE)(*((DWORD_PTR*)lpBuffer + 1))) +#else + if (CurrentSectionView->SectionHandle == (HANDLE)(*((DWORD*)lpBuffer + 1))) +#endif + { + CurrentSectionView->TargetProcessId = pid; + DoOutputDebugString("WriteProcessMemory hook: Section handle 0x%x written to stack of target process %d.\n", CurrentSectionView->SectionHandle, pid); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + } + if (NT_SUCCESS(ret) && *lpNumberOfBytesWritten > 0) { // Check if we have a valid DOS and PE header at the beginning of Buffer diff --git a/hook_thread.c b/hook_thread.c index a150e12..9347293 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -230,13 +230,28 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, __in HANDLE ThreadHandle, __inout LPCONTEXT Context ) { - NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); - if (Context->ContextFlags & CONTEXT_CONTROL) + NTSTATUS ret; + struct InjectionInfo *CurrentInjectionInfo; + DWORD pid = pid_from_thread_handle(ThreadHandle); + + ret = Old_NtGetContextThread(ThreadHandle, Context); + + CurrentInjectionInfo = GetInjectionInfo(pid); + + if (Context->ContextFlags & CONTEXT_CONTROL) + { #ifdef _WIN64 + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + CurrentInjectionInfo->StackPointer = (LPVOID)Context->Rsp; + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); #else + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) + CurrentInjectionInfo->StackPointer = (LPVOID)Context->Esp; + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); #endif + } else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); return ret; @@ -263,13 +278,22 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds ep on 64-bit LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); + + if (Context->Rip == (DWORD_PTR)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) + DoOutputDebugString("NtSetContextThread hook: Hollow process entry point set to NtMapViewOfSection (process %d).\n", pid); + else + DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); #else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds ep on 32-bit - + LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); + + if (Context->Eip == (DWORD)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) + DoOutputDebugString("NtSetContextThread hook: Hollow process entry point set to NtMapViewOfSection (process %d).\n", pid); + else + DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); #endif - DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); } else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); From 6fdef28d8dc2eb597285857ae762abf0516feb4d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Dec 2017 15:11:02 +0000 Subject: [PATCH 17/39] Minor bug fix and code cleanup. --- CAPE/CAPE.c | 8 -------- hook_process.c | 13 +++++++------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 0ab9a87..58f75b1 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -340,18 +340,10 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) { PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - //TODO remove debug - DoOutputDebugString("GetSectionView: Global section view list 0x%x, looking for handle 0x%x\n", CurrentSectionView, SectionHandle); - while (CurrentSectionView) { - //TODO remove debug - DoOutputDebugString("GetSectionView: looking at section handle 0x%x.\n", CurrentSectionView->SectionHandle); if (CurrentSectionView->SectionHandle == SectionHandle) - { - DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); return CurrentSectionView; - } CurrentSectionView = CurrentSectionView->NextSectionView; } diff --git a/hook_process.c b/hook_process.c index ee03a9c..0981dd7 100644 --- a/hook_process.c +++ b/hook_process.c @@ -348,9 +348,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, { CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - if (!CurrentInjectionInfo->ImageBase) - DoOutputDebugString("NtOpenProcess: Unable to obtain target process image base for process %d (handle 0x%x).\n", pid, *ProcessHandle); - else + if (CurrentInjectionInfo->ImageBase) DoOutputDebugString("NtOpenProcess: Image base for process %d (handle 0x%x): 0x%p.\n", pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); } } @@ -516,7 +514,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, { if (CurrentSectionView->LocalView == BaseAddress) { - DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view, faking.\n"); + DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, faking.\n", BaseAddress); ret = STATUS_SUCCESS; @@ -565,8 +563,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, if (pid == GetCurrentProcessId()) { - AddSectionView(SectionHandle, *BaseAddress, *ViewSize); - DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); + if (!GetSectionView(SectionHandle)) + { + AddSectionView(SectionHandle, *BaseAddress, *ViewSize); + DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); + } } else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { From c27a571ba6e2096272afb666ba33cbe82f647eae Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Dec 2017 13:38:52 +0000 Subject: [PATCH 18/39] Improved handling of unmapped/replaced views (e.g. new Ursnif). --- hook_process.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hook_process.c b/hook_process.c index 0981dd7..0c2e5aa 100644 --- a/hook_process.c +++ b/hook_process.c @@ -516,7 +516,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, { DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, faking.\n", BaseAddress); - ret = STATUS_SUCCESS; + ret = STATUS_SUCCESS; LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", map_size); @@ -563,11 +563,22 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, if (pid == GetCurrentProcessId()) { - if (!GetSectionView(SectionHandle)) + PINJECTIONSECTIONVIEW CurrentSectionView = GetSectionView(SectionHandle); + + if (!CurrentSectionView) { AddSectionView(SectionHandle, *BaseAddress, *ViewSize); DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); } + else + { + if (NT_SUCCESS(ret) && CurrentSectionView->LocalView != *BaseAddress) + { + CurrentSectionView->LocalView = *BaseAddress; + CurrentSectionView->ViewSize = *ViewSize; + DoOutputDebugString("NtMapViewOfSection hook: Updated local view to 0x%x for section view with handle 0x%x.\n", *BaseAddress, SectionHandle); + } + } } else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { From 91583bd9398bcb11c10cb14b822b3d8441d62880 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Dec 2017 08:39:28 +0000 Subject: [PATCH 19/39] Fix in NtMapViewOfSection hook. --- CAPE/CAPE.c | 16 +++++++++++++--- hook_process.c | 6 +++--- hook_special.c | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 58f75b1..86d9ba2 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -262,9 +262,17 @@ PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) //************************************************************************************** { DWORD CurrentProcessId; - - PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; - while (CurrentInjectionInfo) + PINJECTIONINFO CurrentInjectionInfo; + + if (InjectionInfoList == NULL) + { + DoOutputDebugString("GetInjectionInfo: Failed to find InjectionInfoList.\n"); + return NULL; + } + + CurrentInjectionInfo = InjectionInfoList; + + while (CurrentInjectionInfo) { CurrentProcessId = CurrentInjectionInfo->ProcessId; @@ -330,6 +338,8 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) CurrentInjectionInfo->ProcessId = ProcessId; } + + DoOutputDebugString("CreateInjectionInfo: Created injection info at 0x%x for process %d.\n", CurrentInjectionInfo, CurrentInjectionInfo->ProcessId); return CurrentInjectionInfo; } diff --git a/hook_process.c b/hook_process.c index 0c2e5aa..c2784ab 100644 --- a/hook_process.c +++ b/hook_process.c @@ -584,7 +584,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, { DoOutputDebugString("NtMapViewOfSection hook: Section view with handle 0x%x and target process %d.\n", SectionHandle, pid); - CurrentSectionViewInfo = GetSectionView(SectionHandle); + CurrentSectionViewInfo = AddSectionView(SectionHandle, *BaseAddress, *ViewSize); if (CurrentSectionViewInfo) { @@ -593,7 +593,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, } else { - DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); + DoOutputDebugString("NtMapViewOfSection hook: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, pid); } } else if (!CurrentInjectionInfo && pid != GetCurrentProcessId()) @@ -633,7 +633,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); } else - DoOutputDebugString("NtMapViewOfSection hook: Error, section view with handle 0x%x and target process %d not found in global list.\n", SectionHandle, pid); + DoOutputDebugString("NtMapViewOfSection hook: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, pid); } } diff --git a/hook_special.c b/hook_special.c index cc3e669..e9c174e 100644 --- a/hook_special.c +++ b/hook_special.c @@ -188,7 +188,7 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); - DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); } // if the CREATE_SUSPENDED flag was not set, then we have to resume From e5e822d8b4270832bc6b2ac0fa0795f3448cd480 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Jan 2018 09:48:50 +0000 Subject: [PATCH 20/39] Tidy up debug output. --- CAPE/CAPE.c | 3 --- hook_process.c | 4 ---- hook_thread.c | 4 ++-- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 86d9ba2..53508dc 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -265,10 +265,7 @@ PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) PINJECTIONINFO CurrentInjectionInfo; if (InjectionInfoList == NULL) - { - DoOutputDebugString("GetInjectionInfo: Failed to find InjectionInfoList.\n"); return NULL; - } CurrentInjectionInfo = InjectionInfoList; diff --git a/hook_process.c b/hook_process.c index c2784ab..f6b8552 100644 --- a/hook_process.c +++ b/hook_process.c @@ -582,8 +582,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, } else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) { - DoOutputDebugString("NtMapViewOfSection hook: Section view with handle 0x%x and target process %d.\n", SectionHandle, pid); - CurrentSectionViewInfo = AddSectionView(SectionHandle, *BaseAddress, *ViewSize); if (CurrentSectionViewInfo) @@ -600,8 +598,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, { CurrentInjectionInfo = CreateInjectionInfo(pid); - DoOutputDebugString("NtMapViewOfSection hook: Injection info created for pid %d.\n", pid); - if (CurrentInjectionInfo == NULL) { DoOutputDebugString("NtMapViewOfSection hook: Cannot create new injection info - FATAL ERROR.\n"); diff --git a/hook_thread.c b/hook_thread.c index 9347293..3a77caa 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -342,10 +342,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, CurrentInjectionInfo = GetInjectionInfo(pid); - DoOutputDebugString("NtResumeThread hook: CurrentInjectionInfo 0x%x (pid %d).\n", CurrentInjectionInfo, pid); - if (CurrentInjectionInfo) { + DoOutputDebugString("NtResumeThread hook: CurrentInjectionInfo 0x%x (pid %d).\n", CurrentInjectionInfo, pid); + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { CapeMetaData->DumpType = INJECTION_PE; From 901270bc2fc2e470ed9b04ce4d9028fcc9e47ce4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Feb 2018 11:32:56 +0000 Subject: [PATCH 21/39] Improve handling of malformed injected PE images. --- CAPE/Scylla/PeParser.cpp | 9 +++++++-- hook_process.c | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 0c81e80..6caa891 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -310,15 +310,16 @@ bool PeParser::readPeSectionsFromProcess() if (!readSectionFromProcess(readOffset, listPeSection[i])) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess failed offset 0x%x, section %d\n", readOffset, i+1); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess failed offset 0x%x, section %d (VA 0x%p, size 0x%x)\n", readOffset, i+1, listPeSection[i].sectionHeader.VirtualAddress, listPeSection[i].normalSize); #endif retValue = false; + goto out; // To continue upon failure may lead to crashes } } #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess success.\n"); #endif - +out: return retValue; } @@ -1278,6 +1279,10 @@ bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * return savePeFileToDisk(dumpFilePath); } +#ifdef DEBUG_COMMENTS + else + DoOutputDebugString("PeParser::dumpProcess: readPeSectionsFromProcess failed.\n"); +#endif return false; } diff --git a/hook_process.c b/hook_process.c index f6b8552..bb2e1c7 100644 --- a/hook_process.c +++ b/hook_process.c @@ -892,7 +892,14 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", lpBuffer, CurrentInjectionInfo->BufferSizeOfImage); } else - DoOutputDebugString("WriteProcessMemory hook: Failed to dump PE image from buffer.\n"); + { + DoOutputDebugString("WriteProcessMemory hook: Failed to dump PE image from buffer, dumping raw buffer.\n"); + + if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) + DoOutputDebugString("WriteProcessMemory hook: Dumped malformed PE image from buffer."); + else + DoOutputDebugString("WriteProcessMemory hook: Failed to dump malformed PE image from buffer."); + } } } else From 271f17a4f02f630211342bbfe56af86e8d86ffd5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Feb 2018 12:26:24 +0000 Subject: [PATCH 22/39] Merge updates from other packages. --- CAPE/CAPE.c | 758 +++++++++++--------- CAPE/CAPE.h | 60 +- CAPE/Debugger.c | 1822 ++++++++++++++++++++++++++++++++--------------- CAPE/Debugger.h | 156 ++-- CAPE/Output.c | 13 +- config.c | 30 +- config.h | 2 +- hook_process.c | 11 +- hook_special.c | 3 +- hook_thread.c | 6 +- misc.c | 110 ++- misc.h | 4 +- 12 files changed, 1951 insertions(+), 1024 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 53508dc..d794a44 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -15,6 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.If not, see . */ +#define _CRT_RAND_S +#include #include #include #include @@ -28,6 +30,7 @@ along with this program.If not, see . #include "CAPE.h" #include "Debugger.h" +#include "..\alloc.h" #include "..\pipe.h" #include "..\config.h" @@ -47,14 +50,19 @@ extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buf extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern void CapeOutputFile(LPCTSTR lpOutputFile); -extern int IsPeImageVirtual(DWORD_PTR Buffer); -extern int ScyllaDumpCurrentProcess(DWORD NewOEP); -extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); -extern int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP); -extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD NewOEP); - -extern wchar_t *our_process_path; +extern int IsPeImageVirtual(LPVOID Buffer); +extern int ScyllaDumpCurrentProcess(DWORD_PTR NewOEP); +extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD_PTR NewOEP); +extern int ScyllaDumpCurrentProcessFixImports(DWORD_PTR NewOEP); +extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD_PTR NewOEP); +extern int ScyllaDumpPE(DWORD_PTR Buffer); + +extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); +extern unsigned int address_is_in_stack(PVOID Address); extern ULONG_PTR base_of_dll_of_interest; +extern wchar_t *our_process_path; +extern ULONG_PTR g_our_dll_base; +extern DWORD g_our_dll_size; static HMODULE s_hInst = NULL; static WCHAR s_wzDllPath[MAX_PATH]; @@ -62,6 +70,98 @@ CHAR s_szDllPath[MAX_PATH]; BOOL ProcessDumped; +//************************************************************************************** +BOOL InsideHook(LPVOID* ReturnAddress, LPVOID Address) +//************************************************************************************** +{ + if ((ULONG_PTR)Address >= g_our_dll_base && (ULONG_PTR)Address < (g_our_dll_base + g_our_dll_size)) + { + if (ReturnAddress) + *ReturnAddress = Address; + return TRUE; + } + + return FALSE; +} + +//************************************************************************************** +LPVOID GetReturnAddress(PCONTEXT ContextRecord) +//************************************************************************************** +{ + LPVOID ReturnAddress = NULL; + + __try + { +#ifdef _WIN64 + operate_on_backtrace(0, (ULONG_PTR)ContextRecord->Rip, &ReturnAddress, InsideHook); +#else + operate_on_backtrace(0, (ULONG_PTR)ContextRecord->Ebp, &ReturnAddress, InsideHook); +#endif + + if (!ReturnAddress) +#ifdef _WIN64 + ReturnAddress = *(LPVOID*)(ContextRecord->Rbp + sizeof(LPVOID)); +#else + ReturnAddress = *(LPVOID*)(ContextRecord->Ebp + sizeof(LPVOID)); +#endif + + return ReturnAddress; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { +#ifdef _WIN64 + DoOutputDebugString("GetReturnAddress: Exception trying to get return address with Rip 0x%p and Rbp 0x%p.\n", ContextRecord->Rip, ContextRecord->Rbp); +#else + DoOutputDebugString("GetReturnAddress: Exception trying to get return address with base pointer 0x%x.\n", ContextRecord->Ebp); +#endif + return NULL; + } +} + +//************************************************************************************** +void GetHookCallerBase() +//************************************************************************************** +{ + CONTEXT ContextRecord; + PVOID ReturnAddress, AllocationBase; + + if (CallingModule) + return; + +#ifdef _WIN64 + RtlCaptureContext(&ContextRecord); +#else + ZeroMemory(&ContextRecord, sizeof(CONTEXT)); + + __asm + { + Label: + mov eax, [Label]; + mov [ContextRecord.Eip], eax; + mov [ContextRecord.Ebp], ebp; + mov [ContextRecord.Esp], esp; + } +#endif + ReturnAddress = GetReturnAddress(&ContextRecord); + + if (ReturnAddress) + { + DWORD ThreadId = GetCurrentThreadId(); + + AllocationBase = GetAllocationBase(ReturnAddress); + DoOutputDebugString("GetHookCallerBase: thread %d (handle 0x%x), return address 0x%p, allocation base 0x%p.\n", ThreadId, GetThreadHandle(ThreadId), ReturnAddress, AllocationBase); + + if (AllocationBase) + { + CallingModule = AllocationBase; + } + } + else + DoOutputDebugString("GetHookCallerBase: failed to get return address.\n"); + + return; +} + //************************************************************************************** void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned int Count) //************************************************************************************** @@ -135,6 +235,70 @@ BOOL TranslatePathFromDeviceToLetter(__in char *DeviceFilePath, __out char* Driv return TRUE; } +//************************************************************************************** +PVOID GetAllocationBase(PVOID Address) +//************************************************************************************** +{ + MEMORY_BASIC_INFORMATION MemInfo; + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("GetAllocationBase: Failed to obtain system page size.\n"); + return 0; + } + + if (!VirtualQuery(Address, &MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("GetAllocationBase: unable to query memory address 0x%x", Address); + return 0; + } + + return MemInfo.AllocationBase; +} + +//************************************************************************************** +SIZE_T GetAllocationSize(PVOID Address) +//************************************************************************************** +{ + MEMORY_BASIC_INFORMATION MemInfo; + PVOID OriginalAllocationBase, AddressOfPage; + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("GetAllocationSize: Failed to obtain system page size.\n"); + return 0; + } + + if (!VirtualQuery(Address, &MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("GetAllocationSize: unable to query memory address 0x%x", Address); + return 0; + } + + OriginalAllocationBase = MemInfo.AllocationBase; + AddressOfPage = OriginalAllocationBase; + + while (MemInfo.AllocationBase == OriginalAllocationBase) + { + (PUCHAR)AddressOfPage += SystemInfo.dwPageSize; + + if (!VirtualQuery(AddressOfPage, &MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("GetAllocationSize: unable to query memory page 0x%x", AddressOfPage); + return 0; + } + } + + return (SIZE_T)((DWORD_PTR)AddressOfPage - (DWORD_PTR)OriginalAllocationBase); + +} + //************************************************************************************** BOOL SetCapeMetaData(DWORD DumpType, DWORD TargetPid, HANDLE hTargetProcess, PVOID Address) //************************************************************************************** @@ -176,11 +340,11 @@ BOOL SetCapeMetaData(DWORD DumpType, DWORD TargetPid, HANDLE hTargetProcess, PVO return FALSE; } } - else if (DumpType == EXTRACTION_PE || DumpType == EXTRACTION_SHELLCODE) + else if (DumpType == EXTRACTION_PE || DumpType == EXTRACTION_SHELLCODE || DumpType == URSNIF_PAYLOAD) { if (!Address) { - DoOutputDebugString("SetCapeMetaData: Extraction type with no PID - error.\n"); + DoOutputDebugString("SetCapeMetaData: CAPE type with missing PID - error.\n"); return FALSE; } @@ -262,14 +426,9 @@ PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) //************************************************************************************** { DWORD CurrentProcessId; - PINJECTIONINFO CurrentInjectionInfo; - - if (InjectionInfoList == NULL) - return NULL; - - CurrentInjectionInfo = InjectionInfoList; - - while (CurrentInjectionInfo) + + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; + while (CurrentInjectionInfo) { CurrentProcessId = CurrentInjectionInfo->ProcessId; @@ -335,8 +494,6 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) CurrentInjectionInfo->ProcessId = ProcessId; } - - DoOutputDebugString("CreateInjectionInfo: Created injection info at 0x%x for process %d.\n", CurrentInjectionInfo, CurrentInjectionInfo->ProcessId); return CurrentInjectionInfo; } @@ -347,10 +504,18 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) { PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + //TODO remove debug + DoOutputDebugString("GetSectionView: Global section view list 0x%x, looking for handle 0x%x\n", CurrentSectionView, SectionHandle); + while (CurrentSectionView) { + //TODO remove debug + DoOutputDebugString("GetSectionView: looking at section handle 0x%x.\n", CurrentSectionView->SectionHandle); if (CurrentSectionView->SectionHandle == SectionHandle) + { + DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); return CurrentSectionView; + } CurrentSectionView = CurrentSectionView->NextSectionView; } @@ -505,7 +670,7 @@ void DumpSectionViewsForPid(DWORD Pid) CapeMetaData->TargetPid = Pid; CapeMetaData->Address = PEPointer; - if (DumpImageInCurrentProcess((DWORD_PTR)PEPointer)) + if (DumpImageInCurrentProcess(PEPointer)) { DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); Dumped = TRUE; @@ -553,7 +718,8 @@ char* GetName() char *OutputFilename, *FullPathName; SYSTEMTIME Time; DWORD RetVal; - + unsigned int random; + FullPathName = (char*) malloc(MAX_PATH); if (FullPathName == NULL) @@ -571,7 +737,14 @@ char* GetName() } GetSystemTime(&Time); - sprintf_s(OutputFilename, MAX_PATH*sizeof(char), "%d_%d%d%d%d%d%d%d%d", GetCurrentProcessId(), Time.wMilliseconds, Time.wSecond, Time.wMinute, Time.wHour, Time.wDay, Time.wDayOfWeek, Time.wMonth, Time.wYear); + + if (rand_s(&random)) + { + DoOutputErrorString("GetName: failed to obtain a random number"); + return 0; + } + + sprintf_s(OutputFilename, MAX_PATH*sizeof(char), "%d_%d%d%d%d%d%d%d%d", GetCurrentProcessId(), abs(random * Time.wMilliseconds), Time.wSecond, Time.wMinute, Time.wHour, Time.wDay, Time.wDayOfWeek, Time.wMonth, Time.wYear); // We want to dump CAPE output to the 'analyzer' directory memset(FullPathName, 0, MAX_PATH); @@ -725,9 +898,8 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) //************************************************************************************** { LONG e_lfanew; - DWORD NT_Signature, FullKey; - WORD TestKey; - unsigned int i, j, k, rotation; + DWORD NT_Signature; + unsigned int i, j, k; BYTE* DecryptedBuffer; for (i=0; i<=0xFF; i++) @@ -782,191 +954,19 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) *(DecryptedBuffer+k) = *(DecryptedBuffer+k)^i; CapeMetaData->Address = DecryptedBuffer; - DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); + DumpImageInCurrentProcess(DecryptedBuffer); free(DecryptedBuffer); return i; } else { - DoOutputDebugString("PE signature invalid, looks like a false positive! 1 in 0x10000!!\n"); + DoOutputDebugString("PE signature invalid, looks like a false positive.\n"); return FALSE; } } } -#ifndef _WIN64 - for (i=0; i<=0xffff; i++) - { - // check for the DOS signature a.k.a MZ header - if ((*(WORD*)Buffer^(WORD)i) == IMAGE_DOS_SIGNATURE) - { - DoOutputDebugString("MZ header found with wordwise XOR key 0x%.2x%.2x\n", *(BYTE*)&i, *((BYTE*)&i+1)); - - // let's try just the little end of the full lfanew which is almost always the whole value anyway - e_lfanew = *(WORD*)(Buffer+0x3c); - - // try and decrypt - e_lfanew = e_lfanew^(WORD)i; - - if ((unsigned int)e_lfanew > PE_HEADER_LIMIT) - { - // even if dword-encrypted, - // if the little endian word of the dword takes it too far it's over - DoOutputDebugString("Sadly the pointer to the PE header seems a tad too large: 0x%x", e_lfanew); - //return FALSE; - } - - // get PE header - memcpy(&NT_Signature, Buffer+e_lfanew, 4); - - // We need to rotate our key for a non-dword aligned offset - TestKey = i; - if (e_lfanew % 2) - { - __asm - { - mov ax, TestKey - ror ax, 8 - mov TestKey, ax - } - } - - // let's try decrypting it with the word key - for (k=0; k<2; k++) - *((WORD*)&NT_Signature+k) = *((WORD*)&NT_Signature+k)^TestKey; - - // does it check out? - if (NT_Signature == IMAGE_NT_SIGNATURE) - { - DoOutputDebugString("Xor-encrypted PE detected, about to dump.\n"); - - DecryptedBuffer = (BYTE*)malloc(Size); - - if (DecryptedBuffer == NULL) - { - DoOutputErrorString("Error allocating memory for decrypted PE binary"); - return FALSE; - } - - memcpy(DecryptedBuffer, Buffer, Size); - - for (k=0; kAddress = DecryptedBuffer; - DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); - - free(DecryptedBuffer); - return TRUE; - } - else if ((WORD)NT_Signature == (WORD)IMAGE_NT_SIGNATURE) - { - // looks like DWORD encrypted with zero most significant word of lfanew - // let's confirm - DWORD FullKey = TestKey + ((*(WORD*)(Buffer+0x3e))<<16); - - // let's recopy our candidate PE header - memcpy(&NT_Signature, Buffer+e_lfanew, 4); - - // We need to rotate our key for a non-dword aligned offset - for (rotation = 0; rotation<(unsigned int)(e_lfanew % 4); rotation++) - { - __asm - { - mov eax, FullKey - ror eax, 8 - mov FullKey, eax - } - } - - // final test of the latter two bytes of PE header - // (might as well test the whole thing) - if ((NT_Signature ^ FullKey) == IMAGE_NT_SIGNATURE) - { - DoOutputDebugString("Xor-encrypted PE detected, about to dump.\n"); - - DecryptedBuffer = (BYTE*)malloc(Size); - - if (DecryptedBuffer == NULL) - { - DoOutputErrorString("Error allocating memory for decrypted PE binary"); - return FALSE; - } - - memcpy(DecryptedBuffer, Buffer, Size); - - for (k=0; kAddress = DecryptedBuffer; - DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); - - free(DecryptedBuffer); - return TRUE; - } - else - { - // There's *very* remote this was a false positive, we should continue - continue; - } - } - - // could be dword with non-zero most signicant bytes of lfanew - // brute force the 0xffff possibilities here - - for (TestKey=0; TestKey<0xffff; TestKey++) - { - long full_lfanew = e_lfanew + (0x10000*((*(WORD*)(Buffer+0x3e))^TestKey)); - - if ((unsigned int)full_lfanew > PE_HEADER_LIMIT) - { - continue; - } - - memcpy(&NT_Signature, Buffer+full_lfanew, 4); - - // We need to rotate our key for a non-dword aligned offset - FullKey = i + (TestKey<<16); - for (rotation = 0; rotation<(unsigned int)(full_lfanew % 4); rotation++) - { - __asm - { - mov eax, FullKey - ror eax, 8 - mov FullKey, eax - } - } - - // let's try decrypting it with the key - if ((NT_Signature ^ FullKey) == IMAGE_NT_SIGNATURE) - { - DoOutputDebugString("Xor-encrypted PE detected, about to dump.\n"); - - DecryptedBuffer = (BYTE*)malloc(Size); - - if (DecryptedBuffer == NULL) - { - DoOutputErrorString("Error allocating memory for decrypted PE binary"); - return FALSE; - } - - memcpy(DecryptedBuffer, Buffer, Size); - - for (k=0; kAddress = DecryptedBuffer; - DumpImageInCurrentProcess((DWORD_PTR)DecryptedBuffer); - - free(DecryptedBuffer); - return TRUE; - } - } - } - } - -#endif // We free can free DecryptedBuffer as it's no longer needed free(DecryptedBuffer); @@ -980,12 +980,18 @@ int ScanPageForNonZero(LPVOID Address) unsigned int p; DWORD_PTR AddressOfPage; + if (!Address) + { + DoOutputDebugString("ScanPageForNonZero: Error - Supplied address zero.\n"); + return 0; + } + if (!SystemInfo.dwPageSize) GetSystemInfo(&SystemInfo); if (!SystemInfo.dwPageSize) { - DoOutputErrorString("Failed to obtain system page size.\n"); + DoOutputErrorString("ScanPageForNonZero: Failed to obtain system page size.\n"); return 0; } @@ -1007,10 +1013,16 @@ int ScanPageForNonZero(LPVOID Address) } //************************************************************************************** -int ScanForNonZero(LPVOID Buffer, unsigned int Size) +int ScanForNonZero(LPVOID Buffer, SIZE_T Size) //************************************************************************************** { - unsigned int p; + SIZE_T p; + + if (!Buffer) + { + DoOutputDebugString("ScanForNonZero: Error - Supplied address zero.\n"); + return 0; + } __try { @@ -1028,16 +1040,38 @@ int ScanForNonZero(LPVOID Buffer, unsigned int Size) } //************************************************************************************** -int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset) +PVOID GetPageAddress(PVOID Address) //************************************************************************************** -{ - unsigned int p; +{ + if (!Address) + { + DoOutputDebugString("GetPageAddress: Error - Supplied address zero.\n"); + return NULL; + } + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("GetPageAddress: Failed to obtain system page size.\n"); + return NULL; + } + + return (PVOID)(((DWORD_PTR)Address/SystemInfo.dwPageSize)*SystemInfo.dwPageSize); + +} +//************************************************************************************** +int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) +//************************************************************************************** +{ // deprecated in favour of ScanForDisguisedPE + SIZE_T p; PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader; - if (Size == 0) + if (!Buffer || !Size) { - DoOutputDebugString("ScanForPE: Error, zero size given\n"); + DoOutputDebugString("ScanForPE: Error, Buffer or Size zero: 0x%x, 0x%x\n", Buffer, Size); return 0; } @@ -1098,149 +1132,120 @@ int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset) } //************************************************************************************** -int ScanForDisguisedPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset) +int IsDisguisedPEHeader(LPVOID Buffer) //************************************************************************************** { - unsigned int p; PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader; - if (Size == 0) - { - DoOutputDebugString("ScanForDisguisedPE: Error, zero size given\n"); - return 0; - } - - for (p=0; p < Size - 0x41; p++) // we want to stop short of the look-ahead to e_lfanew - { - __try - { - pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer+p); - - if (!pDosHeader->e_lfanew || (ULONG)pDosHeader->e_lfanew > Size-p || pDosHeader->e_lfanew > PE_HEADER_LIMIT) - { - continue; - } - - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - - if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) - { - continue; - } - - // Basic requirements - if - ( - pNtHeader->FileHeader.Machine == 0 || - pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || - pNtHeader->OptionalHeader.SizeOfHeaders == 0 || - pNtHeader->OptionalHeader.FileAlignment == 0 - ) - { - DoOutputDebugString("ScanForDisguisedPE: Basic requirements failure.\n"); - continue; - } - - if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) - { - DoOutputDebugString("IsDisguisedPE: Characteristics bad."); - continue; - } - - if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) - { - DoOutputDebugString("IsDisguisedPE: SizeOfOptionalHeader bad."); - continue; - } - - if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) - { - DoOutputDebugString("IsDisguisedPE: FileAlignment invalid."); - continue; - } - - if (Offset) - { - *Offset = (LPVOID)((char*)Buffer+p); - } - - DoOutputDebugString("ScanForDisguisedPE: PE image located at: 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); - - return 1; - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - DoOutputDebugString("ScanForDisguisedPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); - return 0; - } - } - - DoOutputDebugString("ScanForDisguisedPE: No PE image located in range 0x%x-0x%x.\n", Buffer, (DWORD_PTR)Buffer + Size); - return 0; -} - -//************************************************************************************** -int IsDisguisedPE(LPVOID Buffer, unsigned int Size) -//************************************************************************************** -{ - PIMAGE_DOS_HEADER pDosHeader; - PIMAGE_NT_HEADERS pNtHeader; - - if (Size == 0) - { - DoOutputDebugString("IsDisguisedPE: Error, zero size given\n"); - return 0; - } - __try { pDosHeader = (PIMAGE_DOS_HEADER)Buffer; - if (!pDosHeader->e_lfanew || pDosHeader->e_lfanew > PE_HEADER_LIMIT) + if (!pDosHeader->e_lfanew || (ULONG)pDosHeader->e_lfanew > PE_HEADER_LIMIT || ((ULONG)pDosHeader->e_lfanew & 3) != 0) { - //DoOutputDebugString("IsDisguisedPE: e_lfanew bad."); + //DoOutputDebugString("IsDisguisedPEHeader: e_lfanew bad. (0x%x)", (DWORD_PTR)Buffer); return 0; } - - // more tests to establish it's PE + //else + // DoOutputDebugString("IsDisguisedPEHeader: e_lfanew ok!: 0x%x (0x%x)", (ULONG)pDosHeader->e_lfanew, (DWORD_PTR)Buffer); + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) { - // Basic requirements - DoOutputDebugString("IsDisguisedPE: Basic requirements bad."); + //DoOutputDebugString("IsDisguisedPEHeader: OptionalHeader.Magic bad. (0x%x)", (DWORD_PTR)Buffer); + return 0; + } + //else + // DoOutputDebugString("IsDisguisedPEHeader: OptionalHeader.Magic ok!: 0x%x (0x%x)", pNtHeader->OptionalHeader.Magic, (DWORD_PTR)Buffer); + + // Basic requirements + if + ( + pNtHeader->FileHeader.Machine == 0 || + pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || + pNtHeader->OptionalHeader.SizeOfHeaders == 0 || + pNtHeader->OptionalHeader.FileAlignment == 0 + ) + { + DoOutputDebugString("IsDisguisedPEHeader: Basic requirements failure (Base 0x%x).\n", (DWORD_PTR)Buffer); return 0; } if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) { - DoOutputDebugString("IsDisguisedPE: Characteristics bad."); + DoOutputDebugString("IsDisguisedPEHeader: Characteristics bad. (0x%x)", (DWORD_PTR)Buffer); return 0; } if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) { - DoOutputDebugString("IsDisguisedPE: SizeOfOptionalHeader bad."); + DoOutputDebugString("IsDisguisedPEHeader: SizeOfOptionalHeader bad. (0x%x)", (DWORD_PTR)Buffer); return 0; } - - if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) + + if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) { - DoOutputDebugString("IsDisguisedPE: OptionalHeader.Magic bad."); + DoOutputDebugString("IsDisguisedPEHeader: FileAlignment invalid. (0x%x)", (DWORD_PTR)Buffer); return 0; } + if (pNtHeader->OptionalHeader.SectionAlignment < pNtHeader->OptionalHeader.FileAlignment) + { + DoOutputDebugString("IsDisguisedPEHeader: FileAlignment greater than SectionAlignment.\n (0x%x)", (DWORD_PTR)Buffer); + return 0; + } + // To pass the above tests it should now be safe to assume it's a PE image - return 1; + return (ULONG)pDosHeader->e_lfanew; } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputDebugString("IsDisguisedPE: Exception occured reading region at 0x%x\n", (DWORD_PTR)(Buffer)); + DoOutputDebugString("IsDisguisedPEHeader: Exception occured reading region at 0x%x\n", (DWORD_PTR)(Buffer)); + return -1; + } + + //DoOutputDebugString("IsDisguisedPEHeader: No PE image located\n (0x%x)", (DWORD_PTR)Buffer); + //return 0; +} + +//************************************************************************************** +int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) +//************************************************************************************** +{ + SIZE_T p; + int RetVal; + + if (Size == 0) + { + DoOutputDebugString("ScanForDisguisedPE: Error, zero size given\n"); return 0; } - DoOutputDebugString("IsDisguisedPE: No PE image located\n"); + for (p=0; p < Size - 0x41; p++) // we want to stop short of the look-ahead to e_lfanew + { + RetVal = IsDisguisedPEHeader((BYTE*)Buffer+p); + + if (!RetVal) + continue; + else if (RetVal == -1) + { + DoOutputDebugString("ScanForDisguisedPE: Exception occured scanning buffer at 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); + return 0; + } + + if (Offset) + { + *Offset = (LPVOID)((BYTE*)Buffer+p); + } + + DoOutputDebugString("ScanForDisguisedPE: PE image located at: 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); + + return 1; + } + + DoOutputDebugString("ScanForDisguisedPE: No PE image located in range 0x%x-0x%x.\n", Buffer, (DWORD_PTR)Buffer + Size); return 0; } @@ -1256,11 +1261,13 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) DoOutputDebugString("DumpPEsInRange: Scanning range 0x%x - 0x%x.\n", Buffer, (BYTE*)Buffer + Size); - while (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) + if (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) { pDosHeader = (PIMAGE_DOS_HEADER)PEPointer; if (*(WORD*)PEPointer != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) { + DoOutputDebugString("DumpPEsInRange: Disguised PE image (bad MZ and/or PE headers) at 0x%x.\n", PEPointer); + // We want to fix the PE header in the dump (for e.g. disassembly etc) PEImage = (BYTE*)malloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); memcpy(PEImage, PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); @@ -1271,7 +1278,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); - if (DumpImageInCurrentProcess((DWORD)PEImage)) + if (DumpImageInCurrentProcess((LPVOID)PEImage)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); RetVal = TRUE; @@ -1283,7 +1290,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) { SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); - if (DumpImageInCurrentProcess((DWORD)PEPointer)) + if (DumpImageInCurrentProcess((LPVOID)PEPointer)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); RetVal = TRUE; @@ -1292,14 +1299,14 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); } - ((BYTE*)PEPointer)++; + //((BYTE*)PEPointer)++; } return RetVal; } //************************************************************************************** -int DumpMemory(LPVOID Buffer, unsigned int Size) +int DumpMemory(LPVOID Buffer, SIZE_T Size) //************************************************************************************** { char *FullPathName; @@ -1347,7 +1354,7 @@ int DumpMemory(LPVOID Buffer, unsigned int Size) return 0; } - if (FALSE == WriteFile(hOutputFile, BufferCopy, Size, &dwBytesWritten, NULL)) + if (FALSE == WriteFile(hOutputFile, BufferCopy, (DWORD)Size, &dwBytesWritten, NULL)) { DoOutputErrorString("DumpMemory: WriteFile error on CAPE output file"); free(FullPathName); @@ -1370,10 +1377,83 @@ int DumpMemory(LPVOID Buffer, unsigned int Size) } //************************************************************************************** -int DumpCurrentProcessFixImports(DWORD NewEP) +BOOL DumpRegion(PVOID Address) //************************************************************************************** { - if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcessFixImports(NewEP)) + MEMORY_BASIC_INFORMATION MemInfo; + PVOID OriginalAllocationBase, OriginalBaseAddress, AddressOfPage; + SIZE_T AllocationSize, OriginalRegionSize; + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("DumpRegion: Failed to obtain system page size.\n"); + return 0; + } + + if (!VirtualQuery(Address, &MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("DumpRegion: unable to query memory address 0x%x", Address); + return 0; + } + + OriginalAllocationBase = MemInfo.AllocationBase; + OriginalBaseAddress = MemInfo.BaseAddress; + OriginalRegionSize = MemInfo.RegionSize; + AddressOfPage = OriginalAllocationBase; + + while (MemInfo.AllocationBase == OriginalAllocationBase) + { + (PUCHAR)AddressOfPage += SystemInfo.dwPageSize; + + if (!VirtualQuery(AddressOfPage, &MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("DumpRegion: unable to query memory page 0x%x", AddressOfPage); + return 0; + } + } + + AllocationSize = (SIZE_T)((DWORD_PTR)AddressOfPage - (DWORD_PTR)OriginalAllocationBase); + + SetCapeMetaData(EXTRACTION_SHELLCODE, 0, NULL, (PVOID)OriginalAllocationBase); + + if (DumpMemory(OriginalAllocationBase, AllocationSize)) + { + if (address_is_in_stack(Address)) + DoOutputDebugString("DumpRegion: Dumped stack region from 0x%p, size 0x%x.\n", OriginalAllocationBase, AllocationSize); + else + DoOutputDebugString("DumpRegion: Dumped entire allocation from 0x%p, size 0x%x.\n", OriginalAllocationBase, AllocationSize); + return TRUE; + } + else + { + DoOutputDebugString("DumpRegion: Failed to dump entire allocation from 0x%p size 0x%x.\n", OriginalAllocationBase, AllocationSize); + + SetCapeMetaData(EXTRACTION_SHELLCODE, 0, NULL, (PVOID)OriginalBaseAddress); + + if (DumpMemory(OriginalBaseAddress, OriginalRegionSize)) + { + if (address_is_in_stack(Address)) + DoOutputDebugString("DumpRegion: Dumped stack region from 0x%p, size 0x%x.\n", OriginalBaseAddress, OriginalRegionSize); + else + DoOutputDebugString("DumpRegion: Dumped base address 0x%p, size 0x%x.\n", OriginalBaseAddress, OriginalRegionSize); + return TRUE; + } + else + { + DoOutputDebugString("DumpRegion: Failed to dump base address 0x%p size 0x%x.\n", OriginalBaseAddress, OriginalRegionSize); + return FALSE; + } + } +} + +//************************************************************************************** +int DumpCurrentProcessFixImports(LPVOID NewEP) +//************************************************************************************** +{ + if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcessFixImports((DWORD_PTR)NewEP)) { DumpCount++; return 1; @@ -1383,10 +1463,10 @@ int DumpCurrentProcessFixImports(DWORD NewEP) } //************************************************************************************** -int DumpCurrentProcessNewEP(DWORD NewEP) +int DumpCurrentProcessNewEP(LPVOID NewEP) //************************************************************************************** { - if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcess(NewEP)) + if (DumpCount < DUMP_MAX && ScyllaDumpCurrentProcess((DWORD_PTR)NewEP)) { DumpCount++; return 1; @@ -1409,12 +1489,12 @@ int DumpCurrentProcess() } //************************************************************************************** -int DumpModuleInCurrentProcess(DWORD_PTR ModuleBase) +int DumpModuleInCurrentProcess(LPVOID ModuleBase) //************************************************************************************** { SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); - if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), ModuleBase, 0)) + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) { DumpCount++; return 1; @@ -1424,7 +1504,7 @@ int DumpModuleInCurrentProcess(DWORD_PTR ModuleBase) } //************************************************************************************** -int DumpImageInCurrentProcess(DWORD_PTR ImageBase) +int DumpImageInCurrentProcess(LPVOID ImageBase) //************************************************************************************** { PIMAGE_DOS_HEADER pDosHeader; @@ -1470,7 +1550,7 @@ int DumpImageInCurrentProcess(DWORD_PTR ImageBase) { DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump 'raw' PE image.\n"); - if (ScyllaDumpPE(ImageBase)) + if (ScyllaDumpPE((DWORD_PTR)ImageBase)) { DumpCount++; return 1; @@ -1485,7 +1565,7 @@ int DumpImageInCurrentProcess(DWORD_PTR ImageBase) DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump virtual PE image.\n"); - if (!ScyllaDumpProcess(GetCurrentProcess(), ImageBase, 0)) + if (!ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ImageBase, 0)) { DoOutputDebugString("DumpImageInCurrentProcess: Failed to dump PE as virtual image.\n"); return 0; @@ -1496,10 +1576,10 @@ int DumpImageInCurrentProcess(DWORD_PTR ImageBase) } //************************************************************************************** -int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase) +int DumpProcess(HANDLE hProcess, LPVOID ImageBase) //************************************************************************************** { - if (DumpCount < DUMP_MAX && ScyllaDumpProcess(hProcess, ImageBase, 0)) + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(hProcess, (DWORD_PTR)ImageBase, 0)) { DumpCount++; return 1; @@ -1527,7 +1607,7 @@ int DumpPE(LPVOID Buffer) int RoutineProcessDump() //************************************************************************************** { - if (g_config.procmemdump && ProcessDumped == FALSE) + if (g_config.procdump && ProcessDumped == FALSE) { ProcessDumped = TRUE; // this prevents a second call before the first is complete if (g_config.import_reconstruction) @@ -1557,7 +1637,7 @@ void init_CAPE() CapeMetaData = (PCAPEMETADATA)malloc(sizeof(CAPEMETADATA)); CapeMetaData->Pid = GetCurrentProcessId(); CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); - WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, (int)wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); // Specific to Injection package: CapeMetaData->DumpType = INJECTION_SHELLCODE; // default value for now, may be changed to INJECTION_PE @@ -1569,22 +1649,24 @@ void init_CAPE() // made at the end of a process' lifetime. // It is normally only set in the base packages, // or upon submission. (This overrides submission.) - // g_config.procmemdump = 0; + // g_config.procdump = 0; // Cuckoo debug output level for development (0=none, 2=max) // g_config.debug = 2; #endif - // Start the debugger thread - // if required by package + // Start the debugger thread if required by package if (DEBUGGER_ENABLED) - launch_debugger(); + if (launch_debugger()) + DoOutputDebugString("Debugger initialised.\n"); + else + DoOutputDebugString("Failed to initialise debugger.\n"); #ifdef _WIN64 - DoOutputDebugString("CAPE initialised (64-bit).\n"); + DoOutputDebugString("CAPE initialised: 64-bit Injection package loaded at 0x%p, process image base 0x%p\n", g_our_dll_base, GetModuleHandle(NULL)); #else - DoOutputDebugString("CAPE initialised (32-bit).\n"); + DoOutputDebugString("CAPE initialised: 32-bit Injection package loaded at 0x%p, process image base 0x%p\n", g_our_dll_base, GetModuleHandle(NULL)); #endif return; -} \ No newline at end of file +} diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index b199af7..82e10e3 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -1,27 +1,48 @@ +/* +CAPE - Config And Payload Extraction +Copyright(C) 2015-2017 Context Information Security. (kevin.oreilly@contextis.com) + +This program is free software : you can redistribute it and / or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.If not, see . +*/ extern HMODULE s_hInst; extern WCHAR s_wzDllPath[MAX_PATH]; extern CHAR s_szDllPath[MAX_PATH]; + +//Global debugger switch +#define DEBUGGER_ENABLED 0 + +void GetHookCallerBase(); +PVOID GetPageAddress(PVOID Address); +PVOID GetAllocationBase(PVOID Address); BOOL TranslatePathFromDeviceToLetter(__in TCHAR *DeviceFilePath, __out TCHAR* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize); -int DumpMemory(LPVOID Buffer, SIZE_T Size); BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size); -int DumpCurrentProcessNewEP(DWORD NewEP); +BOOL DumpRegion(PVOID Address); +int DumpMemory(LPVOID Buffer, SIZE_T Size); +int DumpCurrentProcessNewEP(LPVOID NewEP); int DumpCurrentProcess(); -int DumpProcess(HANDLE hProcess, DWORD_PTR ImageBase); +int DumpProcess(HANDLE hProcess, LPVOID ImageBase); int DumpPE(LPVOID Buffer); -int ScyllaDumpPE(DWORD_PTR Buffer); -int ScanForNonZero(LPVOID Buffer, unsigned int Size); +int ScanForNonZero(LPVOID Buffer, SIZE_T Size); int ScanPageForNonZero(LPVOID Address); -int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); -int ScanForDisguisedPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); -int IsDisguisedPE(LPVOID Buffer, unsigned int Size); -int DumpImageInCurrentProcess(DWORD_PTR ImageBase); +int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); +int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); +int IsDisguisedPEHeader(LPVOID Buffer); +int DumpImageInCurrentProcess(LPVOID ImageBase); void DumpSectionViewsForPid(DWORD Pid); -unsigned int DumpSize; -SYSTEM_INFO SystemInfo; -//Global switch for debugger -#define DEBUGGER_ENABLED 0 -#define GUARD_PAGES_ENABLED 0 +SYSTEM_INFO SystemInfo; +PVOID CallingModule; typedef struct InjectionSectionView { @@ -122,8 +143,15 @@ enum { PLUGX_CONFIG = 0x11, EVILGRAB_PAYLOAD = 0x14, - EVILGRAB_DATA = 0x15 + EVILGRAB_DATA = 0x15, + + SEDRECO_DATA = 0x20, + + URSNIF_CONFIG = 0x24, + URSNIF_PAYLOAD = 0x25, + + CERBER_CONFIG = 0x30, + CERBER_PAYLOAD = 0x31 }; HANDLE EvilGrabRegHandle; - diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 64b2dd1..68f5453 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -21,6 +21,7 @@ along with this program.If not, see . #include #include #include "Debugger.h" +#include "..\alloc.h" #include "..\config.h" #include "..\pipe.h" @@ -59,11 +60,6 @@ typedef struct _DR7 DWORD LEN3 : 2; //Length bp3 } DR7, *PDR7; -#define NUMBER_OF_DEBUG_REGISTERS 4 -#define MAX_DEBUG_REGISTER_DATA_SIZE 4 -#define DEBUG_REGISTER_DATA_SIZES {1, 2, 4} -#define DEBUG_REGISTER_LENGTH_MASKS {0xFFFFFFFF, 0, 1, 0xFFFFFFFF, 3} - typedef struct _LSA_UNICODE_STRING { USHORT Length; USHORT MaximumLength; @@ -80,15 +76,20 @@ DWORD LengthMask[MAX_DEBUG_REGISTER_DATA_SIZE + 1] = DEBUG_REGISTER_LENGTH_MASKS DWORD MainThreadId; struct ThreadBreakpoints *MainThreadBreakpointList; -LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; SINGLE_STEP_HANDLER SingleStepHandler; GUARD_PAGE_HANDLER GuardPageHandler; -HANDLE hParentPipe; +HANDLE hCapePipe; + +extern SYSTEM_INFO SystemInfo; extern ULONG_PTR g_our_dll_base; extern DWORD g_our_dll_size; +extern BOOLEAN is_address_in_ntdll(ULONG_PTR address); +extern char *convert_address_to_dll_name_and_offset(ULONG_PTR addr, unsigned int *offset); extern LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); +extern BOOL ExtractionGuardPageHandler(struct _EXCEPTION_POINTERS* ExceptionInfo); +extern PVOID GetPageAddress(PVOID Address); extern unsigned int address_is_in_stack(DWORD Address); extern BOOL WoW64fix(void); extern BOOL WoW64PatchBreakpoint(unsigned int Register); @@ -98,313 +99,609 @@ extern DWORD MyGetThreadId(HANDLE hThread); extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -typedef void (WINAPI *PWIN32ENTRY)(); -PWIN32ENTRY OEP; - void DebugOutputThreadBreakpoints(); -BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL ClearSingleStepMode(PCONTEXT Context); unsigned int TrapIndex; +unsigned int DepthCount; +extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); + +//************************************************************************************** +BOOL CountDepth(LPVOID* ReturnAddress, LPVOID Address) +//************************************************************************************** +{ +#ifdef _WIN64 + if (DepthCount == 0 && ReturnAddress && Address) +#else + if (DepthCount == 2 && ReturnAddress && Address) +#endif + { + DepthCount = 0; + *ReturnAddress = Address; + return TRUE; + } + + DepthCount++; + + DoOutputDebugString("CountDepth: Address 0x%p, depthcount = %i.\n", Address, DepthCount); + + return FALSE; +} + //************************************************************************************** -BOOL IsInGuardPages(PVOID Address) +BOOL IsInTrackedRegions(PVOID Address) //************************************************************************************** { - PGUARDPAGES CurrentGuardPages = GuardPageList; + PTRACKEDREGION CurrentTrackedRegion = TrackedRegionList; - if (GuardPageList == NULL) + if (TrackedRegionList == NULL) return FALSE; - while (CurrentGuardPages) + while (CurrentTrackedRegion) { - if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentTrackedRegion->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentTrackedRegion->BaseAddress + (DWORD_PTR)CurrentTrackedRegion->RegionSize)) return TRUE; - CurrentGuardPages = CurrentGuardPages->NextGuardPages; + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } return FALSE; } //************************************************************************************** -PGUARDPAGES GetGuardPages(PVOID Address) +PTRACKEDREGION GetTrackedRegion(PVOID Address) //************************************************************************************** { - PGUARDPAGES CurrentGuardPages = GuardPageList; + PTRACKEDREGION CurrentTrackedRegion = TrackedRegionList; if (Address == NULL) { - DoOutputDebugString("GetGuardPages: NULL passed as argument - error.\n"); + DoOutputDebugString("GetTrackedRegion: NULL passed as argument - error.\n"); return FALSE; } - if (GuardPageList == NULL) + if (TrackedRegionList == NULL) { - DoOutputDebugString("GetGuardPages: failed to obtain initial guard page list.\n"); + //DoOutputDebugString("GetTrackedRegion: failed to obtain initial tracked region list.\n"); return FALSE; } - while (CurrentGuardPages) + while (CurrentTrackedRegion) { - if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) - return CurrentGuardPages; + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentTrackedRegion->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentTrackedRegion->BaseAddress + (DWORD_PTR)CurrentTrackedRegion->RegionSize)) + { + //DoOutputDebugString("GetTrackedRegion: found 0x%x in tracked region at 0x%x.\n", Address, CurrentTrackedRegion->BaseAddress); + return CurrentTrackedRegion; + } - CurrentGuardPages = CurrentGuardPages->NextGuardPages; + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } - DoOutputDebugString("GetGuardPages: failed to find guard pages in list.\n"); + //DoOutputDebugString("GetTrackedRegion: failed to find tracked region in list for address 0x%x.\n", Address); return NULL; } //************************************************************************************** -BOOL DropGuardPages(PGUARDPAGES GuardPages) +PTRACKEDREGION CreateTrackedRegion() //************************************************************************************** -{ - // DEBUG - DoOutputDebugString("DropGuardPages entry.\n"); +{ + if (TrackedRegionList == NULL) + { + TrackedRegionList = ((struct TrackedRegion*)malloc(sizeof(struct TrackedRegion))); + + if (TrackedRegionList == NULL) + { + DoOutputDebugString("CreateTrackedRegion: failed to allocate memory for initial tracked region list.\n"); + return NULL; + } + + memset(TrackedRegionList, 0, sizeof(struct TrackedRegion)); + } + + return TrackedRegionList; +} + +//************************************************************************************** +PTRACKEDREGION AddTrackedRegion(PVOID Address, SIZE_T RegionSize, ULONG Protect) +//************************************************************************************** +{ + BOOL PageAlreadyTracked; + PTRACKEDREGION CurrentTrackedRegion, PreviousTrackedRegion; + unsigned int NumberOfTrackedRegions; + + NumberOfTrackedRegions = 0; + PreviousTrackedRegion = NULL; + + if (TrackedRegionList == NULL) + CreateTrackedRegion(); + + CurrentTrackedRegion = TrackedRegionList; + + while (CurrentTrackedRegion) + { + if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentTrackedRegion->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentTrackedRegion->BaseAddress + (DWORD_PTR)CurrentTrackedRegion->RegionSize)) + PageAlreadyTracked = TRUE; + else + PageAlreadyTracked = FALSE; + + NumberOfTrackedRegions++; + + PreviousTrackedRegion = CurrentTrackedRegion; + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; + } + + if (NumberOfTrackedRegions > 10) + DoOutputDebugString("AddTrackedRegion: DEBUG Warning - number of tracked regions %d.\n", NumberOfTrackedRegions); + + if (GetPageAddress(Address) == GetPageAddress(TrackedRegionList)) + { + DoOutputDebugString("AddTrackedRegion: Warning - attempting to track the page (0x%p) containing the tracked region list at 0x%p.\n", Address, TrackedRegionList); + + return NULL; + } + + if (PageAlreadyTracked) + { + DoOutputDebugString("AddTrackedRegion: Region at 0x%p already in list.\n", Address); + return NULL; + } + + // We haven't found it in the linked list, so create a new one + CurrentTrackedRegion = PreviousTrackedRegion; + + CurrentTrackedRegion->NextTrackedRegion = ((struct TrackedRegion*)malloc(sizeof(struct TrackedRegion))); + + if (CurrentTrackedRegion->NextTrackedRegion == NULL) + { + DoOutputDebugString("AddTrackedRegion: Failed to allocate new tracked region struct.\n"); + return NULL; + } + + memset(CurrentTrackedRegion->NextTrackedRegion, 0, sizeof(struct TrackedRegion)); + + if (!VirtualQuery(Address, &CurrentTrackedRegion->MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("AddTrackedRegion: unable to query memory region 0x%p", Address); + return NULL; + } + + CurrentTrackedRegion->BaseAddress = CurrentTrackedRegion->MemInfo.BaseAddress; + + if (Address != CurrentTrackedRegion->BaseAddress) + CurrentTrackedRegion->ProtectAddress = Address; - PGUARDPAGES CurrentGuardPages, PreviousGuardPages; + if ((BYTE*)Address + RegionSize > (BYTE*)CurrentTrackedRegion->BaseAddress + CurrentTrackedRegion->MemInfo.RegionSize) + CurrentTrackedRegion->RegionSize = RegionSize; + else + CurrentTrackedRegion->RegionSize = CurrentTrackedRegion->MemInfo.RegionSize; + + CurrentTrackedRegion->Protect = Protect; + + //DoOutputDebugString("AddTrackedRegion: DEBUG - added region 0x%p to list at 0x%p - 0x%p.\n", Address, TrackedRegionList, (BYTE*)TrackedRegionList + NumberOfTrackedRegions*sizeof(TRACKEDREGION)); + + return CurrentTrackedRegion; +} + +//************************************************************************************** +BOOL DropTrackedRegion(PTRACKEDREGION TrackedRegion) +//************************************************************************************** +{ + PTRACKEDREGION CurrentTrackedRegion, PreviousTrackedRegion; - if (GuardPages == NULL) + if (TrackedRegion == NULL) { - DoOutputDebugString("DropGuardPages: NULL passed as argument - error.\n"); + DoOutputDebugString("DropTrackedRegion: NULL passed as argument - error.\n"); return FALSE; } - PreviousGuardPages = NULL; + PreviousTrackedRegion = NULL; - if (GuardPageList == NULL) + if (TrackedRegionList == NULL) { - DoOutputDebugString("DropGuardPages: failed to obtain initial guard page list.\n"); + DoOutputDebugString("DropTrackedRegion: failed to obtain initial tracked region list.\n"); return FALSE; } - CurrentGuardPages = GuardPageList; + CurrentTrackedRegion = TrackedRegionList; - while (CurrentGuardPages) + while (CurrentTrackedRegion) { - DoOutputDebugString("DropGuardPages: CurrentGuardPages 0x%x.\n", CurrentGuardPages); + DoOutputDebugString("DropTrackedRegion: CurrentTrackedRegion 0x%x, BaseAddress 0x%x.\n", CurrentTrackedRegion, CurrentTrackedRegion->BaseAddress); - if (CurrentGuardPages == GuardPages) + if (CurrentTrackedRegion == TrackedRegion) { - DoOutputDebugString("DropGuardPages: About to unlink.\n"); + // Clear any breakpoints in this region + ClearBreakpointsInRange(GetCurrentThreadId(), TrackedRegion->BaseAddress, TrackedRegion->RegionSize); + + DoOutputDebugString("DropTrackedRegion: About to unlink.\n"); // Unlink this from the list and free the memory - if (PreviousGuardPages && CurrentGuardPages->NextGuardPages) + if (PreviousTrackedRegion && CurrentTrackedRegion->NextTrackedRegion) { - DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); - PreviousGuardPages->NextGuardPages = CurrentGuardPages->NextGuardPages; + DoOutputDebugString("DropTrackedRegion: removed pages 0x%x-0x%x from tracked region list.\n", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); + PreviousTrackedRegion->NextTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } - else if (PreviousGuardPages && CurrentGuardPages->NextGuardPages == NULL) + else if (PreviousTrackedRegion && CurrentTrackedRegion->NextTrackedRegion == NULL) { - DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from the end of the guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); - PreviousGuardPages->NextGuardPages = NULL; + DoOutputDebugString("DropTrackedRegion: removed pages 0x%x-0x%x from the end of the tracked region list.\n", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); + PreviousTrackedRegion->NextTrackedRegion = NULL; } - else if (!PreviousGuardPages) + else if (!PreviousTrackedRegion) { - DoOutputDebugString("DropGuardPages: removed pages 0x%x-0x%x from the head of the guard page list.\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); - GuardPageList = NULL; + DoOutputDebugString("DropTrackedRegion: removed pages 0x%x-0x%x from the head of the tracked region list.\n", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); + TrackedRegionList = NULL; } - DoOutputDebugString("DropGuardPages: about to free the memory!\n"); - free(CurrentGuardPages); + DoOutputDebugString("DropTrackedRegion: about to free the memory!\n"); + free(CurrentTrackedRegion); return TRUE; } - PreviousGuardPages = CurrentGuardPages; - CurrentGuardPages = CurrentGuardPages->NextGuardPages; + PreviousTrackedRegion = CurrentTrackedRegion; + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } - DoOutputDebugString("DropGuardPages: failed to find guard pages in list.\n"); + DoOutputDebugString("DropTrackedRegion: failed to find tracked region in list.\n"); return FALSE; } //************************************************************************************** -BOOL ReinstateGuardPages(PGUARDPAGES GuardPages) +BOOL ActivateGuardPages(PTRACKEDREGION TrackedRegion) //************************************************************************************** { DWORD OldProtect; - BOOL GuardPagesFound = FALSE; - PGUARDPAGES CurrentGuardPages = GuardPageList; - MEMORY_BASIC_INFORMATION MemInfo; + BOOL TrackedRegionFound = FALSE; + PTRACKEDREGION CurrentTrackedRegion; + PVOID TestAddress; + SIZE_T MatchingRegionSize; + + if (TrackedRegion == NULL) + { + DoOutputDebugString("ActivateGuardPages: NULL passed as argument - error.\n"); + return FALSE; + } - if (GuardPageList == NULL) + if (TrackedRegionList == NULL) + { + DoOutputDebugString("ActivateGuardPages: Error - no tracked region list.\n"); return FALSE; + } - while (CurrentGuardPages) + CurrentTrackedRegion = TrackedRegionList; + + while (CurrentTrackedRegion) { - if (GuardPages->BaseAddress == CurrentGuardPages->BaseAddress) - GuardPagesFound = TRUE; + //DoOutputDebugString("TrackedRegion->BaseAddress 0x%x, CurrentTrackedRegion->BaseAddress 0x%x.\n", TrackedRegion->BaseAddress, CurrentTrackedRegion->BaseAddress); + + __try + { + TestAddress = CurrentTrackedRegion->BaseAddress; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ActivateGuardPages: Exception trying to access BaseAddres from tracked region at 0x%x", CurrentTrackedRegion); + return FALSE; + } + + if (TrackedRegion->BaseAddress == CurrentTrackedRegion->BaseAddress) + TrackedRegionFound = TRUE; - CurrentGuardPages = CurrentGuardPages->NextGuardPages; + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } - if (GuardPagesFound == FALSE) + if (!TrackedRegionFound) { - DoOutputDebugString("ReinstateGuardPages: failed to locate guard page(s) in guard page list.\n"); + DoOutputDebugString("ActivateGuardPages: failed to locate tracked region(s) in tracked region list.\n"); return FALSE; } - MatchingRegionSize = VirtualQuery(GuardPages->BaseAddress, &MemInfo, GuardPages->RegionSize); + MatchingRegionSize = VirtualQuery(TrackedRegion->BaseAddress, &TrackedRegion->MemInfo, sizeof(MEMORY_BASIC_INFORMATION)); if (!MatchingRegionSize) { - DoOutputErrorString("ReinstateGuardPages: failed to query guard page(s) status in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + DoOutputErrorString("ActivateGuardPages: failed to query tracked region(s) status in region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return FALSE; } + + //DoOutputDebugString("ActivateGuardPages: BaseAddress 0x%x, AllocationBase 0x%x, AllocationProtect 0x%x, RegionSize 0x%x, State 0x%x, Protect 0x%x, Type 0x%x\n", TrackedRegion->MemInfo.BaseAddress, TrackedRegion->MemInfo.AllocationBase, TrackedRegion->MemInfo.AllocationProtect, TrackedRegion->MemInfo.RegionSize, TrackedRegion->MemInfo.State, TrackedRegion->MemInfo.Protect, TrackedRegion->MemInfo.Type); - if (MatchingRegionSize == GuardPages->RegionSize && MemInfo.Protect & PAGE_GUARD) + if (MatchingRegionSize == TrackedRegion->RegionSize && TrackedRegion->MemInfo.Protect & PAGE_GUARD) { - DoOutputDebugString("ReinstateGuardPages: guard page(s) already set in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + DoOutputDebugString("ActivateGuardPages: guard page(s) already set in region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return FALSE; } - if (!VirtualProtect(GuardPages->BaseAddress, GuardPages->RegionSize, GuardPages->Protect | PAGE_GUARD, &OldProtect)) + if (!VirtualProtect(TrackedRegion->BaseAddress, TrackedRegion->RegionSize, TrackedRegion->Protect | PAGE_GUARD, &OldProtect)) { - DoOutputErrorString("ReinstateGuardPages: failed to reinstate guard page(s) on region 0x%x size 0x%x", GuardPages->BaseAddress, GuardPages->RegionSize); + DoOutputErrorString("ActivateGuardPages: failed to activate guard page(s) on region 0x%x size 0x%x", TrackedRegion->BaseAddress, TrackedRegion->RegionSize); return FALSE; } - // This is unreliable if some pages no longer have PAGE_GUARD, - // i.e. they have been touched, while others haven't - //if (OldProtect != GuardPages->Protect) - //{ - // DoOutputDebugString("ReinstateGuardPages error: inconsistency in protecton flags for region 0x%x-0x%x - OldProtect = 0x%x, GuardPages->Protect = 0x%x\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize, OldProtect, GuardPages->Protect); - //} + //DoOutputDebugString("ActivateGuardPages: Activated guard page(s) on region 0x%x size 0x%x", TrackedRegion->BaseAddress, TrackedRegion->RegionSize); + + return TRUE; +} + +//************************************************************************************** +BOOL ActivateGuardPagesOnProtectedRange(PTRACKEDREGION TrackedRegion) +//************************************************************************************** +{ + DWORD OldProtect; + BOOL TrackedRegionFound = FALSE; + PTRACKEDREGION CurrentTrackedRegion; + DWORD_PTR AddressOfPage; + SIZE_T Size; + PVOID TestAddress; + + if (TrackedRegion == NULL) + { + DoOutputDebugString("ActivateGuardPagesOnProtectedRange: NULL passed as argument - error.\n"); + return FALSE; + } + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("ActivateGuardPagesOnProtectedRange: Failed to obtain system page size.\n"); + return 0; + } + + if (TrackedRegionList == NULL) + { + DoOutputDebugString("ActivateGuardPagesOnProtectedRange: Error - no tracked region list.\n"); + return FALSE; + } + + CurrentTrackedRegion = TrackedRegionList; + + while (CurrentTrackedRegion) + { + //DoOutputDebugString("TrackedRegion->BaseAddress 0x%x, CurrentTrackedRegion->BaseAddress 0x%x.\n", TrackedRegion->BaseAddress, CurrentTrackedRegion->BaseAddress); + + __try + { + TestAddress = CurrentTrackedRegion->BaseAddress; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ActivateGuardPagesOnProtectedRange: Exception trying to access BaseAddress from tracked region at 0x%x", CurrentTrackedRegion); + return FALSE; + } + + if (TrackedRegion->BaseAddress == CurrentTrackedRegion->BaseAddress) + TrackedRegionFound = TRUE; + + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; + } + + if (!TrackedRegionFound) + { + DoOutputDebugString("ActivateGuardPagesOnProtectedRange: failed to locate tracked region(s) in tracked region list.\n"); + return FALSE; + } + + if (!TrackedRegion->ProtectAddress || !TrackedRegion->RegionSize) + { + DoOutputDebugString("ActivateGuardPagesOnProtectedRange: Protect address or size zero: 0x%x, 0x%x.\n", TrackedRegion->ProtectAddress, TrackedRegion->RegionSize); + return FALSE; + } + + if (!VirtualQuery(TrackedRegion->BaseAddress, &TrackedRegion->MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("ActivateGuardPagesOnProtectedRange: unable to query memory region 0x%x", TrackedRegion->BaseAddress); + return FALSE; + } + + AddressOfPage = ((DWORD_PTR)TrackedRegion->ProtectAddress/SystemInfo.dwPageSize)*SystemInfo.dwPageSize; + + Size = (BYTE*)TrackedRegion->ProtectAddress + TrackedRegion->RegionSize - (BYTE*)AddressOfPage; + if (!VirtualProtect((LPVOID)AddressOfPage, Size, TrackedRegion->Protect | PAGE_GUARD, &OldProtect)) + { + DoOutputErrorString("ActivateGuardPagesOnProtectedRange: failed to activate guard page(s) on region 0x%x size 0x%x", AddressOfPage, Size); + return FALSE; + } + return TRUE; } //************************************************************************************** -BOOL DisableGuardPages(PGUARDPAGES GuardPages) +BOOL DeactivateGuardPages(PTRACKEDREGION TrackedRegion) //************************************************************************************** { DWORD OldProtect; - BOOL GuardPagesFound = FALSE; - PGUARDPAGES CurrentGuardPages = GuardPageList; - MEMORY_BASIC_INFORMATION MemInfo; SIZE_T MatchingRegionSize; + BOOL TrackedRegionFound = FALSE; + PTRACKEDREGION CurrentTrackedRegion = TrackedRegionList; + PVOID TestAddress; - if (GuardPageList == NULL) + if (TrackedRegion == NULL) + { + DoOutputDebugString("DeactivateGuardPages: NULL passed as argument - error.\n"); + return FALSE; + } + + if (TrackedRegionList == NULL) + { + DoOutputDebugString("DeactivateGuardPages: Error - no tracked region list.\n"); return FALSE; + } + + //DoOutputDebugString("DeactivateGuardPages: DEBUG - tracked region list 0x%x, BaseAddress 0x%x.\n", CurrentTrackedRegion, CurrentTrackedRegion->BaseAddress); - while (CurrentGuardPages) + while (CurrentTrackedRegion) { - if (GuardPages->BaseAddress == CurrentGuardPages->BaseAddress) - GuardPagesFound = TRUE; + __try + { + TestAddress = CurrentTrackedRegion->BaseAddress; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("DeactivateGuardPages: Exception trying to access BaseAddres from tracked region at 0x%x", CurrentTrackedRegion); + return FALSE; + } - CurrentGuardPages = CurrentGuardPages->NextGuardPages; + if (TrackedRegion->BaseAddress == CurrentTrackedRegion->BaseAddress) + TrackedRegionFound = TRUE; + + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } - if (GuardPagesFound == FALSE) + if (!TrackedRegionFound) { - DoOutputDebugString("DisableGuardPages: failed to locate guard page(s) in guard page list.\n"); + DoOutputDebugString("DeactivateGuardPages: failed to locate tracked region(s) in tracked region list.\n"); return FALSE; } - MatchingRegionSize = VirtualQuery(GuardPages->BaseAddress, &MemInfo, GuardPages->RegionSize); + MatchingRegionSize = VirtualQuery(TrackedRegion->BaseAddress, &TrackedRegion->MemInfo, sizeof(MEMORY_BASIC_INFORMATION)); if (!MatchingRegionSize) { - DoOutputErrorString("DisableGuardPages: failed to query guard page(s) status in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + DoOutputErrorString("DeactivateGuardPages: failed to query tracked region(s) status in region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return FALSE; } - if (MatchingRegionSize == GuardPages->RegionSize && !(MemInfo.Protect & PAGE_GUARD)) + if (MatchingRegionSize == TrackedRegion->RegionSize && !(TrackedRegion->MemInfo.Protect & PAGE_GUARD)) { - DoOutputDebugString("DisableGuardPages: guard page(s) not set in region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + DoOutputDebugString("DeactivateGuardPages: guard page(s) not set in region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return FALSE; } - if (!VirtualProtect(GuardPages->BaseAddress, GuardPages->RegionSize, GuardPages->Protect, &OldProtect)) + if (!VirtualProtect(TrackedRegion->BaseAddress, TrackedRegion->RegionSize, TrackedRegion->Protect, &OldProtect)) { - DoOutputErrorString("DisableGuardPages: failed to disable guard page(s) on region 0x%x-0x%x", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize); + DoOutputErrorString("DeactivateGuardPages: failed to deactivate guard page(s) on region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return FALSE; } - //if (OldProtect != (GuardPages->Protect & PAGE_GUARD)) - //{ - // DoOutputDebugString("DisableGuardPages error: inconsistency in protecton flags for region 0x%x-0x%x - OldProtect = 0x%x, GuardPages->Protect = 0x%x\n", GuardPages->BaseAddress, (DWORD_PTR)GuardPages->BaseAddress + GuardPages->RegionSize, OldProtect, GuardPages->Protect); - //} + DoOutputDebugString("DeactivateGuardPages: DEBUG: Deactivated guard page(s) on region 0x%x-0x%x", TrackedRegion->BaseAddress, (DWORD_PTR)TrackedRegion->BaseAddress + TrackedRegion->RegionSize); return TRUE; } //************************************************************************************** -PGUARDPAGES CreateGuardPages() +BOOL ActivateSurroundingGuardPages(PTRACKEDREGION TrackedRegion) //************************************************************************************** -{ - if (GuardPageList == NULL) +{ + DWORD OldProtect, RetVal; + DWORD_PTR AddressOfPage, PagePointer; + BOOL TrackedRegionFound = FALSE; + PTRACKEDREGION CurrentTrackedRegion = TrackedRegionList; + PVOID TestAddress; + + if (TrackedRegionList == NULL) + { + DoOutputDebugString("ActivateSurroundingGuardPages: Error - TrackedRegionList NULL.\n"); + return 0; + } + + if (!SystemInfo.dwPageSize) + GetSystemInfo(&SystemInfo); + + if (!SystemInfo.dwPageSize) + { + DoOutputErrorString("ActivateSurroundingGuardPages: Failed to obtain system page size.\n"); + return 0; + } + + while (CurrentTrackedRegion) { - GuardPageList = ((struct GuardPages*)malloc(sizeof(struct GuardPages))); - - if (GuardPageList == NULL) + __try { - DoOutputDebugString("CreateGuardPages: failed to allocate memory for initial thread breakpoint list.\n"); - return NULL; + TestAddress = CurrentTrackedRegion->BaseAddress; } - memset(GuardPageList, 0, sizeof(struct GuardPages)); + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputErrorString("ActivateSurroundingGuardPages: Exception trying to access BaseAddres from tracked region at 0x%x", CurrentTrackedRegion); + return FALSE; + } + + if (TrackedRegion->BaseAddress == CurrentTrackedRegion->BaseAddress) + TrackedRegionFound = TRUE; + + CurrentTrackedRegion = CurrentTrackedRegion->NextTrackedRegion; } + + if (!TrackedRegionFound) + { + DoOutputDebugString("ActivateSurroundingGuardPages: Failed to locate tracked region(s) in tracked region list.\n"); + return FALSE; + } - return GuardPageList; -} + if (!TrackedRegion->LastAccessAddress) + { + DoOutputDebugString("ActivateSurroundingGuardPages: Error - Last access address not set.\n"); + return 0; + } -//************************************************************************************** -BOOL AddGuardPages(PVOID Address, SIZE_T RegionSize, ULONG Protect) -//************************************************************************************** -{ - BOOL PageAlreadyGuarded; - PGUARDPAGES CurrentGuardPages, PreviousGuardPages; - - PreviousGuardPages = NULL; + if ((DWORD_PTR)TrackedRegion->LastAccessAddress < (DWORD_PTR)TrackedRegion->BaseAddress || (DWORD_PTR)TrackedRegion->LastAccessAddress >= ((DWORD_PTR)TrackedRegion->BaseAddress + (DWORD_PTR)TrackedRegion->RegionSize)) + { + DoOutputDebugString("ActivateSurroundingGuardPages: Last access address 0x%x not within tracked region at 0x%x.\n", TrackedRegion->LastAccessAddress, TrackedRegion->BaseAddress); + return FALSE; + } - if (GuardPageList == NULL) - CreateGuardPages(); - - CurrentGuardPages = GuardPageList; + AddressOfPage = ((DWORD_PTR)TrackedRegion->LastAccessAddress/SystemInfo.dwPageSize)*SystemInfo.dwPageSize; - while (CurrentGuardPages) - { - if ((DWORD_PTR)Address >= (DWORD_PTR)CurrentGuardPages->BaseAddress && (DWORD_PTR)Address < ((DWORD_PTR)CurrentGuardPages->BaseAddress + (DWORD_PTR)CurrentGuardPages->RegionSize)) - PageAlreadyGuarded = TRUE; - else - PageAlreadyGuarded = FALSE; - - PreviousGuardPages = CurrentGuardPages; - CurrentGuardPages = CurrentGuardPages->NextGuardPages; - } + if (!VirtualQuery(TrackedRegion->BaseAddress, &TrackedRegion->MemInfo, sizeof(MEMORY_BASIC_INFORMATION))) + { + DoOutputErrorString("ProtectionHandler: unable to query memory region 0x%x", TrackedRegion->BaseAddress); + return FALSE; + } - if (PageAlreadyGuarded == FALSE) - { - // We haven't found it in the linked list, so create a new one - CurrentGuardPages = PreviousGuardPages; + for + ( + PagePointer = ((DWORD_PTR)TrackedRegion->BaseAddress/SystemInfo.dwPageSize)*SystemInfo.dwPageSize; + (BYTE*)PagePointer + SystemInfo.dwPageSize < (BYTE*)TrackedRegion->BaseAddress + TrackedRegion->RegionSize; + PagePointer += SystemInfo.dwPageSize + ) + { + // We skip the initial page if a switch to breakpoints has occured + if (PagePointer == (DWORD_PTR)TrackedRegion->BaseAddress && TrackedRegion->BreakpointsSet) + PagePointer += SystemInfo.dwPageSize; - CurrentGuardPages->NextGuardPages = ((struct GuardPages*)malloc(sizeof(struct GuardPages))); + if (PagePointer != AddressOfPage) + { + RetVal = VirtualProtect((LPVOID)PagePointer, SystemInfo.dwPageSize, TrackedRegion->Protect | PAGE_GUARD, &OldProtect); + + if (!RetVal) + { + DoOutputDebugString("ActivateSurroundingGuardPages: Failed to activate page guard on tracked region at 0x%x.\n", PagePointer); + return FALSE; + } + } + } + + return TRUE; +} + +//************************************************************************************** +PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId) +//************************************************************************************** +{ + DWORD CurrentThreadId; - if (CurrentGuardPages->NextGuardPages == NULL) - { - DoOutputDebugString("AddGuardPages: Failed to allocate new guard page struct.\n"); - return FALSE; - } - memset(CurrentGuardPages->NextGuardPages, 0, sizeof(struct GuardPages)); + PTHREADBREAKPOINTS CurrentThreadBreakpoint = MainThreadBreakpointList; + + while (CurrentThreadBreakpoint) + { + CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); - CurrentGuardPages->BaseAddress = Address; - CurrentGuardPages->RegionSize = RegionSize; - CurrentGuardPages->Protect = Protect; - CurrentGuardPages->WriteDetected = FALSE; - CurrentGuardPages->LastWriteAddress = NULL; - CurrentGuardPages->PagesDumped = FALSE; + if (CurrentThreadId == ThreadId) + return CurrentThreadBreakpoint; + else + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; } - return TRUE; + return NULL; } //************************************************************************************** -PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId) +HANDLE GetThreadHandle(DWORD ThreadId) //************************************************************************************** { DWORD CurrentThreadId; @@ -416,7 +713,7 @@ PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId) CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); if (CurrentThreadId == ThreadId) - return CurrentThreadBreakpoint; + return CurrentThreadBreakpoint->ThreadHandle; else CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; } @@ -442,8 +739,10 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) DoOutputDebugString("CreateThreadBreakpoints: failed to allocate memory for initial thread breakpoint list.\n"); return NULL; } + memset(MainThreadBreakpointList, 0, sizeof(struct ThreadBreakpoints)); - MainThreadBreakpointList->ThreadId = MainThreadId; + + MainThreadBreakpointList->ThreadId = MainThreadId; } CurrentThreadBreakpoint = MainThreadBreakpointList; @@ -479,6 +778,7 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) DoOutputDebugString("CreateThreadBreakpoints: Failed to allocate new thread breakpoints.\n"); return NULL; } + memset(CurrentThreadBreakpoint->NextThreadBreakpoints, 0, sizeof(struct ThreadBreakpoints)); CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; @@ -517,29 +817,77 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) } //************************************************************************************** -BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register) +BOOL InitNewThreadBreakpoints(DWORD ThreadId) //************************************************************************************** { - DWORD CurrentThreadId; - unsigned int i; + //DoOutputDebugString("InitNewThreadBreakpoints: Initialising breakpoints for thread %d.\n", ThreadId); + //return TRUE; + PTHREADBREAKPOINTS NewThreadBreakpoints; - PTHREADBREAKPOINTS CurrentThreadBreakpoint = MainThreadBreakpointList; - - if (CurrentThreadBreakpoint == NULL) + if (MainThreadBreakpointList == NULL) { - DoOutputDebugString("GetNextAvailableBreakpoint: MainThreadBreakpointList NULL.\n"); - return FALSE; + DoOutputDebugString("InitNewThreadBreakpoints: Failed to create thread breakpoints struct.\n"); + return FALSE; } - while (CurrentThreadBreakpoint) + NewThreadBreakpoints = CreateThreadBreakpoints(ThreadId); + + if (NewThreadBreakpoints == NULL) { - CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); + DoOutputDebugString("InitNewThreadBreakpoints: Cannot create new thread breakpoints.\n"); + return FALSE; + } + + if (NewThreadBreakpoints->ThreadHandle == NULL) + { + DoOutputDebugString("InitNewThreadBreakpoints error: main thread handle not set.\n"); + return FALSE; + } - if (CurrentThreadId == ThreadId) - { - for (i=0; i < NUMBER_OF_DEBUG_REGISTERS; i++) - { - if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) + for (unsigned int Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) + { + if (!MainThreadBreakpointList->BreakpointInfo[Register].Address) + continue; + + NewThreadBreakpoints->BreakpointInfo[Register] = MainThreadBreakpointList->BreakpointInfo[Register]; + + if (!NewThreadBreakpoints->BreakpointInfo[Register].Address) + DoOutputDebugString("InitNewThreadBreakpoints error: failed to copy the bleeding breakpoint struct!\n"); + + if (NewThreadBreakpoints->BreakpointInfo[Register].Address && !SetThreadBreakpoint(ThreadId, Register, NewThreadBreakpoints->BreakpointInfo[Register].Size, NewThreadBreakpoints->BreakpointInfo[Register].Address, NewThreadBreakpoints->BreakpointInfo[Register].Type, NewThreadBreakpoints->BreakpointInfo[Register].Callback)) + { + DoOutputDebugString("InitNewThreadBreakpoints error: failed to set breakpoint %d for new thread %d.\n", Register, ThreadId); + return FALSE; + } + } + + return TRUE; +} + +//************************************************************************************** +BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register) +//************************************************************************************** +{ + DWORD CurrentThreadId; + unsigned int i; + + PTHREADBREAKPOINTS CurrentThreadBreakpoint = MainThreadBreakpointList; + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("GetNextAvailableBreakpoint: MainThreadBreakpointList NULL.\n"); + return FALSE; + } + + while (CurrentThreadBreakpoint) + { + CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); + + if (CurrentThreadId == ThreadId) + { + for (i=0; i < NUMBER_OF_DEBUG_REGISTERS; i++) + { + if (CurrentThreadBreakpoint->BreakpointInfo[i].Address == NULL) { *Register = i; return TRUE; @@ -564,7 +912,7 @@ BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ContextGetNextAvailableBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", GetCurrentThreadId()); + DoOutputDebugString("ContextGetNextAvailableBreakpoint: Creating new thread breakpoints for thread %d.\n", GetCurrentThreadId()); CurrentThreadBreakpoint = CreateThreadBreakpoints(GetCurrentThreadId()); } @@ -631,6 +979,10 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { BREAKPOINT_HANDLER Handler; unsigned int bp; + PTRACKEDREGION TrackedRegion; + DWORD OldProtect; + //char* DllName; + //unsigned int DllRVA; // Hardware breakpoints generate EXCEPTION_SINGLE_STEP rather than EXCEPTION_BREAKPOINT if (ExceptionInfo->ExceptionRecord->ExceptionCode==EXCEPTION_SINGLE_STEP) @@ -638,7 +990,15 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) BOOL BreakpointFlag; PBREAKPOINTINFO pBreakpointInfo; PTHREADBREAKPOINTS CurrentThreadBreakpoint; - + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); + return EXCEPTION_CONTINUE_SEARCH; + } + // Test Dr6 to see if this is a breakpoint BreakpointFlag = FALSE; for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) @@ -650,15 +1010,18 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) } // If not it's a single-step - if (BreakpointFlag == FALSE) + if (!BreakpointFlag) { if (SingleStepHandler) SingleStepHandler(ExceptionInfo); else if (TrapIndex) - // this is from StepOverExecutionBreakpoint + // this is from a 'StepOver' function { DoOutputDebugString("CAPEExceptionFilter: Stepping over execution breakpoint to: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); - ResumeAfterExecutionBreakpoint(ExceptionInfo->ContextRecord); + + pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[TrapIndex-1]); + + ResumeAfterExecutionBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo); } else { @@ -669,15 +1032,12 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) return EXCEPTION_CONTINUE_EXECUTION; } - DoOutputDebugString("Entering CAPEExceptionFilter: breakpoint hit: 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); - - CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); - - if (CurrentThreadBreakpoint == NULL) - { - DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); - return EXCEPTION_CONTINUE_SEARCH; - } + if (TrapIndex) + { + DoOutputDebugString("CAPEExceptionFilter: Anomaly detected: Trap index set on non-single-step: %d\n", TrapIndex); + } + + DoOutputDebugString("CAPEExceptionFilter: breakpoint hit by instruction at 0x%p\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) { @@ -711,7 +1071,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetThreadBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -725,7 +1085,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetThreadBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -739,7 +1099,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on stack breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetThreadBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -753,7 +1113,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) { DoOutputDebugString("CAPEExceptionFilter: Reinstated BP_READWRITE on breakpoint %d (WoW64 workaround)\n", pBreakpointInfo->Register); - ContextSetBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); + ContextSetThreadBreakpoint(ExceptionInfo->ContextRecord, pBreakpointInfo->Register, pBreakpointInfo->Size, (BYTE*)pBreakpointInfo->Address, pBreakpointInfo->Type, pBreakpointInfo->Callback); } else { @@ -790,8 +1150,18 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) //DoOutputDebugString("Entering CAPEExceptionFilter: guarded page access at 0x%x by 0x%x\n", ExceptionInfo->ExceptionRecord->ExceptionInformation[1], ExceptionInfo->ExceptionRecord->ExceptionAddress); - if (IsInGuardPages((PVOID)ExceptionInfo->ExceptionRecord->ExceptionInformation[1])) + if (TrackedRegion = GetTrackedRegion((PVOID)ExceptionInfo->ExceptionRecord->ExceptionInformation[1])) { + if (is_address_in_ntdll((ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress)) + { + if (!VirtualProtect((PVOID)ExceptionInfo->ExceptionRecord->ExceptionInformation[1], 1, TrackedRegion->Protect | PAGE_GUARD, &OldProtect)) + { + DoOutputDebugString("CAPEExceptionFilter: Failed to re-activate page guard on tracked region around 0x%x touched by ntdll.\n", ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); + } + + return EXCEPTION_CONTINUE_EXECUTION; + } + if (GuardPageHandler) { if (GuardPageHandler(ExceptionInfo)) @@ -811,17 +1181,17 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) return EXCEPTION_CONTINUE_SEARCH; } } - else if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) - { - // This is likely our own DoOutputDebugString function! - // So we let Windows handle this so we get our output. - return EXCEPTION_CONTINUE_SEARCH; - } - else if (OriginalExceptionHandler) + //else if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) + //{ + // // This could be useful output + // // TODO: find string buffer(s) and send info to DoOutputDebugString + // return EXCEPTION_CONTINUE_SEARCH; + //} + else if (!VECTORED_HANDLER && OriginalExceptionHandler) { if ((ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress >= g_our_dll_base && (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress < (g_our_dll_base + g_our_dll_size)) { - // This is a CAPE exception, likely from the try/catch blocks in buffer scans + // This is a CAPE (or Cuckoo) exception return EXCEPTION_EXECUTE_HANDLER; } @@ -831,8 +1201,28 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) SetUnhandledExceptionFilter(OriginalExceptionHandler); return EXCEPTION_EXECUTE_HANDLER; } + else if (VECTORED_HANDLER && SampleVectoredHandler) + { + // As it's not a bp and the sample has registered its own handler + //DoOutputDebugString("CAPEExceptionFilter: Non-breakpoint exception caught, passing to sample's vectored handler.\n"); + SampleVectoredHandler(ExceptionInfo); + } + + if ((ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress >= g_our_dll_base && (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress < (g_our_dll_base + g_our_dll_size)) + { + // This is a CAPE (or Cuckoo) exception + DoOutputDebugString("CAPEExceptionFilter: Exception 0x%x caught at RVA 0x%x in capemon caught accessing 0x%x (expected in memory scans), passing to next handler.\n", ExceptionInfo->ExceptionRecord->ExceptionCode, (BYTE*)ExceptionInfo->ExceptionRecord->ExceptionAddress - g_our_dll_base, ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); + return EXCEPTION_CONTINUE_SEARCH; + } - // Some other exception occurred. Pass it to next handler. + // Some other exception occurred. Pass it to next handler. + //DllRVA = 0; + //if (ExceptionInfo->ExceptionRecord->ExceptionAddress) + // DllName = convert_address_to_dll_name_and_offset((ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress, &DllRVA); + //else + // DllName = "unknown"; + // + //DoOutputDebugString("CAPEExceptionFilter: Exception 0x%x caught at 0x%x accessing 0x%x (RVA 0x%x in %s) passing.\n", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress, ExceptionInfo->ExceptionRecord->ExceptionInformation[1], DllRVA, DllName); return EXCEPTION_CONTINUE_SEARCH; } @@ -848,6 +1238,9 @@ BOOL ContextSetDebugRegister ) { DWORD Length; +#ifdef _WIN64 + PTHREADBREAKPOINTS CurrentThreadBreakpoint; +#endif PDWORD_PTR Dr0 = &(Context->Dr0); PDWORD_PTR Dr1 = &(Context->Dr1); @@ -879,7 +1272,7 @@ BOOL ContextSetDebugRegister return FALSE; } - DoOutputDebugString("ContextSetDebugRegister: Setting breakpoint %i within Context, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, Size, Address, Type); + DoOutputDebugString("ContextSetDebugRegister: Setting breakpoint %i within Context, Size=0x%x, Address=0x%p and Type=0x%x.\n", Register, Size, Address, Type); Length = LengthMask[Size]; @@ -923,6 +1316,32 @@ BOOL ContextSetDebugRegister Dr7->LE = 1; Context->Dr6 = 0; + +#ifdef _WIN64 + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextSetDebugRegister: No breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + if (CurrentThreadBreakpoint->ThreadHandle == NULL) + { + DoOutputDebugString("ContextSetDebugRegister: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, Context)) + { + DoOutputErrorString("ContextSetDebugRegister: SetThreadContext failed"); + return FALSE; + } + else + DoOutputDebugString("ContextSetDebugRegister: SetThreadContext success.\n"); +#endif return TRUE; } @@ -941,11 +1360,11 @@ BOOL SetDebugRegister DWORD Length; CONTEXT Context; - PDWORD_PTR Dr0 = &Context.Dr0; - PDWORD_PTR Dr1 = &Context.Dr1; - PDWORD_PTR Dr2 = &Context.Dr2; - PDWORD_PTR Dr3 = &Context.Dr3; - PDR7 Dr7 = (PDR7)&(Context.Dr7); + PDWORD_PTR Dr0 = &Context.Dr0; + PDWORD_PTR Dr1 = &Context.Dr1; + PDWORD_PTR Dr2 = &Context.Dr2; + PDWORD_PTR Dr3 = &Context.Dr3; + PDR7 Dr7 = (PDR7)&(Context.Dr7); if ((unsigned int)Type > 3) { @@ -971,13 +1390,13 @@ BOOL SetDebugRegister return FALSE; } - DoOutputDebugString("SetDebugRegister: Setting breakpoint %i hThread=0x%x, Size=0x%x, Address=0x%x and Type=0x%x.\n", Register, hThread, Size, Address, Type); + DoOutputDebugString("SetDebugRegister: Setting breakpoint %i hThread=0x%x, Size=0x%x, Address=0x%p and Type=0x%x.\n", Register, hThread, Size, Address, Type); Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; if (!GetThreadContext(hThread, &Context)) { - DoOutputErrorString("SetDebugRegister: GetThreadContext failed"); + DoOutputErrorString("SetDebugRegister: GetThreadContext failed (thread handle 0x%x)", hThread); return FALSE; } @@ -1031,7 +1450,7 @@ BOOL SetDebugRegister DoOutputErrorString("SetDebugRegister: SetThreadContext failed"); return FALSE; } - + return TRUE; } @@ -1068,11 +1487,11 @@ BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext) PDWORD_PTR Dr1 = &Context.Dr1; PDWORD_PTR Dr2 = &Context.Dr2; PDWORD_PTR Dr3 = &Context.Dr3; - PDR7 Dr7 = (PDR7)&(Context.Dr7); + PDR7 Dr7 = (PDR7)&(Context.Dr7); if (!hThread && !pContext) { - DoOutputDebugString("CheckDebugRegisters - reqruied arguments missing.\n"); + DoOutputDebugString("CheckDebugRegisters - required arguments missing.\n"); return FALSE; } @@ -1111,7 +1530,7 @@ BOOL ContextClearAllBreakpoints(PCONTEXT Context) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ContextClearAllBreakpoints: No breakpoints found for current thread 0x%x.\n", GetCurrentThreadId()); + DoOutputDebugString("ContextClearAllBreakpoints: No breakpoints found for current thread %d.\n", GetCurrentThreadId()); return FALSE; } @@ -1130,64 +1549,86 @@ BOOL ContextClearAllBreakpoints(PCONTEXT Context) Context->Dr3 = 0; Context->Dr6 = 0; Context->Dr7 = 0; - + +#ifdef _WIN64 + if (CurrentThreadBreakpoint->ThreadHandle == NULL) + { + DoOutputDebugString("ContextClearAllBreakpoints: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, Context)) + { + DoOutputErrorString("ContextClearAllBreakpoints: SetThreadContext failed"); + return FALSE; + } + else + DoOutputDebugString("ContextClearAllBreakpoints: SetThreadContext success.\n"); +#endif + return TRUE; } //************************************************************************************** -BOOL ClearAllBreakpoints(DWORD ThreadId) +BOOL ClearAllBreakpoints() //************************************************************************************** { CONTEXT Context; PTHREADBREAKPOINTS CurrentThreadBreakpoint; - unsigned int Register; - DWORD CurrentThreadId; + unsigned int Register; CurrentThreadBreakpoint = MainThreadBreakpointList; while (CurrentThreadBreakpoint) { - CurrentThreadId = MyGetThreadId(CurrentThreadBreakpoint->ThreadHandle); - - if (CurrentThreadId == ThreadId) + if (!CurrentThreadBreakpoint->ThreadId) { - for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) - { - CurrentThreadBreakpoint->BreakpointInfo[Register].Register = 0; - CurrentThreadBreakpoint->BreakpointInfo[Register].Size = 0; - CurrentThreadBreakpoint->BreakpointInfo[Register].Address = NULL; - CurrentThreadBreakpoint->BreakpointInfo[Register].Type = 0; - CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = NULL; - } + DoOutputDebugString("ClearAllBreakpoints: Error: no thread id for thread breakpoints 0x%x.\n", CurrentThreadBreakpoint); + return FALSE; + } - Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; + if (!CurrentThreadBreakpoint->ThreadHandle) + { + DoOutputDebugString("ClearAllBreakpoints: Error no thread handle for thread %d.\n", CurrentThreadBreakpoint->ThreadId); + return FALSE; + } - if (!GetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) - { - DoOutputDebugString("ClearAllBreakpoints: Error getting thread context (thread %d).\n", CurrentThreadId); - return FALSE; - } + for (Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) + { + CurrentThreadBreakpoint->BreakpointInfo[Register].Register = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Size = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Address = NULL; + CurrentThreadBreakpoint->BreakpointInfo[Register].Type = 0; + CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = NULL; + } - Context.Dr0 = 0; - Context.Dr1 = 0; - Context.Dr2 = 0; - Context.Dr3 = 0; - Context.Dr6 = 0; - Context.Dr7 = 0; - - if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) - { - DoOutputDebugString("ClearAllBreakpoints: Error setting thread context (thread %d).\n", CurrentThreadId); - return FALSE; - } - - return TRUE; + Context.ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!GetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) + { + DoOutputDebugString("ClearAllBreakpoints: Error getting thread context (thread %d).\n", CurrentThreadBreakpoint->ThreadId); + return FALSE; } - else - CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; + + Context.Dr0 = 0; + Context.Dr1 = 0; + Context.Dr2 = 0; + Context.Dr3 = 0; + Context.Dr6 = 0; + Context.Dr7 = 0; + + if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, &Context)) + { + DoOutputDebugString("ClearAllBreakpoints: Error setting thread context (thread %d).\n", CurrentThreadBreakpoint->ThreadId); + return FALSE; + } + + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; } - return FALSE; + return TRUE; } //************************************************************************************** @@ -1206,7 +1647,7 @@ BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) Dr3 = &(Context->Dr3); Dr7 = (PDR7)&(Context->Dr7); - DoOutputDebugString("ContextClearBreakpoint: Clearing Context breakpoint %i\n", pBreakpointInfo->Register); + DoOutputDebugString("ContextClearBreakpoint: Clearing breakpoint %i\n", pBreakpointInfo->Register); if (pBreakpointInfo->Register == 0) { @@ -1243,6 +1684,24 @@ BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) #endif Context->Dr6 = 0; + +#ifdef _WIN64 + if (pBreakpointInfo->ThreadHandle == NULL) + { + DoOutputDebugString("ContextClearBreakpoint: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(pBreakpointInfo->ThreadHandle, Context)) + { + DoOutputErrorString("ContextClearBreakpoint: SetThreadContext failed"); + return FALSE; + } + else + DoOutputDebugString("ContextClearBreakpoint: SetThreadContext success.\n"); +#endif pBreakpointInfo->Address = 0; pBreakpointInfo->Size = 0; @@ -1334,9 +1793,11 @@ BOOL ClearSingleStepMode(PCONTEXT Context) if (Context == NULL) return FALSE; - // Clear the trap flag + // Clear the trap flag & index Context->EFlags &= ~FL_TF; + TrapIndex = 0; + SingleStepHandler = NULL; return TRUE; @@ -1378,12 +1839,28 @@ BOOL StepOverExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointIn // set the 'trap index' so we know which 'register' we're skipping // (off by one to allow 'set'/'unset' to be signified by !0/0) TrapIndex = pBreakpointInfo->Register + 1; + +#ifdef _WIN64 + if (pBreakpointInfo->ThreadHandle == NULL) + { + DoOutputDebugString("StepOverExecutionBreakpoint: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(pBreakpointInfo->ThreadHandle, Context)) + { + DoOutputErrorString("StepOverExecutionBreakpoint: SetThreadContext failed"); + return FALSE; + } +#endif return TRUE; } //************************************************************************************** -BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context) +BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo) //************************************************************************************** { PDR7 Dr7; @@ -1393,7 +1870,15 @@ BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context) Dr7 = (PDR7)&(Context->Dr7); - switch(TrapIndex-1) +#ifdef _WIN64 + if (!pBreakpointInfo) + { + DoOutputDebugString("ResumeAfterExecutionBreakpoint: pBreakpointInfo NULL.\n"); + return FALSE; + } +#endif + + switch(TrapIndex-1) { case 0: Dr7->L0 = 1; @@ -1412,9 +1897,25 @@ BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context) // Clear the trap flag Context->EFlags &= ~FL_TF; +#ifdef _WIN64 + if (pBreakpointInfo->ThreadHandle == NULL) + { + DoOutputDebugString("ResumeAfterExecutionBreakpoint: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(pBreakpointInfo->ThreadHandle, Context)) + { + DoOutputErrorString("ResumeAfterExecutionBreakpoint: SetThreadContext failed"); + return FALSE; + } +#endif + // clear the 'trap index' TrapIndex = 0; - + return TRUE; } @@ -1434,7 +1935,7 @@ BOOL ClearDebugRegister PDWORD_PTR Dr1 = &Context.Dr1; PDWORD_PTR Dr2 = &Context.Dr2; PDWORD_PTR Dr3 = &Context.Dr3; - PDR7 Dr7 = (PDR7)&(Context.Dr7); + PDR7 Dr7 = (PDR7)&(Context.Dr7); if ((unsigned int)Type > 3) { @@ -1575,8 +2076,55 @@ int CheckDebugRegister(HANDLE hThread, int Register) return -1; } + +//************************************************************************************** +BOOL ContextSetBreakpoint(PTHREADBREAKPOINTS ReferenceThreadBreakpoint) +//************************************************************************************** +{ + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + + if (ReferenceThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextSetBreakpoint: ReferenceThreadBreakpoint NULL.\n"); + return FALSE; + } + + if (MainThreadBreakpointList == NULL) + { + DoOutputDebugString("ContextSetBreakpoint: MainThreadBreakpointList NULL.\n"); + return FALSE; + } + + CurrentThreadBreakpoint = MainThreadBreakpointList; + + while (CurrentThreadBreakpoint) + { + if (CurrentThreadBreakpoint != ReferenceThreadBreakpoint) + { + for (unsigned int i = 0; i < NUMBER_OF_DEBUG_REGISTERS; i++) + { + if (CurrentThreadBreakpoint->ThreadHandle) + CurrentThreadBreakpoint->BreakpointInfo[i].ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; + CurrentThreadBreakpoint->BreakpointInfo[i].Register = ReferenceThreadBreakpoint->BreakpointInfo[i].Register; + CurrentThreadBreakpoint->BreakpointInfo[i].Size = ReferenceThreadBreakpoint->BreakpointInfo[i].Size; + CurrentThreadBreakpoint->BreakpointInfo[i].Address = ReferenceThreadBreakpoint->BreakpointInfo[i].Address; + CurrentThreadBreakpoint->BreakpointInfo[i].Type = ReferenceThreadBreakpoint->BreakpointInfo[i].Type; + CurrentThreadBreakpoint->BreakpointInfo[i].Callback = ReferenceThreadBreakpoint->BreakpointInfo[i].Callback; + + if (CurrentThreadBreakpoint->BreakpointInfo[i].Address) + SetThreadBreakpoint(CurrentThreadBreakpoint->ThreadId, CurrentThreadBreakpoint->BreakpointInfo[i].Register, CurrentThreadBreakpoint->BreakpointInfo[i].Size, CurrentThreadBreakpoint->BreakpointInfo[i].Address, CurrentThreadBreakpoint->BreakpointInfo[i].Type, CurrentThreadBreakpoint->BreakpointInfo[i].Callback); + } + } + + CurrentThreadBreakpoint = CurrentThreadBreakpoint->NextThreadBreakpoints; + } + + return TRUE; +} + + //************************************************************************************** -BOOL ContextSetBreakpoint +BOOL ContextSetThreadBreakpoint //************************************************************************************** ( PCONTEXT Context, @@ -1591,23 +2139,23 @@ BOOL ContextSetBreakpoint if (Register > 3 || Register < 0) { - DoOutputDebugString("ContextSetBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("ContextSetThreadBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } - if (ContextSetDebugRegister(Context, Register, Size, Address, Type) == FALSE) + if (!ContextSetDebugRegister(Context, Register, Size, Address, Type)) { - DoOutputDebugString("ContextSetBreakpoint: Call to ContextSetDebugRegister failed.\n"); + DoOutputDebugString("ContextSetThreadBreakpoint: Call to ContextSetDebugRegister failed.\n"); } else { - DoOutputDebugString("ContextSetBreakpoint: Call to ContextSetDebugRegister succeeded.\n"); + DoOutputDebugString("ContextSetThreadBreakpoint: Call to ContextSetDebugRegister succeeded.\n"); CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("Error: Failed to acquire thread breakpoints.\n"); + DoOutputDebugString("ContextSetThreadBreakpoint: Error - Failed to acquire thread breakpoints.\n"); return FALSE; } @@ -1619,6 +2167,28 @@ BOOL ContextSetBreakpoint CurrentThreadBreakpoint->BreakpointInfo[Register].Callback = Callback; } +#ifdef _WIN64 + if (CurrentThreadBreakpoint->ThreadHandle == NULL) + { + DoOutputDebugString("ContextSetThreadBreakpoint: No thread handle found in breakpoints found for current thread %d.\n", GetCurrentThreadId()); + return FALSE; + } + + Context->ContextFlags = CONTEXT_DEBUG_REGISTERS; + + if (!SetThreadContext(CurrentThreadBreakpoint->ThreadHandle, Context)) + { + DoOutputErrorString("ContextSetThreadBreakpoint: SetThreadContext failed"); + return FALSE; + } +#endif + + //if (!ContextSetBreakpoint(CurrentThreadBreakpoint)) + //{ + // DoOutputErrorString("ContextSetThreadBreakpoint: ContextSetBreakpoint failed"); + // return FALSE; + //} + return TRUE; } @@ -1634,13 +2204,28 @@ BOOL ContextSetNextAvailableBreakpoint PVOID Callback ) { - if (ContextGetNextAvailableBreakpoint(Context, Register) == FALSE) + if (Register) { - DoOutputDebugString("ContextSetNextAvailableBreakpoint: ContextGetNextAvailableBreakpoint failed\n"); - return FALSE; + if (!ContextGetNextAvailableBreakpoint(Context, Register)) + { + DoOutputDebugString("ContextSetNextAvailableBreakpoint: ContextGetNextAvailableBreakpoint failed\n"); + return FALSE; + } + + return ContextSetThreadBreakpoint(Context, *Register, Size, Address, Type, Callback); } + else + { + unsigned int TempRegister; + + if (!ContextGetNextAvailableBreakpoint(Context, &TempRegister)) + { + DoOutputDebugString("ContextSetNextAvailableBreakpoint: ContextGetNextAvailableBreakpoint failed\n"); + return FALSE; + } - return ContextSetBreakpoint(Context, *Register, Size, Address, Type, Callback); + return ContextSetThreadBreakpoint(Context, TempRegister, Size, Address, Type, Callback); + } } //************************************************************************************** @@ -1682,22 +2267,22 @@ BOOL ContextUpdateCurrentBreakpoint { if (bp == 0 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr0) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE0)) { - return ContextSetBreakpoint(Context, 0, Size, Address, Type, Callback); + return ContextSetThreadBreakpoint(Context, 0, Size, Address, Type, Callback); } if (bp == 1 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr1) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE1)) { - return ContextSetBreakpoint(Context, 1, Size, Address, Type, Callback); + return ContextSetThreadBreakpoint(Context, 1, Size, Address, Type, Callback); } if (bp == 2 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr2) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE2)) { - return ContextSetBreakpoint(Context, 2, Size, Address, Type, Callback); + return ContextSetThreadBreakpoint(Context, 2, Size, Address, Type, Callback); } if (bp == 3 && ((DWORD_PTR)pBreakpointInfo->Address == Context->Dr3) && ((DWORD)pBreakpointInfo->Type == ((PDR7)&(Context->Dr7))->RWE3)) { - return ContextSetBreakpoint(Context, 3, Size, Address, Type, Callback); + return ContextSetThreadBreakpoint(Context, 3, Size, Address, Type, Callback); } } } @@ -1707,34 +2292,66 @@ BOOL ContextUpdateCurrentBreakpoint } //************************************************************************************** -DWORD WINAPI SetBreakpointThread(LPVOID lpParam) +BOOL ContextClearCurrentBreakpoint //************************************************************************************** -{ - DWORD RetVal; - - PBREAKPOINTINFO pBreakpointInfo = (PBREAKPOINTINFO)lpParam; - +( + PCONTEXT Context +) +{ + PTHREADBREAKPOINTS CurrentThreadBreakpoint; + PBREAKPOINTINFO pBreakpointInfo; + unsigned int bp; + + CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ContextUpdateCurrentBreakpoint: Error - Failed to acquire thread breakpoints.\n"); + return FALSE; + } + + for (bp = 0; bp < NUMBER_OF_DEBUG_REGISTERS; bp++) + { + if (Context->Dr6 & (DWORD_PTR)(1 << bp)) + { + pBreakpointInfo = &(CurrentThreadBreakpoint->BreakpointInfo[bp]); + + if (pBreakpointInfo == NULL) + { + DoOutputDebugString("ContextUpdateCurrentBreakpoint: Can't get BreakpointInfo.\n"); + return FALSE; + } + + if (pBreakpointInfo->Register == bp) + return ContextClearBreakpoint(Context, pBreakpointInfo); + } + } + + return FALSE; +} + +//************************************************************************************** +DWORD WINAPI SetBreakpointThread(LPVOID lpParam) +//************************************************************************************** +{ + DWORD RetVal; + + PBREAKPOINTINFO pBreakpointInfo = (PBREAKPOINTINFO)lpParam; + if (SuspendThread(pBreakpointInfo->ThreadHandle) == 0xFFFFFFFF) - DoOutputErrorString("SetBreakpointThread: Call to SuspendThread failed"); + DoOutputErrorString("SetBreakpointThread: Call to SuspendThread failed for thread handle 0x%x", pBreakpointInfo->ThreadHandle); - if (SetDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) - { - DoOutputErrorString("SetBreakpointThread: Call to SetDebugRegister failed"); - } + if (!SetDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type)) + DoOutputErrorString("SetBreakpointThread: Call to SetDebugRegister failed for thread handle 0x%x", pBreakpointInfo->ThreadHandle); RetVal = ResumeThread(pBreakpointInfo->ThreadHandle); + if (RetVal == -1) - { - DoOutputErrorString("SetBreakpointThread: ResumeThread failed.\n"); - } + DoOutputErrorString("SetBreakpointThread: ResumeThread failed for thread handle 0x%x", pBreakpointInfo->ThreadHandle); else if (RetVal == 0) - { - DoOutputDebugString("SetBreakpointThread: Error - Sample thread was not suspended.\n"); - } + DoOutputDebugString("SetBreakpointThread: Error - thread with handle 0x%x was not suspended.\n", pBreakpointInfo->ThreadHandle); else if (g_config.debug) - { - DoOutputDebugString("SetBreakpointThread: Sample thread was suspended, now resumed.\n"); - } + DoOutputDebugString("SetBreakpointThread: Sample thread with handle 0x%x was suspended, now resumed.\n", pBreakpointInfo->ThreadHandle); return 1; } @@ -1749,7 +2366,7 @@ DWORD WINAPI ClearBreakpointThread(LPVOID lpParam) if (SuspendThread(pBreakpointInfo->ThreadHandle) == 0xFFFFFFFF) DoOutputErrorString("ClearBreakpointThread: Call to SuspendThread failed"); - if (ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) + if (!ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type)) { DoOutputDebugString("ClearBreakpointThread: Call to ClearDebugRegister failed.\n"); } @@ -1790,7 +2407,7 @@ BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ClearBreakpointWithoutThread: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + DoOutputDebugString("ClearBreakpointWithoutThread: Creating new thread breakpoints for thread %d.\n", ThreadId); CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } @@ -1808,7 +2425,7 @@ BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) return FALSE; } - if (ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type) == FALSE) + if (!ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type)) { DoOutputDebugString("ClearBreakpointWithoutThread: Call to ClearDebugRegister failed.\n"); return FALSE; @@ -1849,7 +2466,7 @@ BOOL SetBreakpointWithoutThread if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetBreakpointWithoutThread: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + DoOutputDebugString("SetBreakpointWithoutThread: Creating new thread breakpoints for thread %d.\n", ThreadId); CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } @@ -1876,7 +2493,7 @@ BOOL SetBreakpointWithoutThread __try { - RetVal = (SetDebugRegister(pBreakpointInfo->ThreadHandle, Register, Size, Address, Type)); + RetVal = SetDebugRegister(pBreakpointInfo->ThreadHandle, Register, Size, Address, Type); } __except(EXCEPTION_EXECUTE_HANDLER) { @@ -1891,7 +2508,7 @@ BOOL SetBreakpointWithoutThread } //************************************************************************************** -BOOL SetBreakpoint +BOOL SetThreadBreakpoint //************************************************************************************** ( DWORD ThreadId, @@ -1913,7 +2530,7 @@ BOOL SetBreakpoint if (Register > 3 || Register < 0) { - DoOutputDebugString("SetBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); + DoOutputDebugString("SetThreadBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } @@ -1921,13 +2538,13 @@ BOOL SetBreakpoint if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + DoOutputDebugString("SetThreadBreakpoint: Creating new thread breakpoints for thread %d.\n", ThreadId); CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetBreakpoint: Cannot create new thread breakpoints - error.\n"); + DoOutputDebugString("SetThreadBreakpoint: Cannot create new thread breakpoints - error.\n"); return FALSE; } @@ -1935,7 +2552,7 @@ BOOL SetBreakpoint if (CurrentThreadBreakpoint->ThreadHandle == NULL) { - DoOutputDebugString("SetBreakpoint: There is no thread handle in the thread breakpoint - Error.\n"); + DoOutputDebugString("SetThreadBreakpoint: There is no thread handle in the thread breakpoint - Error.\n"); return FALSE; } @@ -1947,80 +2564,146 @@ BOOL SetBreakpoint pBreakpointInfo->Callback = Callback; if (VECTORED_HANDLER) - AddVectoredExceptionHandler(1, CAPEExceptionFilter); + { + CAPEExceptionFilterHandle = AddVectoredExceptionHandler(1, CAPEExceptionFilter); + OriginalExceptionHandler = NULL; + } else + { OriginalExceptionHandler = SetUnhandledExceptionFilter(CAPEExceptionFilter); + CAPEExceptionFilterHandle = NULL; + } - __try - { - hSetBreakpointThread = CreateThread( - NULL, - 0, - SetBreakpointThread, - pBreakpointInfo, - 0, - &SetBreakpointThreadId); - } + __try + { + hSetBreakpointThread = CreateThread(NULL, 0, SetBreakpointThread, pBreakpointInfo, 0, &SetBreakpointThreadId); + } __except(EXCEPTION_EXECUTE_HANDLER) - { - DoOutputErrorString("SetBreakpoint: Unable to create SetBreakpointThread thread"); + { + DoOutputErrorString("SetThreadBreakpoint: An exception was raised creating SetBreakpointThread thread"); } - if (hSetBreakpointThread) + if (!hSetBreakpointThread) { - // If this hasn't happened in under a second, we bail - // and set without creating a thread - RetVal = WaitForSingleObject(hSetBreakpointThread, 1000); + DoOutputDebugString("SetThreadBreakpoint: Failed to create SetBreakpointThread thread, falling back to SetBreakpointWithoutThread.\n"); - if (RetVal != WAIT_OBJECT_0) - { - TerminateThread(hSetBreakpointThread, 0); - DoOutputDebugString("SetBreakpoint: SetBreakpointThread timeout, thread killed.\n"); - - RetVal = ResumeThread(CurrentThreadBreakpoint->ThreadHandle); - if (RetVal == -1) - { - DoOutputErrorString("SetBreakpoint: ResumeThread failed. About to set breakpoint without thread.\n"); - } - else if (RetVal == 0) - { - DoOutputDebugString("SetBreakpoint: Sample thread was not suspended. About to set breakpoint without thread.\n"); - } - else - { - DoOutputDebugString("SetBreakpoint: Sample thread was suspended, now resumed. About to set breakpoint without thread.\n"); - } - - return SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); - } - - DoOutputDebugString("SetBreakpoint: Set bp %d type %d at address 0x%x, size %d with Callback 0x%x, ThreadHandle = 0x%x.\n", - pBreakpointInfo->Register, - pBreakpointInfo->Type, - pBreakpointInfo->Address, - pBreakpointInfo->Size, - pBreakpointInfo->Callback, - pBreakpointInfo->ThreadHandle - ); - - CloseHandle(hSetBreakpointThread); - - return TRUE; - } - else - { __try { RetVal = SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputErrorString("SetBreakpoint: Error calling SetBreakpointWithoutThread"); + DoOutputErrorString("SetThreadBreakpoint: Error calling SetBreakpointWithoutThread"); return FALSE; } return RetVal; } + + // We wait for the thread to complete - if this hasn't happened + // in under a second, we bail and set without creating a thread + RetVal = WaitForSingleObject(hSetBreakpointThread, 1000); + + if (RetVal != WAIT_OBJECT_0) + { + TerminateThread(hSetBreakpointThread, 0); + DoOutputDebugString("SetThreadBreakpoint: SetBreakpointThread timeout, thread killed.\n"); + + RetVal = ResumeThread(CurrentThreadBreakpoint->ThreadHandle); + if (RetVal == -1) + { + DoOutputErrorString("SetThreadBreakpoint: ResumeThread failed. About to set breakpoint without thread.\n"); + } + else if (RetVal == 0) + { + DoOutputDebugString("SetThreadBreakpoint: Sample thread was not suspended. About to set breakpoint without thread.\n"); + } + else + { + DoOutputDebugString("SetThreadBreakpoint: Sample thread was suspended, now resumed. About to set breakpoint without thread.\n"); + } + + return SetBreakpointWithoutThread(ThreadId, Register, Size, Address, Type, Callback); + } + + DoOutputDebugString("SetThreadBreakpoint: Set bp %d thread id %d type %d at address 0x%p, size %d with Callback 0x%x.\n", + Register, + ThreadId, + Type, + Address, + Size, + Callback + ); + + CloseHandle(hSetBreakpointThread); + + return TRUE; +} + +//************************************************************************************** +BOOL SetBreakpoint +//************************************************************************************** +( + int Register, + int Size, + LPVOID Address, + DWORD Type, + PVOID Callback +) +{ + if (MainThreadBreakpointList == NULL) + { + DoOutputDebugString("SetBreakpoint: MainThreadBreakpointList NULL.\n"); + return FALSE; + } + + PTHREADBREAKPOINTS ThreadBreakpoints = MainThreadBreakpointList; + + while (ThreadBreakpoints) + { + if (ThreadBreakpoints->ThreadHandle) + ThreadBreakpoints->BreakpointInfo[Register].ThreadHandle = ThreadBreakpoints->ThreadHandle; + ThreadBreakpoints->BreakpointInfo[Register].Register = Register; + ThreadBreakpoints->BreakpointInfo[Register].Size = Size; + ThreadBreakpoints->BreakpointInfo[Register].Address = Address; + ThreadBreakpoints->BreakpointInfo[Register].Type = Type; + ThreadBreakpoints->BreakpointInfo[Register].Callback = Callback; + + DoOutputDebugString("SetBreakpoint: About to call SetThreadBreakpoint for thread %d.\n", ThreadBreakpoints->ThreadId); + + SetThreadBreakpoint(ThreadBreakpoints->ThreadId, Register, Size, Address, Type, Callback); + + ThreadBreakpoints = ThreadBreakpoints->NextThreadBreakpoints; + } + + return TRUE; +} + +//************************************************************************************** +BOOL SetThreadBreakpoints(PTHREADBREAKPOINTS ThreadBreakpoints) +//************************************************************************************** +{ + if (!ThreadBreakpoints->ThreadId) + { + DoOutputErrorString("SetThreadBreakpoints: Error - Thread ID missing from ThreadBreakpoints.\n"); + return FALSE; + } + + for (unsigned int Register = 0; Register < NUMBER_OF_DEBUG_REGISTERS; Register++) + { + if (!SetThreadBreakpoint + ( + ThreadBreakpoints->ThreadId, + ThreadBreakpoints->BreakpointInfo[Register].Register, + ThreadBreakpoints->BreakpointInfo[Register].Size, + ThreadBreakpoints->BreakpointInfo[Register].Address, + ThreadBreakpoints->BreakpointInfo[Register].Type, + ThreadBreakpoints->BreakpointInfo[Register].Callback + )) + return FALSE; + } + + return TRUE; } //************************************************************************************** @@ -2130,7 +2813,7 @@ BOOL SetNextAvailableBreakpoint if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetNextAvailableBreakpoint: Creating new thread breakpoints for thread 0x%x.\n", ThreadId); + DoOutputDebugString("SetNextAvailableBreakpoint: Creating new thread breakpoints for thread %d.\n", ThreadId); CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); } @@ -2140,13 +2823,13 @@ BOOL SetNextAvailableBreakpoint return FALSE; } - if (GetNextAvailableBreakpoint(ThreadId, Register) == FALSE) + if (!GetNextAvailableBreakpoint(ThreadId, Register)) { - DoOutputDebugString("SetNextAvailableBreakpoint: GetNextAvailableBreakpoint failed\n"); + DoOutputDebugString("SetNextAvailableBreakpoint: GetNextAvailableBreakpoint failed (breakpoints possibly full).\n"); return FALSE; } - return SetBreakpoint(ThreadId, *Register, Size, Address, Type, Callback); + return SetThreadBreakpoint(ThreadId, *Register, Size, Address, Type, Callback); } //************************************************************************************** @@ -2159,7 +2842,7 @@ BOOL InitialiseDebugger(void) if (DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &MainThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS) == 0) { - DoOutputDebugString("Failed to duplicate thread handle.\n"); + DoOutputDebugString("InitialiseDebugger: Failed to duplicate thread handle.\n"); return FALSE; } @@ -2167,7 +2850,7 @@ BOOL InitialiseDebugger(void) if (MainThreadBreakpointList == NULL) { - DoOutputDebugString("Failed to create thread breakpoints struct.\n"); + DoOutputDebugString("InitialiseDebugger: Failed to create thread breakpoints struct.\n"); return FALSE; } @@ -2177,15 +2860,31 @@ BOOL InitialiseDebugger(void) return FALSE; } - // Initialise any global variables + // Initialise global variables ChildProcessId = 0; SingleStepHandler = NULL; + SampleVectoredHandler = NULL; VECTORED_HANDLER = TRUE; #ifndef _WIN64 // Ensure wow64 patch is installed if needed WoW64fix(); #endif + + // Set up handler to catch breakpoint exceptions + if (VECTORED_HANDLER) + { + CAPEExceptionFilterHandle = AddVectoredExceptionHandler(1, CAPEExceptionFilter); + OriginalExceptionHandler = NULL; + } + else // deprecated alternative via unhandled exception filter + { + OriginalExceptionHandler = SetUnhandledExceptionFilter(CAPEExceptionFilter); + CAPEExceptionFilterHandle = NULL; + } + + // Global switch for guard pages + GuardPagesDisabled = TRUE; return TRUE; } @@ -2222,16 +2921,12 @@ __declspec (naked dllexport) void DebuggerInit(void) pushad } - if (InitialiseDebugger() == FALSE) + if (!InitialiseDebugger()) DoOutputDebugString("Debugger initialisation failure!\n"); // Package specific code -#ifdef STANDALONE - -#endif // End of package specific code - - DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); + DoOutputDebugString("Debugger initialisation complete, about to execute OEP at 0x%p\n", OEP); _asm { @@ -2251,13 +2946,12 @@ void DebuggerInit(void) StackPointer = GetNestedStackPointer() - 8; // this offset has been determined experimentally - TODO: tidy - if (InitialiseDebugger() == FALSE) + if (!InitialiseDebugger()) DoOutputDebugString("Debugger initialisation failure!\n"); else DoOutputDebugString("Debugger initialised, ESP = 0x%x\n", StackPointer); // Package specific code - // End of package specific code DoOutputDebugString("Debugger initialisation complete, about to execute OEP.\n"); @@ -2267,26 +2961,23 @@ void DebuggerInit(void) #pragma optimize("", on) #endif -BOOL SendDebuggerMessage(DWORD Input) +BOOL SendDebuggerMessage(PVOID Input) { BOOL fSuccess; DWORD cbReplyBytes, cbWritten; - //struct DEBUGGER_DATA DebuggerData; - - //memset(&DebuggerData, 0, sizeof(struct DEBUGGER_DATA)); - cbReplyBytes = sizeof(DWORD_PTR); + cbReplyBytes = sizeof(PVOID); - if (hParentPipe == NULL) + if (hCapePipe == NULL) { - DoOutputErrorString("SendDebuggerMessage: hParentPipe NULL."); + DoOutputErrorString("SendDebuggerMessage: hCapePipe NULL."); return FALSE; } // Write the reply to the pipe. fSuccess = WriteFile ( - hParentPipe, // handle to pipe + hCapePipe, // handle to pipe &Input, // buffer to write from cbReplyBytes, // number of bytes to write &cbWritten, // number of bytes written @@ -2299,162 +2990,11 @@ BOOL SendDebuggerMessage(DWORD Input) return FALSE; } - DoOutputDebugString("SendDebuggerMessage: Sent message via pipe.\n"); + DoOutputDebugString("SendDebuggerMessage: Sent message via pipe: 0x%x\n", Input); return TRUE; } -//************************************************************************************** -DWORD WINAPI DebuggerLaunch(LPVOID lpParam) -//************************************************************************************** -{ - HANDLE hPipe; - BOOL fSuccess = FALSE, NT5; - DWORD cbRead, cbToWrite, cbWritten, dwMode; - PVOID FuncAddress; - - char lpszPipename[MAX_PATH]; - OSVERSIONINFO VersionInfo; - - DoOutputDebugString("DebuggerLaunch: About to connect to CAPEpipe.\n"); - - memset(lpszPipename, 0, MAX_PATH*sizeof(CHAR)); - sprintf_s(lpszPipename, MAX_PATH, "\\\\.\\pipe\\CAPEpipe_%x", GetCurrentProcessId()); - while (1) - { - hPipe = CreateFile( - lpszPipename, - GENERIC_READ | - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); - - if (hPipe != INVALID_HANDLE_VALUE) - break; - - if (GetLastError() != ERROR_PIPE_BUSY) - { - DoOutputErrorString("DebuggerLaunch: Could not open pipe"); - return -1; - } - - if (!WaitNamedPipe(lpszPipename, 20)) - { - DoOutputDebugString("DebuggerLaunch: Could not open pipe: 20 ms wait timed out.\n"); - return -1; - } - } - - // The pipe connected; change to message-read mode. - dwMode = PIPE_READMODE_MESSAGE; - fSuccess = SetNamedPipeHandleState - ( - hPipe, - &dwMode, - NULL, - NULL - ); - if (!fSuccess) - { - DoOutputDebugString("DebuggerLaunch: SetNamedPipeHandleState failed.\n"); - return -1; - } - - // Send VA of DebuggerInit to loader - FuncAddress = &DebuggerInit; - - cbToWrite = sizeof(PVOID); - - fSuccess = WriteFile - ( - hPipe, - &FuncAddress, - cbToWrite, - &cbWritten, - NULL - ); - if (!fSuccess) - { - DoOutputErrorString("DebuggerLaunch: WriteFile to pipe failed"); - return -1; - } - - DoOutputDebugString("DebuggerLaunch: DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); - - fSuccess = ReadFile( - hPipe, - &OEP, - sizeof(DWORD_PTR), - &cbRead, - NULL); - - if (!fSuccess && GetLastError() == ERROR_MORE_DATA) - { - DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); - CloseHandle(hPipe); - return -1; - } - - if (!fSuccess) - { - DoOutputErrorString("DebuggerLaunch: ReadFile (OEP) from pipe failed"); - CloseHandle(hPipe); - return -1; - } - - DoOutputDebugString("Read OEP from pipe: 0x%x\n", OEP); - - fSuccess = ReadFile( - hPipe, - &OEP, - sizeof(DWORD_PTR), - &cbRead, - NULL); - - if (!fSuccess && GetLastError() == ERROR_MORE_DATA) - { - DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); - CloseHandle(hPipe); - return -1; - } - - if (!fSuccess && GetLastError() == ERROR_BROKEN_PIPE) - { - DoOutputDebugString("DebuggerLaunch: Pipe closed, no further updates to OEP\n"); - CloseHandle(hPipe); - } - else if (!fSuccess) - { - DoOutputErrorString("ReadFile from pipe failed"); - CloseHandle(hPipe); - return -1; - } - else - DoOutputDebugString("Read thread EP from pipe: 0x%x\n", OEP); - - ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO)); - VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&VersionInfo); - - NT5 = (VersionInfo.dwMajorVersion == 5); - - if (NT5) - { - DoOutputDebugString("NT5: Leaving debugger thread alive.\n"); - while(1) - { - Sleep(500000); - } - } - - DoOutputDebugString("NT6+: Terminating debugger thread.\n"); - - return 0; -} - //************************************************************************************** BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD CreationFlags) //************************************************************************************** @@ -2466,6 +3006,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati DWORD cbBytesRead, cbWritten, cbReplyBytes; memset(lpszPipename, 0, MAX_PATH*sizeof(CHAR)); + sprintf_s(lpszPipename, MAX_PATH, "\\\\.\\pipe\\CAPEpipe_%x", ProcessId); hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, ProcessId); @@ -2482,7 +3023,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati return FALSE; } - hParentPipe = CreateNamedPipe + hCapePipe = CreateNamedPipe ( lpszPipename, PIPE_ACCESS_DUPLEX, @@ -2496,7 +3037,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati NULL ); - if (hParentPipe == INVALID_HANDLE_VALUE) + if (hCapePipe == INVALID_HANDLE_VALUE) { DoOutputErrorString("DebugNewProcess: CreateNamedPipe failed"); return FALSE; @@ -2505,23 +3046,23 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati DoOutputDebugString("DebugNewProcess: Announcing new process to Cuckoo, pid: %d\n", ProcessId); pipe("DEBUGGER:%d,%d", ProcessId, ThreadId); - fConnected = ConnectNamedPipe(hParentPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); + fConnected = ConnectNamedPipe(hCapePipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); fSuccess = FALSE; cbBytesRead = 0; if (!fConnected) { DoOutputDebugString("DebugNewProcess: The client could not connect, closing pipe.\n"); - CloseHandle(hParentPipe); + CloseHandle(hCapePipe); return FALSE; } - DoOutputDebugString("DebugNewProcess: Client connected\n"); + DoOutputDebugString("DebugNewProcess: Client connected.\n"); fSuccess = ReadFile ( - hParentPipe, - &RemoteFuncAddress, + hCapePipe, + &DebuggerEP, sizeof(DWORD_PTR), &cbBytesRead, NULL @@ -2539,9 +3080,9 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati } } - if (!RemoteFuncAddress) + if (!DebuggerEP) { - DoOutputErrorString("DebugNewProcess: Successfully read from pipe, however RemoteFuncAddress = 0."); + DoOutputErrorString("DebugNewProcess: Successfully read from pipe, however DebuggerEP = 0."); return FALSE; } @@ -2564,7 +3105,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati // Send the OEP to the new process fSuccess = WriteFile ( - hParentPipe, + hCapePipe, &OEP, cbReplyBytes, &cbWritten, @@ -2576,14 +3117,14 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati return FALSE; } - DoOutputDebugString("DebugNewProcess: Sent OEP 0x%x via pipe\n", OEP); + DoOutputDebugString("DebugNewProcess: Sent OEP 0x%p via pipe\n", OEP); Context.ContextFlags = CONTEXT_ALL; #ifdef _WIN64 - Context.Rcx = RemoteFuncAddress; // set the new EP to debugger_init + Context.Rcx = DebuggerEP; // set the new EP to debugger_init #else - Context.Eax = RemoteFuncAddress; + Context.Eax = DebuggerEP; #endif if (!SetThreadContext(hThread, &Context)) @@ -2605,31 +3146,196 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati } //************************************************************************************** -int launch_debugger() +DWORD WINAPI DebuggerLaunch(LPVOID lpParam) //************************************************************************************** -{ - DWORD NewThreadId; - HANDLE hDebuggerLaunch; +{ + HANDLE hPipe; + BOOL fSuccess = FALSE, NT5; + DWORD cbRead, cbToWrite, cbWritten, dwMode; + PVOID FuncAddress; + + char lpszPipename[MAX_PATH]; + OSVERSIONINFO VersionInfo; + + DoOutputDebugString("DebuggerLaunch: About to connect to CAPEpipe.\n"); + + memset(lpszPipename, 0, MAX_PATH*sizeof(CHAR)); + + sprintf_s(lpszPipename, MAX_PATH, "\\\\.\\pipe\\CAPEpipe_%x", GetCurrentProcessId()); + + while (1) + { + hPipe = CreateFile( + lpszPipename, + GENERIC_READ | + GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + 0, + NULL); + + if (hPipe != INVALID_HANDLE_VALUE) + break; + + if (GetLastError() != ERROR_PIPE_BUSY) + { + DoOutputErrorString("DebuggerLaunch: Could not open pipe"); + return -1; + } + + if (!WaitNamedPipe(lpszPipename, 20)) + { + DoOutputDebugString("DebuggerLaunch: Could not open pipe: 20 ms wait timed out.\n"); + return -1; + } + } + + // The pipe connected; change to message-read mode. + dwMode = PIPE_READMODE_MESSAGE; + fSuccess = SetNamedPipeHandleState + ( + hPipe, + &dwMode, + NULL, + NULL + ); + if (!fSuccess) + { + DoOutputDebugString("DebuggerLaunch: SetNamedPipeHandleState failed.\n"); + return -1; + } + + // Send VA of DebuggerInit to loader + FuncAddress = &DebuggerInit; + + cbToWrite = sizeof(PVOID); + + fSuccess = WriteFile + ( + hPipe, + &FuncAddress, + cbToWrite, + &cbWritten, + NULL + ); + if (!fSuccess) + { + DoOutputErrorString("DebuggerLaunch: WriteFile to pipe failed"); + return -1; + } - hDebuggerLaunch = CreateThread( - NULL, - 0, - DebuggerLaunch, - NULL, - 0, - &NewThreadId); + DoOutputDebugString("DebuggerLaunch: DebuggerInit VA sent to loader: 0x%x\n", FuncAddress); - if (hDebuggerLaunch == NULL) + fSuccess = ReadFile( + hPipe, + &OEP, + sizeof(DWORD_PTR), + &cbRead, + NULL); + + if (!fSuccess && GetLastError() == ERROR_MORE_DATA) + { + DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); + CloseHandle(hPipe); + return -1; + } + + if (!fSuccess) + { + DoOutputErrorString("DebuggerLaunch: ReadFile (OEP) from pipe failed"); + CloseHandle(hPipe); + return -1; + } + + DoOutputDebugString("DebuggerLaunch: Read OEP from pipe: 0x%p\n", OEP); + + while (1) { - DoOutputDebugString("CAPE: Failed to create debugger launch thread.\n"); - return 0; + fSuccess = ReadFile( + hPipe, + &OEP, + sizeof(DWORD_PTR), + &cbRead, + NULL); + + if (!fSuccess && GetLastError() == ERROR_BROKEN_PIPE) + { + DoOutputDebugString("DebuggerLaunch: Pipe closed, no further updates to OEP\n"); + CloseHandle(hPipe); + break; + } + + if (!fSuccess && GetLastError() == ERROR_MORE_DATA) + { + DoOutputDebugString("DebuggerLaunch: ReadFile on Pipe: ERROR_MORE_DATA\n"); + CloseHandle(hPipe); + return -1; + } + + if (!fSuccess) + { + DoOutputErrorString("DebuggerLaunch: ReadFile from pipe failed"); + CloseHandle(hPipe); + return -1; + } + else + DoOutputDebugString("DebuggerLaunch: Read updated EP from pipe: 0x%p\n", OEP); } - else + + ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO)); + VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&VersionInfo); + + NT5 = (VersionInfo.dwMajorVersion == 5); + + if (NT5) { - DoOutputDebugString("CAPE: Launching debugger.\n"); + DoOutputDebugString("NT5: Leaving debugger thread alive.\n"); + while (1) + { + Sleep(500000); + } } - CloseHandle(hDebuggerLaunch); + DoOutputDebugString("NT6+: Terminating debugger thread.\n"); - return 1; + return 0; +} + +//************************************************************************************** +int launch_debugger() +//************************************************************************************** +{ + if (DEBUGGER_LAUNCHER) + { + DWORD NewThreadId; + HANDLE hDebuggerLaunch; + + hDebuggerLaunch = CreateThread( + NULL, + 0, + DebuggerLaunch, + NULL, + 0, + &NewThreadId); + + if (hDebuggerLaunch == NULL) + { + DoOutputDebugString("CAPE: Failed to create debugger launch thread.\n"); + return 0; + } + + DoOutputDebugString("CAPE: Launching debugger.\n"); + + CloseHandle(hDebuggerLaunch); + + return 1; + } + else + { + DebuggerInitialised = InitialiseDebugger(); + + return DebuggerInitialised; + } } \ No newline at end of file diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 7e0fa41..601052f 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -1,12 +1,21 @@ #pragma once +#pragma once -void* CAPE_var; +#define DEBUGGER_LAUNCHER 0 +#define DisableThreadSuspend 0 #define BP_EXEC 0x00 #define BP_WRITE 0x01 #define BP_RESERVED 0x02 #define BP_READWRITE 0x03 +#define NUMBER_OF_DEBUG_REGISTERS 4 +#define MAX_DEBUG_REGISTER_DATA_SIZE 4 +#define DEBUG_REGISTER_DATA_SIZES {1, 2, 4} +#define DEBUG_REGISTER_LENGTH_MASKS {0xFFFFFFFF, 0, 1, 0xFFFFFFFF, 3} + +#define EXECUTABLE_FLAGS (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) + #define EXTRACTION_MIN_SIZE 0x1001 typedef struct _EXCEPTION_REGISTRATION_RECORD { @@ -16,14 +25,6 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD { typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD; -PEXCEPTION_ROUTINE SEH_TopLevelHandler; -LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; -LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); -BOOL VECTORED_HANDLER; - -DWORD ChildProcessId; -DWORD_PTR RemoteFuncAddress; - typedef struct BreakpointInfo { HANDLE ThreadHandle; @@ -36,7 +37,7 @@ typedef struct BreakpointInfo typedef BOOL (cdecl *BREAKPOINT_HANDLER)(PBREAKPOINTINFO, struct _EXCEPTION_POINTERS*); -typedef struct ThreadBreakpoints +typedef struct ThreadBreakpoints { DWORD ThreadId; HANDLE ThreadHandle; @@ -44,76 +45,125 @@ typedef struct ThreadBreakpoints struct ThreadBreakpoints *NextThreadBreakpoints; } THREADBREAKPOINTS, *PTHREADBREAKPOINTS; -typedef struct GuardPages +typedef struct TrackedRegion { PVOID BaseAddress; + PVOID ProtectAddress; SIZE_T RegionSize; ULONG Protect; - BOOL WriteDetected; + MEMORY_BASIC_INFORMATION MemInfo; + BOOL Committed; + PVOID LastAccessAddress; PVOID LastWriteAddress; + PVOID LastReadAddress; + BOOL WriteDetected; BOOL ReadDetected; + PVOID LastAccessBy; + PVOID LastWrittenBy; PVOID LastReadBy; BOOL PagesDumped; - struct GuardPages *NextGuardPages; -} GUARDPAGES, *PGUARDPAGES; - -struct GuardPages *GuardPageList; + BOOL CanDump; + BOOL Guarded; + unsigned int WriteCounter; + // under review + BOOL WriteBreakpointSet; + BOOL PeImageDetected; + BOOL AllocationBaseExecBpSet; + BOOL AllocationWriteDetected; + // + PVOID ExecBp; + unsigned int ExecBpRegister; + PVOID MagicBp; + unsigned int MagicBpRegister; + BOOL BreakpointsSet; + BOOL BreakpointsSaved; + struct ThreadBreakpoints *TrackedRegionBreakpoints; + struct TrackedRegion *NextTrackedRegion; +} TRACKEDREGION, *PTRACKEDREGION; + +struct TrackedRegion *TrackedRegionList; typedef BOOL (cdecl *SINGLE_STEP_HANDLER)(struct _EXCEPTION_POINTERS*); typedef BOOL (cdecl *GUARD_PAGE_HANDLER)(struct _EXCEPTION_POINTERS*); +typedef BOOL (cdecl *SAMPLE_HANDLER)(struct _EXCEPTION_POINTERS*); + +typedef void (WINAPI *PWIN32ENTRY)(); #ifdef __cplusplus extern "C" { #endif +BOOL DebuggerInitialised; -BOOL SetBreakpoint -( - DWORD ThreadId, - int Register, - int Size, - LPVOID Address, - DWORD Type, - PVOID Callback -); +// Global variables for submission options +void *CAPE_var1, *CAPE_var2, *CAPE_var3, *CAPE_var4; +PVOID bp0, bp1, bp2, bp3; -BOOL ClearBreakpoint(DWORD ThreadId, int Register); +LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); +PVOID CAPEExceptionFilterHandle; +SAMPLE_HANDLER SampleVectoredHandler; +PEXCEPTION_ROUTINE SEH_TopLevelHandler; +LPTOP_LEVEL_EXCEPTION_FILTER OriginalExceptionHandler; +BOOL VECTORED_HANDLER; +BOOL GuardPagesDisabled; -BOOL ContextSetBreakpoint -( - PCONTEXT Context, - int Register, - int Size, - LPVOID Address, - DWORD Type, - PVOID Callback -); +DWORD ChildProcessId; +DWORD ChildThreadId; +DWORD_PTR DebuggerEP; +PWIN32ENTRY OEP; -BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register); -BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register); +int launch_debugger(void); + +// Set +BOOL SetBreakpoint(int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL SetThreadBreakpoint(DWORD ThreadId, int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL ContextSetThreadBreakpoint(PCONTEXT Context, int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL SetThreadBreakpoints(PTHREADBREAKPOINTS ThreadBreakpoints); +BOOL ContextSetBreakpoint(PTHREADBREAKPOINTS ThreadBreakpoints); BOOL ContextUpdateCurrentBreakpoint(PCONTEXT Context, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL SetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); -BOOL ContextSetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); -BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); -BOOL ClearBreakpointsInRange(DWORD ThreadId, PVOID BaseAddress, SIZE_T Size); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); -BOOL ClearSingleStepMode(PCONTEXT Context); -BOOL ContextClearAllBreakpoints(PCONTEXT Context); -BOOL ClearAllBreakpoints(DWORD ThreadId); -BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); +BOOL SetResumeFlag(PCONTEXT Context); +PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId); + +// Get +BOOL GetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register); +PTHREADBREAKPOINTS GetThreadBreakpoints(DWORD ThreadId); +BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register); +BOOL ContextSetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); int CheckDebugRegister(HANDLE hThread, int Register); +BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); int ContextCheckDebugRegister(CONTEXT Context, int Register); +HANDLE GetThreadHandle(DWORD ThreadId); + +// Clear +BOOL ClearBreakpoint(DWORD ThreadId, int Register); +BOOL ClearBreakpointsInRange(DWORD ThreadId, PVOID BaseAddress, SIZE_T Size); +BOOL ContextClearBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); +BOOL ContextClearCurrentBreakpoint(PCONTEXT Context); +BOOL ContextClearAllBreakpoints(PCONTEXT Context); +BOOL ClearAllBreakpoints(); +BOOL ClearSingleStepMode(PCONTEXT Context); + +// Misc +BOOL InitNewThreadBreakpoints(DWORD ThreadId); BOOL InitialiseDebugger(void); BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD CreationFlags); -BOOL SendDebuggerMessage(DWORD Input); -int launch_debugger(void); -BOOL IsInGuardPages(PVOID Address); -PGUARDPAGES GetGuardPages(PVOID Address); -BOOL DropGuardPages(PGUARDPAGES GuardPages); -PGUARDPAGES CreateGuardPagess(); -BOOL AddGuardPages(PVOID Address, SIZE_T RegionSize, ULONG Protect); -BOOL ReinstateGuardPages(PGUARDPAGES GuardPages); -BOOL DisableGuardPages(PGUARDPAGES GuardPages); +BOOL SendDebuggerMessage(PVOID Input); +BOOL StepOverExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); +BOOL ResumeAfterExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointInfo); + +void ShowStack(DWORD_PTR StackPointer, unsigned int NumberOfRecords); + +BOOL IsInTrackedRegions(PVOID Address); +PTRACKEDREGION CreateTrackedRegions(); +PTRACKEDREGION GetTrackedRegion(PVOID Address); +PTRACKEDREGION AddTrackedRegion(PVOID Address, SIZE_T RegionSize, ULONG Protect); +BOOL DropTrackedRegion(PTRACKEDREGION TrackedRegion); +BOOL ActivateGuardPages(PTRACKEDREGION TrackedRegion); +BOOL ActivateGuardPagesOnProtectedRange(PTRACKEDREGION TrackedRegion); +BOOL DeactivateGuardPages(PTRACKEDREGION TrackedRegion); +BOOL ActivateSurroundingGuardPages(PTRACKEDREGION TrackedRegion); #ifdef __cplusplus } diff --git a/CAPE/Output.c b/CAPE/Output.c index 80b7d10..915fcc7 100644 --- a/CAPE/Output.c +++ b/CAPE/Output.c @@ -133,7 +133,7 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) } CapeMetaData->ModulePath = (char*)malloc(MAX_PATH); - WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)g_config.file_of_interest, wcslen(g_config.file_of_interest)+1, CapeMetaData->ModulePath, MAX_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)g_config.file_of_interest, (int)wcslen(g_config.file_of_interest)+1, CapeMetaData->ModulePath, MAX_PATH, NULL, NULL); } else CapeMetaData->ModulePath = CapeMetaData->ProcessPath; @@ -141,7 +141,7 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) // This metadata format is specific to process dumps _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath); - if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) + if (FALSE == WriteFile(hMetadata, Buffer, (DWORD)strlen(Buffer), &dwBytesWritten, NULL)) { DoOutputDebugString("WriteFile error on CAPE metadata file %s\n"); CloseHandle(hMetadata); @@ -189,19 +189,24 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) if (CapeMetaData->DumpType == EXTRACTION_PE || CapeMetaData->DumpType == EXTRACTION_SHELLCODE) { // Extraction-specific format - _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n0x%x\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, (DWORD)CapeMetaData->Address); + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n0x%p\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->Address); } else if (CapeMetaData->DumpType == INJECTION_PE || CapeMetaData->DumpType == INJECTION_SHELLCODE || CapeMetaData->DumpType == EVILGRAB_PAYLOAD || CapeMetaData->DumpType == EVILGRAB_DATA) { if (CapeMetaData->TargetProcess && CapeMetaData->ProcessPath) // Injection-specific format _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n%s\n%d\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, CapeMetaData->TargetProcess, CapeMetaData->TargetPid); + } + else if (CapeMetaData->DumpType == SEDRECO_DATA) + { + // Sedreco-specific format where TargetPid is used for config item index # + _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n0x%x\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath, (DWORD)CapeMetaData->TargetPid); } else if (CapeMetaData->ProcessPath) _snprintf_s(Buffer, BufferSize, BufferSize, "%d\n%d\n%s\n%s\n", CapeMetaData->DumpType, CapeMetaData->Pid, CapeMetaData->ProcessPath, CapeMetaData->ModulePath); - if (FALSE == WriteFile(hMetadata, Buffer, strlen(Buffer), &dwBytesWritten, NULL)) + if (FALSE == WriteFile(hMetadata, Buffer, (DWORD)strlen(Buffer), &dwBytesWritten, NULL)) { DoOutputDebugString("WriteFile error on CAPE metadata file %s\n"); CloseHandle(hMetadata); diff --git a/config.c b/config.c index a2216fe..f4df68a 100644 --- a/config.c +++ b/config.c @@ -24,7 +24,7 @@ along with this program. If not, see . #include "hooking.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern void* CAPE_var; +extern DWORD_PTR CAPE_var1, CAPE_var2, CAPE_var3, CAPE_var4; int read_config(void) { @@ -50,7 +50,7 @@ int read_config(void) #else g_config.hook_type = HOOK_HOTPATCH_JMP_INDIRECT; #endif - g_config.procmemdump = 0; + g_config.procdump = 0; memset(buf, 0, sizeof(buf)); while (fgets(buf, sizeof(buf), fp) != NULL) @@ -218,13 +218,25 @@ int read_config(void) p = p2 + 1; } } - else if (!strcmp(key, "breakpoint")) { - CAPE_var = (void*)(DWORD_PTR)strtoul(value, NULL, 10); - DoOutputDebugString("CAPE_var set to 0x%x", CAPE_var); + else if (!strcmp(key, "CAPE_var1")) { + CAPE_var1 = (DWORD_PTR)strtoul(value, NULL, 10); + DoOutputDebugString("CAPE_var1 set to 0x%x", CAPE_var1); } - else if (!strcmp(key, "procmemdump")) { - g_config.procmemdump = value[0] == '1'; - if (g_config.procmemdump) + else if (!strcmp(key, "CAPE_var2")) { + CAPE_var2 = (DWORD_PTR)strtoul(value, NULL, 10); + DoOutputDebugString("CAPE_var2 set to 0x%x", CAPE_var2); + } + else if (!strcmp(key, "CAPE_var3")) { + CAPE_var3 = (DWORD_PTR)strtoul(value, NULL, 10); + DoOutputDebugString("CAPE_var3 set to 0x%x", CAPE_var3); + } + else if (!strcmp(key, "CAPE_var4")) { + CAPE_var4 = (DWORD_PTR)strtoul(value, NULL, 10); + DoOutputDebugString("CAPE_var4 set to 0x%x", CAPE_var4); + } + else if (!strcmp(key, "procdump")) { + g_config.procdump = value[0] == '1'; + if (g_config.procdump) DoOutputDebugString("Process memory dumps enabled.\n"); else DoOutputDebugString("Process memory dumps disabled.\n"); @@ -236,7 +248,7 @@ int read_config(void) else DoOutputDebugString("Import reconstruction of process dumps disabled.\n"); } - + else DoOutputDebugString("CAPE debug - unrecognised key %s.\n", key); } } diff --git a/config.h b/config.h index b92e851..2d67042 100644 --- a/config.h +++ b/config.h @@ -106,7 +106,7 @@ struct _g_config { wchar_t *excluded_dllnames[EXCLUSION_MAX]; // should we dump each process on exit/analysis timeout? - int procmemdump; + int procdump; // should we attempt import reconstruction on each process dump? (slow) int import_reconstruction; diff --git a/hook_process.c b/hook_process.c index bb2e1c7..cf2c796 100644 --- a/hook_process.c +++ b/hook_process.c @@ -33,8 +33,9 @@ along with this program. If not, see . extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern int DumpMemory(LPVOID Buffer, SIZE_T Size); -extern int DumpImageInCurrentProcess(DWORD_PTR ImageBase); -extern int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); +extern int DumpImageInCurrentProcess(PVOID ImageBase); +extern int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); +extern PVOID get_process_image_base(HANDLE process_handle); HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -379,7 +380,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); - CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, CurrentInjectionInfo->ImageBase); + CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped) { @@ -752,7 +753,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD_PTR)Buffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)Buffer); if (CurrentInjectionInfo->ImageDumped) { @@ -883,7 +884,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((DWORD_PTR)lpBuffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)lpBuffer); if (CurrentInjectionInfo->ImageDumped) { diff --git a/hook_special.c b/hook_special.c index e9c174e..c313a94 100644 --- a/hook_special.c +++ b/hook_special.c @@ -27,6 +27,7 @@ along with this program. If not, see . #include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern PVOID get_process_image_base(HANDLE process_handle); HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, __in_opt PWCHAR PathToFile, @@ -186,7 +187,7 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, } } - WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, (int)wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); } diff --git a/hook_thread.c b/hook_thread.c index 3a77caa..fada70b 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -29,8 +29,8 @@ along with this program. If not, see . extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern int DumpMemory(LPVOID Buffer, SIZE_T Size); -extern int DumpImageInCurrentProcess(DWORD_PTR ImageBase); -extern int ScanForPE(LPVOID Buffer, unsigned int Size, LPVOID* Offset); +extern int DumpImageInCurrentProcess(PVOID ImageBase); +extern int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); static lookup_t g_ignored_threads; @@ -353,7 +353,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, DoOutputDebugString("NtResumeThread hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); - CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, CurrentInjectionInfo->ImageBase); + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped) { diff --git a/misc.c b/misc.c index a20a5f0..a473a35 100644 --- a/misc.c +++ b/misc.c @@ -28,7 +28,6 @@ along with this program. If not, see . #include "config.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); static _NtQueryInformationProcess pNtQueryInformationProcess; static _NtQueryInformationThread pNtQueryInformationThread; @@ -140,6 +139,25 @@ int is_stack_pivoted(void) return 1; } +PCHAR memmem(PCHAR haystack, ULONG hlen, PCHAR needle, ULONG nlen) +{ + if (nlen > hlen) + return NULL; + + ULONG i; + for (i = 0; i < hlen - nlen + 1; i++) { + if (!memcmp(haystack + i, needle, nlen)) + return haystack + i; + } + + return NULL; +} + +BOOL is_bytes_in_buf(PCHAR buf, ULONG len, PCHAR memstr, ULONG memlen, ULONG maxsearchbytes) +{ + return memmem(buf, min(maxsearchbytes, len), memstr, memlen) ? TRUE : FALSE; +} + void replace_string_in_buf(PCHAR buf, ULONG len, PCHAR findstr, PCHAR repstr) { unsigned int findlen = (unsigned int)strlen(findstr); @@ -333,6 +351,12 @@ void perform_ascii_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength replace_string_in_buf(Data, DataLength, "Xeon(R) ", "Core(TM)"); } + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\SystemManufacturer") || + !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\SystemProductName")) { + replace_string_in_buf(Data, DataLength, "VMware", "Lenovo"); + replace_string_in_buf(Data, DataLength, "Virtual Platform", "X230 ThinkPad PC"); + } + // fake the manufacturer name if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\SystemInformation\\SystemManufacturer")) replace_string_in_buf(Data, DataLength, "QEMU", "DELL"); @@ -391,7 +415,13 @@ void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLeng if (!wcsnicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor", 63) && !wcsicmp(keypath + wcslen(keypath) - wcslen(L"ProcessorNameString"), L"ProcessorNameString")) { replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"QEMU Virtual CPU version 2.0.0", L"Intel(R) Core(TM) i7 CPU @3GHz"); - replace_wstring_in_buf(Data, DataLength, L"Xeon(R) ", L"Core(TM)"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"Xeon(R) ", L"Core(TM)"); + } + + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\SystemManufacturer") || + !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\SystemProductName")) { + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMware", L"Lenovo"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"Virtual Platform", L"X230 ThinkPad PC"); } // fake the manufacturer name @@ -613,7 +643,7 @@ void add_all_dlls_to_dll_ranges(void) for (mod = (LDR_MODULE *)mod->InLoadOrderModuleList.Flink; mod->BaseAddress != NULL; mod = (LDR_MODULE *)mod->InLoadOrderModuleList.Flink) { - if ((ULONG_PTR)mod->BaseAddress != base_of_dll_of_interest) + //if ((ULONG_PTR)mod->BaseAddress != base_of_dll_of_interest) add_dll_range((ULONG_PTR)mod->BaseAddress, (ULONG_PTR)mod->BaseAddress + mod->SizeOfImage); } @@ -831,13 +861,13 @@ char *ensure_absolute_ascii_path(char *out, const char *in) wchar_t *ensure_absolute_unicode_path(wchar_t *out, const wchar_t *in) { - wchar_t *tmpout; - wchar_t *nonexistent; + wchar_t *tmpout = NULL; + wchar_t *nonexistent = NULL; unsigned int lenchars; unsigned int nonexistentidx; - wchar_t *pathcomponent; + wchar_t *pathcomponent = NULL; unsigned int pathcomponentlen; - const wchar_t *inadj; + const wchar_t *inadj = NULL; unsigned int inlen; int is_globalroot = 0; @@ -1775,55 +1805,67 @@ void register_dll_notification_manually(PLDR_DLL_NOTIFICATION_FUNCTION notify) #endif } -unsigned int address_is_in_stack(DWORD Address) +unsigned int address_is_in_stack(PVOID Address) { -#ifdef _WIN64 - return 0; -#else - __try { - PNT_TIB pTib = (PNT_TIB)(NtCurrentTeb()); - - if ((Address < (DWORD)pTib->StackBase) && (Address > (DWORD)pTib->StackLimit)) - DoOutputDebugString("Address:0x%x within stack base = %p, limit = %p\r\n", Address, pTib->StackBase, pTib->StackLimit); - return 1; - - DoOutputDebugString("Address:0x%x not within stack base = %p, limit = %p\r\n", Address, pTib->StackBase, pTib->StackLimit); - return 0; - } - __except (EXCEPTION_EXECUTE_HANDLER) { - return 0; + __try { + PNT_TIB pTib = (PNT_TIB)(NtCurrentTeb()); + + if ((Address < pTib->StackBase) && (Address > pTib->StackLimit)) + DoOutputDebugString("Address 0x%p within stack base = 0x%p, limit = 0x%p\r\n", Address, pTib->StackBase, pTib->StackLimit); + return 1; + + DoOutputDebugString("Address 0x%x not within stack base = 0x%p, limit = 0x%p\r\n", Address, pTib->StackBase, pTib->StackLimit); + return 0; + } + __except (EXCEPTION_EXECUTE_HANDLER) { + return 0; } -#endif } PVOID get_process_image_base(HANDLE process_handle) { PROCESS_BASIC_INFORMATION pbi; ULONG ulSize; + HANDLE dup_handle = process_handle; + PVOID pPEB = 0, ImageBase = 0; PEB Peb; SIZE_T dwBytesRead; lasterror_t lasterror; - PVOID pPEB = 0, ImageBase = 0; get_lasterrors(&lasterror); + if (process_handle == GetCurrentProcess()) + { + ImageBase = GetModuleHandle(NULL); + goto out; + } + memset(&pbi, 0, sizeof(pbi)); - if (process_handle == GetCurrentProcess()) - ImageBase = GetModuleHandle(NULL); - else if (pNtQueryInformationProcess(process_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) + if (pNtQueryInformationProcess(process_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) { pPEB = pbi.PebBaseAddress; - if (!pPEB) - DoOutputDebugString("get_process_image_base: Failed to obtain address of PEB in target process.\n"); - else if (ReadProcessMemory(process_handle, pPEB, &Peb, sizeof(Peb), &dwBytesRead)) + if (ReadProcessMemory(process_handle, pPEB, &Peb, sizeof(Peb), &dwBytesRead)) + { ImageBase = Peb.ImageBaseAddress; - else - DoOutputErrorString("get_process_image_base: ReadProcessMemory failed to read from 0x%p", pPEB); + } + else return NULL; } - + +out: set_lasterrors(&lasterror); return ImageBase; } + +BOOLEAN is_address_in_ntdll(ULONG_PTR address) +{ + ULONG_PTR ntdll_base = (ULONG_PTR)GetModuleHandle("ntdll"); + DWORD ntdll_size = get_image_size(ntdll_base); + + if (address >= ntdll_base && address < (ntdll_base + ntdll_size)) + return TRUE; + + return FALSE; +} diff --git a/misc.h b/misc.h index 5d78999..ecdfffa 100644 --- a/misc.h +++ b/misc.h @@ -177,6 +177,8 @@ ULONG_PTR get_cdocument_write_addr(HMODULE mod); ULONG_PTR get_olescript_compile_addr(HMODULE mod); ULONG_PTR get_olescript_parsescripttext_addr(HMODULE mod); +PCHAR memmem(PCHAR haystack, ULONG hlen, PCHAR needle, ULONG nlen); +BOOL is_bytes_in_buf(PCHAR buf, ULONG len, PCHAR memstr, ULONG memlen, ULONG maxsearchbytes); void replace_string_in_buf(PCHAR buf, ULONG len, PCHAR findstr, PCHAR repstr); void replace_wstring_in_buf(PWCHAR buf, ULONG len, PWCHAR findstr, PWCHAR repstr); void replace_ci_string_in_buf(PCHAR buf, ULONG len, PCHAR findstr, PCHAR repstr); @@ -198,5 +200,3 @@ wchar_t *ascii_to_unicode_dup(char *str); int is_stack_pivoted(void); LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); - -PVOID get_process_image_base(HANDLE process_handle); \ No newline at end of file From 09f09b25de74441fd76fc8ac3016721bf504432f Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 3 Mar 2018 08:20:50 +0000 Subject: [PATCH 23/39] Update package to catch spawning of EQNEDT32 via DCOM. --- CAPE/CAPE.c | 131 +++++-- CAPE/CAPE.h | 3 +- CAPE/Scylla/IATSearch.cpp | 2 + CAPE/Scylla/PeParser.cpp | 167 ++++++-- CAPE/Scylla/PeParser.h | 2 + CAPE/Scylla/ProcessAccessHelp.cpp | 1 + CAPE/Scylla/multitree.h | 608 ------------------------------ CAPE/ScyllaHarness.cpp | 121 ++++-- cuckoomon.c | 18 +- cuckoomon.vcxproj | 1 - cuckoomon.vcxproj.filters | 3 - hook_file.c | 126 +++++-- hook_misc.c | 65 +++- hook_network.c | 37 +- hook_process.c | 52 +-- hook_reg.c | 325 ++++++++++++---- hook_sleep.c | 22 +- hook_socket.c | 24 +- hook_special.c | 6 +- hook_sync.c | 24 ++ hook_window.c | 62 ++- hooking.c | 8 +- hooking.h | 1 + hooks.h | 73 +++- ntapi.h | 23 +- 25 files changed, 984 insertions(+), 921 deletions(-) delete mode 100644 CAPE/Scylla/multitree.h diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index d794a44..c52a687 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -654,49 +654,46 @@ void DumpSectionViewsForPid(DWORD Pid) while (CurrentSectionView) { - if (CurrentSectionView->TargetProcessId == Pid) + if (CurrentSectionView->TargetProcessId == Pid && CurrentSectionView->LocalView) { - DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d.\n", Pid); + DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d, local address 0x%p.\n", Pid); - if (CurrentSectionView->LocalView) + PEPointer = CurrentSectionView->LocalView; + + while (ScanForPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) { - PEPointer = CurrentSectionView->LocalView; - - while (ScanForPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%x.\n", PEPointer); - - CapeMetaData->DumpType = INJECTION_PE; - CapeMetaData->TargetPid = Pid; - CapeMetaData->Address = PEPointer; + DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); + + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + CapeMetaData->Address = PEPointer; - if (DumpImageInCurrentProcess(PEPointer)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); - - ((BYTE*)PEPointer)++; + if (DumpImageInCurrentProcess(PEPointer)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); + Dumped = TRUE; } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); + + ((BYTE*)PEPointer)++; + } + + if (Dumped == FALSE) + { + DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); - if (Dumped == FALSE) + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = Pid; + + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) { - DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = Pid; - - if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); + DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); + Dumped = TRUE; } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); } } @@ -711,6 +708,70 @@ void DumpSectionViewsForPid(DWORD Pid) return; } +//************************************************************************************** +void DumpSectionViewForPid(PINJECTIONSECTIONVIEW SectionView, DWORD Pid) +//************************************************************************************** +{ + struct InjectionInfo *CurrentInjectionInfo; + DWORD BufferSize = MAX_PATH; + LPVOID PEPointer = NULL; + BOOL Dumped = FALSE; + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("DumpSectionViewForPid: No injection info for pid %d.\n", Pid); + return; + } + + if (SectionView->TargetProcessId == Pid && SectionView->LocalView) + { + PEPointer = SectionView->LocalView; + + while (ScanForPE(PEPointer, SectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)SectionView->LocalView), &PEPointer)) + { + DoOutputDebugString("DumpSectionViewForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); + + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + CapeMetaData->Address = PEPointer; + + if (DumpImageInCurrentProcess(PEPointer)) + { + DoOutputDebugString("DumpSectionViewForPid: Dumped PE image from shared section view.\n"); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewForPid: Failed to dump PE image from shared section view.\n"); + + ((BYTE*)PEPointer)++; + } + + if (Dumped == FALSE) + { + DoOutputDebugString("DumpSectionViewForPid: no PE file found in shared section view, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = Pid; + + if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) + { + DoOutputDebugString("DumpSectionViewForPid: Dumped shared section view."); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewForPid: Failed to dump shared section view."); + } + + if (Dumped == TRUE) + DropSectionView(SectionView); + } + + return; +} + //************************************************************************************** char* GetName() //************************************************************************************** diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 82e10e3..70d449d 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -39,7 +39,6 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); int DumpImageInCurrentProcess(LPVOID ImageBase); -void DumpSectionViewsForPid(DWORD Pid); SYSTEM_INFO SystemInfo; PVOID CallingModule; @@ -56,6 +55,8 @@ typedef struct InjectionSectionView PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); +void DumpSectionViewsForPid(DWORD Pid); +void DumpSectionViewForPid(PINJECTIONSECTIONVIEW SectionView, DWORD Pid); typedef struct InjectionInfo { diff --git a/CAPE/Scylla/IATSearch.cpp b/CAPE/Scylla/IATSearch.cpp index f035fa7..4404f3f 100644 --- a/CAPE/Scylla/IATSearch.cpp +++ b/CAPE/Scylla/IATSearch.cpp @@ -51,6 +51,7 @@ bool IATSearch::findIATAdvanced( DWORD_PTR startAddress, DWORD_PTR* addressIAT, #ifdef DEBUG_COMMENTS DoOutputDebugString("findAPIAddressInIAT2 :: error reading memory"); #endif + delete [] dataBuffer; return false; } @@ -277,6 +278,7 @@ bool IATSearch::findIATStartAndSize(DWORD_PTR address, DWORD_PTR * addressIAT, D #ifdef DEBUG_COMMENTS DoOutputDebugString("findIATStartAddress :: error reading memory"); #endif + delete [] dataBuffer; return false; } diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 6caa891..1a1e6d0 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -97,6 +97,7 @@ void PeParser::initClass() filename = 0; fileSize = 0; + dumpSize = 0; moduleBaseAddress = 0; hFile = INVALID_HANDLE_VALUE; } @@ -298,28 +299,74 @@ bool PeParser::readPeSectionsFromProcess() { bool retValue = true; DWORD_PTR readOffset = 0; + DWORD fileAlignment = 0, sectionAlignment = 0; + unsigned int NumberOfSections = getNumberOfSections(); + + if (isPE32()) + { + fileAlignment = pNTHeader32->OptionalHeader.FileAlignment; + sectionAlignment = pNTHeader32->OptionalHeader.SectionAlignment; + } + else + { + fileAlignment = pNTHeader64->OptionalHeader.FileAlignment; + sectionAlignment = pNTHeader64->OptionalHeader.SectionAlignment; + } - listPeSection.reserve(getNumberOfSections()); - - for (WORD i = 0; i < getNumberOfSections(); i++) + listPeSection.reserve(NumberOfSections); + + for (WORD i = 0; i < NumberOfSections; i++) { readOffset = listPeSection[i].sectionHeader.VirtualAddress + moduleBaseAddress; - listPeSection[i].normalSize = listPeSection[i].sectionHeader.Misc.VirtualSize; + if (i < NumberOfSections - 1) + { + if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > (listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress)) + { + listPeSection[i].normalSize = alignValue(listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for section %d from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].normalSize); +#endif + } + else + { + listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for section %d ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + } + else + { + if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)) + { + listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].normalSize); +#endif + } + else + { + listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + } + if (!readSectionFromProcess(readOffset, listPeSection[i])) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess failed offset 0x%x, section %d (VA 0x%p, size 0x%x)\n", readOffset, i+1, listPeSection[i].sectionHeader.VirtualAddress, listPeSection[i].normalSize); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess failed offset 0x%x, section %d\n", readOffset, i+1); #endif retValue = false; - goto out; // To continue upon failure may lead to crashes } } #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: readSectionFromProcess success.\n"); #endif -out: + return retValue; } @@ -566,6 +613,9 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil if (!readOffset || !readSize) { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: readSectionFrom: readOffset or readSize zero: 0x%x, 0x%x\n", readOffset, readSize); +#endif return true; //section without data is valid } @@ -574,6 +624,10 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil peFileSection.dataSize = readSize; peFileSection.normalSize = readSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: readSectionFrom: readSize <= maxReadSize: 0x%x.\n", readSize); +#endif + if (isProcess) { return readPeSectionFromProcess(readOffset, peFileSection); @@ -592,11 +646,14 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil } currentOffset = readOffset + readSize - currentReadSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: About to attempt to read section from 0x%x size 0x%x.\n", readOffset, readSize); +#endif while(currentOffset >= readOffset) //start from the end { ZeroMemory(data, currentReadSize); - + if (isProcess) { retValue = ProcessAccessHelp::readMemoryPartlyFromProcess(currentOffset, currentReadSize, data); @@ -608,6 +665,9 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil if (!retValue) { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: readMemory failure reading 0x%x bytes from 0x%x.\n", currentOffset , currentReadSize); +#endif break; } @@ -616,6 +676,9 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil { //found some real code +#ifdef DEBUG_COMMENTS + //DoOutputDebugString("PeParser:: readMemory found data at 0x%x.\n", currentOffset); +#endif currentOffset += valuesFound; if (readOffset < currentOffset) @@ -635,15 +698,25 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil break; } +#ifdef DEBUG_COMMENTS + //else + // DoOutputDebugString("PeParser:: readMemory found nothing at 0x%x.\n", currentOffset); +#endif currentReadSize = maxReadSize; currentOffset -= currentReadSize; } +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: calls to readSectionFrom succeeded.\n"); +#endif if (peFileSection.dataSize) { - if (isProcess) +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser:: readSectionFrom: About to read PE section from 0x%x.\n", readOffset); +#endif + if (isProcess) { retValue = readPeSectionFromProcess(readOffset, peFileSection); } @@ -656,7 +729,6 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil return retValue; } - DWORD PeParser::isMemoryNotNull( BYTE * data, int dataSize ) { for (int i = (dataSize - 1); i >= 0; i--) @@ -797,6 +869,7 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) } SetEndOfFile(hFile); + dumpSize = dwFileOffset; if (newFile) closeFileHandle(); @@ -905,6 +978,7 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) } SetEndOfFile(hFile); + dumpSize = dwWriteSize; if (newFile) closeFileHandle(); @@ -1228,6 +1302,7 @@ bool PeFileSectionSortByVirtualAddress(const PeFileSection& d1, const PeFileSect void PeParser::alignAllSectionHeaders() { + unsigned int NumberOfSections; DWORD sectionAlignment = 0; DWORD fileAlignment = 0; DWORD newFileSize = 0; @@ -1243,20 +1318,58 @@ void PeParser::alignAllSectionHeaders() fileAlignment = pNTHeader64->OptionalHeader.FileAlignment; } + NumberOfSections = getNumberOfSections(); + std::sort(listPeSection.begin(), listPeSection.end(), PeFileSectionSortByPointerToRawData); //sort by PointerToRawData ascending - newFileSize = pDosHeader->e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + pNTHeader32->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)); - + newFileSize = pDosHeader->e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + pNTHeader32->FileHeader.SizeOfOptionalHeader + (NumberOfSections * sizeof(IMAGE_SECTION_HEADER)); - for (WORD i = 0; i < getNumberOfSections(); i++) - { + for (WORD i = 0; i < NumberOfSections; i++) + { listPeSection[i].sectionHeader.VirtualAddress = alignValue(listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); - listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); listPeSection[i].sectionHeader.PointerToRawData = alignValue(newFileSize, fileAlignment); listPeSection[i].sectionHeader.SizeOfRawData = alignValue(listPeSection[i].dataSize, fileAlignment); - - newFileSize = listPeSection[i].sectionHeader.PointerToRawData + listPeSection[i].sectionHeader.SizeOfRawData; + + newFileSize = listPeSection[i].sectionHeader.PointerToRawData + listPeSection[i].sectionHeader.SizeOfRawData; + } + + for (WORD i = 0; i < NumberOfSections; i++) + { + if (i < NumberOfSections - 1) + { + if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > (listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress)) + { + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for section %d from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + else + { + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: VirtualSize for section %d ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + } + else + { + if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)) + { + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + else + { + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); +#endif + } + } } std::sort(listPeSection.begin(), listPeSection.end(), PeFileSectionSortByVirtualAddress); //sort by VirtualAddress ascending @@ -1266,23 +1379,31 @@ bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * { moduleBaseAddress = modBase; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("dumpProcess DEBUG: entry: modBase = 0x%x.\n", modBase); +#endif + if (readPeSectionsFromProcess()) { - setDefaultFileAlignment(); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("dumpProcess DEBUG: readPeSectionsFromProcess success.\n"); +#endif + + setDefaultFileAlignment(); - setEntryPointVa(entryPoint); + if (entryPoint) + setEntryPointVa(entryPoint); alignAllSectionHeaders(); fixPeHeader(); getFileOverlay(); +#ifdef DEBUG_COMMENTS + DoOutputDebugString("dumpProcess DEBUG: Fixups complete, about to save to disk.\n"); +#endif return savePeFileToDisk(dumpFilePath); } -#ifdef DEBUG_COMMENTS - else - DoOutputDebugString("PeParser::dumpProcess: readPeSectionsFromProcess failed.\n"); -#endif return false; } diff --git a/CAPE/Scylla/PeParser.h b/CAPE/Scylla/PeParser.h index 0be9a92..672d1f7 100644 --- a/CAPE/Scylla/PeParser.h +++ b/CAPE/Scylla/PeParser.h @@ -92,6 +92,8 @@ class PeParser PIMAGE_NT_HEADERS getCurrentNtHeader(); std::vector listPeSection; + + DWORD dumpSize; protected: PeParser(); diff --git a/CAPE/Scylla/ProcessAccessHelp.cpp b/CAPE/Scylla/ProcessAccessHelp.cpp index 9efa57f..10eebb5 100644 --- a/CAPE/Scylla/ProcessAccessHelp.cpp +++ b/CAPE/Scylla/ProcessAccessHelp.cpp @@ -609,6 +609,7 @@ LPVOID ProcessAccessHelp::createFileMappingView(const CHAR * filePath, DWORD acc #ifdef DEBUG_COMMENTS DoOutputDebugString("createFileMappingView :: GetLastError() == ERROR_ALREADY_EXISTS"); #endif + CloseHandle(hMappedFile); return NULL; } diff --git a/CAPE/Scylla/multitree.h b/CAPE/Scylla/multitree.h deleted file mode 100644 index 4b793a0..0000000 --- a/CAPE/Scylla/multitree.h +++ /dev/null @@ -1,608 +0,0 @@ -#pragma once - -///////////////////////////////////////////////////////////////////////////// -// MultiSelectTree - A tree control with multi-select capabilities -// -// Written by Bjarke Viksoe (bjarke@viksoe.dk) -// Copyright (c) 2005 Bjarke Viksoe. -// -// Add the following macro to the parent's message map: -// REFLECT_NOTIFICATIONS() -// -// This code may be used in compiled form in any way you desire. This -// source file may be redistributed by any means PROVIDING it is -// not sold for profit without the authors written consent, and -// providing that this notice and the authors name is included. -// -// This file is provided "as is" with no expressed or implied warranty. -// The author accepts no liability if it causes any damage to you or your -// computer whatsoever. It's free, so don't hassle me about it. -// -// Beware of bugs. -// - -#ifndef __cplusplus - #error WTL requires C++ compilation (use a .cpp suffix) -#endif - -#ifndef __ATLMISC_H__ - #error multitree.h requires atlmisc.h to be included first -#endif - -#ifndef __ATLCRACK_H__ - #error multitree.h requires atlcrack.h to be included first -#endif - -#ifndef __ATLCTRLS_H__ - #error multitree.h requires atlctrls.h to be included first -#endif - -// Extended MultiSelectTree styles -static const DWORD MTVS_EX_NOMARQUEE = 0x00000001; - -// New control notifications -static const UINT TVN_ITEMSELECTING = 0x0001; -static const UINT TVN_ITEMSELECTED = 0x0002; - -static bool operator==(const CTreeItem& ti1, const CTreeItem& ti2) -{ - return ti1.m_hTreeItem == ti2.m_hTreeItem; -} - -template< class T, class TBase = CTreeViewCtrlEx, class TWinTraits = CControlWinTraits > -class ATL_NO_VTABLE CMultiSelectTreeViewImpl : - public CWindowImpl< T, TBase, TWinTraits >, - public CCustomDraw< T > -{ -public: - DECLARE_WND_SUPERCLASS(NULL, TBase::GetWndClassName()) - - DWORD m_dwExStyle; // Additional styles - CTreeItem m_hExtSelStart; // Item where SHIFT was last pressed - bool m_bMarquee; // Are we drawing rubberband? - CPoint m_ptDragStart; // Point where rubberband started - CPoint m_ptDragOld; // Last mousepos of rubberband - - CSimpleMap m_aData; - - CMultiSelectTreeViewImpl() : m_dwExStyle(0), m_bMarquee(false) - { - } - - CTreeItem _MakeItem(HTREEITEM hItem) const - { - return CTreeItem(hItem, (CTreeViewCtrlEx*)this); - } - - // Operations - - BOOL SubclassWindow(HWND hWnd) - { - ATLASSERT(m_hWnd == NULL); - ATLASSERT(::IsWindow(hWnd)); - - BOOL bRet = CWindowImpl< T, TBase, TWinTraits >::SubclassWindow(hWnd); - if( bRet ) - _Init(); - return bRet; - } - - DWORD SetExtendedTreeStyle(DWORD dwStyle) - { - ATLASSERT(!m_ctrlTree.IsWindow()); // Before control is created, please! - - DWORD dwOldStyle = m_dwTreeStyle; - m_dwTreeStyle = dwStyle; - return dwOldStyle; - } - - BOOL SelectItem(HTREEITEM hItem, BOOL bSelect) - { - ATLASSERT(::IsWindow(m_hWnd)); - - _SelectItem(hItem, bSelect == TRUE); - if( bSelect ) - TBase::SelectItem(hItem); - return TRUE; - } - - BOOL SelectAllItems(BOOL bSelect) - { - ATLASSERT(::IsWindow(m_hWnd)); - - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - _SelectItem(i, bSelect == TRUE); - } - return TRUE; - } - - BOOL IsItemSelected(HTREEITEM hItem) - { - ATLASSERT(::IsWindow(m_hWnd)); - - int iIndex = m_aData.FindKey(hItem); - if( iIndex >= 0 ) - { - return m_aData.GetValueAt(iIndex) ? TRUE : FALSE; - } - return FALSE; - } - - CTreeItem GetSelectedItem() const - { - ATLASSERT(false); // Not usable! - return GetFirstSelectedItem(); - } - - CTreeItem GetFocusItem() const - { - return TBase::GetSelectedItem(); - } - - UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const - { - UINT nRes = TBase::GetItemState(hItem, nStateMask); - if( (nStateMask & TVIS_SELECTED) != 0 ) - { - int iIndex = m_aData.FindKey(hItem); - if( iIndex >= 0 ) - { - nRes &= ~TVIS_SELECTED; - if( m_aData.GetValueAt(iIndex) ) - nRes |= TVIS_SELECTED; - } - } - return nRes; - } - - CTreeItem GetFirstSelectedItem() const - { - HTREEITEM item = NULL; - if( m_aData.GetSize() > 0 ) - { - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - if( m_aData.GetValueAt(i) ) - { - item = m_aData.GetKeyAt(i); - break; - } - } - } - return _MakeItem(item); - } - - CTreeItem GetNextSelectedItem(HTREEITEM hItem) const - { - HTREEITEM item = NULL; - int iIndex = m_aData.FindKey(hItem); - if( iIndex >= 0 ) - { - for( int i = iIndex + 1; i < m_aData.GetSize(); i++ ) - { - if( m_aData.GetValueAt(i) ) - { - item = m_aData.GetKeyAt(i); - break; - } - } - } - return _MakeItem(item); - } - - int GetSelectedCount() const - { - int nCount = 0; - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - if( m_aData.GetValueAt(i) ) - nCount++; - } - return nCount; - } - - // Implementation - - void _Init() - { - ATLASSERT(::IsWindow(m_hWnd)); - - ModifyStyle(TVS_SHOWSELALWAYS, 0); - } - - void _SelectItem(int iIndex, bool bSelect, int action = TVC_UNKNOWN) - { - if( iIndex < 0 ) - return; - bool bSelected = m_aData.GetValueAt(iIndex); - // Don't change if state is already updated (avoids flicker) - if( bSelected == bSelect ) - return; - HTREEITEM hItem = m_aData.GetKeyAt(iIndex); - CWindow parent = GetParent(); - // Send notifications - NMTREEVIEW nmtv = { 0 }; - nmtv.hdr.code = TVN_ITEMSELECTING; - nmtv.hdr.hwndFrom = m_hWnd; - nmtv.hdr.idFrom = GetDlgCtrlID(); - nmtv.action = action; - nmtv.itemNew.hItem = hItem; - nmtv.itemNew.lParam = GetItemData(hItem); - nmtv.itemNew.state = bSelect ? TVIS_SELECTED : 0; - nmtv.itemNew.stateMask = TVIS_SELECTED; - if( parent.SendMessage(WM_NOTIFY, nmtv.hdr.idFrom, (LPARAM) &nmtv) != 0 ) - return; - // Change state - m_aData.SetAtIndex(iIndex, hItem, bSelect); - // Repaint item - CRect rcItem; - if( GetItemRect(hItem, &rcItem, FALSE) ) - InvalidateRect(&rcItem, TRUE); - // More notifications - nmtv.hdr.code = TVN_ITEMSELECTED; - parent.SendMessage(WM_NOTIFY, nmtv.hdr.idFrom, (LPARAM) &nmtv); - } - - void _SelectItem(HTREEITEM hItem, bool bSelect, int action = TVC_UNKNOWN) - { - _SelectItem(m_aData.FindKey(hItem), bSelect, action); - } - - void _SelectTree(HTREEITEM hItem, HTREEITEM hGoal, int action) - { - if( !_SelectTreeSub(hItem, hGoal, action) ) - return; - hItem = GetParentItem(hItem); - while( (hItem = GetNextSiblingItem(hItem)) != NULL ) - { - if( !_SelectTreeSub(hItem, hGoal, action) ) - return; - } - } - - bool _SelectTreeSub(HTREEITEM hItem, HTREEITEM hGoal, int action) - { - while( hItem != NULL ) - { - _SelectItem(hItem, true, action); - if( hItem == hGoal ) - return false; - if( (TBase::GetItemState(hItem, TVIS_EXPANDED) & TVIS_EXPANDED) != 0 ) - { - if( !_SelectTreeSub(GetChildItem(hItem), hGoal, action) ) - return false; - } - hItem = GetNextSiblingItem(hItem); - } - return true; - } - - /* - TODO: keep list of 'temporary' selected items - if you select an item with the mouse and it gets - out of the selection rectangle it stays selected. - it should unselect it but keep old selected items - (when holding CTRL) - */ - void _SelectBox(CRect rc) - { - HTREEITEM hItem = GetFirstVisibleItem(); - while( hItem != NULL ) - { - int i = m_aData.FindKey(hItem); - if(i >= 0 && !m_aData.GetValueAt(i)) // ignore already selected - { - CRect rcItem, rcTemp; - GetItemRect(hItem, &rcItem, TRUE); - _SelectItem(hItem, rcTemp.IntersectRect(&rcItem, &rc) == TRUE, TVC_BYMOUSE); - } - hItem = GetNextVisibleItem(hItem); - } - } - - void _DrawDragRect(CPoint pt) - { - CClientDC dc(m_hWnd); - CSize szFrame(1, 1); - CRect rect(m_ptDragStart, pt); - rect.NormalizeRect(); - //CRect rectOld(m_ptDragStart, m_ptDragOld); - //rectOld.NormalizeRect(); - dc.DrawDragRect(&rect, szFrame, NULL/*&rectOld*/, szFrame); - } - - // Message map and handlers - - BEGIN_MSG_MAP_EX(CMultiSelectTreeViewImpl) - MESSAGE_HANDLER_EX(WM_CREATE, OnCreate) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_KEYDOWN(OnKeyDown) - MSG_WM_KEYUP(OnKeyUp) - MSG_WM_CHAR(OnChar) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_LBUTTONDOWN(OnLButtonDown) - MSG_WM_LBUTTONUP(OnLButtonUp) - MSG_WM_MOUSEMOVE(OnMouseMove) - MSG_WM_CAPTURECHANGED(OnCaptureChanged) - MESSAGE_HANDLER_EX(TVM_INSERTITEM, OnInsertItem) - REFLECTED_NOTIFY_CODE_HANDLER_EX(TVN_DELETEITEM, OnDeleteItem) - CHAIN_MSG_MAP_ALT( CCustomDraw< T >, 1 ) - END_MSG_MAP() - - LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam) - { - LRESULT lRes = DefWindowProc(); - _Init(); - return lRes; - } - - void OnDestroy() - { - m_aData.RemoveAll(); - SetMsgHandled(FALSE); - } - - void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) - { - if( nChar == VK_SHIFT ) - m_hExtSelStart = GetFocusItem(); - - if( ::GetKeyState(VK_SHIFT) < 0 && m_hExtSelStart == GetFocusItem() ) - { - switch( nChar ) - { - case VK_UP: - case VK_DOWN: - case VK_HOME: - case VK_END: - case VK_NEXT: - case VK_PRIOR: - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - _SelectItem(i, false, TVC_BYKEYBOARD); - } - } - } - SetMsgHandled(FALSE); - } - - void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) - { - if( ::GetKeyState(VK_SHIFT) < 0 ) - { - switch( nChar ) - { - case VK_UP: - case VK_DOWN: - case VK_HOME: - case VK_END: - case VK_NEXT: - case VK_PRIOR: - HTREEITEM hItem = GetFocusItem(); - // Is current or first-shift-item the upper item? - CRect rcItem1, rcItem2; - GetItemRect(m_hExtSelStart, &rcItem1, TRUE); - GetItemRect(hItem, &rcItem2, TRUE); - // Select from current item to item where SHIFT was pressed - if( rcItem1.top > rcItem2.top ) - _SelectTree(hItem, m_hExtSelStart, TVC_BYKEYBOARD); - else - _SelectTree(m_hExtSelStart, hItem, TVC_BYKEYBOARD); - _SelectItem(hItem, true, TVC_BYKEYBOARD); - } - } - SetMsgHandled(FALSE); - } - - void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) - { - if( nChar == VK_SPACE ) - { - HTREEITEM hItem = GetFocusItem(); - _SelectItem(hItem, IsItemSelected(hItem) == TRUE/*GetItemState(hItem, TVIS_SELECTED) & TVIS_SELECTED) == 0*/, TVC_BYKEYBOARD); - return; - } - SetMsgHandled(FALSE); - } - - void OnSetFocus(CWindow wndOld) - { - DefWindowProc(); - // FIX: We really need the focus-rectangle in this control since it - // improves the navigation a lot. So let's ask Windows to display it. - SendMessage(WM_UPDATEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS)); - } - - void OnLButtonDown(UINT nFlags, CPoint point) - { - SetMsgHandled(FALSE); - - // Hit-test and figure out where we're clicking... - TVHITTESTINFO hti = { 0 }; - hti.pt = point; - HTREEITEM hItem = HitTest(&hti); - if( (hItem == NULL || (hti.flags & TVHT_ONITEMRIGHT) != 0) ) - { - if( (m_dwExStyle & MTVS_EX_NOMARQUEE) == 0 && ::DragDetect(m_hWnd, point) ) - { - // Great we're dragging a rubber-band - // Clear selection if CTRL is not down - if( ::GetKeyState(VK_CONTROL) >= 0 ) - { - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - _SelectItem(i, false, TVC_BYMOUSE); - } - UpdateWindow(); - } - // Now start drawing the rubber-band... - SetCapture(); - m_ptDragStart = m_ptDragOld = point; - _DrawDragRect(point); - m_bMarquee = true; - SetMsgHandled(FALSE); //SetMsgHandled(TRUE); - return; - } - } - - if( hItem == NULL ) - return; - - if( (hti.flags & TVHT_ONITEMBUTTON) != 0 ) - return; - - // Great, let's do an advanced selection - if( (hti.flags & TVHT_ONITEMRIGHT) != 0 ) - { - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - _SelectItem(i, false, TVC_BYMOUSE); - } - return; - } - int iIndex = m_aData.FindKey(hItem); - if( iIndex < 0 ) - return; - // Simulate drag'n'drop? - if( m_aData.GetValueAt(iIndex) && (GetStyle() & TVS_DISABLEDRAGDROP) == 0 && ::DragDetect(m_hWnd, point) ) - { - NMTREEVIEW nmtv = { 0 }; - nmtv.hdr.code = TVN_BEGINDRAG; - nmtv.hdr.hwndFrom = m_hWnd; - nmtv.hdr.idFrom = GetDlgCtrlID(); - nmtv.itemNew.hItem = hItem; - nmtv.itemNew.lParam = GetItemData(hItem); - CWindow parent = GetParent(); - parent.SendMessage(WM_NOTIFY, nmtv.hdr.idFrom, (LPARAM) &nmtv); - } - bool bSelected = m_aData.GetValueAt(iIndex); - if( ::GetKeyState(VK_SHIFT) < 0 ) - { - // Is current or first-shift-item the upper item? - CRect rcItem1, rcItem2; - GetItemRect(m_hExtSelStart, &rcItem1, TRUE); - GetItemRect(hItem, &rcItem2, TRUE); - // Select from current item to item where SHIFT was pressed - if( rcItem1.top > rcItem2.top ) - _SelectTree(hItem, m_hExtSelStart, TVC_BYMOUSE); - else - _SelectTree(m_hExtSelStart, hItem, TVC_BYMOUSE); - } - else if( ::GetKeyState(VK_CONTROL) < 0 ) - { - // Just toggle item - _SelectItem(iIndex, !bSelected, TVC_BYMOUSE); - } - else - { - // Remove current selection and replace it with clicked item - for( int i = 0; i < m_aData.GetSize(); i++ ) - { - _SelectItem(i, i == iIndex, TVC_BYMOUSE); - } - } - } - - void OnLButtonUp(UINT nFlags, CPoint point) - { - if( m_bMarquee ) - ReleaseCapture(); - SetMsgHandled(FALSE); - } - - void OnMouseMove(UINT nFlags, CPoint point) - { - if( m_bMarquee ) - { - CRect rc(m_ptDragStart, point); - _DrawDragRect(m_ptDragOld); - rc.NormalizeRect(); - _SelectBox(rc); - UpdateWindow(); - _DrawDragRect(point); - m_ptDragOld = point; - } - SetMsgHandled(FALSE); - } - - void OnCaptureChanged(CWindow wnd) - { - if( m_bMarquee ) - { - _DrawDragRect(m_ptDragOld); - m_bMarquee = false; - } - SetMsgHandled(FALSE); - } - - LRESULT OnInsertItem(UINT uMsg, WPARAM wParam, LPARAM lParam) - { - HTREEITEM hItem = (HTREEITEM) DefWindowProc(uMsg, wParam, lParam); - if( hItem == NULL ) - return (LRESULT) hItem; - // We manage a bit of extra information for each item. We'll store - // this in an ATL::CSimpleMap. Not a particular speedy structure for lookups. - // Don't keep too many items around in the tree! - m_aData.Add(hItem, false); - return (LRESULT) hItem; - } - - LRESULT OnDeleteItem(NMHDR* pnmh) - { - const NMTREEVIEW* lpNMTV = (NMTREEVIEW*) pnmh; - m_aData.Remove(lpNMTV->itemNew.hItem); - return 0; - } - - // Custom Draw - - DWORD OnPrePaint(int /*idCtrl*/, NMCUSTOMDRAW* /*lpNMCustomDraw*/) - { - return CDRF_NOTIFYITEMDRAW; // We need per-item notifications - } - - DWORD OnItemPrePaint(int /*idCtrl*/, NMCUSTOMDRAW* lpNMCustomDraw) - { - NMTVCUSTOMDRAW* lpTVCD = (NMTVCUSTOMDRAW*) lpNMCustomDraw; - HTREEITEM hItem = (HTREEITEM) lpTVCD->nmcd.dwItemSpec; - int iIndex = m_aData.FindKey(hItem); - if( iIndex >= 0 ) - { - bool bSelected = m_aData.GetValueAt(iIndex); - // Trick TreeView into displaying correct selection colors - if( bSelected ) - { - lpTVCD->clrText = ::GetSysColor(COLOR_HIGHLIGHTTEXT); - lpTVCD->clrTextBk = ::GetSysColor(COLOR_HIGHLIGHT); - } - else - { - // Special case of tree-item actually have selection, but our - // state says it is currently not selected (CTRL+click on same item twice). - if( (lpTVCD->nmcd.uItemState & CDIS_SELECTED) != 0 ) - { - COLORREF clrText = GetTextColor(); - if( clrText == CLR_NONE ) - clrText = ::GetSysColor(COLOR_WINDOWTEXT); - COLORREF clrBack = GetBkColor(); - if( clrBack == CLR_NONE ) - clrBack = ::GetSysColor(COLOR_WINDOW); - //CDCHandle dc = lpTVCD->nmcd.hdc; - //dc.SetTextColor(clrText); - //dc.SetBkColor(clrBack); - lpTVCD->clrText = clrText; - lpTVCD->clrTextBk = clrBack; - } - } - return CDRF_NEWFONT; - } - return CDRF_DODEFAULT; - } -}; - -class CMultiSelectTreeViewCtrl : public CMultiSelectTreeViewImpl > -{ -public: - DECLARE_WND_SUPERCLASS(_T("WTL_MultiSelectTree"), GetWndClassName()) -}; diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 135827d..ee475f8 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -54,17 +54,49 @@ void ScyllaInitCurrentProcess() } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) +extern "C" DWORD_PTR GetEntryPointVA(DWORD_PTR modBase) +//************************************************************************************** +{ + PeParser * peFile = 0; + + ScyllaInitCurrentProcess(); + + peFile = new PeParser((DWORD_PTR)modBase, true); + + return peFile->getEntryPoint() + (DWORD_PTR)modBase; +} + +//************************************************************************************** +extern "C" DWORD_PTR FileOffsetToVA(DWORD_PTR modBase, DWORD_PTR dwOffset) +//************************************************************************************** +{ + DWORD_PTR Test; + PeParser * peFile = 0; + + ScyllaInitCurrentProcess(); + + peFile = new PeParser(modBase, true); + + //return peFile->convertOffsetToRVAVector(dwOffset) + modBase; + Test = peFile->convertOffsetToRVAVector(dwOffset) + modBase; + + DoOutputDebugString("FileOffsetToVA: Debug - VA = 0x%p.\n", Test); + + return Test; +} + +//************************************************************************************** +extern "C" int ScyllaDumpCurrentProcess(DWORD_PTR NewOEP) //************************************************************************************** { DWORD_PTR entrypoint = 0; PeParser * peFile = 0; - DWORD ModuleBase; + DWORD_PTR ModuleBase; ModuleBase = (DWORD)(ULONG_PTR)GetModuleHandle(NULL); ScyllaInitCurrentProcess(); - DoOutputDebugString("DumpCurrentProcess: Instantiating PeParser with address: 0x%x", ModuleBase); + DoOutputDebugString("DumpCurrentProcess: Instantiating PeParser with address: 0x%p.\n", ModuleBase); peFile = new PeParser(ModuleBase, TRUE); @@ -75,7 +107,7 @@ extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) else entrypoint = peFile->getEntryPoint() + ModuleBase; - DoOutputDebugString("DumpCurrentProcess: Module entry point VA is 0x%x", entrypoint); + DoOutputDebugString("DumpCurrentProcess: Module entry point VA is 0x%p.\n", entrypoint); if (peFile->dumpProcess(ModuleBase, entrypoint, NULL)) { @@ -90,7 +122,7 @@ extern "C" int ScyllaDumpCurrentProcess(DWORD NewOEP) } else { - DoOutputDebugString("DumpCurrentProcess: Invalid PE file or invalid PE header."); + DoOutputDebugString("DumpCurrentProcess: Invalid PE file or invalid PE header.\n"); delete peFile; return 0; } @@ -114,32 +146,41 @@ void ScyllaInit(HANDLE hProcess) } //************************************************************************************** -extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD NewOEP) +extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PTR NewOEP) //************************************************************************************** { - DWORD_PTR entrypoint = 0; + unsigned int entrypoint = 0, SectionBasedFileSize; PeParser * peFile = 0; ScyllaInit(hProcess); - DoOutputDebugString("DumpProcess: Instantiating PeParser with address: 0x%x", ModuleBase); + DoOutputDebugString("DumpProcess: Instantiating PeParser with address: 0x%p.\n", ModuleBase); peFile = new PeParser(ModuleBase, TRUE); if (peFile->isValidPeFile()) { if (NewOEP) - entrypoint = NewOEP; + entrypoint = (unsigned int)NewOEP; else - entrypoint = peFile->getEntryPoint(); + entrypoint = (unsigned int)peFile->getEntryPoint(); - entrypoint = entrypoint + ModuleBase; - - DoOutputDebugString("DumpProcess: Module entry point VA is 0x%x", entrypoint); + SectionBasedFileSize = (unsigned int)peFile->getSectionHeaderBasedFileSize(); + + if (entrypoint > SectionBasedFileSize) + { + DoOutputDebugString("DumpProcess: Error - entry point too big: 0x%x, ignoring.\n", entrypoint); + entrypoint = 0; + } + else + { + DoOutputDebugString("DumpProcess: Module entry point VA is 0x%p.\n", entrypoint); + entrypoint = entrypoint + ModuleBase; + } if (peFile->dumpProcess(ModuleBase, entrypoint, NULL)) { - DoOutputDebugString("DumpProcess: Module image dump success"); + DoOutputDebugString("DumpProcess: Module image dump success - dump size 0x%x.\n", peFile->dumpSize); } else { @@ -150,7 +191,7 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD Ne } else { - DoOutputDebugString("DumpProcess: Invalid PE file or invalid PE header."); + DoOutputDebugString("DumpProcess: Invalid PE file or invalid PE header.\n"); delete peFile; return 0; } @@ -172,7 +213,7 @@ DWORD SafeGetDword(PVOID Address) } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputDebugString("SafeGetDword: Exception occured reading memory address 0x%x\n", Address); + DoOutputDebugString("SafeGetDword: Exception occured reading memory address 0x%p\n", Address); return NULL; } @@ -191,7 +232,7 @@ extern "C" int ScyllaDumpPE(DWORD_PTR Buffer) ProcessAccessHelp::setCurrentProcessAsTarget(); - DoOutputDebugString("DumpPE: Instantiating PeParser with address: 0x%x", Buffer); + DoOutputDebugString("DumpPE: Instantiating PeParser with address: 0x%p.\n", Buffer); peFile = new PeParser((DWORD_PTR)Buffer, TRUE); @@ -225,7 +266,7 @@ extern "C" int ScyllaDumpPE(DWORD_PTR Buffer) if (!ScanForNonZero((LPVOID)PointerToLastSection, SizeOfLastSection)) { - DoOutputDebugString("DumpPE: Empty last section, file image seems incomplete (from 0x%x to 0x%x).\n", PointerToLastSection, (DWORD_PTR)PointerToLastSection + SizeOfLastSection); + DoOutputDebugString("DumpPE: Empty or inaccessible last section, file image seems incomplete (from 0x%p to 0x%p).\n", PointerToLastSection, (DWORD_PTR)PointerToLastSection + SizeOfLastSection); return 0; } @@ -233,18 +274,18 @@ extern "C" int ScyllaDumpPE(DWORD_PTR Buffer) if (peFile->saveCompletePeToDisk(NULL)) { - DoOutputDebugString("DumpPE: PE file in memory dumped successfully."); + DoOutputDebugString("DumpPE: PE file in memory dumped successfully - dump size 0x%x.\n", peFile->dumpSize); } else { - DoOutputDebugString("DumpPE: Error: Cannot dump PE file from memory."); + DoOutputDebugString("DumpPE: Error: Cannot dump PE file from memory.\n"); delete peFile; return 0; } } else { - DoOutputDebugString("DumpPE: Error: Invalid PE file or invalid PE header."); + DoOutputDebugString("DumpPE: Error: Invalid PE file or invalid PE header.\n"); delete peFile; return 0; } @@ -267,7 +308,7 @@ extern "C" int LooksLikeSectionBoundary(DWORD_PTR Buffer) ) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("LooksLikeSectionBoundary: Yes - end of previous candidate section zero, beginning of candidate section at 0x%x non-zero.\n", Buffer); + DoOutputDebugString("LooksLikeSectionBoundary: Yes - end of previous candidate section zero, beginning of candidate section at 0x%p non-zero.\n", Buffer); #endif return 1; } @@ -275,17 +316,17 @@ extern "C" int LooksLikeSectionBoundary(DWORD_PTR Buffer) { #ifdef DEBUG_COMMENTS if (*(DWORD*)((BYTE*)Buffer - 4) != 0) - DoOutputDebugString("LooksLikeSectionBoundary: No - end of previous candidate section 0x%x not zero.\n", Buffer); + DoOutputDebugString("LooksLikeSectionBoundary: No - end of previous candidate section 0x%p not zero.\n", Buffer); if (*(DWORD*)((BYTE*)Buffer) == 0) - DoOutputDebugString("LooksLikeSectionBoundary: No - beginning of candidate section 0x%x zero.\n", Buffer); + DoOutputDebugString("LooksLikeSectionBoundary: No - beginning of candidate section 0x%p zero.\n", Buffer); #endif return 0; } } __except(EXCEPTION_EXECUTE_HANDLER) { - DoOutputDebugString("LooksLikeSectionBoundary: Exception occured reading around suspected boundary at 0x%x\n", Buffer); + DoOutputDebugString("LooksLikeSectionBoundary: Exception occured reading around suspected boundary at 0x%p\n", Buffer); return 0; } } @@ -388,13 +429,13 @@ bool isIATOutsidePeImage (DWORD_PTR addressIAT) } //************************************************************************************** -extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) +extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD_PTR NewOEP) //************************************************************************************** { DWORD addressIAT, sizeIAT; BOOL IAT_Found, AdvancedIATSearch = FALSE; bool isAfter; - DWORD ModuleBase; + DWORD_PTR ModuleBase; IATSearch iatSearch; ApiReader apiReader; @@ -424,7 +465,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) // Enumerate DLLs and imported functions apiReader.readApisFromModuleList(); - DoOutputDebugString("DumpCurrentProcessFixImports: Instantiating PeParser with address: 0x%x", ModuleBase); + DoOutputDebugString("DumpCurrentProcessFixImports: Instantiating PeParser with address: 0x%p.\n", ModuleBase); peFile = new PeParser(ModuleBase, TRUE); @@ -435,7 +476,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString(TEXT("DumpCurrentProcessFixImports: Module entry point VA is 0x%x"), ModuleBase + entrypointRVA); + DoOutputDebugString(TEXT("DumpCurrentProcessFixImports: Module entry point VA is 0x%p"), ModuleBase + entrypointRVA); // Let's dump then fix the dump on disk if (peFile->dumpProcess(ModuleBase, ModuleBase + entrypointRVA, CAPE_OUTPUT_FILE)) @@ -473,7 +514,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) { DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Found %d additional api addresses", iatReferenceScan.numberOfDirectImportApisNotInIat()); DWORD sizeIatNew = iatReferenceScan.addAdditionalApisToList(); - DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Old IAT size 0x%08x new IAT size 0x%08x", sizeIAT, sizeIatNew); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports - Old IAT size 0x%08x new IAT size 0x%08x.\n", sizeIAT, sizeIatNew); importsHandling.scanAndFixModuleList(); } @@ -491,14 +532,14 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) isAfter = 1; iatReferenceScan.patchDirectImportsMemory(isAfter); - DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports patched."); + DoOutputDebugString("DumpCurrentProcessFixImports: Direct imports patched.\n"); } } } if (isIATOutsidePeImage(addressIAT)) { - DoOutputDebugString("DumpCurrentProcessFixImports: Warning - IAT is not inside the PE image, requires rebasing."); + DoOutputDebugString("DumpCurrentProcessFixImports: Warning - IAT is not inside the PE image, requires rebasing.\n"); } ImportRebuilder importRebuild(CAPE_OUTPUT_FILE); @@ -546,7 +587,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) } else { - DoOutputDebugString("DumpCurrentProcessFixImports: Error - Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("DumpCurrentProcessFixImports: Error - Invalid PE file or invalid PE header. Try reading PE header from disk/process.\n"); delete peFile; return 0; } @@ -557,7 +598,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD NewOEP) } //************************************************************************************** -extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD NewOEP) +extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PTR NewOEP) //************************************************************************************** { bool isAfter; @@ -586,7 +627,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase apiReader.readApisFromModuleList(); - DoOutputDebugString(TEXT("DumpProcessFixImports: Instantiating PeParser with address: 0x%x"), ModuleBase); + DoOutputDebugString(TEXT("DumpProcessFixImports: Instantiating PeParser with address: 0x%p"), ModuleBase); peFile = new PeParser(ModuleBase, true); @@ -597,7 +638,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase else entrypointRVA = peFile->getEntryPoint(); - DoOutputDebugString(TEXT("DumpProcessFixImports: Module entry point VA is 0x%x"), ModuleBase + entrypointRVA); + DoOutputDebugString(TEXT("DumpProcessFixImports: Module entry point VA is 0x%p"), ModuleBase + entrypointRVA); // Let's dump then fix the dump on disk if (peFile->dumpProcess(ModuleBase, ModuleBase + entrypointRVA, CAPE_OUTPUT_FILE)) @@ -635,7 +676,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase { DoOutputDebugString("Direct imports - Found %d additional api addresses", iatReferenceScan.numberOfDirectImportApisNotInIat()); DWORD sizeIatNew = iatReferenceScan.addAdditionalApisToList(); - DoOutputDebugString("Direct imports - Old IAT size 0x%08x new IAT size 0x%08x", sizeIAT, sizeIatNew); + DoOutputDebugString("Direct imports - Old IAT size 0x%08x new IAT size 0x%08x.\n", sizeIAT, sizeIatNew); importsHandling.scanAndFixModuleList(); } @@ -653,14 +694,14 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase isAfter = 1; iatReferenceScan.patchDirectImportsMemory(isAfter); - DoOutputDebugString("Direct imports patched."); + DoOutputDebugString("Direct imports patched.\n"); } } } if (isIATOutsidePeImage(addressIAT)) { - DoOutputDebugString("Warning - IAT is not inside the PE image, requires rebasing."); + DoOutputDebugString("Warning - IAT is not inside the PE image, requires rebasing.\n"); } ImportRebuilder importRebuild(CapeOutputPath); @@ -707,7 +748,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase } else { - DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process."); + DoOutputDebugString("Error: Invalid PE file or invalid PE header. Try reading PE header from disk/process.\n"); delete peFile; return 0; } diff --git a/cuckoomon.c b/cuckoomon.c index f28128b..633ad20 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -80,7 +80,7 @@ static hook_t g_hooks[] = { // HOOK_NOTAIL_ALT(ntdll, LdrLoadDll, 4), - //HOOK_NOTAIL(ntdll, LdrUnloadDll, 1), + HOOK_NOTAIL(ntdll, LdrUnloadDll, 1), HOOK_SPECIAL(kernel32, CreateProcessInternalW), //HOOK_SPECIAL(ntdll, NtCreateThread), //HOOK_SPECIAL(ntdll, NtCreateThreadEx), @@ -125,6 +125,8 @@ static hook_t g_hooks[] = { HOOK(ntdll, NtCreateDirectoryObject), HOOK(ntdll, NtQueryDirectoryObject), + HOOK(kernel32, CreateFileTransactedA), + HOOK(kernel32, CreateFileTransactedW), // CreateDirectoryExA calls CreateDirectoryExW // CreateDirectoryW does not call CreateDirectoryExW HOOK(kernel32, CreateDirectoryW), @@ -141,7 +143,7 @@ static hook_t g_hooks[] = { // Covered by NtCreateFile() but still grab this information HOOK(kernel32, CopyFileA), HOOK(kernel32, CopyFileW), - HOOK(kernel32, CopyFileExW), + HOOK_NOTAIL_ALT(kernel32, CopyFileExW, 6), // Covered by NtSetInformationFile() but still grab this information HOOK(kernel32, DeleteFileA), @@ -272,6 +274,8 @@ static hook_t g_hooks[] = { //HOOK(user32, EnumWindows), HOOK(user32, PostMessageA), HOOK(user32, PostMessageW), + //HOOK(user32, SendMessageA), + //HOOK(user32, SendMessageW), HOOK(user32, SendNotifyMessageA), HOOK(user32, SendNotifyMessageW), HOOK(user32, SetWindowLongA), @@ -289,6 +293,11 @@ static hook_t g_hooks[] = { HOOK(ntdll, NtOpenEvent), HOOK(ntdll, NtCreateNamedPipeFile), + HOOK(ntdll, NtAddAtom), + HOOK(ntdll, NtAddAtomEx), + HOOK(ntdll, NtFindAtom), + HOOK(ntdll, NtDeleteAtom), + HOOK(ntdll, NtQueryInformationAtom), // // Process Hooks @@ -361,7 +370,8 @@ static hook_t g_hooks[] = { HOOK(user32, SetWindowsHookExA), HOOK(user32, SetWindowsHookExW), HOOK(user32, UnhookWindowsHookEx), - HOOK(kernel32, SetUnhandledExceptionFilter), + //HOOK(kernel32, SetUnhandledExceptionFilter), + HOOK(ntdll, RtlAddVectoredExceptionHandler), HOOK(kernel32, SetErrorMode), HOOK(ntdll, LdrGetDllHandle), HOOK(ntdll, LdrGetProcedureAddress), @@ -421,6 +431,7 @@ static hook_t g_hooks[] = { HOOK(netapi32, NetGetJoinInformation), HOOK(netapi32, NetUserGetLocalGroups), HOOK(urlmon, URLDownloadToFileW), + HOOK(urlmon, URLDownloadToCacheFileW), HOOK(urlmon, ObtainUserAgentString), HOOK(wininet, InternetGetConnectedState), HOOK(wininet, InternetOpenA), @@ -507,6 +518,7 @@ static hook_t g_hooks[] = { HOOK(ntdll, NtSetTimer), HOOK(ntdll, NtSetTimerEx), HOOK(user32, MsgWaitForMultipleObjectsEx), + HOOK(kernel32, CreateTimerQueueTimer), // // Socket Hooks diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index e91b5ce..9cf051e 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -413,7 +413,6 @@ - diff --git a/cuckoomon.vcxproj.filters b/cuckoomon.vcxproj.filters index 1a6ee9d..2e08dd6 100644 --- a/cuckoomon.vcxproj.filters +++ b/cuckoomon.vcxproj.filters @@ -395,9 +395,6 @@ Header Files\CAPE\Scylla - - Header Files\CAPE\Scylla - Header Files\CAPE\Scylla diff --git a/hook_file.c b/hook_file.c index c718804..8c3c413 100644 --- a/hook_file.c +++ b/hook_file.c @@ -28,8 +28,7 @@ along with this program. If not, see . #include "lookup.h" #include "config.h" -#define DUMP_FILE_MASK ((GENERIC_ALL | GENERIC_WRITE | FILE_GENERIC_WRITE | \ - FILE_WRITE_DATA | FILE_APPEND_DATA | STANDARD_RIGHTS_WRITE | MAXIMUM_ALLOWED) & ~SYNCHRONIZE) +#define DUMP_FILE_MASK ((GENERIC_ALL | GENERIC_WRITE | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_APPEND_DATA | MAXIMUM_ALLOWED) & ~SYNCHRONIZE) // length of a hardcoded unicode string #define UNILEN(x) (sizeof(x) / sizeof(wchar_t) - 1) @@ -48,6 +47,8 @@ typedef struct _file_log_t { static lookup_t g_files; static lookup_t g_file_logs; +static void new_file(const UNICODE_STRING *obj); + void file_init() { specialname_map_init(); @@ -139,17 +140,9 @@ void file_write(HANDLE file_handle) get_lasterrors(&lasterror); r = lookup_get(&g_files, (ULONG_PTR)file_handle, NULL); - if(r != NULL) { - UNICODE_STRING str; - str.Length = (USHORT)r->length * sizeof(wchar_t); - str.MaximumLength = ((USHORT)r->length + 1) * sizeof(wchar_t); - str.Buffer = r->filename; - - // we do in fact want to dump this file because it was written to - new_file(&str); - - // delete the file record from the list - lookup_del(&g_files, (ULONG_PTR)file_handle); + if(r == NULL) { + r = lookup_add(&g_files, (ULONG_PTR)file_handle, sizeof(file_record_t)); + memset(r, 0, sizeof(*r)); } set_lasterrors(&lasterror); @@ -199,7 +192,7 @@ static void handle_new_file(HANDLE file_handle, const OBJECT_ATTRIBUTES *obj) len = lstrlenW(absolutename); // cache this file if (is_ignored_file_unicode(absolutename, len) == 0) - cache_file(file_handle, absolutename, len, obj->Attributes); + cache_file(file_handle, absolutename, len, obj->Attributes); free(absolutename); } else { @@ -242,12 +235,33 @@ void handle_duplicate(HANDLE old_handle, HANDLE new_handle) void file_close(HANDLE file_handle) { lasterror_t lasterror; + file_record_t *r; get_lasterrors(&lasterror); - lookup_del(&g_files, (ULONG_PTR) file_handle); + + r = lookup_get(&g_files, (ULONG_PTR)file_handle, NULL); + if(r != NULL) { + UNICODE_STRING str; + str.Length = (USHORT)r->length * sizeof(wchar_t); + str.MaximumLength = ((USHORT)r->length + 1) * sizeof(wchar_t); + str.Buffer = r->filename; + + new_file(&str); + + lookup_del(&g_files, (ULONG_PTR) file_handle); + } + set_lasterrors(&lasterror); } +void handle_terminate() +{ + entry_t *p; + + for (p = (entry_t*)&(g_files.root); p != NULL; p = p->next) { + file_close((HANDLE)p->id); + } +} static BOOLEAN is_protected_objattr(POBJECT_ATTRIBUTES obj) { wchar_t path[MAX_PATH_PLUS_TOLERANCE]; @@ -259,8 +273,8 @@ static BOOLEAN is_protected_objattr(POBJECT_ATTRIBUTES obj) lasterror_t lasterror; lasterror.NtstatusError = STATUS_ACCESS_DENIED; lasterror.Win32Error = ERROR_ACCESS_DENIED; - set_lasterrors(&lasterror); free(absolutepath); + set_lasterrors(&lasterror); return TRUE; } free(absolutepath); @@ -395,8 +409,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtReadFile, set_special_api(API_NTREADFILE, deletelast); - set_lasterrors(&lasterrors); - if (read_count <= 50) { fname = calloc(32768, sizeof(wchar_t)); path_from_handle(FileHandle, fname, 32768); @@ -411,6 +423,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtReadFile, free(fname); } + set_lasterrors(&lasterrors); + return ret; } @@ -879,6 +893,46 @@ HOOKDEF_ALT(BOOL, WINAPI, MoveFileWithProgressTransactedW, return ret; } +HOOKDEF (HANDLE, WINAPI, CreateFileTransactedA, + __in LPCSTR lpFileName, + __in DWORD dwDesiredAccess, + __in DWORD dwShareMode, + __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, + __in DWORD dwCreationDisposition, + __in DWORD dwFlagsAndAttributes, + __in_opt HANDLE hTemplateFile, + __in HANDLE hTransaction, + __in_opt PUSHORT pusMiniVersion, + __reserved PVOID pExtendedParameter +) { + HANDLE ret = Old_CreateFileTransactedA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, + dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter); + + LOQ_handle("filesystem", "hfhh", "FileHandle", ret, "FileName", lpFileName, "TransactionHandle", hTransaction, "FlagsAndAttributes", dwFlagsAndAttributes); + + return ret; +} + +HOOKDEF (HANDLE, WINAPI, CreateFileTransactedW, + __in LPCWSTR lpFileName, + __in DWORD dwDesiredAccess, + __in DWORD dwShareMode, + __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, + __in DWORD dwCreationDisposition, + __in DWORD dwFlagsAndAttributes, + __in_opt HANDLE hTemplateFile, + __in HANDLE hTransaction, + __in_opt PUSHORT pusMiniVersion, + __reserved PVOID pExtendedParameter +) { + HANDLE ret = Old_CreateFileTransactedW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, + dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter); + + LOQ_handle("filesystem", "hFhh", "FileHandle", ret, "FileName", lpFileName, "TransactionHandle", hTransaction, "FlagsAndAttributes", dwFlagsAndAttributes); + + return ret; +} + HOOKDEF(HANDLE, WINAPI, FindFirstFileExA, __in LPCSTR lpFileName, __in FINDEX_INFO_LEVELS fInfoLevelId, @@ -1049,7 +1103,31 @@ HOOKDEF(BOOL, WINAPI, CopyFileW, return ret; } -HOOKDEF(BOOL, WINAPI, CopyFileExW, +HOOKDEF_NOTAIL(WINAPI, CopyFileExW, + _In_ LPWSTR lpExistingFileName, + _In_ LPWSTR lpNewFileName, + _In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine, + _In_opt_ LPVOID lpData, + _In_opt_ LPBOOL pbCancel, + _In_ DWORD dwCopyFlags +) { + BOOL ret = TRUE; + BOOL file_existed = FALSE; + + if (GetFileAttributesW(lpNewFileName) != INVALID_FILE_ATTRIBUTES) + file_existed = TRUE; + + if (lpProgressRoutine) { + LOQ_bool("filesystem", "FFis", "ExistingFileName", lpExistingFileName, + "NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, "ExistedBefore", file_existed ? "yes" : "no"); + return 0; + } + + return 1; +} + + +HOOKDEF_ALT(BOOL, WINAPI, CopyFileExW, _In_ LPWSTR lpExistingFileName, _In_ LPWSTR lpNewFileName, _In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine, @@ -1065,14 +1143,13 @@ HOOKDEF(BOOL, WINAPI, CopyFileExW, ret = Old_CopyFileExW(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags); LOQ_bool("filesystem", "FFis", "ExistingFileName", lpExistingFileName, - "NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, file_existed ? "yes" : "no"); + "NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, "ExistedBefore", file_existed ? "yes" : "no"); if (ret) new_file_path_unicode(lpNewFileName); return ret; } - HOOKDEF(BOOL, WINAPI, DeleteFileA, __in LPCSTR lpFileName ) { @@ -1222,6 +1299,9 @@ HOOKDEF(BOOL, WINAPI, GetVolumeInformationA, *lpVolumeSerialNumber = 0x46e70ca9; debug_message("Changed Volume Serial Number."); } + + + } #endif return ret; @@ -1292,7 +1372,7 @@ HOOKDEF(BOOL, WINAPI, GetVolumeInformationByHandleW, if (ret && lpVolumeSerialNumber && g_config.serial_number) *lpVolumeSerialNumber = g_config.serial_number; - LOQ_bool("filesystem", "uH", "VolumeName", lpVolumeNameBuffer, "VolumeSerial", lpVolumeSerialNumber); + LOQ_bool("filesystem", "puH", "Handle", hFile, "VolumeName", lpVolumeNameBuffer, "VolumeSerial", lpVolumeSerialNumber); return ret; } @@ -1324,8 +1404,8 @@ HOOKDEF(HRESULT, WINAPI, SHGetKnownFolderPath, memcpy(&id1, rfid, sizeof(id1)); sprintf(idbuf, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); - set_lasterrors(&lasterrors); LOQ_hresult("filesystem", "shu", "FolderID", idbuf, "Flags", dwFlags, "Path", ppszPath ? *ppszPath : NULL); + set_lasterrors(&lasterrors); return ret; } diff --git a/hook_misc.c b/hook_misc.c index 7767708..f8d94fd 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -27,6 +27,8 @@ along with this program. If not, see . #include "config.h" #include "ignore.h" +#define STATUS_BAD_COMPRESSION_BUFFER ((NTSTATUS)0xC0000242L) + HOOKDEF(HHOOK, WINAPI, SetWindowsHookExA, __in int idHook, __in HOOKPROC lpfn, @@ -93,6 +95,19 @@ HOOKDEF(LPTOP_LEVEL_EXCEPTION_FILTER, WINAPI, SetUnhandledExceptionFilter, return res; } +HOOKDEF(PVOID, WINAPI, RtlAddVectoredExceptionHandler, + __in ULONG First, + __out PVECTORED_EXCEPTION_HANDLER Handler +) { + PVOID ret = 0; + + ret = Old_RtlAddVectoredExceptionHandler(First, Handler); + + LOQ_nonnull("hooking", "ip", "First", First, "Handler", Handler); + + return ret; +} + HOOKDEF(UINT, WINAPI, SetErrorMode, _In_ UINT uMode ) { @@ -557,8 +572,14 @@ HOOKDEF(NTSTATUS, WINAPI, RtlDecompressBuffer, NTSTATUS ret = Old_RtlDecompressBuffer(CompressionFormat, UncompressedBuffer, UncompressedBufferSize, CompressedBuffer, CompressedBufferSize, FinalUncompressedSize); - LOQ_ntstatus("misc", "pch", "UncompressedBufferAddress", UncompressedBuffer, "UncompressedBuffer", - ret ? 0 : *FinalUncompressedSize, UncompressedBuffer, "UncompressedBufferLength", ret ? 0 : *FinalUncompressedSize); + if ((NT_SUCCESS(ret) || ret == STATUS_BAD_COMPRESSION_BUFFER) && (*FinalUncompressedSize > 0)) { + // There are samples that return STATUS_BAD_COMPRESSION_BUFFER but still continue + LOQ_ntstatus("misc", "pch", "UncompressedBufferAddress", UncompressedBuffer, "UncompressedBuffer", + *FinalUncompressedSize, UncompressedBuffer, "UncompressedBufferLength", *FinalUncompressedSize); + } + else + LOQ_ntstatus("misc", "pch", "UncompressedBufferAddress", UncompressedBuffer, "UncompressedBuffer", + 0, UncompressedBuffer, "UncompressedBufferLength", 0); return ret; } @@ -739,12 +760,13 @@ HOOKDEF(HDEVINFO, WINAPI, SetupDiGetClassDevsA, memcpy(&id1, ClassGuid, sizeof(id1)); sprintf(idbuf, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); - set_lasterrors(&lasterror); if ((known = known_object(&id1))) LOQ_handle("misc", "ss", "ClassGuid", idbuf, "Known", known); else LOQ_handle("misc", "s", "ClassGuid", idbuf); + + set_lasterrors(&lasterror); } return ret; } @@ -759,17 +781,21 @@ HOOKDEF(HDEVINFO, WINAPI, SetupDiGetClassDevsW, char idbuf[40]; char *known; lasterror_t lasterror; + + get_lasterrors(&lasterror); + HDEVINFO ret = Old_SetupDiGetClassDevsW(ClassGuid, Enumerator, hwndParent, Flags); if (ClassGuid) { memcpy(&id1, ClassGuid, sizeof(id1)); sprintf(idbuf, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); - set_lasterrors(&lasterror); if ((known = known_object(&id1))) LOQ_handle("misc", "ss", "ClassGuid", idbuf, "Known", known); else LOQ_handle("misc", "s", "ClassGuid", idbuf); + + set_lasterrors(&lasterror); } return ret; } @@ -789,15 +815,15 @@ HOOKDEF(BOOL, WINAPI, SetupDiGetDeviceRegistryPropertyA, ret = Old_SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); - if (PropertyBuffer) - LOQ_bool("misc", "ir", "Property", Property, "PropertyBuffer", *PropertyRegDataType, PropertyBufferSize, PropertyBuffer); - if (!g_config.no_stealth && ret && PropertyBuffer) { replace_ci_string_in_buf(PropertyBuffer, *RequiredSize, "VBOX", "DELL_"); replace_ci_string_in_buf(PropertyBuffer, *RequiredSize, "QEMU", "DELL"); replace_ci_string_in_buf(PropertyBuffer, *RequiredSize, "VMWARE", "DELL__"); } + if (PropertyBuffer) + LOQ_bool("misc", "ir", "Property", Property, "PropertyBuffer", *PropertyRegDataType, PropertyBufferSize, PropertyBuffer); + return ret; } @@ -817,15 +843,15 @@ HOOKDEF(BOOL, WINAPI, SetupDiGetDeviceRegistryPropertyW, ret = Old_SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize); - if (PropertyBuffer) - LOQ_bool("misc", "iR", "Property", Property, "PropertyBuffer", *PropertyRegDataType, PropertyBufferSize, PropertyBuffer); - if (!g_config.no_stealth && ret && PropertyBuffer) { replace_ci_wstring_in_buf((PWCHAR)PropertyBuffer, *RequiredSize / sizeof(WCHAR), L"VBOX", L"DELL_"); replace_ci_wstring_in_buf((PWCHAR)PropertyBuffer, *RequiredSize / sizeof(WCHAR), L"QEMU", L"DELL"); replace_ci_wstring_in_buf((PWCHAR)PropertyBuffer, *RequiredSize / sizeof(WCHAR), L"VMWARE", L"DELL__"); } + if (PropertyBuffer) + LOQ_bool("misc", "iR", "Property", Property, "PropertyBuffer", *PropertyRegDataType, PropertyBufferSize, PropertyBuffer); + return ret; } @@ -1025,20 +1051,33 @@ HOOKDEF(void, WINAPIV, memcpy, size_t count ) { - int ret = 0; // seems this is needed for LOQ_void. TODO: fix this lameness + int ret = 0; // needed for LOQ_void Old_memcpy(dest, src, count); - LOQ_void("misc", "bi", "DestinationBuffer", count, dest, "count", count); + if (count > 0xa00) + LOQ_void("misc", "bppi", "DestinationBuffer", count, dest, "source", src, "destination", dest, "count", count); return; } +HOOKDEF(unsigned int, WINAPIV, SizeofResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +) +{ + unsigned int ret = Old_SizeofResource(hModule, hResInfo); + + LOQ_nonzero("misc", "ppi", "ModuleHandle", hModule, "ResourceInfo", hResInfo, "Size", ret); + + return ret; +} + HOOKDEF(void, WINAPIV, srand, unsigned int seed ) { - int ret = 0; // seems this is needed for LOQ_void. TODO: fix this lameness + int ret = 0; // needed for LOQ_void Old_srand(seed); diff --git a/hook_network.c b/hook_network.c index 6e819bb..0140a68 100644 --- a/hook_network.c +++ b/hook_network.c @@ -255,15 +255,30 @@ HOOKDEF(HRESULT, WINAPI, URLDownloadToFileW, DWORD dwReserved, LPVOID lpfnCB ) { - HRESULT ret = Old_URLDownloadToFileW(pCaller, szURL, szFileName, - dwReserved, lpfnCB); - LOQ_hresult("network", "uFs", "URL", szURL, "FileName", szFileName, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); - if(ret == S_OK) { - pipe("FILE_NEW:%S", -1, szFileName); - } + HRESULT ret = Old_URLDownloadToFileW(pCaller, szURL, szFileName, dwReserved, lpfnCB); + LOQ_hresult("network", "uFs", "URL", szURL, "FileName", szFileName, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + if(ret == S_OK) + pipe("FILE_NEW:%Z", szFileName); + return ret; } +HOOKDEF(HRESULT, WINAPI, URLDownloadToCacheFileW, + _In_ LPUNKNOWN lpUnkcalled, + _In_ LPCWSTR szURL, + _Out_ LPWSTR szFilename, + _In_ DWORD cchFilename, + _Reserved_ DWORD dwReserved, + _In_opt_ VOID *pBSC +) { + HRESULT ret = Old_URLDownloadToCacheFileW(lpUnkcalled, szURL, szFilename, cchFilename, dwReserved, pBSC); + LOQ_hresult("network", "uFs", "URL", szURL, "Filename", ret == S_OK ? szFilename : L"", "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + if (ret == S_OK) + pipe("FILE_NEW:%Z", szFilename); + + return ret; +} + HOOKDEF(BOOL, WINAPI, InternetGetConnectedState, _Out_ LPDWORD lpdwFlags, _In_ DWORD dwReserved @@ -647,10 +662,12 @@ HOOKDEF(BOOL, WINAPI, InternetReadFile, _In_ DWORD dwNumberOfBytesToRead, _Out_ LPDWORD lpdwNumberOfBytesRead ) { - BOOL ret = Old_InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, - lpdwNumberOfBytesRead); - LOQ_bool("network", "pB", "InternetHandle", hFile, - "Buffer", lpdwNumberOfBytesRead, lpBuffer); + BOOL ret = Old_InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead); + if (is_bytes_in_buf(lpBuffer, *lpdwNumberOfBytesRead, "\x00\x50\x4f\x4c\x49\x4d\x4f\x52\x46\x00", 10, 256)) + LOQ_bool("network", "pCI", "InternetHandle", hFile, "Buffer", lpdwNumberOfBytesRead, lpBuffer, "BytesRead", lpdwNumberOfBytesRead); + else + LOQ_bool("network", "pBI", "InternetHandle", hFile, "Buffer", lpdwNumberOfBytesRead, lpBuffer, "BytesRead", lpdwNumberOfBytesRead); + return ret; } diff --git a/hook_process.c b/hook_process.c index cf2c796..35be5a5 100644 --- a/hook_process.c +++ b/hook_process.c @@ -121,8 +121,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateProcessEx, NTSTATUS ret = Old_NtCreateProcessEx(ProcessHandle, DesiredAccess, ObjectAttributes, ParentProcess, Flags, SectionHandle, DebugPort, ExceptionPort, InJob); - LOQ_ntstatus("process", "PphO", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, - "FileName", ObjectAttributes); + LOQ_ntstatus("process", "PphOhh", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, + "FileName", ObjectAttributes, "Flags", Flags, "SectionHandle", SectionHandle); if(NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); @@ -515,14 +515,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, { if (CurrentSectionView->LocalView == BaseAddress) { - DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, faking.\n", BaseAddress); - - ret = STATUS_SUCCESS; - - LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "RegionSize", map_size); - - return ret; + DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); + DumpSectionViewForPid(CurrentSectionView, pid); } CurrentSectionView = CurrentSectionView->NextSectionView; @@ -659,7 +653,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtAllocateVirtualMemory, NTSTATUS ret = Old_NtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect); - if (ret != STATUS_CONFLICTING_ADDRESSES && (Protect != PAGE_READWRITE || GetCurrentProcessId() != our_getprocessid(ProcessHandle))) { + if (ret != STATUS_CONFLICTING_ADDRESSES) { LOQ_ntstatus("process", "pPPhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", RegionSize, "Protection", Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); } @@ -680,10 +674,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtReadVirtualMemory, ret = Old_NtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToRead, NumberOfBytesRead); - if (pid_from_process_handle(ProcessHandle) != GetCurrentProcessId()) { - LOQ_ntstatus("process", "ppB", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "Buffer", NumberOfBytesRead, Buffer); - } + LOQ_ntstatus("process", "ppB", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "Buffer", NumberOfBytesRead, Buffer); return ret; } @@ -695,16 +687,14 @@ HOOKDEF(BOOL, WINAPI, ReadProcessMemory, _In_ SIZE_T nSize, _Out_ PSIZE_T lpNumberOfBytesRead ) { - BOOL ret; + BOOL ret; ENSURE_SIZET(lpNumberOfBytesRead); ret = Old_ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead); - if (pid_from_process_handle(hProcess) != GetCurrentProcessId()) { - LOQ_bool("process", "ppB", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, - "Buffer", lpNumberOfBytesRead, lpBuffer); - } + LOQ_bool("process", "ppB", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, + "Buffer", lpNumberOfBytesRead, lpBuffer); return ret; } @@ -992,10 +982,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtWow64WriteVirtualMemory64, pid = pid_from_process_handle(ProcessHandle); - if (pid != GetCurrentProcessId()) { - LOQ_bool("process", "pxbhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "Buffer", NumberOfBytesWritten->LowPart, Buffer, "BufferLength", NumberOfBytesWritten->LowPart, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + LOQ_bool("process", "pxbhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "Buffer", NumberOfBytesWritten->LowPart, Buffer, "BufferLength", NumberOfBytesWritten->LowPart, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + if (pid != GetCurrentProcessId()) { if (ret) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); @@ -1026,10 +1016,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, ret = Old_NtProtectVirtualMemory(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection); - /* Don't log an uninteresting case */ - //if (OldAccessProtection && *OldAccessProtection == NewAccessProtection) - // return ret; - memset(&meminfo, 0, sizeof(meminfo)); if (NT_SUCCESS(ret)) { lasterror_t lasterrors; @@ -1038,7 +1024,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, set_lasterrors(&lasterrors); } - if (NewAccessProtection == PAGE_EXECUTE_READWRITE && GetCurrentProcessId() == our_getprocessid(ProcessHandle) && + if (NewAccessProtection == PAGE_EXECUTE_READWRITE && (ULONG_PTR)meminfo.AllocationBase >= get_stack_bottom() && (((ULONG_PTR)meminfo.AllocationBase + meminfo.RegionSize) <= get_stack_top())) { LOQ_ntstatus("process", "pPPhhHss", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "NumberOfBytesProtected", NumberOfBytesToProtect, @@ -1073,10 +1059,6 @@ HOOKDEF(BOOL, WINAPI, VirtualProtectEx, ret = Old_VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect, lpflOldProtect); - /* Don't log an uninteresting case */ - //if (lpflOldProtect && *lpflOldProtect == flNewProtect) - // return ret; - memset(&meminfo, 0, sizeof(meminfo)); if (ret) { lasterror_t lasterrors; @@ -1107,10 +1089,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtFreeVirtualMemory, NTSTATUS ret = Old_NtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType); - if (GetCurrentProcessId() != our_getprocessid(ProcessHandle)) { - LOQ_ntstatus("process", "pPPh", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "RegionSize", RegionSize, "FreeType", FreeType); - } + LOQ_ntstatus("process", "pPPh", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "RegionSize", RegionSize, "FreeType", FreeType); return ret; } diff --git a/hook_reg.c b/hook_reg.c index 5fdeb2c..f3f45ff 100644 --- a/hook_reg.c +++ b/hook_reg.c @@ -30,30 +30,45 @@ HOOKDEF(LONG, WINAPI, RegOpenKeyExA, __in REGSAM samDesired, __out PHKEY phkResult ) { + HKEY saved_hkey = phkResult ? *phkResult : INVALID_HANDLE_VALUE; LONG ret = Old_RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, phkResult); // fake the absence of some keys - if (!g_config.no_stealth && ret == ERROR_SUCCESS) { - unsigned int allocsize = sizeof(KEY_NAME_INFORMATION)+MAX_KEY_BUFLEN; + if (!g_config.no_stealth && (ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED)) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; PKEY_NAME_INFORMATION keybuf = malloc(allocsize); wchar_t *keypath = get_full_key_pathA(hKey, lpSubKey, keybuf, allocsize); - - if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT")) { - lasterror_t errors; - ret = errors.Win32Error = ERROR_FILE_NOT_FOUND; - errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND; - set_lasterrors(&errors); + int i; + + wchar_t *hidden_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT" + }; + + for (i = 0; i < _countof(hidden_keys); ++i) { + if (!wcsicmp(keypath, hidden_keys[i])) { + lasterror_t errors; + // clean up state to avoid leaking information + if (ret == ERROR_SUCCESS && phkResult) { + RegCloseKey(*phkResult); + *phkResult = saved_hkey; + } + ret = errors.Win32Error = ERROR_FILE_NOT_FOUND; + errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND; + set_lasterrors(&errors); + break; + } } + free(keybuf); } - LOQ_zero("registry", "psPe", "Registry", (DWORD)hKey, "SubKey", lpSubKey, "Handle", phkResult, - "FullName", (DWORD)hKey, lpSubKey); + LOQ_zero("registry", "psPe", "Registry", hKey, "SubKey", lpSubKey, "Handle", phkResult, + "FullName", hKey, lpSubKey); return ret; } @@ -64,30 +79,45 @@ HOOKDEF(LONG, WINAPI, RegOpenKeyExW, __in REGSAM samDesired, __out PHKEY phkResult ) { + HKEY saved_hkey = phkResult ? *phkResult : INVALID_HANDLE_VALUE; LONG ret = Old_RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult); // fake the absence of some keys - if (!g_config.no_stealth && ret == ERROR_SUCCESS) { - unsigned int allocsize = sizeof(KEY_NAME_INFORMATION)+MAX_KEY_BUFLEN; + if (!g_config.no_stealth && (ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED)) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; PKEY_NAME_INFORMATION keybuf = malloc(allocsize); wchar_t *keypath = get_full_key_pathW(hKey, lpSubKey, keybuf, allocsize); - - if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__") || - !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT")) { - lasterror_t errors; - ret = errors.Win32Error = ERROR_FILE_NOT_FOUND; - errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND; - set_lasterrors(&errors); + int i; + + wchar_t *hidden_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT" + }; + + for (i = 0; i < _countof(hidden_keys); ++i) { + if (!wcsicmp(keypath, hidden_keys[i])) { + lasterror_t errors; + // clean up state to avoid leaking information + if (ret == ERROR_SUCCESS && phkResult) { + RegCloseKey(*phkResult); + *phkResult = saved_hkey; + } + ret = errors.Win32Error = ERROR_FILE_NOT_FOUND; + errors.NtstatusError = STATUS_OBJECT_NAME_NOT_FOUND; + set_lasterrors(&errors); + break; + } } + free(keybuf); } - LOQ_zero("registry", "puPE", "Registry", (DWORD)hKey, "SubKey", lpSubKey, "Handle", phkResult, - "FullName", (DWORD)hKey, lpSubKey); + LOQ_zero("registry", "puPE", "Registry", hKey, "SubKey", lpSubKey, "Handle", phkResult, + "FullName", hKey, lpSubKey); return ret; } @@ -107,8 +137,34 @@ HOOKDEF(LONG, WINAPI, RegCreateKeyExA, ret = Old_RegCreateKeyExA(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); - LOQ_zero("registry", "psshPeI", "Registry", (DWORD)hKey, "SubKey", lpSubKey, "Class", lpClass, - "Access", samDesired, "Handle", phkResult, "FullName", (DWORD)hKey, lpSubKey, + + // fake the absence of some keys + if (!g_config.no_stealth && ret == ERROR_SUCCESS && *lpdwDisposition == REG_OPENED_EXISTING_KEY) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; + PKEY_NAME_INFORMATION keybuf = malloc(allocsize); + wchar_t *keypath = get_full_key_pathA(hKey, lpSubKey, keybuf, allocsize); + int i; + + wchar_t *hidden_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT" + }; + + for (i = 0; i < _countof(hidden_keys); ++i) { + if (!wcsicmp(keypath, hidden_keys[i])) { + *lpdwDisposition = REG_CREATED_NEW_KEY; + break; + } + } + free(keybuf); + } + + LOQ_zero("registry", "psshPeI", "Registry", hKey, "SubKey", lpSubKey, "Class", lpClass, + "Access", samDesired, "Handle", phkResult, "FullName", hKey, lpSubKey, "Disposition", lpdwDisposition); return ret; } @@ -129,8 +185,34 @@ HOOKDEF(LONG, WINAPI, RegCreateKeyExW, ret = Old_RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); - LOQ_zero("registry", "puuhPEI", "Registry", (DWORD)hKey, "SubKey", lpSubKey, "Class", lpClass, - "Access", samDesired, "Handle", phkResult, "FullName", (DWORD)hKey, lpSubKey, + + // fake the absence of some keys + if (!g_config.no_stealth && ret == ERROR_SUCCESS && *lpdwDisposition == REG_OPENED_EXISTING_KEY) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; + PKEY_NAME_INFORMATION keybuf = malloc(allocsize); + wchar_t *keypath = get_full_key_pathW(hKey, lpSubKey, keybuf, allocsize); + int i; + + wchar_t *hidden_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT\\VBOX__\\VBOXBIOS", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT\\VBOX__\\VBOXFACP", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT\\VBOX__\\VBOXRSDT" + }; + + for (i = 0; i < _countof(hidden_keys); ++i) { + if (!wcsicmp(keypath, hidden_keys[i])) { + *lpdwDisposition = REG_CREATED_NEW_KEY; + break; + } + } + free(keybuf); + } + + LOQ_zero("registry", "puuhPEI", "Registry", hKey, "SubKey", lpSubKey, "Class", lpClass, + "Access", samDesired, "Handle", phkResult, "FullName", hKey, lpSubKey, "Disposition", lpdwDisposition); return ret; } @@ -140,8 +222,8 @@ HOOKDEF(LONG, WINAPI, RegDeleteKeyA, __in LPCTSTR lpSubKey ) { LONG ret = Old_RegDeleteKeyA(hKey, lpSubKey); - LOQ_zero("registry", "pse", "Handle", (DWORD)hKey, "SubKey", lpSubKey, - "FullName", (DWORD)hKey, lpSubKey); + LOQ_zero("registry", "pse", "Handle", hKey, "SubKey", lpSubKey, + "FullName", hKey, lpSubKey); return ret; } @@ -162,8 +244,37 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyW, __in DWORD cchName ) { LONG ret = Old_RegEnumKeyW(hKey, dwIndex, lpName, cchName); - LOQ_zero("registry", "piuE", "Handle", (DWORD)hKey, "Index", dwIndex, "Name", ret ? L"" : lpName, - "FullName", (DWORD)hKey, ret ? L"" : lpName); + + // fake the absence of some keys + if (!g_config.no_stealth && ret == ERROR_SUCCESS) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; + PKEY_NAME_INFORMATION keybuf = malloc(allocsize); + wchar_t *keypath = get_full_key_pathW(hKey, NULL, keybuf, allocsize); + int i, j; + + wchar_t *parent_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT", + }; + + wchar_t *replace_subkeys[] = { + L"VBOX__", L"DELL__", + L"VBOX__", L"DELL__", + L"VBOX__", L"DELL__" + }; + + for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { + if (!wcsicmp(keypath, parent_keys[i]) && !wcsicmp(lpName, replace_subkeys[j])) { + wcscpy(lpName, replace_subkeys[j + 1]); + break; + } + } + free(keybuf); + } + + LOQ_zero("registry", "piuE", "Handle", hKey, "Index", dwIndex, "Name", ret ? L"" : lpName, + "FullName", hKey, ret ? L"" : lpName); return ret; } @@ -180,8 +291,37 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExA, ) { LONG ret = Old_RegEnumKeyExA(hKey, dwIndex, lpName, lpcName, lpReserved, lpClass, lpcClass, lpftLastWriteTime); - LOQ_zero("registry", "pisse", "Handle", (DWORD)hKey, "Index", dwIndex, "Name", ret ? "" : lpName, - "Class", ret ? "" : lpClass, "FullName", (DWORD)hKey, ret ? "" : lpName); + + // fake the absence of some keys + if (!g_config.no_stealth && ret == ERROR_SUCCESS) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; + PKEY_NAME_INFORMATION keybuf = malloc(allocsize); + wchar_t *keypath = get_full_key_pathA(hKey, NULL, keybuf, allocsize); + int i, j; + + wchar_t *parent_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT" + }; + + char *replace_subkeys[] = { + "VBOX__", "DELL__", + "VBOX__", "DELL__", + "VBOX__", "DELL__" + }; + + for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { + if (!wcsicmp(keypath, parent_keys[i]) && !stricmp(lpName, replace_subkeys[j])) { + strcpy(lpName, replace_subkeys[j + 1]); + break; + } + } + free(keybuf); + } + + LOQ_zero("registry", "pisse", "Handle", hKey, "Index", dwIndex, "Name", ret ? "" : lpName, + "Class", ret ? "" : lpClass, "FullName", hKey, ret ? "" : lpName); return ret; } @@ -197,8 +337,37 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExW, ) { LONG ret = Old_RegEnumKeyExW(hKey, dwIndex, lpName, lpcName, lpReserved, lpClass, lpcClass, lpftLastWriteTime); - LOQ_zero("registry", "piuuE", "Handle", (DWORD)hKey, "Index", dwIndex, "Name", ret ? L"" : lpName, - "Class", ret ? L"" : lpClass, "FullName", (DWORD)hKey, ret ? L"" : lpName); + + // fake the absence of some keys + if (!g_config.no_stealth && ret == ERROR_SUCCESS) { + unsigned int allocsize = sizeof(KEY_NAME_INFORMATION) + MAX_KEY_BUFLEN; + PKEY_NAME_INFORMATION keybuf = malloc(allocsize); + wchar_t *keypath = get_full_key_pathW(hKey, NULL, keybuf, allocsize); + int i, j; + + wchar_t *parent_keys[] = { + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT", + }; + + wchar_t *replace_subkeys[] = { + L"VBOX__", L"DELL__", + L"VBOX__", L"DELL__", + L"VBOX__", L"DELL__" + }; + + for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { + if (!wcsicmp(keypath, parent_keys[i]) && !wcsicmp(lpName, replace_subkeys[j])) { + wcscpy(lpName, replace_subkeys[j + 1]); + break; + } + } + free(keybuf); + } + + LOQ_zero("registry", "piuuE", "Handle", hKey, "Index", dwIndex, "Name", ret ? L"" : lpName, + "Class", ret ? L"" : lpClass, "FullName", hKey, ret ? L"" : lpName); return ret; } @@ -218,9 +387,9 @@ HOOKDEF(LONG, WINAPI, RegEnumValueA, lpReserved, lpType, lpData, lpcbData); if(ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL && lpcbData != NULL) { - LOQ_zero("registry", "pisre", "Handle", (DWORD)hKey, "Index", dwIndex, + LOQ_zero("registry", "pisre", "Handle", hKey, "Index", dwIndex, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { LOQ_zero("registry", "pisIIe", "Handle", hKey, "Index", dwIndex, @@ -246,9 +415,9 @@ HOOKDEF(LONG, WINAPI, RegEnumValueW, lpReserved, lpType, lpData, lpcbData); if(ret == ERROR_SUCCESS && lpType != NULL && lpData != NULL && lpcbData != NULL) { - LOQ_zero("registry", "piuRE", "Handle", (DWORD)hKey, "Index", dwIndex, + LOQ_zero("registry", "piuRE", "Handle", hKey, "Index", dwIndex, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { LOQ_zero("registry", "piuIIE", "Handle", hKey, "Index", dwIndex, @@ -269,13 +438,13 @@ HOOKDEF(LONG, WINAPI, RegSetValueExA, LONG ret = Old_RegSetValueExA(hKey, lpValueName, Reserved, dwType, lpData, cbData); if(ret == ERROR_SUCCESS) { - LOQ_zero("registry", "psiriv", "Handle", (DWORD)hKey, "ValueName", lpValueName, "Type", dwType, + LOQ_zero("registry", "psiriv", "Handle", hKey, "ValueName", lpValueName, "Type", dwType, "Buffer", dwType, cbData, lpData, "BufferLength", cbData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { - LOQ_zero("registry", "psiv", "Handle", (DWORD)hKey, "ValueName", lpValueName, "Type", dwType, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "psiv", "Handle", hKey, "ValueName", lpValueName, "Type", dwType, + "FullName", hKey, lpValueName); } return ret; } @@ -291,13 +460,13 @@ HOOKDEF(LONG, WINAPI, RegSetValueExW, LONG ret = Old_RegSetValueExW(hKey, lpValueName, Reserved, dwType, lpData, cbData); if(ret == ERROR_SUCCESS) { - LOQ_zero("registry", "puiRiV", "Handle", (DWORD)hKey, "ValueName", lpValueName, "Type", dwType, + LOQ_zero("registry", "puiRiV", "Handle", hKey, "ValueName", lpValueName, "Type", dwType, "Buffer", dwType, cbData, lpData, "BufferLength", cbData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { - LOQ_zero("registry", "puiV", "Handle", (DWORD)hKey, "ValueName", lpValueName, "Type", dwType, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "puiV", "Handle", hKey, "ValueName", lpValueName, "Type", dwType, + "FullName", hKey, lpValueName); } return ret; } @@ -320,7 +489,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExA, PKEY_NAME_INFORMATION keybuf = malloc(allocsize); wchar_t *keypath = get_full_keyvalue_pathA(hKey, lpValueName, keybuf, allocsize); - LOQ_zero("registry", "psru", "Handle", (DWORD)hKey, "ValueName", lpValueName, + LOQ_zero("registry", "psru", "Handle", hKey, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData, "FullName", keypath); @@ -330,13 +499,13 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExA, free(keybuf); } else if (ret == ERROR_MORE_DATA) { - LOQ_zero("registry", "psPIv", "Handle", (DWORD)hKey, "ValueName", lpValueName, + LOQ_zero("registry", "psPIv", "Handle", hKey, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { - LOQ_zero("registry", "psv", "Handle", (DWORD)hKey, "ValueName", lpValueName, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "psv", "Handle", hKey, "ValueName", lpValueName, + "FullName", hKey, lpValueName); } return ret; } @@ -359,7 +528,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExW, PKEY_NAME_INFORMATION keybuf = malloc(allocsize); wchar_t *keypath = get_full_keyvalue_pathW(hKey, lpValueName, keybuf, allocsize); - LOQ_zero("registry", "puRu", "Handle", (DWORD)hKey, "ValueName", lpValueName, + LOQ_zero("registry", "puRu", "Handle", hKey, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData, "FullName", keypath); @@ -369,13 +538,13 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExW, free(keybuf); } else if (ret == ERROR_MORE_DATA) { - LOQ_zero("registry", "puPIV", "Handle", (DWORD)hKey, "ValueName", lpValueName, + LOQ_zero("registry", "puPIV", "Handle", hKey, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData, - "FullName", (DWORD)hKey, lpValueName); + "FullName", hKey, lpValueName); } else { - LOQ_zero("registry", "puV", "Handle", (DWORD)hKey, "ValueName", lpValueName, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "puV", "Handle", hKey, "ValueName", lpValueName, + "FullName", hKey, lpValueName); } return ret; } @@ -385,8 +554,8 @@ HOOKDEF(LONG, WINAPI, RegDeleteValueA, __in_opt LPCTSTR lpValueName ) { LONG ret = Old_RegDeleteValueA(hKey, lpValueName); - LOQ_zero("registry", "psv", "Handle", (DWORD)hKey, "ValueName", lpValueName, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "psv", "Handle", hKey, "ValueName", lpValueName, + "FullName", hKey, lpValueName); return ret; } @@ -395,8 +564,8 @@ HOOKDEF(LONG, WINAPI, RegDeleteValueW, __in_opt LPWSTR lpValueName ) { LONG ret = Old_RegDeleteValueW(hKey, lpValueName); - LOQ_zero("registry", "puV", "Handle", (DWORD)hKey, "ValueName", lpValueName, - "FullName", (DWORD)hKey, lpValueName); + LOQ_zero("registry", "puV", "Handle", hKey, "ValueName", lpValueName, + "FullName", hKey, lpValueName); return ret; } @@ -418,7 +587,7 @@ HOOKDEF(LONG, WINAPI, RegQueryInfoKeyA, lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor, lpftLastWriteTime); - LOQ_zero("registry", "pS6I", "KeyHandle", (DWORD)hKey, "Class", lpcClass ? *lpcClass : 0, lpClass, + LOQ_zero("registry", "pS6I", "KeyHandle", hKey, "Class", lpcClass ? *lpcClass : 0, lpClass, "SubKeyCount", lpcSubKeys, "MaxSubKeyLength", lpcMaxSubKeyLen, "MaxClassLength", lpcMaxClassLen, "ValueCount", lpcValues, "MaxValueNameLength", lpcMaxValueNameLen, @@ -444,7 +613,7 @@ HOOKDEF(LONG, WINAPI, RegQueryInfoKeyW, lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor, lpftLastWriteTime); - LOQ_zero("registry", "pU6I", "KeyHandle", (DWORD)hKey, "Class", lpcClass ? *lpcClass : 0, lpClass, + LOQ_zero("registry", "pU6I", "KeyHandle", hKey, "Class", lpcClass ? *lpcClass : 0, lpClass, "SubKeyCount", lpcSubKeys, "MaxSubKeyLength", lpcMaxSubKeyLen, "MaxClassLength", lpcMaxClassLen, "ValueCount", lpcValues, "MaxValueNameLength", lpcMaxValueNameLen, @@ -453,11 +622,11 @@ HOOKDEF(LONG, WINAPI, RegQueryInfoKeyW, } HOOKDEF(LONG, WINAPI, RegCloseKey, - __in HKEY hKey -) { - LONG ret = Old_RegCloseKey(hKey); - LOQ_zero("registry", "p", "Handle", hKey); - return ret; + __in HKEY hKey + ) { + LONG ret = Old_RegCloseKey(hKey); + LOQ_zero("registry", "p", "Handle", hKey); + return ret; } HOOKDEF(LONG, WINAPI, RegNotifyChangeKeyValue, @@ -470,12 +639,12 @@ HOOKDEF(LONG, WINAPI, RegNotifyChangeKeyValue, LONG ret = 0; if (!fAsynchronous) - LOQ_zero("registry", "Ehii", "FullName", (DWORD)hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous); + LOQ_zero("registry", "Ehii", "FullName", hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous); ret = Old_RegNotifyChangeKeyValue(hKey, bWatchSubtree, dwNotifyFilter, hEvent, fAsynchronous); if (fAsynchronous) - LOQ_zero("registry", "Ehii", "FullName", (DWORD)hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous); + LOQ_zero("registry", "Ehii", "FullName", hKey, NULL, "NotifyFilter", dwNotifyFilter, "WatchSubtree", bWatchSubtree, "Asynchronous", fAsynchronous); return ret; -} \ No newline at end of file +} diff --git a/hook_sleep.c b/hook_sleep.c index 660ef8e..b7a4ad8 100644 --- a/hook_sleep.c +++ b/hook_sleep.c @@ -460,9 +460,9 @@ HOOKDEF(void, WINAPI, GetLocalTime, ft.dwLowDateTime = li.LowPart; FileTimeToSystemTime(&ft, lpSystemTime); - set_lasterrors(&lasterror); - LOQ_void("system", ""); + + set_lasterrors(&lasterror); } HOOKDEF(void, WINAPI, GetSystemTime, @@ -484,9 +484,9 @@ HOOKDEF(void, WINAPI, GetSystemTime, ft.dwLowDateTime = li.LowPart; FileTimeToSystemTime(&ft, lpSystemTime); - set_lasterrors(&lasterror); - LOQ_void("system", ""); + + set_lasterrors(&lasterror); } DWORD raw_gettickcount(void) @@ -587,6 +587,20 @@ HOOKDEF(void, WINAPI, GetSystemTimeAsFileTime, return; } +HOOKDEF(BOOL, WINAPI, CreateTimerQueueTimer, + _Out_ PHANDLE phNewTimer, + _In_opt_ HANDLE TimerQueue, + _In_ WAITORTIMERCALLBACK Callback, + _In_opt_ PVOID Parameter, + _In_ DWORD DueTime, + _In_ DWORD Period, + _In_ ULONG Flags +) { + BOOL ret = Old_CreateTimerQueueTimer(phNewTimer, TimerQueue, Callback, Parameter, DueTime, Period, Flags); + LOQ_bool("system", "Pphhiii", "phNewTimer", phNewTimer, "TimerQueue", TimerQueue, "Callback", Callback, "Parameter", Parameter, "DueTime", DueTime, "Period", Period, "Flags", Flags); + return ret; +} + static int lastinput_called; HOOKDEF(BOOL, WINAPI, GetLastInputInfo, diff --git a/hook_socket.c b/hook_socket.c index bd3f170..a27ea9f 100644 --- a/hook_socket.c +++ b/hook_socket.c @@ -48,24 +48,30 @@ static PVOID alloc_combined_wsabuf(LPWSABUF buf, DWORD count, DWORD *outlen) return retbuf; } -static void get_ip_port(const struct sockaddr *addr, +static BOOLEAN get_ip_port(const struct sockaddr *addr, char *ip, int *port) { lasterror_t lasterror; + BOOLEAN ret = TRUE; if (addr == NULL) - return; + return FALSE; get_lasterrors(&lasterror); - // TODO IPv6 support. - if(addr->sa_family == AF_INET) { - const struct sockaddr_in *addr4 = (const struct sockaddr_in *) addr; - addr_to_string(addr4->sin_addr, ip); - *port = our_htons(addr4->sin_port); - } - + __try { + // TODO IPv6 support. + if (addr->sa_family == AF_INET) { + const struct sockaddr_in *addr4 = (const struct sockaddr_in *) addr; + addr_to_string(addr4->sin_addr, ip); + *port = our_htons(addr4->sin_port); + } + } + __except (EXCEPTION_EXECUTE_HANDLER) { + ret = FALSE; + } set_lasterrors(&lasterror); + return ret; } HOOKDEF(int, WINAPI, WSAStartup, diff --git a/hook_special.c b/hook_special.c index c313a94..9909555 100644 --- a/hook_special.c +++ b/hook_special.c @@ -201,7 +201,7 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, disable_sleep_skip(); } - if (!called_by_hook()) { +// if (!called_by_hook()) { if (dwCreationFlags & EXTENDED_STARTUPINFO_PRESENT && lpStartupInfo->cb == sizeof(STARTUPINFOEXW)) { HANDLE ParentHandle = (HANDLE)-1; unsigned int i; @@ -227,7 +227,7 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, "ProcessHandle", lpProcessInformation->hProcess, "ThreadHandle", lpProcessInformation->hThread, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); } - } +// } return ret; } @@ -274,7 +274,7 @@ HOOKDEF(HRESULT, WINAPI, CoCreateInstance, if (!strcmp(idbuf1, "0F87369F-A4E5-4CFC-BD3E-73E6154572DD") || !strcmp(idbuf1, "0F87369F-A4E5-4CFC-BD3E-5529CE8784B0")) pipe("TASKSCHED:"); if (!strcmp(idbuf1, "000209FF-0000-0000-C000-000000000046") || !strcmp(idbuf1, "00024500-0000-0000-C000-000000000046") || !strcmp(idbuf1, "91493441-5A91-11CF-8700-00AA0060263B") || - !strcmp(idbuf1, "000246FF-0000-0000-C000-000000000046")) + !strcmp(idbuf1, "000246FF-0000-0000-C000-000000000046") || !strcmp(idbuf1, "0002CE02-0000-0000-C000-000000000046")) pipe("INTEROP:"); set_lasterrors(&lasterror); diff --git a/hook_sync.c b/hook_sync.c index 762a3b1..640e6ac 100644 --- a/hook_sync.c +++ b/hook_sync.c @@ -144,3 +144,27 @@ HOOKDEF(NTSTATUS, WINAPI, NtAddAtomEx, LOQ_ntstatus("synchronization", "uh", "AtomName", AtomName, "Atom", *Atom); return ret; } + +HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationAtom, + IN RTL_ATOM Atom, + IN ATOM_INFORMATION_CLASS AtomInformationClass, + OUT PVOID AtomInformation, + IN ULONG AtomInformationLength, + OUT PULONG ReturnLength OPTIONAL +) { + WCHAR* AtomName; + ULONG AtomNameLength; + + NTSTATUS ret = Old_NtQueryInformationAtom(Atom, AtomInformationClass, AtomInformation, AtomInformationLength, ReturnLength); + + if (NT_SUCCESS(ret) && AtomInformationClass == AtomBasicInformation) + { + AtomNameLength = (ULONG)((PATOM_BASIC_INFORMATION)AtomInformation)->NameLength; + AtomName = ((PATOM_BASIC_INFORMATION)AtomInformation)->Name; + LOQ_ntstatus("synchronization", "bih", "AtomName", AtomNameLength, AtomName, "Size", AtomNameLength, "Atom", Atom); + } + else + LOQ_ntstatus("synchronization", "h", "Atom", Atom); + + return ret; +} diff --git a/hook_window.c b/hook_window.c index 2a0644c..fac3ca5 100644 --- a/hook_window.c +++ b/hook_window.c @@ -22,10 +22,6 @@ along with this program. If not, see . #include "misc.h" #include "pipe.h" #include "log.h" -#include "CAPE\CAPE.h" - -extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); typedef DWORD (WINAPI * __GetWindowThreadProcessId)( __in HWND hWnd, @@ -151,7 +147,6 @@ HOOKDEF(BOOL, WINAPI, PostMessageA, _In_ LPARAM lParam ) { BOOL ret; - /* DWORD pid; lasterror_t lasterror; @@ -160,7 +155,6 @@ HOOKDEF(BOOL, WINAPI, PostMessageA, if (pid != GetCurrentProcessId()) pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); set_lasterrors(&lasterror); - */ ret = Old_PostMessageA(hWnd, Msg, wParam, lParam); LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); @@ -175,7 +169,6 @@ HOOKDEF(BOOL, WINAPI, PostMessageW, _In_ LPARAM lParam ) { BOOL ret; - /* DWORD pid; lasterror_t lasterror; @@ -184,7 +177,6 @@ HOOKDEF(BOOL, WINAPI, PostMessageW, if (pid != GetCurrentProcessId()) pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); set_lasterrors(&lasterror); - */ ret = Old_PostMessageW(hWnd, Msg, wParam, lParam); LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); @@ -192,6 +184,50 @@ HOOKDEF(BOOL, WINAPI, PostMessageW, return ret; } +HOOKDEF(BOOL, WINAPI, SendMessageA, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +) { + BOOL ret; + DWORD pid; + lasterror_t lasterror; + + get_lasterrors(&lasterror); + GetWindowThreadProcessId(hWnd, &pid); + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + set_lasterrors(&lasterror); + ret = Old_SendMessageA(hWnd, Msg, wParam, lParam); + + LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); + + return ret; +} + +HOOKDEF(BOOL, WINAPI, SendMessageW, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam + ) { + BOOL ret; + DWORD pid; + lasterror_t lasterror; + + get_lasterrors(&lasterror); + GetWindowThreadProcessId(hWnd, &pid); + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + set_lasterrors(&lasterror); + ret = Old_SendMessageW(hWnd, Msg, wParam, lParam); + + LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); + + return ret; +} + HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, _In_ HWND hWnd, _In_ UINT Msg, @@ -199,7 +235,6 @@ HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, _In_ LPARAM lParam ) { BOOL ret; - /* DWORD pid; lasterror_t lasterror; @@ -208,7 +243,6 @@ HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, if (pid != GetCurrentProcessId()) pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); set_lasterrors(&lasterror); - */ ret = Old_SendNotifyMessageA(hWnd, Msg, wParam, lParam); LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); @@ -221,9 +255,8 @@ HOOKDEF(BOOL, WINAPI, SendNotifyMessageW, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam -) { + ) { BOOL ret; - /* DWORD pid; lasterror_t lasterror; @@ -232,7 +265,6 @@ HOOKDEF(BOOL, WINAPI, SendNotifyMessageW, if (pid != GetCurrentProcessId()) pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); set_lasterrors(&lasterror); - */ ret = Old_SendNotifyMessageW(hWnd, Msg, wParam, lParam); LOQ_bool("windows", "ph", "WindowHandle", hWnd, "Message", Msg); @@ -258,7 +290,6 @@ HOOKDEF(LONG, WINAPI, SetWindowLongA, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; - DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -289,7 +320,6 @@ HOOKDEF(LONG_PTR, WINAPI, SetWindowLongPtrA, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; - DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -320,7 +350,6 @@ HOOKDEF(LONG, WINAPI, SetWindowLongW, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; - DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); @@ -352,7 +381,6 @@ HOOKDEF(LONG_PTR, WINAPI, SetWindowLongPtrW, if (!stricmp(classname, "Shell_TrayWnd") && nIndex == 0) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); isbad = TRUE; - DumpSectionViewsForPid(pid); } } set_lasterrors(&lasterror); diff --git a/hooking.c b/hooking.c index b1bb846..f97aaba 100644 --- a/hooking.c +++ b/hooking.c @@ -174,7 +174,11 @@ hook_info_t *hook_info() void get_lasterrors(lasterror_t *errors) { - char *teb = (char *)NtCurrentTeb(); + char *teb; + + errors->Eflags = (DWORD)__readeflags(); + + teb = (char *)NtCurrentTeb(); errors->Win32Error = *(DWORD *)(teb + TLS_LAST_WIN32_ERROR); errors->NtstatusError = *(DWORD *)(teb + TLS_LAST_NTSTATUS_ERROR); @@ -187,6 +191,8 @@ void set_lasterrors(lasterror_t *errors) *(DWORD *)(teb + TLS_LAST_WIN32_ERROR) = errors->Win32Error; *(DWORD *)(teb + TLS_LAST_NTSTATUS_ERROR) = errors->NtstatusError; + + __writeeflags(errors->Eflags); } void hook_enable() diff --git a/hooking.h b/hooking.h index 40d6a37..e4ae038 100644 --- a/hooking.h +++ b/hooking.h @@ -128,6 +128,7 @@ typedef struct _hook_info_t { typedef struct _lasterror_t { DWORD Win32Error; DWORD NtstatusError; + DWORD Eflags; } lasterror_t; int lde(void *addr); diff --git a/hooks.h b/hooks.h index 0f667ff..6ad37c9 100644 --- a/hooks.h +++ b/hooks.h @@ -213,6 +213,32 @@ extern HOOKDEF(BOOL, WINAPI, RemoveDirectoryW, __in LPWSTR lpPathName ); +extern HOOKDEF(HANDLE, WINAPI, CreateFileTransactedA, + __in LPCSTR lpFileName, + __in DWORD dwDesiredAccess, + __in DWORD dwShareMode, + __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, + __in DWORD dwCreationDisposition, + __in DWORD dwFlagsAndAttributes, + __in_opt HANDLE hTemplateFile, + __in HANDLE hTransaction, + __in_opt PUSHORT pusMiniVersion, + __reserved PVOID pExtendedParameter +); + +extern HOOKDEF(HANDLE, WINAPI, CreateFileTransactedW, + __in LPCWSTR lpFileName, + __in DWORD dwDesiredAccess, + __in DWORD dwShareMode, + __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, + __in DWORD dwCreationDisposition, + __in DWORD dwFlagsAndAttributes, + __in_opt HANDLE hTemplateFile, + __in HANDLE hTransaction, + __in_opt PUSHORT pusMiniVersion, + __reserved PVOID pExtendedParameter +); + extern HOOKDEF(HANDLE, WINAPI, FindFirstFileExA, __in LPCTSTR lpFileName, __in FINDEX_INFO_LEVELS fInfoLevelId, @@ -784,6 +810,20 @@ extern HOOKDEF(BOOL, WINAPI, PostMessageW, _In_ LPARAM lParam ); +extern HOOKDEF(BOOL, WINAPI, SendMessageA, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +); + +extern HOOKDEF(BOOL, WINAPI, SendMessageW, + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +); + extern HOOKDEF(BOOL, WINAPI, SendNotifyMessageA, _In_ HWND hWnd, _In_ UINT Msg, @@ -894,6 +934,14 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtAddAtomEx, IN PVOID Unknown ); +extern HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationAtom, + IN RTL_ATOM Atom, + IN ATOM_INFORMATION_CLASS AtomInformationClass, + OUT PVOID AtomInformation, + IN ULONG AtomInformationLength, + OUT PULONG ReturnLength OPTIONAL +); + // // Process Hooks // @@ -1594,16 +1642,6 @@ extern HOOKDEF(void, WINAPIV, memcpy, size_t count ); -extern HOOKDEF(HANDLE, WINAPI, GetProcessHeap, - void -); - -extern HOOKDEF(LPVOID, WINAPI, HeapAlloc, - _In_ HANDLE hHeap, - _In_ DWORD dwFlags, - _In_ SIZE_T dwBytes -); - extern HOOKDEF(HDEVINFO, WINAPI, SetupDiGetClassDevsA, _In_opt_ const GUID *ClassGuid, _In_opt_ PCSTR Enumerator, @@ -2290,6 +2328,16 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtQueryPerformanceCounter, _Out_opt_ PLARGE_INTEGER PerformanceFrequency ); +extern HOOKDEF(BOOL, WINAPI, CreateTimerQueueTimer, + _Out_ PHANDLE phNewTimer, + _In_opt_ HANDLE TimerQueue, + _In_ WAITORTIMERCALLBACK Callback, + _In_opt_ PVOID Parameter, + _In_ DWORD DueTime, + _In_ DWORD Period, + _In_ ULONG Flags +); + // // Socket Hooks // @@ -2808,6 +2856,11 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtQuerySystemInformation, _Out_opt_ PULONG ReturnLength ); +extern HOOKDEF(unsigned int, WINAPIV, SizeofResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +); + extern HOOKDEF(void, WINAPIV, srand, unsigned int seed ); diff --git a/ntapi.h b/ntapi.h index ba9dc3d..cf573ca 100644 --- a/ntapi.h +++ b/ntapi.h @@ -480,8 +480,8 @@ typedef struct _PEB { BOOLEAN ReadImageFileExecOptions; BOOLEAN BeingDebugged; BOOLEAN Spare; - BYTE Reserved2[12]; - PVOID ImageBaseAddress; + HANDLE Mutant; + PVOID ImageBaseAddress; PPEB_LDR_DATA LoaderData; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; BYTE Reserved3[520]; @@ -496,7 +496,7 @@ typedef struct _PEB { BOOLEAN BeingDebugged; BOOLEAN Spare; HANDLE Mutant; - PVOID ImageBaseAddress; + PVOID ImageBaseAddress; PPEB_LDR_DATA LoaderData; PRTL_USER_PROCESS_PARAMETERS ProcessParameters; PVOID SubSystemData; @@ -666,6 +666,23 @@ static inline void __writefsdword(unsigned int index, unsigned int value) typedef unsigned short RTL_ATOM, *PRTL_ATOM; +typedef enum _ATOM_INFORMATION_CLASS { + AtomBasicInformation, + AtomTableInformation +} ATOM_INFORMATION_CLASS; + +typedef struct _ATOM_BASIC_INFORMATION { + USHORT UsageCount; + USHORT Flags; + USHORT NameLength; + WCHAR Name[ 1 ]; +} ATOM_BASIC_INFORMATION, *PATOM_BASIC_INFORMATION; + +typedef struct _ATOM_TABLE_INFORMATION { + ULONG NumberOfAtoms; + RTL_ATOM Atoms[ 1 ]; +} ATOM_TABLE_INFORMATION, *PATOM_TABLE_INFORMATION; + typedef struct _SECTION_IMAGE_INFORMATION { VOID* TransferAddress; uint32_t ZeroBits; From 3ce5bf1a602ed67c69f75b980a831d53828df644 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Mar 2018 11:45:01 +0000 Subject: [PATCH 24/39] Improve handling of malformed PE images. --- CAPE/Scylla/PeParser.cpp | 116 +++++++++++++++++++++++++++------------ CAPE/Scylla/PeParser.h | 4 +- CAPE/ScyllaHarness.cpp | 4 +- 3 files changed, 84 insertions(+), 40 deletions(-) diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 1a1e6d0..9820ddb 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -6,6 +6,7 @@ #pragma comment(lib, "Imagehlp.lib") //#define DEBUG_COMMENTS +#define SIZE_LIMIT 0x1000000 extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); @@ -275,7 +276,6 @@ bool PeParser::readPeHeaderFromFile(bool readSectionHeaders) } } - delete [] headerMemory; headerMemory = new BYTE[readSize]; @@ -323,19 +323,27 @@ bool PeParser::readPeSectionsFromProcess() { if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > (listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress)) { - listPeSection[i].normalSize = alignValue(listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); + listPeSection[i].normalSize = alignValue(listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for section %d from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].normalSize); -#endif - +#endif } else { listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for section %d ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for section %d ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); #endif } + + if ((listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + { + DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); +#endif + listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + } } else { @@ -344,17 +352,32 @@ bool PeParser::readPeSectionsFromProcess() listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].normalSize); -#endif +#endif } else { listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); -#endif +#endif + } + + if ((listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + { + DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); +#endif + listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; } } + if (listPeSection[i].sectionHeader.Misc.VirtualSize > SIZE_LIMIT) + { + DoOutputDebugString("PeParser: Section %d size too big: 0x%x\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); + return false; + } + if (!readSectionFromProcess(readOffset, listPeSection[i])) { #ifdef DEBUG_COMMENTS @@ -377,7 +400,6 @@ bool PeParser::readPeSectionsFromFile() listPeSection.reserve(getNumberOfSections()); - if (openFileHandle()) { for (WORD i = 0; i < getNumberOfSections(); i++) @@ -744,7 +766,7 @@ DWORD PeParser::isMemoryNotNull( BYTE * data, int dataSize ) bool PeParser::savePeFileToDisk(const CHAR *newFile) { - bool retValue = true; + bool retValue = true, SectionDataWritten = false; char *CapeName; #ifdef DEBUG_COMMENTS @@ -842,6 +864,8 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) } dwFileOffset += dwWriteSize; + SectionDataWritten = true; + if (listPeSection[i].dataSize < listPeSection[i].sectionHeader.SizeOfRawData) //padding { dwWriteSize = listPeSection[i].sectionHeader.SizeOfRawData - listPeSection[i].dataSize; @@ -871,9 +895,14 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) SetEndOfFile(hFile); dumpSize = dwFileOffset; - if (newFile) - closeFileHandle(); - else + closeFileHandle(); + + // If only headers are written, fail + // (this will allow a subsequent 'raw' memory dump) + if (!SectionDataWritten) + return false; + + if (!newFile) { closeFileHandle(); @@ -896,7 +925,6 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) } CapeOutputFile(CapeOutputPath); - return 1; } else if (GetLastError() == ERROR_ALREADY_EXISTS) // have seen this occasionally { @@ -915,7 +943,6 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) } CapeOutputFile(CapeOutputPath); - return 1; } else { @@ -1005,7 +1032,6 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) } CapeOutputFile(CapeOutputPath); - return 1; } else { @@ -1350,7 +1376,16 @@ void PeParser::alignAllSectionHeaders() listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::alignAllSectionHeaders: VirtualSize for section %d ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); -#endif +#endif + } + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + { + DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); +#endif + listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; } } else @@ -1360,15 +1395,30 @@ void PeParser::alignAllSectionHeaders() listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].sectionHeader.Misc.VirtualSize); -#endif +#endif } else { listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::alignAllSectionHeaders: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); -#endif +#endif } + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + { + DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); +#endif + listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + } + } + + if (listPeSection[i].sectionHeader.Misc.VirtualSize > SIZE_LIMIT) + { + DoOutputDebugString("PeParser::alignAllSectionHeaders: Section %d size too big: 0x%x\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); + //return; } } @@ -1380,32 +1430,28 @@ bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * moduleBaseAddress = modBase; #ifdef DEBUG_COMMENTS - DoOutputDebugString("dumpProcess DEBUG: entry: modBase = 0x%x.\n", modBase); + DoOutputDebugString("DumpProcess: called with modBase = 0x%x.\n", modBase); #endif - if (readPeSectionsFromProcess()) - { + if (!readPeSectionsFromProcess()) + DoOutputDebugString("DumpProcess: There was a problem reading one or more sections, the dump may be incomplete.\n"); #ifdef DEBUG_COMMENTS - DoOutputDebugString("dumpProcess DEBUG: readPeSectionsFromProcess success.\n"); + else + DoOutputDebugString("DumpProcess: Successfully read all sections.\n"); #endif - - setDefaultFileAlignment(); + setDefaultFileAlignment(); - if (entryPoint) - setEntryPointVa(entryPoint); + if (entryPoint) + setEntryPointVa(entryPoint); - alignAllSectionHeaders(); - fixPeHeader(); + alignAllSectionHeaders(); + fixPeHeader(); - getFileOverlay(); + getFileOverlay(); #ifdef DEBUG_COMMENTS - DoOutputDebugString("dumpProcess DEBUG: Fixups complete, about to save to disk.\n"); + DoOutputDebugString("dumpProcess DEBUG: Fixups complete, about to save to disk.\n"); #endif - - return savePeFileToDisk(dumpFilePath); - } - - return false; + return savePeFileToDisk(dumpFilePath); } bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * dumpFilePath, std::vector & sectionList) diff --git a/CAPE/Scylla/PeParser.h b/CAPE/Scylla/PeParser.h index 672d1f7..3bb2063 100644 --- a/CAPE/Scylla/PeParser.h +++ b/CAPE/Scylla/PeParser.h @@ -94,7 +94,7 @@ class PeParser std::vector listPeSection; DWORD dumpSize; - + protected: PeParser(); @@ -162,6 +162,4 @@ class PeParser void removeIatDirectory(); bool getFileOverlay(); - }; - diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index ee475f8..6eb7205 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -115,7 +115,7 @@ extern "C" int ScyllaDumpCurrentProcess(DWORD_PTR NewOEP) } else { - DoOutputErrorString("DumpCurrentProcess: Error - Cannot dump image"); + DoOutputDebugString("DumpCurrentProcess: Error - Cannot dump image.\n"); delete peFile; return 0; } @@ -184,7 +184,7 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PT } else { - DoOutputErrorString("DumpProcess: Error - Cannot dump image"); + DoOutputDebugString("DumpProcess: Error - Cannot dump image.\n"); delete peFile; return 0; } From 67414a13596cea158d3be0e7ae17edd0ccbc9500 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Mar 2018 14:11:09 +0000 Subject: [PATCH 25/39] Further tweak to handling of malformed PE images. --- CAPE/Scylla/PeParser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 9820ddb..3ac5d76 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -805,7 +805,6 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) dwFileOffset += dwWriteSize; } - //Pe Header if (isPE32()) { @@ -855,8 +854,11 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) dwWriteSize = listPeSection[i].dataSize; - if (dwWriteSize) + if (dwWriteSize >= pNTHeader32->OptionalHeader.FileAlignment) { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::savePeFileToDisk: Writing section %d of size 0x%x bytes.\n", i+1, dwWriteSize); +#endif if (!ProcessAccessHelp::writeMemoryToFile(hFile, listPeSection[i].sectionHeader.PointerToRawData, dwWriteSize, listPeSection[i].data)) { retValue = false; @@ -984,7 +986,8 @@ bool PeParser::saveCompletePeToDisk( const CHAR * newFile ) return false; } - if (!listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData || !listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData) + if (listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData < pNTHeader32->OptionalHeader.FileAlignment + || listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData < pNTHeader32->OptionalHeader.FileAlignment) { DoOutputDebugString("PE Parser: Error - image seems incomplete: (%d sections, PointerToRawData: 0x%x, SizeOfRawData: 0x%x) - dump failed.\n", getNumberOfSections(), listPeSection[getNumberOfSections()-1].sectionHeader.PointerToRawData, listPeSection[getNumberOfSections()-1].sectionHeader.SizeOfRawData); return false; From 70c5f8e4406d1e2f1c7c4103487fa0c2097a92ac Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Mar 2018 11:43:22 +0000 Subject: [PATCH 26/39] Fix bugs in dumper code inadvertently introduced yesterday. --- CAPE/CAPE.c | 130 ++++++++++++++++++++++----------------- CAPE/CAPE.h | 3 +- CAPE/Scylla/PeParser.cpp | 61 +++++++++++------- hook_process.c | 6 +- 4 files changed, 118 insertions(+), 82 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index c52a687..e38314e 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -18,6 +18,7 @@ along with this program.If not, see . #define _CRT_RAND_S #include #include +#include #include #include #include @@ -660,7 +661,7 @@ void DumpSectionViewsForPid(DWORD Pid) PEPointer = CurrentSectionView->LocalView; - while (ScanForPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) + while (ScanForDisguisedPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) { DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); @@ -709,66 +710,49 @@ void DumpSectionViewsForPid(DWORD Pid) } //************************************************************************************** -void DumpSectionViewForPid(PINJECTIONSECTIONVIEW SectionView, DWORD Pid) +void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) //************************************************************************************** { - struct InjectionInfo *CurrentInjectionInfo; DWORD BufferSize = MAX_PATH; LPVOID PEPointer = NULL; BOOL Dumped = FALSE; - CurrentInjectionInfo = GetInjectionInfo(Pid); - - if (CurrentInjectionInfo == NULL) + if (!SectionView->LocalView) { - DoOutputDebugString("DumpSectionViewForPid: No injection info for pid %d.\n", Pid); + DoOutputDebugString("DumpSectionView: Section view local view address not set.\n"); return; } - if (SectionView->TargetProcessId == Pid && SectionView->LocalView) + if (!SectionView->TargetProcessId) { - PEPointer = SectionView->LocalView; + DoOutputDebugString("DumpSectionView: Section view has no target process - error.\n"); + return; + } + + Dumped = DumpPEsInRange(SectionView->LocalView, SectionView->ViewSize); + + if (Dumped) + DoOutputDebugString("DumpSectionView: Dumped PE image from shared section view, local address 0x%p.\n", SectionView->LocalView); + else + { + DoOutputDebugString("DumpSectionView: no PE file found in shared section view, attempting raw dump.\n"); - while (ScanForPE(PEPointer, SectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)SectionView->LocalView), &PEPointer)) - { - DoOutputDebugString("DumpSectionViewForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); - - CapeMetaData->DumpType = INJECTION_PE; - CapeMetaData->TargetPid = Pid; - CapeMetaData->Address = PEPointer; - - if (DumpImageInCurrentProcess(PEPointer)) - { - DoOutputDebugString("DumpSectionViewForPid: Dumped PE image from shared section view.\n"); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewForPid: Failed to dump PE image from shared section view.\n"); - - ((BYTE*)PEPointer)++; - } + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = SectionView->TargetProcessId; - if (Dumped == FALSE) + if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) { - DoOutputDebugString("DumpSectionViewForPid: no PE file found in shared section view, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = Pid; - - if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) - { - DoOutputDebugString("DumpSectionViewForPid: Dumped shared section view."); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewForPid: Failed to dump shared section view."); + DoOutputDebugString("DumpSectionView: Dumped shared section view."); + Dumped = TRUE; } - - if (Dumped == TRUE) - DropSectionView(SectionView); + else + DoOutputDebugString("DumpSectionView: Failed to dump shared section view."); } + if (Dumped == TRUE) + DropSectionView(SectionView); + return; } @@ -924,7 +908,7 @@ char* GetHashFromHandle(HANDLE hFile) { e_lfanew = *(long*)(Buffer+0x3c); - if ((unsigned int)e_lfanew>PE_HEADER_LIMIT) + if ((unsigned int)e_lfanew > PE_HEADER_LIMIT) { // This check is possibly not appropriate here // As long as we've got what's been compressed @@ -1197,13 +1181,13 @@ int IsDisguisedPEHeader(LPVOID Buffer) //************************************************************************************** { PIMAGE_DOS_HEADER pDosHeader; - PIMAGE_NT_HEADERS pNtHeader; + PIMAGE_NT_HEADERS pNtHeader = NULL; __try { pDosHeader = (PIMAGE_DOS_HEADER)Buffer; - if (!pDosHeader->e_lfanew || (ULONG)pDosHeader->e_lfanew > PE_HEADER_LIMIT || ((ULONG)pDosHeader->e_lfanew & 3) != 0) + if ((ULONG)pDosHeader->e_lfanew > PE_HEADER_LIMIT || ((ULONG)pDosHeader->e_lfanew & 3) != 0) { //DoOutputDebugString("IsDisguisedPEHeader: e_lfanew bad. (0x%x)", (DWORD_PTR)Buffer); return 0; @@ -1211,7 +1195,22 @@ int IsDisguisedPEHeader(LPVOID Buffer) //else // DoOutputDebugString("IsDisguisedPEHeader: e_lfanew ok!: 0x%x (0x%x)", (ULONG)pDosHeader->e_lfanew, (DWORD_PTR)Buffer); - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' has been zeroed + WORD* MachineProbe = (WORD*)&pDosHeader->e_lfanew; + while ((PCHAR)MachineProbe < (PCHAR)&pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + pNtHeader = (PIMAGE_NT_HEADERS)(&(PCHAR)MachineProbe - 4); + MachineProbe += sizeof(WORD); + } + + if (!pNtHeader) + return 0; + } + else + pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) { @@ -1284,7 +1283,7 @@ int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) return 0; } - for (p=0; p < Size - 0x41; p++) // we want to stop short of the look-ahead to e_lfanew + for (p=0; p < Size - PE_HEADER_LIMIT; p++) // we want to stop short of the max look-ahead in IsDisguisedPEHeader { RetVal = IsDisguisedPEHeader((BYTE*)Buffer+p); @@ -1322,7 +1321,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) DoOutputDebugString("DumpPEsInRange: Scanning range 0x%x - 0x%x.\n", Buffer, (BYTE*)Buffer + Size); - if (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) + while (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) { pDosHeader = (PIMAGE_DOS_HEADER)PEPointer; if (*(WORD*)PEPointer != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) @@ -1333,11 +1332,29 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) PEImage = (BYTE*)malloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); memcpy(PEImage, PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); pDosHeader = (PIMAGE_DOS_HEADER)PEImage; + + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' has been zeroed + PIMAGE_NT_HEADERS pNtHeader = NULL; + WORD* MachineProbe = (WORD*)&pDosHeader->e_lfanew; + while ((PCHAR)MachineProbe < (PCHAR)&pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + pNtHeader = (PIMAGE_NT_HEADERS)(&(PCHAR)MachineProbe - 4); + MachineProbe += sizeof(WORD); + } + + if (!pNtHeader) + return FALSE; + + pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + } *(WORD*)PEImage = IMAGE_DOS_SIGNATURE; *(DWORD*)(PEImage + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; - SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)PEPointer); if (DumpImageInCurrentProcess((LPVOID)PEImage)) { @@ -1346,10 +1363,13 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) } else DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); + + if (PEImage) + free(PEImage); } else { - SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)PEPointer); + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)PEPointer); if (DumpImageInCurrentProcess((LPVOID)PEPointer)) { @@ -1360,7 +1380,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); } - //((BYTE*)PEPointer)++; + (BYTE*)PEPointer += PE_HEADER_LIMIT; } return RetVal; @@ -1553,7 +1573,7 @@ int DumpCurrentProcess() int DumpModuleInCurrentProcess(LPVOID ModuleBase) //************************************************************************************** { - SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)ModuleBase); if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) { @@ -1653,7 +1673,7 @@ int DumpProcess(HANDLE hProcess, LPVOID ImageBase) int DumpPE(LPVOID Buffer) //************************************************************************************** { - SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)Buffer); + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)Buffer); if (DumpCount < DUMP_MAX && ScyllaDumpPE((DWORD_PTR)Buffer)) { diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 70d449d..7f2052f 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -56,7 +56,7 @@ PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); void DumpSectionViewsForPid(DWORD Pid); -void DumpSectionViewForPid(PINJECTIONSECTIONVIEW SectionView, DWORD Pid); +void DumpSectionView(PINJECTIONSECTIONVIEW SectionView); typedef struct InjectionInfo { @@ -110,7 +110,6 @@ struct InjectionSectionView *SectionViewList; #define DLL 2 #define PLUGX_SIGNATURE 0x5658 // 'XV' -#define PE_HEADER_LIMIT 0x200 // Range to look for PE header within candidate buffer typedef struct CapeMetadata { diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 3ac5d76..d1ac079 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -336,39 +336,47 @@ bool PeParser::readPeSectionsFromProcess() #endif } - if ((listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + if (i) { - DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; + DWORD EndOfPreviousSection = alignValue(listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize, sectionAlignment); + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != EndOfPreviousSection)) + { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, EndOfPreviousSection); #endif - listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + listPeSection[i].sectionHeader.VirtualAddress = EndOfPreviousSection; + } } } else { if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)) { - listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].normalSize); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)); #endif + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); } else { - listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); #endif } - if ((listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + if (i) { - DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; + DWORD EndOfPreviousSection = alignValue(listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize, sectionAlignment); + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != EndOfPreviousSection)) + { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); + DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, EndOfPreviousSection); #endif - listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + listPeSection[i].sectionHeader.VirtualAddress = EndOfPreviousSection; + } } } @@ -1367,11 +1375,12 @@ void PeParser::alignAllSectionHeaders() { if (i < NumberOfSections - 1) { + if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > (listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress)) { listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i+1].sectionHeader.VirtualAddress - listPeSection[i].sectionHeader.VirtualAddress, sectionAlignment); #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for section %d from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].sectionHeader.Misc.VirtualSize); + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)); #endif } else @@ -1382,23 +1391,27 @@ void PeParser::alignAllSectionHeaders() #endif } - if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + if (i) { - DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; + DWORD EndOfPreviousSection = alignValue(listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize, sectionAlignment); + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != EndOfPreviousSection)) + { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for section %d from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, EndOfPreviousSection); #endif - listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + listPeSection[i].sectionHeader.VirtualAddress = EndOfPreviousSection; + } } } else { if ((listPeSection[i].sectionHeader.Misc.VirtualSize) > alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)) { - listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, listPeSection[i].sectionHeader.Misc.VirtualSize); + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)); #endif + listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); } else { @@ -1408,13 +1421,17 @@ void PeParser::alignAllSectionHeaders() #endif } - if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != (listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize))) + if (i) { - DWORD NewVirtualAddress = listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize; + DWORD EndOfPreviousSection = alignValue(listPeSection[i-1].sectionHeader.VirtualAddress + listPeSection[i-1].sectionHeader.Misc.VirtualSize, sectionAlignment); + + if (listPeSection[i].sectionHeader.VirtualAddress && (listPeSection[i].sectionHeader.VirtualAddress != EndOfPreviousSection)) + { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, NewVirtualAddress); + DoOutputDebugString("PeParser::alignAllSectionHeaders: Correcting VirtualAddress for last section (%d) from: 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.VirtualAddress, EndOfPreviousSection); #endif - listPeSection[i].sectionHeader.VirtualAddress = NewVirtualAddress; + listPeSection[i].sectionHeader.VirtualAddress = EndOfPreviousSection; + } } } diff --git a/hook_process.c b/hook_process.c index 35be5a5..ad00b5a 100644 --- a/hook_process.c +++ b/hook_process.c @@ -308,7 +308,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); - if (NT_SUCCESS(ret)){// && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ + if (NT_SUCCESS(ret) && pid != GetCurrentProcessId()) {// && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ CurrentInjectionInfo = GetInjectionInfo(pid); if (CurrentInjectionInfo == NULL) @@ -513,10 +513,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, while (CurrentSectionView) { - if (CurrentSectionView->LocalView == BaseAddress) + if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) { DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); - DumpSectionViewForPid(CurrentSectionView, pid); + DumpSectionView(CurrentSectionView); } CurrentSectionView = CurrentSectionView->NextSectionView; From d953444c0c1a802a76db9ea46a87cd2a748c1dc7 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 Mar 2018 16:04:50 +0000 Subject: [PATCH 27/39] Merge updates from other branches. --- CAPE/CAPE.c | 317 ++++++++++++++++++++++++++------------- CAPE/CAPE.h | 1 + CAPE/Debugger.c | 15 +- CAPE/Debugger.h | 1 + CAPE/Scylla/PeParser.cpp | 114 +++++++++++--- CAPE/ScyllaHarness.cpp | 14 +- cuckoomon.c | 7 +- hook_file.c | 3 +- 8 files changed, 337 insertions(+), 135 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index e38314e..742a4a9 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -1,6 +1,6 @@ /* CAPE - Config And Payload Extraction -Copyright(C) 2015, 2016 Context Information Security. (kevin.oreilly@contextis.com) +Copyright(C) 2015 - 2018 Context Information Security. (kevin.oreilly@contextis.com) This program is free software : you can redistribute it and / or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,15 @@ You should have received a copy of the GNU General Public License along with this program.If not, see . */ #define _CRT_RAND_S +#define MD5LEN 16 + +#define MAX_PRETRAMP_SIZE 320 +#define MAX_TRAMP_SIZE 128 + +#define BUFSIZE 1024 // For hashing +#define DUMP_MAX 100 +#define CAPE_OUTPUT_FILE "CapeOutput.bin" + #include #include #include @@ -37,17 +46,65 @@ along with this program.If not, see . #pragma comment(lib, "Shlwapi.lib") -#define BUFSIZE 1024 // For hashing -#define MD5LEN 16 -#define DUMP_MAX 100 -#define CAPE_OUTPUT_FILE "CapeOutput.bin" +typedef union _UNWIND_CODE { + struct { + BYTE CodeOffset; + BYTE UnwindOp : 4; + BYTE OpInfo : 4; + }; + USHORT FrameOffset; +} UNWIND_CODE; + +typedef struct _UNWIND_INFO { + BYTE Version : 3; + BYTE Flags : 5; + BYTE SizeOfProlog; + BYTE CountOfCodes; + BYTE FrameRegister : 4; + BYTE FrameOffset : 4; + UNWIND_CODE UnwindCode[20]; +} UNWIND_INFO; + +typedef struct _hook_data_t { + unsigned char tramp[MAX_TRAMP_SIZE]; + unsigned char pre_tramp[MAX_PRETRAMP_SIZE]; + //unsigned char our_handler[128]; + unsigned char hook_data[32]; + + UNWIND_INFO unwind_info; +} hook_data_t; + +typedef struct _hook_t { + const wchar_t *library; + const char *funcname; + void *addr; + void *hook_addr; + void *new_func; + void **old_func; + void *alt_func; + int allow_hook_recursion; + int fully_emulate; + unsigned char numargs; + int notail; + int is_hooked; + hook_data_t *hookdata; +} hook_t; + +typedef struct _hook_info_t { + int disable_count; + hook_t *last_hook; + hook_t *current_hook; + ULONG_PTR return_address; + ULONG_PTR stack_pointer; + ULONG_PTR frame_pointer; + ULONG_PTR main_caller_retaddr; + ULONG_PTR parent_caller_retaddr; +} hook_info_t; static unsigned int DumpCount; extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buffer_len); -#define CAPE_OUTPUT_FILE "CapeOutput.bin" - extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern void CapeOutputFile(LPCTSTR lpOutputFile); @@ -57,9 +114,11 @@ extern int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR modBase, DWORD_PTR NewOE extern int ScyllaDumpCurrentProcessFixImports(DWORD_PTR NewOEP); extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD_PTR NewOEP); extern int ScyllaDumpPE(DWORD_PTR Buffer); +extern BOOL CountDepth(LPVOID* ReturnAddress, LPVOID Address); extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); extern unsigned int address_is_in_stack(PVOID Address); +extern hook_info_t *hook_info(); extern ULONG_PTR base_of_dll_of_interest; extern wchar_t *our_process_path; extern ULONG_PTR g_our_dll_base; @@ -86,34 +145,36 @@ BOOL InsideHook(LPVOID* ReturnAddress, LPVOID Address) } //************************************************************************************** -LPVOID GetReturnAddress(PCONTEXT ContextRecord) +BOOL GetCurrentFrame(LPVOID* ReturnAddress, LPVOID Address) +//************************************************************************************** +{ + *ReturnAddress = Address; + + return TRUE; +} + +//************************************************************************************** +LPVOID GetReturnAddress(hook_info_t *hookinfo) //************************************************************************************** { LPVOID ReturnAddress = NULL; - + __try { #ifdef _WIN64 - operate_on_backtrace(0, (ULONG_PTR)ContextRecord->Rip, &ReturnAddress, InsideHook); -#else - operate_on_backtrace(0, (ULONG_PTR)ContextRecord->Ebp, &ReturnAddress, InsideHook); -#endif - - if (!ReturnAddress) -#ifdef _WIN64 - ReturnAddress = *(LPVOID*)(ContextRecord->Rbp + sizeof(LPVOID)); + DoOutputDebugString("GetReturnAddress: operate_on_backtrace call with Rip 0x%p.\n", hookinfo->frame_pointer); #else - ReturnAddress = *(LPVOID*)(ContextRecord->Ebp + sizeof(LPVOID)); + DoOutputDebugString("GetReturnAddress: operate_on_backtrace call with Ebp 0x%x.\n", hookinfo->frame_pointer); #endif - + operate_on_backtrace(hookinfo->stack_pointer, hookinfo->frame_pointer, &ReturnAddress, GetCurrentFrame); return ReturnAddress; } __except(EXCEPTION_EXECUTE_HANDLER) { #ifdef _WIN64 - DoOutputDebugString("GetReturnAddress: Exception trying to get return address with Rip 0x%p and Rbp 0x%p.\n", ContextRecord->Rip, ContextRecord->Rbp); + DoOutputDebugString("GetReturnAddress: Exception trying to get return address with Rip 0x%p.\n", hookinfo->frame_pointer); #else - DoOutputDebugString("GetReturnAddress: Exception trying to get return address with base pointer 0x%x.\n", ContextRecord->Ebp); + DoOutputDebugString("GetReturnAddress: Exception trying to get return address with base pointer 0x%x.\n", hookinfo->frame_pointer); #endif return NULL; } @@ -123,27 +184,12 @@ LPVOID GetReturnAddress(PCONTEXT ContextRecord) void GetHookCallerBase() //************************************************************************************** { - CONTEXT ContextRecord; PVOID ReturnAddress, AllocationBase; if (CallingModule) return; -#ifdef _WIN64 - RtlCaptureContext(&ContextRecord); -#else - ZeroMemory(&ContextRecord, sizeof(CONTEXT)); - - __asm - { - Label: - mov eax, [Label]; - mov [ContextRecord.Eip], eax; - mov [ContextRecord.Ebp], ebp; - mov [ContextRecord.Esp], esp; - } -#endif - ReturnAddress = GetReturnAddress(&ContextRecord); + ReturnAddress = GetReturnAddress(hook_info()); if (ReturnAddress) { @@ -155,6 +201,7 @@ void GetHookCallerBase() if (AllocationBase) { CallingModule = AllocationBase; + // Base-dependent breakpoints can be activated now } } else @@ -504,14 +551,9 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) //************************************************************************************** { PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - - //TODO remove debug - DoOutputDebugString("GetSectionView: Global section view list 0x%x, looking for handle 0x%x\n", CurrentSectionView, SectionHandle); while (CurrentSectionView) { - //TODO remove debug - DoOutputDebugString("GetSectionView: looking at section handle 0x%x.\n", CurrentSectionView->SectionHandle); if (CurrentSectionView->SectionHandle == SectionHandle) { DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); @@ -1140,7 +1182,7 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) continue; } - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { @@ -1177,88 +1219,117 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) } //************************************************************************************** -int IsDisguisedPEHeader(LPVOID Buffer) +BOOL TestPERequirements(PIMAGE_NT_HEADERS pNtHeader) //************************************************************************************** { - PIMAGE_DOS_HEADER pDosHeader; - PIMAGE_NT_HEADERS pNtHeader = NULL; - __try { - pDosHeader = (PIMAGE_DOS_HEADER)Buffer; - - if ((ULONG)pDosHeader->e_lfanew > PE_HEADER_LIMIT || ((ULONG)pDosHeader->e_lfanew & 3) != 0) - { - //DoOutputDebugString("IsDisguisedPEHeader: e_lfanew bad. (0x%x)", (DWORD_PTR)Buffer); - return 0; - } - //else - // DoOutputDebugString("IsDisguisedPEHeader: e_lfanew ok!: 0x%x (0x%x)", (ULONG)pDosHeader->e_lfanew, (DWORD_PTR)Buffer); - - if (!pDosHeader->e_lfanew) - { - // In case the header until and including 'PE' has been zeroed - WORD* MachineProbe = (WORD*)&pDosHeader->e_lfanew; - while ((PCHAR)MachineProbe < (PCHAR)&pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) - { - if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) - pNtHeader = (PIMAGE_NT_HEADERS)(&(PCHAR)MachineProbe - 4); - MachineProbe += sizeof(WORD); - } - - if (!pNtHeader) - return 0; - } - else - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) { - //DoOutputDebugString("IsDisguisedPEHeader: OptionalHeader.Magic bad. (0x%x)", (DWORD_PTR)Buffer); - return 0; + //DoOutputDebugString("TestPERequirements: OptionalHeader.Magic bad. (0x%x)", (DWORD_PTR)pNtHeader); // extremely noisy + return FALSE; } //else - // DoOutputDebugString("IsDisguisedPEHeader: OptionalHeader.Magic ok!: 0x%x (0x%x)", pNtHeader->OptionalHeader.Magic, (DWORD_PTR)Buffer); + // DoOutputDebugString("TestPERequirements: OptionalHeader.Magic ok!: 0x%x (0x%x)", pNtHeader->OptionalHeader.Magic, (DWORD_PTR)pNtHeader); // Basic requirements if ( pNtHeader->FileHeader.Machine == 0 || pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || - pNtHeader->OptionalHeader.SizeOfHeaders == 0 || - pNtHeader->OptionalHeader.FileAlignment == 0 + pNtHeader->OptionalHeader.SizeOfHeaders == 0 //|| + //pNtHeader->OptionalHeader.FileAlignment == 0 ) { - DoOutputDebugString("IsDisguisedPEHeader: Basic requirements failure (Base 0x%x).\n", (DWORD_PTR)Buffer); - return 0; + //DoOutputDebugString("TestPERequirements: Basic requirements failure (0x%x).\n", (DWORD_PTR)pNtHeader); // very noisy + return FALSE; } if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) { - DoOutputDebugString("IsDisguisedPEHeader: Characteristics bad. (0x%x)", (DWORD_PTR)Buffer); - return 0; + DoOutputDebugString("TestPERequirements: Characteristics bad. (0x%x)", (DWORD_PTR)pNtHeader); + return FALSE; } if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) { - DoOutputDebugString("IsDisguisedPEHeader: SizeOfOptionalHeader bad. (0x%x)", (DWORD_PTR)Buffer); - return 0; + DoOutputDebugString("TestPERequirements: SizeOfOptionalHeader bad. (0x%x)", (DWORD_PTR)pNtHeader); + return FALSE; } if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) { - DoOutputDebugString("IsDisguisedPEHeader: FileAlignment invalid. (0x%x)", (DWORD_PTR)Buffer); - return 0; + DoOutputDebugString("TestPERequirements: FileAlignment invalid. (0x%x)", (DWORD_PTR)pNtHeader); + return FALSE; } if (pNtHeader->OptionalHeader.SectionAlignment < pNtHeader->OptionalHeader.FileAlignment) { - DoOutputDebugString("IsDisguisedPEHeader: FileAlignment greater than SectionAlignment.\n (0x%x)", (DWORD_PTR)Buffer); - return 0; + DoOutputDebugString("TestPERequirements: FileAlignment greater than SectionAlignment.\n (0x%x)", (DWORD_PTR)pNtHeader); + return FALSE; } // To pass the above tests it should now be safe to assume it's a PE image - return (ULONG)pDosHeader->e_lfanew; + return TRUE; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + DoOutputDebugString("TestPERequirements: Exception occured reading region at 0x%x\n", (DWORD_PTR)(pNtHeader)); + return FALSE; + } +} + +//************************************************************************************** +int IsDisguisedPEHeader(LPVOID Buffer) +//************************************************************************************** +{ + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader = NULL; + WORD* MachineProbe; + + __try + { + pDosHeader = (PIMAGE_DOS_HEADER)Buffer; + + if (pDosHeader->e_lfanew && (ULONG)pDosHeader->e_lfanew < PE_HEADER_LIMIT && ((ULONG)pDosHeader->e_lfanew & 3) == 0) + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' has been zeroed + MachineProbe = (WORD*)&pDosHeader->e_lfanew; + while ((PUCHAR)MachineProbe < (PUCHAR)&pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + { + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + break; + } + MachineProbe += sizeof(WORD); + } + } + + if (pNtHeader && TestPERequirements(pNtHeader)) + return 1; + + // In case the header until and including 'PE' is missing + MachineProbe = (WORD*)Buffer; + pNtHeader = NULL; + while ((PUCHAR)MachineProbe < (PUCHAR)pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + { + if ((PUCHAR)MachineProbe >= (PUCHAR)pDosHeader + 4) + { + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + break; + } + } + MachineProbe += sizeof(WORD); + } + + if (pNtHeader && TestPERequirements(pNtHeader)) + return 1; } __except(EXCEPTION_EXECUTE_HANDLER) { @@ -1267,7 +1338,7 @@ int IsDisguisedPEHeader(LPVOID Buffer) } //DoOutputDebugString("IsDisguisedPEHeader: No PE image located\n (0x%x)", (DWORD_PTR)Buffer); - //return 0; + return 0; } //************************************************************************************** @@ -1315,7 +1386,8 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) { PBYTE PEImage; PIMAGE_DOS_HEADER pDosHeader; - + PIMAGE_NT_HEADERS pNtHeader = NULL; + BOOL RetVal = FALSE; LPVOID PEPointer = Buffer; @@ -1324,45 +1396,76 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) while (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) { pDosHeader = (PIMAGE_DOS_HEADER)PEPointer; + if (*(WORD*)PEPointer != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) { DoOutputDebugString("DumpPEsInRange: Disguised PE image (bad MZ and/or PE headers) at 0x%x.\n", PEPointer); // We want to fix the PE header in the dump (for e.g. disassembly etc) - PEImage = (BYTE*)malloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); + PEImage = (BYTE*)calloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), sizeof(PUCHAR)); memcpy(PEImage, PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); - pDosHeader = (PIMAGE_DOS_HEADER)PEImage; + pDosHeader = (PIMAGE_DOS_HEADER)(PEImage); if (!pDosHeader->e_lfanew) { // In case the header until and including 'PE' has been zeroed - PIMAGE_NT_HEADERS pNtHeader = NULL; WORD* MachineProbe = (WORD*)&pDosHeader->e_lfanew; - while ((PCHAR)MachineProbe < (PCHAR)&pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + while ((PUCHAR)MachineProbe < (PUCHAR)pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) { if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) - pNtHeader = (PIMAGE_NT_HEADERS)(&(PCHAR)MachineProbe - 4); + { + if ((PUCHAR)MachineProbe > (PUCHAR)pDosHeader + 3) + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + } MachineProbe += sizeof(WORD); } - if (!pNtHeader) - return FALSE; + if (pNtHeader) + pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + } + + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' is missing + pNtHeader = NULL; + WORD* MachineProbe = (WORD*)pDosHeader; + while ((PUCHAR)MachineProbe < (PUCHAR)pDosHeader + (PE_HEADER_LIMIT - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + { + if ((PUCHAR)MachineProbe >= (PUCHAR)pDosHeader + 4) + { + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + //break; + } + } + MachineProbe += sizeof(WORD); - pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + if (pNtHeader && (PUCHAR)pNtHeader == (PUCHAR)pDosHeader && pNtHeader->OptionalHeader.SizeOfHeaders) + { + SIZE_T HeaderShift = sizeof(IMAGE_DOS_HEADER); + memmove(PEImage + HeaderShift, PEImage, pNtHeader->OptionalHeader.SizeOfHeaders - HeaderShift); + memset(PEImage, 0, HeaderShift); + pDosHeader = (PIMAGE_DOS_HEADER)PEImage; + pNtHeader = (PIMAGE_NT_HEADERS)(PEImage + HeaderShift); + pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + DoOutputDebugString("DumpPEsInRange: pNtHeader moved from 0x%x to 0x%x, e_lfanew 0x%x\n", pDosHeader, pNtHeader, pDosHeader->e_lfanew); + } + } } - *(WORD*)PEImage = IMAGE_DOS_SIGNATURE; - *(DWORD*)(PEImage + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; + *(WORD*)pDosHeader = IMAGE_DOS_SIGNATURE; + *(DWORD*)((PUCHAR)pDosHeader + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; - SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)PEPointer); + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)pDosHeader); - if (DumpImageInCurrentProcess((LPVOID)PEImage)) + if (DumpImageInCurrentProcess((LPVOID)pDosHeader)) { - DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); + DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", pDosHeader); RetVal = TRUE; } else - DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); + DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", pDosHeader); if (PEImage) free(PEImage); @@ -1611,7 +1714,7 @@ int DumpImageInCurrentProcess(LPVOID ImageBase) return 0; } - pNtHeader = (PIMAGE_NT_HEADERS)((PCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 7f2052f..e24309b 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -39,6 +39,7 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); int DumpImageInCurrentProcess(LPVOID ImageBase); +void DumpSectionViewsForPid(DWORD Pid); SYSTEM_INFO SystemInfo; PVOID CallingModule; diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 68f5453..403f978 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -28,6 +28,7 @@ along with this program.If not, see . #define PIPEBUFSIZE 512 // eflags register +#define FL_ZF 0x00000040 // Zero Flag #define FL_TF 0x00000100 // Trap flag #define FL_RF 0x00010000 // Resume flag @@ -1771,6 +1772,18 @@ BOOL SetResumeFlag(PCONTEXT Context) return TRUE; } +//************************************************************************************** +BOOL SetZeroFlag(PCONTEXT Context) +//************************************************************************************** +{ + if (Context == NULL) + return FALSE; + + Context->EFlags |= FL_ZF; + + return TRUE; +} + //************************************************************************************** BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler) //************************************************************************************** @@ -2939,7 +2952,7 @@ __declspec (naked dllexport) void DebuggerInit(void) #else #pragma optimize("", off) //************************************************************************************** -void DebuggerInit(void) +__declspec(dllexport) void DebuggerInit(void) //************************************************************************************** { DWORD_PTR StackPointer; diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index 601052f..e3bff28 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -124,6 +124,7 @@ BOOL ContextUpdateCurrentBreakpoint(PCONTEXT Context, int Size, LPVOID Address, BOOL SetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL SetResumeFlag(PCONTEXT Context); +BOOL SetZeroFlag(PCONTEXT Context); PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId); // Get diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index d1ac079..08b7ff2 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -49,7 +49,7 @@ PeParser::PeParser(const DWORD_PTR moduleBase, bool readSectionHeaders) if (moduleBaseAddress) { readPeHeaderFromProcess(readSectionHeaders); - + if (readSectionHeaders) { if (isValidPeFile()) @@ -225,7 +225,10 @@ bool PeParser::readPeHeaderFromProcess(bool readSectionHeaders) if (readSize < correctSize) { - readSize = correctSize; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::readPeHeaderFromProcess: Correcting header size to 0x%x.\n", correctSize); +#endif + readSize = correctSize; delete [] headerMemory; headerMemory = new BYTE[readSize]; @@ -482,7 +485,8 @@ std::vector & PeParser::getSectionHeaderList() void PeParser::getDosAndNtHeader(BYTE * memory, LONG size) { pDosHeader = (PIMAGE_DOS_HEADER)memory; - + DWORD readSize = getInitialHeaderReadSize(true); + pNTHeader32 = 0; pNTHeader64 = 0; dosStubSize = 0; @@ -504,6 +508,74 @@ void PeParser::getDosAndNtHeader(BYTE * memory, LONG size) pDosHeader->e_lfanew = sizeof(IMAGE_DOS_HEADER); } } + + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' has been zeroed (e.g. Ursnif) + PIMAGE_NT_HEADERS pNtHeader = NULL; + WORD* MachineProbe = (WORD*)&pDosHeader->e_lfanew; + while ((PUCHAR)MachineProbe < (PUCHAR)&pDosHeader + (readSize - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + MachineProbe += sizeof(WORD); + } + + if (pNtHeader) + pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + } + + if (!pDosHeader->e_lfanew) + { + // In case the header until and including 'PE' is missing + PIMAGE_NT_HEADERS pNtHeader = NULL; + WORD* MachineProbe = (WORD*)pDosHeader; + while ((PUCHAR)MachineProbe < (PUCHAR)pDosHeader + (readSize - offsetof(IMAGE_DOS_HEADER, e_lfanew))) + { + if (*MachineProbe == IMAGE_FILE_MACHINE_I386 || *MachineProbe == IMAGE_FILE_MACHINE_AMD64) + { + if ((PUCHAR)MachineProbe >= (PUCHAR)pDosHeader + 4 && !pNtHeader) + { + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)MachineProbe - 4); + } + } + MachineProbe += sizeof(WORD); + + if (pNtHeader && (PUCHAR)pNtHeader == (PUCHAR)pDosHeader) + { + SIZE_T HeaderShift = sizeof(IMAGE_DOS_HEADER); + delete [] headerMemory; + headerMemory = new BYTE[readSize]; + memset(headerMemory, 0, readSize); + if (ProcessAccessHelp::readMemoryPartlyFromProcess(moduleBaseAddress, readSize - HeaderShift, headerMemory + HeaderShift)) + { + pDosHeader = (PIMAGE_DOS_HEADER)headerMemory; + pNtHeader = (PIMAGE_NT_HEADERS)(headerMemory + HeaderShift); + pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); + } +#ifdef DEBUG_COMMENTS + DoOutputDebugString("PeParser::getDosAndNtHeader: Corrected: DOS header 0x%x, lfanew 0x%x, NT header 0x%x.\n", pDosHeader, pDosHeader->e_lfanew, pNtHeader); +#endif + } + } + } + + if (pDosHeader->e_lfanew && pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) + { + PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); + + if ((pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) || (pNtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)) + { + pDosHeader->e_magic = IMAGE_DOS_SIGNATURE; + pNtHeader->Signature = IMAGE_NT_SIGNATURE; + } + } + + if (pDosHeader->e_lfanew) + { + pNTHeader32 = (PIMAGE_NT_HEADERS32)((DWORD_PTR)pDosHeader + pDosHeader->e_lfanew); + pNTHeader64 = (PIMAGE_NT_HEADERS64)((DWORD_PTR)pDosHeader + pDosHeader->e_lfanew); + } } DWORD PeParser::calcCorrectPeHeaderSize(bool readSectionHeaders) @@ -644,7 +716,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil if (!readOffset || !readSize) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: readSectionFrom: readOffset or readSize zero: 0x%x, 0x%x\n", readOffset, readSize); + DoOutputDebugString("PeParser: readSectionFrom: readOffset or readSize zero: 0x%x, 0x%x\n", readOffset, readSize); #endif return true; //section without data is valid } @@ -655,7 +727,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil peFileSection.normalSize = readSize; #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: readSectionFrom: readSize <= maxReadSize: 0x%x.\n", readSize); + DoOutputDebugString("PeParser: readSectionFrom: readSize <= maxReadSize: 0x%x.\n", readSize); #endif if (isProcess) @@ -677,7 +749,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil currentOffset = readOffset + readSize - currentReadSize; #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: About to attempt to read section from 0x%x size 0x%x.\n", readOffset, readSize); + DoOutputDebugString("PeParser: About to attempt to read section from 0x%x size 0x%x.\n", readOffset, readSize); #endif while(currentOffset >= readOffset) //start from the end @@ -696,7 +768,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil if (!retValue) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: readMemory failure reading 0x%x bytes from 0x%x.\n", currentOffset , currentReadSize); + DoOutputDebugString("PeParser: readMemory failure reading 0x%x bytes from 0x%x.\n", currentOffset , currentReadSize); #endif break; } @@ -707,7 +779,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil //found some real code #ifdef DEBUG_COMMENTS - //DoOutputDebugString("PeParser:: readMemory found data at 0x%x.\n", currentOffset); + //DoOutputDebugString("PeParser: readMemory found data at 0x%x.\n", currentOffset); #endif currentOffset += valuesFound; @@ -730,7 +802,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil } #ifdef DEBUG_COMMENTS //else - // DoOutputDebugString("PeParser:: readMemory found nothing at 0x%x.\n", currentOffset); + // DoOutputDebugString("PeParser: readMemory found nothing at 0x%x.\n", currentOffset); #endif currentReadSize = maxReadSize; @@ -738,13 +810,13 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil } #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: calls to readSectionFrom succeeded.\n"); + DoOutputDebugString("PeParser: calls to readSectionFrom succeeded.\n"); #endif if (peFileSection.dataSize) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser:: readSectionFrom: About to read PE section from 0x%x.\n", readOffset); + DoOutputDebugString("PeParser: readSectionFrom: About to read PE section from 0x%x.\n", readOffset); #endif if (isProcess) { @@ -1247,12 +1319,15 @@ void PeParser::fixPeHeader() pNTHeader32->OptionalHeader.SizeOfImage = getSectionHeaderBasedSizeOfImage(); - if (moduleBaseAddress) - { - pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; - } + //if (moduleBaseAddress) + //{ + // pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; + //} pNTHeader32->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader32->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader32->OptionalHeader.FileAlignment); +#ifdef DEBUG_COMMENTS + //DoOutputDebugString("fixPeHeader: imagebase 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); +#endif } else { @@ -1272,12 +1347,13 @@ void PeParser::fixPeHeader() pNTHeader64->OptionalHeader.SizeOfImage = getSectionHeaderBasedSizeOfImage(); - if (moduleBaseAddress) - { - pNTHeader64->OptionalHeader.ImageBase = moduleBaseAddress; - } + //if (moduleBaseAddress) + //{ + // pNTHeader64->OptionalHeader.ImageBase = moduleBaseAddress; + //} pNTHeader64->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader64->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader64->OptionalHeader.FileAlignment); + //DoOutputDebugString("fixPeHeader: imagebase 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); } removeIatDirectory(); diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 6eb7205..3dd3752 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -77,12 +77,16 @@ extern "C" DWORD_PTR FileOffsetToVA(DWORD_PTR modBase, DWORD_PTR dwOffset) peFile = new PeParser(modBase, true); - //return peFile->convertOffsetToRVAVector(dwOffset) + modBase; - Test = peFile->convertOffsetToRVAVector(dwOffset) + modBase; + if (peFile->isValidPeFile()) + { + //return peFile->convertOffsetToRVAVector(dwOffset) + modBase; + Test = peFile->convertOffsetToRVAVector(dwOffset) + modBase; - DoOutputDebugString("FileOffsetToVA: Debug - VA = 0x%p.\n", Test); - - return Test; + DoOutputDebugString("FileOffsetToVA: Debug - VA = 0x%p.\n", Test); + + return Test; + } + else return NULL; } //************************************************************************************** diff --git a/cuckoomon.c b/cuckoomon.c index 633ad20..7f182cd 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -36,6 +36,7 @@ along with this program. If not, see . volatile int dummy_val; extern void init_CAPE(); +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); void disable_tail_call_optimization(void) { @@ -274,8 +275,8 @@ static hook_t g_hooks[] = { //HOOK(user32, EnumWindows), HOOK(user32, PostMessageA), HOOK(user32, PostMessageW), - //HOOK(user32, SendMessageA), - //HOOK(user32, SendMessageW), + HOOK(user32, SendMessageA), + HOOK(user32, SendMessageW), HOOK(user32, SendNotifyMessageA), HOOK(user32, SendNotifyMessageW), HOOK(user32, SetWindowLongA), @@ -664,6 +665,8 @@ VOID CALLBACK DllLoadNotification( dllname = get_dll_basename(&library); set_hooks_dll(dllname); + + DoOutputDebugString("DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); } else { // unload diff --git a/hook_file.c b/hook_file.c index 8c3c413..8e4b584 100644 --- a/hook_file.c +++ b/hook_file.c @@ -259,7 +259,8 @@ void handle_terminate() entry_t *p; for (p = (entry_t*)&(g_files.root); p != NULL; p = p->next) { - file_close((HANDLE)p->id); + if (p->id) + file_close((HANDLE)p->id); } } static BOOLEAN is_protected_objattr(POBJECT_ATTRIBUTES obj) From d81c237bddb35589c3d9228db6214f26dc31aea9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Aug 2018 14:41:58 +0100 Subject: [PATCH 28/39] Refactored injection-relevant hook code into a distinct module, Injection.c, updates from main branch. --- CAPE/CAPE.c | 130 +++++--- CAPE/CAPE.h | 7 +- CAPE/Debugger.c | 14 +- CAPE/Debugger.h | 4 + CAPE/Injection.c | 412 +++++++++++++++++++++++++ CAPE/Output.c | 12 +- CAPE/Scylla/IATReferenceScan.cpp | 6 - CAPE/Scylla/PeParser.cpp | 64 ++-- CAPE/ScyllaHarness.cpp | 128 +++++++- README.md | 28 +- config.c | 42 ++- config.h | 1 + cuckoomon.c | 77 ++--- cuckoomon.vcxproj | 3 +- cuckoomon.vcxproj.filters | 3 + hook_crypto.c | 8 +- hook_file.c | 74 ++--- hook_misc.c | 66 +++- hook_process.c | 503 +++++++------------------------ hook_sleep.c | 6 +- hook_special.c | 150 ++++----- hook_thread.c | 226 +++++++------- hooking.c | 20 +- hooking.h | 3 + hooks.h | 23 ++ log.h | 3 + lookup.c | 51 ++++ lookup.h | 4 + misc.c | 4 +- ntapi.h | 104 ++++++- unhook.c | 11 + 31 files changed, 1377 insertions(+), 810 deletions(-) create mode 100644 CAPE/Injection.c diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 742a4a9..f8ab68f 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -100,10 +100,16 @@ typedef struct _hook_info_t { ULONG_PTR main_caller_retaddr; ULONG_PTR parent_caller_retaddr; } hook_info_t; - -static unsigned int DumpCount; extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buffer_len); +extern int called_by_hook(void); +extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); +extern unsigned int address_is_in_stack(PVOID Address); +extern hook_info_t *hook_info(); +extern ULONG_PTR base_of_dll_of_interest; +extern wchar_t *our_process_path; +extern ULONG_PTR g_our_dll_base; +extern DWORD g_our_dll_size; extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); @@ -115,21 +121,30 @@ extern int ScyllaDumpCurrentProcessFixImports(DWORD_PTR NewOEP); extern int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR modBase, DWORD_PTR NewOEP); extern int ScyllaDumpPE(DWORD_PTR Buffer); extern BOOL CountDepth(LPVOID* ReturnAddress, LPVOID Address); +extern SIZE_T GetPESize(PVOID Buffer); +extern LPVOID GetReturnAddress(hook_info_t *hookinfo); +extern PVOID CallingModule; -extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); -extern unsigned int address_is_in_stack(PVOID Address); -extern hook_info_t *hook_info(); -extern ULONG_PTR base_of_dll_of_interest; -extern wchar_t *our_process_path; -extern ULONG_PTR g_our_dll_base; -extern DWORD g_our_dll_size; - -static HMODULE s_hInst = NULL; -static WCHAR s_wzDllPath[MAX_PATH]; -CHAR s_szDllPath[MAX_PATH]; +BOOL ProcessDumped, FilesDumped; +static unsigned int DumpCount; -BOOL ProcessDumped; +static __inline ULONG_PTR get_stack_top(void) +{ +#ifndef _WIN64 + return __readfsdword(0x04); +#else + return __readgsqword(0x08); +#endif +} +static __inline ULONG_PTR get_stack_bottom(void) +{ +#ifndef _WIN64 + return __readfsdword(0x08); +#else + return __readgsqword(0x10); +#endif +} //************************************************************************************** BOOL InsideHook(LPVOID* ReturnAddress, LPVOID Address) //************************************************************************************** @@ -161,11 +176,6 @@ LPVOID GetReturnAddress(hook_info_t *hookinfo) __try { -#ifdef _WIN64 - DoOutputDebugString("GetReturnAddress: operate_on_backtrace call with Rip 0x%p.\n", hookinfo->frame_pointer); -#else - DoOutputDebugString("GetReturnAddress: operate_on_backtrace call with Ebp 0x%x.\n", hookinfo->frame_pointer); -#endif operate_on_backtrace(hookinfo->stack_pointer, hookinfo->frame_pointer, &ReturnAddress, GetCurrentFrame); return ReturnAddress; } @@ -181,15 +191,18 @@ LPVOID GetReturnAddress(hook_info_t *hookinfo) } //************************************************************************************** -void GetHookCallerBase() +PVOID GetHookCallerBase() //************************************************************************************** { PVOID ReturnAddress, AllocationBase; + hook_info_t *hookinfo = hook_info(); - if (CallingModule) - return; - - ReturnAddress = GetReturnAddress(hook_info()); + if (hookinfo->main_caller_retaddr) + ReturnAddress = (PVOID)hookinfo->main_caller_retaddr; + else if (hookinfo->parent_caller_retaddr) + ReturnAddress = (PVOID)hookinfo->parent_caller_retaddr; + //else + // ReturnAddress = GetReturnAddress(hookinfo); if (ReturnAddress) { @@ -201,13 +214,14 @@ void GetHookCallerBase() if (AllocationBase) { CallingModule = AllocationBase; + return CallingModule; // Base-dependent breakpoints can be activated now } } else DoOutputDebugString("GetHookCallerBase: failed to get return address.\n"); - return; + return NULL; } //************************************************************************************** @@ -1676,13 +1690,42 @@ int DumpCurrentProcess() int DumpModuleInCurrentProcess(LPVOID ModuleBase) //************************************************************************************** { - SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)ModuleBase); + PIMAGE_DOS_HEADER pDosHeader; + + if (!IsDisguisedPEHeader(ModuleBase)) + { + DoOutputDebugString("DumpModuleInCurrentProcess: Not a valid image at 0x%p - cannot dump.\n", ModuleBase); + return 0; + } + + pDosHeader = (PIMAGE_DOS_HEADER)ModuleBase; + + if (*(WORD*)ModuleBase != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) + { + PBYTE PEImage; + SIZE_T ImageSize; + + DoOutputDebugString("DumpModuleInCurrentProcess: Disguised PE image (bad MZ and/or PE headers) at 0x%p.\n", ModuleBase); + + // We want to fix the PE header in the dump (for e.g. disassembly etc) + ImageSize = GetPESize(ModuleBase); + PEImage = (BYTE*)malloc(ImageSize); + memcpy(PEImage, ModuleBase, ImageSize); + pDosHeader = (PIMAGE_DOS_HEADER)PEImage; + + *(WORD*)PEImage = IMAGE_DOS_SIGNATURE; + *(DWORD*)(PEImage + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; + + ModuleBase = PEImage; + } + DoOutputDebugString("DumpModuleInCurrentProcess: About to call ScyllaDumpProcess.\n"); if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) - { + { DumpCount++; - return 1; - } + return 1; + } + DoOutputDebugString("DumpModuleInCurrentProcess: returned from ScyllaDumpProcess.\n"); return 0; } @@ -1791,22 +1834,25 @@ int DumpPE(LPVOID Buffer) int RoutineProcessDump() //************************************************************************************** { + PVOID ImageBase, CallerBase = GetHookCallerBase(); + + if (base_of_dll_of_interest) + ImageBase = (PVOID)base_of_dll_of_interest; + else + ImageBase = GetModuleHandle(NULL); + if (g_config.procdump && ProcessDumped == FALSE) { ProcessDumped = TRUE; // this prevents a second call before the first is complete if (g_config.import_reconstruction) - { - if (base_of_dll_of_interest) - ProcessDumped = ScyllaDumpProcessFixImports(GetCurrentProcess(), base_of_dll_of_interest, 0); - else - ProcessDumped = ScyllaDumpCurrentProcessFixImports(0); - } + ProcessDumped = ScyllaDumpProcessFixImports(GetCurrentProcess(), (DWORD_PTR)ImageBase, 0); else + ProcessDumped = ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ImageBase, 0); + + if (CallerBase && ImageBase != CallerBase && called_by_hook()) { - if (base_of_dll_of_interest) - ProcessDumped = ScyllaDumpProcess(GetCurrentProcess(), base_of_dll_of_interest, 0); - else - ProcessDumped = ScyllaDumpCurrentProcess(0); + DoOutputDebugString("RoutineProcessDump: Terminate caller base (0x%p) different to imagebase (0x%p) - dumping.\n", CallerBase, ImageBase); + ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)CallerBase, 0); } } @@ -1833,7 +1879,7 @@ void init_CAPE() // made at the end of a process' lifetime. // It is normally only set in the base packages, // or upon submission. (This overrides submission.) - // g_config.procdump = 0; + g_config.procdump = 0; // Cuckoo debug output level for development (0=none, 2=max) // g_config.debug = 2; @@ -1847,9 +1893,9 @@ void init_CAPE() DoOutputDebugString("Failed to initialise debugger.\n"); #ifdef _WIN64 - DoOutputDebugString("CAPE initialised: 64-bit Injection package loaded at 0x%p, process image base 0x%p\n", g_our_dll_base, GetModuleHandle(NULL)); + DoOutputDebugString("CAPE initialised: 64-bit Injection package loaded in process %d at 0x%p, image base 0x%p, stack from 0x%p-0x%p\n", GetCurrentProcessId(), g_our_dll_base, GetModuleHandle(NULL), get_stack_bottom(), get_stack_top()); #else - DoOutputDebugString("CAPE initialised: 32-bit Injection package loaded at 0x%p, process image base 0x%p\n", g_our_dll_base, GetModuleHandle(NULL)); + DoOutputDebugString("CAPE initialised: 32-bit Injection package loaded in process %d at 0x%x, image base 0x%x, stack from 0x%x-0x%x\n", GetCurrentProcessId(), g_our_dll_base, GetModuleHandle(NULL), get_stack_bottom(), get_stack_top()); #endif return; diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index e24309b..dc6fc44 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -22,7 +22,7 @@ extern CHAR s_szDllPath[MAX_PATH]; //Global debugger switch #define DEBUGGER_ENABLED 0 -void GetHookCallerBase(); +PVOID GetHookCallerBase(); PVOID GetPageAddress(PVOID Address); PVOID GetAllocationBase(PVOID Address); BOOL TranslatePathFromDeviceToLetter(__in TCHAR *DeviceFilePath, __out TCHAR* DriveLetterFilePath, __inout LPDWORD lpdwBufferSize); @@ -38,6 +38,7 @@ int ScanPageForNonZero(LPVOID Address); int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); +int DumpModuleInCurrentProcess(LPVOID ModuleBase); int DumpImageInCurrentProcess(LPVOID ImageBase); void DumpSectionViewsForPid(DWORD Pid); @@ -152,7 +153,9 @@ enum { URSNIF_PAYLOAD = 0x25, CERBER_CONFIG = 0x30, - CERBER_PAYLOAD = 0x31 + CERBER_PAYLOAD = 0x31, + + DATADUMP = 0x66 }; HANDLE EvilGrabRegHandle; diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 403f978..3778ca8 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -1,6 +1,6 @@ /* CAPE - Config And Payload Extraction -Copyright(C) 2015, 2016 Context Information Security. (kevin.oreilly@contextis.com) +Copyright(C) 2015 - 2018 Context Information Security. (kevin.oreilly@contextis.com) This program is free software : you can redistribute it and / or modify it under the terms of the GNU General Public License as published by @@ -1784,6 +1784,18 @@ BOOL SetZeroFlag(PCONTEXT Context) return TRUE; } +//************************************************************************************** +BOOL ClearZeroFlag(PCONTEXT Context) +//************************************************************************************** +{ + if (Context == NULL) + return FALSE; + + Context->EFlags &= ~FL_ZF; + + return TRUE; +} + //************************************************************************************** BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler) //************************************************************************************** diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index e3bff28..fc38b5a 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -15,6 +15,7 @@ #define DEBUG_REGISTER_LENGTH_MASKS {0xFFFFFFFF, 0, 1, 0xFFFFFFFF, 3} #define EXECUTABLE_FLAGS (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) +#define WRITABLE_FLAGS (PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY | PAGE_WRITECOMBINE) #define EXTRACTION_MIN_SIZE 0x1001 @@ -118,6 +119,7 @@ int launch_debugger(void); BOOL SetBreakpoint(int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL SetThreadBreakpoint(DWORD ThreadId, int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); BOOL ContextSetThreadBreakpoint(PCONTEXT Context, int Register, int Size, LPVOID Address, DWORD Type, PVOID Callback); +BOOL ContextSetDebugRegister(PCONTEXT Context, int Register, int Size, LPVOID Address, DWORD Type); BOOL SetThreadBreakpoints(PTHREADBREAKPOINTS ThreadBreakpoints); BOOL ContextSetBreakpoint(PTHREADBREAKPOINTS ThreadBreakpoints); BOOL ContextUpdateCurrentBreakpoint(PCONTEXT Context, int Size, LPVOID Address, DWORD Type, PVOID Callback); @@ -125,6 +127,7 @@ BOOL SetNextAvailableBreakpoint(DWORD ThreadId, unsigned int* Register, int Size BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler); BOOL SetResumeFlag(PCONTEXT Context); BOOL SetZeroFlag(PCONTEXT Context); +BOOL ClearZeroFlag(PCONTEXT Context); PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId); // Get @@ -135,6 +138,7 @@ BOOL ContextSetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register, int CheckDebugRegister(HANDLE hThread, int Register); BOOL CheckDebugRegisters(HANDLE hThread, PCONTEXT pContext); int ContextCheckDebugRegister(CONTEXT Context, int Register); +BOOL ContextCheckDebugRegisters(PCONTEXT pContext); HANDLE GetThreadHandle(DWORD ThreadId); // Clear diff --git a/CAPE/Injection.c b/CAPE/Injection.c new file mode 100644 index 0000000..1d6838b --- /dev/null +++ b/CAPE/Injection.c @@ -0,0 +1,412 @@ +/* +CAPE - Config And Payload Extraction +Copyright(C) 2015 - 2018 Context Information Security. (kevin.oreilly@contextis.com) + +This program is free software : you can redistribute it and / or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.If not, see . +*/ +#include +#include "..\ntapi.h" +#include +#include +#include "..\misc.h" +#include "..\hooking.h" +#include "..\log.h" +#include "Debugger.h" +#include "CAPE.h" + +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void TestDoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); +extern PVOID get_process_image_base(HANDLE process_handle); + +void GetThreadContextHandler(DWORD Pid, LPCONTEXT Context) +{ + if (Context && Context->ContextFlags & CONTEXT_CONTROL) + { + struct InjectionInfo *CurrentInjectionInfo = GetInjectionInfo(Pid); +#ifdef _WIN64 + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + CurrentInjectionInfo->StackPointer = (LPVOID)Context->Rsp; +#else + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + CurrentInjectionInfo->StackPointer = (LPVOID)Context->Esp; +#endif + } +} + +void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context) +{ + if (Context && Context->ContextFlags & CONTEXT_CONTROL) + { + struct InjectionInfo *CurrentInjectionInfo = GetInjectionInfo(Pid); +#ifdef _WIN64 + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds ep on 64-bit + + if (Context->Rip == (DWORD_PTR)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point set to NtMapViewOfSection (process %d).\n", Pid); + else + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); +#else + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds ep on 32-bit + + if (Context->Eip == (DWORD)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point set to NtMapViewOfSection (process %d).\n", Pid); + else + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); +#endif + } +} + +void ResumeThreadHandler(DWORD Pid) +{ + struct InjectionInfo *CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!CurrentInjectionInfo) + { + DoOutputDebugString("ResumeThreadHandler: CurrentInjectionInfo 0x%x (Pid %d).\n", CurrentInjectionInfo, Pid); + return; + } + + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) + { + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + + DoOutputDebugString("ResumeThreadHandler: Dumping hollowed process %d, image base 0x%x.\n", Pid, CurrentInjectionInfo->ImageBase); + + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("ResumeThreadHandler: Dumped PE image from buffer.\n"); + } + else + DoOutputDebugString("ResumeThreadHandler: Failed to dump PE image from buffer.\n"); + } + + DumpSectionViewsForPid(Pid); +} + +void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROCESS_INFORMATION lpProcessInformation) +{ + WCHAR TargetProcess[MAX_PATH]; + struct InjectionInfo *CurrentInjectionInfo; + + // Create 'injection info' struct for the newly created process + CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("CreateProcessHandler: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + return; + } + + CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + + CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); + memset(TargetProcess, 0, MAX_PATH*sizeof(WCHAR)); + + if (lpApplicationName) + _snwprintf(TargetProcess, MAX_PATH, L"%s", lpApplicationName); + else if (lpCommandLine) + { + DoOutputDebugString("CreateProcessHandler: using lpCommandLine: %ws.\n", lpCommandLine); + if (*lpCommandLine == L'\"') + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); + else + { + if (wcschr(lpCommandLine, ' ')) + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); + else + wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); + } + } + + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, (int)wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); + + DoOutputDebugString("CreateProcessHandler: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); +} + +void OpenProcessHandler(PHANDLE ProcessHandle, int Pid) +{ + struct InjectionInfo *CurrentInjectionInfo; + DWORD BufferSize = MAX_PATH; + char DevicePath[MAX_PATH]; + unsigned int PathLength; + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { // First call for this process, create new info + CurrentInjectionInfo = CreateInjectionInfo(Pid); + + DoOutputDebugString("OpenProcessHandler: Injection info created for Pid %d.\n", Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("OpenProcessHandler: Cannot create new injection info - FATAL ERROR.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = *ProcessHandle; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); + + if (!CurrentInjectionInfo->ImageBase) + DoOutputDebugString("OpenProcessHandler: Error obtaining target process image base for process %d (handle 0x%x).\n", Pid, *ProcessHandle); + else + DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); + + PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); + + if (!PathLength) + { + DoOutputErrorString("OpenProcessHandler: Error obtaining target process name"); + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("OpenProcessHandler: Error translating target process path"); + } + } + else if (CurrentInjectionInfo->ImageBase == (DWORD_PTR)NULL) + { + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); + + if (CurrentInjectionInfo->ImageBase) + DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); + } +} + +void ResumeProcessHandler(HANDLE ProcessHandle) +{ + struct InjectionInfo *CurrentInjectionInfo; + + DWORD Pid = pid_from_process_handle(ProcessHandle); + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (CurrentInjectionInfo) + { + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) + { + SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); + + DoOutputDebugString("ResumeProcessHandler: Dumping hollowed process %d, image base 0x%x.\n", Pid, CurrentInjectionInfo->ImageBase); + + CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("ResumeProcessHandler: Dumped PE image from buffer.\n"); + } + else + DoOutputDebugString("ResumeProcessHandler: Failed to dump PE image from buffer.\n"); + } + + DumpSectionViewsForPid(Pid); + } +} + +void UnmapSectionViewHandler(PVOID BaseAddress) +{ + PINJECTIONSECTIONVIEW CurrentSectionView; + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) + { + DoOutputDebugString("UnmapSectionViewHandler: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); + DumpSectionView(CurrentSectionView); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } +} + +void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, PSIZE_T ViewSize) +{ + struct InjectionInfo *CurrentInjectionInfo; + struct InjectionSectionView *CurrentSectionViewInfo; + char DevicePath[MAX_PATH]; + unsigned int PathLength; + DWORD BufferSize = MAX_PATH; + + DWORD Pid = pid_from_process_handle(ProcessHandle); + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (Pid == GetCurrentProcessId()) + { + PINJECTIONSECTIONVIEW CurrentSectionView = GetSectionView(SectionHandle); + + if (!CurrentSectionView) + { + AddSectionView(SectionHandle, BaseAddress, *ViewSize); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, BaseAddress); + } + else + { + if (CurrentSectionView->LocalView != BaseAddress) + { + CurrentSectionView->LocalView = BaseAddress; + CurrentSectionView->ViewSize = *ViewSize; + DoOutputDebugString("MapSectionViewHandler: Updated local view to 0x%x for section view with handle 0x%x.\n", BaseAddress, SectionHandle); + } + } + } + else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + { + CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, *ViewSize); + + if (CurrentSectionViewInfo) + { + CurrentSectionViewInfo->TargetProcessId = Pid; + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, Pid); + } + else + { + DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, Pid); + } + } + else if (!CurrentInjectionInfo && Pid != GetCurrentProcessId()) + { + CurrentInjectionInfo = CreateInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("MapSectionViewHandler: Cannot create new injection info - FATAL ERROR.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = ProcessHandle; + CurrentInjectionInfo->ProcessId = Pid; + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); + + if (!PathLength) + { + DoOutputErrorString("MapSectionViewHandler: Error obtaining target process name"); + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("MapSectionViewHandler: Error translating target process path"); + + CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, *ViewSize); + + if (CurrentSectionViewInfo) + { + CurrentSectionViewInfo->TargetProcessId = Pid; + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, Pid); + } + else + DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, Pid); + } + } +} + +void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesToWrite, PSIZE_T NumberOfBytesWritten) +{ + DWORD Pid; + struct InjectionInfo *CurrentInjectionInfo; + PIMAGE_DOS_HEADER pDosHeader; + PIMAGE_NT_HEADERS pNtHeader; + + Pid = pid_from_process_handle(ProcessHandle); + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!CurrentInjectionInfo || CurrentInjectionInfo->ProcessId != Pid) + return; + + if (*NumberOfBytesWritten == 0) + return; + + CurrentInjectionInfo->WriteDetected = TRUE; + + // Check if we have a valid DOS and PE header at the beginning of Buffer + if (IsDisguisedPEHeader((PVOID)Buffer)) + { + pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer); + + pNtHeader = (PIMAGE_NT_HEADERS)((char*)Buffer + pDosHeader->e_lfanew); + + CurrentInjectionInfo->ImageBase = (DWORD_PTR)BaseAddress; + + DoOutputDebugString("WriteMemoryHandler: Executable binary injected into process %d (ImageBase 0x%x)\n", Pid, CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); + + CurrentInjectionInfo->ImageDumped = DumpModuleInCurrentProcess((PVOID)Buffer); + + if (CurrentInjectionInfo->ImageDumped) + { + CurrentInjectionInfo->BufferBase = (LPVOID)Buffer; + CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; + DoOutputDebugString("WriteMemoryHandler: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", Buffer, CurrentInjectionInfo->BufferSizeOfImage); + } + else + { + DoOutputDebugString("WriteMemoryHandler: Failed to dump PE image from buffer, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = Pid; + if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) + DoOutputDebugString("WriteMemoryHandler: Dumped malformed PE image from buffer."); + else + DoOutputDebugString("WriteMemoryHandler: Failed to dump malformed PE image from buffer."); + } + } + } + else + { + if (*NumberOfBytesWritten > 0x10) + { + if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && + Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) + { + // Looks like a previously dumped PE image is being written a section at a time to the target process. + // We don't want to dump these writes. + DoOutputDebugString("WriteMemoryHandler: injection of section of PE image which has already been dumped.\n"); + } + else + { + DoOutputDebugString("WriteMemoryHandler: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, *NumberOfBytesWritten, Pid); + + // dump injected code/data + CapeMetaData->DumpType = INJECTION_SHELLCODE; + CapeMetaData->TargetPid = Pid; + if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) + DoOutputDebugString("WriteMemoryHandler: Dumped injected code/data from buffer."); + else + DoOutputDebugString("WriteMemoryHandler: Failed to dump injected code/data from buffer."); + } + } + } +} diff --git a/CAPE/Output.c b/CAPE/Output.c index 915fcc7..c6617c5 100644 --- a/CAPE/Output.c +++ b/CAPE/Output.c @@ -40,12 +40,12 @@ void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...) va_start(args, lpOutputString); memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); - _vsntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, lpOutputString, args); + _vsntprintf_s(DebugOutput, MAX_PATH, _TRUNCATE, lpOutputString, args); #ifdef STANDALONE OutputDebugString(DebugOutput); #else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); - _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "DEBUG:%s", DebugOutput); + _sntprintf_s(PipeOutput, MAX_PATH, _TRUNCATE, "DEBUG:%s", DebugOutput); pipe(PipeOutput, strlen(PipeOutput)); #endif va_end(args); @@ -74,15 +74,15 @@ void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...) NULL); memset(DebugOutput, 0, MAX_PATH*sizeof(TCHAR)); - _vsntprintf_s(DebugOutput, MAX_PATH, MAX_PATH, lpOutputString, args); + _vsntprintf_s(DebugOutput, MAX_PATH, _TRUNCATE, lpOutputString, args); memset(ErrorOutput, 0, MAX_PATH*sizeof(TCHAR)); - _sntprintf_s(ErrorOutput, MAX_PATH, MAX_PATH, "Error %d (0x%x) - %s: %s", ErrorCode, ErrorCode, DebugOutput, (char*)lpMsgBuf); + _sntprintf_s(ErrorOutput, MAX_PATH, _TRUNCATE, "Error %d (0x%x) - %s: %s", ErrorCode, ErrorCode, DebugOutput, (char*)lpMsgBuf); #ifdef STANDALONE OutputDebugString(ErrorOutput); #else memset(PipeOutput, 0, MAX_PATH*sizeof(TCHAR)); - _sntprintf_s(PipeOutput, MAX_PATH, MAX_PATH, "DEBUG:%s", ErrorOutput); + _sntprintf_s(PipeOutput, MAX_PATH, _TRUNCATE, "DEBUG:%s", ErrorOutput); pipe(PipeOutput, strlen(PipeOutput)); #endif @@ -184,6 +184,8 @@ void CapeOutputFile(_In_ LPCTSTR lpOutputFile) Buffer = malloc(BufferSize); + if (!CapeMetaData->ProcessPath) + CapeMetaData->ProcessPath = "Unknown path"; CapeMetaData->ModulePath = CapeMetaData->ProcessPath; if (CapeMetaData->DumpType == EXTRACTION_PE || CapeMetaData->DumpType == EXTRACTION_SHELLCODE) diff --git a/CAPE/Scylla/IATReferenceScan.cpp b/CAPE/Scylla/IATReferenceScan.cpp index 471a21d..7e1690e 100644 --- a/CAPE/Scylla/IATReferenceScan.cpp +++ b/CAPE/Scylla/IATReferenceScan.cpp @@ -67,8 +67,6 @@ void IATReferenceScan::startScan(DWORD_PTR imageBase, DWORD imageSize, DWORD_PTR iatDirectImportList.reserve(50); } - - DWORD_PTR section = imageBase; do @@ -410,7 +408,6 @@ void IATReferenceScan::patchNewIat(DWORD_PTR stdImagebase, DWORD_PTR newIatBaseA } } - void IATReferenceScan::printDirectImportLog() { DoOutputDebugString("------------------------------------------------------------"); @@ -455,7 +452,6 @@ void IATReferenceScan::printDirectImportLog() DoOutputDebugString("------------------------------------------------------------"); } - void IATReferenceScan::findDirectIatReferenceCallJmp( _DInst * instruction ) { IATReference ref; @@ -735,5 +731,3 @@ DWORD IATReferenceScan::addAdditionalApisToList() return newIatSize; } - - diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 08b7ff2..4b4c564 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -359,11 +359,11 @@ bool PeParser::readPeSectionsFromProcess() #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: Correcting VirtualSize for last section (%d) from 0x%x to 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize, alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment)); #endif - listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); + listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.SizeOfRawData, sectionAlignment); } else { - listPeSection[i].sectionHeader.Misc.VirtualSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); + listPeSection[i].normalSize = alignValue(listPeSection[i].sectionHeader.Misc.VirtualSize, sectionAlignment); #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::readPeSectionsFromProcess: VirtualSize for last section (%d) ok: 0x%x.\n", i+1, listPeSection[i].sectionHeader.Misc.VirtualSize); #endif @@ -749,7 +749,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil currentOffset = readOffset + readSize - currentReadSize; #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser: About to attempt to read section from 0x%x size 0x%x.\n", readOffset, readSize); + DoOutputDebugString("PeParser: About to reverse-scan section from 0x%p size 0x%x.\n", readOffset, readSize); #endif while(currentOffset >= readOffset) //start from the end @@ -768,10 +768,14 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil if (!retValue) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser: readMemory failure reading 0x%x bytes from 0x%x.\n", currentOffset , currentReadSize); + DoOutputDebugString("PeParser: readMemory failure reading from 0x%p (currentReadSize 0x%x).\n", currentOffset, currentReadSize); #endif break; } +#ifdef DEBUG_COMMENTS + //else + // DoOutputDebugString("PeParser: Read memory chunk from 0x%p size 0x%x.\n", currentOffset, currentReadSize); +#endif valuesFound = isMemoryNotNull(data, currentReadSize); if (valuesFound) @@ -779,7 +783,7 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil //found some real code #ifdef DEBUG_COMMENTS - //DoOutputDebugString("PeParser: readMemory found data at 0x%x.\n", currentOffset); + DoOutputDebugString("PeParser: readMemory found data at 0x%p (currentReadSize 0x%x).\n", currentOffset, currentReadSize); #endif currentOffset += valuesFound; @@ -802,21 +806,17 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil } #ifdef DEBUG_COMMENTS //else - // DoOutputDebugString("PeParser: readMemory found nothing at 0x%x.\n", currentOffset); + // DoOutputDebugString("PeParser: readMemory found nothing at 0x%p (currentReadSize 0x%x).\n", currentOffset, currentReadSize); #endif currentReadSize = maxReadSize; currentOffset -= currentReadSize; } -#ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser: calls to readSectionFrom succeeded.\n"); -#endif - if (peFileSection.dataSize) { #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser: readSectionFrom: About to read PE section from 0x%x.\n", readOffset); + DoOutputDebugString("PeParser: readSectionFrom: About to read full PE section from 0x%p size 0x%x.\n", readOffset, peFileSection.dataSize); #endif if (isProcess) { @@ -827,6 +827,10 @@ bool PeParser::readSectionFrom(const DWORD_PTR readOffset, PeFileSection & peFil retValue = readPeSectionFromFile((DWORD)readOffset, peFileSection); } } +#ifdef DEBUG_COMMENTS + else + DoOutputDebugString("PeParser: No data read from section at 0x%p.\n", readOffset); +#endif return retValue; } @@ -850,7 +854,7 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) char *CapeName; #ifdef DEBUG_COMMENTS - DoOutputDebugString("PeParser::savePeFileToDisk: Function entry.\n"); + //DoOutputDebugString("PeParser::savePeFileToDisk: Function entry.\n"); #endif DWORD dwFileOffset = 0, dwWriteSize = 0; @@ -919,7 +923,6 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) if (!listPeSection[i].sectionHeader.PointerToRawData) continue; - if (listPeSection[i].sectionHeader.PointerToRawData > dwFileOffset) { dwWriteSize = listPeSection[i].sectionHeader.PointerToRawData - dwFileOffset; //padding @@ -934,7 +937,7 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) dwWriteSize = listPeSection[i].dataSize; - if (dwWriteSize >= pNTHeader32->OptionalHeader.FileAlignment) + if (dwWriteSize) { #ifdef DEBUG_COMMENTS DoOutputDebugString("PeParser::savePeFileToDisk: Writing section %d of size 0x%x bytes.\n", i+1, dwWriteSize); @@ -960,7 +963,10 @@ bool PeParser::savePeFileToDisk(const CHAR *newFile) dwFileOffset += dwWriteSize; } } - +#ifdef DEBUG_COMMENTS + else + DoOutputDebugString("PeParser::savePeFileToDisk: Nothing to write for section %d.\n", i+1); +#endif } //add overlay? @@ -1319,15 +1325,15 @@ void PeParser::fixPeHeader() pNTHeader32->OptionalHeader.SizeOfImage = getSectionHeaderBasedSizeOfImage(); - //if (moduleBaseAddress) - //{ - // pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; - //} - pNTHeader32->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader32->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader32->OptionalHeader.FileAlignment); + + if (moduleBaseAddress && moduleBaseAddress != pNTHeader32->OptionalHeader.ImageBase) + { + pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; #ifdef DEBUG_COMMENTS - //DoOutputDebugString("fixPeHeader: imagebase 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); + DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); #endif + } } else { @@ -1347,13 +1353,15 @@ void PeParser::fixPeHeader() pNTHeader64->OptionalHeader.SizeOfImage = getSectionHeaderBasedSizeOfImage(); - //if (moduleBaseAddress) - //{ - // pNTHeader64->OptionalHeader.ImageBase = moduleBaseAddress; - //} - pNTHeader64->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader64->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader64->OptionalHeader.FileAlignment); - //DoOutputDebugString("fixPeHeader: imagebase 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); + + if (moduleBaseAddress && moduleBaseAddress != pNTHeader64->OptionalHeader.ImageBase) + { + pNTHeader64->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); +#endif + } } removeIatDirectory(); @@ -1541,9 +1549,11 @@ bool PeParser::dumpProcess(DWORD_PTR modBase, DWORD_PTR entryPoint, const CHAR * setEntryPointVa(entryPoint); alignAllSectionHeaders(); + fixPeHeader(); getFileOverlay(); + #ifdef DEBUG_COMMENTS DoOutputDebugString("dumpProcess DEBUG: Fixups complete, about to save to disk.\n"); #endif diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index 3dd3752..b6ff1de 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -1,6 +1,6 @@ /* CAPE - Config And Payload Extraction -Copyright(C) 2015, 2016 Context Information Security. (kevin.oreilly@contextis.com) +Copyright(C) 2015 - 2018 Context Information Security. (kevin.oreilly@contextis.com) This program is free software : you can redistribute it and / or modify it under the terms of the GNU General Public License as published by @@ -153,8 +153,9 @@ void ScyllaInit(HANDLE hProcess) extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PTR NewOEP) //************************************************************************************** { - unsigned int entrypoint = 0, SectionBasedFileSize; + SIZE_T SectionBasedFileSize; PeParser * peFile = 0; + DWORD_PTR entrypoint = NULL; ScyllaInit(hProcess); @@ -165,21 +166,21 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PT if (peFile->isValidPeFile()) { if (NewOEP) - entrypoint = (unsigned int)NewOEP; + entrypoint = NewOEP; else - entrypoint = (unsigned int)peFile->getEntryPoint(); + entrypoint = peFile->getEntryPoint(); - SectionBasedFileSize = (unsigned int)peFile->getSectionHeaderBasedFileSize(); + SectionBasedFileSize = (SIZE_T)peFile->getSectionHeaderBasedFileSize(); - if (entrypoint > SectionBasedFileSize) + if ((SIZE_T)entrypoint > SectionBasedFileSize) { DoOutputDebugString("DumpProcess: Error - entry point too big: 0x%x, ignoring.\n", entrypoint); - entrypoint = 0; + entrypoint = NULL; } else { DoOutputDebugString("DumpProcess: Module entry point VA is 0x%p.\n", entrypoint); - entrypoint = entrypoint + ModuleBase; + entrypoint = entrypoint + (DWORD_PTR)ModuleBase; } if (peFile->dumpProcess(ModuleBase, entrypoint, NULL)) @@ -335,6 +336,75 @@ extern "C" int LooksLikeSectionBoundary(DWORD_PTR Buffer) } } +//************************************************************************************** +extern "C" SIZE_T GetPESize(PVOID Buffer) +//************************************************************************************** +{ + PeParser * peFile = 0; + unsigned int NumberOfSections = 0; + SIZE_T SectionBasedFileSize, SectionBasedImageSize; + + NativeWinApi::initialize(); + + ProcessAccessHelp::setCurrentProcessAsTarget(); + + peFile = new PeParser((DWORD_PTR)Buffer, TRUE); + + NumberOfSections = peFile->getNumberOfSections(); + SectionBasedFileSize = (SIZE_T)peFile->getSectionHeaderBasedFileSize(); + SectionBasedImageSize = (SIZE_T)peFile->getSectionHeaderBasedSizeOfImage(); + +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: NumberOfSections %d, SectionBasedFileSize 0x%x.\n", NumberOfSections, SectionBasedFileSize); +#endif + if (NumberOfSections == 0) + // makes no difference in this case + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: zero sections, therefore meaningless.\n"); +#endif + delete peFile; + return SectionBasedFileSize; + } + + for (unsigned int SectionIndex = 0; SectionIndex < NumberOfSections; SectionIndex++) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString + ( + "IsPeImageVirtual: Section %d, PointerToRawData 0x%x, VirtualAddress 0x%x, SizeOfRawData 0x%x, VirtualSize 0x%x.\n", + SectionIndex+1, + peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData, + peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress, + peFile->listPeSection[SectionIndex].sectionHeader.SizeOfRawData, + peFile->listPeSection[SectionIndex].sectionHeader.Misc.VirtualSize + ); +#endif + if (peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData != peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress) + { + if (LooksLikeSectionBoundary((DWORD_PTR)Buffer + peFile->listPeSection[SectionIndex].sectionHeader.PointerToRawData)) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: Found what looks like a 'raw' section boundary - image looks raw.\n"); +#endif + delete peFile; + return SectionBasedFileSize; + } + else if (LooksLikeSectionBoundary((DWORD_PTR)Buffer + peFile->listPeSection[SectionIndex].sectionHeader.VirtualAddress)) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("IsPeImageVirtual: Found what looks like a virtual section boundary - image looks virtual.\n"); +#endif + delete peFile; + return SectionBasedImageSize; + } + } + } + + delete peFile; + return SectionBasedImageSize; +} + //************************************************************************************** extern "C" int IsPeImageVirtual(DWORD_PTR Buffer) //************************************************************************************** @@ -497,7 +567,7 @@ extern "C" int ScyllaDumpCurrentProcessFixImports(DWORD_PTR NewOEP) if (addressIAT && sizeIAT) { - DoOutputDebugString(TEXT("DumpCurrentProcessFixImports: Found IAT: 0x%x, size: 0x%x"), addressIAT, sizeIAT); + DoOutputDebugString("DumpCurrentProcessFixImports: Found IAT: 0x%x, size: 0x%x", addressIAT, sizeIAT); apiReader.readAndParseIAT(addressIAT, sizeIAT, importsHandling.moduleList); importsHandling.scanAndFixModuleList(); @@ -659,7 +729,7 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase if (addressIAT && sizeIAT) { - DoOutputDebugString(TEXT("DumpProcessFixImports: Found IAT - 0x%x, size: 0x%x"), addressIAT, sizeIAT); + DoOutputDebugString("DumpProcessFixImports: Found IAT - 0x%x, size: 0x%x", addressIAT, sizeIAT); apiReader.readAndParseIAT(addressIAT, sizeIAT, importsHandling.moduleList); importsHandling.scanAndFixModuleList(); @@ -758,6 +828,42 @@ extern "C" int ScyllaDumpProcessFixImports(HANDLE hProcess, DWORD_PTR ModuleBase } delete peFile; - + return 1; } + +//************************************************************************************** +extern "C" BOOL ScyllaGetSectionByName(PVOID ImageBase, char* Name, PVOID* SectionData, SIZE_T* SectionSize) +//************************************************************************************** +{ + ScyllaInitCurrentProcess(); + + PeParser *peFile = new PeParser((DWORD_PTR)ImageBase, true); + + if (!peFile->isValidPeFile()) + { + DoOutputDebugString("ScyllaGetSectionByName: Invalid PE image.\n"); + return 0; + } + + if (!peFile->readPeSectionsFromProcess()) + { + DoOutputDebugString("ScyllaGetSectionByName: Failed to read PE sections from image.\n"); + return 0; + } + + unsigned int NumberOfSections = peFile->getNumberOfSections(); + + for (unsigned int i = 0; i < NumberOfSections; i++) + { + if (!strcmp((char*)peFile->listPeSection[i].sectionHeader.Name, Name)) + { + *SectionData = peFile->listPeSection[i].sectionHeader.VirtualAddress + (PUCHAR)ImageBase; + *SectionSize = peFile->listPeSection[i].sectionHeader.Misc.VirtualSize; + DoOutputDebugString("ScyllaGetSectionByName: %s section at 0x%p size 0x%x.\n", Name, *SectionData, *SectionSize); + return TRUE; + } + } + + return FALSE; +} \ No newline at end of file diff --git a/README.md b/README.md index 315deeb..6459338 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,26 @@ -This fork aims to continue the work of the heavily modified version of the upstream [Cuckoo Sandbox](http://www.cuckoosandbox.org) cuckoomon provided under the GPL by Optiv. +## capemon: The monitor DLLs for CAPE: Config And Payload Extraction (https://github.com/ctxis/CAPE). -32/64-bit compiled versions of this software are provided in our cuckoo-modified repository. -Please see that repository for more information on the changes to this edition of cuckoomon. +Much of the functionality of CAPE is contained within the monitor DLLs; the CAPE debugger and the different CAPE 'packages' are implemented within the DLLs. This repository is organised in branches for each of the packages. + +The 'standard' package is in the capemon branch. + +The three 'behavioural' packages are contained within the following branches: + +- Compression +- Extraction +- Injection + +These are designed to dump malware payloads associated with the respective behaviours. + +Additional malware-specific packages are within the following branches: + +- Cerber +- EvilGrab +- PlugX +- Sedreco + +These allow for the extraction of both payloads and malware configuration from the respective malware families. + +There is also a UPX package to dynamically unpack 'hacked' UPX binaries. + +CAPE is an extension of Cuckoo specifically designed to extract payloads and configuration from malware. It is derived from spender-sandbox, which is derived from Cuckoo Sandbox, so thanks to Brad Spengler, Claudio Guarnieri, and the countless other Cuckoo contributors without whom this work would not be possible. diff --git a/config.c b/config.c index f4df68a..e82e07c 100644 --- a/config.c +++ b/config.c @@ -24,7 +24,7 @@ along with this program. If not, see . #include "hooking.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern DWORD_PTR CAPE_var1, CAPE_var2, CAPE_var3, CAPE_var4; +extern PVOID bp0, bp1, bp2, bp3; int read_config(void) { @@ -218,21 +218,37 @@ int read_config(void) p = p2 + 1; } } - else if (!strcmp(key, "CAPE_var1")) { - CAPE_var1 = (DWORD_PTR)strtoul(value, NULL, 10); - DoOutputDebugString("CAPE_var1 set to 0x%x", CAPE_var1); + else if (!strcmp(key, "base-on-api")) { + unsigned int x = 0; + char *p2; + p = value; + while (p && x < EXCLUSION_MAX) { + p2 = strchr(p, ':'); + if (p2) { + *p2 = '\0'; + } + g_config.base_on_apiname[x++] = strdup(p); + DoOutputDebugString("Added '%s' to base-on-API list.\n", p); + if (p2 == NULL) + break; + p = p2 + 1; + } + } + else if (!strcmp(key, "bp0")) { + bp0 = (PVOID)strtoul(value, NULL, 10); + DoOutputDebugString("bp0 set to 0x%x", bp0); } - else if (!strcmp(key, "CAPE_var2")) { - CAPE_var2 = (DWORD_PTR)strtoul(value, NULL, 10); - DoOutputDebugString("CAPE_var2 set to 0x%x", CAPE_var2); + else if (!strcmp(key, "bp1")) { + bp1 = (PVOID)strtoul(value, NULL, 10); + DoOutputDebugString("bp1 set to 0x%x", bp1); } - else if (!strcmp(key, "CAPE_var3")) { - CAPE_var3 = (DWORD_PTR)strtoul(value, NULL, 10); - DoOutputDebugString("CAPE_var3 set to 0x%x", CAPE_var3); + else if (!strcmp(key, "bp2")) { + bp2 = (PVOID)strtoul(value, NULL, 10); + DoOutputDebugString("bp2 set to 0x%x", bp2); } - else if (!strcmp(key, "CAPE_var4")) { - CAPE_var4 = (DWORD_PTR)strtoul(value, NULL, 10); - DoOutputDebugString("CAPE_var4 set to 0x%x", CAPE_var4); + else if (!strcmp(key, "bp3")) { + bp3 = (PVOID)strtoul(value, NULL, 10); + DoOutputDebugString("bp3 set to 0x%x", bp3); } else if (!strcmp(key, "procdump")) { g_config.procdump = value[0] == '1'; diff --git a/config.h b/config.h index 2d67042..d60503f 100644 --- a/config.h +++ b/config.h @@ -104,6 +104,7 @@ struct _g_config { char *excluded_apinames[EXCLUSION_MAX]; wchar_t *excluded_dllnames[EXCLUSION_MAX]; + char *base_on_apiname[EXCLUSION_MAX]; // should we dump each process on exit/analysis timeout? int procdump; diff --git a/cuckoomon.c b/cuckoomon.c index 7f182cd..5a58e0f 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -30,13 +30,13 @@ along with this program. If not, see . #include "config.h" #include "unhook.h" #include "bson.h" -#include "CAPE\CAPE.h" -#include "CAPE\Debugger.h" volatile int dummy_val; extern void init_CAPE(); extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo); +extern ULONG_PTR base_of_dll_of_interest; void disable_tail_call_optimization(void) { @@ -293,7 +293,6 @@ static hook_t g_hooks[] = { HOOK(ntdll, NtCreateEvent), HOOK(ntdll, NtOpenEvent), HOOK(ntdll, NtCreateNamedPipeFile), - HOOK(ntdll, NtAddAtom), HOOK(ntdll, NtAddAtomEx), HOOK(ntdll, NtFindAtom), @@ -357,13 +356,18 @@ static hook_t g_hooks[] = { HOOK(kernel32, CreateThread), HOOK(kernel32, CreateRemoteThread), HOOK(ntdll, RtlCreateUserThread), + HOOK(ntdll, NtSetInformationThread), + HOOK(ntdll, NtQueryInformationThread), // // Misc Hooks // - - //HOOK(msvcrt, memcpy), - //HOOK(ntdll, memcpy), +#ifndef _WIN64 + HOOK(ntdll, memcpy), +#endif + HOOK(msvcrt, memcpy), + //HOOK(kernel32, SizeofResource), + HOOK(msvcrt, srand), // for debugging only //HOOK(kernel32, GetLastError), @@ -371,7 +375,7 @@ static hook_t g_hooks[] = { HOOK(user32, SetWindowsHookExA), HOOK(user32, SetWindowsHookExW), HOOK(user32, UnhookWindowsHookEx), - //HOOK(kernel32, SetUnhandledExceptionFilter), + HOOK(kernel32, SetUnhandledExceptionFilter), HOOK(ntdll, RtlAddVectoredExceptionHandler), HOOK(kernel32, SetErrorMode), HOOK(ntdll, LdrGetDllHandle), @@ -399,6 +403,7 @@ static hook_t g_hooks[] = { HOOK(user32, GetAsyncKeyState), HOOK(ntdll, NtLoadDriver), HOOK(ntdll, NtSetInformationProcess), + //HOOK(ntdll, NtQueryInformationProcess), HOOK(ntdll, RtlDecompressBuffer), HOOK(ntdll, RtlCompressBuffer), HOOK(kernel32, GetSystemInfo), @@ -641,7 +646,7 @@ void revalidate_all_hooks(void) PVOID g_dll_notify_cookie; -VOID CALLBACK DllLoadNotification( +VOID CALLBACK New_DllLoadNotification( _In_ ULONG NotificationReason, _In_ const PLDR_DLL_NOTIFICATION_DATA NotificationData, _In_opt_ PVOID Context) @@ -654,19 +659,23 @@ VOID CALLBACK DllLoadNotification( /* Just for debug purposes, gives a stripped fake function name */ LOQ_void("system", "sup", "NotificationReason", NotificationReason == 1 ? "load" : "unload", "DllName", library.Buffer, "DllBase", NotificationReason == 1 ? NotificationData->Loaded.DllBase : NotificationData->Unloaded.DllBase); } - + if (NotificationReason == 1) { + if (g_config.file_of_interest && !wcsicmp(library.Buffer, g_config.file_of_interest)) { + if (base_of_dll_of_interest) + DoOutputDebugString("Target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); + else + set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); + } + else { + // unoptimized, but easy + add_all_dlls_to_dll_ranges(); - if (g_config.file_of_interest && !wcsicmp(library.Buffer, g_config.file_of_interest)) - set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); - - // unoptimized, but easy - add_all_dlls_to_dll_ranges(); - - dllname = get_dll_basename(&library); - set_hooks_dll(dllname); + dllname = get_dll_basename(&library); + set_hooks_dll(dllname); - DoOutputDebugString("DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); + DoOutputDebugString("DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); + } } else { // unload @@ -680,8 +689,6 @@ VOID CALLBACK DllLoadNotification( extern _LdrRegisterDllNotification pLdrRegisterDllNotification; -CRITICAL_SECTION g_tmp_hookinfo_lock; - void set_hooks() { // before modifying any DLLs, let's first freeze all other threads in our process @@ -698,14 +705,14 @@ void set_hooks() // the hooks contain executable code as well, so they have to be RWX DWORD old_protect; - InitializeCriticalSection(&g_tmp_hookinfo_lock); - VirtualProtect(g_hooks, sizeof(g_hooks), PAGE_EXECUTE_READWRITE, &old_protect); memset(&threadInfo, 0, sizeof(threadInfo)); threadInfo.dwSize = sizeof(threadInfo); + hook_init(); + hook_disable(); hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); @@ -735,9 +742,9 @@ void set_hooks() free(suspended_threads); if (pLdrRegisterDllNotification) - pLdrRegisterDllNotification(0, &DllLoadNotification, NULL, &g_dll_notify_cookie); + pLdrRegisterDllNotification(0, &New_DllLoadNotification, NULL, &g_dll_notify_cookie); else - register_dll_notification_manually(&DllLoadNotification); + register_dll_notification_manually(&New_DllLoadNotification); hook_enable(); } @@ -786,14 +793,16 @@ LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *Excepti } #endif - if (g_config.debug == 1 && ExceptionInfo->ExceptionRecord->ExceptionCode < 0xc0000000) return EXCEPTION_CONTINUE_SEARCH; if (ExceptionInfo->ExceptionRecord->ExceptionCode == DBG_PRINTEXCEPTION_C) return EXCEPTION_CONTINUE_SEARCH; - if (DEBUGGER_ENABLED && ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) + if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) + return CAPEExceptionFilter(ExceptionInfo); + + if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION) return CAPEExceptionFilter(ExceptionInfo); hook_disable(); @@ -846,6 +855,7 @@ LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *Excepti eipptr[0], eipptr[1], eipptr[2], eipptr[3], eipptr[4], eipptr[5], eipptr[6], eipptr[7], eipptr[8], eipptr[9], eipptr[10], eipptr[11], eipptr[12], eipptr[13], eipptr[14], eipptr[15]); } debug_message(msg); + DoOutputDebugString(msg); if (dllname) free(dllname); free(msg); @@ -960,7 +970,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) if (!memcmp((PUCHAR)WaitForDebugEvent, "\x8b\xff\xff\x25", 4) || !memcmp((PUCHAR)WaitForDebugEvent, "\xff\x25", 2) || !memcmp((PUCHAR)WaitForDebugEvent, "\x8b\xff\xe9", 3) || !memcmp((PUCHAR)WaitForDebugEvent, "\xe9", 1) || !memcmp((PUCHAR)WaitForDebugEvent, "\xeb\xf9", 2)) - goto early_abort; + goto abort; g_our_dll_base = (ULONG_PTR)hModule; g_our_dll_size = get_image_size(g_our_dll_base); @@ -985,7 +995,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) g_tls_hook_index = TlsAlloc(); if (g_tls_hook_index == TLS_OUT_OF_INDEXES) - goto early_abort; + goto abort; // adds our own DLL range as well, since the hiding is done later add_all_dlls_to_dll_ranges(); @@ -996,12 +1006,12 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) ; #else // if we're not debugging, then failure to read the cuckoomon config should be a critical error - goto early_abort; + goto abort; #endif // don't inject into our own binaries run out of the analyzer directory unless they're the first process (intended) if (wcslen(g_config.w_analyzer) && !wcsnicmp(our_process_path, g_config.w_analyzer, wcslen(g_config.w_analyzer)) && !g_config.first_process) - goto out; + goto abort; if (g_config.debug) { AddVectoredExceptionHandler(1, cuckoomon_exception_handler); @@ -1076,13 +1086,12 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) } g_dll_main_complete = TRUE; - -out: set_lasterrors(&lasterror); return TRUE; -early_abort: + +abort: sprintf(config_fname, "C:\\%u.ini", GetCurrentProcessId()); DeleteFileA(config_fname); set_lasterrors(&lasterror); - return TRUE; + return FALSE; } diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index 9cf051e..d1ce263 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -137,7 +137,7 @@ - WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) + WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions) MultiThreaded Level3 ProgramDatabase @@ -199,6 +199,7 @@ + diff --git a/cuckoomon.vcxproj.filters b/cuckoomon.vcxproj.filters index 2e08dd6..cbb1656 100644 --- a/cuckoomon.vcxproj.filters +++ b/cuckoomon.vcxproj.filters @@ -276,6 +276,9 @@ Source Files\CAPE\Scylla + + Source Files\CAPE + diff --git a/hook_crypto.c b/hook_crypto.c index acf3bbb..59ee66b 100644 --- a/hook_crypto.c +++ b/hook_crypto.c @@ -119,8 +119,8 @@ HOOKDEF(BOOL, WINAPI, CryptDecrypt, ) { BOOL ret = Old_CryptDecrypt(hKey, hHash, Final, dwFlags, pbData, pdwDataLen); - LOQ_bool("crypto", "ppBi", "CryptKey", hKey, "CryptHash", hHash, - "Buffer", pdwDataLen, pbData, "Final", Final); + LOQ_bool("crypto", "ppBii", "CryptKey", hKey, "CryptHash", hHash, + "Buffer", pdwDataLen, pbData, "Length", *pdwDataLen, "Final", Final); return ret; } @@ -134,8 +134,8 @@ HOOKDEF(BOOL, WINAPI, CryptEncrypt, _In_ DWORD dwBufLen ) { BOOL ret = 1; - LOQ_bool("crypto", "ppbi", "CryptKey", hKey, "CryptHash", hHash, - "Buffer", dwBufLen, pbData, "Final", Final); + LOQ_bool("crypto", "ppbii", "CryptKey", hKey, "CryptHash", hHash, + "Buffer", dwBufLen, pbData, "Length", *pdwDataLen, "Final", Final); ret = Old_CryptEncrypt(hKey, hHash, Final, dwFlags, pbData, pdwDataLen, dwBufLen); disable_tail_call_optimization(); return ret; diff --git a/hook_file.c b/hook_file.c index 8e4b584..94e7749 100644 --- a/hook_file.c +++ b/hook_file.c @@ -33,6 +33,8 @@ along with this program. If not, see . // length of a hardcoded unicode string #define UNILEN(x) (sizeof(x) / sizeof(wchar_t) - 1) +extern BOOL FilesDumped; + typedef struct _file_record_t { unsigned int attributes; size_t length; @@ -240,29 +242,48 @@ void file_close(HANDLE file_handle) get_lasterrors(&lasterror); r = lookup_get(&g_files, (ULONG_PTR)file_handle, NULL); - if(r != NULL) { + if (r != NULL) { UNICODE_STRING str; str.Length = (USHORT)r->length * sizeof(wchar_t); str.MaximumLength = ((USHORT)r->length + 1) * sizeof(wchar_t); str.Buffer = r->filename; - new_file(&str); - lookup_del(&g_files, (ULONG_PTR) file_handle); } set_lasterrors(&lasterror); } -void handle_terminate() +void file_handle_terminate() { - entry_t *p; + entry_t *p; + file_record_t *r; + lasterror_t lasterror; + + // ensure this only happens once as we can't lookup_del in the loop + if (FilesDumped) + return; + + FilesDumped = TRUE; + + get_lasterrors(&lasterror); for (p = (entry_t*)&(g_files.root); p != NULL; p = p->next) { - if (p->id) - file_close((HANDLE)p->id); + if (p->id) { + r = lookup_get(&g_files, (ULONG_PTR)p->id, NULL); + if (r != NULL) { + UNICODE_STRING str; + str.Length = (USHORT)r->length * sizeof(wchar_t); + str.MaximumLength = ((USHORT)r->length + 1) * sizeof(wchar_t); + str.Buffer = r->filename; + new_file(&str); + } + } } + + set_lasterrors(&lasterror); } + static BOOLEAN is_protected_objattr(POBJECT_ATTRIBUTES obj) { wchar_t path[MAX_PATH_PLUS_TOLERANCE]; @@ -417,7 +438,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtReadFile, if (read_count < 50) LOQ_ntstatus("filesystem", "pFbl", "FileHandle", FileHandle, "HandleName", fname, "Buffer", InitialBufferLength, InitialBuffer, "Length", AccumulatedLength); - else if (read_count == 50) + else LOQ_ntstatus("filesystem", "pFbls", "FileHandle", FileHandle, "HandleName", fname, "Buffer", InitialBufferLength, InitialBuffer, "Length", AccumulatedLength, "Status", "Maximum logged reads reached for this file"); @@ -826,7 +847,6 @@ HOOKDEF_ALT(BOOL, WINAPI, MoveFileWithProgressW, // we can do this here because it's not scheduled for deletion until reboot pipe("FILE_DEL:%Z", path); } - } free(path); @@ -885,7 +905,6 @@ HOOKDEF_ALT(BOOL, WINAPI, MoveFileWithProgressTransactedW, // we can do this here because it's not scheduled for deletion until reboot pipe("FILE_DEL:%Z", path); } - } free(path); @@ -1286,25 +1305,6 @@ HOOKDEF(BOOL, WINAPI, GetVolumeInformationA, { BOOL ret = Old_GetVolumeInformationA(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize); LOQ_bool("filesystem", "s", "RootPathName", lpRootPathName); -#ifdef KEV - if (ret != 0 && lpVolumeSerialNumber != NULL) - { - char SystemDirectory[MAX_PATH]; - size_t DirectoryPathLength = GetSystemDirectoryA(SystemDirectory, MAX_PATH); - - if (DirectoryPathLength == 0) - return ret; - - if (!strncmp(lpRootPathName, SystemDirectory, 3)) - { - *lpVolumeSerialNumber = 0x46e70ca9; - debug_message("Changed Volume Serial Number."); - } - - - - } -#endif return ret; } @@ -1321,22 +1321,6 @@ HOOKDEF(BOOL, WINAPI, GetVolumeInformationW, { BOOL ret = Old_GetVolumeInformationW(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize); LOQ_bool("filesystem", "u", "RootPathName", lpRootPathName); -#ifdef KEV - if (ret != 0 && lpVolumeSerialNumber != NULL) - { - WCHAR SystemDirectory[MAX_PATH]; - size_t DirectoryPathLength = GetSystemDirectoryW(SystemDirectory, MAX_PATH); - - if (DirectoryPathLength == 0) - return ret; - - if (!wcsncmp(lpRootPathName, SystemDirectory, 3)) - { - *lpVolumeSerialNumber = 0x46e70ca9; - debug_message("Changed Volume Serial Number."); - } - } -#endif return ret; } diff --git a/hook_misc.c b/hook_misc.c index f8d94fd..0836d57 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -26,9 +26,13 @@ along with this program. If not, see . #include "hook_sleep.h" #include "config.h" #include "ignore.h" +#include "CAPE\CAPE.h" +#include "CAPE\Debugger.h" #define STATUS_BAD_COMPRESSION_BUFFER ((NTSTATUS)0xC0000242L) +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); + HOOKDEF(HHOOK, WINAPI, SetWindowsHookExA, __in int idHook, __in HOOKPROC lpfn, @@ -100,11 +104,34 @@ HOOKDEF(PVOID, WINAPI, RtlAddVectoredExceptionHandler, __out PVECTORED_EXCEPTION_HANDLER Handler ) { PVOID ret = 0; - - ret = Old_RtlAddVectoredExceptionHandler(First, Handler); - + + if (DEBUGGER_ENABLED && VECTORED_HANDLER && First) + { + if (!CAPEExceptionFilterHandle) + { + DoOutputDebugString("RtlAddVectoredExceptionHandler hook: Error - CAPE vectored handler not registered.\n"); + ret = Old_RtlAddVectoredExceptionHandler(First, Handler); + LOQ_nonnull("hooking", "ip", "First", First, "Handler", Handler); + return ret; + } + + // We register the handler at the bottom, this minimizes + // our interference and means the handle is valid + ret = Old_RtlAddVectoredExceptionHandler(0, Handler); + + if (ret == NULL) + return ret; + + // We record the handler address so that + // CAPEExceptionFilter can call it directly + DoOutputDebugString("RtlAddVectoredExceptionHandler hook: CAPE vectored handler protected as First.\n"); + SampleVectoredHandler = (SAMPLE_HANDLER)Handler; + } + else + ret = Old_RtlAddVectoredExceptionHandler(First, Handler); + LOQ_nonnull("hooking", "ip", "First", First, "Handler", Handler); - + return ret; } @@ -459,10 +486,11 @@ static int lasty; HOOKDEF(BOOL, WINAPI, GetCursorPos, _Out_ LPPOINT lpPoint ) { + ENSURE_STRUCT(lpPoint, POINT); BOOL ret = Old_GetCursorPos(lpPoint); /* work around the fact that skipping sleeps prevents the human module from making the system look active */ - if (lpPoint && time_skipped.QuadPart != last_skipped.QuadPart) { + if (ret && time_skipped.QuadPart != last_skipped.QuadPart) { int xres, yres; xres = our_GetSystemMetrics(0); yres = our_GetSystemMetrics(1); @@ -485,9 +513,13 @@ HOOKDEF(BOOL, WINAPI, GetCursorPos, last_skipped.QuadPart = time_skipped.QuadPart; } - LOQ_bool("misc", "ii", "x", lpPoint != NULL ? lpPoint->x : 0, - "y", lpPoint != NULL ? lpPoint->y : 0); - + if (ret){ + LOQ_bool("misc", "ii", "x", lpPoint != NULL ? lpPoint->x : 0, + "y", lpPoint != NULL ? lpPoint->y : 0); + } + else{ + LOQ_bool("misc", "ii", "x", 0, "y", 0); + } return ret; } @@ -626,11 +658,25 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetInformationProcess, __in ULONG ProcessInformationLength ) { NTSTATUS ret = Old_NtSetInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength); - if (NT_SUCCESS(ret) && (ProcessInformationClass == ProcessInfoDEPPolicy || ProcessInformationClass == ProcessBreakOnTermination) && ProcessInformationLength == 4) - LOQ_ntstatus("misc", "ii", "ProcessInformationClass", ProcessInformationClass, "Value", *(int *)ProcessInformation); + if ((ProcessInformationClass == ProcessExecuteFlags || ProcessInformationClass == ProcessBreakOnTermination) && ProcessInformationLength == 4) + LOQ_ntstatus("process", "ii", "ProcessInformationClass", ProcessInformationClass, "ProcessInformation", *(int*)ProcessInformation); + else + LOQ_ntstatus("process", "ib", "ProcessInformationClass", ProcessInformationClass, "ProcessInformation", ProcessInformationLength, ProcessInformation); return ret; } +HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationProcess, + IN HANDLE ProcessHandle, + IN PROCESSINFOCLASS ProcessInformationClass, + OUT PVOID ProcessInformation, + IN ULONG ProcessInformationLength, + OUT PULONG ReturnLength OPTIONAL +) { + NTSTATUS ret = Old_NtQueryInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength); + LOQ_ntstatus("process", "ib", "ProcessInformationClass", ProcessInformationClass, "ProcessInformation", ProcessInformationLength, ProcessInformation); + return ret; +} + HOOKDEF(NTSTATUS, WINAPI, NtQuerySystemInformation, _In_ ULONG SystemInformationClass, _Inout_ PVOID SystemInformation, diff --git a/hook_process.c b/hook_process.c index ad00b5a..50a3e07 100644 --- a/hook_process.c +++ b/hook_process.c @@ -19,7 +19,6 @@ along with this program. If not, see . #include #include "ntapi.h" #include -#include #include "hooking.h" #include "log.h" #include "pipe.h" @@ -28,14 +27,18 @@ along with this program. If not, see . #include "hook_sleep.h" #include "unhook.h" #include "config.h" -#include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); -extern int DumpMemory(LPVOID Buffer, SIZE_T Size); -extern int DumpImageInCurrentProcess(PVOID ImageBase); -extern int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); -extern PVOID get_process_image_base(HANDLE process_handle); +extern void file_handle_terminate(); +extern int RoutineProcessDump(); +extern BOOL ProcessDumped; +#ifdef CAPE_INJECTION +extern void OpenProcessHandler(PHANDLE ProcessHandle, int Pid); +extern void ResumeProcessHandler(HANDLE ProcessHandle); +extern void UnmapSectionViewHandler(PVOID BaseAddress); +extern void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, PSIZE_T ViewSize); +extern void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesToWrite, PSIZE_T NumberOfBytesWritten); +#endif HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -218,21 +221,33 @@ HOOKDEF(BOOL, WINAPI, CreateProcessWithLogonW, ) { BOOL ret; LPWSTR origcommandline = NULL; - + ENSURE_STRUCT(lpProcessInfo, PROCESS_INFORMATION); + if (lpCommandLine) origcommandline = wcsdup(lpCommandLine); ret = Old_CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInfo); - LOQ_bool("process", "uuuhuuhiipp", "Username", lpUsername, "Domain", lpDomain, "Password", lpPassword, "LogonFlags", dwLogonFlags, "ApplicationName", lpApplicationName, "CommandLine", origcommandline, "CreationFlags", dwCreationFlags, - "ProcessId", lpProcessInfo->dwProcessId, "ThreadId", lpProcessInfo->dwThreadId, "ProcessHandle", lpProcessInfo->hProcess, "ThreadHandle", lpProcessInfo->hThread); + LOQ_bool("process", "uuuhuuhiipp", + "Username", lpUsername, + "Domain", lpDomain, + "Password", lpPassword, + "LogonFlags", dwLogonFlags, + "ApplicationName", lpApplicationName, + "CommandLine", origcommandline, + "CreationFlags", dwCreationFlags, + "ProcessId", lpProcessInfo->dwProcessId, + "ThreadId", lpProcessInfo->dwThreadId, + "ProcessHandle", lpProcessInfo->hProcess, + "ThreadHandle", lpProcessInfo->hThread + ); if (origcommandline) free(origcommandline); if (ret) { pipe("PROCESS:%d:%d,%d", is_suspended(lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId), lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId); - if (!(dwCreationFlags & CREATE_SUSPENDED)) + if (!(dwCreationFlags & CREATE_SUSPENDED) && is_valid_address_range((ULONG_PTR)lpProcessInfo, (DWORD)sizeof(PROCESS_INFORMATION))) ResumeThread(lpProcessInfo->hThread); disable_sleep_skip(); } @@ -258,13 +273,35 @@ HOOKDEF(BOOL, WINAPI, CreateProcessWithTokenW, ret = Old_CreateProcessWithTokenW(hToken, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInfo); - LOQ_bool("process", "huuhiipp", "LogonFlags", dwLogonFlags, "ApplicationName", lpApplicationName, "CommandLine", origcommandline, "CreationFlags", dwCreationFlags, - "ProcessId", lpProcessInfo->dwProcessId, "ThreadId", lpProcessInfo->dwThreadId, "ProcessHandle", lpProcessInfo->hProcess, "ThreadHandle", lpProcessInfo->hThread); + if (lpProcessInfo) { + LOQ_bool("process", "huuhiipp", + "LogonFlags", dwLogonFlags, + "ApplicationName", lpApplicationName, + "CommandLine", origcommandline, + "CreationFlags", dwCreationFlags, + "ProcessId", lpProcessInfo->dwProcessId, + "ThreadId", lpProcessInfo->dwThreadId, + "ProcessHandle", lpProcessInfo->hProcess, + "ThreadHandle", lpProcessInfo->hThread + ); + } + else { + LOQ_bool("process", "huuhiipp", + "LogonFlags", dwLogonFlags, + "ApplicationName", lpApplicationName, + "CommandLine", origcommandline, + "CreationFlags", dwCreationFlags, + "ProcessId", NULL, + "ThreadId", NULL, + "ProcessHandle", NULL, + "ThreadHandle", NULL + ); + } if (origcommandline) free(origcommandline); - if (ret) { + if (ret && lpProcessInfo) { pipe("PROCESS:%d:%d,%d", is_suspended(lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId), lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId); if (!(dwCreationFlags & CREATE_SUSPENDED)) ResumeThread(lpProcessInfo->hThread); @@ -282,12 +319,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, // although the documentation on msdn is a bit vague, this seems correct // for both XP and Vista (the ClientId->UniqueProcess part, that is) - NTSTATUS ret; - struct InjectionInfo *CurrentInjectionInfo; - DWORD BufferSize = MAX_PATH; - char DevicePath[MAX_PATH]; - unsigned int PathLength; int pid = 0; + NTSTATUS ret; if(ClientId != NULL) { __try { @@ -305,55 +338,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, return ret; } +#ifdef CAPE_INJECTION + OpenProcessHandler(ProcessHandle, pid); +#endif ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); - - if (NT_SUCCESS(ret) && pid != GetCurrentProcessId()) {// && (DesiredAccess & (PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_SUSPEND_RESUME))){ - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (CurrentInjectionInfo == NULL) - { // First call for this process, create new info - CurrentInjectionInfo = CreateInjectionInfo(pid); - DoOutputDebugString("NtOpenProcess: Injection info created for pid %d.\n", pid); - - if (CurrentInjectionInfo == NULL) - { - DoOutputDebugString("NtOpenProcess: Cannot create new injection info - FATAL ERROR.\n"); - } - else - { - CurrentInjectionInfo->ProcessHandle = *ProcessHandle; - CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; - CurrentInjectionInfo->ImageDumped = FALSE; - CapeMetaData->TargetProcess = (char*)malloc(BufferSize); - - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - - if (!CurrentInjectionInfo->ImageBase) - DoOutputDebugString("NtOpenProcess: Error obtaining target process image base for process %d (handle 0x%x).\n", pid, *ProcessHandle); - else - DoOutputDebugString("NtOpenProcess: Image base for process %d (handle 0x%x): 0x%p.\n", pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); - - PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); - - if (!PathLength) - { - DoOutputErrorString("NtOpenProcess: Error obtaining target process name"); - _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); - } - else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) - DoOutputErrorString("NtOpenProcess: Error translating target process path"); - } - } - else if (CurrentInjectionInfo->ImageBase == (DWORD_PTR)NULL) - { - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - - if (CurrentInjectionInfo->ImageBase) - DoOutputDebugString("NtOpenProcess: Image base for process %d (handle 0x%x): 0x%p.\n", pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); - } - } - LOQ_ntstatus("process", "Phi", "ProcessHandle", ProcessHandle, "DesiredAccess", DesiredAccess, "ProcessIdentifier", pid); @@ -365,39 +354,15 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, __in HANDLE ProcessHandle ) { NTSTATUS ret; - struct InjectionInfo *CurrentInjectionInfo; - - DWORD pid = pid_from_process_handle(ProcessHandle); + DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (CurrentInjectionInfo) - { - if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) - { - SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - - DoOutputDebugString("NtResumeProcess hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); - - CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); - - if (CurrentInjectionInfo->ImageDumped) - { - DoOutputDebugString("NtResumeProcess hook: Dumped PE image from buffer.\n"); - } - else - DoOutputDebugString("NtResumeProcess hook: Failed to dump PE image from buffer.\n"); - } - - DumpSectionViewsForPid(pid); - } - ret = Old_NtResumeProcess(ProcessHandle); LOQ_ntstatus("process", "p", "ProcessHandle", ProcessHandle); return ret; } + int process_shutting_down; HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, @@ -413,14 +378,26 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, // we mark this here as this termination type will kill all threads but ours, including // the logging thread. By setting this, we'll switch into a direct logging mode // for the subsequent call to NtTerminateProcess against our own process handle + if (g_config.procdump && !ProcessDumped) + { + DoOutputDebugString("NtTerminateProcess hook: Attempting to dump process %d\n", GetCurrentProcessId()); + RoutineProcessDump(); + } process_shutting_down = 1; LOQ_ntstatus("process", "ph", "ProcessHandle", ProcessHandle, "ExitCode", ExitStatus); + file_handle_terminate(); } else if (GetCurrentProcessId() == our_getprocessid(ProcessHandle)) { + if (g_config.procdump && !ProcessDumped) + { + DoOutputDebugString("NtTerminateProcess hook: Attempting to dump process %d\n", GetCurrentProcessId()); + RoutineProcessDump(); + } process_shutting_down = 1; LOQ_ntstatus("process", "ph", "ProcessHandle", ProcessHandle, "ExitCode", ExitStatus); pipe("KILL:%d", GetCurrentProcessId()); log_free(); + file_handle_terminate(); } else { DWORD PID = pid_from_process_handle(ProcessHandle); @@ -497,33 +474,20 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, _In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress ) { - PINJECTIONSECTIONVIEW CurrentSectionView; SIZE_T map_size = 0; MEMORY_BASIC_INFORMATION mbi; DWORD pid = pid_from_process_handle(ProcessHandle); - DWORD protect = PAGE_READWRITE; NTSTATUS ret; if (VirtualQueryEx(ProcessHandle, BaseAddress, &mbi, sizeof(mbi)) == sizeof(mbi)) { map_size = mbi.RegionSize; - protect = mbi.Protect; } - - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) - { - DoOutputDebugString("NtUnmapViewOfSection hook: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); - DumpSectionView(CurrentSectionView); - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } - ret = Old_NtUnmapViewOfSection(ProcessHandle, BaseAddress); +#ifdef CAPE_INJECTION + UnmapSectionViewHandler(BaseAddress); +#endif + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", map_size); @@ -541,93 +505,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, __in UINT InheritDisposition, __in ULONG AllocationType, __in ULONG Win32Protect -) { - struct InjectionInfo *CurrentInjectionInfo; - struct InjectionSectionView *CurrentSectionViewInfo; - char DevicePath[MAX_PATH]; - unsigned int PathLength; - DWORD BufferSize = MAX_PATH; - - NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, + ) { + NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); - - DWORD pid = pid_from_process_handle(ProcessHandle); - - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (pid == GetCurrentProcessId()) - { - PINJECTIONSECTIONVIEW CurrentSectionView = GetSectionView(SectionHandle); - - if (!CurrentSectionView) - { - AddSectionView(SectionHandle, *BaseAddress, *ViewSize); - DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, *BaseAddress); - } - else - { - if (NT_SUCCESS(ret) && CurrentSectionView->LocalView != *BaseAddress) - { - CurrentSectionView->LocalView = *BaseAddress; - CurrentSectionView->ViewSize = *ViewSize; - DoOutputDebugString("NtMapViewOfSection hook: Updated local view to 0x%x for section view with handle 0x%x.\n", *BaseAddress, SectionHandle); - } - } - } - else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - { - CurrentSectionViewInfo = AddSectionView(SectionHandle, *BaseAddress, *ViewSize); + DWORD pid = pid_from_process_handle(ProcessHandle); - if (CurrentSectionViewInfo) - { - CurrentSectionViewInfo->TargetProcessId = pid; - DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); - } - else - { - DoOutputDebugString("NtMapViewOfSection hook: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, pid); - } - } - else if (!CurrentInjectionInfo && pid != GetCurrentProcessId()) - { - CurrentInjectionInfo = CreateInjectionInfo(pid); - - if (CurrentInjectionInfo == NULL) - { - DoOutputDebugString("NtMapViewOfSection hook: Cannot create new injection info - FATAL ERROR.\n"); - } - else - { - CurrentInjectionInfo->ProcessHandle = ProcessHandle; - CurrentInjectionInfo->ProcessId = pid; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); - CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; - CurrentInjectionInfo->ImageDumped = FALSE; - CapeMetaData->TargetProcess = (char*)malloc(BufferSize); - - PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); - - if (!PathLength) - { - DoOutputErrorString("NtMapViewOfSection hook: Error obtaining target process name"); - _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); - } - else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) - DoOutputErrorString("NtMapViewOfSection hook: Error translating target process path"); - - CurrentSectionViewInfo = AddSectionView(SectionHandle, *BaseAddress, *ViewSize); - - if (CurrentSectionViewInfo) - { - CurrentSectionViewInfo->TargetProcessId = pid; - DoOutputDebugString("NtMapViewOfSection hook: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, pid); - } - else - DoOutputDebugString("NtMapViewOfSection hook: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, pid); - } - } - LOQ_ntstatus("process", "ppPpPhs", "SectionHandle", SectionHandle, "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); @@ -636,6 +519,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, if (pid != GetCurrentProcessId()) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); +#ifdef CAPE_INJECTION + MapSectionViewHandler(SectionHandle, ProcessHandle, *BaseAddress, ViewSize); +#endif } } return ret; @@ -671,11 +557,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtReadVirtualMemory, NTSTATUS ret; ENSURE_SIZET(NumberOfBytesRead); - ret = Old_NtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, - NumberOfBytesToRead, NumberOfBytesRead); + ret = Old_NtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToRead, NumberOfBytesRead); - LOQ_ntstatus("process", "ppB", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "Buffer", NumberOfBytesRead, Buffer); + LOQ_ntstatus("process", "pphB", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "Size", NumberOfBytesToRead, "Buffer", NumberOfBytesRead, Buffer); return ret; } @@ -690,11 +574,9 @@ HOOKDEF(BOOL, WINAPI, ReadProcessMemory, BOOL ret; ENSURE_SIZET(lpNumberOfBytesRead); - ret = Old_ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, - nSize, lpNumberOfBytesRead); + ret = Old_ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead); - LOQ_bool("process", "ppB", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, - "Buffer", lpNumberOfBytesRead, lpBuffer); + LOQ_bool("process", "pphB", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, "Size", nSize, "Buffer", lpNumberOfBytesRead, lpBuffer); return ret; } @@ -708,100 +590,27 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, ) { NTSTATUS ret; DWORD pid; - struct InjectionInfo *CurrentInjectionInfo; - PIMAGE_DOS_HEADER pDosHeader; - PIMAGE_NT_HEADERS pNtHeader; ENSURE_SIZET(NumberOfBytesWritten); ret = Old_NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten); pid = pid_from_process_handle(ProcessHandle); - - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - { - CurrentInjectionInfo->WriteDetected = TRUE; - - if (NT_SUCCESS(ret) && *NumberOfBytesWritten > 0) - { - // Check if we have a valid DOS and PE header at the beginning of Buffer - if (*(WORD*)Buffer == IMAGE_DOS_SIGNATURE) - { - pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer); - - if (pDosHeader->e_lfanew && (unsigned int)pDosHeader->e_lfanew < PE_HEADER_LIMIT) - pNtHeader = (PIMAGE_NT_HEADERS)((char*)Buffer + pDosHeader->e_lfanew); - - if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) - { - CurrentInjectionInfo->ImageBase = (DWORD_PTR)BaseAddress; - - DoOutputDebugString("NtWriteVirtualMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); - - if (CurrentInjectionInfo->ImageDumped == FALSE) - { - SetCapeMetaData(INJECTION_PE, pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)Buffer); - - if (CurrentInjectionInfo->ImageDumped) - { - CurrentInjectionInfo->BufferBase = (LPVOID)Buffer; - CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; - DoOutputDebugString("NtWriteVirtualMemory hook: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", Buffer, CurrentInjectionInfo->BufferSizeOfImage); - } - else - DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump PE image from buffer.\n"); - } - } - else - { - DoOutputDebugString("NtWriteVirtualMemory hook: invalid PE file in buffer, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - CapeMetaData->TargetPid = pid; - if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) - DoOutputDebugString("NtWriteVirtualMemory hook: Dumped malformed PE image from buffer."); - else - DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump malformed PE image from buffer."); - } - } - else - { - if (*NumberOfBytesWritten > 0x10) - { - if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && - Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) - { - // Looks like a previously dumped PE image is being written a section at a time to the target process. - // We don't want to dump these writes. - DoOutputDebugString("NtWriteVirtualMemory hook: injection of section of PE image which has already been dumped.\n"); - } - else - { - DoOutputDebugString("NtWriteVirtualMemory hook: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, *NumberOfBytesWritten, pid); - - // dump injected code to .bin file - CapeMetaData->DumpType = INJECTION_SHELLCODE; - CapeMetaData->TargetPid = pid; - if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) - DoOutputDebugString("NtWriteVirtualMemory hook: Dumped injected code from buffer."); - else - DoOutputDebugString("NtWriteVirtualMemory hook: Failed to dump injected code from buffer."); - } - } - } - } - } - if (pid != GetCurrentProcessId()) { - LOQ_ntstatus("process", "ppBhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "Buffer", NumberOfBytesWritten, Buffer, "BufferLength", *NumberOfBytesWritten, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + LOQ_ntstatus("process", "ppBhs", + "ProcessHandle", ProcessHandle, + "BaseAddress", BaseAddress, + "Buffer", NumberOfBytesWritten, Buffer, + "BufferLength", is_valid_address_range((ULONG_PTR)NumberOfBytesWritten, 4) ? *NumberOfBytesWritten : 0, + "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + if (pid != GetCurrentProcessId()) { if (NT_SUCCESS(ret)) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); +#ifdef CAPE_INJECTION + WriteMemoryHandler(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten); +#endif } } @@ -817,129 +626,23 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, ) { BOOL ret; DWORD pid; - struct InjectionInfo *CurrentInjectionInfo; - PIMAGE_DOS_HEADER pDosHeader; - PIMAGE_NT_HEADERS pNtHeader; ENSURE_SIZET(lpNumberOfBytesWritten); ret = Old_WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); - pid = pid_from_process_handle(hProcess); - - CurrentInjectionInfo = GetInjectionInfo(pid); + pid = pid_from_process_handle(hProcess); - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - { - CurrentInjectionInfo->WriteDetected = TRUE; - - if ((unsigned int)((PUCHAR)CurrentInjectionInfo->StackPointer - (PUCHAR)lpBaseAddress) < 0x100) - { - PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - - DoOutputDebugString("WriteProcessMemory hook: Target address is stack of target process %d.\n", pid); - - while (CurrentSectionView) - { -#ifdef _WIN64 - if (CurrentSectionView->SectionHandle == (HANDLE)(*((DWORD_PTR*)lpBuffer + 1))) -#else - if (CurrentSectionView->SectionHandle == (HANDLE)(*((DWORD*)lpBuffer + 1))) -#endif - { - CurrentSectionView->TargetProcessId = pid; - DoOutputDebugString("WriteProcessMemory hook: Section handle 0x%x written to stack of target process %d.\n", CurrentSectionView->SectionHandle, pid); - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } - } - - if (NT_SUCCESS(ret) && *lpNumberOfBytesWritten > 0) - { - // Check if we have a valid DOS and PE header at the beginning of Buffer - if (*(WORD*)lpBuffer == IMAGE_DOS_SIGNATURE) - { - pDosHeader = (PIMAGE_DOS_HEADER)((char*)lpBuffer); - - if (pDosHeader->e_lfanew && (unsigned int)pDosHeader->e_lfanew < PE_HEADER_LIMIT) - pNtHeader = (PIMAGE_NT_HEADERS)((char*)lpBuffer + pDosHeader->e_lfanew); - - if (pNtHeader->Signature == IMAGE_NT_SIGNATURE && pNtHeader->FileHeader.Machine != 0 && pNtHeader->FileHeader.SizeOfOptionalHeader != 0) - { - CurrentInjectionInfo->ImageBase = (DWORD_PTR)lpBaseAddress; - - DoOutputDebugString("WriteProcessMemory hook: Executable binary injected into process %d (ImageBase 0x%x)\n", pid, CurrentInjectionInfo->ImageBase); - - if (CurrentInjectionInfo->ImageDumped == FALSE) - { - SetCapeMetaData(INJECTION_PE, pid, hProcess, NULL); - CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)lpBuffer); - - if (CurrentInjectionInfo->ImageDumped) - { - CurrentInjectionInfo->BufferBase = (LPVOID)lpBuffer; - CurrentInjectionInfo->BufferSizeOfImage = pNtHeader->OptionalHeader.SizeOfImage; - DoOutputDebugString("WriteProcessMemory hook: Dumped PE image from buffer at 0x%x, SizeOfImage 0x%x.\n", lpBuffer, CurrentInjectionInfo->BufferSizeOfImage); - } - else - { - DoOutputDebugString("WriteProcessMemory hook: Failed to dump PE image from buffer, dumping raw buffer.\n"); - - if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) - DoOutputDebugString("WriteProcessMemory hook: Dumped malformed PE image from buffer."); - else - DoOutputDebugString("WriteProcessMemory hook: Failed to dump malformed PE image from buffer."); - } - } - } - else - { - DoOutputDebugString("WriteProcessMemory hook: invalid PE file in buffer, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - CapeMetaData->TargetPid = pid; - if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) - DoOutputDebugString("WriteProcessMemory hook: Dumped malformed PE image from buffer."); - else - DoOutputDebugString("WriteProcessMemory hook: Failed to dump malformed PE image from buffer."); - } - } - else - { - if (*lpNumberOfBytesWritten > 0x10) - { - if (CurrentInjectionInfo->BufferBase && lpBuffer > CurrentInjectionInfo->BufferBase && - lpBuffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) - { - // Looks like a previously dumped PE image is being written a section at a time to the target process. - // We don't want to dump these writes. - DoOutputDebugString("WriteProcessMemory hook: injection of section of PE image which has already been dumped.\n"); - } - else - { - DoOutputDebugString("WriteProcessMemory hook: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", lpBuffer, *lpNumberOfBytesWritten, pid); - - // dump injected code to .bin file - CapeMetaData->DumpType = INJECTION_SHELLCODE; - CapeMetaData->TargetPid = pid; - if (DumpMemory((LPVOID)lpBuffer, *lpNumberOfBytesWritten)) - DoOutputDebugString("WriteProcessMemory hook: Dumped injected code from buffer."); - else - DoOutputDebugString("WriteProcessMemory hook: Failed to dump injected code from buffer."); - } - } - } - } - } + LOQ_bool("process", "ppBhs", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, + "Buffer", lpNumberOfBytesWritten, lpBuffer, "BufferLength", *lpNumberOfBytesWritten, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); if (pid != GetCurrentProcessId()) { - LOQ_bool("process", "ppBhs", "ProcessHandle", hProcess, "BaseAddress", lpBaseAddress, - "Buffer", lpNumberOfBytesWritten, lpBuffer, "BufferLength", *lpNumberOfBytesWritten, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); - if (ret) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); +#ifdef CAPE_INJECTION + WriteMemoryHandler(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); +#endif } } @@ -1012,12 +715,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, if (NewAccessProtection == PAGE_EXECUTE_READ && BaseAddress && NumberOfBytesToProtect && GetCurrentProcessId() == our_getprocessid(ProcessHandle) && is_in_dll_range((ULONG_PTR)*BaseAddress)) restore_hooks_on_range((ULONG_PTR)*BaseAddress, (ULONG_PTR)*BaseAddress + *NumberOfBytesToProtect); - + ret = Old_NtProtectVirtualMemory(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection); memset(&meminfo, 0, sizeof(meminfo)); - if (NT_SUCCESS(ret)) { + if (NT_SUCCESS(ret) && OldAccessProtection && *OldAccessProtection == NewAccessProtection) { lasterror_t lasterrors; get_lasterrors(&lasterrors); VirtualQueryEx(ProcessHandle, *BaseAddress, &meminfo, sizeof(meminfo)); @@ -1060,7 +763,7 @@ HOOKDEF(BOOL, WINAPI, VirtualProtectEx, lpflOldProtect); memset(&meminfo, 0, sizeof(meminfo)); - if (ret) { + if (ret && lpflOldProtect && *lpflOldProtect == flNewProtect) { lasterror_t lasterrors; get_lasterrors(&lasterrors); VirtualQueryEx(hProcess, lpAddress, &meminfo, sizeof(meminfo)); @@ -1178,7 +881,7 @@ HOOKDEF_NOTAIL(WINAPI, RtlDispatchException, if (tebtmp[0] != 0xffffffff) seh = ((DWORD *)tebtmp[0])[1]; if (seh < g_our_dll_base || seh >= (g_our_dll_base + g_our_dll_size)) { - _snprintf(buf, sizeof(buf), "Exception reported at offset 0x%x in cuckoomon itself while accessing 0x%x from hook %s", (DWORD)((ULONG_PTR)ExceptionRecord->ExceptionAddress - g_our_dll_base), ExceptionRecord->ExceptionInformation[1], hook_info()->current_hook ? hook_info()->current_hook->funcname : "unknown"); + _snprintf(buf, sizeof(buf), "Exception 0x%x reported at offset 0x%x in capemon itself while accessing 0x%x from hook %s", ExceptionRecord->ExceptionCode, (DWORD)((ULONG_PTR)ExceptionRecord->ExceptionAddress - g_our_dll_base), ExceptionRecord->ExceptionInformation[1], hook_info()->current_hook ? hook_info()->current_hook->funcname : "unknown"); log_anomaly("cuckoocrash", buf); } } diff --git a/hook_sleep.c b/hook_sleep.c index b7a4ad8..9f08c1e 100644 --- a/hook_sleep.c +++ b/hook_sleep.c @@ -119,7 +119,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWaitForSingleObject, LOQ_ntstatus("system", "s", "Status", "Small log limit reached"); num_wait_small++; } - else if (num_wait_small > 20) { + else { // likely using a bunch of tiny sleeps to delay execution, so let's suddenly mimic high load and give our // fake passage of time the impression of longer delays to return from sleep time_skipped.QuadPart += (randint(500, 1000) * 10000); @@ -213,7 +213,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtDelayExecution, LOQ_ntstatus("system", "s", "Status", "Small log limit reached"); num_small++; } - else if (num_small > 20) { + else { // likely using a bunch of tiny sleeps to delay execution, so let's suddenly mimic high load and give our // fake passage of time the impression of longer delays to return from sleep time_skipped.QuadPart += (randint(500, 1000) * 10000); @@ -267,7 +267,7 @@ HOOKDEF(DWORD, WINAPI, MsgWaitForMultipleObjectsEx, LOQ_msgwait("system", "s", "Status", "Small log limit reached"); num_msg_small++; } - else if (num_msg_small > 20) { + else { // likely using a bunch of tiny sleeps to delay execution, so let's suddenly mimic high load and give our // fake passage of time the impression of longer delays to return from sleep time_skipped.QuadPart += (randint(500, 1000) * 10000); diff --git a/hook_special.c b/hook_special.c index 9909555..daffbe2 100644 --- a/hook_special.c +++ b/hook_special.c @@ -24,10 +24,15 @@ along with this program. If not, see . #include "hook_sleep.h" #include "misc.h" #include "config.h" -#include "CAPE\CAPE.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern PVOID get_process_image_base(HANDLE process_handle); +extern int RoutineProcessDump(); +extern ULONG_PTR base_of_dll_of_interest; +#ifdef CAPE_INJECTION +extern void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROCESS_INFORMATION lpProcessInformation); +#endif + +PVOID LastDllUnload; HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, __in_opt PWCHAR PathToFile, @@ -35,7 +40,6 @@ HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, __in PUNICODE_STRING ModuleFileName, __out PHANDLE ModuleHandle ) { - // // In the event that loading this dll results in loading another dll as // well, then the unicode string (which is located in the TEB) will be @@ -68,7 +72,7 @@ HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, LOQ_ntstatus("system", "HoP", "Flags", Flags, "FileName", &library, "BaseAddress", ModuleHandle); - if (library.Buffer[1] == L':' && (!wcsnicmp(library.Buffer, L"c:\\windows\\system32\\", 20) || + if (library.Buffer[1] == L':' && (!wcsnicmp(library.Buffer, L"c:\\windows\\system32\\", 20) || !wcsnicmp(library.Buffer, L"c:\\windows\\syswow64\\", 20) || !wcsnicmp(library.Buffer, L"c:\\windows\\sysnative\\", 21))) { ret = 1; @@ -99,6 +103,9 @@ HOOKDEF_ALT(NTSTATUS, WINAPI, LdrLoadDll, __out PHANDLE ModuleHandle ) { NTSTATUS ret; + + COPY_UNICODE_STRING(library, ModuleFileName); + hook_info_t saved_hookinfo; memcpy(&saved_hookinfo, hook_info(), sizeof(saved_hookinfo)); @@ -109,15 +116,22 @@ HOOKDEF_ALT(NTSTATUS, WINAPI, LdrLoadDll, return ret; } - extern void revalidate_all_hooks(void); HOOKDEF_NOTAIL(WINAPI, LdrUnloadDll, PVOID DllImageBase ) { - return 0; -} + if (DllImageBase && DllImageBase == (PVOID)base_of_dll_of_interest) + RoutineProcessDump(); + if (DllImageBase && DllImageBase != LastDllUnload) + { + DoOutputDebugString("DLL unloaded from 0x%p.\n", DllImageBase); + LastDllUnload = DllImageBase; + } + + return 0; +} HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, __in_opt LPVOID lpUnknown1, @@ -134,18 +148,16 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, __in_opt LPVOID lpUnknown2 ) { BOOL ret; - struct InjectionInfo *CurrentInjectionInfo; hook_info_t saved_hookinfo; - WCHAR TargetProcess[MAX_PATH]; - memcpy(&saved_hookinfo, hook_info(), sizeof(saved_hookinfo)); + memcpy(&saved_hookinfo, hook_info(), sizeof(saved_hookinfo)); ret = Old_CreateProcessInternalW(lpUnknown1, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, lpUnknown2); memcpy(hook_info(), &saved_hookinfo, sizeof(saved_hookinfo)); - if(ret != FALSE) { + if (ret != FALSE) { BOOL dont_monitor = FALSE; if (g_config.file_of_interest && g_config.suspend_logging && lpApplicationName && !wcsicmp(lpApplicationName, L"c:\\windows\\splwow64.exe")) dont_monitor = TRUE; @@ -153,81 +165,44 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, if (!dont_monitor) pipe("PROCESS:%d:%d,%d", (dwCreationFlags & CREATE_SUSPENDED) ? 1 : 0, lpProcessInformation->dwProcessId, lpProcessInformation->dwThreadId); - - // CAPE: Create 'injection info' struct for the newly created process - CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); - - if (CurrentInjectionInfo == NULL) - { - DoOutputDebugString("CreateProcessInternal hook: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); - } - else - { - CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); - CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; - CurrentInjectionInfo->ImageDumped = FALSE; - - CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); - memset(TargetProcess, 0, MAX_PATH*sizeof(WCHAR)); - - if (lpApplicationName) - _snwprintf(TargetProcess, MAX_PATH, L"%s", lpApplicationName); - else if (lpCommandLine) - { - DoOutputDebugString("CreateProcessInternal hook: using lpCommandLine: %ws.\n", lpCommandLine); - if (*lpCommandLine == L'\"') - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); - else - { - if (wcschr(lpCommandLine, ' ')) - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); - else - wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); - } - } - - WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, (int)wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); - - DoOutputDebugString("CreateProcessInternal hook: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); - } - // if the CREATE_SUSPENDED flag was not set, then we have to resume - // the main thread ourself - if((dwCreationFlags & CREATE_SUSPENDED) == 0) { +#ifdef CAPE_INJECTION + CreateProcessHandler(lpApplicationName, lpCommandLine, lpProcessInformation); +#endif + + // if the CREATE_SUSPENDED flag was not set, then we have to resume the main thread ourself + if ((dwCreationFlags & CREATE_SUSPENDED) == 0) { ResumeThread(lpProcessInformation->hThread); } - + disable_sleep_skip(); } -// if (!called_by_hook()) { - if (dwCreationFlags & EXTENDED_STARTUPINFO_PRESENT && lpStartupInfo->cb == sizeof(STARTUPINFOEXW)) { - HANDLE ParentHandle = (HANDLE)-1; - unsigned int i; - LPSTARTUPINFOEXW lpExtStartupInfo = (LPSTARTUPINFOEXW)lpStartupInfo; - if (lpExtStartupInfo->lpAttributeList) { - for (i = 0; i < lpExtStartupInfo->lpAttributeList->Count; i++) - if (lpExtStartupInfo->lpAttributeList->Entries[i].Attribute == PROC_THREAD_ATTRIBUTE_PARENT_PROCESS) - ParentHandle = *(HANDLE *)lpExtStartupInfo->lpAttributeList->Entries[i].lpValue; - } - LOQ_bool("process", "uuhiippps", "ApplicationName", lpApplicationName, - "CommandLine", lpCommandLine, "CreationFlags", dwCreationFlags, - "ProcessId", lpProcessInformation->dwProcessId, - "ThreadId", lpProcessInformation->dwThreadId, - "ParentHandle", ParentHandle, - "ProcessHandle", lpProcessInformation->hProcess, - "ThreadHandle", lpProcessInformation->hThread, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); - } - else { - LOQ_bool("process", "uuhiipps", "ApplicationName", lpApplicationName, - "CommandLine", lpCommandLine, "CreationFlags", dwCreationFlags, - "ProcessId", lpProcessInformation->dwProcessId, - "ThreadId", lpProcessInformation->dwThreadId, - "ProcessHandle", lpProcessInformation->hProcess, - "ThreadHandle", lpProcessInformation->hThread, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); - } -// } + if (dwCreationFlags & EXTENDED_STARTUPINFO_PRESENT && lpStartupInfo->cb == sizeof(STARTUPINFOEXW)) { + HANDLE ParentHandle = (HANDLE)-1; + unsigned int i; + LPSTARTUPINFOEXW lpExtStartupInfo = (LPSTARTUPINFOEXW)lpStartupInfo; + if (lpExtStartupInfo->lpAttributeList) { + for (i = 0; i < lpExtStartupInfo->lpAttributeList->Count; i++) + if (lpExtStartupInfo->lpAttributeList->Entries[i].Attribute == PROC_THREAD_ATTRIBUTE_PARENT_PROCESS) + ParentHandle = *(HANDLE *)lpExtStartupInfo->lpAttributeList->Entries[i].lpValue; + } + LOQ_bool("process", "uuhiippps", "ApplicationName", lpApplicationName, + "CommandLine", lpCommandLine, "CreationFlags", dwCreationFlags, + "ProcessId", lpProcessInformation->dwProcessId, + "ThreadId", lpProcessInformation->dwThreadId, + "ParentHandle", ParentHandle, + "ProcessHandle", lpProcessInformation->hProcess, + "ThreadHandle", lpProcessInformation->hThread, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + } + else { + LOQ_bool("process", "uuhiipps", "ApplicationName", lpApplicationName, + "CommandLine", lpCommandLine, "CreationFlags", dwCreationFlags, + "ProcessId", lpProcessInformation->dwProcessId, + "ThreadId", lpProcessInformation->dwThreadId, + "ProcessHandle", lpProcessInformation->hProcess, + "ThreadHandle", lpProcessInformation->hThread, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); + } return ret; } @@ -258,8 +233,10 @@ HOOKDEF(HRESULT, WINAPI, CoCreateInstance, if (!pProgIDFromCLSID) pProgIDFromCLSID = (_ProgIDFromCLSID)GetProcAddress(GetModuleHandleA("ole32"), "ProgIDFromCLSID"); - memcpy(&id1, rclsid, sizeof(id1)); - memcpy(&id2, riid, sizeof(id2)); + if (is_valid_address_range((ULONG_PTR)rclsid, 16)) + memcpy(&id1, rclsid, sizeof(id1)); + if (is_valid_address_range((ULONG_PTR)riid, 16)) + memcpy(&id2, riid, sizeof(id2)); sprintf(idbuf1, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); sprintf(idbuf2, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id2.Data1, id2.Data2, id2.Data3, @@ -319,7 +296,8 @@ HOOKDEF(HRESULT, WINAPI, CoCreateInstanceEx, if (!pProgIDFromCLSID) pProgIDFromCLSID = (_ProgIDFromCLSID)GetProcAddress(GetModuleHandleA("ole32"), "ProgIDFromCLSID"); - memcpy(&id1, rclsid, sizeof(id1)); + if (is_valid_address_range((ULONG_PTR)rclsid, 16)) + memcpy(&id1, rclsid, sizeof(id1)); sprintf(idbuf1, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); @@ -381,8 +359,10 @@ HOOKDEF(HRESULT, WINAPI, CoGetClassObject, if (!pProgIDFromCLSID) pProgIDFromCLSID = (_ProgIDFromCLSID)GetProcAddress(GetModuleHandleA("ole32"), "ProgIDFromCLSID"); - memcpy(&id1, rclsid, sizeof(id1)); - memcpy(&id2, riid, sizeof(id2)); + if (is_valid_address_range((ULONG_PTR)rclsid, 16)) + memcpy(&id1, rclsid, sizeof(id1)); + if (is_valid_address_range((ULONG_PTR)riid, 16)) + memcpy(&id2, riid, sizeof(id2)); sprintf(idbuf1, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id1.Data1, id1.Data2, id1.Data3, id1.Data4[0], id1.Data4[1], id1.Data4[2], id1.Data4[3], id1.Data4[4], id1.Data4[5], id1.Data4[6], id1.Data4[7]); sprintf(idbuf2, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", id2.Data1, id2.Data2, id2.Data3, diff --git a/hook_thread.c b/hook_thread.c index fada70b..1a55fa3 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -26,14 +26,19 @@ along with this program. If not, see . #include "unhook.h" #include "lookup.h" #include "CAPE\CAPE.h" +#include "CAPE\Debugger.h" extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern int DumpMemory(LPVOID Buffer, SIZE_T Size); -extern int DumpImageInCurrentProcess(PVOID ImageBase); -extern int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); +#ifdef CAPE_INJECTION +extern void GetThreadContextHandler(DWORD Pid, LPCONTEXT Context); +extern void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context); +extern void ResumeThreadHandler(DWORD Pid); +#endif static lookup_t g_ignored_threads; +DWORD LastInjected; + void ignored_threads_init(void) { lookup_init(&g_ignored_threads); @@ -72,7 +77,6 @@ void add_ignored_thread(DWORD tid) set_lasterrors(&lasterror); } - HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThread, __in HANDLE ThreadHandle, __in PIO_APC_ROUTINE ApcRoutine, @@ -84,10 +88,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThread, DWORD TID = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; - pipe("PROCESS:%d:%d,%d", is_suspended(PID, TID), PID, TID); + pipe("PROCESS:%d:%d,%d", is_suspended(PID, TID), PID, TID); - ret = Old_NtQueueApcThread(ThreadHandle, ApcRoutine, - ApcRoutineContext, ApcStatusBlock, ApcReserved); + ret = Old_NtQueueApcThread(ThreadHandle, ApcRoutine, ApcRoutineContext, ApcStatusBlock, ApcReserved); LOQ_ntstatus("threading", "iip", "ProcessId", PID, "ThreadId", TID, "ThreadHandle", ThreadHandle); @@ -110,8 +113,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThreadEx, pipe("PROCESS:%d:%d,%d", is_suspended(PID, TID), PID, TID); - ret = Old_NtQueueApcThreadEx(ThreadHandle, UserApcReserveHandle, ApcRoutine, - ApcRoutineContext, ApcStatusBlock, ApcReserved); + ret = Old_NtQueueApcThreadEx(ThreadHandle, UserApcReserveHandle, ApcRoutine, ApcRoutineContext, ApcStatusBlock, ApcReserved); LOQ_ntstatus("threading", "iip", "ProcessId", PID, "ThreadId", TID, "ThreadHandle", ThreadHandle); @@ -120,7 +122,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThreadEx, return ret; } - HOOKDEF(NTSTATUS, WINAPI, NtCreateThread, __out PHANDLE ThreadHandle, __in ACCESS_MASK DesiredAccess, @@ -132,16 +133,23 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateThread, __in BOOLEAN CreateSuspended ) { DWORD pid = pid_from_process_handle(ProcessHandle); - NTSTATUS ret = Old_NtCreateThread(ThreadHandle, DesiredAccess, ObjectAttributes, ProcessHandle, ClientId, ThreadContext, InitialTeb, TRUE); if (NT_SUCCESS(ret)) { + DWORD tid = tid_from_thread_handle(*ThreadHandle); //if (called_by_hook() && pid == GetCurrentProcessId()) - // add_ignored_thread((DWORD)ClientId->UniqueThread); - pipe("PROCESS:%d:%d,%d", is_suspended(pid, (DWORD)(ULONG_PTR)ClientId->UniqueThread), pid, (DWORD)(ULONG_PTR)ClientId->UniqueThread); - if (CreateSuspended == FALSE) { + // add_ignored_thread(tid); + + if (DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("NtCreateThread: Initialising breakpoints for thread %d.\n", tid); + InitNewThreadBreakpoints(tid); + } + + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); + + if (CreateSuspended == FALSE) { lasterror_t lasterror; get_lasterrors(&lasterror); ResumeThread(*ThreadHandle); @@ -182,8 +190,15 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateThreadEx, //if (called_by_hook() && pid == GetCurrentProcessId()) // add_ignored_thread(tid); - pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); - if (!(CreateFlags & 1)) { + if (pid != GetCurrentProcessId()) + if (DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("NtCreateThreadEx: Initialising breakpoints for thread %d.\n", tid); + InitNewThreadBreakpoints(tid); + } + + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); + + if (!(CreateFlags & 1)) { lasterror_t lasterror; get_lasterrors(&lasterror); ResumeThread(*hThread); @@ -230,30 +245,21 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, __in HANDLE ThreadHandle, __inout LPCONTEXT Context ) { - NTSTATUS ret; - struct InjectionInfo *CurrentInjectionInfo; - DWORD pid = pid_from_thread_handle(ThreadHandle); - - ret = Old_NtGetContextThread(ThreadHandle, Context); - - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (Context->ContextFlags & CONTEXT_CONTROL) - { + ENSURE_HANDLE(ThreadHandle); + ENSURE_STRUCT(Context, CONTEXT); + NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); + if (Context && Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->StackPointer = (LPVOID)Context->Rsp; - - LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); #else - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->StackPointer = (LPVOID)Context->Esp; - - LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); #endif - } else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); +#ifdef CAPE_INJECTION + DWORD pid = pid_from_thread_handle(ThreadHandle); + GetThreadContextHandler(pid, Context); +#endif return ret; } @@ -262,42 +268,25 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, __in const CONTEXT *Context ) { NTSTATUS ret; - struct InjectionInfo *CurrentInjectionInfo; DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); - pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); - ret = Old_NtSetContextThread(ThreadHandle, Context); - - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (Context->ContextFlags & CONTEXT_CONTROL) - { + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); + + ret = Old_NtSetContextThread(ThreadHandle, Context); + + if (Context && Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds ep on 64-bit - - LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Rcx, "InstructionPointer", Context->Rip); - - if (Context->Rip == (DWORD_PTR)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) - DoOutputDebugString("NtSetContextThread hook: Hollow process entry point set to NtMapViewOfSection (process %d).\n", pid); - else - DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); #else - if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == pid) - CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds ep on 32-bit - - LOQ_ntstatus("threading", "ppp", "ThreadHandle", ThreadHandle, "EntryPoint", Context->Eax, "InstructionPointer", Context->Eip); - - if (Context->Eip == (DWORD)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) - DoOutputDebugString("NtSetContextThread hook: Hollow process entry point set to NtMapViewOfSection (process %d).\n", pid); - else - DoOutputDebugString("NtSetContextThread hook: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, pid); + LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Eax); #endif - } else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); - +#ifdef CAPE_INJECTION + SetThreadContextHandler(pid, Context); +#endif return ret; } @@ -332,47 +321,21 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, __in HANDLE ThreadHandle, __out_opt ULONG *SuspendCount ) { - struct InjectionInfo *CurrentInjectionInfo; - DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; ENSURE_ULONG(SuspendCount); pipe("RESUME:%d,%d", pid, tid); +#ifdef CAPE_INJECTION + ResumeThreadHandler(pid); +#endif - CurrentInjectionInfo = GetInjectionInfo(pid); - - if (CurrentInjectionInfo) - { - DoOutputDebugString("NtResumeThread hook: CurrentInjectionInfo 0x%x (pid %d).\n", CurrentInjectionInfo, pid); - - if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) - { - CapeMetaData->DumpType = INJECTION_PE; - CapeMetaData->TargetPid = pid; - - DoOutputDebugString("NtResumeThread hook: Dumping hollowed process %d, image base 0x%x.\n", pid, CurrentInjectionInfo->ImageBase); - - CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); - - if (CurrentInjectionInfo->ImageDumped) - { - DoOutputDebugString("NtResumeThread hook: Dumped PE image from buffer.\n"); - } - else - DoOutputDebugString("NtResumeThread hook: Failed to dump PE image from buffer.\n"); - } - - DumpSectionViewsForPid(pid); - } - ret = Old_NtResumeThread(ThreadHandle, SuspendCount); LOQ_ntstatus("threading", "pI", "ThreadHandle", ThreadHandle, "SuspendCount", SuspendCount); return ret; } extern DWORD tmphookinfo_threadid; -extern CRITICAL_SECTION g_tmp_hookinfo_lock; HOOKDEF(NTSTATUS, WINAPI, NtTerminateThread, __in HANDLE ThreadHandle, @@ -385,7 +348,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateThread, if (tmphookinfo_threadid && tid == tmphookinfo_threadid) { tmphookinfo_threadid = 0; - LeaveCriticalSection(&g_tmp_hookinfo_lock); } //remove_ignored_thread(tid); @@ -418,7 +380,19 @@ HOOKDEF(HANDLE, WINAPI, CreateThread, ENSURE_DWORD(lpThreadId); ret = Old_CreateThread(lpThreadAttributes, dwStackSize, - lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); + lpStartAddress, lpParameter, dwCreationFlags | CREATE_SUSPENDED, lpThreadId); + + if (ret != NULL && DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("CreateThread: Initialising breakpoints for thread %d.\n", *lpThreadId); + InitNewThreadBreakpoints(*lpThreadId); + } + + if (!(dwCreationFlags && CREATE_SUSPENDED)) { + lasterror_t lasterror; + get_lasterrors(&lasterror); + ResumeThread(ret); + set_lasterrors(&lasterror); + } LOQ_nonnull("threading", "pphI", "StartRoutine", lpStartAddress, "Parameter", lpParameter, "CreationFlags", dwCreationFlags, "ThreadId", lpThreadId); if (ret != NULL) @@ -445,8 +419,14 @@ HOOKDEF(HANDLE, WINAPI, CreateRemoteThread, lpThreadId); if (ret != NULL) { - pipe("PROCESS:%d:%d,%d", is_suspended(pid, *lpThreadId), pid, *lpThreadId); - if (!(dwCreationFlags & CREATE_SUSPENDED)) { + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d,%d", is_suspended(pid, *lpThreadId), pid, *lpThreadId); + else if (DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("CreateRemoteThread: Initialising breakpoints for (local) thread %d.\n", *lpThreadId); + InitNewThreadBreakpoints(*lpThreadId); + } + + if (!(dwCreationFlags & CREATE_SUSPENDED)) { lasterror_t lasterror; get_lasterrors(&lasterror); ResumeThread(ret); @@ -477,10 +457,11 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserThread, ) { DWORD pid; NTSTATUS ret; + ENSURE_HANDLE(ThreadHandle); ENSURE_CLIENT_ID(ClientId); pid = pid_from_process_handle(ProcessHandle); - + ret = Old_RtlCreateUserThread(ProcessHandle, SecurityDescriptor, TRUE, StackZeroBits, StackReserved, StackCommit, StartAddress, StartParameter, ThreadHandle, ClientId); @@ -489,12 +470,18 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserThread, "StartParameter", StartParameter, "ThreadHandle", ThreadHandle, "ThreadIdentifier", ClientId->UniqueThread); - if (NT_SUCCESS(ret)) { - pipe("PROCESS:%d:%d,%d", is_suspended(pid, (DWORD)(ULONG_PTR)ClientId->UniqueThread), pid, (DWORD)(ULONG_PTR)ClientId->UniqueThread); - if (CreateSuspended == FALSE) { + if (NT_SUCCESS(ret) && ClientId && ThreadHandle) { + DWORD tid = tid_from_thread_handle(ThreadHandle); + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); + else if (DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("RtlCreateUserThread: Initialising breakpoints for (local) thread %d.\n", tid); + InitNewThreadBreakpoints(tid); + } + if (CreateSuspended == FALSE && is_valid_address_range((ULONG_PTR)ThreadHandle, 4)) { lasterror_t lasterror; get_lasterrors(&lasterror); - ResumeThread(ThreadHandle); + ResumeThread(*ThreadHandle); set_lasterrors(&lasterror); } } @@ -504,3 +491,40 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserThread, return ret; } + +HOOKDEF(NTSTATUS, WINAPI, NtSetInformationThread, + IN HANDLE ThreadHandle, + IN THREADINFOCLASS ThreadInformationClass, + IN PVOID ThreadInformation, + IN ULONG ThreadInformationLength +) { + NTSTATUS ret; + ENSURE_HANDLE(ThreadHandle); + + ret = Old_NtSetInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength); + + LOQ_ntstatus("threading", "pib", "ThreadHandle", ThreadHandle, + "ThreadInformationClass", ThreadInformationClass, + "ThreadInformation", ThreadInformationLength, ThreadInformation); + + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationThread, + IN HANDLE ThreadHandle, + IN THREADINFOCLASS ThreadInformationClass, + OUT PVOID ThreadInformation, + IN ULONG ThreadInformationLength, + OUT PULONG ReturnLength OPTIONAL +) { + NTSTATUS ret; + ENSURE_HANDLE(ThreadHandle); + + ret = Old_NtQueryInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength, ReturnLength); + + LOQ_ntstatus("threading", "pib", "ThreadHandle", ThreadHandle, + "ThreadInformationClass", ThreadInformationClass, + "ThreadInformation", ThreadInformationLength, ThreadInformation); + + return ret; +} diff --git a/hooking.c b/hooking.c index f97aaba..5720b14 100644 --- a/hooking.c +++ b/hooking.c @@ -36,6 +36,13 @@ extern DWORD g_tls_hook_index; #define TLS_LAST_NTSTATUS_ERROR 0xbf4 #endif +static lookup_t g_hook_info; + +void hook_init() +{ + lookup_init(&g_hook_info); +} + void emit_rel(unsigned char *buf, unsigned char *source, unsigned char *target) { *(DWORD *)buf = (DWORD)(target - (source + 4)); @@ -99,7 +106,6 @@ int called_by_hook(void) } extern BOOLEAN is_ignored_thread(DWORD tid); -extern CRITICAL_SECTION g_tmp_hookinfo_lock; static hook_info_t tmphookinfo; DWORD tmphookinfo_threadid; @@ -114,11 +120,10 @@ int WINAPI enter_hook(hook_t *h, ULONG_PTR sp, ULONG_PTR ebp_or_rip) if (h->fully_emulate) return 1; - if (g_tls_hook_index >= 0x40 && h->new_func == &New_NtAllocateVirtualMemory) { + if (h->new_func == &New_NtAllocateVirtualMemory) { lasterror_t lasterrors; get_lasterrors(&lasterrors); - if (TlsGetValue(g_tls_hook_index) == NULL && (!tmphookinfo_threadid || tmphookinfo_threadid != GetCurrentThreadId())) { - EnterCriticalSection(&g_tmp_hookinfo_lock); + if (lookup_get_no_cs(&g_hook_info, (ULONG_PTR)GetCurrentThreadId(), NULL) == NULL && (!tmphookinfo_threadid || tmphookinfo_threadid != GetCurrentThreadId())) { memset(&tmphookinfo, 0, sizeof(tmphookinfo)); tmphookinfo_threadid = GetCurrentThreadId(); } @@ -126,7 +131,6 @@ int WINAPI enter_hook(hook_t *h, ULONG_PTR sp, ULONG_PTR ebp_or_rip) } else if (tmphookinfo_threadid) { tmphookinfo_threadid = 0; - LeaveCriticalSection(&g_tmp_hookinfo_lock); } hookinfo = hook_info(); @@ -161,10 +165,10 @@ hook_info_t *hook_info() get_lasterrors(&lasterror); - ptr = (hook_info_t *)TlsGetValue(g_tls_hook_index); + ptr = (hook_info_t *)lookup_get_no_cs(&g_hook_info, (ULONG_PTR)GetCurrentThreadId(), NULL); if (ptr == NULL) { - ptr = (hook_info_t *)calloc(1, sizeof(hook_info_t)); - TlsSetValue(g_tls_hook_index, ptr); + ptr = lookup_add_no_cs(&g_hook_info, (ULONG_PTR)GetCurrentThreadId(), sizeof(hook_info_t)); + memset(ptr, 0, sizeof(*ptr)); } set_lasterrors(&lasterror); diff --git a/hooking.h b/hooking.h index e4ae038..a2a7015 100644 --- a/hooking.h +++ b/hooking.h @@ -20,6 +20,7 @@ along with this program. If not, see . #define __HOOKING_H #include "ntapi.h" +#include "lookup.h" #include "config.h" #include @@ -288,4 +289,6 @@ static inline BOOLEAN disable_this_hook(hook_t *h) return TRUE; } +void hook_init(); + #endif \ No newline at end of file diff --git a/hooks.h b/hooks.h index 6ad37c9..17cb12a 100644 --- a/hooks.h +++ b/hooks.h @@ -1142,6 +1142,14 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtSetInformationProcess, __in ULONG ProcessInformationLength ); +extern HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationProcess, + IN HANDLE ProcessHandle, + IN PROCESSINFOCLASS ProcessInformationClass, + OUT PVOID ProcessInformation, + IN ULONG ProcessInformationLength, + OUT PULONG ReturnLength OPTIONAL +); + extern HOOKDEF(NTSTATUS, WINAPI, NtAllocateVirtualMemory, __in HANDLE ProcessHandle, __inout PVOID *BaseAddress, @@ -2864,3 +2872,18 @@ extern HOOKDEF(unsigned int, WINAPIV, SizeofResource, extern HOOKDEF(void, WINAPIV, srand, unsigned int seed ); + +extern HOOKDEF(NTSTATUS, WINAPI, NtSetInformationThread, + IN HANDLE ThreadHandle, + IN THREADINFOCLASS ThreadInformationClass, + IN PVOID ThreadInformation, + IN ULONG ThreadInformationLength +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationThread, + IN HANDLE ThreadHandle, + IN THREADINFOCLASS ThreadInformationClass, + OUT PVOID ThreadInformation, + IN ULONG ThreadInformationLength, + OUT PULONG ReturnLength OPTIONAL +); \ No newline at end of file diff --git a/log.h b/log.h index a211632..31ca007 100644 --- a/log.h +++ b/log.h @@ -145,6 +145,9 @@ do { \ #define ENSURE_CLIENT_ID(param) \ CLIENT_ID _##param; memset(&_##param, 0, sizeof(_##param)); if (param == NULL) param = &_##param +#define ENSURE_HANDLE(param) \ + HANDLE _##param; memset(&_##param, 0, sizeof(_##param)); if (param == NULL) param = &_##param + #define ENSURE_STRUCT(param, type) \ type _##param; memset(&_##param, 0, sizeof(_##param)); if(param == NULL) param = &_##param diff --git a/lookup.c b/lookup.c index 3b034a1..7a69c61 100644 --- a/lookup.c +++ b/lookup.c @@ -51,6 +51,17 @@ void *lookup_add(lookup_t *d, ULONG_PTR id, unsigned int size) return t->data; } +void *lookup_add_no_cs(lookup_t *d, ULONG_PTR id, unsigned int size) +{ + entry_t *t = (entry_t *) malloc(sizeof(entry_t) + size); + memset(t, 0, sizeof(*t)); + t->next = d->root; + t->id = id; + t->size = size; + d->root = t; + return t->data; +} + void *lookup_get(lookup_t *d, ULONG_PTR id, unsigned int *size) { entry_t *p; @@ -70,6 +81,23 @@ void *lookup_get(lookup_t *d, ULONG_PTR id, unsigned int *size) return NULL; } +void *lookup_get_no_cs(lookup_t *d, ULONG_PTR id, unsigned int *size) +{ + entry_t *p; + for (p = d->root; p != NULL; p = p->next) { + if(p->id == id) { + void *data; + if(size != NULL) { + *size = p->size; + } + data = p->data; + LEAVE(); + return data; + } + } + return NULL; +} + void lookup_del(lookup_t *d, ULONG_PTR id) { entry_t *p; @@ -94,3 +122,26 @@ void lookup_del(lookup_t *d, ULONG_PTR id) } LEAVE(); } + +void lookup_del_no_cs(lookup_t *d, ULONG_PTR id) +{ + entry_t *p; + entry_t *last; + + p = d->root; + // edge case; we want to delete the first entry + if(p != NULL && p->id == id) { + entry_t *t = p->next; + free(d->root); + d->root = t; + LEAVE(); + return; + } + for (last = NULL; p != NULL; last = p, p = p->next) { + if(p->id == id) { + last->next = p->next; + free(p); + break; + } + } +} diff --git a/lookup.h b/lookup.h index 235b714..15e58f3 100644 --- a/lookup.h +++ b/lookup.h @@ -35,3 +35,7 @@ void lookup_init(lookup_t *d); void *lookup_add(lookup_t *d, ULONG_PTR id, unsigned int size); void *lookup_get(lookup_t *d, ULONG_PTR id, unsigned int *size); void lookup_del(lookup_t *d, ULONG_PTR id); + +void *lookup_add_no_cs(lookup_t *d, ULONG_PTR id, unsigned int size); +void *lookup_get_no_cs(lookup_t *d, ULONG_PTR id, unsigned int *size); +void lookup_del_no_cs(lookup_t *d, ULONG_PTR id); diff --git a/misc.c b/misc.c index a473a35..25e5158 100644 --- a/misc.c +++ b/misc.c @@ -781,9 +781,7 @@ uint32_t path_from_object_attributes(const OBJECT_ATTRIBUTES *obj, return copylen; } - length = path_from_handle(obj->RootDirectory, - path, buffer_length); - + length = path_from_handle(obj->RootDirectory, path, buffer_length); path[length++] = L'\\'; if (length >= (buffer_length - 1)) diff --git a/ntapi.h b/ntapi.h index cf573ca..54750a4 100644 --- a/ntapi.h +++ b/ntapi.h @@ -768,14 +768,106 @@ typedef enum { FileFsSectorSizeInformation = 11 } FS_INFORMATION_CLASS; -typedef enum { - ProcessBreakOnTermination = 29, - ProcessInfoDEPPolicy = 34 +typedef enum _PROCESSINFOCLASS { + ProcessBasicInformation, + ProcessQuotaLimits, + ProcessIoCounters, + ProcessVmCounters, + ProcessTimes, + ProcessBasePriority, + ProcessRaisePriority, + ProcessDebugPort, + ProcessExceptionPort, + ProcessAccessToken, + ProcessLdtInformation, + ProcessLdtSize, + ProcessDefaultHardErrorMode, + ProcessIoPortHandlers, // Note: this is kernel mode only + ProcessPooledUsageAndLimits, + ProcessWorkingSetWatch, + ProcessUserModeIOPL, + ProcessEnableAlignmentFaultFixup, + ProcessPriorityClass, + ProcessWx86Information, + ProcessHandleCount, + ProcessAffinityMask, + ProcessPriorityBoost, + ProcessDeviceMap, + ProcessSessionInformation, + ProcessForegroundInformation, + ProcessWow64Information, + ProcessImageFileName, + ProcessLUIDDeviceMapsEnabled, + ProcessBreakOnTermination, + ProcessDebugObjectHandle, + ProcessDebugFlags, + ProcessHandleTracing, + ProcessIoPriority, + ProcessExecuteFlags, + ProcessTlsInformation, + ProcessCookie, + ProcessImageInformation, + ProcessCycleTime, + ProcessPagePriority, + ProcessInstrumentationCallback, + ProcessThreadStackAllocation, + ProcessWorkingSetWatchEx, + ProcessImageFileNameWin32, + ProcessImageFileMapping, + ProcessAffinityUpdateMode, + ProcessMemoryAllocationMode, + ProcessGroupInformation, + ProcessTokenVirtualizationEnabled, + ProcessConsoleHostProcess, + ProcessWindowInformation, + ProcessHandleInformation, + ProcessMitigationPolicy, + ProcessDynamicFunctionTableInformation, + ProcessHandleCheckingMode, + ProcessKeepAliveCount, + ProcessRevokeFileHandles, + ProcessWorkingSetControl, + MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum } PROCESSINFOCLASS; -typedef enum { - ThreadBasicInformation = 0, -} THREAD_INFORMATION_CLASS; +typedef enum _THREADINFOCLASS { + ThreadBasicInformation, + ThreadTimes, + ThreadPriority, + ThreadBasePriority, + ThreadAffinityMask, + ThreadImpersonationToken, + ThreadDescriptorTableEntry, + ThreadEnableAlignmentFaultFixup, + ThreadEventPair_Reusable, + ThreadQuerySetWin32StartAddress, + ThreadZeroTlsCell, + ThreadPerformanceCount, + ThreadAmILastThread, + ThreadIdealProcessor, + ThreadPriorityBoost, + ThreadSetTlsArrayAddress, // Obsolete + ThreadIsIoPending, + ThreadHideFromDebugger, + ThreadBreakOnTermination, + ThreadSwitchLegacyState, + ThreadIsTerminated, + ThreadLastSystemCall, + ThreadIoPriority, + ThreadCycleTime, + ThreadPagePriority, + ThreadActualBasePriority, + ThreadTebInformation, + ThreadCSwitchMon, // Obsolete + ThreadCSwitchPmu, + ThreadWow64Context, + ThreadGroupInformation, + ThreadUmsInformation, // UMS + ThreadCounterProfiling, + ThreadIdealProcessorEx, + ThreadCpuAccountingInformation, + MaxThreadInfoClass +} THREADINFOCLASS; typedef struct _FILE_FS_VOLUME_INFORMATION { LARGE_INTEGER VolumeCreationTime; diff --git a/unhook.c b/unhook.c index 91597bb..3ef7aa9 100644 --- a/unhook.c +++ b/unhook.c @@ -28,6 +28,11 @@ along with this program. If not, see . #define UNHOOK_MAXCOUNT 2048 #define UNHOOK_BUFSIZE 32 +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void file_handle_terminate(); +extern int RoutineProcessDump(); +extern BOOL ProcessDumped; + static HANDLE g_unhook_thread_handle, g_watcher_thread_handle; // Index for adding new hooks and iterating all existing hooks. @@ -251,6 +256,12 @@ static DWORD WINAPI _terminate_event_thread(LPVOID param) while (1) { WaitForSingleObject(g_terminate_event_handle, INFINITE); + if (g_config.procdump && !ProcessDumped) + { + DoOutputDebugString("Terminate Event: Attempting to dump process %d\n", GetCurrentProcessId()); + RoutineProcessDump(); + } + file_handle_terminate(); log_flush(); } From c58cb4b2fca2cb79d2e918ea048021543a41ffd6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Aug 2018 09:25:33 +0100 Subject: [PATCH 29/39] Complete refactoring into Injection.c, integrated Sandor's new hooks and anti-module-reload mechanism. --- CAPE/CAPE.c | 6 +- CAPE/Injection.c | 30 +++-- cuckoomon.c | 34 +++++- hook_misc.c | 294 +++++++++++++++++++++++++++++++++++++++++++++-- hook_process.c | 33 +++--- hooks.h | 123 +++++++++++++++++++- misc.c | 38 ++++++ misc.h | 8 +- pipe.c | 94 +++++++-------- 9 files changed, 553 insertions(+), 107 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index f8ab68f..a98d0e6 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -569,10 +569,7 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) while (CurrentSectionView) { if (CurrentSectionView->SectionHandle == SectionHandle) - { - DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); return CurrentSectionView; - } CurrentSectionView = CurrentSectionView->NextSectionView; } @@ -1453,6 +1450,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) //break; } } + MachineProbe += sizeof(WORD); if (pNtHeader && (PUCHAR)pNtHeader == (PUCHAR)pDosHeader && pNtHeader->OptionalHeader.SizeOfHeaders) @@ -1471,8 +1469,6 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) *(WORD*)pDosHeader = IMAGE_DOS_SIGNATURE; *(DWORD*)((PUCHAR)pDosHeader + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; - SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)pDosHeader); - if (DumpImageInCurrentProcess((LPVOID)pDosHeader)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", pDosHeader); diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 1d6838b..c783ba4 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -143,7 +143,7 @@ void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROC DoOutputDebugString("CreateProcessHandler: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); } -void OpenProcessHandler(PHANDLE ProcessHandle, int Pid) +void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid) { struct InjectionInfo *CurrentInjectionInfo; DWORD BufferSize = MAX_PATH; @@ -171,9 +171,7 @@ void OpenProcessHandler(PHANDLE ProcessHandle, int Pid) CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - if (!CurrentInjectionInfo->ImageBase) - DoOutputDebugString("OpenProcessHandler: Error obtaining target process image base for process %d (handle 0x%x).\n", Pid, *ProcessHandle); - else + if (CurrentInjectionInfo->ImageBase) DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); @@ -196,12 +194,10 @@ void OpenProcessHandler(PHANDLE ProcessHandle, int Pid) } } -void ResumeProcessHandler(HANDLE ProcessHandle) +void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid) { struct InjectionInfo *CurrentInjectionInfo; - DWORD Pid = pid_from_process_handle(ProcessHandle); - CurrentInjectionInfo = GetInjectionInfo(Pid); if (CurrentInjectionInfo) @@ -237,6 +233,8 @@ void UnmapSectionViewHandler(PVOID BaseAddress) if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) { DoOutputDebugString("UnmapSectionViewHandler: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = CurrentSectionView->TargetProcessId; DumpSectionView(CurrentSectionView); } @@ -255,7 +253,7 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas DWORD Pid = pid_from_process_handle(ProcessHandle); CurrentInjectionInfo = GetInjectionInfo(Pid); - + if (Pid == GetCurrentProcessId()) { PINJECTIONSECTIONVIEW CurrentSectionView = GetSectionView(SectionHandle); @@ -282,7 +280,7 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas if (CurrentSectionViewInfo) { CurrentSectionViewInfo->TargetProcessId = Pid; - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, Pid); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d.\n", SectionHandle, Pid); } else { @@ -321,7 +319,7 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas if (CurrentSectionViewInfo) { CurrentSectionViewInfo->TargetProcessId = Pid; - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and to target process %d.\n", SectionHandle, Pid); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d.\n", SectionHandle, Pid); } else DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, Pid); @@ -329,7 +327,7 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas } } -void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesToWrite, PSIZE_T NumberOfBytesWritten) +void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesWritten) { DWORD Pid; struct InjectionInfo *CurrentInjectionInfo; @@ -343,7 +341,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer if (!CurrentInjectionInfo || CurrentInjectionInfo->ProcessId != Pid) return; - if (*NumberOfBytesWritten == 0) + if (NumberOfBytesWritten == 0) return; CurrentInjectionInfo->WriteDetected = TRUE; @@ -377,7 +375,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = Pid; - if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) + if (DumpMemory((LPVOID)Buffer, NumberOfBytesWritten)) DoOutputDebugString("WriteMemoryHandler: Dumped malformed PE image from buffer."); else DoOutputDebugString("WriteMemoryHandler: Failed to dump malformed PE image from buffer."); @@ -386,7 +384,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer } else { - if (*NumberOfBytesWritten > 0x10) + if (NumberOfBytesWritten > 0x10) { if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) @@ -397,12 +395,12 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer } else { - DoOutputDebugString("WriteMemoryHandler: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, *NumberOfBytesWritten, Pid); + DoOutputDebugString("WriteMemoryHandler: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, NumberOfBytesWritten, Pid); // dump injected code/data CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = Pid; - if (DumpMemory((LPVOID)Buffer, *NumberOfBytesWritten)) + if (DumpMemory((LPVOID)Buffer, NumberOfBytesWritten)) DoOutputDebugString("WriteMemoryHandler: Dumped injected code/data from buffer."); else DoOutputDebugString("WriteMemoryHandler: Failed to dump injected code/data from buffer."); diff --git a/cuckoomon.c b/cuckoomon.c index 5a58e0f..cf90253 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -86,6 +86,8 @@ static hook_t g_hooks[] = { //HOOK_SPECIAL(ntdll, NtCreateThread), //HOOK_SPECIAL(ntdll, NtCreateThreadEx), //HOOK_SPECIAL(ntdll, NtTerminateThread), + //HOOK_SPECIAL(kernel32, lstrcpynA), + //HOOK_SPECIAL(kernel32, lstrcmpiA), // has special handling @@ -275,8 +277,8 @@ static hook_t g_hooks[] = { //HOOK(user32, EnumWindows), HOOK(user32, PostMessageA), HOOK(user32, PostMessageW), - HOOK(user32, SendMessageA), - HOOK(user32, SendMessageW), + //HOOK(user32, SendMessageA), + //HOOK(user32, SendMessageW), HOOK(user32, SendNotifyMessageA), HOOK(user32, SendNotifyMessageW), HOOK(user32, SetWindowLongA), @@ -366,7 +368,6 @@ static hook_t g_hooks[] = { HOOK(ntdll, memcpy), #endif HOOK(msvcrt, memcpy), - //HOOK(kernel32, SizeofResource), HOOK(msvcrt, srand), // for debugging only @@ -429,6 +430,28 @@ static hook_t g_hooks[] = { HOOK(pstorec, PStoreCreateInstance), HOOK(advapi32, SaferIdentifyLevel), + // PE resource related functions + HOOK(kernel32, FindResourceExA), + HOOK(kernel32, FindResourceExW), + HOOK(kernel32, LoadResource), + HOOK(kernel32, LockResource), + HOOK(kernel32, SizeofResource), + + // functions with callbacks (abused for control-flow transfer) + HOOK(kernel32, EnumResourceTypesExA), + HOOK(kernel32, EnumResourceTypesExW), + HOOK(kernel32, EnumCalendarInfoA), + HOOK(kernel32, EnumCalendarInfoW), + HOOK(kernel32, EnumTimeFormatsA), + HOOK(kernel32, EnumTimeFormatsW), + + // transaction functions (for process doppel-ganging) + HOOK(ntdll, NtCreateTransaction), + HOOK(ntdll, NtOpenTransaction), + HOOK(ntdll, NtRollbackTransaction), + HOOK(ntdll, NtCommitTransaction), + HOOK(ntdll, RtlSetCurrentTransaction), + // // Network Hooks // @@ -662,10 +685,9 @@ VOID CALLBACK New_DllLoadNotification( if (NotificationReason == 1) { if (g_config.file_of_interest && !wcsicmp(library.Buffer, g_config.file_of_interest)) { - if (base_of_dll_of_interest) - DoOutputDebugString("Target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); - else + if (!base_of_dll_of_interest) set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); + DoOutputDebugString("Target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); } else { // unoptimized, but easy diff --git a/hook_misc.c b/hook_misc.c index 0836d57..2e80868 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -1107,25 +1107,297 @@ HOOKDEF(void, WINAPIV, memcpy, return; } -HOOKDEF(unsigned int, WINAPIV, SizeofResource, - _In_opt_ HMODULE hModule, - _In_ HRSRC hResInfo +HOOKDEF(void, WINAPIV, srand, + unsigned int seed ) { - unsigned int ret = Old_SizeofResource(hModule, hResInfo); + int ret = 0; // needed for LOQ_void + + Old_srand(seed); + + LOQ_void("misc", "h", "seed", seed); +} + +HOOKDEF(LPSTR, WINAPI, lstrcpynA, + _Out_ LPSTR lpString1, + _In_ LPSTR lpString2, + _In_ int iMaxLength +) +{ + LPSTR ret; + + ret = Old_lstrcpynA(lpString1, lpString2, iMaxLength); + + LOQ_nonzero("misc", "u", "String", lpString1); - LOQ_nonzero("misc", "ppi", "ModuleHandle", hModule, "ResourceInfo", hResInfo, "Size", ret); - return ret; } -HOOKDEF(void, WINAPIV, srand, - unsigned int seed +HOOKDEF(int, WINAPI, lstrcmpiA, + _In_ LPCSTR lpString1, + _In_ LPCSTR lpString2 ) { - int ret = 0; // needed for LOQ_void + int ret; - Old_srand(seed); + ret = Old_lstrcmpiA(lpString1, lpString2); - LOQ_void("misc", "h", "seed", seed); + LOQ_nonzero("misc", "ss", "String1", lpString1, "String2", lpString2); + + return ret; +} + +HOOKDEF(HRSRC, WINAPI, FindResourceExA, + HMODULE hModule, + LPCSTR lpType, + LPCSTR lpName, + WORD wLanguage +) +{ + HRSRC ret = Old_FindResourceExA(hModule, lpType, lpName, wLanguage); + + char type_id[8]; + if (IS_INTRESOURCE(lpType)) { + snprintf(type_id, sizeof type_id, "#%hu", (WORD)lpType); + lpType = type_id; + } + + char name_id[8]; + if (IS_INTRESOURCE(lpName)) { + snprintf(name_id, sizeof name_id, "#%hu", (WORD)lpName); + lpName = name_id; + } + + LOQ_handle("misc", "pssh", "Module", hModule, "Type", lpType, "Name", lpName, "Language", wLanguage); + + return ret; +} + +HOOKDEF(HRSRC, WINAPI, FindResourceExW, + HMODULE hModule, + LPCWSTR lpType, + LPCWSTR lpName, + WORD wLanguage +) +{ + HRSRC ret = Old_FindResourceExW(hModule, lpType, lpName, wLanguage); + + wchar_t type_id[8]; + if (IS_INTRESOURCE(lpType)) { + swprintf(type_id, sizeof type_id, L"#%hu", (WORD)lpType); + lpType = type_id; + } + + wchar_t name_id[8]; + if (IS_INTRESOURCE(lpName)) { + swprintf(name_id, sizeof name_id, L"#%hu", (WORD)lpName); + lpName = name_id; + } + + LOQ_handle("misc", "puuh", "Module", hModule, "Type", lpType, "Name", lpName, "Language", wLanguage); + + return ret; +} + +HOOKDEF(HGLOBAL, WINAPI, LoadResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +) +{ + HGLOBAL ret = Old_LoadResource(hModule, hResInfo); + + LOQ_handle("misc", "pp", "Module", hModule, "ResourceInfo", hResInfo); + + return ret; +} + +HOOKDEF(LPVOID, WINAPI, LockResource, + _In_ HGLOBAL hResData +) +{ + LPVOID ret = Old_LockResource(hResData); + + LOQ_nonnull("misc", "p", "ResourceData", hResData); + + return ret; +} + +HOOKDEF(DWORD, WINAPI, SizeofResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +) +{ + DWORD ret = Old_SizeofResource(hModule, hResInfo); + + LOQ_nonzero("misc", "pp", "ModuleHandle", hModule, "ResourceInfo", hResInfo); + + return ret; +} + +HOOKDEF(BOOL, WINAPI, EnumResourceTypesExA, + _In_opt_ HMODULE hModule, + _In_ ENUMRESTYPEPROC lpEnumFunc, + _In_ LONG_PTR lParam, + _In_ DWORD dwFlags, + _In_ LANGID LangId +) { + BOOL ret = TRUE; + LOQ_bool("misc", "ppphh", + "ModuleHandle", hModule, + "EnumFunc", lpEnumFunc, + "Parameter", lParam, + "Flags", dwFlags, + "LangId", LangId + ); + return Old_EnumResourceTypesExA(hModule, lpEnumFunc, lParam, dwFlags, LangId);; +} + +HOOKDEF(BOOL, WINAPI, EnumResourceTypesExW, + _In_opt_ HMODULE hModule, + _In_ ENUMRESTYPEPROC lpEnumFunc, + _In_ LONG_PTR lParam, + _In_ DWORD dwFlags, + _In_ LANGID LangId +) { + BOOL ret = TRUE; + LOQ_bool("misc", "ppphh", + "ModuleHandle", hModule, + "EnumFunc", lpEnumFunc, + "Parameter", lParam, + "Flags", dwFlags, + "LangId", LangId + ); + return Old_EnumResourceTypesExW(hModule, lpEnumFunc, lParam, dwFlags, LangId);; +} + +HOOKDEF(BOOL, WINAPI, EnumCalendarInfoA, + CALINFO_ENUMPROCA lpCalInfoEnumProc, + LCID Locale, + CALID Calendar, + CALTYPE CalType +) { + BOOL ret = TRUE; + LOQ_bool("misc", "phhh", + "CalInfoEnumProc", lpCalInfoEnumProc, + "Locale", Locale, + "Calendar", Calendar, + "CalType", CalType + ); + return Old_EnumCalendarInfoA(lpCalInfoEnumProc, Locale, Calendar, CalType); +} + +HOOKDEF(BOOL, WINAPI, EnumCalendarInfoW, + CALINFO_ENUMPROCA lpCalInfoEnumProc, + LCID Locale, + CALID Calendar, + CALTYPE CalType +) { + BOOL ret = TRUE; + LOQ_bool("misc", "phhh", + "CalInfoEnumProc", lpCalInfoEnumProc, + "Locale", Locale, + "Calendar", Calendar, + "CalType", CalType + ); + return Old_EnumCalendarInfoW(lpCalInfoEnumProc, Locale, Calendar, CalType); +} + +HOOKDEF(BOOL, WINAPI, EnumTimeFormatsA, + TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, + LCID Locale, + DWORD dwFlags +) { + BOOL ret = TRUE; + LOQ_bool("misc", "phh", + "TimeFmtEnumProc", lpTimeFmtEnumProc, + "Locale", Locale, + "Flags", dwFlags + ); + return Old_EnumTimeFormatsA(lpTimeFmtEnumProc, Locale, dwFlags); +} + +HOOKDEF(BOOL, WINAPI, EnumTimeFormatsW, + TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, + LCID Locale, + DWORD dwFlags +) { + BOOL ret = TRUE; + LOQ_bool("misc", "phh", + "TimeFmtEnumProc", lpTimeFmtEnumProc, + "Locale", Locale, + "Flags", dwFlags + ); + return Old_EnumTimeFormatsW(lpTimeFmtEnumProc, Locale, dwFlags); +} + +HOOKDEF(NTSTATUS, WINAPI, NtCreateTransaction, + PHANDLE TransactionHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + LPGUID Uow, + HANDLE TmHandle, + ULONG CreateOptions, + ULONG IsolationLevel, + ULONG IsolationFlags, + PLARGE_INTEGER Timeout, + PUNICODE_STRING Description +) { + NTSTATUS ret = Old_NtCreateTransaction(TransactionHandle, DesiredAccess, ObjectAttributes, Uow, TmHandle, CreateOptions, IsolationLevel, IsolationFlags, Timeout, Description); + LOQ_ntstatus("misc", "PhObphhhio", + "TransactionHandle", TransactionHandle, + "DesiredAccess", DesiredAccess, + "ObjectAttributes", ObjectAttributes, + "UnitOfWork", sizeof (GUID), Uow, + "TmHandle", TmHandle, + "CreateOptions", CreateOptions, + "IsolationLevel", IsolationLevel, + "IsolationFlags", IsolationFlags, + "Timeout", Timeout, + "Description", Description + ); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtOpenTransaction, + PHANDLE TransactionHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + LPGUID Uow, + HANDLE TmHandle +) { + NTSTATUS ret = Old_NtOpenTransaction(TransactionHandle, DesiredAccess, ObjectAttributes, Uow, TmHandle); + LOQ_ntstatus("misc", "PhObp", + "TransactionHandle", TransactionHandle, + "DesiredAccess", DesiredAccess, + "ObjectAttributes", ObjectAttributes, + "UnitOfWork", sizeof (GUID), Uow, + "TmHandle", TmHandle + ); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtRollbackTransaction, + HANDLE TransactionHandle, + BOOLEAN Wait +) { + NTSTATUS ret = Old_NtRollbackTransaction(TransactionHandle, Wait); + LOQ_ntstatus("misc", "pi", "TransactionHandle", TransactionHandle, "Wait", Wait); + return ret; +} + +HOOKDEF(NTSTATUS, WINAPI, NtCommitTransaction, + HANDLE TransactionHandle, + BOOLEAN Wait +) { + NTSTATUS ret = Old_NtCommitTransaction(TransactionHandle, Wait); + LOQ_ntstatus("misc", "pi", "TransactionHandle", TransactionHandle, "Wait", Wait); + return ret; +} + +HOOKDEF(BOOL, WINAPI, RtlSetCurrentTransaction, + _In_ HANDLE TransactionHandle +) { + BOOL ret = Old_RtlSetCurrentTransaction(TransactionHandle); + LOQ_bool("misc", "p", "TransactionHandle", TransactionHandle); + return ret; } diff --git a/hook_process.c b/hook_process.c index 50a3e07..f7feb51 100644 --- a/hook_process.c +++ b/hook_process.c @@ -33,11 +33,11 @@ extern void file_handle_terminate(); extern int RoutineProcessDump(); extern BOOL ProcessDumped; #ifdef CAPE_INJECTION -extern void OpenProcessHandler(PHANDLE ProcessHandle, int Pid); -extern void ResumeProcessHandler(HANDLE ProcessHandle); +extern void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid); +extern void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid); extern void UnmapSectionViewHandler(PVOID BaseAddress); extern void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, PSIZE_T ViewSize); -extern void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesToWrite, PSIZE_T NumberOfBytesWritten); +extern void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesWritten); #endif HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, @@ -319,12 +319,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, // although the documentation on msdn is a bit vague, this seems correct // for both XP and Vista (the ClientId->UniqueProcess part, that is) - int pid = 0; + DWORD pid = 0; NTSTATUS ret; if(ClientId != NULL) { __try { - pid = (int)(ULONG_PTR)ClientId->UniqueProcess; + pid = (DWORD)(ULONG_PTR)ClientId->UniqueProcess; } __except (EXCEPTION_EXECUTE_HANDLER) { ; @@ -356,7 +356,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, NTSTATUS ret; DWORD pid = pid_from_process_handle(ProcessHandle); pipe("RESUME:%d", pid); - +#ifdef CAPE_INJECTION + ResumeProcessHandler(ProcessHandle, pid); +#endif ret = Old_NtResumeProcess(ProcessHandle); LOQ_ntstatus("process", "p", "ProcessHandle", ProcessHandle); return ret; @@ -482,12 +484,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, sizeof(mbi)) == sizeof(mbi)) { map_size = mbi.RegionSize; } - ret = Old_NtUnmapViewOfSection(ProcessHandle, BaseAddress); - #ifdef CAPE_INJECTION UnmapSectionViewHandler(BaseAddress); #endif + ret = Old_NtUnmapViewOfSection(ProcessHandle, BaseAddress); + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", map_size); @@ -516,13 +518,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, "SectionOffset", SectionOffset, "ViewSize", ViewSize, "Win32Protect", Win32Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); if (NT_SUCCESS(ret)) { - if (pid != GetCurrentProcessId()) { - pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); - disable_sleep_skip(); #ifdef CAPE_INJECTION - MapSectionViewHandler(SectionHandle, ProcessHandle, *BaseAddress, ViewSize); + MapSectionViewHandler(SectionHandle, ProcessHandle, *BaseAddress, ViewSize); #endif + if (pid != GetCurrentProcessId()) { + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + disable_sleep_skip(); } + //else { + // prevent_module_reloading(BaseAddress); + //} } return ret; } @@ -609,7 +614,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); #ifdef CAPE_INJECTION - WriteMemoryHandler(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten); + WriteMemoryHandler(ProcessHandle, BaseAddress, Buffer, *NumberOfBytesWritten); #endif } } @@ -641,7 +646,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); #ifdef CAPE_INJECTION - WriteMemoryHandler(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten); + WriteMemoryHandler(hProcess, lpBaseAddress, lpBuffer, *lpNumberOfBytesWritten); #endif } } diff --git a/hooks.h b/hooks.h index 17cb12a..6b5119b 100644 --- a/hooks.h +++ b/hooks.h @@ -2864,11 +2864,6 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtQuerySystemInformation, _Out_opt_ PULONG ReturnLength ); -extern HOOKDEF(unsigned int, WINAPIV, SizeofResource, - _In_opt_ HMODULE hModule, - _In_ HRSRC hResInfo -); - extern HOOKDEF(void, WINAPIV, srand, unsigned int seed ); @@ -2886,4 +2881,120 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationThread, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL -); \ No newline at end of file +); + +extern HOOKDEF(LPSTR, WINAPI, lstrcpynA, + _Out_ LPSTR lpString1, + _In_ LPSTR lpString2, + _In_ int iMaxLength +); + +extern HOOKDEF(int, WINAPI, lstrcmpiA, + _In_ LPCSTR lpString1, + _In_ LPCSTR lpString2 +); + +extern HOOKDEF(HRSRC, WINAPI, FindResourceExA, + HMODULE hModule, + LPCSTR lpType, + LPCSTR lpName, + WORD wLanguage +); + +extern HOOKDEF(HRSRC, WINAPI, FindResourceExW, + HMODULE hModule, + LPCWSTR lpType, + LPCWSTR lpName, + WORD wLanguage +); + +extern HOOKDEF(HGLOBAL, WINAPI, LoadResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +); + +extern HOOKDEF(LPVOID, WINAPI, LockResource, + _In_ HGLOBAL hResData +); + +extern HOOKDEF(DWORD, WINAPI, SizeofResource, + _In_opt_ HMODULE hModule, + _In_ HRSRC hResInfo +); + +extern HOOKDEF(BOOL, WINAPI, EnumResourceTypesExA, + _In_opt_ HMODULE hModule, + _In_ ENUMRESTYPEPROC lpEnumFunc, + _In_ LONG_PTR lParam, + _In_ DWORD dwFlags, + _In_ LANGID LangId +); + +extern HOOKDEF(BOOL, WINAPI, EnumResourceTypesExW, + _In_opt_ HMODULE hModule, + _In_ ENUMRESTYPEPROC lpEnumFunc, + _In_ LONG_PTR lParam, + _In_ DWORD dwFlags, + _In_ LANGID LangId +); + +extern HOOKDEF(BOOL, WINAPI, EnumCalendarInfoA, + CALINFO_ENUMPROCA lpCalInfoEnumProc, + LCID Locale, + CALID Calendar, + CALTYPE CalType +); + +extern HOOKDEF(BOOL, WINAPI, EnumCalendarInfoW, + CALINFO_ENUMPROCA lpCalInfoEnumProc, + LCID Locale, + CALID Calendar, + CALTYPE CalType +); + +extern HOOKDEF(BOOL, WINAPI, EnumTimeFormatsA, + TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, + LCID Locale, + DWORD dwFlags +); + +extern HOOKDEF(BOOL, WINAPI, EnumTimeFormatsW, + TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, + LCID Locale, + DWORD dwFlags +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtCreateTransaction, + PHANDLE TransactionHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + LPGUID Uow, + HANDLE TmHandle, + ULONG CreateOptions, + ULONG IsolationLevel, + ULONG IsolationFlags, + PLARGE_INTEGER Timeout, + PUNICODE_STRING Description +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtOpenTransaction, + PHANDLE TransactionHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + LPGUID Uow, + HANDLE TmHandle +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtRollbackTransaction, + HANDLE TransactionHandle, + BOOLEAN Wait +); + +extern HOOKDEF(NTSTATUS, WINAPI, NtCommitTransaction, + HANDLE TransactionHandle, + BOOLEAN Wait +); + +extern HOOKDEF(BOOL, WINAPI, RtlSetCurrentTransaction, + _In_ HANDLE TransactionHandle +); diff --git a/misc.c b/misc.c index 25e5158..2db5950 100644 --- a/misc.c +++ b/misc.c @@ -19,6 +19,7 @@ along with this program. If not, see . #include #include #include "ntapi.h" +#include #include #include #include "misc.h" @@ -37,6 +38,7 @@ static _NtQueryObject pNtQueryObject; static _NtQueryKey pNtQueryKey; static _NtDelayExecution pNtDelayExecution; static _NtQuerySystemInformation pNtQuerySystemInformation; +static _NtUnmapViewOfSection pNtUnmapViewOfSection; _NtAllocateVirtualMemory pNtAllocateVirtualMemory; _NtProtectVirtualMemory pNtProtectVirtualMemory; _NtFreeVirtualMemory pNtFreeVirtualMemory; @@ -58,6 +60,7 @@ void resolve_runtime_apis(void) *(FARPROC *)&pNtFreeVirtualMemory = GetProcAddress(ntdllbase, "NtFreeVirtualMemory"); *(FARPROC *)&pLdrRegisterDllNotification = GetProcAddress(ntdllbase, "LdrRegisterDllNotification"); *(FARPROC *)&pRtlGenRandom = GetProcAddress(GetModuleHandle("advapi32"), "SystemFunction036"); + *(FARPROC *)&pNtUnmapViewOfSection = GetProcAddress(ntdllbase, "NtUnmapViewOfSection"); } ULONG_PTR g_our_dll_base; @@ -1867,3 +1870,38 @@ BOOLEAN is_address_in_ntdll(ULONG_PTR address) return FALSE; } + +void prevent_module_reloading(PVOID *BaseAddress) { + // prevent hook evasion via mapping system libraries (e.g. ntdll.dll) from disk + // this still won't stop reading the file using NtReadFile and mapping it manually + wchar_t *whitelist[] = { + L"C:\\Windows\\System32\\ntdll.dll", + L"C:\\Windows\\SysWOW64\\ntdll.dll", + NULL + }; + + // get the file path for the mapped section + wchar_t *filepath = malloc(MAX_PATH * sizeof(wchar_t)); + GetMappedFileNameW(GetCurrentProcess(), *BaseAddress, filepath, MAX_PATH); + + // convert device path to an actual path + wchar_t *absolutepath = malloc(32768 * sizeof(wchar_t)); + ensure_absolute_unicode_path(absolutepath, filepath); + free(filepath); + + // check against the whitelist + for (int i = 0; whitelist[i]; i++) { + if (!wcsicmp(whitelist[i], absolutepath)) { + // is this a loaded module? + HMODULE address = GetModuleHandleW(absolutepath); + if (address != NULL) { + pipe("INFO:Sample tried to reload already loaded module '%Z' from disk, returning original module address instead: 0x%x", absolutepath, address); + pNtUnmapViewOfSection(GetCurrentProcess(), *BaseAddress); + *BaseAddress = (LPVOID)address; + } + break; + } + } + + free(absolutepath); +} diff --git a/misc.h b/misc.h index ecdfffa..16f3f40 100644 --- a/misc.h +++ b/misc.h @@ -46,8 +46,10 @@ typedef NTSTATUS(WINAPI *_NtQueryKey)( PULONG ResultLength); typedef NTSTATUS(WINAPI *_NtDelayExecution)( BOOLEAN Alertable, - PLARGE_INTEGER Interval - ); + PLARGE_INTEGER Interval); +typedef NTSTATUS(WINAPI *_NtUnmapViewOfSection)( + HANDLE ProcessHandle, + PVOID BaseAddress); typedef struct _LDR_DLL_LOADED_NOTIFICATION_DATA { ULONG Flags; @@ -200,3 +202,5 @@ wchar_t *ascii_to_unicode_dup(char *str); int is_stack_pivoted(void); LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); + +void prevent_module_reloading(PVOID *BaseAddress); diff --git a/pipe.c b/pipe.c index f131124..5c81e4c 100644 --- a/pipe.c +++ b/pipe.c @@ -68,42 +68,42 @@ static int _pipe_sprintf(char *out, const char *fmt, va_list args) ret += _pipe_ascii(&out, s, (int)strlen(s)); } - else if (*fmt == 'c') { - char buf[2]; - buf[0] = va_arg(args, char); - buf[1] = '\0'; - ret += _pipe_ascii(&out, buf, 1); - } + else if (*fmt == 'c') { + char buf[2]; + buf[0] = va_arg(args, char); + buf[1] = '\0'; + ret += _pipe_ascii(&out, buf, 1); + } else if(*fmt == 'Z') { const wchar_t *s = va_arg(args, const wchar_t *); if(s == NULL) return -1; ret += _pipe_unicode(&out, s, lstrlenW(s)); } - else if (*fmt == 'F') { - const wchar_t *s = va_arg(args, const wchar_t *); - wchar_t *absolutepath = malloc(32768 * sizeof(wchar_t)); - if (s == NULL) return -1; - if (absolutepath) { - ensure_absolute_unicode_path(absolutepath, s); - ret += _pipe_unicode(&out, absolutepath, lstrlenW(absolutepath)); - free(absolutepath); - } - else { - return -1; - } - } - else if (*fmt == 's') { + else if (*fmt == 'F') { + const wchar_t *s = va_arg(args, const wchar_t *); + wchar_t *absolutepath = malloc(32768 * sizeof(wchar_t)); + if (s == NULL) return -1; + if (absolutepath) { + ensure_absolute_unicode_path(absolutepath, s); + ret += _pipe_unicode(&out, absolutepath, lstrlenW(absolutepath)); + free(absolutepath); + } + else { + return -1; + } + } + else if (*fmt == 's') { int len = va_arg(args, int); const char *s = va_arg(args, const char *); - if(s == NULL) return -1; + if(s == NULL || !is_valid_address_range((ULONG_PTR)s, len)) return -1; - ret += _pipe_ascii(&out, s, len < 0 ? (int)strlen(s) : len); + ret += _pipe_ascii(&out, s, len < 0 ? (int)strlen(s) : len); } else if(*fmt == 'S') { int len = va_arg(args, int); const wchar_t *s = va_arg(args, const wchar_t *); - if(s == NULL) return -1; + if(s == NULL || !is_valid_address_range((ULONG_PTR)s, len)) return -1; ret += _pipe_unicode(&out, s, len < 0 ? lstrlenW(s) : len); } @@ -116,43 +116,43 @@ static int _pipe_sprintf(char *out, const char *fmt, va_list args) } else if(*fmt == 'O') { OBJECT_ATTRIBUTES *obj = va_arg(args, OBJECT_ATTRIBUTES *); - wchar_t path[MAX_PATH_PLUS_TOLERANCE]; - wchar_t *absolutepath; + wchar_t path[MAX_PATH_PLUS_TOLERANCE]; + wchar_t *absolutepath; if(obj == NULL || obj->ObjectName == NULL) return -1; - absolutepath = malloc(32768 * sizeof(wchar_t)); - if (absolutepath) { - path_from_object_attributes(obj, path, (unsigned int)MAX_PATH_PLUS_TOLERANCE); + absolutepath = malloc(32768 * sizeof(wchar_t)); + if (absolutepath) { + path_from_object_attributes(obj, path, (unsigned int)MAX_PATH_PLUS_TOLERANCE); - ensure_absolute_unicode_path(absolutepath, path); + ensure_absolute_unicode_path(absolutepath, path); - ret += _pipe_unicode(&out, absolutepath, lstrlenW(absolutepath)); - free(absolutepath); - } - else { - ret += _pipe_unicode(&out, L"", 0); - } + ret += _pipe_unicode(&out, absolutepath, lstrlenW(absolutepath)); + free(absolutepath); + } + else { + ret += _pipe_unicode(&out, L"", 0); + } } else if(*fmt == 'd') { char s[32]; - num_to_string(s, sizeof(s), va_arg(args, int)); - ret += _pipe_ascii(&out, s, (int)strlen(s)); + num_to_string(s, sizeof(s), va_arg(args, int)); + ret += _pipe_ascii(&out, s, (int)strlen(s)); } else if(*fmt == 'x') { char s[16]; sprintf(s, "%x", va_arg(args, int)); - ret += _pipe_ascii(&out, s, (int)strlen(s)); + ret += _pipe_ascii(&out, s, (int)strlen(s)); + } + else if (*fmt == 'p') { + char s[18]; + sprintf(s, "%p", va_arg(args, void *)); + ret += _pipe_ascii(&out, s, (int)strlen(s)); + } + else { + const char *msg = "-- UNKNOWN FORMAT STRING -- "; + ret += _pipe_ascii(&out, msg, (int)strlen(msg)); } - else if (*fmt == 'p') { - char s[18]; - sprintf(s, "%p", va_arg(args, void *)); - ret += _pipe_ascii(&out, s, (int)strlen(s)); - } - else { - const char *msg = "-- UNKNOWN FORMAT STRING -- "; - ret += _pipe_ascii(&out, msg, (int)strlen(msg)); - } fmt++; } return ret; From 1e5924c2fc0d715eb1909bb2eb1a549722527a7b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Aug 2018 10:25:41 +0100 Subject: [PATCH 30/39] Fix numerous issues with new refactoring work --- CAPE/Debugger.c | 20 ++++----- CAPE/Injection.c | 104 ++++++++++++++++++++++++---------------------- cuckoomon.c | 4 +- cuckoomon.vcxproj | 2 +- hook_process.c | 42 ++++++++++--------- hook_special.c | 10 ++--- hook_thread.c | 12 +++--- 7 files changed, 101 insertions(+), 93 deletions(-) diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index 3778ca8..f12e8b7 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -919,7 +919,7 @@ BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ContextGetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); + DoOutputDebugString("ContextGetNextAvailableBreakpoint: Error - cannot create new thread breakpoints.\n"); return FALSE; } @@ -951,7 +951,7 @@ void DebugOutputThreadBreakpoints() if (pBreakpointInfo == NULL) { - DoOutputDebugString("DebugOutputThreadBreakpoints: Can't get BreakpointInfo - FATAL.\n"); + DoOutputDebugString("DebugOutputThreadBreakpoints: Error - can't get BreakpointInfo.\n"); } DoOutputDebugString("Callback = 0x%x, Address = 0x%x, Size = 0x%x, Register = %i, ThreadHandle = 0x%x, Type = 0x%x\n", @@ -996,7 +996,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); + DoOutputDebugString("CAPEExceptionFilter: Error - can't get thread breakpoints.\n"); return EXCEPTION_CONTINUE_SEARCH; } @@ -1048,7 +1048,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (pBreakpointInfo == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Can't get BreakpointInfo - FATAL.\n"); + DoOutputDebugString("CAPEExceptionFilter: Error - can't get BreakpointInfo.\n"); return EXCEPTION_CONTINUE_EXECUTION; } @@ -1129,7 +1129,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (pBreakpointInfo->Callback == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Can't get callback - FATAL.\n"); + DoOutputDebugString("CAPEExceptionFilter: Error - can't get callback.\n"); return EXCEPTION_CONTINUE_EXECUTION; } @@ -2084,7 +2084,7 @@ int CheckDebugRegister(HANDLE hThread, int Register) if (!GetThreadContext(hThread, &Context)) { - DoOutputDebugString("CheckDebugRegister: GetThreadContext failed - FATAL\n"); + DoOutputDebugString("CheckDebugRegister: Error - GetThreadContext failed.\n"); return FALSE; } @@ -2438,7 +2438,7 @@ BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ClearBreakpointWithoutThread: Cannot create new thread breakpoints - FATAL.\n"); + DoOutputDebugString("ClearBreakpointWithoutThread: Error - cannot create new thread breakpoints.\n"); return FALSE; } @@ -2497,7 +2497,7 @@ BOOL SetBreakpointWithoutThread if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetBreakpointWithoutThread: Cannot create new thread breakpoints - FATAL.\n"); + DoOutputDebugString("SetBreakpointWithoutThread: Error - cannot create new thread breakpoints.\n"); return FALSE; } @@ -2844,7 +2844,7 @@ BOOL SetNextAvailableBreakpoint if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); + DoOutputDebugString("SetNextAvailableBreakpoint: Error - cannot create new thread breakpoints.\n"); return FALSE; } @@ -3114,7 +3114,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati Context.ContextFlags = CONTEXT_ALL; if (!GetThreadContext(hThread, &Context)) { - DoOutputDebugString("DebugNewProcess: GetThreadContext failed - FATAL\n"); + DoOutputDebugString("DebugNewProcess: Error - GetThreadContext failed.\n"); return FALSE; } diff --git a/CAPE/Injection.c b/CAPE/Injection.c index c783ba4..18a0855 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -57,7 +57,7 @@ void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context) if (Context->Rip == (DWORD_PTR)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) DoOutputDebugString("SetThreadContextHandler: Hollow process entry point set to NtMapViewOfSection (process %d).\n", Pid); else - DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%p (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); #else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) CurrentInjectionInfo->EntryPoint = Context->Eax - CurrentInjectionInfo->ImageBase; // eax holds ep on 32-bit @@ -65,7 +65,7 @@ void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context) if (Context->Eip == (DWORD)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) DoOutputDebugString("SetThreadContextHandler: Hollow process entry point set to NtMapViewOfSection (process %d).\n", Pid); else - DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%x (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); + DoOutputDebugString("SetThreadContextHandler: Hollow process entry point reset via NtSetContextThread to 0x%p (process %d).\n", CurrentInjectionInfo->EntryPoint, Pid); #endif } } @@ -85,7 +85,7 @@ void ResumeThreadHandler(DWORD Pid) CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = Pid; - DoOutputDebugString("ResumeThreadHandler: Dumping hollowed process %d, image base 0x%x.\n", Pid, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("ResumeThreadHandler: Dumping hollowed process %d, image base 0x%p.\n", Pid, CurrentInjectionInfo->ImageBase); CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); @@ -110,7 +110,7 @@ void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROC if (CurrentInjectionInfo == NULL) { - DoOutputDebugString("CreateProcessHandler: Failed to create injection info for new process %d, ImageBase: 0x%x", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("CreateProcessHandler: Failed to create injection info for new process %d, ImageBase: 0x%p", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); return; } @@ -140,10 +140,10 @@ void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROC WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, (int)wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); - DoOutputDebugString("CreateProcessHandler: Injection info set for new process %d, ImageBase: 0x%x", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("CreateProcessHandler: Injection info set for new process %d, ImageBase: 0x%p", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); } -void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid) +void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid) { struct InjectionInfo *CurrentInjectionInfo; DWORD BufferSize = MAX_PATH; @@ -160,21 +160,21 @@ void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid) if (CurrentInjectionInfo == NULL) { - DoOutputDebugString("OpenProcessHandler: Cannot create new injection info - FATAL ERROR.\n"); + DoOutputDebugString("OpenProcessHandler: Error - cannot create new injection info.\n"); } else { - CurrentInjectionInfo->ProcessHandle = *ProcessHandle; + CurrentInjectionInfo->ProcessHandle = ProcessHandle; CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(BufferSize); - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + if (CurrentInjectionInfo->ImageBase) - DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); - - PathLength = GetProcessImageFileName(*ProcessHandle, DevicePath, BufferSize); + DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, ProcessHandle, CurrentInjectionInfo->ImageBase); + + PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); if (!PathLength) { @@ -187,10 +187,10 @@ void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid) } else if (CurrentInjectionInfo->ImageBase == (DWORD_PTR)NULL) { - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(*ProcessHandle); - + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + if (CurrentInjectionInfo->ImageBase) - DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, *ProcessHandle, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("OpenProcessHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, ProcessHandle, CurrentInjectionInfo->ImageBase); } } @@ -206,7 +206,7 @@ void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid) { SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); - DoOutputDebugString("ResumeProcessHandler: Dumping hollowed process %d, image base 0x%x.\n", Pid, CurrentInjectionInfo->ImageBase); + DoOutputDebugString("ResumeProcessHandler: Dumping hollowed process %d, image base 0x%p.\n", Pid, CurrentInjectionInfo->ImageBase); CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); @@ -222,27 +222,7 @@ void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid) } } -void UnmapSectionViewHandler(PVOID BaseAddress) -{ - PINJECTIONSECTIONVIEW CurrentSectionView; - - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) - { - DoOutputDebugString("UnmapSectionViewHandler: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); - CapeMetaData->DumpType = INJECTION_PE; - CapeMetaData->TargetPid = CurrentSectionView->TargetProcessId; - DumpSectionView(CurrentSectionView); - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } -} - -void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, PSIZE_T ViewSize) +void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID BaseAddress, SIZE_T ViewSize) { struct InjectionInfo *CurrentInjectionInfo; struct InjectionSectionView *CurrentSectionViewInfo; @@ -260,22 +240,22 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas if (!CurrentSectionView) { - AddSectionView(SectionHandle, BaseAddress, *ViewSize); - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%x to global list.\n", SectionHandle, BaseAddress); + AddSectionView(SectionHandle, BaseAddress, ViewSize); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%p to global list.\n", SectionHandle, BaseAddress); } else { if (CurrentSectionView->LocalView != BaseAddress) { CurrentSectionView->LocalView = BaseAddress; - CurrentSectionView->ViewSize = *ViewSize; - DoOutputDebugString("MapSectionViewHandler: Updated local view to 0x%x for section view with handle 0x%x.\n", BaseAddress, SectionHandle); + CurrentSectionView->ViewSize = ViewSize; + DoOutputDebugString("MapSectionViewHandler: Updated local view to 0x%p for section view with handle 0x%x.\n", BaseAddress, SectionHandle); } } } else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) { - CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, *ViewSize); + CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, ViewSize); if (CurrentSectionViewInfo) { @@ -293,17 +273,21 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas if (CurrentInjectionInfo == NULL) { - DoOutputDebugString("MapSectionViewHandler: Cannot create new injection info - FATAL ERROR.\n"); + DoOutputDebugString("MapSectionViewHandler: Cannot create new injection info - error.\n"); } else { CurrentInjectionInfo->ProcessHandle = ProcessHandle; CurrentInjectionInfo->ProcessId = Pid; - CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; CurrentInjectionInfo->ImageDumped = FALSE; CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + + if (CurrentInjectionInfo->ImageBase) + DoOutputDebugString("MapSectionViewHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, ProcessHandle, CurrentInjectionInfo->ImageBase); + PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); if (!PathLength) @@ -314,7 +298,7 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) DoOutputErrorString("MapSectionViewHandler: Error translating target process path"); - CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, *ViewSize); + CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, ViewSize); if (CurrentSectionViewInfo) { @@ -327,6 +311,26 @@ void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID Bas } } +void UnmapSectionViewHandler(PVOID BaseAddress) +{ + PINJECTIONSECTIONVIEW CurrentSectionView; + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId && CurrentSectionView->LocalView == BaseAddress) + { + DoOutputDebugString("UnmapSectionViewHandler: Attempt to unmap view at 0x%p, dumping.\n", BaseAddress); + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = CurrentSectionView->TargetProcessId; + DumpSectionView(CurrentSectionView); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } +} + void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesWritten) { DWORD Pid; @@ -340,10 +344,10 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer if (!CurrentInjectionInfo || CurrentInjectionInfo->ProcessId != Pid) return; - + if (NumberOfBytesWritten == 0) return; - + CurrentInjectionInfo->WriteDetected = TRUE; // Check if we have a valid DOS and PE header at the beginning of Buffer @@ -384,7 +388,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer } else { - if (NumberOfBytesWritten > 0x10) + if (NumberOfBytesWritten > 0x10) // We assign some lower limit { if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) @@ -395,7 +399,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer } else { - DoOutputDebugString("WriteMemoryHandler: Shellcode at 0x%x (size 0x%x) injected into process %d.\n", Buffer, NumberOfBytesWritten, Pid); + DoOutputDebugString("WriteMemoryHandler: shellcode at 0x%p (size 0x%x) injected into process %d.\n", Buffer, NumberOfBytesWritten, Pid); // dump injected code/data CapeMetaData->DumpType = INJECTION_SHELLCODE; diff --git a/cuckoomon.c b/cuckoomon.c index cf90253..1b053af 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -277,8 +277,8 @@ static hook_t g_hooks[] = { //HOOK(user32, EnumWindows), HOOK(user32, PostMessageA), HOOK(user32, PostMessageW), - //HOOK(user32, SendMessageA), - //HOOK(user32, SendMessageW), + HOOK(user32, SendMessageA), + HOOK(user32, SendMessageW), HOOK(user32, SendNotifyMessageA), HOOK(user32, SendNotifyMessageW), HOOK(user32, SetWindowLongA), diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index d1ce263..be9152c 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -168,7 +168,7 @@ - WIN32;_WIN64;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) + WIN32;_WIN64;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions) MultiThreaded Level3 ProgramDatabase diff --git a/hook_process.c b/hook_process.c index f7feb51..aae6680 100644 --- a/hook_process.c +++ b/hook_process.c @@ -33,10 +33,10 @@ extern void file_handle_terminate(); extern int RoutineProcessDump(); extern BOOL ProcessDumped; #ifdef CAPE_INJECTION -extern void OpenProcessHandler(PHANDLE ProcessHandle, DWORD Pid); +extern void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid); extern void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid); extern void UnmapSectionViewHandler(PVOID BaseAddress); -extern void MapSectionViewHandler(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, PSIZE_T ViewSize); +extern void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID BaseAddress, SIZE_T ViewSize); extern void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesWritten); #endif @@ -102,7 +102,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateProcess, DebugPort, ExceptionPort); LOQ_ntstatus("process", "PphO", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, "FileName", ObjectAttributes); - if(NT_SUCCESS(ret)) { + if (NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); @@ -126,7 +126,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateProcessEx, ExceptionPort, InJob); LOQ_ntstatus("process", "PphOhh", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, "FileName", ObjectAttributes, "Flags", Flags, "SectionHandle", SectionHandle); - if(NT_SUCCESS(ret)) { + if (NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); @@ -168,7 +168,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateUserProcess, "ThreadName", ThreadObjectAttributes, "ImagePathName", &ProcessParameters->ImagePathName, "CommandLine", &ProcessParameters->CommandLine); - if(NT_SUCCESS(ret)) { + if (NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); DWORD tid = tid_from_thread_handle(*ThreadHandle); pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); @@ -197,7 +197,7 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserProcess, ExceptionPort, ProcessInformation); LOQ_ntstatus("process", "ohp", "ImagePath", ImagePath, "ObjectAttributes", ObjectAttributes, "ParentHandle", ParentProcess); - if(NT_SUCCESS(ret)) { + if (NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(ProcessInformation->ProcessHandle); DWORD tid = tid_from_thread_handle(ProcessInformation->ThreadHandle); pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); @@ -333,16 +333,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, if(is_protected_pid(pid)) { ret = STATUS_ACCESS_DENIED; - LOQ_ntstatus("process", "ppl", "ProcessHandle", NULL, "DesiredAccess", DesiredAccess, - "ProcessIdentifier", pid); + LOQ_ntstatus("process", "ppl", "ProcessHandle", NULL, "DesiredAccess", DesiredAccess, "ProcessIdentifier", pid); return ret; } + ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); + #ifdef CAPE_INJECTION - OpenProcessHandler(ProcessHandle, pid); + if (NT_SUCCESS(ret)) + OpenProcessHandler(*ProcessHandle, pid); #endif - ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, - ObjectAttributes, ClientId); LOQ_ntstatus("process", "Phi", "ProcessHandle", ProcessHandle, "DesiredAccess", DesiredAccess, "ProcessIdentifier", pid); @@ -355,10 +355,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, ) { NTSTATUS ret; DWORD pid = pid_from_process_handle(ProcessHandle); - pipe("RESUME:%d", pid); #ifdef CAPE_INJECTION ResumeProcessHandler(ProcessHandle, pid); #endif + pipe("RESUME:%d", pid); ret = Old_NtResumeProcess(ProcessHandle); LOQ_ntstatus("process", "p", "ProcessHandle", ProcessHandle); return ret; @@ -519,16 +519,18 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, if (NT_SUCCESS(ret)) { #ifdef CAPE_INJECTION - MapSectionViewHandler(SectionHandle, ProcessHandle, *BaseAddress, ViewSize); + MapSectionViewHandler(ProcessHandle, SectionHandle, *BaseAddress, *ViewSize); #endif if (pid != GetCurrentProcessId()) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); } - //else { - // prevent_module_reloading(BaseAddress); - //} + else { + prevent_module_reloading(BaseAddress); + } } + else + DoOutputDebugString("NtMapViewOfSection hook: skipping MapSectionViewHandler (ret %d).\n", ret); return ret; } @@ -611,11 +613,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (pid != GetCurrentProcessId()) { if (NT_SUCCESS(ret)) { - pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); - disable_sleep_skip(); #ifdef CAPE_INJECTION WriteMemoryHandler(ProcessHandle, BaseAddress, Buffer, *NumberOfBytesWritten); #endif + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + disable_sleep_skip(); } } @@ -643,11 +645,11 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (pid != GetCurrentProcessId()) { if (ret) { - pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); - disable_sleep_skip(); #ifdef CAPE_INJECTION WriteMemoryHandler(hProcess, lpBaseAddress, lpBuffer, *lpNumberOfBytesWritten); #endif + pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); + disable_sleep_skip(); } } diff --git a/hook_special.c b/hook_special.c index daffbe2..7eea208 100644 --- a/hook_special.c +++ b/hook_special.c @@ -162,13 +162,13 @@ HOOKDEF(BOOL, WINAPI, CreateProcessInternalW, if (g_config.file_of_interest && g_config.suspend_logging && lpApplicationName && !wcsicmp(lpApplicationName, L"c:\\windows\\splwow64.exe")) dont_monitor = TRUE; - if (!dont_monitor) - pipe("PROCESS:%d:%d,%d", (dwCreationFlags & CREATE_SUSPENDED) ? 1 : 0, lpProcessInformation->dwProcessId, - lpProcessInformation->dwThreadId); - + if (!dont_monitor) { #ifdef CAPE_INJECTION - CreateProcessHandler(lpApplicationName, lpCommandLine, lpProcessInformation); + CreateProcessHandler(lpApplicationName, lpCommandLine, lpProcessInformation); #endif + pipe("PROCESS:%d:%d,%d", (dwCreationFlags & CREATE_SUSPENDED) ? 1 : 0, lpProcessInformation->dwProcessId, + lpProcessInformation->dwThreadId); + } // if the CREATE_SUSPENDED flag was not set, then we have to resume the main thread ourself if ((dwCreationFlags & CREATE_SUSPENDED) == 0) { diff --git a/hook_thread.c b/hook_thread.c index 1a55fa3..45c7f44 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -247,8 +247,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, ) { ENSURE_HANDLE(ThreadHandle); ENSURE_STRUCT(Context, CONTEXT); + NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); - if (Context && Context->ContextFlags & CONTEXT_CONTROL) + + if (Context && Context->ContextFlags & CONTEXT_CONTROL) #ifdef _WIN64 LOQ_ntstatus("threading", "pp", "ThreadHandle", ThreadHandle, "InstructionPointer", Context->Rcx); #else @@ -271,9 +273,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); - if (pid != GetCurrentProcessId()) - pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); - ret = Old_NtSetContextThread(ThreadHandle, Context); if (Context && Context->ContextFlags & CONTEXT_CONTROL) @@ -287,6 +286,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, #ifdef CAPE_INJECTION SetThreadContextHandler(pid, Context); #endif + if (pid != GetCurrentProcessId()) + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); + return ret; } @@ -325,10 +327,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; ENSURE_ULONG(SuspendCount); - pipe("RESUME:%d,%d", pid, tid); #ifdef CAPE_INJECTION ResumeThreadHandler(pid); #endif + pipe("RESUME:%d,%d", pid, tid); ret = Old_NtResumeThread(ThreadHandle, SuspendCount); LOQ_ntstatus("threading", "pI", "ThreadHandle", ThreadHandle, "SuspendCount", SuspendCount); From 5b33fab8c4986b70a297d71e4c7cf6d332943936 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 31 Aug 2018 14:57:51 +0100 Subject: [PATCH 31/39] Improve anti-VM (VMware) countermeasures in RegEnumKeyEx hooks. --- hook_reg.c | 34 ++++++++++++++++++++++------------ misc.c | 12 ++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/hook_reg.c b/hook_reg.c index f3f45ff..d85c1dc 100644 --- a/hook_reg.c +++ b/hook_reg.c @@ -255,13 +255,14 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyW, wchar_t *parent_keys[] = { L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", - L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT" + L"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Enum\\IDE" }; wchar_t *replace_subkeys[] = { L"VBOX__", L"DELL__", - L"VBOX__", L"DELL__", - L"VBOX__", L"DELL__" + L"VMware_", L"Dell_", + L"VMWar_", L"Dell_", }; for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { @@ -303,12 +304,13 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExA, L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT" + L"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Enum\\IDE" }; char *replace_subkeys[] = { "VBOX__", "DELL__", - "VBOX__", "DELL__", - "VBOX__", "DELL__" + "VMware_", "Dell_", + "VMWar_", "Dell_", }; for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { @@ -317,6 +319,10 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExA, break; } } + + // fake some values + if (!g_config.no_stealth) + perform_ascii_registry_fakery(keypath, lpName, (ULONG)strlen(lpName)); free(keybuf); } @@ -348,13 +354,13 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExW, wchar_t *parent_keys[] = { L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\DSDT", L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\FADT", - L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT", + L"HKEY_LOCAL_MACHINE\\HARDWARE\\ACPI\\RSDT" }; wchar_t *replace_subkeys[] = { L"VBOX__", L"DELL__", - L"VBOX__", L"DELL__", - L"VBOX__", L"DELL__" + L"VMware_", L"Dell_", + L"VMWar_", L"Dell_", }; for (i = 0, j = 0; i < _countof(parent_keys); i += 1, j += 2) { @@ -363,6 +369,10 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExW, break; } } + + // fake some values + if (!g_config.no_stealth) + perform_unicode_registry_fakery(keypath, lpName, (ULONG)wcslen(lpName)); free(keybuf); } @@ -489,14 +499,14 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExA, PKEY_NAME_INFORMATION keybuf = malloc(allocsize); wchar_t *keypath = get_full_keyvalue_pathA(hKey, lpValueName, keybuf, allocsize); - LOQ_zero("registry", "psru", "Handle", hKey, "ValueName", lpValueName, - "Data", *lpType, *lpcbData, lpData, - "FullName", keypath); - // fake some values if (!g_config.no_stealth) perform_ascii_registry_fakery(keypath, lpData, *lpcbData); free(keybuf); + + LOQ_zero("registry", "psru", "Handle", hKey, "ValueName", lpValueName, + "Data", *lpType, *lpcbData, lpData, + "FullName", keypath); } else if (ret == ERROR_MORE_DATA) { LOQ_zero("registry", "psPIv", "Handle", hKey, "ValueName", lpValueName, diff --git a/misc.c b/misc.c index 2db5950..8b5312b 100644 --- a/misc.c +++ b/misc.c @@ -363,6 +363,12 @@ void perform_ascii_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength // fake the manufacturer name if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\SystemInformation\\SystemManufacturer")) replace_string_in_buf(Data, DataLength, "QEMU", "DELL"); + + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\IDE\\") || + !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\SCSI\\")) { + replace_string_in_buf(Data, DataLength, "VMware", "Lenovo"); + replace_string_in_buf(Data, DataLength, "VMWar", "Lenov"); + } } void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength) @@ -430,6 +436,12 @@ void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLeng // fake the manufacturer name if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\SystemInformation\\SystemManufacturer")) replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"QEMU", L"DELL"); + + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\IDE\\") || + !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\SCSI\\")) { + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMware", L"Lenovo"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMWar", L"Lenov"); + } } From 840909929c2db4a07657564e28c52be14a43a0da Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 31 Aug 2018 15:26:04 +0100 Subject: [PATCH 32/39] Improve anti-VM (VBOX) countermeasures in RegEnumKeyEx hooks. --- misc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc.c b/misc.c index 8b5312b..afe795c 100644 --- a/misc.c +++ b/misc.c @@ -368,6 +368,7 @@ void perform_ascii_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\SCSI\\")) { replace_string_in_buf(Data, DataLength, "VMware", "Lenovo"); replace_string_in_buf(Data, DataLength, "VMWar", "Lenov"); + replace_string_in_buf(Data, DataLength, "VBOX", "DELL"); } } @@ -441,6 +442,7 @@ void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLeng !wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Enum\\SCSI\\")) { replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMware", L"Lenovo"); replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMWar", L"Lenov"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VBOX", L"DELL"); } } From 1c45d667d381328bb374b2f796c617b4ed3d63e9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Sep 2018 18:34:04 +0100 Subject: [PATCH 33/39] Allow for capture of injections to a previous unseen handle (e.g. IcedID) --- CAPE/Injection.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 18a0855..79e9884 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -295,7 +295,7 @@ void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID Bas DoOutputErrorString("MapSectionViewHandler: Error obtaining target process name"); _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); } - else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) DoOutputErrorString("MapSectionViewHandler: Error translating target process path"); CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, ViewSize); @@ -337,15 +337,51 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer struct InjectionInfo *CurrentInjectionInfo; PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader; + char DevicePath[MAX_PATH]; + unsigned int PathLength; + DWORD BufferSize = MAX_PATH; Pid = pid_from_process_handle(ProcessHandle); CurrentInjectionInfo = GetInjectionInfo(Pid); - if (!CurrentInjectionInfo || CurrentInjectionInfo->ProcessId != Pid) + if (NumberOfBytesWritten == 0) return; - if (NumberOfBytesWritten == 0) + if (!CurrentInjectionInfo && Pid != GetCurrentProcessId()) + { + CurrentInjectionInfo = CreateInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("WriteMemoryHandler: Cannot create new injection info - error.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = ProcessHandle; + CurrentInjectionInfo->ProcessId = Pid; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(ProcessHandle); + + if (CurrentInjectionInfo->ImageBase) + DoOutputDebugString("WriteMemoryHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, ProcessHandle, CurrentInjectionInfo->ImageBase); + + PathLength = GetProcessImageFileName(ProcessHandle, DevicePath, BufferSize); + + if (!PathLength) + { + DoOutputErrorString("WriteMemoryHandler: Error obtaining target process name"); + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("WriteMemoryHandler: Error translating target process path"); + } + } + + if (CurrentInjectionInfo->ProcessId != Pid) return; CurrentInjectionInfo->WriteDetected = TRUE; From 9d3d5f58543b6c54ad5d554d489175510d34c6c4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Sep 2018 10:59:53 +0100 Subject: [PATCH 34/39] Prevent PE ImageBase being overwritten when dumping injected payloads. --- CAPE/Scylla/PeParser.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index 4b4c564..b6b0ef3 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -1327,13 +1327,13 @@ void PeParser::fixPeHeader() pNTHeader32->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader32->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader32->OptionalHeader.FileAlignment); - if (moduleBaseAddress && moduleBaseAddress != pNTHeader32->OptionalHeader.ImageBase) - { - pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; -#ifdef DEBUG_COMMENTS - DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); -#endif - } +// if (moduleBaseAddress && moduleBaseAddress != pNTHeader32->OptionalHeader.ImageBase) +// { +// pNTHeader32->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; +//#ifdef DEBUG_COMMENTS +// DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); +//#endif +// } } else { @@ -1355,13 +1355,13 @@ void PeParser::fixPeHeader() pNTHeader64->OptionalHeader.SizeOfHeaders = alignValue(dwSize + pNTHeader64->FileHeader.SizeOfOptionalHeader + (getNumberOfSections() * sizeof(IMAGE_SECTION_HEADER)), pNTHeader64->OptionalHeader.FileAlignment); - if (moduleBaseAddress && moduleBaseAddress != pNTHeader64->OptionalHeader.ImageBase) - { - pNTHeader64->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; -#ifdef DEBUG_COMMENTS - DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); -#endif - } +// if (moduleBaseAddress && moduleBaseAddress != pNTHeader64->OptionalHeader.ImageBase) +// { +// pNTHeader64->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; +//#ifdef DEBUG_COMMENTS +// DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); +//#endif +// } } removeIatDirectory(); From 435ea8df44e13bff6a0fc765bbda21ad427ecc4a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Sep 2018 18:23:53 +0100 Subject: [PATCH 35/39] Updates and bugfixes from main branch --- CAPE/CAPE.c | 29 +++++-- CAPE/CAPE.h | 1 - CAPE/Debugger.c | 159 +++++++-------------------------------- CAPE/Scylla/PeParser.cpp | 6 +- config.c | 16 ++++ config.h | 5 +- cuckoomon.c | 53 +++++++++---- hook_process.c | 58 ++++++++++---- hook_reg.c | 16 +++- hook_special.c | 1 + hook_thread.c | 133 ++++++++++++++++++-------------- hooking.c | 84 ++++++++++++++++++++- hooking_32.c | 5 -- hooking_64.c | 5 -- hooks.h | 10 +++ misc.c | 17 ++++- misc.h | 1 + ntapi.h | 18 +++-- unhook.c | 2 +- 19 files changed, 366 insertions(+), 253 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index a98d0e6..30be9a2 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -108,6 +108,7 @@ extern unsigned int address_is_in_stack(PVOID Address); extern hook_info_t *hook_info(); extern ULONG_PTR base_of_dll_of_interest; extern wchar_t *our_process_path; +extern wchar_t *our_commandline; extern ULONG_PTR g_our_dll_base; extern DWORD g_our_dll_size; @@ -124,8 +125,12 @@ extern BOOL CountDepth(LPVOID* ReturnAddress, LPVOID Address); extern SIZE_T GetPESize(PVOID Buffer); extern LPVOID GetReturnAddress(hook_info_t *hookinfo); extern PVOID CallingModule; +#ifdef CAPE_TRACE +extern BOOL SetInitialBreakpoints(PVOID ImageBase); +extern BOOL BreakpointsSet; +#endif -BOOL ProcessDumped, FilesDumped; +BOOL ProcessDumped, FilesDumped, ModuleDumped; static unsigned int DumpCount; static __inline ULONG_PTR get_stack_top(void) @@ -1469,6 +1474,10 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) *(WORD*)pDosHeader = IMAGE_DOS_SIGNATURE; *(DWORD*)((PUCHAR)pDosHeader + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; +#ifdef CAPE_INJECTION + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)pDosHeader); +#endif + if (DumpImageInCurrentProcess((LPVOID)pDosHeader)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", pDosHeader); @@ -1715,13 +1724,17 @@ int DumpModuleInCurrentProcess(LPVOID ModuleBase) ModuleBase = PEImage; } - DoOutputDebugString("DumpModuleInCurrentProcess: About to call ScyllaDumpProcess.\n"); +#ifdef CAPE_INJECTION + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)ModuleBase); +#else + SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); +#endif + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) { DumpCount++; return 1; } - DoOutputDebugString("DumpModuleInCurrentProcess: returned from ScyllaDumpProcess.\n"); return 0; } @@ -1857,6 +1870,7 @@ int RoutineProcessDump() void init_CAPE() { + char* CommandLine; // Initialise CAPE global variables // #ifndef STANDALONE @@ -1864,7 +1878,10 @@ void init_CAPE() CapeMetaData->Pid = GetCurrentProcessId(); CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, (int)wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); - + + CommandLine = (char*)malloc(MAX_PATH); + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_commandline, (int)wcslen(our_commandline)+1, CommandLine, MAX_PATH, NULL, NULL); + // Specific to Injection package: CapeMetaData->DumpType = INJECTION_SHELLCODE; // default value for now, may be changed to INJECTION_PE CapeMetaData->Address = NULL; @@ -1893,6 +1910,8 @@ void init_CAPE() #else DoOutputDebugString("CAPE initialised: 32-bit Injection package loaded in process %d at 0x%x, image base 0x%x, stack from 0x%x-0x%x\n", GetCurrentProcessId(), g_our_dll_base, GetModuleHandle(NULL), get_stack_bottom(), get_stack_top()); #endif - + + DoOutputDebugString("Commandline: %s.\n", CommandLine); + return; } diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index dc6fc44..4449577 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -38,7 +38,6 @@ int ScanPageForNonZero(LPVOID Address); int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); -int DumpModuleInCurrentProcess(LPVOID ModuleBase); int DumpImageInCurrentProcess(LPVOID ImageBase); void DumpSectionViewsForPid(DWORD Pid); diff --git a/CAPE/Debugger.c b/CAPE/Debugger.c index f12e8b7..a8e3d85 100644 --- a/CAPE/Debugger.c +++ b/CAPE/Debugger.c @@ -661,7 +661,7 @@ BOOL ActivateSurroundingGuardPages(PTRACKEDREGION TrackedRegion) PagePointer += SystemInfo.dwPageSize ) { - // We skip the initial page if a switch to breakpoints has occured + // We skip the initial page if a switch to breakpoints has occurred if (PagePointer == (DWORD_PTR)TrackedRegion->BaseAddress && TrackedRegion->BreakpointsSet) PagePointer += SystemInfo.dwPageSize; @@ -821,8 +821,6 @@ PTHREADBREAKPOINTS CreateThreadBreakpoints(DWORD ThreadId) BOOL InitNewThreadBreakpoints(DWORD ThreadId) //************************************************************************************** { - //DoOutputDebugString("InitNewThreadBreakpoints: Initialising breakpoints for thread %d.\n", ThreadId); - //return TRUE; PTHREADBREAKPOINTS NewThreadBreakpoints; if (MainThreadBreakpointList == NULL) @@ -919,7 +917,7 @@ BOOL ContextGetNextAvailableBreakpoint(PCONTEXT Context, unsigned int* Register) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("ContextGetNextAvailableBreakpoint: Error - cannot create new thread breakpoints.\n"); + DoOutputDebugString("ContextGetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } @@ -951,7 +949,7 @@ void DebugOutputThreadBreakpoints() if (pBreakpointInfo == NULL) { - DoOutputDebugString("DebugOutputThreadBreakpoints: Error - can't get BreakpointInfo.\n"); + DoOutputDebugString("DebugOutputThreadBreakpoints: Can't get BreakpointInfo - FATAL.\n"); } DoOutputDebugString("Callback = 0x%x, Address = 0x%x, Size = 0x%x, Register = %i, ThreadHandle = 0x%x, Type = 0x%x\n", @@ -996,7 +994,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Error - can't get thread breakpoints.\n"); + DoOutputDebugString("CAPEExceptionFilter: Can't get thread breakpoints - FATAL.\n"); return EXCEPTION_CONTINUE_SEARCH; } @@ -1048,7 +1046,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (pBreakpointInfo == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Error - can't get BreakpointInfo.\n"); + DoOutputDebugString("CAPEExceptionFilter: Can't get BreakpointInfo - FATAL.\n"); return EXCEPTION_CONTINUE_EXECUTION; } @@ -1129,7 +1127,7 @@ LONG WINAPI CAPEExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) if (pBreakpointInfo->Callback == NULL) { - DoOutputDebugString("CAPEExceptionFilter: Error - can't get callback.\n"); + DoOutputDebugString("CAPEExceptionFilter: Can't get callback - FATAL.\n"); return EXCEPTION_CONTINUE_EXECUTION; } @@ -1247,7 +1245,7 @@ BOOL ContextSetDebugRegister PDWORD_PTR Dr1 = &(Context->Dr1); PDWORD_PTR Dr2 = &(Context->Dr2); PDWORD_PTR Dr3 = &(Context->Dr3); - PDR7 Dr7 = (PDR7)&(Context->Dr7); + PDR7 Dr7 = (PDR7)&(Context->Dr7); if ((unsigned int)Type > 3) { @@ -1802,10 +1800,10 @@ BOOL SetSingleStepMode(PCONTEXT Context, PVOID Handler) { if (Context == NULL) return FALSE; - + // set the trap flag Context->EFlags |= FL_TF; - + SingleStepHandler = (SINGLE_STEP_HANDLER)Handler; return TRUE; @@ -1841,7 +1839,7 @@ BOOL StepOverExecutionBreakpoint(PCONTEXT Context, PBREAKPOINTINFO pBreakpointIn return FALSE; Dr7 = (PDR7)&(Context->Dr7); - + switch(pBreakpointInfo->Register) { case 0: @@ -2084,7 +2082,7 @@ int CheckDebugRegister(HANDLE hThread, int Register) if (!GetThreadContext(hThread, &Context)) { - DoOutputDebugString("CheckDebugRegister: Error - GetThreadContext failed.\n"); + DoOutputDebugString("CheckDebugRegister: GetThreadContext failed - FATAL\n"); return FALSE; } @@ -2174,8 +2172,6 @@ BOOL ContextSetThreadBreakpoint } else { - DoOutputDebugString("ContextSetThreadBreakpoint: Call to ContextSetDebugRegister succeeded.\n"); - CurrentThreadBreakpoint = GetThreadBreakpoints(GetCurrentThreadId()); if (CurrentThreadBreakpoint == NULL) @@ -2208,12 +2204,6 @@ BOOL ContextSetThreadBreakpoint } #endif - //if (!ContextSetBreakpoint(CurrentThreadBreakpoint)) - //{ - // DoOutputErrorString("ContextSetThreadBreakpoint: ContextSetBreakpoint failed"); - // return FALSE; - //} - return TRUE; } @@ -2415,56 +2405,6 @@ DWORD WINAPI ClearBreakpointThread(LPVOID lpParam) return TRUE; } -//************************************************************************************** -BOOL ClearBreakpointWithoutThread(DWORD ThreadId, int Register) -//************************************************************************************** -{ - PBREAKPOINTINFO pBreakpointInfo; - PTHREADBREAKPOINTS CurrentThreadBreakpoint; - - if (Register > 3 || Register < 0) - { - DoOutputDebugString("ClearBreakpointWithoutThread: Error - register value %d, can only have value 0-3.\n", Register); - return FALSE; - } - - CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); - - if (CurrentThreadBreakpoint == NULL) - { - DoOutputDebugString("ClearBreakpointWithoutThread: Creating new thread breakpoints for thread %d.\n", ThreadId); - CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); - } - - if (CurrentThreadBreakpoint == NULL) - { - DoOutputDebugString("ClearBreakpointWithoutThread: Error - cannot create new thread breakpoints.\n"); - return FALSE; - } - - pBreakpointInfo = &CurrentThreadBreakpoint->BreakpointInfo[Register]; - - if (CurrentThreadBreakpoint->ThreadHandle == NULL) - { - DoOutputDebugString("ClearBreakpointWithoutThread: There is no thread handle in the thread breakpoint - Error.\n"); - return FALSE; - } - - if (!ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type)) - { - DoOutputDebugString("ClearBreakpointWithoutThread: Call to ClearDebugRegister failed.\n"); - return FALSE; - } - - //pBreakpointInfo->Register = 0; - pBreakpointInfo->Size = 0; - pBreakpointInfo->Address = 0; - pBreakpointInfo->Type = 0; - pBreakpointInfo->Callback = NULL; - - return TRUE; -} - //************************************************************************************** BOOL SetBreakpointWithoutThread //************************************************************************************** @@ -2497,7 +2437,7 @@ BOOL SetBreakpointWithoutThread if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetBreakpointWithoutThread: Error - cannot create new thread breakpoints.\n"); + DoOutputDebugString("SetBreakpointWithoutThread: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } @@ -2735,24 +2675,26 @@ BOOL SetThreadBreakpoints(PTHREADBREAKPOINTS ThreadBreakpoints) BOOL ClearBreakpoint(DWORD ThreadId, int Register) //************************************************************************************** { - return ClearBreakpointWithoutThread(ThreadId, Register); -/* PBREAKPOINTINFO pBreakpointInfo; PTHREADBREAKPOINTS CurrentThreadBreakpoint; - HANDLE hClearBreakpointThread; - BOOL RetVal; - + if (Register > 3 || Register < 0) { DoOutputDebugString("ClearBreakpoint: Error - register value %d, can only have value 0-3.\n", Register); return FALSE; } - - CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); + CurrentThreadBreakpoint = GetThreadBreakpoints(ThreadId); + if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("Cannot find thread breakpoints - failed to clear.\n"); + DoOutputDebugString("ClearBreakpoint: Creating new thread breakpoints for thread %d.\n", ThreadId); + CurrentThreadBreakpoint = CreateThreadBreakpoints(ThreadId); + } + + if (CurrentThreadBreakpoint == NULL) + { + DoOutputDebugString("ClearBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } @@ -2763,55 +2705,13 @@ BOOL ClearBreakpoint(DWORD ThreadId, int Register) DoOutputDebugString("ClearBreakpoint: There is no thread handle in the thread breakpoint - Error.\n"); return FALSE; } - - pBreakpointInfo->ThreadHandle = CurrentThreadBreakpoint->ThreadHandle; - - __try - { - hClearBreakpointThread = CreateThread(NULL, 0, ClearBreakpointThread, pBreakpointInfo, 0, &ThreadId); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - DoOutputErrorString("ClearBreakpoint: Unable to create ClearBreakpointThread thread"); - } - - if (hClearBreakpointThread) - { - DoOutputDebugString("ClearBreakpoint: thread created, handle 0x%x.\n", hClearBreakpointThread); - - // If this hasn't happened in under a second, we bail - // and clear without creating a thread - RetVal = WaitForSingleObject(hClearBreakpointThread, 1000); - DoOutputDebugString("ClearBreakpoint: Aboot tae close handle.\n"); - //CloseHandle(hClearBreakpointThread); - - if (RetVal != WAIT_OBJECT_0) - { - DoOutputDebugString("ClearBreakpoint: thread timeout, falling back to clearing without thread.\n"); - - return ClearBreakpointWithoutThread(ThreadId, Register); - } - - DoOutputDebugString("ClearBreakpoint: Cleared breakpoint %d.\n", pBreakpointInfo->Register); + if (!ClearDebugRegister(pBreakpointInfo->ThreadHandle, pBreakpointInfo->Register, pBreakpointInfo->Size, pBreakpointInfo->Address, pBreakpointInfo->Type)) + { + DoOutputDebugString("ClearBreakpoint: Call to ClearDebugRegister failed.\n"); + return FALSE; + } - return TRUE; - } - else - { - __try - { - RetVal = ClearBreakpointWithoutThread(ThreadId, Register); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - DoOutputErrorString("ClearBreakpoint: Error calling ClearBreakpointWithoutThread"); - return FALSE; - } - - return RetVal; - } - //pBreakpointInfo->Register = 0; pBreakpointInfo->Size = 0; pBreakpointInfo->Address = 0; @@ -2819,7 +2719,6 @@ BOOL ClearBreakpoint(DWORD ThreadId, int Register) pBreakpointInfo->Callback = NULL; return TRUE; -*/ } //************************************************************************************** @@ -2844,7 +2743,7 @@ BOOL SetNextAvailableBreakpoint if (CurrentThreadBreakpoint == NULL) { - DoOutputDebugString("SetNextAvailableBreakpoint: Error - cannot create new thread breakpoints.\n"); + DoOutputDebugString("SetNextAvailableBreakpoint: Cannot create new thread breakpoints - FATAL.\n"); return FALSE; } @@ -3114,7 +3013,7 @@ BOOL DebugNewProcess(unsigned int ProcessId, unsigned int ThreadId, DWORD Creati Context.ContextFlags = CONTEXT_ALL; if (!GetThreadContext(hThread, &Context)) { - DoOutputDebugString("DebugNewProcess: Error - GetThreadContext failed.\n"); + DoOutputDebugString("DebugNewProcess: GetThreadContext failed - FATAL\n"); return FALSE; } diff --git a/CAPE/Scylla/PeParser.cpp b/CAPE/Scylla/PeParser.cpp index b6b0ef3..8a310ec 100644 --- a/CAPE/Scylla/PeParser.cpp +++ b/CAPE/Scylla/PeParser.cpp @@ -1333,7 +1333,7 @@ void PeParser::fixPeHeader() //#ifdef DEBUG_COMMENTS // DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader32->OptionalHeader.ImageBase); //#endif -// } +// } } else { @@ -1357,11 +1357,11 @@ void PeParser::fixPeHeader() // if (moduleBaseAddress && moduleBaseAddress != pNTHeader64->OptionalHeader.ImageBase) // { -// pNTHeader64->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; +// pNTHeader64->OptionalHeader.ImageBase = (DWORD)moduleBaseAddress; //#ifdef DEBUG_COMMENTS // DoOutputDebugString("fixPeHeader: ImageBase set to 0x%x.\n", pNTHeader64->OptionalHeader.ImageBase); //#endif -// } +// } } removeIatDirectory(); diff --git a/config.c b/config.c index e82e07c..58354d3 100644 --- a/config.c +++ b/config.c @@ -234,6 +234,22 @@ int read_config(void) p = p2 + 1; } } + else if (!strcmp(key, "dump-on-api")) { + unsigned int x = 0; + char *p2; + p = value; + while (p && x < EXCLUSION_MAX) { + p2 = strchr(p, ':'); + if (p2) { + *p2 = '\0'; + } + g_config.dump_on_apinames[x++] = strdup(p); + DoOutputDebugString("Added '%s' to dump-on-API list.\n", p); + if (p2 == NULL) + break; + p = p2 + 1; + } + } else if (!strcmp(key, "bp0")) { bp0 = (PVOID)strtoul(value, NULL, 10); DoOutputDebugString("bp0 set to 0x%x", bp0); diff --git a/config.h b/config.h index d60503f..e4e6637 100644 --- a/config.h +++ b/config.h @@ -105,10 +105,11 @@ struct _g_config { char *excluded_apinames[EXCLUSION_MAX]; wchar_t *excluded_dllnames[EXCLUSION_MAX]; char *base_on_apiname[EXCLUSION_MAX]; - + char *dump_on_apinames[EXCLUSION_MAX]; + // should we dump each process on exit/analysis timeout? int procdump; - + // should we attempt import reconstruction on each process dump? (slow) int import_reconstruction; }; diff --git a/cuckoomon.c b/cuckoomon.c index 1b053af..a4562b1 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -31,6 +31,11 @@ along with this program. If not, see . #include "unhook.h" #include "bson.h" +struct _g_config g_config; +wchar_t *our_process_path; +wchar_t *our_commandline; +BOOL is_64bit_os; + volatile int dummy_val; extern void init_CAPE(); @@ -308,6 +313,8 @@ static hook_t g_hooks[] = { HOOK(kernel32, CreateToolhelp32Snapshot), HOOK(kernel32, Process32FirstW), HOOK(kernel32, Process32NextW), + HOOK(kernel32, Module32FirstW), + HOOK(kernel32, Module32NextW), HOOK(ntdll, NtCreateProcess), HOOK(ntdll, NtCreateProcessEx), HOOK(ntdll, NtCreateUserProcess), @@ -674,7 +681,7 @@ VOID CALLBACK New_DllLoadNotification( _In_ const PLDR_DLL_NOTIFICATION_DATA NotificationData, _In_opt_ PVOID Context) { - PWCHAR dllname; + PWCHAR dllname, rundll_path; COPY_UNICODE_STRING(library, NotificationData->Loaded.FullDllName); if (g_config.debug) { @@ -682,13 +689,29 @@ VOID CALLBACK New_DllLoadNotification( /* Just for debug purposes, gives a stripped fake function name */ LOQ_void("system", "sup", "NotificationReason", NotificationReason == 1 ? "load" : "unload", "DllName", library.Buffer, "DllBase", NotificationReason == 1 ? NotificationData->Loaded.DllBase : NotificationData->Unloaded.DllBase); } - - if (NotificationReason == 1) { + + // for rundll32 only + rundll_path = wcschr(our_commandline, ' '); + if (rundll_path) + if (*rundll_path == L' ') rundll_path++; + + if (NotificationReason == 1) { if (g_config.file_of_interest && !wcsicmp(library.Buffer, g_config.file_of_interest)) { if (!base_of_dll_of_interest) set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); DoOutputDebugString("Target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); } + else if (((!wcsnicmp(our_commandline, L"c:\\windows\\system32\\rundll32.exe", 32) || + !wcsnicmp(our_commandline, L"c:\\windows\\syswow64\\rundll32.exe", 32) || + !wcsnicmp(our_commandline, L"c:\\windows\\sysnative\\rundll32.exe", 33))) && + !wcsnicmp(rundll_path, library.Buffer, wcslen(library.Buffer))) { + set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); + if (g_config.file_of_interest == NULL) { + g_config.file_of_interest = calloc(1, (wcslen(library.Buffer) + 1) * sizeof(wchar_t)); + wcsncpy(g_config.file_of_interest, library.Buffer, wcslen(library.Buffer)); + } + DoOutputDebugString("rundll32 target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); + } else { // unoptimized, but easy add_all_dlls_to_dll_ranges(); @@ -727,8 +750,7 @@ void set_hooks() // the hooks contain executable code as well, so they have to be RWX DWORD old_protect; - VirtualProtect(g_hooks, sizeof(g_hooks), PAGE_EXECUTE_READWRITE, - &old_protect); + VirtualProtect(g_hooks, sizeof(g_hooks), PAGE_EXECUTE_READWRITE, &old_protect); memset(&threadInfo, 0, sizeof(threadInfo)); threadInfo.dwSize = sizeof(threadInfo); @@ -895,10 +917,6 @@ static void notify_successful_load(void) pipe("LOADED:%d", GetCurrentProcessId()); } -struct _g_config g_config; -wchar_t *our_process_path; -BOOL is_64bit_os; - void get_our_process_path(void) { wchar_t *tmp = calloc(1, 32768 * sizeof(wchar_t)); @@ -913,6 +931,17 @@ void get_our_process_path(void) free(tmp); } +void get_our_commandline(void) +{ + wchar_t *tmp = calloc(1, 32768 * sizeof(wchar_t)); + + PEB *peb = get_peb(); + + ensure_absolute_unicode_path(tmp, peb->ProcessParameters->CommandLine.Buffer); + + our_commandline = tmp; +} + void set_os_bitness(void) { LPFN_ISWOW64PROCESS pIsWow64Process; @@ -954,8 +983,6 @@ void init_private_heap(void) BOOLEAN g_dll_main_complete; -DWORD g_tls_hook_index; - extern void ignored_threads_init(void); extern CRITICAL_SECTION readfile_critsec; @@ -1015,9 +1042,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) get_our_process_path(); - g_tls_hook_index = TlsAlloc(); - if (g_tls_hook_index == TLS_OUT_OF_INDEXES) - goto abort; + get_our_commandline(); // adds our own DLL range as well, since the hiding is done later add_all_dlls_to_dll_ranges(); diff --git a/hook_process.c b/hook_process.c index aae6680..861f53d 100644 --- a/hook_process.c +++ b/hook_process.c @@ -87,6 +87,34 @@ HOOKDEF(BOOL, WINAPI, Process32FirstW, return ret; } +HOOKDEF(BOOL, WINAPI, Module32NextW, + __in HANDLE hSnapshot, + __out LPMODULEENTRY32W lpme + ) { + BOOL ret = Old_Module32NextW(hSnapshot, lpme); + + if (ret) + LOQ_bool("process", "uii", "ModuleName", lpme->szModule, "ModuleID", lpme->th32ModuleID, "ProcessId", lpme->th32ProcessID); + else + LOQ_bool("process", ""); + + return ret; +} + +HOOKDEF(BOOL, WINAPI, Module32FirstW, + __in HANDLE hSnapshot, + __out LPMODULEENTRY32W lpme + ) { + BOOL ret = Old_Module32FirstW(hSnapshot, lpme); + + if (ret) + LOQ_bool("process", "uii", "ModuleName", lpme->szModule, "ModuleID", lpme->th32ModuleID, "ProcessId", lpme->th32ProcessID); + else + LOQ_bool("process", ""); + + return ret; +} + HOOKDEF(NTSTATUS, WINAPI, NtCreateProcess, __out PHANDLE ProcessHandle, __in ACCESS_MASK DesiredAccess, @@ -102,7 +130,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateProcess, DebugPort, ExceptionPort); LOQ_ntstatus("process", "PphO", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, "FileName", ObjectAttributes); - if (NT_SUCCESS(ret)) { + if(NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); @@ -126,7 +154,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateProcessEx, ExceptionPort, InJob); LOQ_ntstatus("process", "PphOhh", "ProcessHandle", ProcessHandle, "ParentHandle", ParentProcess, "DesiredAccess", DesiredAccess, "FileName", ObjectAttributes, "Flags", Flags, "SectionHandle", SectionHandle); - if (NT_SUCCESS(ret)) { + if(NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); @@ -168,7 +196,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateUserProcess, "ThreadName", ThreadObjectAttributes, "ImagePathName", &ProcessParameters->ImagePathName, "CommandLine", &ProcessParameters->CommandLine); - if (NT_SUCCESS(ret)) { + if(NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(*ProcessHandle); DWORD tid = tid_from_thread_handle(*ThreadHandle); pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); @@ -197,7 +225,7 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserProcess, ExceptionPort, ProcessInformation); LOQ_ntstatus("process", "ohp", "ImagePath", ImagePath, "ObjectAttributes", ObjectAttributes, "ParentHandle", ParentProcess); - if (NT_SUCCESS(ret)) { + if(NT_SUCCESS(ret)) { DWORD pid = pid_from_process_handle(ProcessInformation->ProcessHandle); DWORD tid = tid_from_thread_handle(ProcessInformation->ThreadHandle); pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); @@ -319,12 +347,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, // although the documentation on msdn is a bit vague, this seems correct // for both XP and Vista (the ClientId->UniqueProcess part, that is) - DWORD pid = 0; + int pid = 0; NTSTATUS ret; if(ClientId != NULL) { __try { - pid = (DWORD)(ULONG_PTR)ClientId->UniqueProcess; + pid = (int)(ULONG_PTR)ClientId->UniqueProcess; } __except (EXCEPTION_EXECUTE_HANDLER) { ; @@ -333,12 +361,13 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, if(is_protected_pid(pid)) { ret = STATUS_ACCESS_DENIED; - LOQ_ntstatus("process", "ppl", "ProcessHandle", NULL, "DesiredAccess", DesiredAccess, "ProcessIdentifier", pid); + LOQ_ntstatus("process", "ppl", "ProcessHandle", NULL, "DesiredAccess", DesiredAccess, + "ProcessIdentifier", pid); return ret; } ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); - + #ifdef CAPE_INJECTION if (NT_SUCCESS(ret)) OpenProcessHandler(*ProcessHandle, pid); @@ -364,7 +393,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeProcess, return ret; } - int process_shutting_down; HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, @@ -489,7 +517,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtUnmapViewOfSection, #endif ret = Old_NtUnmapViewOfSection(ProcessHandle, BaseAddress); - + LOQ_ntstatus("process", "ppp", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, "RegionSize", map_size); @@ -508,7 +536,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, __in ULONG AllocationType, __in ULONG Win32Protect ) { - NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, + PVOID InputAddress = *BaseAddress; + LARGE_INTEGER InputOffset = *SectionOffset; + SIZE_T InputSize = *ViewSize; + + NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); DWORD pid = pid_from_process_handle(ProcessHandle); @@ -525,12 +557,10 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); } - else { + else if (ret == STATUS_IMAGE_NOT_AT_BASE && Win32Protect == PAGE_READONLY) { prevent_module_reloading(BaseAddress); } } - else - DoOutputDebugString("NtMapViewOfSection hook: skipping MapSectionViewHandler (ret %d).\n", ret); return ret; } diff --git a/hook_reg.c b/hook_reg.c index d85c1dc..767fc58 100644 --- a/hook_reg.c +++ b/hook_reg.c @@ -64,6 +64,10 @@ HOOKDEF(LONG, WINAPI, RegOpenKeyExA, break; } } + + // fake some values + if (lpSubKey && !g_config.no_stealth) + perform_ascii_registry_fakery(keypath, (LPVOID)lpSubKey, (ULONG)strlen(lpSubKey)); free(keybuf); } @@ -113,6 +117,10 @@ HOOKDEF(LONG, WINAPI, RegOpenKeyExW, break; } } + + // fake some values + if (lpSubKey && !g_config.no_stealth) + perform_unicode_registry_fakery(keypath, lpSubKey, (ULONG)wcslen(lpSubKey)); free(keybuf); } @@ -321,7 +329,7 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExA, } // fake some values - if (!g_config.no_stealth) + if (lpName && !g_config.no_stealth) perform_ascii_registry_fakery(keypath, lpName, (ULONG)strlen(lpName)); free(keybuf); } @@ -371,7 +379,7 @@ HOOKDEF(LONG, WINAPI, RegEnumKeyExW, } // fake some values - if (!g_config.no_stealth) + if (lpName && !g_config.no_stealth) perform_unicode_registry_fakery(keypath, lpName, (ULONG)wcslen(lpName)); free(keybuf); } @@ -500,7 +508,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExA, wchar_t *keypath = get_full_keyvalue_pathA(hKey, lpValueName, keybuf, allocsize); // fake some values - if (!g_config.no_stealth) + if (lpData && !g_config.no_stealth) perform_ascii_registry_fakery(keypath, lpData, *lpcbData); free(keybuf); @@ -543,7 +551,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExW, "FullName", keypath); // fake some values - if (!g_config.no_stealth) + if (lpData && !g_config.no_stealth) perform_unicode_registry_fakery(keypath, lpData, *lpcbData); free(keybuf); } diff --git a/hook_special.c b/hook_special.c index 7eea208..ab22f7f 100644 --- a/hook_special.c +++ b/hook_special.c @@ -40,6 +40,7 @@ HOOKDEF_NOTAIL(WINAPI, LdrLoadDll, __in PUNICODE_STRING ModuleFileName, __out PHANDLE ModuleHandle ) { + // // In the event that loading this dll results in loading another dll as // well, then the unicode string (which is located in the TEB) will be diff --git a/hook_thread.c b/hook_thread.c index 45c7f44..8952eb9 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -55,6 +55,7 @@ BOOLEAN is_ignored_thread(DWORD tid) if (ret) return TRUE; + return FALSE; } @@ -84,18 +85,19 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThread, __in_opt PIO_STATUS_BLOCK ApcStatusBlock, __in_opt ULONG ApcReserved ) { - DWORD PID = pid_from_thread_handle(ThreadHandle); - DWORD TID = tid_from_thread_handle(ThreadHandle); + DWORD pid = pid_from_thread_handle(ThreadHandle); + DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; - pipe("PROCESS:%d:%d,%d", is_suspended(PID, TID), PID, TID); + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); ret = Old_NtQueueApcThread(ThreadHandle, ApcRoutine, ApcRoutineContext, ApcStatusBlock, ApcReserved); - LOQ_ntstatus("threading", "iip", "ProcessId", PID, "ThreadId", TID, "ThreadHandle", ThreadHandle); + LOQ_ntstatus("threading", "iip", "ProcessId", pid, "ThreadId", tid, "ThreadHandle", ThreadHandle); if (NT_SUCCESS(ret)) disable_sleep_skip(); + return ret; } @@ -107,18 +109,19 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueueApcThreadEx, __in_opt PIO_STATUS_BLOCK ApcStatusBlock, __in_opt PVOID ApcReserved ) { - DWORD PID = pid_from_thread_handle(ThreadHandle); - DWORD TID = tid_from_thread_handle(ThreadHandle); + DWORD pid = pid_from_thread_handle(ThreadHandle); + DWORD tid = tid_from_thread_handle(ThreadHandle); NTSTATUS ret; - pipe("PROCESS:%d:%d,%d", is_suspended(PID, TID), PID, TID); + pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); ret = Old_NtQueueApcThreadEx(ThreadHandle, UserApcReserveHandle, ApcRoutine, ApcRoutineContext, ApcStatusBlock, ApcReserved); - LOQ_ntstatus("threading", "iip", "ProcessId", PID, "ThreadId", TID, "ThreadHandle", ThreadHandle); + LOQ_ntstatus("threading", "iip", "ProcessId", pid, "ThreadId", tid, "ThreadHandle", ThreadHandle); if (NT_SUCCESS(ret)) disable_sleep_skip(); + return ret; } @@ -155,13 +158,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateThread, ResumeThread(*ThreadHandle); set_lasterrors(&lasterror); } - } - - LOQ_ntstatus("threading", "PpOi", "ThreadHandle", ThreadHandle, "ProcessHandle", ProcessHandle, - "ObjectAttributes", ObjectAttributes, "CreateSuspended", CreateSuspended); + + LOQ_ntstatus("threading", "PpOii", "ThreadHandle", ThreadHandle, "ProcessHandle", ProcessHandle, + "ObjectAttributes", ObjectAttributes, "CreateSuspended", CreateSuspended, "ThreadId", tid); - if (NT_SUCCESS(ret)) disable_sleep_skip(); + } + else + LOQ_ntstatus("threading", "PpOi", "ThreadHandle", ThreadHandle, "ProcessHandle", ProcessHandle, + "ObjectAttributes", ObjectAttributes, "CreateSuspended", CreateSuspended); + return ret; } @@ -204,14 +210,17 @@ HOOKDEF(NTSTATUS, WINAPI, NtCreateThreadEx, ResumeThread(*hThread); set_lasterrors(&lasterror); } + + LOQ_ntstatus("threading", "Ppphi", "ThreadHandle", hThread, "ProcessHandle", ProcessHandle, + "StartAddress", lpStartAddress, "CreateFlags", CreateFlags, "ThreadId", tid); + + disable_sleep_skip(); } - LOQ_ntstatus("threading", "Ppph", "ThreadHandle", hThread, "ProcessHandle", ProcessHandle, - "StartAddress", lpStartAddress, "CreateFlags", CreateFlags); + else + LOQ_ntstatus("threading", "Ppph", "ThreadHandle", hThread, "ProcessHandle", ProcessHandle, + "StartAddress", lpStartAddress, "CreateFlags", CreateFlags); - if (NT_SUCCESS(ret)) - disable_sleep_skip(); - - return ret; + return ret; } HOOKDEF(NTSTATUS, WINAPI, NtOpenThread, @@ -222,17 +231,17 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenThread, ) { NTSTATUS ret = Old_NtOpenThread(ThreadHandle, DesiredAccess, ObjectAttributes, ClientId); - DWORD PID = 0; - DWORD TID = 0; + DWORD pid = 0; + DWORD tid = 0; if (NT_SUCCESS(ret) && ThreadHandle) { - PID = pid_from_thread_handle(*ThreadHandle); - TID = tid_from_thread_handle(*ThreadHandle); + pid = pid_from_thread_handle(*ThreadHandle); + tid = tid_from_thread_handle(*ThreadHandle); } if (ClientId) { LOQ_ntstatus("threading", "Phii", "ThreadHandle", ThreadHandle, "DesiredAccess", DesiredAccess, - "ProcessId", PID, "ThreadId", TID); + "ProcessId", pid, "ThreadId", tid); } else { LOQ_ntstatus("threading", "PhO", "ThreadHandle", ThreadHandle, "DesiredAccess", DesiredAccess, "ObjectAttributes", ObjectAttributes); @@ -247,7 +256,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, ) { ENSURE_HANDLE(ThreadHandle); ENSURE_STRUCT(Context, CONTEXT); - + DWORD tid = tid_from_thread_handle(ThreadHandle); + NTSTATUS ret = Old_NtGetContextThread(ThreadHandle, Context); if (Context && Context->ContextFlags & CONTEXT_CONTROL) @@ -296,9 +306,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtSuspendThread, __in HANDLE ThreadHandle, __out_opt ULONG *PreviousSuspendCount ) { + NTSTATUS ret; DWORD pid = pid_from_thread_handle(ThreadHandle); DWORD tid = tid_from_thread_handle(ThreadHandle); - NTSTATUS ret; ENSURE_ULONG(PreviousSuspendCount); if (pid == GetCurrentProcessId() && tid && (tid == g_unhook_detect_thread_id || tid == g_unhook_watcher_thread_id || @@ -311,11 +321,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtSuspendThread, } else { pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); - ret = Old_NtSuspendThread(ThreadHandle, PreviousSuspendCount); - LOQ_ntstatus("threading", "pL", "ThreadHandle", ThreadHandle, - "SuspendCount", PreviousSuspendCount); - } + LOQ_ntstatus("threading", "pLi", "ThreadHandle", ThreadHandle, "SuspendCount", PreviousSuspendCount, "ThreadId", tid); + } return ret; } @@ -362,7 +370,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateThread, return ret; } - LOQ_ntstatus("threading", "ph", "ThreadHandle", ThreadHandle, "ExitStatus", ExitStatus); + LOQ_ntstatus("threading", "phi", "ThreadHandle", ThreadHandle, "ExitStatus", ExitStatus, "ThreadId", tid); + ret = Old_NtTerminateThread(ThreadHandle, ExitStatus); disable_tail_call_optimization(); @@ -384,21 +393,28 @@ HOOKDEF(HANDLE, WINAPI, CreateThread, ret = Old_CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags | CREATE_SUSPENDED, lpThreadId); - if (ret != NULL && DEBUGGER_ENABLED && !called_by_hook()) { - DoOutputDebugString("CreateThread: Initialising breakpoints for thread %d.\n", *lpThreadId); - InitNewThreadBreakpoints(*lpThreadId); - } + if (ret != NULL) { + if (DEBUGGER_ENABLED && !called_by_hook()) { + DoOutputDebugString("CreateThread: Initialising breakpoints for thread %d.\n", *lpThreadId); + InitNewThreadBreakpoints(*lpThreadId); + } + + if (!(dwCreationFlags && CREATE_SUSPENDED)) { + lasterror_t lasterror; + get_lasterrors(&lasterror); + ResumeThread(ret); + set_lasterrors(&lasterror); + } + + LOQ_nonnull("threading", "pphI", "StartRoutine", lpStartAddress, "Parameter", lpParameter, + "CreationFlags", dwCreationFlags, "ThreadId", lpThreadId); - if (!(dwCreationFlags && CREATE_SUSPENDED)) { - lasterror_t lasterror; - get_lasterrors(&lasterror); - ResumeThread(ret); - set_lasterrors(&lasterror); - } - LOQ_nonnull("threading", "pphI", "StartRoutine", lpStartAddress, "Parameter", lpParameter, - "CreationFlags", dwCreationFlags, "ThreadId", lpThreadId); - if (ret != NULL) disable_sleep_skip(); + } + else + LOQ_nonnull("threading", "pphI", "StartRoutine", lpStartAddress, "Parameter", lpParameter, + "CreationFlags", dwCreationFlags); + return ret; } @@ -434,14 +450,14 @@ HOOKDEF(HANDLE, WINAPI, CreateRemoteThread, ResumeThread(ret); set_lasterrors(&lasterror); } + + disable_sleep_skip(); } LOQ_nonnull("threading", "ppphI", "ProcessHandle", hProcess, "StartRoutine", lpStartAddress, "Parameter", lpParameter, "CreationFlags", dwCreationFlags, "ThreadId", lpThreadId); - if (ret != NULL) - disable_sleep_skip(); return ret; } @@ -486,12 +502,15 @@ HOOKDEF(NTSTATUS, WINAPI, RtlCreateUserThread, ResumeThread(*ThreadHandle); set_lasterrors(&lasterror); } + disable_sleep_skip(); } - if (NT_SUCCESS(ret)) - disable_sleep_skip(); + LOQ_ntstatus("threading", "pippPi", "ProcessHandle", ProcessHandle, + "CreateSuspended", CreateSuspended, "StartAddress", StartAddress, + "StartParameter", StartParameter, "ThreadHandle", ThreadHandle, + "ThreadId", ClientId->UniqueThread); - return ret; + return ret; } HOOKDEF(NTSTATUS, WINAPI, NtSetInformationThread, @@ -502,12 +521,14 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetInformationThread, ) { NTSTATUS ret; ENSURE_HANDLE(ThreadHandle); + DWORD tid = tid_from_thread_handle(ThreadHandle); ret = Old_NtSetInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength); - - LOQ_ntstatus("threading", "pib", "ThreadHandle", ThreadHandle, - "ThreadInformationClass", ThreadInformationClass, - "ThreadInformation", ThreadInformationLength, ThreadInformation); + + if (ThreadInformationClass == ThreadHideFromDebugger) + LOQ_ntstatus("threading", "pii", "ThreadHandle", ThreadHandle, + "ThreadInformationClass", ThreadInformationClass, + "ThreadId", tid); return ret; } @@ -521,12 +542,14 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationThread, ) { NTSTATUS ret; ENSURE_HANDLE(ThreadHandle); + DWORD tid = tid_from_thread_handle(ThreadHandle); ret = Old_NtQueryInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength, ReturnLength); - LOQ_ntstatus("threading", "pib", "ThreadHandle", ThreadHandle, + LOQ_ntstatus("threading", "pibi", "ThreadHandle", ThreadHandle, "ThreadInformationClass", ThreadInformationClass, - "ThreadInformation", ThreadInformationLength, ThreadInformation); + "ThreadInformation", ThreadInformationLength, ThreadInformation, + "ThreadId", tid); return ret; } diff --git a/hooking.c b/hooking.c index 5720b14..61b785f 100644 --- a/hooking.c +++ b/hooking.c @@ -26,8 +26,6 @@ along with this program. If not, see . #include "misc.h" #include "pipe.h" -extern DWORD g_tls_hook_index; - #ifdef _WIN64 #define TLS_LAST_WIN32_ERROR 0x68 #define TLS_LAST_NTSTATUS_ERROR 0x1250 @@ -38,6 +36,17 @@ extern DWORD g_tls_hook_index; static lookup_t g_hook_info; +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern BOOL DumpRegion(PVOID Address); +extern int DumpModuleInCurrentProcess(LPVOID ModuleBase); +extern PVOID GetAllocationBase(PVOID Address); +extern PVOID GetHookCallerBase(); +extern BOOL ModuleDumped; +#ifdef CAPE_TRACE +extern BOOL SetInitialBreakpoints(PVOID ImageBase); +extern BOOL BreakpointsSet; +#endif + void hook_init() { lookup_init(&g_hook_info); @@ -105,8 +114,73 @@ int called_by_hook(void) return __called_by_hook(hookinfo->stack_pointer, hookinfo->frame_pointer); } -extern BOOLEAN is_ignored_thread(DWORD tid); +void dump_on_api(hook_t *h) +{ + unsigned int i; + hook_info_t *hookinfo = hook_info(); + for (i = 0; i < ARRAYSIZE(g_config.dump_on_apinames); i++) { + PVOID AllocationBase; + if (!g_config.dump_on_apinames[i]) + break; + if (!ModuleDumped && !stricmp(h->funcname, g_config.dump_on_apinames[i])) { + DoOutputDebugString("Dump-on-API: GetHookCallerBase 0x%p main_caller_retaddr 0x%p parent_caller_retaddr 0x%p.\n", GetHookCallerBase(), hookinfo->main_caller_retaddr, hookinfo->parent_caller_retaddr); + if (hookinfo->main_caller_retaddr) { + AllocationBase = GetAllocationBase((PVOID)hookinfo->main_caller_retaddr); + if (!AllocationBase) + AllocationBase = GetAllocationBase((PVOID)hookinfo->parent_caller_retaddr); + if (AllocationBase) { + if (DumpModuleInCurrentProcess(AllocationBase)) { + ModuleDumped = TRUE; + DoOutputDebugString("Dump-on-API: Dumped module at 0x%p due to %s call.\n", AllocationBase, h->funcname); + } + else if (DumpRegion(AllocationBase)) { + ModuleDumped = TRUE; + DoOutputDebugString("Dump-on-API: Dumped memory region at 0x%p due to %s call.\n", AllocationBase, h->funcname); + } + else { + DoOutputDebugString("Dump-on-API: Failed to dump memory region at 0x%p due to %s call.\n", AllocationBase, h->funcname); + } + } + else + DoOutputDebugString("Dump-on-API: Failed to obtain current module base address.\n"); + } + return; + } + } + + return; +} + +#ifdef CAPE_TRACE +void base_on_api(hook_t *h) +{ + unsigned int i; + hook_info_t *hookinfo = hook_info(); + + for (i = 0; i < ARRAYSIZE(g_config.base_on_apiname); i++) { + if (!g_config.base_on_apiname[i]) + break; + if (!BreakpointsSet && !called_by_hook() && !stricmp(h->funcname, g_config.base_on_apiname[i])) { + DoOutputDebugString("Base-on-API: %s call detected in thread %d.\n", g_config.base_on_apiname[i], GetCurrentThreadId()); + PVOID AllocationBase = GetHookCallerBase(); + if (AllocationBase) { + BreakpointsSet = SetInitialBreakpoints((PVOID)AllocationBase); + if (BreakpointsSet) + DoOutputDebugString("Base-on-API: GetHookCallerBase success 0x%p - Breakpoints set.\n", AllocationBase); + else + DoOutputDebugString("Base-on-API: Failed to set breakpoints on 0x%p.\n", AllocationBase); + } + else + DoOutputDebugString("Base-on-API: GetHookCallerBase fail.\n"); + } + } + + return; +} +#endif + +extern BOOLEAN is_ignored_thread(DWORD tid); static hook_info_t tmphookinfo; DWORD tmphookinfo_threadid; @@ -148,6 +222,10 @@ int WINAPI enter_hook(hook_t *h, ULONG_PTR sp, ULONG_PTR ebp_or_rip) operate_on_backtrace(sp, ebp_or_rip, NULL, set_caller_info); +#ifdef CAPE_DUMP_ON_API + dump_on_api(h); +#endif + return 1; } diff --git a/hooking_32.c b/hooking_32.c index 71c7259..cfd41f7 100644 --- a/hooking_32.c +++ b/hooking_32.c @@ -29,11 +29,6 @@ along with this program. If not, see . #include "pipe.h" #include "config.h" -extern DWORD g_tls_hook_index; - -// do not change this number -#define TLS_LAST_ERROR 0x34 - // length disassembler engine static int lde(void *addr) { diff --git a/hooking_64.c b/hooking_64.c index 854a557..c9e2c3f 100644 --- a/hooking_64.c +++ b/hooking_64.c @@ -28,11 +28,6 @@ along with this program. If not, see . #include "pipe.h" #include "config.h" -extern DWORD g_tls_hook_index; - -// do not change this number -#define TLS_LAST_ERROR 0x34 - // length disassembler engine static int lde(void *addr) { diff --git a/hooks.h b/hooks.h index 6b5119b..c36ad2e 100644 --- a/hooks.h +++ b/hooks.h @@ -961,6 +961,16 @@ extern HOOKDEF(BOOL, WINAPI, Process32NextW, __out LPPROCESSENTRY32W lppe ); +extern HOOKDEF(BOOL, WINAPI, Module32FirstW, + __in HANDLE hSnapshot, + __out LPMODULEENTRY32W lpme +); + +extern HOOKDEF(BOOL, WINAPI, Module32NextW, + __in HANDLE hSnapshot, + __out LPMODULEENTRY32W lpme +); + extern HOOKDEF(NTSTATUS, WINAPI, NtCreateProcess, __out PHANDLE ProcessHandle, __in ACCESS_MASK DesiredAccess, diff --git a/misc.c b/misc.c index afe795c..769f1e7 100644 --- a/misc.c +++ b/misc.c @@ -370,6 +370,12 @@ void perform_ascii_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength replace_string_in_buf(Data, DataLength, "VMWar", "Lenov"); replace_string_in_buf(Data, DataLength, "VBOX", "DELL"); } + + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\DeviceClasses\\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}")) { + replace_string_in_buf(Data, DataLength, "VMware", "Lenovo"); + replace_string_in_buf(Data, DataLength, "VMWar", "Lenov"); + replace_string_in_buf(Data, DataLength, "VBOX", "DELL"); + } } void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLength) @@ -444,6 +450,12 @@ void perform_unicode_registry_fakery(PWCHAR keypath, LPVOID Data, ULONG DataLeng replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMWar", L"Lenov"); replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VBOX", L"DELL"); } + + if (!wcsicmp(keypath, L"HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\DeviceClasses\\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}")) { + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMware", L"Lenovo"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VMWar", L"Lenov"); + replace_wstring_in_buf(Data, DataLength / sizeof(wchar_t), L"VBOX", L"DELL"); + } } @@ -660,10 +672,9 @@ void add_all_dlls_to_dll_ranges(void) for (mod = (LDR_MODULE *)mod->InLoadOrderModuleList.Flink; mod->BaseAddress != NULL; mod = (LDR_MODULE *)mod->InLoadOrderModuleList.Flink) { - //if ((ULONG_PTR)mod->BaseAddress != base_of_dll_of_interest) + if ((ULONG_PTR)mod->BaseAddress != base_of_dll_of_interest) add_dll_range((ULONG_PTR)mod->BaseAddress, (ULONG_PTR)mod->BaseAddress + mod->SizeOfImage); } - } char *convert_address_to_dll_name_and_offset(ULONG_PTR addr, unsigned int *offset) @@ -1909,7 +1920,7 @@ void prevent_module_reloading(PVOID *BaseAddress) { // is this a loaded module? HMODULE address = GetModuleHandleW(absolutepath); if (address != NULL) { - pipe("INFO:Sample tried to reload already loaded module '%Z' from disk, returning original module address instead: 0x%x", absolutepath, address); + pipe("INFO:Sample attempted to remap module '%Z' at 0x%p, returning original module address instead: 0x%p", absolutepath, *BaseAddress, address); pNtUnmapViewOfSection(GetCurrentProcess(), *BaseAddress); *BaseAddress = (LPVOID)address; } diff --git a/misc.h b/misc.h index 16f3f40..d81a2f3 100644 --- a/misc.h +++ b/misc.h @@ -204,3 +204,4 @@ int is_stack_pivoted(void); LONG WINAPI cuckoomon_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo); void prevent_module_reloading(PVOID *BaseAddress); +PVOID test_module_reloading(PVOID *BaseAddress); diff --git a/ntapi.h b/ntapi.h index 54750a4..46fa5af 100644 --- a/ntapi.h +++ b/ntapi.h @@ -59,6 +59,16 @@ typedef LONG NTSTATUS; #pragma warning( disable : 4996) #endif +#define Suspended 5 +#define OptionShutdownSystem 6 +// NTSTATUS +#define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 +#define STATUS_CONFLICTING_ADDRESSES 0xc0000018 +#define STATUS_OBJECT_NAME_NOT_FOUND 0xc0000034 +#define STATUS_INVALID_DEVICE_REQUEST 0xc0000010 +#define STATUS_ACCESS_DENIED ((NTSTATUS) 0xc0000022) +#define STATUS_IMAGE_NOT_AT_BASE ((NTSTATUS) 0x40000003) + typedef struct _STRING { USHORT Length; USHORT MaximumLength; @@ -248,12 +258,6 @@ typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION { ULONG InterruptCount; } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; -#define Suspended 5 -#define OptionShutdownSystem 6 -#define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 -#define STATUS_CONFLICTING_ADDRESSES 0xc0000018 -#define STATUS_OBJECT_NAME_NOT_FOUND 0xc0000034 -#define STATUS_INVALID_DEVICE_REQUEST 0xc0000010 typedef struct _INITIAL_TEB { PVOID StackBase; PVOID StackLimit; @@ -362,8 +366,6 @@ typedef enum _FILE_INFORMATION_CLASS { FileMaximumInformation } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; -#define STATUS_ACCESS_DENIED ((NTSTATUS) 0xc0000022) - typedef struct _FILE_BASIC_INFORMATION { LARGE_INTEGER CreationTime; LARGE_INTEGER LastAccessTime; diff --git a/unhook.c b/unhook.c index 3ef7aa9..770b229 100644 --- a/unhook.c +++ b/unhook.c @@ -344,7 +344,7 @@ int procname_watch_init() if (g_procname_watch_thread_handle != NULL) return 0; - pipe("CRITICAL:Error initializing terminate event thread!"); + pipe("CRITICAL:Error initializing procname watch thread!"); return -1; } From 7d1bdf06fbc3e22eae9ed18acd61a24e56d111ee Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Oct 2018 21:55:49 +0000 Subject: [PATCH 36/39] Upgrade package to VS2017 and merge updates from main branch. --- .gitignore | 2 +- CAPE/CAPE.c | 20 +- CAPE/Debugger.h | 2 + CAPE/Injection.c | 2 +- CAPE/Scylla/ApiReader.h | 2 +- CAPE/Scylla/ImportsHandling.cpp | 461 - CAPE/Scylla/ImportsHandling.h | 69 +- CAPE/Scylla/Thunks.h | 10 +- CAPE/ScyllaHarness.cpp | 98 +- CAPE/{wow64ext => w64wow64}/internal.h | 6 +- CAPE/w64wow64/w64wow64.c | 469 + CAPE/w64wow64/w64wow64.h | 44 + CAPE/w64wow64/w64wow64defs.h | 34 + CAPE/w64wow64/windef.h | 93 + CAPE/{wow64_fix.cpp => wow64_fix.c} | 42 +- CAPE/wow64ext/wow64ext.cpp | 338 - CAPE/wow64ext/wow64ext.h | 348 - Makefile | 8 +- bson/bson.vcxproj | 10 +- cuckoomon.c | 12 +- cuckoomon.vcxproj | 85 +- cuckoomon.vcxproj.filters | 82 +- distorm/COPYING | 26 + .../include/distorm.h | 94 +- distorm/include/mnemonics.h | 301 + {distorm3.2-package => distorm}/src/config.h | 18 +- {distorm3.2-package => distorm}/src/decoder.c | 134 +- {distorm3.2-package => distorm}/src/decoder.h | 0 {distorm3.2-package => distorm}/src/distorm.c | 71 +- .../src/instructions.c | 71 +- .../src/instructions.h | 105 +- distorm/src/insts.c | 7939 +++++++++++++++++ distorm/src/insts.h | 64 + .../src/mnemonics.c | 166 +- .../src/operands.c | 39 +- distorm/src/operands.h | 28 + {distorm3.2-package => distorm}/src/prefix.c | 16 +- {distorm3.2-package => distorm}/src/prefix.h | 16 +- .../src/textdefs.c | 16 +- .../src/textdefs.h | 18 +- {distorm3.2-package => distorm}/src/wstring.c | 16 +- {distorm3.2-package => distorm}/src/wstring.h | 16 +- {distorm3.2-package => distorm}/src/x86defs.h | 49 +- distorm3.2-package/COPYING | 674 -- distorm3.2-package/include/mnemonics.h | 312 - distorm3.2-package/src/insts.c | 7343 --------------- distorm3.2-package/src/insts.h | 47 - distorm3.2-package/src/operands.h | 40 - distorm3.2-package/src/x86defs.c | 50 - hook_misc.c | 73 + hook_process.c | 109 +- hook_sleep.c | 51 +- hook_thread.c | 9 + hooking.c | 3 + hooking_32.c | 2 +- hooks.h | 12 +- loader/loader/loader.vcxproj | 10 +- 57 files changed, 9905 insertions(+), 10270 deletions(-) rename CAPE/{wow64ext => w64wow64}/internal.h (97%) create mode 100644 CAPE/w64wow64/w64wow64.c create mode 100644 CAPE/w64wow64/w64wow64.h create mode 100644 CAPE/w64wow64/w64wow64defs.h create mode 100644 CAPE/w64wow64/windef.h rename CAPE/{wow64_fix.cpp => wow64_fix.c} (89%) delete mode 100644 CAPE/wow64ext/wow64ext.cpp delete mode 100644 CAPE/wow64ext/wow64ext.h create mode 100644 distorm/COPYING rename {distorm3.2-package => distorm}/include/distorm.h (89%) create mode 100644 distorm/include/mnemonics.h rename {distorm3.2-package => distorm}/src/config.h (85%) rename {distorm3.2-package => distorm}/src/decoder.c (84%) rename {distorm3.2-package => distorm}/src/decoder.h (100%) rename {distorm3.2-package => distorm}/src/distorm.c (88%) rename {distorm3.2-package => distorm}/src/instructions.c (91%) rename {distorm3.2-package => distorm}/src/instructions.h (88%) create mode 100644 distorm/src/insts.c create mode 100644 distorm/src/insts.h rename {distorm3.2-package => distorm}/src/mnemonics.c (68%) rename {distorm3.2-package => distorm}/src/operands.c (97%) create mode 100644 distorm/src/operands.h rename {distorm3.2-package => distorm}/src/prefix.c (94%) rename {distorm3.2-package => distorm}/src/prefix.h (77%) rename {distorm3.2-package => distorm}/src/textdefs.c (90%) rename {distorm3.2-package => distorm}/src/textdefs.h (64%) rename {distorm3.2-package => distorm}/src/wstring.c (54%) rename {distorm3.2-package => distorm}/src/wstring.h (58%) rename {distorm3.2-package => distorm}/src/x86defs.h (54%) delete mode 100644 distorm3.2-package/COPYING delete mode 100644 distorm3.2-package/include/mnemonics.h delete mode 100644 distorm3.2-package/src/insts.c delete mode 100644 distorm3.2-package/src/insts.h delete mode 100644 distorm3.2-package/src/operands.h delete mode 100644 distorm3.2-package/src/x86defs.c diff --git a/.gitignore b/.gitignore index 00415bc..ffc88da 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ cuckoomon.opensdf cuckoomon.sdf cuckoomon.v11.suo cuckoomon.v12.suo -cuckoomon.VC.db bson/bson.sdf bson/bson.v11.suo bson/bson.v12.suo @@ -17,3 +16,4 @@ Release tests/logging-test.* *.suo *.opendb +*.VC.db \ No newline at end of file diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 30be9a2..c9f0c99 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -574,7 +574,10 @@ PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) while (CurrentSectionView) { if (CurrentSectionView->SectionHandle == SectionHandle) + { + DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); return CurrentSectionView; + } CurrentSectionView = CurrentSectionView->NextSectionView; } @@ -1003,7 +1006,7 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) LONG e_lfanew; DWORD NT_Signature; unsigned int i, j, k; - BYTE* DecryptedBuffer; + BYTE* DecryptedBuffer = NULL; for (i=0; i<=0xFF; i++) { @@ -1071,7 +1074,8 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) } // We free can free DecryptedBuffer as it's no longer needed - free(DecryptedBuffer); + if(DecryptedBuffer) + free(DecryptedBuffer); return FALSE; } @@ -1455,7 +1459,6 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) //break; } } - MachineProbe += sizeof(WORD); if (pNtHeader && (PUCHAR)pNtHeader == (PUCHAR)pDosHeader && pNtHeader->OptionalHeader.SizeOfHeaders) @@ -1474,9 +1477,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) *(WORD*)pDosHeader = IMAGE_DOS_SIGNATURE; *(DWORD*)((PUCHAR)pDosHeader + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; -#ifdef CAPE_INJECTION SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)pDosHeader); -#endif if (DumpImageInCurrentProcess((LPVOID)pDosHeader)) { @@ -1724,11 +1725,7 @@ int DumpModuleInCurrentProcess(LPVOID ModuleBase) ModuleBase = PEImage; } -#ifdef CAPE_INJECTION - SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)ModuleBase); -#else SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); -#endif if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) { @@ -1878,14 +1875,14 @@ void init_CAPE() CapeMetaData->Pid = GetCurrentProcessId(); CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, (int)wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); - + CommandLine = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_commandline, (int)wcslen(our_commandline)+1, CommandLine, MAX_PATH, NULL, NULL); // Specific to Injection package: CapeMetaData->DumpType = INJECTION_SHELLCODE; // default value for now, may be changed to INJECTION_PE CapeMetaData->Address = NULL; - + DumpCount = 0; // This flag controls whether a dump is automatically @@ -1912,6 +1909,5 @@ void init_CAPE() #endif DoOutputDebugString("Commandline: %s.\n", CommandLine); - return; } diff --git a/CAPE/Debugger.h b/CAPE/Debugger.h index fc38b5a..88f43fc 100644 --- a/CAPE/Debugger.h +++ b/CAPE/Debugger.h @@ -19,12 +19,14 @@ #define EXTRACTION_MIN_SIZE 0x1001 +#if (NTDDI_VERSION <= NTDDI_WINBLUE) typedef struct _EXCEPTION_REGISTRATION_RECORD { struct _EXCEPTION_REGISTRATION_RECORD *Next; PEXCEPTION_ROUTINE Handler; } EXCEPTION_REGISTRATION_RECORD; typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD; +#endif typedef struct BreakpointInfo { diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 79e9884..44990bc 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -401,7 +401,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer { SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); - CurrentInjectionInfo->ImageDumped = DumpModuleInCurrentProcess((PVOID)Buffer); + CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)Buffer); if (CurrentInjectionInfo->ImageDumped) { diff --git a/CAPE/Scylla/ApiReader.h b/CAPE/Scylla/ApiReader.h index 45e67ef..54d1431 100644 --- a/CAPE/Scylla/ApiReader.h +++ b/CAPE/Scylla/ApiReader.h @@ -29,6 +29,7 @@ class ApiReader : public ProcessAccessHelp void addFoundApiToModuleList(DWORD_PTR iatAddress, ApiInfo * apiFound, bool isNewModule, bool isSuspect); void clearAll(); bool isInvalidMemoryForIat( DWORD_PTR address ); + void parseModuleWithOwnProcess( ModuleInfo * module ); private: bool readExportTableAlwaysFromDisk; void parseIAT(DWORD_PTR addressIAT, BYTE * iatBuffer, SIZE_T size); @@ -49,7 +50,6 @@ class ApiReader : public ProcessAccessHelp void findApiByModule(ModuleInfo * module, char * searchFunctionName, WORD ordinal, DWORD_PTR * vaApi, DWORD_PTR * rvaApi); bool isModuleLoadedInOwnProcess( ModuleInfo * module ); - void parseModuleWithOwnProcess( ModuleInfo * module ); bool isPeAndExportTableValid(PIMAGE_NT_HEADERS pNtHeader); void findApiInProcess( ModuleInfo * module, char * searchFunctionName, WORD ordinal, DWORD_PTR * vaApi, DWORD_PTR * rvaApi ); bool findApiInExportTable(ModuleInfo *module, PIMAGE_EXPORT_DIRECTORY pExportDir, DWORD_PTR deltaAddress, char * searchFunctionName, WORD ordinal, DWORD_PTR * vaApi, DWORD_PTR * rvaApi); diff --git a/CAPE/Scylla/ImportsHandling.cpp b/CAPE/Scylla/ImportsHandling.cpp index 17c9cda..4724f15 100644 --- a/CAPE/Scylla/ImportsHandling.cpp +++ b/CAPE/Scylla/ImportsHandling.cpp @@ -3,12 +3,6 @@ #include "Thunks.h" #include "Architecture.h" -#include -#include -//#include "multitree.h" // CMultiSelectTreeViewCtrl - -//#include "resource.h" - //#define DEBUG_COMMENTS extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); @@ -59,59 +53,6 @@ ImportsHandling::ImportsHandling() ImportsHandling::~ImportsHandling() { - //TreeIcons.Destroy(); -} - -bool ImportsHandling::isModule(CTreeItem item) -{ - return (0 != getModuleThunk(item)); -} - -bool ImportsHandling::isImport(CTreeItem item) -{ - return (0 != getImportThunk(item)); -} - -ImportModuleThunk * ImportsHandling::getModuleThunk(CTreeItem item) -{ - stdext::hash_map::const_iterator it; - it = itemData.find(item); - if(it != itemData.end()) - { - const TreeItemData * data = &it->second; - if(data->isModule) - { - return data->module; - } - } - return NULL; -} - -ImportThunk * ImportsHandling::getImportThunk(CTreeItem item) -{ - stdext::hash_map::const_iterator it; - TreeItemData * data = getItemData(item); - if(data && !data->isModule) - { - return data->import; - } - return NULL; -} - -void ImportsHandling::setItemData(CTreeItem item, const TreeItemData * data) -{ - itemData[item] = *data; -} - -ImportsHandling::TreeItemData * ImportsHandling::getItemData(CTreeItem item) -{ - stdext::hash_map::iterator it; - it = itemData.find(item); - if(it != itemData.end()) - { - return &it->second; - } - return NULL; } void ImportsHandling::updateCounts() @@ -144,160 +85,17 @@ void ImportsHandling::updateCounts() } } -/*bool ImportsHandling::addImport(const CHAR * moduleName, const CHAR * name, DWORD_PTR va, DWORD_PTR rva, WORD ordinal, bool valid, bool suspect) -{ - ImportThunk import; - ImportModuleThunk * module = 0; - std::map::iterator iterator1; - - if (moduleList.size() > 1) - { - iterator1 = moduleList.begin(); - while (iterator1 != moduleList.end()) - { - if (rva >= iterator1->second.firstThunk) - { - iterator1++; - if (iterator1 == moduleList.end()) - { - iterator1--; - module = &(iterator1->second); - break; - } - else if (rva < iterator1->second.firstThunk) - { - iterator1--; - module = &(iterator1->second); - break; - } - } - } - } - else - { - iterator1 = moduleList.begin(); - module = &(iterator1->second); - } - - if (!module) - { - DoOutputDebugString("ImportsHandling::addFunction module not found rva " PRINTF_DWORD_PTR_FULL, rva); - return false; - } - - //TODO - import.suspect = true; - import.valid = false; - import.va = va; - import.rva = rva; - import.ordinal = ordinal; - - strcpy_s(import.moduleName, MAX_PATH, moduleName); - strcpy_s(import.name, MAX_PATH, name); - - module->thunkList.insert(std::pair(import.rva, import)); - - return true; -} -*/ - -/* -bool ImportsHandling::addModule(const CHAR * moduleName, DWORD_PTR firstThunk) -{ - ImportModuleThunk module; - - module.firstThunk = firstThunk; - strcpy_s(module.moduleName, MAX_PATH, moduleName); - - moduleList.insert(std::pair(firstThunk,module)); - - return true; -} - -void ImportsHandling::displayAllImports() -{ - std::map::iterator it_module; - std::map::iterator it_import; - - //TreeImports.DeleteAllItems(); - itemData.clear(); - //TreeImports.SetImageList(TreeIcons); - - it_module = moduleList.begin(); - while (it_module != moduleList.end()) - { - ImportModuleThunk &moduleThunk = it_module->second; - - moduleThunk.key = moduleThunk.firstThunk; // This belongs elsewhere... - //moduleThunk.hTreeItem = addDllToTreeView(TreeImports, &moduleThunk); - - it_import = moduleThunk.thunkList.begin(); - while (it_import != moduleThunk.thunkList.end()) - { - ImportThunk &importThunk = it_import->second; - - importThunk.key = importThunk.rva; // This belongs elsewhere... - importThunk.hTreeItem = addApiToTreeView(TreeImports, moduleThunk.hTreeItem, &importThunk); - - it_import++; - } - - it_module++; - } - - updateCounts(); -} -*/ - void ImportsHandling::clearAllImports() { - //TreeImports.DeleteAllItems(); - itemData.clear(); moduleList.clear(); updateCounts(); } -/* -CTreeItem ImportsHandling::addDllToTreeView(CMultiSelectTreeViewCtrl& idTreeView, ImportModuleThunk * moduleThunk) -{ - CTreeItem item = idTreeView.InsertItem("", NULL, TVI_ROOT); - - item.SetData(itemData.size()); - - TreeItemData data; - data.isModule = true; - data.module = moduleThunk; - - setItemData(item, &data); - - updateModuleInTreeView(moduleThunk, item); - return item; -} - -CTreeItem ImportsHandling::addApiToTreeView(CMultiSelectTreeViewCtrl& idTreeView, CTreeItem parentDll, ImportThunk * importThunk) -{ - CTreeItem item = idTreeView.InsertItem("", parentDll, TVI_LAST); - - item.SetData(itemData.size()); - - TreeItemData data; - data.isModule = false; - data.import = importThunk; - - setItemData(item, &data); - - updateImportInTreeView(importThunk, item); - return item; -} -*/ - void ImportsHandling::selectImports(bool invalid, bool suspect) { std::map::iterator it_module; std::map::iterator it_import; - //TreeImports.SelectAllItems(FALSE); //remove selection - it_module = moduleList.begin(); while (it_module != moduleList.end()) { @@ -307,13 +105,6 @@ void ImportsHandling::selectImports(bool invalid, bool suspect) while (it_import != moduleThunk.thunkList.end()) { ImportThunk &importThunk = it_import->second; - - if ((invalid && !importThunk.valid) || (suspect && importThunk.suspect)) - { - //TreeImports.SelectItem(importThunk.hTreeItem, TRUE); - importThunk.hTreeItem.EnsureVisible(); - } - it_import++; } @@ -321,232 +112,6 @@ void ImportsHandling::selectImports(bool invalid, bool suspect) } } -bool ImportsHandling::invalidateImport(CTreeItem item) -{ - ImportThunk * import = getImportThunk(item); - if(import) - { - CTreeItem parent = item.GetParent(); - if(!parent.IsNull()) - { - const ImportModuleThunk * module = getModuleThunk(parent); - if(module) - { - import->invalidate(); - - updateImportInTreeView(import, import->hTreeItem); - updateModuleInTreeView(module, module->hTreeItem); - - updateCounts(); - return true; - } - } - } - return false; -} - -bool ImportsHandling::invalidateModule(CTreeItem item) -{ - ImportModuleThunk * module = getModuleThunk(item); - if(module) - { - std::map::iterator it_import; - - it_import = module->thunkList.begin(); - while(it_import != module->thunkList.end()) - { - ImportThunk * import = &it_import->second; - import->invalidate(); - updateImportInTreeView(import, import->hTreeItem); - it_import++; - } - - updateModuleInTreeView(module, module->hTreeItem); - - updateCounts(); - return true; - } - return false; -} - -bool ImportsHandling::setImport(CTreeItem item, const CHAR * moduleName, const CHAR * apiName, WORD ordinal, WORD hint, bool valid, bool suspect) -{ - ImportThunk * import = getImportThunk(item); - if(import) - { - CTreeItem parent = item.GetParent(); - if(!parent.IsNull()) - { - ImportModuleThunk * module = getModuleThunk(parent); - if(module) - { - - strcpy_s(import->moduleName, moduleName); - strcpy_s(import->name, apiName); - import->ordinal = ordinal; - //import->apiAddressVA = api->va; //?? - import->hint = hint; - import->valid = valid; - import->suspect = suspect; - - if (module->isValid()) - { - scanAndFixModuleList(); - //displayAllImports(); - } - else - { - updateImportInTreeView(import, item); - updateCounts(); - } - return true; - } - } - } - return false; -} - -void ImportsHandling::updateImportInTreeView(const ImportThunk * importThunk, CTreeItem item) -{ - if (importThunk->valid) - { - CHAR tempString[300]; - - if (importThunk->name[0] != 0x00) - { - sprintf_s(tempString, "ord: %04X name: %s", importThunk->ordinal, importThunk->name); - } - else - { - sprintf_s(tempString, "ord: %04X", importThunk->ordinal); - } - - sprintf_s(stringBuffer, " rva: " PRINTF_DWORD_PTR_HALF " mod: %s %s", importThunk->rva, importThunk->moduleName, tempString); - } - else - { - sprintf_s(stringBuffer, " rva: " PRINTF_DWORD_PTR_HALF " ptr: " PRINTF_DWORD_PTR_FULL, importThunk->rva, importThunk->apiAddressVA); - } - -// item.SetText(stringBuffer); -// Icon icon = getAppropiateIcon(importThunk); -// item.SetImage(icon, icon); -} - -void ImportsHandling::updateModuleInTreeView(const ImportModuleThunk * importThunk, CTreeItem item) -{ - sprintf_s(stringBuffer, "%s (%d) FThunk: " PRINTF_DWORD_PTR_HALF, importThunk->moduleName,importThunk->thunkList.size(), importThunk->firstThunk); - - item.SetText(stringBuffer); - Icon icon = getAppropiateIcon(importThunk->isValid()); - item.SetImage(icon, icon); -} - -ImportsHandling::Icon ImportsHandling::getAppropiateIcon(const ImportThunk * importThunk) -{ - if(importThunk->valid) - { - if(importThunk->suspect) - { - return iconWarning; - } - else - { - return iconCheck; - } - } - else - { - return iconError; - } -} - -ImportsHandling::Icon ImportsHandling::getAppropiateIcon(bool valid) -{ - if(valid) - { - return iconCheck; - } - else - { - return iconError; - } -} - -bool ImportsHandling::cutImport(CTreeItem item) -{ - ImportThunk * import = getImportThunk(item); - if(import) - { - CTreeItem parent = item.GetParent(); - if(!parent.IsNull()) - { - ImportModuleThunk * module = getModuleThunk(parent); - if(module) - { - itemData.erase(item); - import->hTreeItem.Delete(); - module->thunkList.erase(import->key); - import = 0; - - if (module->thunkList.empty()) - { - itemData.erase(parent); - module->hTreeItem.Delete(); - moduleList.erase(module->key); - module = 0; - } - else - { - if (module->isValid() && module->moduleName[0] == L'?') - { - //update module name - strcpy_s(module->moduleName, module->thunkList.begin()->second.moduleName); - } - - module->firstThunk = module->thunkList.begin()->second.rva; - updateModuleInTreeView(module, module->hTreeItem); - } - - updateCounts(); - return true; - } - } - } - return false; -} - -bool ImportsHandling::cutModule(CTreeItem item) -{ - ImportModuleThunk * module = getModuleThunk(item); - if(module) - { - CTreeItem child = item.GetChild(); - while(!child.IsNull()) - { - itemData.erase(child); - child = child.GetNextSibling(); - } - itemData.erase(item); - module->hTreeItem.Delete(); - moduleList.erase(module->key); - module = 0; - updateCounts(); - return true; - } - return false; -} - -DWORD_PTR ImportsHandling::getApiAddressByNode(CTreeItem item) -{ - const ImportThunk * import = getImportThunk(item); - if(import) - { - return import->apiAddressVA; - } - return 0; -} - void ImportsHandling::scanAndFixModuleList() { CHAR prevModuleName[MAX_PATH] = {0}; @@ -787,29 +352,3 @@ bool ImportsHandling::addFunctionToModuleList(const ImportThunk * apiFound) module->thunkList[import.key] = import; return true; } - -void ImportsHandling::expandAllTreeNodes() -{ - changeExpandStateOfTreeNodes(TVE_EXPAND); -} - -void ImportsHandling::collapseAllTreeNodes() -{ - changeExpandStateOfTreeNodes(TVE_COLLAPSE); -} - -void ImportsHandling::changeExpandStateOfTreeNodes(UINT flag) -{ - std::map::iterator it_module; - - it_module = moduleList.begin(); - while (it_module != moduleList.end()) - { - ImportModuleThunk &moduleThunk = it_module->second; - - moduleThunk.hTreeItem.Expand(flag); - - it_module++; - } -} - diff --git a/CAPE/Scylla/ImportsHandling.h b/CAPE/Scylla/ImportsHandling.h index 8a7fcb4..3c1ee9b 100644 --- a/CAPE/Scylla/ImportsHandling.h +++ b/CAPE/Scylla/ImportsHandling.h @@ -1,15 +1,9 @@ #pragma once +#include #include #include -// WTL -#include -#include -#include // CTreeItem - -class CMultiSelectTreeViewCtrl; - class ImportThunk; class ImportModuleThunk; @@ -26,28 +20,10 @@ class ImportsHandling unsigned int invalidThunkCount() const { return m_invalidThunkCount; } unsigned int suspectThunkCount() const { return m_suspectThunkCount; } - bool isModule(CTreeItem item); - bool isImport(CTreeItem item); - - ImportModuleThunk * getModuleThunk(CTreeItem item); - ImportThunk * getImportThunk(CTreeItem item); - - //void displayAllImports(); void clearAllImports(); void selectImports(bool invalid, bool suspect); - bool invalidateImport(CTreeItem item); - bool invalidateModule(CTreeItem item); - bool setImport(CTreeItem item, const CHAR * moduleName, const CHAR * apiName, WORD ordinal = 0, WORD hint = 0, bool valid = true, bool suspect = false); - bool cutImport(CTreeItem item); - bool cutModule(CTreeItem item); - //bool addImport(const CHAR * moduleName, const CHAR * name, DWORD_PTR va, DWORD_PTR rva, WORD ordinal = 0, bool valid = true, bool suspect = false); - //bool addModule(const CHAR * moduleName, DWORD_PTR firstThunk); - - DWORD_PTR getApiAddressByNode(CTreeItem selectedTreeNode); void scanAndFixModuleList(); - void expandAllTreeNodes(); - void collapseAllTreeNodes(); private: DWORD numberOfFunctions; @@ -56,58 +32,15 @@ class ImportsHandling unsigned int m_invalidThunkCount; unsigned int m_suspectThunkCount; - struct TreeItemData - { - bool isModule; - union - { - ImportModuleThunk * module; - ImportThunk * import; - }; - }; - - stdext::hash_map itemData; - - void setItemData(CTreeItem item, const TreeItemData * data); - TreeItemData * getItemData(CTreeItem item); - CHAR stringBuffer[600]; - //CMultiSelectTreeViewCtrl& TreeImports; - //CImageList TreeIcons; - //CIcon hIconCheck; - //CIcon hIconWarning; - //CIcon hIconError; - - // They have to be added to the image list in that order! - enum Icon { - iconCheck = 0, - iconWarning, - iconError - }; - void updateCounts(); - CTreeItem addDllToTreeView(CMultiSelectTreeViewCtrl& idTreeView, ImportModuleThunk * moduleThunk); - CTreeItem addApiToTreeView(CMultiSelectTreeViewCtrl& idTreeView, CTreeItem parentDll, ImportThunk * importThunk); - - void updateImportInTreeView(const ImportThunk * importThunk, CTreeItem item); - void updateModuleInTreeView(const ImportModuleThunk * importThunk, CTreeItem item); - - //bool isItemSelected(CTreeItem hItem); - //void unselectItem(CTreeItem htItem); - //bool selectItem(CTreeItem hItem, bool select = true); bool findNewModules(std::map & thunkList); - Icon getAppropiateIcon(const ImportThunk * importThunk); - Icon getAppropiateIcon(bool valid); - bool addModuleToModuleList(const CHAR * moduleName, DWORD_PTR firstThunk); void addUnknownModuleToModuleList(DWORD_PTR firstThunk); bool addNotFoundApiToModuleList(const ImportThunk * apiNotFound); bool addFunctionToModuleList(const ImportThunk * apiFound); bool isNewModule(const CHAR * moduleName); - - void changeExpandStateOfTreeNodes(UINT flag); - }; diff --git a/CAPE/Scylla/Thunks.h b/CAPE/Scylla/Thunks.h index 3be2a74..27918bb 100644 --- a/CAPE/Scylla/Thunks.h +++ b/CAPE/Scylla/Thunks.h @@ -4,9 +4,9 @@ #include // WTL -#include -#include -#include // CTreeItem +//#include +//#include +//#include // CTreeItem class ImportThunk { @@ -21,7 +21,7 @@ class ImportThunk bool valid; bool suspect; - CTreeItem hTreeItem; +// CTreeItem hTreeItem; DWORD_PTR key; void invalidate(); @@ -35,7 +35,7 @@ class ImportModuleThunk DWORD_PTR firstThunk; - CTreeItem hTreeItem; +// CTreeItem hTreeItem; DWORD_PTR key; DWORD_PTR getFirstThunk() const; diff --git a/CAPE/ScyllaHarness.cpp b/CAPE/ScyllaHarness.cpp index b6ff1de..398c518 100644 --- a/CAPE/ScyllaHarness.cpp +++ b/CAPE/ScyllaHarness.cpp @@ -37,6 +37,7 @@ typedef unsigned __int64 QWORD; extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern "C" int ScanForNonZero(LPVOID Buffer, unsigned int Size); +extern "C" PVOID GetAllocationBase(PVOID Address); extern char CapeOutputPath[MAX_PATH]; @@ -57,13 +58,19 @@ void ScyllaInitCurrentProcess() extern "C" DWORD_PTR GetEntryPointVA(DWORD_PTR modBase) //************************************************************************************** { + DWORD_PTR EntryPointVA; + PeParser * peFile = 0; ScyllaInitCurrentProcess(); - + peFile = new PeParser((DWORD_PTR)modBase, true); - return peFile->getEntryPoint() + (DWORD_PTR)modBase; + EntryPointVA = peFile->getEntryPoint() + (DWORD_PTR)modBase; + + delete peFile; + + return EntryPointVA; } //************************************************************************************** @@ -153,7 +160,7 @@ void ScyllaInit(HANDLE hProcess) extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PTR NewOEP) //************************************************************************************** { - SIZE_T SectionBasedFileSize; + SIZE_T SectionBasedSizeOfImage; PeParser * peFile = 0; DWORD_PTR entrypoint = NULL; @@ -170,9 +177,9 @@ extern "C" int ScyllaDumpProcess(HANDLE hProcess, DWORD_PTR ModuleBase, DWORD_PT else entrypoint = peFile->getEntryPoint(); - SectionBasedFileSize = (SIZE_T)peFile->getSectionHeaderBasedFileSize(); + SectionBasedSizeOfImage = (SIZE_T)peFile->getSectionHeaderBasedSizeOfImage(); - if ((SIZE_T)entrypoint > SectionBasedFileSize) + if ((SIZE_T)entrypoint >= SectionBasedSizeOfImage) { DoOutputDebugString("DumpProcess: Error - entry point too big: 0x%x, ignoring.\n", entrypoint); entrypoint = NULL; @@ -866,4 +873,83 @@ extern "C" BOOL ScyllaGetSectionByName(PVOID ImageBase, char* Name, PVOID* Secti } return FALSE; -} \ No newline at end of file +} + +//************************************************************************************** +extern "C" PCHAR ScyllaGetExportNameByAddress(PVOID Address, PCHAR* ModuleName) +//************************************************************************************** +{ + ApiReader apiReader; + ApiInfo* apiInfo; + unsigned int ModuleIndex = 0; + bool dummy; + + ScyllaInitCurrentProcess(); + + for (unsigned int i = 0; i < ProcessAccessHelp::ownModuleList.size(); i++) { + if ((DWORD_PTR)Address >= ProcessAccessHelp::ownModuleList[i].modBaseAddr && (DWORD_PTR)Address < (ProcessAccessHelp::ownModuleList[i].modBaseAddr + ProcessAccessHelp::ownModuleList[i].modBaseSize)) + ModuleIndex = i+1; + } + + if (!ModuleIndex) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("ScyllaGetExportNameByAddress: Address 0x%p not within loaded modules.\n", Address); +#endif + return NULL; + } + + PVOID ModuleBase = GetAllocationBase(Address); + + if (!ModuleBase) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("ScyllaGetExportNameByAddress: GetAllocationBase failed for 0x%p.\n", Address); +#endif + return NULL; + } + + PeParser *peFile = new PeParser((DWORD_PTR)ModuleBase, true); + + if (!peFile->isValidPeFile()) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("ScyllaGetExportNameByAddress: Invalid PE image at 0x%p.\n", Address); +#endif + delete peFile; + return NULL; + } + + if (!peFile->hasExportDirectory()) + { +#ifdef DEBUG_COMMENTS + DoOutputDebugString("ScyllaGetExportNameByAddress: Module has no exports.\n"); +#endif + delete peFile; + return NULL; + } + + apiReader.clearAll(); + + // This creates moduleInfo->apiList + apiReader.parseModuleWithOwnProcess(&ProcessAccessHelp::ownModuleList[ModuleIndex-1]); + apiInfo = apiReader.getApiByVirtualAddress((DWORD_PTR)Address, &dummy); + + if (apiInfo) + { + if (ModuleName) + *ModuleName = apiInfo->module->fullPath; +#ifdef DEBUG_COMMENTS + DoOutputDebugString("ScyllaGetExportNameByAddress: Located function %s within module %s.\n", apiInfo->name, apiInfo->module->fullPath); +#endif + delete peFile; + return (PCHAR)apiInfo->name; + } +#ifdef DEBUG_COMMENTS + else + DoOutputDebugString("ScyllaGetExportNameByAddress: Failed to locate function among module exports.\n"); +#endif + + delete peFile; + return NULL; +} diff --git a/CAPE/wow64ext/internal.h b/CAPE/w64wow64/internal.h similarity index 97% rename from CAPE/wow64ext/internal.h rename to CAPE/w64wow64/internal.h index e33cc3c..e09a8b3 100644 --- a/CAPE/wow64ext/internal.h +++ b/CAPE/w64wow64/internal.h @@ -62,10 +62,12 @@ #define X64_Push(r) EMIT(0x48 | ((r) >> 3)) EMIT(0x50 | ((r) & 7)) #define X64_Pop(r) EMIT(0x48 | ((r) >> 3)) EMIT(0x58 | ((r) & 7)) +#define REX_W EMIT(0x48) __asm + //to fool M$ inline asm compiler I'm using 2 DWORDs instead of DWORD64 //use of DWORD64 will generate wrong 'pop word ptr[]' and it will break stack union reg64 { - DWORD dw[2]; - DWORD64 v; + DWORD64 v; + DWORD dw[2]; }; diff --git a/CAPE/w64wow64/w64wow64.c b/CAPE/w64wow64/w64wow64.c new file mode 100644 index 0000000..9140519 --- /dev/null +++ b/CAPE/w64wow64/w64wow64.c @@ -0,0 +1,469 @@ +#ifndef _WIN64 +/* +W64oWoW64 +Copyright (C) 2012 George Nicolaou + +This file is part of W64oWoW64. + +W64oWoW64 is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +W64oWoW64 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with W64oWoW64. If not, see . +*/ +#include +#include "internal.h" +#include "w64wow64.h" +#include "w64wow64defs.h" +#include "windef.h" + +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); + +FUNCTIONPTRS sFunctions = { 0 }; + +/** +* +* X64Call Part of WOW64Ext Library +* See internals.h +*/ +extern unsigned __int64 X64Call(DWORD64 func, int argC, ...) +{ + va_list args; + va_start(args, argC); + union reg64 _rcx = { (argC > 0) ? argC--, va_arg(args, DWORD64) : 0 }; + union reg64 _rdx = { (argC > 0) ? argC--, va_arg(args, DWORD64) : 0 }; + union reg64 _r8 = { (argC > 0) ? argC--, va_arg(args, DWORD64) : 0 }; + union reg64 _r9 = { (argC > 0) ? argC--, va_arg(args, DWORD64) : 0 }; + union reg64 _rax = { 0 }; + + union reg64 restArgs = { (DWORD64)&va_arg(args, DWORD64) }; + + // conversion to QWORD for easier use in inline assembly + union reg64 _argC = { (DWORD64)argC }; + DWORD back_esp = 0; + WORD back_fs = 0; + + __asm + { + ;// reset FS segment, to properly handle RFG + mov back_fs, fs + mov eax, 0x2B + mov fs, ax + + ;// keep original esp in back_esp variable + mov back_esp, esp + + ;// align esp to 0x10, without aligned stack some syscalls may return errors ! + ;// (actually, for syscalls it is sufficient to align to 8, but SSE opcodes + ;// requires 0x10 alignment), it will be further adjusted according to the + ;// number of arguments above 4 + and esp, 0xFFFFFFF0 + + X64_Start(); + + ;// below code is compiled as x86 inline asm, but it is executed as x64 code + ;// that's why it need sometimes REX_W() macro, right column contains detailed + ;// transcription how it will be interpreted by CPU + + ;// fill first four arguments + REX_W mov ecx, _rcx.dw[0] ;// mov rcx, qword ptr [_rcx] + REX_W mov edx, _rdx.dw[0] ;// mov rdx, qword ptr [_rdx] + push _r8.v ;// push qword ptr [_r8] + X64_Pop(_R8); ;// pop r8 + push _r9.v ;// push qword ptr [_r9] + X64_Pop(_R9); ;// pop r9 + ;// + REX_W mov eax, _argC.dw[0] ;// mov rax, qword ptr [_argC] + ;// + ;// final stack adjustment, according to the ;// + ;// number of arguments above 4 ;// + test al, 1 ;// test al, 1 + jnz _no_adjust ;// jnz _no_adjust + sub esp, 8 ;// sub rsp, 8 +_no_adjust: ;// + ;// + push edi ;// push rdi + REX_W mov edi, restArgs.dw[0] ;// mov rdi, qword ptr [restArgs] + ;// + ;// put rest of arguments on the stack ;// + REX_W test eax, eax ;// test rax, rax + jz _ls_e ;// je _ls_e + REX_W lea edi, dword ptr [edi + 8*eax - 8] ;// lea rdi, [rdi + rax*8 - 8] + ;// +_ls: ;// + REX_W test eax, eax ;// test rax, rax + jz _ls_e ;// je _ls_e + push dword ptr [edi] ;// push qword ptr [rdi] + REX_W sub edi, 8 ;// sub rdi, 8 + REX_W sub eax, 1 ;// sub rax, 1 + jmp _ls ;// jmp _ls +_ls_e: ;// + ;// + ;// create stack space for spilling registers ;// + REX_W sub esp, 0x20 ;// sub rsp, 20h + ;// + call func ;// call qword ptr [func] + ;// + ;// cleanup stack ;// + REX_W mov ecx, _argC.dw[0] ;// mov rcx, qword ptr [_argC] + REX_W lea esp, dword ptr [esp + 8*ecx + 0x20] ;// lea rsp, [rsp + rcx*8 + 20h] + ;// + pop edi ;// pop rdi + ;// + // set return value ;// + REX_W mov _rax.dw[0], eax ;// mov qword ptr [_rax], rax + + X64_End(); + + mov ax, ds + mov ss, ax + mov esp, back_esp + + ;// restore FS segment + mov ax, back_fs + mov fs, ax + } + return _rax.v; +} +#pragma warning(pop) + +PTEB64 NtTeb64( void ) +{ + X64_Start(); + GETTEB(); + X64_End(); +} + +PLDR_DATA_TABLE_ENTRY64 GetModule64LdrTable( wchar_t * lwcModuleName ) +{ + PTEB64 psTeb = NtTeb64(); + //PPEB64 psPeb = + PPEB_LDR_DATA Ldr = psTeb->ProcessEnvironmentBlock->Ldr; + PLDR_DATA_TABLE_ENTRY64 psDataEntryStart = + (PLDR_DATA_TABLE_ENTRY64)Ldr->InLoadOrderModuleList.Flink; + PLDR_DATA_TABLE_ENTRY64 psDataEntryCurrent = psDataEntryStart; + + do { + if( memcmp( (DWORD64)psDataEntryCurrent->BaseDllName.Buffer, lwcModuleName, + psDataEntryCurrent->BaseDllName.Length ) == 0 ) { + return psDataEntryCurrent; + } + psDataEntryCurrent = + (PLDR_DATA_TABLE_ENTRY64)psDataEntryCurrent->InLoadOrderLinks.Flink; + } while( psDataEntryStart != psDataEntryCurrent && psDataEntryCurrent ); + return NULL; +} + +extern void __cdecl SetLastErrorFromX64Call(DWORD64 status) +{ + typedef ULONG (WINAPI *RtlNtStatusToDosError_t)(NTSTATUS Status); + typedef ULONG (WINAPI *RtlSetLastWin32Error_t)(NTSTATUS Status); + + static RtlNtStatusToDosError_t RtlNtStatusToDosError = NULL; + static RtlSetLastWin32Error_t RtlSetLastWin32Error = NULL; + + if ((NULL == RtlNtStatusToDosError) || (NULL == RtlSetLastWin32Error)) + { + HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); + RtlNtStatusToDosError = (RtlNtStatusToDosError_t)GetProcAddress(ntdll, "RtlNtStatusToDosError"); + RtlSetLastWin32Error = (RtlSetLastWin32Error_t)GetProcAddress(ntdll, "RtlSetLastWin32Error"); + } + + if ((NULL != RtlNtStatusToDosError) && (NULL != RtlSetLastWin32Error)) + { + RtlSetLastWin32Error(RtlNtStatusToDosError((DWORD)status)); + } +} + +extern SIZE_T VirtualQueryEx64(HANDLE hProcess, DWORD64 lpAddress, MEMORY_BASIC_INFORMATION64* lpBuffer, SIZE_T dwLength) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD ntqvm = 0; + if (0 == ntqvm) + { + ntqvm = (DWORD)GetProcAddress64(lvpNtdll, "NtQueryVirtualMemory"); + if (0 == ntqvm) + return 0; + } + DWORD64 ret = 0; + X64Call(ntqvm, 6, (DWORD64)hProcess, lpAddress, (DWORD64)0, (DWORD64)lpBuffer, (DWORD64)dwLength, (DWORD64)&ret); + return (SIZE_T)ret; +} + +#pragma warning(push) +#pragma warning(disable : 4244) +extern DWORD64 VirtualAllocEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD64 ntavm = 0; + if (0 == ntavm) + { + ntavm = GetProcAddress64(lvpNtdll, "NtAllocateVirtualMemory"); + if (0 == ntavm) + return 0; + } + + DWORD64 tmpAddr = lpAddress; + DWORD64 tmpSize = dwSize; + DWORD64 ret = X64Call(ntavm, 6, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)0, (DWORD64)&tmpSize, (DWORD64)flAllocationType, (DWORD64)flProtect); + if (STATUS_SUCCESS != ret) + { + SetLastErrorFromX64Call(ret); + return FALSE; + } + else + return tmpAddr; +} + +extern BOOL VirtualFreeEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD dwFreeType) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD64 ntfvm = 0; + if (0 == ntfvm) + { + ntfvm = GetProcAddress64(lvpNtdll, "NtFreeVirtualMemory"); + if (0 == ntfvm) + return 0; + } + + DWORD64 tmpAddr = lpAddress; + DWORD64 tmpSize = dwSize; + DWORD64 ret = X64Call(ntfvm, 4, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)&tmpSize, (DWORD64)dwFreeType); + if (STATUS_SUCCESS != ret) + { + SetLastErrorFromX64Call(ret); + return FALSE; + } + else + return TRUE; +} + +extern BOOL VirtualProtectEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flNewProtect, DWORD* lpflOldProtect) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD64 ntpvm = 0; + if (0 == ntpvm) + { + ntpvm = GetProcAddress64(lvpNtdll, "NtProtectVirtualMemory"); + if (0 == ntpvm) + return 0; + } + + DWORD64 tmpAddr = lpAddress; + DWORD64 tmpSize = dwSize; + DWORD64 ret = X64Call(ntpvm, 5, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)&tmpSize, (DWORD64)flNewProtect, (DWORD64)lpflOldProtect); + if (STATUS_SUCCESS != ret) + { + SetLastErrorFromX64Call(ret); + return FALSE; + } + else + return TRUE; +} +#pragma warning(pop) + +extern BOOL ReadProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD nrvm = 0; + if (0 == nrvm) + { + nrvm = (DWORD)GetProcAddress64(lvpNtdll, "NtReadVirtualMemory"); + if (0 == nrvm) + return 0; + } + DWORD64 ret = X64Call(nrvm, 5, (DWORD64)hProcess, lpBaseAddress, (DWORD64)lpBuffer, (DWORD64)nSize, (DWORD64)lpNumberOfBytesRead); + if (STATUS_SUCCESS != ret) + return FALSE; + else + return TRUE; +} + +extern BOOL WriteProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesWritten) +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + static DWORD nrvm = 0; + if (0 == nrvm) + { + nrvm = (DWORD)GetProcAddress64(lvpNtdll, "NtWriteVirtualMemory"); + if (0 == nrvm) + return 0; + } + DWORD64 ret = X64Call(nrvm, 5, (DWORD64)hProcess, lpBaseAddress, (DWORD64)lpBuffer, (DWORD64)nSize, (DWORD64)lpNumberOfBytesWritten); + if (STATUS_SUCCESS != ret) + return FALSE; + else + return TRUE; +} + +DWORD64 GetModuleBase64( wchar_t * lwcModuleName ) +{ + PLDR_DATA_TABLE_ENTRY64 LdrEntry = GetModule64LdrTable( lwcModuleName ); + return (DWORD64)LdrEntry->DllBase; +} + +PIMAGE_NT_HEADERS64 GetModule64NtHeader( DWORD64 lvpBaseAddress ) +{ + PIMAGE_DOS_HEADER psDosHeader = (PIMAGE_DOS_HEADER)lvpBaseAddress; + return (PIMAGE_NT_HEADERS64)( ((__int8 *)lvpBaseAddress) + + psDosHeader->e_lfanew ); +} + +DWORD64 GetModule64PEBaseAddress( DWORD64 lvpBaseAddress ) +{ + PIMAGE_NT_HEADERS64 psNtHeader = GetModule64NtHeader( lvpBaseAddress ); + return (DWORD64)psNtHeader->OptionalHeader.ImageBase; +} + +DWORD64 GetModule64EntryRVA( DWORD64 lvpBaseAddress ) +{ + PIMAGE_NT_HEADERS64 psNtHeader = GetModule64NtHeader( lvpBaseAddress ); + return (DWORD64)psNtHeader->OptionalHeader.AddressOfEntryPoint; +} + +extern DWORD64 GetProcAddress64( DWORD64 lvpBaseAddress, char * lpszProcName ) +{ + PIMAGE_NT_HEADERS64 psNtHeader = GetModule64NtHeader( lvpBaseAddress ); + char * lpcModBase = (char *)lvpBaseAddress; + PIMAGE_EXPORT_DIRECTORY psExportDir = (PIMAGE_EXPORT_DIRECTORY)( lpcModBase + + psNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress ); + + int nNumberOfNames = psExportDir->NumberOfNames; + unsigned long * lpulFunctions = + (unsigned long *)( lpcModBase + psExportDir->AddressOfFunctions ); + + unsigned long * lpulNames = + (unsigned long *)( lpcModBase + psExportDir->AddressOfNames ); + + unsigned short * lpusOrdinals = + (unsigned short *) ( lpcModBase + psExportDir->AddressOfNameOrdinals ); + + int i; + char * lpszFunctionName; + for( i = 0; i < nNumberOfNames; i++ ) { + lpszFunctionName = ((__int8 *)lpulNames[i]) + (int)lvpBaseAddress; + if( strcmp( lpszFunctionName, lpszProcName ) == 0 ) { + return ( (__int8 *)lvpBaseAddress ) + + lpulFunctions[ lpusOrdinals[i] ]; + } + } + return NULL; +} + +BOOL FreeKnownDllPage( wchar_t * lpwzKnownDllName ) +{ + DWORD64 hSection = 0; + DWORD64 lvpBaseAddress = 0; + DWORD64 lvpRealBaseAddress = 0; + DWORD64 stViewSize = 0; + DWORD64 stRegionSize = 0; + PTEB64 psTeb; + X64Call( sFunctions.LdrGetKnownDllSectionHandle, 3, + (DWORD64)lpwzKnownDllName, + (DWORD64)0, + (DWORD64)&hSection ); + + psTeb = NtTeb64(); + psTeb->NtTib.ArbitraryUserPointer = (DWORD64)lpwzKnownDllName; + + X64Call( sFunctions.NtMapViewOfSection, 10, + (DWORD64)hSection, + (DWORD64)-1, + (DWORD64)&lvpBaseAddress, + (DWORD64)0, + (DWORD64)0, + (DWORD64)0, + (DWORD64)&stViewSize, + (DWORD64)ViewUnmap, + (DWORD64)0, + (DWORD64)PAGE_READONLY ); + + lvpRealBaseAddress = + (DWORD64)GetModule64PEBaseAddress( (DWORD64)lvpBaseAddress ); + + X64Call( sFunctions.NtFreeVirtualMemory, 4, + (DWORD64)-1, + (DWORD64)&lvpRealBaseAddress, + (DWORD64)&stRegionSize, + (DWORD64)MEM_RELEASE ); + + X64Call( sFunctions.NtUnmapViewOfSection, 2, (DWORD64)-1, + (DWORD64)lvpBaseAddress ); + return TRUE; +} + +extern DWORD64 LoadLibrary64A( char * lpcLibraryName ) +{ + if( sFunctions.LoadLibraryA == NULL ) { + sFunctions.LoadLibraryA = + GetProcAddress64( GetModuleBase64( L"kernel32.dll" ), "LoadLibraryA" ); + } + return (DWORD64)X64Call( sFunctions.LoadLibraryA, 1, (DWORD64)lpcLibraryName ); +} + +extern BOOL InitializeW64oWoW64() +{ + DWORD64 lvpNtdll = GetModuleBase64( L"ntdll.dll" ); + UNICODE_STRING64 sUnicodeString; + __int8 * lvpKernelBaseBase; + __int8 * lvpKernel32Base; + PLDR_DATA_TABLE_ENTRY64 lpsKernel32Ldr; + PLDR_DATA_TABLE_ENTRY64 lpsKernelBaseLdr; + + sFunctions.LdrGetKnownDllSectionHandle = GetProcAddress64( lvpNtdll, + "LdrGetKnownDllSectionHandle" ); + sFunctions.NtFreeVirtualMemory = GetProcAddress64( lvpNtdll, + "NtFreeVirtualMemory" ); + sFunctions.NtMapViewOfSection = GetProcAddress64( lvpNtdll, + "NtMapViewOfSection" ); + sFunctions.NtUnmapViewOfSection = GetProcAddress64( lvpNtdll, + "NtUnmapViewOfSection" ); + + if( FreeKnownDllPage( L"kernel32.dll" ) == FALSE) return FALSE; + if( FreeKnownDllPage( L"user32.dll" ) == FALSE ) return FALSE; + + sUnicodeString.Length = 0x18; + sUnicodeString.MaximumLength = 0x1a; + sUnicodeString.Buffer = (DWORD64)L"kernel32.dll"; + if( X64Call( GetProcAddress64( lvpNtdll, "LdrLoadDll" ), 4, + (DWORD64)0, + (DWORD64)0, + (DWORD64)&sUnicodeString, + (DWORD64)&lvpKernel32Base ) != NULL ) { + DoOutputErrorString("Failed to load 64-bit kernel32.dll"); + return FALSE; + } + + lvpKernelBaseBase = (__int8 *)GetModuleBase64( L"KERNELBASE.dll"); + X64Call( ( lvpKernelBaseBase + (int)GetModule64EntryRVA( lvpKernelBaseBase ) ), + 3, + (DWORD64)lvpKernelBaseBase, + (DWORD64)DLL_PROCESS_ATTACH, + (DWORD64)0 ); + + X64Call( ( lvpKernel32Base + (int)GetModule64EntryRVA( lvpKernel32Base ) ), + 3, + (DWORD64)lvpKernel32Base, + (DWORD64)DLL_PROCESS_ATTACH, + (DWORD64)0 ); + + lpsKernel32Ldr = GetModule64LdrTable( L"kernel32.dll" ); + lpsKernel32Ldr->LoadCount = 0xffff; + lpsKernel32Ldr->Flags += LDRP_ENTRY_PROCESSED | LDRP_PROCESS_ATTACH_CALLED; + + lpsKernelBaseLdr = GetModule64LdrTable( L"KERNELBASE.dll" ); + lpsKernelBaseLdr->LoadCount = 0xffff; + lpsKernelBaseLdr->Flags += LDRP_ENTRY_PROCESSED | LDRP_PROCESS_ATTACH_CALLED; + + return TRUE; +} + +#endif \ No newline at end of file diff --git a/CAPE/w64wow64/w64wow64.h b/CAPE/w64wow64/w64wow64.h new file mode 100644 index 0000000..ffdbe37 --- /dev/null +++ b/CAPE/w64wow64/w64wow64.h @@ -0,0 +1,44 @@ +/* +W64oWoW64 +Copyright (C) 2012 George Nicolaou + +This file is part of W64oWoW64. + +W64oWoW64 is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +W64oWoW64 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with W64oWoW64. If not, see . +*/ +#pragma once + +#include + +#ifndef STATUS_SUCCESS +# define STATUS_SUCCESS 0 +#endif + +#ifndef __W64WOW64_H_ +#define __W64WOW64_H_ + +unsigned __int64 X64Call( DWORD64 lvpFunctionPtr, int nArgc, ... ); +void __cdecl SetLastErrorFromX64Call(DWORD64 status); +DWORD64 GetProcAddress64( DWORD64 lvpBaseAddress, char * lpszProcName ); +DWORD64 LoadLibrary64A( char * lpcLibraryName ); +DWORD64 GetModuleBase64( wchar_t * lwcModuleName ); + +DWORD64 VirtualAllocEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect); +BOOL VirtualFreeEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flNewProtect, DWORD* lpflOldProtect); +BOOL VirtualProtectEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flNewProtect, DWORD* lpflOldProtect); +BOOL ReadProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead); +BOOL WriteProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesWritten); + +extern BOOL InitializeW64oWoW64(void); +#endif \ No newline at end of file diff --git a/CAPE/w64wow64/w64wow64defs.h b/CAPE/w64wow64/w64wow64defs.h new file mode 100644 index 0000000..d5cd378 --- /dev/null +++ b/CAPE/w64wow64/w64wow64defs.h @@ -0,0 +1,34 @@ +/* +W64oWoW64 +Copyright (C) 2012 George Nicolaou + +This file is part of W64oWoW64. + +W64oWoW64 is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +W64oWoW64 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with W64oWoW64. If not, see . +*/ +#define GETTEB() \ +{ \ + EMIT(0x65) EMIT(0x48) EMIT(0x8b) EMIT(0x04) EMIT(0x25) EMIT(0x30) EMIT(0x00) EMIT(0x00) EMIT(0x00) \ +} + + +typedef struct { + void * LdrGetKnownDllSectionHandle; + void * NtMapViewOfSection; + void * NtFreeVirtualMemory; + void * NtUnmapViewOfSection; + void * LoadLibraryA; +} FUNCTIONPTRS; + +BOOL InitializeW64oWoW64( void ); \ No newline at end of file diff --git a/CAPE/w64wow64/windef.h b/CAPE/w64wow64/windef.h new file mode 100644 index 0000000..fd7b487 --- /dev/null +++ b/CAPE/w64wow64/windef.h @@ -0,0 +1,93 @@ +/* +W64oWoW64 +Copyright (C) 2012 George Nicolaou + +This file is part of W64oWoW64. + +W64oWoW64 is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +W64oWoW64 is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with W64oWoW64. If not, see . +*/ +#include + +typedef struct _CLIENT_ID64 +{ + DWORD64 UniqueProcess; + DWORD64 UniqueThread; +} CLIENT_ID64, *PCLIENT_ID64; + + +typedef struct _PEB_LDR_DATA +{ + ULONG Length; + UCHAR Initialized; + DWORD64 SsHandle; + LIST_ENTRY64 InLoadOrderModuleList; + LIST_ENTRY64 InMemoryOrderModuleList; + LIST_ENTRY64 InInitializationOrderModuleList; + DWORD64 EntryInProgress; +} PEB_LDR_DATA, *PPEB_LDR_DATA; + + +typedef struct _PEB64 +{ + UCHAR InheritedAddressSpace; + UCHAR ReadImageFileExecOptions; + UCHAR BeingDebugged; + UCHAR BitField; + ULONG ImageUsesLargePages: 1; + ULONG IsProtectedProcess: 1; + ULONG IsLegacyProcess: 1; + ULONG IsImageDynamicallyRelocated: 1; + ULONG SpareBits: 4; + DWORD64 Mutant; + DWORD64 ImageBaseAddress; + PPEB_LDR_DATA Ldr; +} PEB64, *PPEB64; + +typedef struct _LSA_UNICODE_STRING { + USHORT Length; + USHORT MaximumLength; + DWORD64 Buffer; +} UNICODE_STRING64, * PUNICODE_STRING64; + +typedef struct _TEB64 +{ + NT_TIB64 NtTib; + DWORD64 EnvironmentPointer; + CLIENT_ID64 ClientId; + DWORD64 ActiveRpcHandle; + DWORD64 ThreadLocalStoragePointer; + PPEB64 ProcessEnvironmentBlock; +} TEB64, *PTEB64; + +typedef struct _LDR_DATA_TABLE_ENTRY64 +{ + LIST_ENTRY64 InLoadOrderLinks; + LIST_ENTRY64 InMemoryOrderLinks; + LIST_ENTRY64 InInitializationOrderLinks; + DWORD64 DllBase; + DWORD64 EntryPoint; + ULONG SizeOfImage; + UNICODE_STRING64 FullDllName; + UNICODE_STRING64 BaseDllName; + ULONG Flags; + WORD LoadCount; +} LDR_DATA_TABLE_ENTRY54, *PLDR_DATA_TABLE_ENTRY64; + +#define LDRP_PROCESS_ATTACH_CALLED 0x000080000 +#define LDRP_ENTRY_PROCESSED 0x000004000 + +typedef enum _SECTION_INHERIT { + ViewShare = 1, + ViewUnmap = 2 +} SECTION_INHERIT, * PSECTION_INHERIT; \ No newline at end of file diff --git a/CAPE/wow64_fix.cpp b/CAPE/wow64_fix.c similarity index 89% rename from CAPE/wow64_fix.cpp rename to CAPE/wow64_fix.c index e8bc595..2e18aa1 100644 --- a/CAPE/wow64_fix.cpp +++ b/CAPE/wow64_fix.c @@ -16,8 +16,9 @@ You should have received a copy of the GNU General Public License along with this program.If not, see . */ #ifndef _WIN64 -#include "wow64ext\wow64ext.h" -// ReWolf's wow64ext library: https://github.com/rwfpl/rewolf-wow64ext +#include "w64wow64\w64wow64.h" +// Based upon ReWolf's wow64ext library: +// https://github.com/rwfpl/rewolf-wow64ext #define DR7_MASK_RWE0 0xFFFDFFFF // 11111111111111011111111111111111 #define DR7_MASK_RWE1 0xFFDFFFFF // 11111111110111111111111111111111 @@ -26,20 +27,20 @@ along with this program.If not, see . const int PAGE_SIZE = 0x1000; -extern "C" void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern "C" void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); BOOL WoW64HookInstalled; -LPVOID lpHookCode = nullptr; -LPVOID lpNewJumpLocation; +DWORD64 lpHookCode = (DWORD64)NULL; +DWORD64 lpNewJumpLocation; -DWORD pfnKiUserExceptionDispatcher; -DWORD pfnNtSetContextThread; -DWORD pfnWow64PrepareForException; +DWORD64 pfnKiUserExceptionDispatcher; +DWORD64 pfnNtSetContextThread; +DWORD64 pfnWow64PrepareForException; //************************************************************************************** -extern "C" BOOL WoW64PatchBreakpoint(unsigned int Register) +extern BOOL WoW64PatchBreakpoint(unsigned int Register) //************************************************************************************** { if (WoW64HookInstalled == FALSE) @@ -69,7 +70,7 @@ extern "C" BOOL WoW64PatchBreakpoint(unsigned int Register) } //************************************************************************************** -extern "C" BOOL WoW64UnpatchBreakpoint(unsigned int Register) +extern BOOL WoW64UnpatchBreakpoint(unsigned int Register) //************************************************************************************** { if (WoW64HookInstalled == FALSE) @@ -99,7 +100,7 @@ extern "C" BOOL WoW64UnpatchBreakpoint(unsigned int Register) } //************************************************************************************** -const LPVOID CreateHook(const DWORD_PTR pKiUserExceptionDispatcher, const DWORD_PTR pNtSetContextThread64, const DWORD_PTR pWow64PrepareForException) +const DWORD64 CreateHook(const DWORD_PTR pKiUserExceptionDispatcher, const DWORD_PTR pNtSetContextThread64, const DWORD_PTR pWow64PrepareForException) //************************************************************************************** // credit to Omega Red http://pastebin.ca/raw/475547 { @@ -130,7 +131,7 @@ const LPVOID CreateHook(const DWORD_PTR pKiUserExceptionDispatcher, const DWORD_ 0xC3 //ret 94 }; // 86 - lpHookCode = (LPVOID)VirtualAllocEx64((HANDLE) -1, NULL, PAGE_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + lpHookCode = VirtualAllocEx64((HANDLE) -1, (DWORD64)NULL, PAGE_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); //insert relative address of NtSetContextThread64 from instruction after call DWORD RelativeOffset = pNtSetContextThread64 - ((DWORD)lpHookCode + 56); @@ -144,7 +145,7 @@ const LPVOID CreateHook(const DWORD_PTR pKiUserExceptionDispatcher, const DWORD_ memcpy(&HookBytes[82], &ReturnAddress, sizeof(DWORD_PTR)); //(8 is address of third instruction) //copy it to newly created page - (void)memcpy(lpHookCode, (const void *)HookBytes, sizeof(HookBytes)); + memcpy((LPVOID)lpHookCode, (const void *)HookBytes, sizeof(HookBytes)); return lpHookCode; } @@ -159,7 +160,7 @@ const void EnableWow64Hook() 0xCC, 0xCC, 0xCC // }; DWORD pNew = (DWORD)lpNewJumpLocation; - DWORD pOrig = pfnKiUserExceptionDispatcher + 5; + DWORD pOrig = (DWORD)pfnKiUserExceptionDispatcher + 5; DWORD RelativeOffset = pNew - pOrig; memcpy(&trampolineBytes[1], (PVOID)&RelativeOffset, sizeof(DWORD_PTR)); @@ -180,7 +181,7 @@ const void EnableWow64Hook() } //************************************************************************************** -extern "C" BOOL WoW64fix(void) +extern BOOL WoW64fix(void) //************************************************************************************** { IsWow64Process(GetCurrentProcess(), &WoW64HookInstalled); @@ -190,9 +191,12 @@ extern "C" BOOL WoW64fix(void) return FALSE; } - DWORD ntdll64 = getNTDLL64(); - DWORD wow64dll = GetModuleHandle64(L"wow64.dll"); - DWORD pfnWow64PrepareForException = GetProcAddress64(wow64dll, "Wow64PrepareForException"); + //DWORD ntdll64 = getNTDLL64(); + //DWORD wow64dll = GetModuleHandle64(L"wow64.dll"); + + DWORD64 ntdll64 = GetModuleBase64(L"ntdll.dll"); + DWORD64 wow64dll = GetModuleBase64(L"wow64.dll"); + DWORD64 pfnWow64PrepareForException = GetProcAddress64(wow64dll, "Wow64PrepareForException"); pfnKiUserExceptionDispatcher = GetProcAddress64(ntdll64, "KiUserExceptionDispatcher"); pfnNtSetContextThread = GetProcAddress64(ntdll64, "NtSetContextThread"); diff --git a/CAPE/wow64ext/wow64ext.cpp b/CAPE/wow64ext/wow64ext.cpp deleted file mode 100644 index 89c6a46..0000000 --- a/CAPE/wow64ext/wow64ext.cpp +++ /dev/null @@ -1,338 +0,0 @@ -#ifndef _WIN64 -#/** - * - * WOW64Ext Library - * - * Copyright (c) 2012 ReWolf - * http://blog.rewolf.pl/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - */ - -#include -#include "internal.h" -#include "wow64ext.h" - -#pragma warning(push) -#pragma warning(disable : 4409) -extern "C" DWORD64 X64Call(DWORD func, int argC, ...) -{ - va_list args; - va_start(args, argC); - DWORD64 _rcx = (argC > 0) ? argC--, va_arg(args, DWORD64) : 0; - DWORD64 _rdx = (argC > 0) ? argC--, va_arg(args, DWORD64) : 0; - DWORD64 _r8 = (argC > 0) ? argC--, va_arg(args, DWORD64) : 0; - DWORD64 _r9 = (argC > 0) ? argC--, va_arg(args, DWORD64) : 0; - reg64 _rax; - _rax.v = 0; - - DWORD64 restArgs = (DWORD64)&va_arg(args, DWORD64); - - //conversion to QWORD for easier use in inline assembly - DWORD64 _argC = argC; - DWORD64 _func = func; - - DWORD back_esp = 0; - - __asm - { - ;//keep original esp in back_esp variable - mov back_esp, esp - - ;//align esp to 8, without aligned stack some syscalls may return errors ! - and esp, 0xFFFFFFF8 - - X64_Start(); - - ;//fill first four arguments - push _rcx - X64_Pop(_RCX); - push _rdx - X64_Pop(_RDX); - push _r8 - X64_Pop(_R8); - push _r9 - X64_Pop(_R9); - - push edi - - push restArgs - X64_Pop(_RDI); - - push _argC - X64_Pop(_RAX); - - ;//put rest of arguments on the stack - test eax, eax - jz _ls_e - lea edi, dword ptr [edi + 8*eax - 8] - - _ls: - test eax, eax - jz _ls_e - push dword ptr [edi] - sub edi, 8 - sub eax, 1 - jmp _ls - _ls_e: - - ;//create stack space for spilling registers - sub esp, 0x20 - - call _func - - ;//cleanup stack - push _argC - X64_Pop(_RCX); - lea esp, dword ptr [esp + 8*ecx + 0x20] - - pop edi - - //set return value - X64_Push(_RAX); - pop _rax.dw[0] - - X64_End(); - - mov esp, back_esp - } - return _rax.v; -} -#pragma warning(pop) - -TEB64* getTEB64() -{ - reg64 reg; - reg.v = 0; - X64_Start(); - //R12 register should always contain pointer to TEB64 in WoW64 processes - X64_Push(_R12); - //below pop will pop QWORD from stack, as we're in x64 mode now - __asm pop reg.dw[0] - X64_End(); - //upper 32 bits should be always 0 in WoW64 processes - if (reg.dw[1] != 0) - return 0; - return (TEB64*)reg.dw[0]; -} - -extern "C" DWORD GetModuleHandle64(wchar_t* lpModuleName) -{ - DWORD module = 0; - - TEB64* teb64 = getTEB64(); - PEB64* peb64 = (PEB64*)teb64->ProcessEnvironmentBlock; - PEB_LDR_DATA64* ldr = (PEB_LDR_DATA64*)peb64->Ldr; - - LDR_DATA_TABLE_ENTRY64* head = (LDR_DATA_TABLE_ENTRY64*)ldr->InLoadOrderModuleList.Flink; - do - { - if (memcmp((void*)head->BaseDllName.Buffer, lpModuleName, head->BaseDllName.Length) == 0) - module = (DWORD)head->DllBase; - head = (LDR_DATA_TABLE_ENTRY64*)head->InLoadOrderLinks.Flink; - } - while (head != (LDR_DATA_TABLE_ENTRY64*)&ldr->InLoadOrderModuleList); - return module; -} - -extern "C" DWORD getNTDLL64() -{ - static DWORD ntdll64 = 0; - if (0 != ntdll64) - return ntdll64; - - ntdll64 = GetModuleHandle64(L"ntdll.dll"); - return ntdll64; -} - -DWORD getLdrGetProcedureAddress() -{ - BYTE* modBase = (BYTE*)getNTDLL64(); - IMAGE_NT_HEADERS64* inh = (IMAGE_NT_HEADERS64*)(modBase + ((IMAGE_DOS_HEADER*)modBase)->e_lfanew); - IMAGE_DATA_DIRECTORY& idd = inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; - if (0 == idd.VirtualAddress) - return 0; - - IMAGE_EXPORT_DIRECTORY* ied = (IMAGE_EXPORT_DIRECTORY*)(modBase + idd.VirtualAddress); - - DWORD* rvaTable = (DWORD*)(modBase + ied->AddressOfFunctions); - WORD* ordTable = (WORD*)(modBase + ied->AddressOfNameOrdinals); - DWORD* nameTable = (DWORD*)(modBase + ied->AddressOfNames); - //lazy search, there is no need to use binsearch for just one function - for (DWORD i = 0; i < ied->NumberOfFunctions; i++) - { - if (strcmp((char*)modBase + nameTable[i], "LdrGetProcedureAddress")) - continue; - else - return (DWORD)(modBase + rvaTable[ordTable[i]]); - } - return 0; -} - -extern "C" __declspec(dllexport) VOID __cdecl SetLastErrorFromX64Call(DWORD64 status) -{ - typedef ULONG (WINAPI *RtlNtStatusToDosError_t)(NTSTATUS Status); - typedef ULONG (WINAPI *RtlSetLastWin32Error_t)(NTSTATUS Status); - - static RtlNtStatusToDosError_t RtlNtStatusToDosError = nullptr; - static RtlSetLastWin32Error_t RtlSetLastWin32Error = nullptr; - - if ((nullptr == RtlNtStatusToDosError) || (nullptr == RtlSetLastWin32Error)) - { - HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); - RtlNtStatusToDosError = (RtlNtStatusToDosError_t)GetProcAddress(ntdll, "RtlNtStatusToDosError"); - RtlSetLastWin32Error = (RtlSetLastWin32Error_t)GetProcAddress(ntdll, "RtlSetLastWin32Error"); - } - - if ((nullptr != RtlNtStatusToDosError) && (nullptr != RtlSetLastWin32Error)) - { - RtlSetLastWin32Error(RtlNtStatusToDosError((DWORD)status)); - } -} - -extern "C" DWORD GetProcAddress64(DWORD hModule, char* funcName) -{ - static DWORD _LdrGetProcedureAddress = 0; - if (0 == _LdrGetProcedureAddress) - { - _LdrGetProcedureAddress = getLdrGetProcedureAddress(); - if (0 == _LdrGetProcedureAddress) - return 0; - } - - _UNICODE_STRING_T fName = { 0 }; - fName.Buffer = (DWORD64)funcName; - fName.Length = (WORD)strlen(funcName); - fName.MaximumLength = fName.Length + 1; - DWORD64 funcRet = 0; - X64Call(_LdrGetProcedureAddress, 4, (DWORD64)hModule, (DWORD64)&fName, (DWORD64)0, (DWORD64)&funcRet); - return (DWORD)funcRet; -} - -extern "C" SIZE_T VirtualQueryEx64(HANDLE hProcess, DWORD64 lpAddress, MEMORY_BASIC_INFORMATION64* lpBuffer, SIZE_T dwLength) -{ - static DWORD ntqvm = 0; - if (0 == ntqvm) - { - ntqvm = (DWORD)GetProcAddress64(getNTDLL64(), "NtQueryVirtualMemory"); - if (0 == ntqvm) - return 0; - } - DWORD64 ret = 0; - X64Call(ntqvm, 6, (DWORD64)hProcess, lpAddress, (DWORD64)0, (DWORD64)lpBuffer, (DWORD64)dwLength, (DWORD64)&ret); - return (SIZE_T)ret; -} - -#pragma warning(push) -#pragma warning(disable : 4244) -extern "C" DWORD64 VirtualAllocEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) -{ - static DWORD64 ntavm = 0; - if (0 == ntavm) - { - ntavm = GetProcAddress64(getNTDLL64(), "NtAllocateVirtualMemory"); - if (0 == ntavm) - return 0; - } - - DWORD64 tmpAddr = lpAddress; - DWORD64 tmpSize = dwSize; - DWORD64 ret = X64Call(ntavm, 6, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)0, (DWORD64)&tmpSize, (DWORD64)flAllocationType, (DWORD64)flProtect); - if (STATUS_SUCCESS != ret) - { - SetLastErrorFromX64Call(ret); - return FALSE; - } - else - return tmpAddr; -} - -extern "C" BOOL VirtualFreeEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD dwFreeType) -{ - static DWORD64 ntfvm = 0; - if (0 == ntfvm) - { - ntfvm = GetProcAddress64(getNTDLL64(), "NtFreeVirtualMemory"); - if (0 == ntfvm) - return 0; - } - - DWORD64 tmpAddr = lpAddress; - DWORD64 tmpSize = dwSize; - DWORD64 ret = X64Call(ntfvm, 4, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)&tmpSize, (DWORD64)dwFreeType); - if (STATUS_SUCCESS != ret) - { - SetLastErrorFromX64Call(ret); - return FALSE; - } - else - return TRUE; -} - -extern "C" BOOL VirtualProtectEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flNewProtect, DWORD* lpflOldProtect) -{ - static DWORD64 ntpvm = 0; - if (0 == ntpvm) - { - ntpvm = GetProcAddress64(getNTDLL64(), "NtProtectVirtualMemory"); - if (0 == ntpvm) - return 0; - } - - DWORD64 tmpAddr = lpAddress; - DWORD64 tmpSize = dwSize; - DWORD64 ret = X64Call(ntpvm, 5, (DWORD64)hProcess, (DWORD64)&tmpAddr, (DWORD64)&tmpSize, (DWORD64)flNewProtect, (DWORD64)lpflOldProtect); - if (STATUS_SUCCESS != ret) - { - SetLastErrorFromX64Call(ret); - return FALSE; - } - else - return TRUE; -} -#pragma warning(pop) - -extern "C" BOOL ReadProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead) -{ - static DWORD nrvm = 0; - if (0 == nrvm) - { - nrvm = (DWORD)GetProcAddress64(getNTDLL64(), "NtReadVirtualMemory"); - if (0 == nrvm) - return 0; - } - DWORD64 ret = X64Call(nrvm, 5, (DWORD64)hProcess, lpBaseAddress, (DWORD64)lpBuffer, (DWORD64)nSize, (DWORD64)lpNumberOfBytesRead); - if (STATUS_SUCCESS != ret) - return FALSE; - else - return TRUE; -} - -extern "C" BOOL WriteProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesWritten) -{ - static DWORD nrvm = 0; - if (0 == nrvm) - { - nrvm = (DWORD)GetProcAddress64(getNTDLL64(), "NtWriteVirtualMemory"); - if (0 == nrvm) - return 0; - } - DWORD64 ret = X64Call(nrvm, 5, (DWORD64)hProcess, lpBaseAddress, (DWORD64)lpBuffer, (DWORD64)nSize, (DWORD64)lpNumberOfBytesWritten); - if (STATUS_SUCCESS != ret) - return FALSE; - else - return TRUE; -} -#endif \ No newline at end of file diff --git a/CAPE/wow64ext/wow64ext.h b/CAPE/wow64ext/wow64ext.h deleted file mode 100644 index 309645d..0000000 --- a/CAPE/wow64ext/wow64ext.h +++ /dev/null @@ -1,348 +0,0 @@ -/** - * - * WOW64Ext Library - * - * Copyright (c) 2012 ReWolf - * http://blog.rewolf.pl/ - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include - -#ifndef STATUS_SUCCESS -# define STATUS_SUCCESS 0 -#endif - -#pragma pack(push) -#pragma pack(1) -template -struct _LIST_ENTRY_T -{ - T Flink; - T Blink; -}; - -template -struct _UNICODE_STRING_T -{ - union - { - struct - { - WORD Length; - WORD MaximumLength; - }; - T dummy; - }; - T Buffer; -}; - -template -struct _NT_TIB_T -{ - T ExceptionList; - T StackBase; - T StackLimit; - T SubSystemTib; - T FiberData; - T ArbitraryUserPointer; - T Self; -}; - -template -struct _CLIENT_ID -{ - T UniqueProcess; - T UniqueThread; -}; - -template -struct _TEB_T_ -{ - _NT_TIB_T NtTib; - T EnvironmentPointer; - _CLIENT_ID ClientId; - T ActiveRpcHandle; - T ThreadLocalStoragePointer; - T ProcessEnvironmentBlock; - DWORD LastErrorValue; - DWORD CountOfOwnedCriticalSections; - T CsrClientThread; - T Win32ThreadInfo; - DWORD User32Reserved[26]; - //rest of the structure is not defined for now, as it is not needed -}; - -template -struct _LDR_DATA_TABLE_ENTRY_T -{ - _LIST_ENTRY_T InLoadOrderLinks; - _LIST_ENTRY_T InMemoryOrderLinks; - _LIST_ENTRY_T InInitializationOrderLinks; - T DllBase; - T EntryPoint; - union - { - DWORD SizeOfImage; - T dummy01; - }; - _UNICODE_STRING_T FullDllName; - _UNICODE_STRING_T BaseDllName; - DWORD Flags; - WORD LoadCount; - WORD TlsIndex; - union - { - _LIST_ENTRY_T HashLinks; - struct - { - T SectionPointer; - T CheckSum; - }; - }; - union - { - T LoadedImports; - DWORD TimeDateStamp; - }; - T EntryPointActivationContext; - T PatchInformation; - _LIST_ENTRY_T ForwarderLinks; - _LIST_ENTRY_T ServiceTagLinks; - _LIST_ENTRY_T StaticLinks; - T ContextInformation; - T OriginalBase; - _LARGE_INTEGER LoadTime; -}; - -template -struct _PEB_LDR_DATA_T -{ - DWORD Length; - DWORD Initialized; - T SsHandle; - _LIST_ENTRY_T InLoadOrderModuleList; - _LIST_ENTRY_T InMemoryOrderModuleList; - _LIST_ENTRY_T InInitializationOrderModuleList; - T EntryInProgress; - DWORD ShutdownInProgress; - T ShutdownThreadId; - -}; - -template -struct _PEB_T -{ - union - { - struct - { - BYTE InheritedAddressSpace; - BYTE ReadImageFileExecOptions; - BYTE BeingDebugged; - BYTE BitField; - }; - T dummy01; - }; - T Mutant; - T ImageBaseAddress; - T Ldr; - T ProcessParameters; - T SubSystemData; - T ProcessHeap; - T FastPebLock; - T AtlThunkSListPtr; - T IFEOKey; - T CrossProcessFlags; - T UserSharedInfoPtr; - DWORD SystemReserved; - DWORD AtlThunkSListPtr32; - T ApiSetMap; - T TlsExpansionCounter; - T TlsBitmap; - DWORD TlsBitmapBits[2]; - T ReadOnlySharedMemoryBase; - T HotpatchInformation; - T ReadOnlyStaticServerData; - T AnsiCodePageData; - T OemCodePageData; - T UnicodeCaseTableData; - DWORD NumberOfProcessors; - union - { - DWORD NtGlobalFlag; - NGF dummy02; - }; - LARGE_INTEGER CriticalSectionTimeout; - T HeapSegmentReserve; - T HeapSegmentCommit; - T HeapDeCommitTotalFreeThreshold; - T HeapDeCommitFreeBlockThreshold; - DWORD NumberOfHeaps; - DWORD MaximumNumberOfHeaps; - T ProcessHeaps; - T GdiSharedHandleTable; - T ProcessStarterHelper; - T GdiDCAttributeList; - T LoaderLock; - DWORD OSMajorVersion; - DWORD OSMinorVersion; - WORD OSBuildNumber; - WORD OSCSDVersion; - DWORD OSPlatformId; - DWORD ImageSubsystem; - DWORD ImageSubsystemMajorVersion; - T ImageSubsystemMinorVersion; - T ActiveProcessAffinityMask; - T GdiHandleBuffer[A]; - T PostProcessInitRoutine; - T TlsExpansionBitmap; - DWORD TlsExpansionBitmapBits[32]; - T SessionId; - ULARGE_INTEGER AppCompatFlags; - ULARGE_INTEGER AppCompatFlagsUser; - T pShimData; - T AppCompatInfo; - _UNICODE_STRING_T CSDVersion; - T ActivationContextData; - T ProcessAssemblyStorageMap; - T SystemDefaultActivationContextData; - T SystemAssemblyStorageMap; - T MinimumStackCommit; - T FlsCallback; - _LIST_ENTRY_T FlsListHead; - T FlsBitmap; - DWORD FlsBitmapBits[4]; - T FlsHighIndex; - T WerRegistrationData; - T WerShipAssertPtr; - T pContextData; - T pImageHeaderHash; - T TracingFlags; -}; - -typedef _LDR_DATA_TABLE_ENTRY_T LDR_DATA_TABLE_ENTRY32; -typedef _LDR_DATA_TABLE_ENTRY_T LDR_DATA_TABLE_ENTRY64; - -typedef _TEB_T_ TEB32; -typedef _TEB_T_ TEB64; - -typedef _PEB_LDR_DATA_T PEB_LDR_DATA32; -typedef _PEB_LDR_DATA_T PEB_LDR_DATA64; - -typedef _PEB_T PEB32; -typedef _PEB_T PEB64; - -#pragma pack(pop) - -#ifdef WOW64EXT_EXPORTS -# define SPEC dllexport -#else -# define SPEC dllimport -#endif - -extern "C" -{ - DWORD64 X64Call(DWORD func, int argC, ...); - DWORD GetModuleHandle64(wchar_t* lpModuleName); - DWORD getNTDLL64(); - DWORD GetProcAddress64(DWORD hModule, char* funcName); - SIZE_T VirtualQueryEx64(HANDLE hProcess, DWORD64 lpAddress, MEMORY_BASIC_INFORMATION64* lpBuffer, SIZE_T dwLength); - DWORD64 VirtualAllocEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect); - BOOL VirtualFreeEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD dwFreeType); - - BOOL VirtualProtectEx64(HANDLE hProcess, DWORD64 lpAddress, SIZE_T dwSize, DWORD flNewProtect, DWORD* lpflOldProtect); - BOOL ReadProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead); - BOOL WriteProcessMemory64(HANDLE hProcess, DWORD64 lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesWritten); -} - - typedef struct DECLSPEC_ALIGN(16) _CONTEXT64 { - - // WinNT.h - // - // Register parameter home addresses. - // - // N.B. These fields are for convience - they could be used to extend the - // context record in the future. - // - - DWORD64 P1Home; - DWORD64 P2Home; - DWORD64 P3Home; - DWORD64 P4Home; - DWORD64 P5Home; - DWORD64 P6Home; - - // - // Control flags. - // - - DWORD ContextFlags; - DWORD MxCsr; - - // - // Segment Registers and processor flags. - // - - WORD SegCs; - WORD SegDs; - WORD SegEs; - WORD SegFs; - WORD SegGs; - WORD SegSs; - DWORD EFlags; - - // - // Debug registers - // - - DWORD64 Dr0; - DWORD64 Dr1; - DWORD64 Dr2; - DWORD64 Dr3; - DWORD64 Dr6; - DWORD64 Dr7; - - // - // Integer registers. - // - - DWORD64 Rax; - DWORD64 Rcx; - DWORD64 Rdx; - DWORD64 Rbx; - DWORD64 Rsp; - DWORD64 Rbp; - DWORD64 Rsi; - DWORD64 Rdi; - DWORD64 R8; - DWORD64 R9; - DWORD64 R10; - DWORD64 R11; - DWORD64 R12; - DWORD64 R13; - DWORD64 R14; - DWORD64 R15; - - // - // Program counter. - // - - DWORD64 Rip; - - // [...] snip -} CONTEXT64, *PCONTEXT64; diff --git a/Makefile b/Makefile index 7d02acd..7a0001e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ MAKEFLAGS = -j8 CFLAGS = -Wall -std=c99 -s -O2 -Wno-strict-aliasing -static DLL = -shared -DIRS = -Idistorm3.2-package/include -Ibson +DIRS = -Idistorm/include -Ibson LIBS = -lws2_32 -lshlwapi OBJDIR = objects @@ -16,8 +16,8 @@ else CC = gcc endif -DISTORM3 = $(wildcard distorm3.2-package/src/*.c) -DISTORM3OBJ = $(DISTORM3:distorm3.2-package/src/%.c=$(OBJDIR)/distorm3.2/%.o) +DISTORM3 = $(wildcard distorm/src/*.c) +DISTORM3OBJ = $(DISTORM3:distorm/src/%.c=$(OBJDIR)/distorm3.2/%.o) CUCKOOSRC = $(wildcard *.c) CUCKOOOBJ = $(CUCKOOSRC:%.c=$(OBJDIR)/%.o) @@ -30,7 +30,7 @@ default: $(OBJDIR) cuckoomon.dll $(OBJDIR): mkdir $@ $@/bson $@/distorm3.2 -$(OBJDIR)/distorm3.2/%.o: distorm3.2-package/src/%.c +$(OBJDIR)/distorm3.2/%.o: distorm/src/%.c $(CC) $(CFLAGS) $(DIRS) -c $^ -o $@ $(OBJDIR)/bson/%.o: bson/%.c diff --git a/bson/bson.vcxproj b/bson/bson.vcxproj index cae92ba..6182471 100644 --- a/bson/bson.vcxproj +++ b/bson/bson.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ StaticLibrary true - v140 + v141 MultiByte StaticLibrary true - v140 + v141 MultiByte StaticLibrary false - v140_xp + v141_xp MultiByte true StaticLibrary false - v140_xp + v141_xp MultiByte true diff --git a/cuckoomon.c b/cuckoomon.c index a4562b1..d58f4fa 100644 --- a/cuckoomon.c +++ b/cuckoomon.c @@ -107,7 +107,7 @@ static hook_t g_hooks[] = { HOOK_SPECIAL(ole32, CoCreateInstanceEx), HOOK_SPECIAL(ole32, CoGetClassObject), - HOOK_NOTAIL(ntdll, RtlDispatchException, 2), + HOOK_SPECIAL(ntdll, RtlDispatchException), HOOK_NOTAIL(ntdll, NtRaiseException, 3), // lowest variant of MoveFile() @@ -367,6 +367,7 @@ static hook_t g_hooks[] = { HOOK(ntdll, RtlCreateUserThread), HOOK(ntdll, NtSetInformationThread), HOOK(ntdll, NtQueryInformationThread), + HOOK(ntdll, NtYieldExecution), // // Misc Hooks @@ -376,7 +377,7 @@ static hook_t g_hooks[] = { #endif HOOK(msvcrt, memcpy), HOOK(msvcrt, srand), - + // for debugging only //HOOK(kernel32, GetLastError), @@ -430,6 +431,7 @@ static hook_t g_hooks[] = { HOOK(rasapi32, RasConnectionNotificationW), HOOK(kernel32, SystemTimeToTzSpecificLocalTime), HOOK(ole32, CLSIDFromProgID), + //HOOK(ole32, OleConvertOLESTREAMToIStorage), HOOK(kernel32, GlobalMemoryStatus), HOOK(kernel32, GlobalMemoryStatusEx), HOOK(user32, SystemParametersInfoA), @@ -700,6 +702,9 @@ VOID CALLBACK New_DllLoadNotification( if (!base_of_dll_of_interest) set_dll_of_interest((ULONG_PTR)NotificationData->Loaded.DllBase); DoOutputDebugString("Target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); +#ifdef CAPE_TRACE + SetInitialBreakpoints((PVOID)base_of_dll_of_interest); +#endif } else if (((!wcsnicmp(our_commandline, L"c:\\windows\\system32\\rundll32.exe", 32) || !wcsnicmp(our_commandline, L"c:\\windows\\syswow64\\rundll32.exe", 32) || @@ -711,6 +716,9 @@ VOID CALLBACK New_DllLoadNotification( wcsncpy(g_config.file_of_interest, library.Buffer, wcslen(library.Buffer)); } DoOutputDebugString("rundll32 target DLL loaded at 0x%p: %ws (0x%x bytes).\n", NotificationData->Loaded.DllBase, library.Buffer, NotificationData->Loaded.SizeOfImage); +#ifdef CAPE_TRACE + SetInitialBreakpoints((PVOID)base_of_dll_of_interest); +#endif } else { // unoptimized, but easy diff --git a/cuckoomon.vcxproj b/cuckoomon.vcxproj index be9152c..ce0186c 100644 --- a/cuckoomon.vcxproj +++ b/cuckoomon.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -21,34 +21,38 @@ {15C69A24-71D1-4A1A-B39B-0466181ACD7E} Win32Proj - 8.1 + 7.0 DynamicLibrary true - v140 + v141 MultiByte + false DynamicLibrary true - v140 + v141 MultiByte + false DynamicLibrary false - v140_xp + v141_xp MultiByte true + false DynamicLibrary false - v140_xp - MultiByte + v141_xp + NotSet true + false @@ -86,16 +90,17 @@ AllRules.ruleset false Injection_x64 + .dll $(VC_IncludePath);$(WindowsSdk_71A_IncludePath);C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\WTL91\Include; - CUCKOODBG;WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS_DEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;%(PreprocessorDefinitions) + CUCKOODBG;WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS_DEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;%(PreprocessorDefinitions);_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS MultiThreadedDebug Level3 ProgramDatabase Disabled - .\bson;.\distorm3.2-package\include;%(AdditionalIncludeDirectories) + .\bson;.\distorm\include;%(AdditionalIncludeDirectories) Default @@ -114,12 +119,12 @@ - CUCKOODBG;WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS_DEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;%(PreprocessorDefinitions) + CUCKOODBG;WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS_DEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;%(PreprocessorDefinitions);_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS MultiThreadedDebug Level3 ProgramDatabase Disabled - .\bson;.\distorm3.2-package\include;%(AdditionalIncludeDirectories) + .\bson;.\distorm\include;%(AdditionalIncludeDirectories) Default @@ -137,11 +142,11 @@ - WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions) + WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions);_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS MultiThreaded Level3 ProgramDatabase - .\bson;.\distorm3.2-package\include;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WTL81\Include;%(AdditionalIncludeDirectories) + .\bson;.\distorm\include;C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WTL81\Include;%(AdditionalIncludeDirectories) true false NoExtensions @@ -168,11 +173,11 @@ - WIN32;_WIN64;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions) + WIN32;_WIN64;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGSNDEBUG;_WINDOWS;_USRDLL;MONGO_HAVE_STDINT;MONGO_STATIC_BUILD;CUCKOOMON_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;CAPE_INJECTION;%(PreprocessorDefinitions);_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS MultiThreaded Level3 ProgramDatabase - .\bson;.\distorm3.2-package\include;%(AdditionalIncludeDirectories) + .\bson;.\distorm\include;%(AdditionalIncludeDirectories) true false @@ -213,20 +218,19 @@ - - + + - - - - - - - - - - + + + + + + + + + @@ -414,25 +418,28 @@ + - - + + + + - - - - - - - - - - + + + + + + + + + + diff --git a/cuckoomon.vcxproj.filters b/cuckoomon.vcxproj.filters index cbb1656..d1b0e95 100644 --- a/cuckoomon.vcxproj.filters +++ b/cuckoomon.vcxproj.filters @@ -28,11 +28,11 @@ {dde7b0e5-0c75-442b-bbf4-24703756bd05} - - {a39cf6bf-3af9-42f9-971d-fcfbc3e0596d} + + {2870ff64-a1ae-437b-b93d-b815724102e4} - - {df6779d0-6bb8-40c0-ab5a-c233ea8726e9} + + {cf36b66e-1611-4be7-abe4-482a5fbacbe2} @@ -192,34 +192,31 @@ Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - - Source Files - - + Source Files @@ -249,12 +246,6 @@ Source Files\CAPE\Scylla - - Source Files\CAPE\wow64ext - - - Source Files\CAPE - Source Files\CAPE\Scylla @@ -276,6 +267,12 @@ Source Files\CAPE\Scylla + + Source Files\CAPE\w64wow64 + + + Source Files\CAPE + Source Files\CAPE @@ -326,34 +323,34 @@ Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files @@ -374,12 +371,6 @@ Header Files\CAPE\Scylla - - Header Files\CAPE\wow64ext - - - Header Files\CAPE\wow64ext - Header Files\CAPE\Scylla @@ -398,6 +389,9 @@ Header Files\CAPE\Scylla + + Header Files\CAPE\Scylla + Header Files\CAPE\Scylla @@ -407,5 +401,17 @@ Header Files\CAPE\Scylla + + Header Files\CAPE\w64wow64 + + + Header Files\CAPE\w64wow64 + + + Header Files\CAPE\w64wow64 + + + Header Files\CAPE\w64wow64 + \ No newline at end of file diff --git a/distorm/COPYING b/distorm/COPYING new file mode 100644 index 0000000..4f365dd --- /dev/null +++ b/distorm/COPYING @@ -0,0 +1,26 @@ +:[diStorm3}: +The ultimate disassembler library. +Copyright (c) 2003-2016, Gil Dabah +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Gil Dabah nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL GIL DABAH BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/distorm3.2-package/include/distorm.h b/distorm/include/distorm.h similarity index 89% rename from distorm3.2-package/include/distorm.h rename to distorm/include/distorm.h index 09db9d2..cce3314 100644 --- a/distorm3.2-package/include/distorm.h +++ b/distorm/include/distorm.h @@ -1,4 +1,4 @@ -/* diStorm3 3.2 */ +/* diStorm 3.3.3 */ /* distorm.h @@ -6,20 +6,8 @@ distorm.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -91,10 +79,10 @@ typedef unsigned __int8 uint8_t; /* * Operand Size or Adderss size are stored inside the flags: - * 0 - 16 bits - * 1 - 32 bits - * 2 - 64 bits - * 3 - reserved + * 00 - 16 bits + * 01 - 32 bits + * 10 - 64 bits + * 11 - reserved * * If you call these set-macros more than once, you will have to clean the bits before doing so. */ @@ -104,6 +92,8 @@ typedef unsigned __int8 uint8_t; #define FLAG_GET_ADDRSIZE(flags) (((flags) >> 10) & 3) /* To get the LOCK/REPNZ/REP prefixes. */ #define FLAG_GET_PREFIX(flags) ((flags) & 7) +/* Indicates whether the instruction is privileged. */ +#define FLAG_GET_PRIVILEGED(flags) (((flags) & FLAG_PRIVILEGED_INSTRUCTION) != 0) /* * Macros to extract segment registers from 'segment': @@ -179,7 +169,7 @@ typedef struct { */ uint8_t index; - /* Size of: + /* Size in bits of: O_REG: register O_IMM: instruction.imm O_IMM1: instruction.imm.ex.i1 @@ -206,29 +196,33 @@ typedef struct { #define FLAG_HINT_TAKEN (1 << 3) /* Indicates there is a hint non-taken for Jcc instructions only. */ #define FLAG_HINT_NOT_TAKEN (1 << 4) -/* The Imm value is signed extended. */ +/* The Imm value is signed extended (E.G in 64 bit decoding mode, a 32 bit imm is usually sign extended into 64 bit imm). */ #define FLAG_IMM_SIGNED (1 << 5) /* The destination operand is writable. */ #define FLAG_DST_WR (1 << 6) /* The instruction uses RIP-relative indirection. */ #define FLAG_RIP_RELATIVE (1 << 7) +/* See flag FLAG_GET_XXX macros above. */ + +/* The instruction is privileged and can only be used from Ring0. */ +#define FLAG_PRIVILEGED_INSTRUCTION (1 << 15) + /* No register was defined. */ #define R_NONE ((uint8_t)-1) -#define REGS64_BASE (0) -#define REGS32_BASE (16) -#define REGS16_BASE (32) -#define REGS8_BASE (48) -#define REGS8_REX_BASE (64) -#define SREGS_BASE (68) -/* #define RIP 74 */ -#define FPUREGS_BASE (75) -#define MMXREGS_BASE (83) -#define SSEREGS_BASE (91) -#define AVXREGS_BASE (107) -#define CREGS_BASE (123) -#define DREGS_BASE (132) +#define REGS64_BASE 0 +#define REGS32_BASE 16 +#define REGS16_BASE 32 +#define REGS8_BASE 48 +#define REGS8_REX_BASE 64 +#define SREGS_BASE 68 +#define FPUREGS_BASE 75 +#define MMXREGS_BASE 83 +#define SSEREGS_BASE 91 +#define AVXREGS_BASE 107 +#define CREGS_BASE 123 +#define DREGS_BASE 132 #define OPERANDS_NO (4) @@ -244,12 +238,12 @@ typedef struct { /* Unused prefixes mask, for each bit that is set that prefix is not used (LSB is byte [addr + 0]). */ uint16_t unusedPrefixesMask; /* Mask of registers that were used in the operands, only used for quick look up, in order to know *some* operand uses that register class. */ - uint16_t usedRegistersMask; + uint32_t usedRegistersMask; /* ID of opcode in the global opcode table. Use for mnemonic look up. */ uint16_t opcode; /* Up to four operands per instruction, ignored if ops[n].type == O_NONE. */ _Operand ops[OPERANDS_NO]; - /* Size of the whole instruction. */ + /* Size of the whole instruction in bytes. */ uint8_t size; /* Segment information of memory indirection, default segment, or overriden one, can be -1. Use SEGMENT macros. */ uint8_t segment; @@ -258,6 +252,8 @@ typedef struct { uint8_t dispSize; /* Meta defines the instruction set class, and the flow control flags. Use META macros. */ uint8_t meta; + /* The CPU flags that the instruction operates upon. */ + uint16_t modifiedFlagsMask, testedFlagsMask, undefinedFlagsMask; uint8_t imm_encoded_size; } _DInst; @@ -280,7 +276,7 @@ typedef struct { _WString mnemonic; /* Mnemonic of decoded instruction, prefixed if required by REP, LOCK etc. */ _WString operands; /* Operands of the decoded instruction, up to 3 operands, comma-seperated. */ _WString instructionHex; /* Hex dump - little endian, including prefixes. */ - unsigned int size; /* Size of decoded instruction. */ + unsigned int size; /* Size of decoded instruction in bytes. */ _OffsetType offset; /* Start offset of the decoded instruction. */ } _DecodedInst; @@ -301,11 +297,30 @@ typedef struct { #define RM_AVX 0x800 /* YMM0 - YMM15 */ #define RM_CR 0x1000 /* CR0, CR2, CR3, CR4, CR8 */ #define RM_DR 0x2000 /* DR0, DR1, DR2, DR3, DR6, DR7 */ +#define RM_R8 0x4000 /* R8B, R8W, R8D, R8 */ +#define RM_R9 0x8000 /* R9B, R9W, R9D, R9 */ +#define RM_R10 0x10000 /* R10B, R10W, R10D, R10 */ +#define RM_R11 0x20000 /* R11B, R11W, R11D, R11 */ +#define RM_R12 0x40000 /* R12B, R12W, R12D, R12 */ +#define RM_R13 0x80000 /* R13B, R13W, R13D, R13 */ +#define RM_R14 0x100000 /* R14B, R14W, R14D, R14 */ +#define RM_R15 0x200000 /* R15B, R15W, R15D, R15 */ + /* RIP should be checked using the 'flags' field and FLAG_RIP_RELATIVE. * Segments should be checked using the segment macros. * For now R8 - R15 are not supported and non general purpose registers map into same RM. */ +/* CPU flags that instructions modify, test or undefine (are EFLAGS compatible!). */ +#define D_CF 1 /* Carry */ +#define D_PF 4 /* Parity */ +#define D_AF 0x10 /* Auxiliary */ +#define D_ZF 0x40 /* Zero */ +#define D_SF 0x80 /* Sign */ +#define D_IF 0x200 /* Interrupt */ +#define D_DF 0x400 /* Direction */ +#define D_OF 0x800 /* Overflow */ + /* * Instructions Set classes: * if you want a better understanding of the available classes, look at disOps project, file: x86sets.py. @@ -418,6 +433,11 @@ typedef enum { DECRES_NONE, DECRES_SUCCESS, DECRES_MEMORYERR, DECRES_INPUTERR, D * Notes: 1)The minimal size of maxInstructions is 15. * 2)You will have to synchronize the offset,code and length by yourself if you pass code fragments and not a complete code block! */ + +/* distorm_decompose + * See more documentation online at the GitHub project's wiki. + * + */ #ifdef SUPPORT_64BIT_OFFSET _DecodeResult distorm_decompose64(_CodeInfo* ci, _DInst result[], unsigned int maxInstructions, unsigned int* usedInstructionsCount); diff --git a/distorm/include/mnemonics.h b/distorm/include/mnemonics.h new file mode 100644 index 0000000..ef9889c --- /dev/null +++ b/distorm/include/mnemonics.h @@ -0,0 +1,301 @@ +/* +mnemonics.h + +diStorm3 - Powerful disassembler for X86/AMD64 +http://ragestorm.net/distorm/ +distorm at gmail dot com +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. +*/ + + +#ifndef MNEMONICS_H +#define MNEMONICS_H + +#ifdef __cplusplus + extern "C" { +#endif + +#ifndef DISTORM_LIGHT + +typedef struct WMnemonic { + unsigned char length; + unsigned char p[1]; /* p is a null terminated string, which contains 'length' characters. */ +} _WMnemonic; + +typedef struct WRegister { + unsigned int length; + unsigned char p[6]; /* p is a null terminated string. */ +} _WRegister; + +extern const unsigned char _MNEMONICS[]; +extern const _WRegister _REGISTERS[]; + +#endif /* DISTORM_LIGHT */ + +#ifdef __cplusplus +} /* End Of Extern */ +#endif + +#define GET_REGISTER_NAME(r) (unsigned char*)_REGISTERS[(r)].p +#define GET_MNEMONIC_NAME(m) ((_WMnemonic*)&_MNEMONICS[(m)])->p + + typedef enum { + I_UNDEFINED = 0, I_AAA = 66, I_AAD = 389, I_AAM = 384, I_AAS = 76, I_ADC = 31, I_ADD = 11, I_ADDPD = 3132, + I_ADDPS = 3125, I_ADDSD = 3146, I_ADDSS = 3139, I_ADDSUBPD = 6416, I_ADDSUBPS = 6426, + I_AESDEC = 9231, I_AESDECLAST = 9248, I_AESENC = 9189, I_AESENCLAST = 9206, + I_AESIMC = 9172, I_AESKEYGENASSIST = 9817, I_AND = 41, I_ANDNPD = 3043, I_ANDNPS = 3035, + I_ANDPD = 3012, I_ANDPS = 3005, I_ARPL = 111, I_BLENDPD = 9394, I_BLENDPS = 9375, + I_BLENDVPD = 7641, I_BLENDVPS = 7631, I_BOUND = 104, I_BSF = 4368, I_BSR = 4380, + I_BSWAP = 960, I_BT = 872, I_BTC = 934, I_BTR = 912, I_BTS = 887, I_CALL = 456, + I_CALL_FAR = 260, I_CBW = 228, I_CDQ = 250, I_CDQE = 239, I_CLC = 492, I_CLD = 512, + I_CLFLUSH = 4351, I_CLGI = 1855, I_CLI = 502, I_CLTS = 541, I_CMC = 487, I_CMOVA = 694, + I_CMOVAE = 663, I_CMOVB = 656, I_CMOVBE = 686, I_CMOVG = 754, I_CMOVGE = 738, + I_CMOVL = 731, I_CMOVLE = 746, I_CMOVNO = 648, I_CMOVNP = 723, I_CMOVNS = 708, + I_CMOVNZ = 678, I_CMOVO = 641, I_CMOVP = 716, I_CMOVS = 701, I_CMOVZ = 671, + I_CMP = 71, I_CMPEQPD = 4471, I_CMPEQPS = 4392, I_CMPEQSD = 4629, I_CMPEQSS = 4550, + I_CMPLEPD = 4489, I_CMPLEPS = 4410, I_CMPLESD = 4647, I_CMPLESS = 4568, I_CMPLTPD = 4480, + I_CMPLTPS = 4401, I_CMPLTSD = 4638, I_CMPLTSS = 4559, I_CMPNEQPD = 4510, I_CMPNEQPS = 4431, + I_CMPNEQSD = 4668, I_CMPNEQSS = 4589, I_CMPNLEPD = 4530, I_CMPNLEPS = 4451, + I_CMPNLESD = 4688, I_CMPNLESS = 4609, I_CMPNLTPD = 4520, I_CMPNLTPS = 4441, + I_CMPNLTSD = 4678, I_CMPNLTSS = 4599, I_CMPORDPD = 4540, I_CMPORDPS = 4461, + I_CMPORDSD = 4698, I_CMPORDSS = 4619, I_CMPS = 301, I_CMPUNORDPD = 4498, I_CMPUNORDPS = 4419, + I_CMPUNORDSD = 4656, I_CMPUNORDSS = 4577, I_CMPXCHG = 898, I_CMPXCHG16B = 6395, + I_CMPXCHG8B = 6384, I_COMISD = 2801, I_COMISS = 2793, I_CPUID = 865, I_CQO = 255, + I_CRC32 = 9280, I_CVTDQ2PD = 6809, I_CVTDQ2PS = 3329, I_CVTPD2DQ = 6819, I_CVTPD2PI = 2703, + I_CVTPD2PS = 3255, I_CVTPH2PS = 4183, I_CVTPI2PD = 2517, I_CVTPI2PS = 2507, + I_CVTPS2DQ = 3339, I_CVTPS2PD = 3245, I_CVTPS2PH = 4193, I_CVTPS2PI = 2693, + I_CVTSD2SI = 2723, I_CVTSD2SS = 3275, I_CVTSI2SD = 2537, I_CVTSI2SS = 2527, + I_CVTSS2SD = 3265, I_CVTSS2SI = 2713, I_CVTTPD2DQ = 6798, I_CVTTPD2PI = 2636, + I_CVTTPS2DQ = 3349, I_CVTTPS2PI = 2625, I_CVTTSD2SI = 2658, I_CVTTSS2SI = 2647, + I_CWD = 245, I_CWDE = 233, I_DAA = 46, I_DAS = 56, I_DEC = 86, I_DIV = 1646, + I_DIVPD = 3521, I_DIVPS = 3514, I_DIVSD = 3535, I_DIVSS = 3528, I_DPPD = 9637, + I_DPPS = 9624, I_EMMS = 4122, I_ENTER = 340, I_EXTRACTPS = 9502, I_EXTRQ = 4158, + I_F2XM1 = 1192, I_FABS = 1123, I_FADD = 1023, I_FADDP = 1549, I_FBLD = 1601, + I_FBSTP = 1607, I_FCHS = 1117, I_FCLEX = 7311, I_FCMOVB = 1376, I_FCMOVBE = 1392, + I_FCMOVE = 1384, I_FCMOVNB = 1445, I_FCMOVNBE = 1463, I_FCMOVNE = 1454, I_FCMOVNU = 1473, + I_FCMOVU = 1401, I_FCOM = 1035, I_FCOMI = 1512, I_FCOMIP = 1623, I_FCOMP = 1041, + I_FCOMPP = 1563, I_FCOS = 1311, I_FDECSTP = 1238, I_FDIV = 1061, I_FDIVP = 1594, + I_FDIVR = 1067, I_FDIVRP = 1586, I_FEDISI = 1488, I_FEMMS = 574, I_FENI = 1482, + I_FFREE = 1527, I_FIADD = 1317, I_FICOM = 1331, I_FICOMP = 1338, I_FIDIV = 1361, + I_FIDIVR = 1368, I_FILD = 1418, I_FIMUL = 1324, I_FINCSTP = 1247, I_FINIT = 7326, + I_FIST = 1432, I_FISTP = 1438, I_FISTTP = 1424, I_FISUB = 1346, I_FISUBR = 1353, + I_FLD = 1074, I_FLD1 = 1141, I_FLDCW = 1098, I_FLDENV = 1090, I_FLDL2E = 1155, + I_FLDL2T = 1147, I_FLDLG2 = 1170, I_FLDLN2 = 1178, I_FLDPI = 1163, I_FLDZ = 1186, + I_FMUL = 1029, I_FMULP = 1556, I_FNCLEX = 7303, I_FNINIT = 7318, I_FNOP = 1111, + I_FNSAVE = 7333, I_FNSTCW = 7288, I_FNSTENV = 7271, I_FNSTSW = 7348, I_FPATAN = 1213, + I_FPREM = 1256, I_FPREM1 = 1230, I_FPTAN = 1206, I_FRNDINT = 1288, I_FRSTOR = 1519, + I_FSAVE = 7341, I_FSCALE = 1297, I_FSETPM = 1496, I_FSIN = 1305, I_FSINCOS = 1279, + I_FSQRT = 1272, I_FST = 1079, I_FSTCW = 7296, I_FSTENV = 7280, I_FSTP = 1084, + I_FSTSW = 7356, I_FSUB = 1048, I_FSUBP = 1579, I_FSUBR = 1054, I_FSUBRP = 1571, + I_FTST = 1129, I_FUCOM = 1534, I_FUCOMI = 1504, I_FUCOMIP = 1614, I_FUCOMP = 1541, + I_FUCOMPP = 1409, I_FXAM = 1135, I_FXCH = 1105, I_FXRSTOR = 9914, I_FXRSTOR64 = 9923, + I_FXSAVE = 9886, I_FXSAVE64 = 9894, I_FXTRACT = 1221, I_FYL2X = 1199, I_FYL2XP1 = 1263, + I_GETSEC = 633, I_HADDPD = 4203, I_HADDPS = 4211, I_HLT = 482, I_HSUBPD = 4237, + I_HSUBPS = 4245, I_IDIV = 1651, I_IMUL = 117, I_IN = 447, I_INC = 81, I_INS = 123, + I_INSERTPS = 9569, I_INSERTQ = 4165, I_INT = 367, I_INT_3 = 360, I_INT1 = 476, + I_INTO = 372, I_INVD = 555, I_INVEPT = 8306, I_INVLPG = 1727, I_INVLPGA = 1869, + I_INVPCID = 8323, I_INVVPID = 8314, I_IRET = 378, I_JA = 166, I_JAE = 147, + I_JB = 143, I_JBE = 161, I_JCXZ = 427, I_JECXZ = 433, I_JG = 202, I_JGE = 192, + I_JL = 188, I_JLE = 197, I_JMP = 462, I_JMP_FAR = 467, I_JNO = 138, I_JNP = 183, + I_JNS = 174, I_JNZ = 156, I_JO = 134, I_JP = 179, I_JRCXZ = 440, I_JS = 170, + I_JZ = 152, I_LAHF = 289, I_LAR = 522, I_LDDQU = 7016, I_LDMXCSR = 9944, I_LDS = 335, + I_LEA = 223, I_LEAVE = 347, I_LES = 330, I_LFENCE = 4287, I_LFS = 917, I_LGDT = 1703, + I_LGS = 922, I_LIDT = 1709, I_LLDT = 1668, I_LMSW = 1721, I_LODS = 313, I_LOOP = 421, + I_LOOPNZ = 406, I_LOOPZ = 414, I_LSL = 527, I_LSS = 907, I_LTR = 1674, I_LZCNT = 4385, + I_MASKMOVDQU = 7141, I_MASKMOVQ = 7131, I_MAXPD = 3581, I_MAXPS = 3574, I_MAXSD = 3595, + I_MAXSS = 3588, I_MFENCE = 4313, I_MINPD = 3461, I_MINPS = 3454, I_MINSD = 3475, + I_MINSS = 3468, I_MONITOR = 1771, I_MOV = 218, I_MOVAPD = 2481, I_MOVAPS = 2473, + I_MOVBE = 9273, I_MOVD = 3942, I_MOVDDUP = 2208, I_MOVDQ2Q = 6544, I_MOVDQA = 3968, + I_MOVDQU = 3976, I_MOVHLPS = 2173, I_MOVHPD = 2367, I_MOVHPS = 2359, I_MOVLHPS = 2350, + I_MOVLPD = 2190, I_MOVLPS = 2182, I_MOVMSKPD = 2837, I_MOVMSKPS = 2827, I_MOVNTDQ = 6871, + I_MOVNTDQA = 7917, I_MOVNTI = 952, I_MOVNTPD = 2578, I_MOVNTPS = 2569, I_MOVNTQ = 6863, + I_MOVNTSD = 2596, I_MOVNTSS = 2587, I_MOVQ = 3948, I_MOVQ2DQ = 6535, I_MOVS = 295, + I_MOVSD = 2132, I_MOVSHDUP = 2375, I_MOVSLDUP = 2198, I_MOVSS = 2125, I_MOVSX = 939, + I_MOVSXD = 10027, I_MOVUPD = 2117, I_MOVUPS = 2109, I_MOVZX = 927, I_MPSADBW = 9650, + I_MUL = 1641, I_MULPD = 3192, I_MULPS = 3185, I_MULSD = 3206, I_MULSS = 3199, + I_MWAIT = 1780, I_NEG = 1636, I_NOP = 581, I_NOT = 1631, I_OR = 27, I_ORPD = 3075, + I_ORPS = 3069, I_OUT = 451, I_OUTS = 128, I_PABSB = 7710, I_PABSD = 7740, I_PABSW = 7725, + I_PACKSSDW = 3871, I_PACKSSWB = 3703, I_PACKUSDW = 7938, I_PACKUSWB = 3781, + I_PADDB = 7226, I_PADDD = 7256, I_PADDQ = 6503, I_PADDSB = 6952, I_PADDSW = 6969, + I_PADDUSB = 6642, I_PADDUSW = 6661, I_PADDW = 7241, I_PALIGNR = 9432, I_PAND = 6629, + I_PANDN = 6687, I_PAUSE = 10035, I_PAVGB = 6702, I_PAVGUSB = 2100, I_PAVGW = 6747, + I_PBLENDVB = 7621, I_PBLENDW = 9413, I_PCLMULQDQ = 9669, I_PCMPEQB = 4065, + I_PCMPEQD = 4103, I_PCMPEQQ = 7898, I_PCMPEQW = 4084, I_PCMPESTRI = 9748, + I_PCMPESTRM = 9725, I_PCMPGTB = 3724, I_PCMPGTD = 3762, I_PCMPGTQ = 8109, + I_PCMPGTW = 3743, I_PCMPISTRI = 9794, I_PCMPISTRM = 9771, I_PEXTRB = 9451, + I_PEXTRD = 9468, I_PEXTRQ = 9476, I_PEXTRW = 6333, I_PF2ID = 1936, I_PF2IW = 1929, + I_PFACC = 2050, I_PFADD = 1999, I_PFCMPEQ = 2057, I_PFCMPGE = 1960, I_PFCMPGT = 2006, + I_PFMAX = 2015, I_PFMIN = 1969, I_PFMUL = 2066, I_PFNACC = 1943, I_PFPNACC = 1951, + I_PFRCP = 1976, I_PFRCPIT1 = 2022, I_PFRCPIT2 = 2073, I_PFRSQIT1 = 2032, I_PFRSQRT = 1983, + I_PFSUB = 1992, I_PFSUBR = 2042, I_PHADDD = 7397, I_PHADDSW = 7414, I_PHADDW = 7380, + I_PHMINPOSUW = 8281, I_PHSUBD = 7473, I_PHSUBSW = 7490, I_PHSUBW = 7456, I_PI2FD = 1922, + I_PI2FW = 1915, I_PINSRB = 9552, I_PINSRD = 9590, I_PINSRQ = 9598, I_PINSRW = 6316, + I_PMADDUBSW = 7433, I_PMADDWD = 7095, I_PMAXSB = 8196, I_PMAXSD = 8213, I_PMAXSW = 6986, + I_PMAXUB = 6670, I_PMAXUD = 8247, I_PMAXUW = 8230, I_PMINSB = 8128, I_PMINSD = 8145, + I_PMINSW = 6924, I_PMINUB = 6612, I_PMINUD = 8179, I_PMINUW = 8162, I_PMOVMSKB = 6553, + I_PMOVSXBD = 7776, I_PMOVSXBQ = 7797, I_PMOVSXBW = 7755, I_PMOVSXDQ = 7860, + I_PMOVSXWD = 7818, I_PMOVSXWQ = 7839, I_PMOVZXBD = 8004, I_PMOVZXBQ = 8025, + I_PMOVZXBW = 7983, I_PMOVZXDQ = 8088, I_PMOVZXWD = 8046, I_PMOVZXWQ = 8067, + I_PMULDQ = 7881, I_PMULHRSW = 7560, I_PMULHRW = 2083, I_PMULHUW = 6762, I_PMULHW = 6781, + I_PMULLD = 8264, I_PMULLW = 6518, I_PMULUDQ = 7076, I_POP = 22, I_POPA = 98, + I_POPCNT = 4360, I_POPF = 277, I_POR = 6941, I_PREFETCH = 1894, I_PREFETCHNTA = 2424, + I_PREFETCHT0 = 2437, I_PREFETCHT1 = 2449, I_PREFETCHT2 = 2461, I_PREFETCHW = 1904, + I_PSADBW = 7114, I_PSHUFB = 7363, I_PSHUFD = 4010, I_PSHUFHW = 4018, I_PSHUFLW = 4027, + I_PSHUFW = 4002, I_PSIGNB = 7509, I_PSIGND = 7543, I_PSIGNW = 7526, I_PSLLD = 7046, + I_PSLLDQ = 9869, I_PSLLQ = 7061, I_PSLLW = 7031, I_PSRAD = 6732, I_PSRAW = 6717, + I_PSRLD = 6473, I_PSRLDQ = 9852, I_PSRLQ = 6488, I_PSRLW = 6458, I_PSUBB = 7166, + I_PSUBD = 7196, I_PSUBQ = 7211, I_PSUBSB = 6890, I_PSUBSW = 6907, I_PSUBUSB = 6574, + I_PSUBUSW = 6593, I_PSUBW = 7181, I_PSWAPD = 2092, I_PTEST = 7651, I_PUNPCKHBW = 3802, + I_PUNPCKHDQ = 3848, I_PUNPCKHQDQ = 3917, I_PUNPCKHWD = 3825, I_PUNPCKLBW = 3634, + I_PUNPCKLDQ = 3680, I_PUNPCKLQDQ = 3892, I_PUNPCKLWD = 3657, I_PUSH = 16, + I_PUSHA = 91, I_PUSHF = 270, I_PXOR = 7003, I_RCL = 977, I_RCPPS = 2975, I_RCPSS = 2982, + I_RCR = 982, I_RDFSBASE = 9904, I_RDGSBASE = 9934, I_RDMSR = 600, I_RDPMC = 607, + I_RDRAND = 10048, I_RDTSC = 593, I_RDTSCP = 1886, I_RET = 325, I_RETF = 354, + I_ROL = 967, I_ROR = 972, I_ROUNDPD = 9318, I_ROUNDPS = 9299, I_ROUNDSD = 9356, + I_ROUNDSS = 9337, I_RSM = 882, I_RSQRTPS = 2937, I_RSQRTSS = 2946, I_SAHF = 283, + I_SAL = 997, I_SALC = 394, I_SAR = 1002, I_SBB = 36, I_SCAS = 319, I_SETA = 807, + I_SETAE = 780, I_SETB = 774, I_SETBE = 800, I_SETG = 859, I_SETGE = 845, I_SETL = 839, + I_SETLE = 852, I_SETNO = 767, I_SETNP = 832, I_SETNS = 819, I_SETNZ = 793, + I_SETO = 761, I_SETP = 826, I_SETS = 813, I_SETZ = 787, I_SFENCE = 4343, I_SGDT = 1691, + I_SHL = 987, I_SHLD = 876, I_SHR = 992, I_SHRD = 892, I_SHUFPD = 6358, I_SHUFPS = 6350, + I_SIDT = 1697, I_SKINIT = 1861, I_SLDT = 1657, I_SMSW = 1715, I_SQRTPD = 2877, + I_SQRTPS = 2869, I_SQRTSD = 2893, I_SQRTSS = 2885, I_STC = 497, I_STD = 517, + I_STGI = 1849, I_STI = 507, I_STMXCSR = 9973, I_STOS = 307, I_STR = 1663, I_SUB = 51, + I_SUBPD = 3401, I_SUBPS = 3394, I_SUBSD = 3415, I_SUBSS = 3408, I_SWAPGS = 1878, + I_SYSCALL = 532, I_SYSENTER = 614, I_SYSEXIT = 624, I_SYSRET = 547, I_TEST = 206, + I_TZCNT = 4373, I_UCOMISD = 2764, I_UCOMISS = 2755, I_UD2 = 569, I_UNPCKHPD = 2318, + I_UNPCKHPS = 2308, I_UNPCKLPD = 2276, I_UNPCKLPS = 2266, I_VADDPD = 3161, + I_VADDPS = 3153, I_VADDSD = 3177, I_VADDSS = 3169, I_VADDSUBPD = 6436, I_VADDSUBPS = 6447, + I_VAESDEC = 9239, I_VAESDECLAST = 9260, I_VAESENC = 9197, I_VAESENCLAST = 9218, + I_VAESIMC = 9180, I_VAESKEYGENASSIST = 9834, I_VANDNPD = 3060, I_VANDNPS = 3051, + I_VANDPD = 3027, I_VANDPS = 3019, I_VBLENDPD = 9403, I_VBLENDPS = 9384, I_VBLENDVPD = 9703, + I_VBLENDVPS = 9692, I_VBROADCASTF128 = 7694, I_VBROADCASTSD = 7680, I_VBROADCASTSS = 7666, + I_VCMPEQPD = 5110, I_VCMPEQPS = 4708, I_VCMPEQSD = 5914, I_VCMPEQSS = 5512, + I_VCMPEQ_OSPD = 5291, I_VCMPEQ_OSPS = 4889, I_VCMPEQ_OSSD = 6095, I_VCMPEQ_OSSS = 5693, + I_VCMPEQ_UQPD = 5197, I_VCMPEQ_UQPS = 4795, I_VCMPEQ_UQSD = 6001, I_VCMPEQ_UQSS = 5599, + I_VCMPEQ_USPD = 5400, I_VCMPEQ_USPS = 4998, I_VCMPEQ_USSD = 6204, I_VCMPEQ_USSS = 5802, + I_VCMPFALSEPD = 5232, I_VCMPFALSEPS = 4830, I_VCMPFALSESD = 6036, I_VCMPFALSESS = 5634, + I_VCMPFALSE_OSPD = 5441, I_VCMPFALSE_OSPS = 5039, I_VCMPFALSE_OSSD = 6245, + I_VCMPFALSE_OSSS = 5843, I_VCMPGEPD = 5259, I_VCMPGEPS = 4857, I_VCMPGESD = 6063, + I_VCMPGESS = 5661, I_VCMPGE_OQPD = 5471, I_VCMPGE_OQPS = 5069, I_VCMPGE_OQSD = 6275, + I_VCMPGE_OQSS = 5873, I_VCMPGTPD = 5269, I_VCMPGTPS = 4867, I_VCMPGTSD = 6073, + I_VCMPGTSS = 5671, I_VCMPGT_OQPD = 5484, I_VCMPGT_OQPS = 5082, I_VCMPGT_OQSD = 6288, + I_VCMPGT_OQSS = 5886, I_VCMPLEPD = 5130, I_VCMPLEPS = 4728, I_VCMPLESD = 5934, + I_VCMPLESS = 5532, I_VCMPLE_OQPD = 5317, I_VCMPLE_OQPS = 4915, I_VCMPLE_OQSD = 6121, + I_VCMPLE_OQSS = 5719, I_VCMPLTPD = 5120, I_VCMPLTPS = 4718, I_VCMPLTSD = 5924, + I_VCMPLTSS = 5522, I_VCMPLT_OQPD = 5304, I_VCMPLT_OQPS = 4902, I_VCMPLT_OQSD = 6108, + I_VCMPLT_OQSS = 5706, I_VCMPNEQPD = 5153, I_VCMPNEQPS = 4751, I_VCMPNEQSD = 5957, + I_VCMPNEQSS = 5555, I_VCMPNEQ_OQPD = 5245, I_VCMPNEQ_OQPS = 4843, I_VCMPNEQ_OQSD = 6049, + I_VCMPNEQ_OQSS = 5647, I_VCMPNEQ_OSPD = 5457, I_VCMPNEQ_OSPS = 5055, I_VCMPNEQ_OSSD = 6261, + I_VCMPNEQ_OSSS = 5859, I_VCMPNEQ_USPD = 5345, I_VCMPNEQ_USPS = 4943, I_VCMPNEQ_USSD = 6149, + I_VCMPNEQ_USSS = 5747, I_VCMPNGEPD = 5210, I_VCMPNGEPS = 4808, I_VCMPNGESD = 6014, + I_VCMPNGESS = 5612, I_VCMPNGE_UQPD = 5413, I_VCMPNGE_UQPS = 5011, I_VCMPNGE_UQSD = 6217, + I_VCMPNGE_UQSS = 5815, I_VCMPNGTPD = 5221, I_VCMPNGTPS = 4819, I_VCMPNGTSD = 6025, + I_VCMPNGTSS = 5623, I_VCMPNGT_UQPD = 5427, I_VCMPNGT_UQPS = 5025, I_VCMPNGT_UQSD = 6231, + I_VCMPNGT_UQSS = 5829, I_VCMPNLEPD = 5175, I_VCMPNLEPS = 4773, I_VCMPNLESD = 5979, + I_VCMPNLESS = 5577, I_VCMPNLE_UQPD = 5373, I_VCMPNLE_UQPS = 4971, I_VCMPNLE_UQSD = 6177, + I_VCMPNLE_UQSS = 5775, I_VCMPNLTPD = 5164, I_VCMPNLTPS = 4762, I_VCMPNLTSD = 5968, + I_VCMPNLTSS = 5566, I_VCMPNLT_UQPD = 5359, I_VCMPNLT_UQPS = 4957, I_VCMPNLT_UQSD = 6163, + I_VCMPNLT_UQSS = 5761, I_VCMPORDPD = 5186, I_VCMPORDPS = 4784, I_VCMPORDSD = 5990, + I_VCMPORDSS = 5588, I_VCMPORD_SPD = 5387, I_VCMPORD_SPS = 4985, I_VCMPORD_SSD = 6191, + I_VCMPORD_SSS = 5789, I_VCMPTRUEPD = 5279, I_VCMPTRUEPS = 4877, I_VCMPTRUESD = 6083, + I_VCMPTRUESS = 5681, I_VCMPTRUE_USPD = 5497, I_VCMPTRUE_USPS = 5095, I_VCMPTRUE_USSD = 6301, + I_VCMPTRUE_USSS = 5899, I_VCMPUNORDPD = 5140, I_VCMPUNORDPS = 4738, I_VCMPUNORDSD = 5944, + I_VCMPUNORDSS = 5542, I_VCMPUNORD_SPD = 5330, I_VCMPUNORD_SPS = 4928, I_VCMPUNORD_SSD = 6134, + I_VCMPUNORD_SSS = 5732, I_VCOMISD = 2818, I_VCOMISS = 2809, I_VCVTDQ2PD = 6841, + I_VCVTDQ2PS = 3360, I_VCVTPD2DQ = 6852, I_VCVTPD2PS = 3296, I_VCVTPS2DQ = 3371, + I_VCVTPS2PD = 3285, I_VCVTSD2SI = 2744, I_VCVTSD2SS = 3318, I_VCVTSI2SD = 2558, + I_VCVTSI2SS = 2547, I_VCVTSS2SD = 3307, I_VCVTSS2SI = 2733, I_VCVTTPD2DQ = 6829, + I_VCVTTPS2DQ = 3382, I_VCVTTSD2SI = 2681, I_VCVTTSS2SI = 2669, I_VDIVPD = 3550, + I_VDIVPS = 3542, I_VDIVSD = 3566, I_VDIVSS = 3558, I_VDPPD = 9643, I_VDPPS = 9630, + I_VERR = 1679, I_VERW = 1685, I_VEXTRACTF128 = 9538, I_VEXTRACTPS = 9513, + I_VFMADD132PD = 8409, I_VFMADD132PS = 8396, I_VFMADD132SD = 8435, I_VFMADD132SS = 8422, + I_VFMADD213PD = 8689, I_VFMADD213PS = 8676, I_VFMADD213SD = 8715, I_VFMADD213SS = 8702, + I_VFMADD231PD = 8969, I_VFMADD231PS = 8956, I_VFMADD231SD = 8995, I_VFMADD231SS = 8982, + I_VFMADDSUB132PD = 8348, I_VFMADDSUB132PS = 8332, I_VFMADDSUB213PD = 8628, + I_VFMADDSUB213PS = 8612, I_VFMADDSUB231PD = 8908, I_VFMADDSUB231PS = 8892, + I_VFMSUB132PD = 8461, I_VFMSUB132PS = 8448, I_VFMSUB132SD = 8487, I_VFMSUB132SS = 8474, + I_VFMSUB213PD = 8741, I_VFMSUB213PS = 8728, I_VFMSUB213SD = 8767, I_VFMSUB213SS = 8754, + I_VFMSUB231PD = 9021, I_VFMSUB231PS = 9008, I_VFMSUB231SD = 9047, I_VFMSUB231SS = 9034, + I_VFMSUBADD132PD = 8380, I_VFMSUBADD132PS = 8364, I_VFMSUBADD213PD = 8660, + I_VFMSUBADD213PS = 8644, I_VFMSUBADD231PD = 8940, I_VFMSUBADD231PS = 8924, + I_VFNMADD132PD = 8514, I_VFNMADD132PS = 8500, I_VFNMADD132SD = 8542, I_VFNMADD132SS = 8528, + I_VFNMADD213PD = 8794, I_VFNMADD213PS = 8780, I_VFNMADD213SD = 8822, I_VFNMADD213SS = 8808, + I_VFNMADD231PD = 9074, I_VFNMADD231PS = 9060, I_VFNMADD231SD = 9102, I_VFNMADD231SS = 9088, + I_VFNMSUB132PD = 8570, I_VFNMSUB132PS = 8556, I_VFNMSUB132SD = 8598, I_VFNMSUB132SS = 8584, + I_VFNMSUB213PD = 8850, I_VFNMSUB213PS = 8836, I_VFNMSUB213SD = 8878, I_VFNMSUB213SS = 8864, + I_VFNMSUB231PD = 9130, I_VFNMSUB231PS = 9116, I_VFNMSUB231SD = 9158, I_VFNMSUB231SS = 9144, + I_VHADDPD = 4219, I_VHADDPS = 4228, I_VHSUBPD = 4253, I_VHSUBPS = 4262, I_VINSERTF128 = 9525, + I_VINSERTPS = 9579, I_VLDDQU = 7023, I_VLDMXCSR = 9963, I_VMASKMOVDQU = 7153, + I_VMASKMOVPD = 7971, I_VMASKMOVPS = 7959, I_VMAXPD = 3610, I_VMAXPS = 3602, + I_VMAXSD = 3626, I_VMAXSS = 3618, I_VMCALL = 1735, I_VMCLEAR = 10011, I_VMFUNC = 1803, + I_VMINPD = 3490, I_VMINPS = 3482, I_VMINSD = 3506, I_VMINSS = 3498, I_VMLAUNCH = 1743, + I_VMLOAD = 1833, I_VMMCALL = 1824, I_VMOVAPD = 2498, I_VMOVAPS = 2489, I_VMOVD = 3954, + I_VMOVDDUP = 2256, I_VMOVDQA = 3984, I_VMOVDQU = 3993, I_VMOVHLPS = 2217, + I_VMOVHPD = 2404, I_VMOVHPS = 2395, I_VMOVLHPS = 2385, I_VMOVLPD = 2236, I_VMOVLPS = 2227, + I_VMOVMSKPD = 2858, I_VMOVMSKPS = 2847, I_VMOVNTDQ = 6880, I_VMOVNTDQA = 7927, + I_VMOVNTPD = 2615, I_VMOVNTPS = 2605, I_VMOVQ = 3961, I_VMOVSD = 2165, I_VMOVSHDUP = 2413, + I_VMOVSLDUP = 2245, I_VMOVSS = 2157, I_VMOVUPD = 2148, I_VMOVUPS = 2139, I_VMPSADBW = 9659, + I_VMPTRLD = 10002, I_VMPTRST = 6407, I_VMREAD = 4150, I_VMRESUME = 1753, I_VMRUN = 1817, + I_VMSAVE = 1841, I_VMULPD = 3221, I_VMULPS = 3213, I_VMULSD = 3237, I_VMULSS = 3229, + I_VMWRITE = 4174, I_VMXOFF = 1763, I_VMXON = 10020, I_VORPD = 3088, I_VORPS = 3081, + I_VPABSB = 7717, I_VPABSD = 7747, I_VPABSW = 7732, I_VPACKSSDW = 3881, I_VPACKSSWB = 3713, + I_VPACKUSDW = 7948, I_VPACKUSWB = 3791, I_VPADDB = 7233, I_VPADDD = 7263, + I_VPADDQ = 6510, I_VPADDSB = 6960, I_VPADDSW = 6977, I_VPADDUSW = 6651, I_VPADDW = 7248, + I_VPALIGNR = 9441, I_VPAND = 6635, I_VPANDN = 6694, I_VPAVGB = 6709, I_VPAVGW = 6754, + I_VPBLENDVB = 9714, I_VPBLENDW = 9422, I_VPCLMULQDQ = 9680, I_VPCMPEQB = 4074, + I_VPCMPEQD = 4112, I_VPCMPEQQ = 7907, I_VPCMPEQW = 4093, I_VPCMPESTRI = 9759, + I_VPCMPESTRM = 9736, I_VPCMPGTB = 3733, I_VPCMPGTD = 3771, I_VPCMPGTQ = 8118, + I_VPCMPGTW = 3752, I_VPCMPISTRI = 9805, I_VPCMPISTRM = 9782, I_VPERM2F128 = 9287, + I_VPERMILPD = 7592, I_VPERMILPS = 7581, I_VPEXTRB = 9459, I_VPEXTRD = 9484, + I_VPEXTRQ = 9493, I_VPEXTRW = 6341, I_VPHADDD = 7405, I_VPHADDSW = 7423, I_VPHADDW = 7388, + I_VPHMINPOSUW = 8293, I_VPHSUBD = 7481, I_VPHSUBSW = 7499, I_VPHSUBW = 7464, + I_VPINSRB = 9560, I_VPINSRD = 9606, I_VPINSRQ = 9615, I_VPINSRW = 6324, I_VPMADDUBSW = 7444, + I_VPMADDWD = 7104, I_VPMAXSB = 8204, I_VPMAXSD = 8221, I_VPMAXSW = 6994, I_VPMAXUB = 6678, + I_VPMAXUD = 8255, I_VPMAXUW = 8238, I_VPMINSB = 8136, I_VPMINSD = 8153, I_VPMINSW = 6932, + I_VPMINUB = 6620, I_VPMINUD = 8187, I_VPMINUW = 8170, I_VPMOVMSKB = 6563, + I_VPMOVSXBD = 7786, I_VPMOVSXBQ = 7807, I_VPMOVSXBW = 7765, I_VPMOVSXDQ = 7870, + I_VPMOVSXWD = 7828, I_VPMOVSXWQ = 7849, I_VPMOVZXBD = 8014, I_VPMOVZXBQ = 8035, + I_VPMOVZXBW = 7993, I_VPMOVZXDQ = 8098, I_VPMOVZXWD = 8056, I_VPMOVZXWQ = 8077, + I_VPMULDQ = 7889, I_VPMULHRSW = 7570, I_VPMULHUW = 6771, I_VPMULHW = 6789, + I_VPMULLD = 8272, I_VPMULLW = 6526, I_VPMULUDQ = 7085, I_VPOR = 6946, I_VPSADBW = 7122, + I_VPSHUFB = 7371, I_VPSHUFD = 4036, I_VPSHUFHW = 4045, I_VPSHUFLW = 4055, + I_VPSIGNB = 7517, I_VPSIGND = 7551, I_VPSIGNW = 7534, I_VPSLLD = 7053, I_VPSLLDQ = 9877, + I_VPSLLQ = 7068, I_VPSLLW = 7038, I_VPSRAD = 6739, I_VPSRAW = 6724, I_VPSRLD = 6480, + I_VPSRLDQ = 9860, I_VPSRLQ = 6495, I_VPSRLW = 6465, I_VPSUBB = 7173, I_VPSUBD = 7203, + I_VPSUBQ = 7218, I_VPSUBSB = 6898, I_VPSUBSW = 6915, I_VPSUBUSB = 6583, I_VPSUBUSW = 6602, + I_VPSUBW = 7188, I_VPTEST = 7658, I_VPUNPCKHBW = 3813, I_VPUNPCKHDQ = 3859, + I_VPUNPCKHQDQ = 3929, I_VPUNPCKHWD = 3836, I_VPUNPCKLBW = 3645, I_VPUNPCKLDQ = 3691, + I_VPUNPCKLQDQ = 3904, I_VPUNPCKLWD = 3668, I_VPXOR = 7009, I_VRCPPS = 2989, + I_VRCPSS = 2997, I_VROUNDPD = 9327, I_VROUNDPS = 9308, I_VROUNDSD = 9365, + I_VROUNDSS = 9346, I_VRSQRTPS = 2955, I_VRSQRTSS = 2965, I_VSHUFPD = 6375, + I_VSHUFPS = 6366, I_VSQRTPD = 2910, I_VSQRTPS = 2901, I_VSQRTSD = 2928, I_VSQRTSS = 2919, + I_VSTMXCSR = 9992, I_VSUBPD = 3430, I_VSUBPS = 3422, I_VSUBSD = 3446, I_VSUBSS = 3438, + I_VTESTPD = 7612, I_VTESTPS = 7603, I_VUCOMISD = 2783, I_VUCOMISS = 2773, + I_VUNPCKHPD = 2339, I_VUNPCKHPS = 2328, I_VUNPCKLPD = 2297, I_VUNPCKLPS = 2286, + I_VXORPD = 3117, I_VXORPS = 3109, I_VZEROALL = 4140, I_VZEROUPPER = 4128, + I_WAIT = 10042, I_WBINVD = 561, I_WRFSBASE = 9953, I_WRGSBASE = 9982, I_WRMSR = 586, + I_XABORT = 1007, I_XADD = 946, I_XBEGIN = 1015, I_XCHG = 212, I_XEND = 1811, + I_XGETBV = 1787, I_XLAT = 400, I_XOR = 61, I_XORPD = 3102, I_XORPS = 3095, + I_XRSTOR = 4295, I_XRSTOR64 = 4303, I_XSAVE = 4271, I_XSAVE64 = 4278, I_XSAVEOPT = 4321, + I_XSAVEOPT64 = 4331, I_XSETBV = 1795, I__3DNOW = 10056 + } _InstructionType; + +typedef enum { + R_RAX, R_RCX, R_RDX, R_RBX, R_RSP, R_RBP, R_RSI, R_RDI, R_R8, R_R9, R_R10, R_R11, R_R12, R_R13, R_R14, R_R15, + R_EAX, R_ECX, R_EDX, R_EBX, R_ESP, R_EBP, R_ESI, R_EDI, R_R8D, R_R9D, R_R10D, R_R11D, R_R12D, R_R13D, R_R14D, R_R15D, + R_AX, R_CX, R_DX, R_BX, R_SP, R_BP, R_SI, R_DI, R_R8W, R_R9W, R_R10W, R_R11W, R_R12W, R_R13W, R_R14W, R_R15W, + R_AL, R_CL, R_DL, R_BL, R_AH, R_CH, R_DH, R_BH, R_R8B, R_R9B, R_R10B, R_R11B, R_R12B, R_R13B, R_R14B, R_R15B, + R_SPL, R_BPL, R_SIL, R_DIL, + R_ES, R_CS, R_SS, R_DS, R_FS, R_GS, + R_RIP, + R_ST0, R_ST1, R_ST2, R_ST3, R_ST4, R_ST5, R_ST6, R_ST7, + R_MM0, R_MM1, R_MM2, R_MM3, R_MM4, R_MM5, R_MM6, R_MM7, + R_XMM0, R_XMM1, R_XMM2, R_XMM3, R_XMM4, R_XMM5, R_XMM6, R_XMM7, R_XMM8, R_XMM9, R_XMM10, R_XMM11, R_XMM12, R_XMM13, R_XMM14, R_XMM15, + R_YMM0, R_YMM1, R_YMM2, R_YMM3, R_YMM4, R_YMM5, R_YMM6, R_YMM7, R_YMM8, R_YMM9, R_YMM10, R_YMM11, R_YMM12, R_YMM13, R_YMM14, R_YMM15, + R_CR0, R_UNUSED0, R_CR2, R_CR3, R_CR4, R_UNUSED1, R_UNUSED2, R_UNUSED3, R_CR8, + R_DR0, R_DR1, R_DR2, R_DR3, R_UNUSED4, R_UNUSED5, R_DR6, R_DR7 +} _RegisterType; + +#endif /* MNEMONICS_H */ diff --git a/distorm3.2-package/src/config.h b/distorm/src/config.h similarity index 85% rename from distorm3.2-package/src/config.h rename to distorm/src/config.h index 30f7d39..164536f 100644 --- a/distorm3.2-package/src/config.h +++ b/distorm/src/config.h @@ -4,20 +4,8 @@ config.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -25,7 +13,7 @@ along with this program. If not, see #define CONFIG_H /* diStorm version number. */ -#define __DISTORMV__ 0x030200 +#define __DISTORMV__ 0x030304 #include /* memset, memcpy - can be easily self implemented for libc independency. */ diff --git a/distorm3.2-package/src/decoder.c b/distorm/src/decoder.c similarity index 84% rename from distorm3.2-package/src/decoder.c rename to distorm/src/decoder.c index 8123753..b76f710 100644 --- a/distorm3.2-package/src/decoder.c +++ b/distorm/src/decoder.c @@ -4,20 +4,8 @@ decoder.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -27,6 +15,7 @@ along with this program. If not, see #include "prefix.h" #include "x86defs.h" #include "operands.h" +#include "insts.h" #include "../include/mnemonics.h" @@ -77,8 +66,17 @@ static _DecodeType decode_get_effective_op_size(_DecodeType dt, _iflags decodedP return dt; } +/* A helper macro to convert from diStorm's CPU flags to EFLAGS. */ +#define CONVERT_FLAGS_TO_EFLAGS(dst, src, field) dst->field = ((src->field & D_COMPACT_SAME_FLAGS) | \ + ((src->field & D_COMPACT_IF) ? D_IF : 0) | \ + ((src->field & D_COMPACT_DF) ? D_DF : 0) | \ + ((src->field & D_COMPACT_OF) ? D_OF : 0)); + static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) { + /* Remember whether the instruction is privileged. */ + uint16_t privilegedFlag = 0; + /* The ModR/M byte of the current instruction. */ unsigned int modrm = 0; @@ -93,6 +91,8 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) /* Holds the info about the current found instruction. */ _InstInfo* ii = NULL; + _InstInfo iip; /* Privileged instruction cache. */ + _InstSharedInfo* isi = NULL; /* Used only for special CMP instructions which have pseudo opcodes suffix. */ unsigned char cmpType = 0; @@ -104,13 +104,26 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) */ int lockable = FALSE; - /* Calcualte (and cache) effective-operand-size and effective-address-size only once. */ + /* Calculate (and cache) effective-operand-size and effective-address-size only once. */ _DecodeType effOpSz, effAdrSz; _iflags instFlags; ii = inst_lookup(ci, ps); if (ii == NULL) goto _Undecodable; - instFlags = INST_INFO_FLAGS(ii); + isi = &InstSharedInfoTable[ii->sharedIndex]; + instFlags = FlagsTable[isi->flagsIndex]; + privilegedFlag = ii->opcodeId & OPCODE_ID_PRIVILEGED; + + if (privilegedFlag) { + /* + * Copy the privileged instruction info so we can remove the privileged bit + * from the opcodeId field. This makes sure we're not modifying the tables + * in case we lookup this privileged instruction later. + */ + iip = *ii; + iip.opcodeId &= ~OPCODE_ID_PRIVILEGED; + ii = &iip; + } /* * If both REX and OpSize are available we will have to disable the OpSize, because REX has precedence. @@ -132,8 +145,8 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) * Which practically means, don't allow 32 bits instructions in 16 bits decoding mode, but do allow * 16 bits instructions in 32 bits decoding mode, of course... - * NOTE: Make sure the instruction set for 32 bits has explicitly this specfic flag set. - * NOTE2: Make sure the instruction set for 64 bits has explicitly this specfic flag set. + * NOTE: Make sure the instruction set for 32 bits has explicitly this specific flag set. + * NOTE2: Make sure the instruction set for 64 bits has explicitly this specific flag set. * If this is the case, drop what we've got and restart all over after DB'ing that byte. @@ -179,22 +192,22 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) * Note: do-while with a constant 0 makes the compiler warning about it. */ for (;;) { - if (ii->d != OT_NONE) { - if (!operands_extract(ci, di, ii, (_OpType)ii->d, ONT_1, modrm, ps, effOpSz, effAdrSz, &lockable)) goto _Undecodable; + if (isi->d != OT_NONE) { + if (!operands_extract(ci, di, ii, instFlags, (_OpType)isi->d, ONT_1, modrm, ps, effOpSz, effAdrSz, &lockable)) goto _Undecodable; } else break; - if (ii->s != OT_NONE) { - if (!operands_extract(ci, di, ii, (_OpType)ii->s, ONT_2, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; + if (isi->s != OT_NONE) { + if (!operands_extract(ci, di, ii, instFlags, (_OpType)isi->s, ONT_2, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; } else break; /* Use third operand, only if the flags says this InstInfo requires it. */ if (instFlags & INST_USE_OP3) { - if (!operands_extract(ci, di, ii, (_OpType)((_InstInfoEx*)ii)->op3, ONT_3, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; + if (!operands_extract(ci, di, ii, instFlags, (_OpType)((_InstInfoEx*)ii)->op3, ONT_3, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; } else break; /* Support for a fourth operand is added for (i.e:) INSERTQ instruction. */ if (instFlags & INST_USE_OP4) { - if (!operands_extract(ci, di, ii, (_OpType)((_InstInfoEx*)ii)->op4, ONT_4, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; + if (!operands_extract(ci, di, ii, instFlags, (_OpType)((_InstInfoEx*)ii)->op4, ONT_4, modrm, ps, effOpSz, effAdrSz, NULL)) goto _Undecodable; } break; } /* Continue here after all operands were extracted. */ @@ -203,7 +216,8 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) if (instFlags & INST_3DNOW_FETCH) { ii = inst_lookup_3dnow(ci); if (ii == NULL) goto _Undecodable; - instFlags = INST_INFO_FLAGS(ii); + isi = &InstSharedInfoTable[ii->sharedIndex]; + instFlags = FlagsTable[isi->flagsIndex]; } /* Check whether pseudo opcode is needed, only for CMP instructions: */ @@ -259,7 +273,7 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) else if ((instFlags & (INST_PRE_ADDR_SIZE | INST_NATIVE)) == (INST_PRE_ADDR_SIZE | INST_NATIVE)) { di->opcode = ii->opcodeId; - /* If LOOPxx gets here from 64bits, it must be Decode32Bits because Address Size perfix is set. */ + /* If LOOPxx gets here from 64bits, it must be Decode32Bits because Address Size prefix is set. */ ps->usedPrefixes |= INST_PRE_ADDR_SIZE; } /* @@ -332,14 +346,14 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) * Therefore, we use another table to fix the offset. */ if (instFlags & INST_PRE_VEX) { - /* Use the AVX pesudo compare mnemonics table. */ + /* Use the AVX pseudo compare mnemonics table. */ di->opcode = ii->opcodeId + VCmpMnemonicOffsets[cmpType]; } else { - /* Use the SSE psuedo compare mnemonics table. */ + /* Use the SSE pseudo compare mnemonics table. */ di->opcode = ii->opcodeId + CmpMnemonicOffsets[cmpType]; } } - + /* * Store the address size inside the flags. * This is necessary for the caller to know the size of rSP when using PUSHA for example. @@ -352,13 +366,21 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di) /* Set the unused prefixes mask. */ di->unusedPrefixesMask = prefixes_set_unused_mask(ps); + /* Fix privileged. Assumes the privilegedFlag is 0x8000 only. */ + di->flags |= privilegedFlag; + /* Copy instruction meta. */ - di->meta = ii->meta; + di->meta = isi->meta; if (di->segment == 0) di->segment = R_NONE; /* Take into account the O_MEM base register for the mask. */ if (di->base != R_NONE) di->usedRegistersMask |= _REGISTERTORCLASS[di->base]; + /* Copy CPU affected flags. */ + CONVERT_FLAGS_TO_EFLAGS(di, isi, modifiedFlagsMask); + CONVERT_FLAGS_TO_EFLAGS(di, isi, testedFlagsMask); + CONVERT_FLAGS_TO_EFLAGS(di, isi, undefinedFlagsMask); + /* Calculate the size of the instruction we've just decoded. */ di->size = (uint8_t)((ci->code - startCode) & 0xff); return DECRES_SUCCESS; @@ -395,6 +417,8 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[ _PrefixState ps; unsigned int prefixSize; _CodeInfo ci; + unsigned int features; + unsigned int mfc; _OffsetType codeOffset = _ci->codeOffset; const uint8_t* code = _ci->code; @@ -419,10 +443,15 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[ #ifdef DISTORM_LIGHT supportOldIntr; /* Unreferenced. */ -#endif + /* + * Only truncate address if we are using the decompose interface. + * Otherwise, we use the textual interface which needs full addresses for formatting bytes output. + * So distorm_format will truncate later. + */ if (_ci->features & DF_MAXIMUM_ADDR32) addrMask = 0xffffffff; else if (_ci->features & DF_MAXIMUM_ADDR16) addrMask = 0xffff; +#endif /* No entries are used yet. */ *usedInstructionsCount = 0; @@ -548,13 +577,26 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[ pdi->addr = startInstOffset & addrMask; /* pdi->disp &= addrMask; */ - /* Advance to next instruction. */ - codeLen -= pdi->size; - codeOffset += pdi->size; - code += pdi->size; + if ((decodeResult == DECRES_INPUTERR) && (ps.decodedPrefixes & INST_PRE_VEX)) { + if (ps.prefixExtType == PET_VEX3BYTES) { + prefixSize -= 2; + codeLen += 2; + } else if (ps.prefixExtType == PET_VEX2BYTES) { + prefixSize -= 1; + codeLen += 1; + } + ps.last = ps.start + prefixSize - 1; + code = ps.last + 1; + codeOffset = startInstOffset + prefixSize; + } else { + /* Advance to next instruction. */ + codeLen -= pdi->size; + codeOffset += pdi->size; + code += pdi->size; - /* Instruction's size should include prefixes. */ - pdi->size += (uint8_t)prefixSize; + /* Instruction's size should include prefixes. */ + pdi->size += (uint8_t)prefixSize; + } /* Drop all prefixes and the instruction itself, because the instruction wasn't successfully decoded. */ if ((decodeResult == DECRES_INPUTERR) && (~_ci->features & DF_RETURN_FC_ONLY)) { @@ -590,14 +632,16 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[ _ci->nextOffset = codeOffset; /* Check whether we need to stop on any flow control instruction. */ - if ((decodeResult == DECRES_SUCCESS) && (_ci->features & DF_STOP_ON_FLOW_CONTROL)) { - if (((_ci->features & DF_STOP_ON_CALL) && (META_GET_FC(pdi->meta) == FC_CALL)) || - ((_ci->features & DF_STOP_ON_RET) && (META_GET_FC(pdi->meta) == FC_RET)) || - ((_ci->features & DF_STOP_ON_SYS) && (META_GET_FC(pdi->meta) == FC_SYS)) || - ((_ci->features & DF_STOP_ON_UNC_BRANCH) && (META_GET_FC(pdi->meta) == FC_UNC_BRANCH)) || - ((_ci->features & DF_STOP_ON_CND_BRANCH) && (META_GET_FC(pdi->meta) == FC_CND_BRANCH)) || - ((_ci->features & DF_STOP_ON_INT) && (META_GET_FC(pdi->meta) == FC_INT)) || - ((_ci->features & DF_STOP_ON_CMOV) && (META_GET_FC(pdi->meta) == FC_CMOV))) + features = _ci->features; + mfc = META_GET_FC(pdi->meta); + if ((decodeResult == DECRES_SUCCESS) && (features & DF_STOP_ON_FLOW_CONTROL)) { + if (((features & DF_STOP_ON_CALL) && (mfc == FC_CALL)) || + ((features & DF_STOP_ON_RET) && (mfc == FC_RET)) || + ((features & DF_STOP_ON_SYS) && (mfc == FC_SYS)) || + ((features & DF_STOP_ON_UNC_BRANCH) && (mfc == FC_UNC_BRANCH)) || + ((features & DF_STOP_ON_CND_BRANCH) && (mfc == FC_CND_BRANCH)) || + ((features & DF_STOP_ON_INT) && (mfc == FC_INT)) || + ((features & DF_STOP_ON_CMOV) && (mfc == FC_CMOV))) return DECRES_SUCCESS; } } diff --git a/distorm3.2-package/src/decoder.h b/distorm/src/decoder.h similarity index 100% rename from distorm3.2-package/src/decoder.h rename to distorm/src/decoder.h diff --git a/distorm3.2-package/src/distorm.c b/distorm/src/distorm.c similarity index 88% rename from distorm3.2-package/src/distorm.c rename to distorm/src/distorm.c index 2b865a6..f4bc9d8 100644 --- a/distorm3.2-package/src/distorm.c +++ b/distorm/src/distorm.c @@ -5,20 +5,8 @@ diStorm3 C Library Interface diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -64,9 +52,10 @@ along with this program. If not, see #ifndef DISTORM_LIGHT -/* Helper function to concat an explicit size when it's unknown from the operands. */ +/* Helper function to concatenate an explicit size when it's unknown from the operands. */ static void distorm_format_size(_WString* str, const _DInst* di, int opNum) { + int isSizingRequired = 0; /* * We only have to output the size explicitly if it's not clear from the operands. * For example: @@ -75,9 +64,42 @@ static void distorm_format_size(_WString* str, const _DInst* di, int opNum) * * If given operand number is higher than 2, then output the size anyways. */ - if (((opNum >= 2) || ((di->ops[0].type != O_REG) && (di->ops[1].type != O_REG))) || - /* INS/OUTS are exception, because DX is a port specifier and not a real src/dst register. */ - ((di->opcode == I_INS) || (di->opcode == I_OUTS))) { + isSizingRequired = ((opNum >= 2) || ((di->ops[0].type != O_REG) && (di->ops[1].type != O_REG))); + + /* Still not sure? Try some special instructions. */ + if (!isSizingRequired) { + /* + * INS/OUTS are exception, because DX is a port specifier and not a real src/dst register. + * A few exceptions that always requires sizing: + * MOVZX, MOVSX, MOVSXD. + * ROL, ROR, RCL, RCR, SHL, SHR, SAL, SAR. + * SHLD, SHRD. + */ + switch (di->opcode) + { + case I_INS: + case I_OUTS: + case I_MOVZX: + case I_MOVSX: + case I_MOVSXD: + case I_ROL: + case I_ROR: + case I_RCL: + case I_RCR: + case I_SHL: + case I_SHR: + case I_SAL: + case I_SAR: + case I_SHLD: + case I_SHRD: + isSizingRequired = 1; + break; + default: /* Instruction doesn't require sizing. */ break; + } + } + + if (isSizingRequired) + { switch (di->ops[opNum].size) { case 0: break; /* OT_MEM's unknown size. */ @@ -125,10 +147,11 @@ static void distorm_format_signed_disp(_WString* str, const _DInst* di, uint64_t /* Copy other fields. */ result->size = di->size; - result->offset = di->addr & addrMask; + result->offset = di->addr; if (di->flags == FLAG_NOT_DECODABLE) { str = &result->mnemonic; + result->offset &= addrMask; strclear_WS(&result->operands); strcpy_WSN(str, "DB "); str_code_hb(str, di->imm.byte); @@ -139,9 +162,13 @@ static void distorm_format_signed_disp(_WString* str, const _DInst* di, uint64_t str = &result->instructionHex; strclear_WS(str); + /* Gotta have full address for (di->addr - ci->codeOffset) to work in all modes. */ for (i = 0; i < di->size; i++) str_hex_b(str, ci->code[(unsigned int)(di->addr - ci->codeOffset + i)]); + /* Truncate address now. */ + result->offset &= addrMask; + str = &result->mnemonic; switch (FLAG_GET_PREFIX(di->flags)) { @@ -149,7 +176,9 @@ static void distorm_format_signed_disp(_WString* str, const _DInst* di, uint64_t strcpy_WSN(str, "LOCK "); break; case FLAG_REP: - strcpy_WSN(str, "REP "); + /* REP prefix for CMPS and SCAS is really a REPZ. */ + if ((di->opcode == I_CMPS) || (di->opcode == I_SCAS)) strcpy_WSN(str, "REPZ "); + else strcpy_WSN(str, "REP "); break; case FLAG_REPNZ: strcpy_WSN(str, "REPNZ "); @@ -203,7 +232,7 @@ static void distorm_format_signed_disp(_WString* str, const _DInst* di, uint64_t break; case O_IMM: /* If the instruction is 'push', show explicit size (except byte imm). */ - if (di->opcode == I_PUSH && di->ops[i].size != 8) distorm_format_size(str, di, i); + if ((di->opcode == I_PUSH) && (di->ops[i].size != 8)) distorm_format_size(str, di, i); /* Special fix for negative sign extended immediates. */ if ((di->flags & FLAG_IMM_SIGNED) && (di->ops[i].size == 8)) { if (di->imm.sbyte < 0) { diff --git a/distorm3.2-package/src/instructions.c b/distorm/src/instructions.c similarity index 91% rename from distorm3.2-package/src/instructions.c rename to distorm/src/instructions.c index df122b9..0f120de 100644 --- a/distorm3.2-package/src/instructions.c +++ b/distorm/src/instructions.c @@ -4,20 +4,8 @@ instructions.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -33,13 +21,16 @@ along with this program. If not, see #define INST_NODE_INDEX(n) ((n) & 0x1fff) #define INST_NODE_TYPE(n) ((n) >> 13) +/* Helper macro to read the actual flags that are associated with an inst-info. */ +#define INST_INFO_FLAGS(ii) (FlagsTable[InstSharedInfoTable[(ii)->sharedIndex].flagsIndex]) + /* I use the trie data structure as I found it most fitting to a disassembler mechanism. When you read a byte and have to decide if it's enough or you should read more bytes, 'till you get to the instruction information. It's really fast because you POP the instruction info in top 3 iterates on the DB, because an instruction can be formed from two bytes + 3 bits reg from the ModR/M byte. For a simple explanation, check this out: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/Trie/ -Futher reading: http://en.wikipedia.org/wiki/Trie +Further reading: http://en.wikipedia.org/wiki/Trie The first GATE (array you read off a trie data structure), as I call them, is statically allocated by the compiler. The second and third gates if used are being allocated dynamically by the instructions-insertion functionality. @@ -83,9 +74,9 @@ But if you read 1, you know that you go to an instruction (in this case, a RET). That's why there's an Instruction-Node structure, it tells you whether you got to an instruction or another list so you should keep on reading byte). -In Intel, you could go through 4 gates at top, because there're instructions which are built from 2 bytes and another smaller list +In Intel, you could go through 4 gates at top, because there are instructions which are built from 2 bytes and another smaller list for the REG part, or newest SSE4 instructions which use 4 bytes for opcode. -Therefore, Intel's first gate is 256 long, and other gates are 256 (/72) or 8 long, yes, it costs pretty much alot of memory +Therefore, Intel's first gate is 256 long, and other gates are 256 (/72) or 8 long, yes, it costs pretty much a lot of memory for non-used defined instructions, but I think that it still rocks. */ @@ -136,7 +127,7 @@ static _InstInfo* inst_get_info(_InstNode in, int index) * Now, it's a mandatory prefix and NOT an operand size one. * 66480f2dc0 db 0x48; CVTPD2PI XMM0, XMM0 * Although this instruction doesn't require a REX.W, it just shows, that even if it did - it doesn't matter. - * REX.W is dropped because it's not requried, but the decode function disabled the operand size even so. + * REX.W is dropped because it's not required, but the decode function disabled the operand size even so. */ static _InstInfo* inst_lookup_prefixed(_InstNode in, _PrefixState* ps) { @@ -225,7 +216,7 @@ static _InstInfo* inst_vex_mod_lookup(_CodeInfo* ci, _InstNode in, _InstInfo* ii /* Make a second lookup for this special instruction. */ return inst_get_info(in, index); } - /* Return the original one, in case we didn't find a stuited instruction. */ + /* Return the original one, in case we didn't find a suited instruction. */ return ii; } @@ -383,14 +374,17 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) * And since the DB can't be patched dynamically, because the DB has to be multi-threaded compliant, * I have no choice but to check for ARPL/MOVSXD right here - "right about now, the funk soul brother, check it out now, the funk soul brother...", fatboy slim */ - return ci->dt == Decode64Bits ? &II_movsxd : &II_arpl; + if (ci->dt == Decode64Bits) { + return &II_MOVSXD; + } /* else ARPL will be returned because its defined in the DB already. */ + break; case INST_NOP_INDEX: /* Nopnopnop */ /* Check for Pause, since it's prefixed with 0xf3, which is not a real mandatory prefix. */ if (ps->decodedPrefixes & INST_PRE_REP) { /* Flag this prefix as used. */ ps->usedPrefixes |= INST_PRE_REP; - return &II_pause; + return &II_PAUSE; } /* @@ -402,7 +396,7 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) * Note that if the REX.B is used, then the register is not RAX anymore but R8, which means it's not a NOP. */ if (rex & PREFIX_EX_W) ps->usedPrefixes |= INST_PRE_REX; - if ((ci->dt != Decode64Bits) || (~rex & PREFIX_EX_B)) return &II_nop; + if ((ci->dt != Decode64Bits) || (~rex & PREFIX_EX_B)) return &II_NOP; break; case INST_LEA_INDEX: @@ -417,7 +411,7 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) return instType == INT_INFO ? &InstInfos[INST_NODE_INDEX(in)] : (_InstInfo*)&InstInfosEx[INST_NODE_INDEX(in)]; } - /* Read second byte, still doens't mean all of its bits are used (I.E: ModRM). */ + /* Read second byte, still doesn't mean all of its bits are used (I.E: ModRM). */ ci->code += 1; ci->codeLen -= 1; if (ci->codeLen < 0) return NULL; @@ -428,7 +422,23 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) /* Try single byte instruction + reg byte OR one whole byte (OCST_1dBYTES). */ if (instType == INT_LIST_DIVIDED) { - /* OCST_1dBYTES is relatively simple to OCST_2dBYTES, since it's really divided at 0xc0. */ + + /* Checking for inst by REG bits is higher priority if it's found not to be divided instruction. */ + { + _InstNode in2 = InstructionsTree[INST_NODE_INDEX(in) + ((tmpIndex1 >> 3) & 7)]; + /* + * Do NOT check for NULL here, since we do a bit of a guess work, + * hence we don't override 'in', cause we might still need it. + */ + instType = INST_NODE_TYPE(in2); + + if (instType == INT_INFO) ii = &InstInfos[INST_NODE_INDEX(in2)]; + else if (instType == INT_INFOEX) ii = (_InstInfo*)&InstInfosEx[INST_NODE_INDEX(in2)]; + if ((ii != NULL) && (INST_INFO_FLAGS(ii) & INST_NOT_DIVIDED)) return ii; + /* ii is reset below. */ + } + + /* Continue normally because of wait prefix. */ if (tmpIndex1 < INST_DIVIDED_MODRM) { /* An instruction which requires a ModR/M byte. Thus it's 1.3 bytes long instruction. */ tmpIndex1 = (tmpIndex1 >> 3) & 7; /* Isolate the 3 REG/OPCODE bits. */ @@ -437,7 +447,7 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) * Divided instructions can't be in the range of 0x8-0xc0. * That's because 0-8 are used for 3 bits group. * And 0xc0-0xff are used for not-divided instruction. - * So the inbetween range is omitted, thus saving some more place in the tables. + * So the in between range is omitted, thus saving some more place in the tables. */ tmpIndex1 -= INST_DIVIDED_MODRM - 8; } @@ -471,21 +481,21 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) instType = INST_NODE_TYPE(in); /* This is where we check if we just read two escape bytes in a row, which means it is a 3DNow! instruction. */ - if ((tmpIndex0 == _3DNOW_ESCAPE_BYTE) && (tmpIndex1 == _3DNOW_ESCAPE_BYTE)) return &II_3dnow; + if ((tmpIndex0 == _3DNOW_ESCAPE_BYTE) && (tmpIndex1 == _3DNOW_ESCAPE_BYTE)) return &II_3DNOW; /* 2 bytes instruction (OCST_2BYTES). */ if (instType < INT_INFOS) return instType == INT_INFO ? &InstInfos[INST_NODE_INDEX(in)] : (_InstInfo*)&InstInfosEx[INST_NODE_INDEX(in)]; /* - * 2 bytes + mandatory perfix. + * 2 bytes + mandatory prefix. * Mandatory prefixes can be anywhere in the prefixes. * There cannot be more than one mandatory prefix, unless it's a normal operand size prefix. */ if (instType == INT_LIST_PREFIXED) return inst_lookup_prefixed(in, ps); } - /* Read third byte, still doens't mean all of its bits are used (I.E: ModRM). */ + /* Read third byte, still doesn't mean all of its bits are used (I.E: ModRM). */ ci->code += 1; ci->codeLen -= 1; if (ci->codeLen < 0) return NULL; @@ -501,7 +511,10 @@ _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps) return instType == INT_INFO ? &InstInfos[INST_NODE_INDEX(in)] : (_InstInfo*)&InstInfosEx[INST_NODE_INDEX(in)]; /* It has to be a prefixed table then. */ - return inst_lookup_prefixed(in, ps); + ii = inst_lookup_prefixed(in, ps); + /* RDRAND and VMPTRLD share same 2.3 bytes opcode, and alternate on the MOD bits. See insts.h for more info. */ + if ((ii != NULL) && (ii->opcodeId == I_VMPTRLD) && (tmpIndex1 >= INST_DIVIDED_MODRM)) return &II_RDRAND; + return ii; } /* Try 2 bytes + divided range (OCST_2dBYTES). */ diff --git a/distorm3.2-package/src/instructions.h b/distorm/src/instructions.h similarity index 88% rename from distorm3.2-package/src/instructions.h rename to distorm/src/instructions.h index 43be7d9..b8d8a64 100644 --- a/distorm3.2-package/src/instructions.h +++ b/distorm/src/instructions.h @@ -4,20 +4,8 @@ instructions.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -58,9 +46,9 @@ typedef enum OpType { /* 16 bits immediate using the first imm-slot */ OT_IMM16_1, /* 8 bits immediate using the first imm-slot */ - OT_IMM8_1, + OT_IMM8_1, /* 8 bits immediate using the second imm-slot */ - OT_IMM8_2, + OT_IMM8_2, /* Use a 8bit register */ OT_REG8, @@ -240,39 +228,39 @@ typedef enum OpType { /* ModR/M for 32 bits. */ OT_RM32, /* Reg32/Reg64 (prefix width) or Mem8. */ - OT_REG32_64_M8, + OT_REG32_64_M8, /* Reg32/Reg64 (prefix width) or Mem16. */ - OT_REG32_64_M16, + OT_REG32_64_M16, /* Reg32/Reg 64 depends on prefix width only. */ - OT_WREG32_64, + OT_WREG32_64, /* RM32/RM64 depends on prefix width only. */ - OT_WRM32_64, + OT_WRM32_64, /* XMM or Mem32/Mem64 depends on perfix width only. */ - OT_WXMM32_64, + OT_WXMM32_64, /* XMM is encoded in VEX.VVVV. */ - OT_VXMM, + OT_VXMM, /* XMM is encoded in the high nibble of an immediate byte. */ - OT_XMM_IMM, + OT_XMM_IMM, /* YMM/XMM is dependent on VEX.L. */ - OT_YXMM, + OT_YXMM, /* YMM/XMM (depends on prefix length) is encoded in the high nibble of an immediate byte. */ - OT_YXMM_IMM, + OT_YXMM_IMM, /* YMM is encoded in reg. */ - OT_YMM, + OT_YMM, /* YMM or Mem256. */ - OT_YMM256, + OT_YMM256, /* YMM is encoded in VEX.VVVV. */ - OT_VYMM, + OT_VYMM, /* YMM/XMM is dependent on VEX.L, and encoded in VEX.VVVV. */ - OT_VYXMM, + OT_VYXMM, /* YMM/XMM or Mem64/Mem256 is dependent on VEX.L. */ - OT_YXMM64_256, + OT_YXMM64_256, /* YMM/XMM or Mem128/Mem256 is dependent on VEX.L. */ - OT_YXMM128_256, + OT_YXMM128_256, /* XMM or Mem64/Mem256 is dependent on VEX.L. */ - OT_LXMM64_128, + OT_LXMM64_128, /* Mem128/Mem256 is dependent on VEX.L. */ - OT_LMEM128_256 + OT_LMEM128_256 } _OpType; /* Flags for instruction: */ @@ -376,6 +364,9 @@ typedef enum OpType { /* Indicates that the instruction doesn't use the VVVV field of the VEX prefix, if it does then it's undecodable. */ #define INST_VEX_V_UNUSED (1 << 6) +/* Indication that the instruction is privileged (Ring 0), this should be checked on the opcodeId field. */ +#define OPCODE_ID_PRIVILEGED ((uint16_t)0x8000) + /* * Indicates which operand is being decoded. * Destination (1st), Source (2nd), op3 (3rd), op4 (4th). @@ -383,17 +374,49 @@ typedef enum OpType { */ typedef enum {ONT_NONE = -1, ONT_1 = 0, ONT_2 = 1, ONT_3 = 2, ONT_4 = 3} _OperandNumberType; +/* CPU Flags that instructions modify, test or undefine, in compacted form (CF,PF,AF,ZF,SF are 1:1 map to EFLAGS). */ +#define D_COMPACT_CF 1 /* Carry */ +#define D_COMPACT_PF 4 /* Parity */ +#define D_COMPACT_AF 0x10 /* Auxiliary */ +#define D_COMPACT_ZF 0x40 /* Zero */ +#define D_COMPACT_SF 0x80 /* Sign */ +/* The following flags have to be translated to EFLAGS. */ +#define D_COMPACT_IF 2 /* Interrupt */ +#define D_COMPACT_DF 8 /* Direction */ +#define D_COMPACT_OF 0x20 /* Overflow */ + +/* The mask of flags that are already compatible with EFLAGS. */ +#define D_COMPACT_SAME_FLAGS (D_COMPACT_CF | D_COMPACT_PF | D_COMPACT_AF | D_COMPACT_ZF | D_COMPACT_SF) + /* - * Info about the instruction, source/dest types, its name in text and flags. - * This structure is used for the instructions DB and NOT for the disassembled result code! - * This is the BASE structure, there are extentions to this structure below. + * In order to save more space for storing the DB statically, + * I came up with another level of shared info. + * Because I saw that most of the information that instructions use repeats itself. + * + * Info about the instruction, source/dest types, meta and flags. + * _InstInfo points to a table of _InstSharedInfo. */ - typedef struct { - uint8_t flagsIndex; /* An index into FlagsTables. */ + uint8_t flagsIndex; /* An index into FlagsTables */ uint8_t s, d; /* OpType. */ uint8_t meta; /* Hi 5 bits = Instruction set class | Lo 3 bits = flow control flags. */ - uint16_t opcodeId; /* The opcodeId is really a byte-offset into the mnemonics table. */ + /* + * The following are CPU flag masks that the instruction changes. + * The flags are compacted so 8 bits representation is enough. + * They will be expanded in runtime to be compatible to EFLAGS. + */ + uint8_t modifiedFlagsMask; + uint8_t testedFlagsMask; + uint8_t undefinedFlagsMask; +} _InstSharedInfo; + +/* + * This structure is used for the instructions DB and NOT for the disassembled result code! + * This is the BASE structure, there are extensions to this structure below. + */ +typedef struct { + uint16_t sharedIndex; /* An index into the SharedInfoTable. */ + uint16_t opcodeId; /* The opcodeId is really a byte-offset into the mnemonics table. MSB is a privileged indication. */ } _InstInfo; /* @@ -406,7 +429,6 @@ typedef struct { * therefore, I decided to make the extended structure contain all extra info in the same structure. * There are a few instructions (SHLD/SHRD/IMUL and SSE too) which use third operand (or a fourth). * A flag will indicate it uses a third/fourth operand. - * */ typedef struct { /* Base structure (doesn't get accessed directly from code). */ @@ -435,9 +457,6 @@ typedef enum { /* Instruction node is treated as { int index:13; int type:3; } */ typedef uint16_t _InstNode; -/* Helper macro to read the actual flags that are associated with an inst-info. */ -#define INST_INFO_FLAGS(ii) (FlagsTable[(ii)->flagsIndex]) - _InstInfo* inst_lookup(_CodeInfo* ci, _PrefixState* ps); _InstInfo* inst_lookup_3dnow(_CodeInfo* ci); diff --git a/distorm/src/insts.c b/distorm/src/insts.c new file mode 100644 index 0000000..a081a2d --- /dev/null +++ b/distorm/src/insts.c @@ -0,0 +1,7939 @@ +/* +insts.c + +diStorm3 - Powerful disassembler for X86/AMD64 +http://ragestorm.net/distorm/ +distorm at gmail dot com +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. +*/ + + +#include "config.h" +#include "insts.h" +#include "instructions.h" + + +/* +* GENERATED BY disOps at Sun Jul 09 21:22:14 2017 +*/ + +_InstInfo II_MOVSXD = /*II*/{ 0x1d3, 10027 }; +_InstInfo II_NOP = /*II*/{ 0x53, 581 }; +_InstInfo II_PAUSE = /*II*/{ 0x88, 10035 }; +_InstInfo II_WAIT = /*II*/{ 0x53, 10042 }; +_InstInfo II_RDRAND = /*II*/{ 0x1d4, 10048 }; +_InstInfo II_3DNOW = /*II*/{ 0x1d5, 10056 }; + +_iflags FlagsTable[101] = { + 0x80000011, + 0x80000000, + 0x800400, + 0x80800400, + 0x800080, + 0x800100, + 0x80800100, + 0x800200, + 0x80800200, + 0x800000, + 0x1, + 0x0, + 0x80800000, + 0x1000000, + 0x81000000, + 0x808000, + 0x800001, + 0x80020001, + 0x1002000, + 0x60, + 0x64, + 0x80000001, + 0x4010000, + 0x1008000, + 0x80000060, + 0x83000064, + 0x3000064, + 0x83000000, + 0x3008000, + 0x200, + 0xc000, + 0x4014000, + 0x8, + 0x81000009, + 0x9, + 0x80000009, + 0x1000808, + 0x81000808, + 0x80020009, + 0x1001008, + 0x81001008, + 0x80000019, + 0x3000009, + 0x83000009, + 0x83000008, + 0xc0000011, + 0x40000001, + 0xc0800011, + 0x40800001, + 0xc0000019, + 0xc1000001, + 0xc0000001, + 0xc0000003, + 0x41000000, + 0x40000000, + 0x40000008, + 0x40000009, + 0x41000001, + 0x43000001, + 0x40000003, + 0x48000000, + 0x200009, + 0x20000009, + 0x60020009, + 0x60000009, + 0x80090009, + 0x200b0009, + 0x20020009, + 0x80100009, + 0x21100009, + 0x87000009, + 0x20009, + 0x20000008, + 0x1000009, + 0x10020009, + 0x160009, + 0x100009, + 0x47000009, + 0x47090009, + 0x40090009, + 0x80002009, + 0xc0000009, + 0x2001, + 0x80002001, + 0x410009, + 0x20420009, + 0x20060009, + 0x120009, + 0x21020009, + 0xc7000019, + 0x20100009, + 0xc0002009, + 0x40002008, + 0xc0000000, + 0xc0002008, + 0x4020009, + 0x40100009, + 0x60120009, + 0x41000009, + 0x83000001, + 0x200001 +}; + +_InstNode Table_0F = 256; +_InstNode Table_0F_0F = 1440; +_InstNode Table_0F_38 = 1896; +_InstNode Table_0F_3A = 2152; + +_InstInfo InstInfos[1246] = { + /*II_00*/{ 0x0, 11 }, + /*II_01*/{ 0x1, 11 }, + /*II_02*/{ 0x2, 11 }, + /*II_03*/{ 0x3, 11 }, + /*II_04*/{ 0x4, 11 }, + /*II_05*/{ 0x5, 11 }, + /*II_06*/{ 0x6, 16 }, + /*II_07*/{ 0x7, 22 }, + /*II_08*/{ 0x8, 27 }, + /*II_09*/{ 0x9, 27 }, + /*II_0A*/{ 0xa, 27 }, + /*II_0B*/{ 0xb, 27 }, + /*II_0C*/{ 0xc, 27 }, + /*II_0D*/{ 0xd, 27 }, + /*II_0E*/{ 0xe, 16 }, + /*II_10*/{ 0xf, 31 }, + /*II_11*/{ 0x10, 31 }, + /*II_12*/{ 0x11, 31 }, + /*II_13*/{ 0x12, 31 }, + /*II_14*/{ 0x13, 31 }, + /*II_15*/{ 0x14, 31 }, + /*II_16*/{ 0x15, 16 }, + /*II_17*/{ 0x16, 22 }, + /*II_18*/{ 0xf, 36 }, + /*II_19*/{ 0x10, 36 }, + /*II_1A*/{ 0x11, 36 }, + /*II_1B*/{ 0x12, 36 }, + /*II_1C*/{ 0x13, 36 }, + /*II_1D*/{ 0x14, 36 }, + /*II_1E*/{ 0x17, 16 }, + /*II_1F*/{ 0x18, 22 }, + /*II_20*/{ 0x19, 41 }, + /*II_21*/{ 0x1a, 41 }, + /*II_22*/{ 0x1b, 41 }, + /*II_23*/{ 0x1c, 41 }, + /*II_24*/{ 0x1d, 41 }, + /*II_25*/{ 0x1e, 41 }, + /*II_27*/{ 0x1f, 46 }, + /*II_28*/{ 0x0, 51 }, + /*II_29*/{ 0x1, 51 }, + /*II_2A*/{ 0x2, 51 }, + /*II_2B*/{ 0x3, 51 }, + /*II_2C*/{ 0x4, 51 }, + /*II_2D*/{ 0x5, 51 }, + /*II_2F*/{ 0x1f, 56 }, + /*II_30*/{ 0x20, 61 }, + /*II_31*/{ 0x21, 61 }, + /*II_32*/{ 0x22, 61 }, + /*II_33*/{ 0x23, 61 }, + /*II_34*/{ 0x24, 61 }, + /*II_35*/{ 0x25, 61 }, + /*II_37*/{ 0x26, 66 }, + /*II_38*/{ 0x27, 71 }, + /*II_39*/{ 0x28, 71 }, + /*II_3A*/{ 0x29, 71 }, + /*II_3B*/{ 0x2a, 71 }, + /*II_3C*/{ 0x2b, 71 }, + /*II_3D*/{ 0x2c, 71 }, + /*II_3F*/{ 0x26, 76 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_40*/{ 0x2d, 81 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_48*/{ 0x2d, 86 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_50*/{ 0x2e, 16 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_58*/{ 0x2f, 22 }, + /*II_60*/{ 0x30, 91 }, + /*II_61*/{ 0x30, 98 }, + /*II_62*/{ 0x31, 104 }, + /*II_63*/{ 0x32, 111 }, + /*II_68*/{ 0x33, 16 }, + /*II_6A*/{ 0x35, 16 }, + /*II_6C*/{ 0x36, 32891 }, + /*II_6D*/{ 0x37, 32891 }, + /*II_6E*/{ 0x38, 32896 }, + /*II_6F*/{ 0x39, 32896 }, + /*II_70*/{ 0x3a, 134 }, + /*II_71*/{ 0x3a, 138 }, + /*II_72*/{ 0x3b, 143 }, + /*II_73*/{ 0x3b, 147 }, + /*II_74*/{ 0x3c, 152 }, + /*II_75*/{ 0x3c, 156 }, + /*II_76*/{ 0x3d, 161 }, + /*II_77*/{ 0x3d, 166 }, + /*II_78*/{ 0x3e, 170 }, + /*II_79*/{ 0x3e, 174 }, + /*II_7A*/{ 0x3f, 179 }, + /*II_7B*/{ 0x3f, 183 }, + /*II_7C*/{ 0x40, 188 }, + /*II_7D*/{ 0x40, 192 }, + /*II_7E*/{ 0x41, 197 }, + /*II_7F*/{ 0x41, 202 }, + /*II_84*/{ 0x42, 206 }, + /*II_85*/{ 0x43, 206 }, + /*II_86*/{ 0x44, 212 }, + /*II_87*/{ 0x45, 212 }, + /*II_88*/{ 0x46, 218 }, + /*II_89*/{ 0x47, 218 }, + /*II_8A*/{ 0x48, 218 }, + /*II_8B*/{ 0x49, 218 }, + /*II_8C*/{ 0x4a, 218 }, + /*II_8D*/{ 0x4b, 223 }, + /*II_8E*/{ 0x4c, 218 }, + /*II_90*/{ 0x4d, 212 }, + /*II_91*/{ 0x4d, 212 }, + /*II_92*/{ 0x4d, 212 }, + /*II_93*/{ 0x4d, 212 }, + /*II_94*/{ 0x4d, 212 }, + /*II_95*/{ 0x4d, 212 }, + /*II_96*/{ 0x4d, 212 }, + /*II_97*/{ 0x4d, 212 }, + /*II_9A*/{ 0x4f, 260 }, + /*II_9C*/{ 0x50, 270 }, + /*II_9D*/{ 0x51, 277 }, + /*II_9E*/{ 0x52, 283 }, + /*II_9F*/{ 0x53, 289 }, + /*II_A0*/{ 0x54, 218 }, + /*II_A1*/{ 0x55, 218 }, + /*II_A2*/{ 0x56, 218 }, + /*II_A3*/{ 0x57, 218 }, + /*II_A4*/{ 0x58, 295 }, + /*II_A5*/{ 0x59, 295 }, + /*II_A6*/{ 0x5a, 301 }, + /*II_A7*/{ 0x5b, 301 }, + /*II_A8*/{ 0x5c, 206 }, + /*II_A9*/{ 0x5d, 206 }, + /*II_AA*/{ 0x5e, 307 }, + /*II_AB*/{ 0x5f, 307 }, + /*II_AC*/{ 0x60, 313 }, + /*II_AD*/{ 0x61, 313 }, + /*II_AE*/{ 0x62, 319 }, + /*II_AF*/{ 0x63, 319 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B0*/{ 0x64, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_B8*/{ 0x65, 218 }, + /*II_C2*/{ 0x66, 325 }, + /*II_C3*/{ 0x67, 325 }, + /*II_C4*/{ 0x68, 330 }, + /*II_C5*/{ 0x68, 335 }, + /*II_C8*/{ 0x69, 340 }, + /*II_C9*/{ 0x6a, 347 }, + /*II_CA*/{ 0x6b, 354 }, + /*II_CB*/{ 0x6c, 354 }, + /*II_CC*/{ 0x6d, 360 }, + /*II_CD*/{ 0x6e, 367 }, + /*II_CE*/{ 0x6f, 372 }, + /*II_CF*/{ 0x70, 33146 }, + /*II_D4*/{ 0x71, 384 }, + /*II_D5*/{ 0x71, 389 }, + /*II_D6*/{ 0x72, 394 }, + /*II_D7*/{ 0x73, 400 }, + /*II_E0*/{ 0x74, 406 }, + /*II_E1*/{ 0x74, 414 }, + /*II_E2*/{ 0x75, 421 }, + /*II_E4*/{ 0x77, 33215 }, + /*II_E5*/{ 0x78, 33215 }, + /*II_E6*/{ 0x79, 33219 }, + /*II_E7*/{ 0x7a, 33219 }, + /*II_E8*/{ 0x7b, 456 }, + /*II_E9*/{ 0x7c, 462 }, + /*II_EA*/{ 0x7d, 467 }, + /*II_EB*/{ 0x7e, 462 }, + /*II_EC*/{ 0x7f, 33215 }, + /*II_ED*/{ 0x80, 33215 }, + /*II_EE*/{ 0x81, 33219 }, + /*II_EF*/{ 0x82, 33219 }, + /*II_F1*/{ 0x6d, 476 }, + /*II_F4*/{ 0x53, 33250 }, + /*II_F5*/{ 0x83, 487 }, + /*II_F8*/{ 0x83, 492 }, + /*II_F9*/{ 0x83, 497 }, + /*II_FA*/{ 0x84, 33270 }, + /*II_FB*/{ 0x84, 33275 }, + /*II_FC*/{ 0x85, 512 }, + /*II_FD*/{ 0x85, 517 }, + /*II_0F_02*/{ 0x86, 522 }, + /*II_0F_03*/{ 0x86, 527 }, + /*II_0F_05*/{ 0x87, 532 }, + /*II_0F_06*/{ 0x88, 33309 }, + /*II_0F_07*/{ 0x87, 547 }, + /*II_0F_08*/{ 0x88, 33323 }, + /*II_0F_09*/{ 0x88, 33329 }, + /*II_0F_0B*/{ 0x89, 569 }, + /*II_0F_0E*/{ 0x8a, 574 }, + /*II_0F_1F*/{ 0x8b, 581 }, + /*II_0F_20*/{ 0x8c, 32986 }, + /*II_0F_21*/{ 0x8d, 32986 }, + /*II_0F_22*/{ 0x8e, 32986 }, + /*II_0F_23*/{ 0x8f, 32986 }, + /*II_0F_30*/{ 0x88, 33354 }, + /*II_0F_31*/{ 0x88, 33361 }, + /*II_0F_32*/{ 0x88, 33368 }, + /*II_0F_33*/{ 0x88, 33375 }, + /*II_0F_34*/{ 0x87, 614 }, + /*II_0F_35*/{ 0x87, 624 }, + /*II_0F_37*/{ 0x90, 633 }, + /*II_0F_40*/{ 0x91, 641 }, + /*II_0F_41*/{ 0x91, 648 }, + /*II_0F_42*/{ 0x92, 656 }, + /*II_0F_43*/{ 0x92, 663 }, + /*II_0F_44*/{ 0x93, 671 }, + /*II_0F_45*/{ 0x93, 678 }, + /*II_0F_46*/{ 0x94, 686 }, + /*II_0F_47*/{ 0x94, 694 }, + /*II_0F_48*/{ 0x95, 701 }, + /*II_0F_49*/{ 0x95, 708 }, + /*II_0F_4A*/{ 0x96, 716 }, + /*II_0F_4B*/{ 0x96, 723 }, + /*II_0F_4C*/{ 0x97, 731 }, + /*II_0F_4D*/{ 0x97, 738 }, + /*II_0F_4E*/{ 0x98, 746 }, + /*II_0F_4F*/{ 0x98, 754 }, + /*II_0F_80*/{ 0x99, 134 }, + /*II_0F_81*/{ 0x99, 138 }, + /*II_0F_82*/{ 0x9a, 143 }, + /*II_0F_83*/{ 0x9a, 147 }, + /*II_0F_84*/{ 0x9b, 152 }, + /*II_0F_85*/{ 0x9b, 156 }, + /*II_0F_86*/{ 0x9c, 161 }, + /*II_0F_87*/{ 0x9c, 166 }, + /*II_0F_88*/{ 0x9d, 170 }, + /*II_0F_89*/{ 0x9d, 174 }, + /*II_0F_8A*/{ 0x9e, 179 }, + /*II_0F_8B*/{ 0x9e, 183 }, + /*II_0F_8C*/{ 0x9f, 188 }, + /*II_0F_8D*/{ 0x9f, 192 }, + /*II_0F_8E*/{ 0xa0, 197 }, + /*II_0F_8F*/{ 0xa0, 202 }, + /*II_0F_90*/{ 0xa1, 761 }, + /*II_0F_91*/{ 0xa1, 767 }, + /*II_0F_92*/{ 0xa2, 774 }, + /*II_0F_93*/{ 0xa2, 780 }, + /*II_0F_94*/{ 0xa3, 787 }, + /*II_0F_95*/{ 0xa3, 793 }, + /*II_0F_96*/{ 0xa4, 800 }, + /*II_0F_97*/{ 0xa4, 807 }, + /*II_0F_98*/{ 0xa5, 813 }, + /*II_0F_99*/{ 0xa5, 819 }, + /*II_0F_9A*/{ 0xa6, 826 }, + /*II_0F_9B*/{ 0xa6, 832 }, + /*II_0F_9C*/{ 0xa7, 839 }, + /*II_0F_9D*/{ 0xa7, 845 }, + /*II_0F_9E*/{ 0xa8, 852 }, + /*II_0F_9F*/{ 0xa8, 859 }, + /*II_0F_A0*/{ 0xa9, 16 }, + /*II_0F_A1*/{ 0xaa, 22 }, + /*II_0F_A2*/{ 0x88, 865 }, + /*II_0F_A3*/{ 0xab, 872 }, + /*II_0F_A8*/{ 0xad, 16 }, + /*II_0F_A9*/{ 0xae, 22 }, + /*II_0F_AA*/{ 0xaf, 882 }, + /*II_0F_AB*/{ 0xb0, 887 }, + /*II_0F_AF*/{ 0xb1, 117 }, + /*II_0F_B0*/{ 0xb2, 898 }, + /*II_0F_B1*/{ 0xb3, 898 }, + /*II_0F_B2*/{ 0xb4, 907 }, + /*II_0F_B3*/{ 0xb0, 912 }, + /*II_0F_B4*/{ 0xb4, 917 }, + /*II_0F_B5*/{ 0xb4, 922 }, + /*II_0F_B6*/{ 0xb5, 927 }, + /*II_0F_B7*/{ 0xb6, 927 }, + /*II_0F_B9*/{ 0x89, 569 }, + /*II_0F_BB*/{ 0xb0, 934 }, + /*II_0F_BE*/{ 0xb5, 939 }, + /*II_0F_BF*/{ 0xb6, 939 }, + /*II_0F_C0*/{ 0xb2, 946 }, + /*II_0F_C1*/{ 0xb3, 946 }, + /*II_0F_C3*/{ 0xb7, 952 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_0F_C8*/{ 0xb8, 960 }, + /*II_80_00*/{ 0xb9, 11 }, + /*II_80_01*/{ 0xba, 27 }, + /*II_80_02*/{ 0xbb, 31 }, + /*II_80_03*/{ 0xbb, 36 }, + /*II_80_04*/{ 0xbc, 41 }, + /*II_80_05*/{ 0xb9, 51 }, + /*II_80_06*/{ 0xbd, 61 }, + /*II_80_07*/{ 0xbe, 71 }, + /*II_81_00*/{ 0xbf, 11 }, + /*II_81_01*/{ 0xc0, 27 }, + /*II_81_02*/{ 0xc1, 31 }, + /*II_81_03*/{ 0xc1, 36 }, + /*II_81_04*/{ 0xc2, 41 }, + /*II_81_05*/{ 0xbf, 51 }, + /*II_81_06*/{ 0xc3, 61 }, + /*II_81_07*/{ 0xc4, 71 }, + /*II_82_00*/{ 0xc5, 11 }, + /*II_82_01*/{ 0xc6, 27 }, + /*II_82_02*/{ 0xc7, 31 }, + /*II_82_03*/{ 0xc7, 36 }, + /*II_82_04*/{ 0xc8, 41 }, + /*II_82_05*/{ 0xc5, 51 }, + /*II_82_06*/{ 0xc9, 61 }, + /*II_82_07*/{ 0xca, 71 }, + /*II_83_00*/{ 0xcb, 11 }, + /*II_83_01*/{ 0xcc, 27 }, + /*II_83_02*/{ 0xcd, 31 }, + /*II_83_03*/{ 0xcd, 36 }, + /*II_83_04*/{ 0xce, 41 }, + /*II_83_05*/{ 0xcb, 51 }, + /*II_83_06*/{ 0xcf, 61 }, + /*II_83_07*/{ 0xd0, 71 }, + /*II_8F_00*/{ 0xd1, 22 }, + /*II_C0_00*/{ 0xd2, 967 }, + /*II_C0_01*/{ 0xd2, 972 }, + /*II_C0_02*/{ 0xd3, 977 }, + /*II_C0_03*/{ 0xd3, 982 }, + /*II_C0_04*/{ 0xd4, 987 }, + /*II_C0_05*/{ 0xd4, 992 }, + /*II_C0_06*/{ 0xd4, 997 }, + /*II_C0_07*/{ 0xd4, 1002 }, + /*II_C1_00*/{ 0xd5, 967 }, + /*II_C1_01*/{ 0xd5, 972 }, + /*II_C1_02*/{ 0xd6, 977 }, + /*II_C1_03*/{ 0xd6, 982 }, + /*II_C1_04*/{ 0xd7, 987 }, + /*II_C1_05*/{ 0xd7, 992 }, + /*II_C1_06*/{ 0xd7, 997 }, + /*II_C1_07*/{ 0xd7, 1002 }, + /*II_C6_00*/{ 0xd8, 218 }, + /*II_C6_F8*/{ 0xd9, 1007 }, + /*II_C7_00*/{ 0xda, 218 }, + /*II_C7_F8*/{ 0xdb, 1015 }, + /*II_D0_00*/{ 0xdc, 967 }, + /*II_D0_01*/{ 0xdc, 972 }, + /*II_D0_02*/{ 0xdd, 977 }, + /*II_D0_03*/{ 0xdd, 982 }, + /*II_D0_04*/{ 0xde, 987 }, + /*II_D0_05*/{ 0xde, 992 }, + /*II_D0_06*/{ 0xde, 997 }, + /*II_D0_07*/{ 0xde, 1002 }, + /*II_D1_00*/{ 0xdf, 967 }, + /*II_D1_01*/{ 0xdf, 972 }, + /*II_D1_02*/{ 0xe0, 977 }, + /*II_D1_03*/{ 0xe0, 982 }, + /*II_D1_04*/{ 0xe1, 987 }, + /*II_D1_05*/{ 0xe1, 992 }, + /*II_D1_06*/{ 0xe1, 997 }, + /*II_D1_07*/{ 0xe1, 1002 }, + /*II_D2_00*/{ 0xe2, 967 }, + /*II_D2_01*/{ 0xe2, 972 }, + /*II_D2_02*/{ 0xe3, 977 }, + /*II_D2_03*/{ 0xe3, 982 }, + /*II_D2_04*/{ 0xe4, 987 }, + /*II_D2_05*/{ 0xe4, 992 }, + /*II_D2_06*/{ 0xe4, 997 }, + /*II_D2_07*/{ 0xe4, 1002 }, + /*II_D3_00*/{ 0xe5, 967 }, + /*II_D3_01*/{ 0xe5, 972 }, + /*II_D3_02*/{ 0xe6, 977 }, + /*II_D3_03*/{ 0xe6, 982 }, + /*II_D3_04*/{ 0xe7, 987 }, + /*II_D3_05*/{ 0xe7, 992 }, + /*II_D3_06*/{ 0xe7, 997 }, + /*II_D3_07*/{ 0xe7, 1002 }, + /*II_D8_00*/{ 0xe8, 1023 }, + /*II_D8_01*/{ 0xe8, 1029 }, + /*II_D8_02*/{ 0xe8, 1035 }, + /*II_D8_03*/{ 0xe8, 1041 }, + /*II_D8_04*/{ 0xe8, 1048 }, + /*II_D8_05*/{ 0xe8, 1054 }, + /*II_D8_06*/{ 0xe8, 1061 }, + /*II_D8_07*/{ 0xe8, 1067 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C0*/{ 0xe9, 1023 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_C8*/{ 0xe9, 1029 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D0*/{ 0xea, 1035 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D9*/{ 0xeb, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_D8*/{ 0xea, 1041 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E0*/{ 0xe9, 1048 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_E8*/{ 0xe9, 1054 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F0*/{ 0xe9, 1061 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D8_F8*/{ 0xe9, 1067 }, + /*II_D9_00*/{ 0xe8, 1074 }, + /*II_D9_02*/{ 0xec, 1079 }, + /*II_D9_03*/{ 0xec, 1084 }, + /*II_D9_04*/{ 0xed, 1090 }, + /*II_D9_05*/{ 0xee, 1098 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C0*/{ 0xea, 1074 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C9*/{ 0xeb, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_C8*/{ 0xea, 1105 }, + /*II_D9_D0*/{ 0xeb, 1111 }, + /*II_D9_E0*/{ 0xeb, 1117 }, + /*II_D9_E1*/{ 0xeb, 1123 }, + /*II_D9_E4*/{ 0xeb, 1129 }, + /*II_D9_E5*/{ 0xeb, 1135 }, + /*II_D9_E8*/{ 0xeb, 1141 }, + /*II_D9_E9*/{ 0xeb, 1147 }, + /*II_D9_EA*/{ 0xeb, 1155 }, + /*II_D9_EB*/{ 0xeb, 1163 }, + /*II_D9_EC*/{ 0xeb, 1170 }, + /*II_D9_ED*/{ 0xeb, 1178 }, + /*II_D9_EE*/{ 0xeb, 1186 }, + /*II_D9_F0*/{ 0xeb, 1192 }, + /*II_D9_F1*/{ 0xeb, 1199 }, + /*II_D9_F2*/{ 0xeb, 1206 }, + /*II_D9_F3*/{ 0xeb, 1213 }, + /*II_D9_F4*/{ 0xeb, 1221 }, + /*II_D9_F5*/{ 0xeb, 1230 }, + /*II_D9_F6*/{ 0xeb, 1238 }, + /*II_D9_F7*/{ 0xeb, 1247 }, + /*II_D9_F8*/{ 0xeb, 1256 }, + /*II_D9_F9*/{ 0xeb, 1263 }, + /*II_D9_FA*/{ 0xeb, 1272 }, + /*II_D9_FB*/{ 0xeb, 1279 }, + /*II_D9_FC*/{ 0xeb, 1288 }, + /*II_D9_FD*/{ 0xeb, 1297 }, + /*II_D9_FE*/{ 0xeb, 1305 }, + /*II_D9_FF*/{ 0xeb, 1311 }, + /*II_DA_00*/{ 0xe8, 1317 }, + /*II_DA_01*/{ 0xe8, 1324 }, + /*II_DA_02*/{ 0xe8, 1331 }, + /*II_DA_03*/{ 0xe8, 1338 }, + /*II_DA_04*/{ 0xe8, 1346 }, + /*II_DA_05*/{ 0xe8, 1353 }, + /*II_DA_06*/{ 0xe8, 1361 }, + /*II_DA_07*/{ 0xe8, 1368 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C0*/{ 0xef, 1376 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_C8*/{ 0xf0, 1384 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D0*/{ 0xf1, 1392 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_D8*/{ 0xf2, 1401 }, + /*II_DA_E9*/{ 0xeb, 1409 }, + /*II_DB_00*/{ 0xe8, 1418 }, + /*II_DB_01*/{ 0xf3, 1424 }, + /*II_DB_02*/{ 0xec, 1432 }, + /*II_DB_03*/{ 0xec, 1438 }, + /*II_DB_05*/{ 0xf4, 1074 }, + /*II_DB_07*/{ 0xf5, 1084 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C0*/{ 0xef, 1445 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_C8*/{ 0xf0, 1454 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D0*/{ 0xf1, 1463 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_D8*/{ 0xf2, 1473 }, + /*II_DB_E0*/{ 0xeb, 1482 }, + /*II_DB_E1*/{ 0xeb, 1488 }, + /*II_DB_E4*/{ 0xeb, 1496 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_E8*/{ 0xf6, 1504 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DB_F0*/{ 0xf7, 1512 }, + /*II_DC_00*/{ 0xf8, 1023 }, + /*II_DC_01*/{ 0xf8, 1029 }, + /*II_DC_02*/{ 0xf8, 1035 }, + /*II_DC_03*/{ 0xf8, 1041 }, + /*II_DC_04*/{ 0xf8, 1048 }, + /*II_DC_05*/{ 0xf8, 1054 }, + /*II_DC_06*/{ 0xf8, 1061 }, + /*II_DC_07*/{ 0xf8, 1067 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C0*/{ 0xf9, 1023 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_C8*/{ 0xf9, 1029 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E0*/{ 0xf9, 1054 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_E8*/{ 0xf9, 1048 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F0*/{ 0xf9, 1067 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DC_F8*/{ 0xf9, 1061 }, + /*II_DD_00*/{ 0xf8, 1074 }, + /*II_DD_01*/{ 0xfa, 1424 }, + /*II_DD_02*/{ 0xfb, 1079 }, + /*II_DD_03*/{ 0xfb, 1084 }, + /*II_DD_04*/{ 0xed, 1519 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_C0*/{ 0xea, 1527 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D0*/{ 0xea, 1079 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_D8*/{ 0xea, 1084 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E1*/{ 0xeb, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E0*/{ 0xf9, 1534 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E9*/{ 0xeb, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DD_E8*/{ 0xea, 1541 }, + /*II_DE_00*/{ 0xee, 1317 }, + /*II_DE_01*/{ 0xee, 1324 }, + /*II_DE_02*/{ 0xee, 1331 }, + /*II_DE_03*/{ 0xee, 1338 }, + /*II_DE_04*/{ 0xee, 1346 }, + /*II_DE_05*/{ 0xee, 1353 }, + /*II_DE_06*/{ 0xee, 1361 }, + /*II_DE_07*/{ 0xee, 1368 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C1*/{ 0xeb, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C0*/{ 0xf9, 1549 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C9*/{ 0xeb, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_C8*/{ 0xf9, 1556 }, + /*II_DE_D9*/{ 0xeb, 1563 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E1*/{ 0xeb, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E0*/{ 0xf9, 1571 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E9*/{ 0xeb, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_E8*/{ 0xf9, 1579 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F1*/{ 0xeb, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F0*/{ 0xf9, 1586 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F9*/{ 0xeb, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DE_F8*/{ 0xf9, 1594 }, + /*II_DF_00*/{ 0xee, 1418 }, + /*II_DF_01*/{ 0xfc, 1424 }, + /*II_DF_02*/{ 0xfd, 1432 }, + /*II_DF_03*/{ 0xfd, 1438 }, + /*II_DF_04*/{ 0xf4, 1601 }, + /*II_DF_05*/{ 0xf8, 1418 }, + /*II_DF_06*/{ 0xf5, 1607 }, + /*II_DF_07*/{ 0xfb, 1438 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_E8*/{ 0xf6, 1614 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_DF_F0*/{ 0xf6, 1623 }, + /*II_F6_00*/{ 0xfe, 206 }, + /*II_F6_02*/{ 0xff, 1631 }, + /*II_F6_03*/{ 0x100, 1636 }, + /*II_F6_04*/{ 0x101, 1641 }, + /*II_F6_05*/{ 0x101, 117 }, + /*II_F6_06*/{ 0x102, 1646 }, + /*II_F6_07*/{ 0x102, 1651 }, + /*II_F7_00*/{ 0x103, 206 }, + /*II_F7_02*/{ 0x104, 1631 }, + /*II_F7_03*/{ 0x105, 1636 }, + /*II_F7_04*/{ 0x106, 1641 }, + /*II_F7_05*/{ 0x106, 117 }, + /*II_F7_06*/{ 0x107, 1646 }, + /*II_F7_07*/{ 0x107, 1651 }, + /*II_FE_00*/{ 0x108, 81 }, + /*II_FE_01*/{ 0x108, 86 }, + /*II_FF_00*/{ 0x109, 81 }, + /*II_FF_01*/{ 0x109, 86 }, + /*II_FF_02*/{ 0x10a, 456 }, + /*II_FF_03*/{ 0x10b, 260 }, + /*II_FF_04*/{ 0x10c, 462 }, + /*II_FF_05*/{ 0x10d, 467 }, + /*II_FF_06*/{ 0x10e, 16 }, + /*II_0F_00_00*/{ 0x10f, 1657 }, + /*II_0F_00_01*/{ 0x110, 1663 }, + /*II_0F_00_02*/{ 0x110, 34436 }, + /*II_0F_00_03*/{ 0x111, 34442 }, + /*II_0F_00_04*/{ 0x112, 1679 }, + /*II_0F_00_05*/{ 0x112, 1685 }, + /*II_0F_01_00*/{ 0x113, 1691 }, + /*II_0F_01_01*/{ 0x113, 1697 }, + /*II_0F_01_02*/{ 0x113, 34471 }, + /*II_0F_01_03*/{ 0x113, 34477 }, + /*II_0F_01_04*/{ 0x114, 1715 }, + /*II_0F_01_06*/{ 0x115, 34489 }, + /*II_0F_01_07*/{ 0x116, 34495 }, + /*II_0F_01_C1*/{ 0x117, 1735 }, + /*II_0F_01_C2*/{ 0x117, 1743 }, + /*II_0F_01_C3*/{ 0x117, 1753 }, + /*II_0F_01_C4*/{ 0x117, 1763 }, + /*II_0F_01_C8*/{ 0x118, 1771 }, + /*II_0F_01_C9*/{ 0x118, 1780 }, + /*II_0F_01_D0*/{ 0x88, 1787 }, + /*II_0F_01_D1*/{ 0x88, 1795 }, + /*II_0F_01_D4*/{ 0x117, 1803 }, + /*II_0F_01_D5*/{ 0x119, 1811 }, + /*II_0F_01_D8*/{ 0x11a, 1817 }, + /*II_0F_01_D9*/{ 0x11b, 1824 }, + /*II_0F_01_DA*/{ 0x11c, 1833 }, + /*II_0F_01_DB*/{ 0x11c, 1841 }, + /*II_0F_01_DC*/{ 0x11b, 1849 }, + /*II_0F_01_DD*/{ 0x11b, 1855 }, + /*II_0F_01_DE*/{ 0x11c, 1861 }, + /*II_0F_01_DF*/{ 0x11d, 1869 }, + /*II_0F_01_F8*/{ 0x11e, 1878 }, + /*II_0F_01_F9*/{ 0x11e, 1886 }, + /*II_0F_0D_00*/{ 0x11f, 1894 }, + /*II_0F_0D_01*/{ 0x11f, 1904 }, + /*II_0F_0F_0C*/{ 0x120, 1915 }, + /*II_0F_0F_0D*/{ 0x121, 1922 }, + /*II_0F_0F_1C*/{ 0x120, 1929 }, + /*II_0F_0F_1D*/{ 0x121, 1936 }, + /*II_0F_0F_8A*/{ 0x120, 1943 }, + /*II_0F_0F_8E*/{ 0x120, 1951 }, + /*II_0F_0F_90*/{ 0x121, 1960 }, + /*II_0F_0F_94*/{ 0x121, 1969 }, + /*II_0F_0F_96*/{ 0x121, 1976 }, + /*II_0F_0F_97*/{ 0x121, 1983 }, + /*II_0F_0F_9A*/{ 0x121, 1992 }, + /*II_0F_0F_9E*/{ 0x121, 1999 }, + /*II_0F_0F_A0*/{ 0x121, 2006 }, + /*II_0F_0F_A4*/{ 0x121, 2015 }, + /*II_0F_0F_A6*/{ 0x121, 2022 }, + /*II_0F_0F_A7*/{ 0x121, 2032 }, + /*II_0F_0F_AA*/{ 0x121, 2042 }, + /*II_0F_0F_AE*/{ 0x121, 2050 }, + /*II_0F_0F_B0*/{ 0x121, 2057 }, + /*II_0F_0F_B4*/{ 0x121, 2066 }, + /*II_0F_0F_B6*/{ 0x121, 2073 }, + /*II_0F_0F_B7*/{ 0x121, 2083 }, + /*II_0F_0F_BB*/{ 0x120, 2092 }, + /*II_0F_0F_BF*/{ 0x121, 2100 }, + /*II_0F_10*/{ 0x122, 2109 }, + /*II_66_0F_10*/{ 0x123, 2117 }, + /*II_F3_0F_10*/{ 0x124, 2125 }, + /*II_F2_0F_10*/{ 0x125, 2132 }, + /*II_0F_11*/{ 0x12a, 2109 }, + /*II_66_0F_11*/{ 0x12b, 2117 }, + /*II_F3_0F_11*/{ 0x12c, 2125 }, + /*II_F2_0F_11*/{ 0x12d, 2132 }, + /*II_66_0F_12*/{ 0x132, 2190 }, + /*II_F3_0F_12*/{ 0x133, 2198 }, + /*II_F2_0F_12*/{ 0x133, 2208 }, + /*II_0F_13*/{ 0x137, 2182 }, + /*II_66_0F_13*/{ 0x138, 2190 }, + /*II_0F_14*/{ 0x13a, 2266 }, + /*II_66_0F_14*/{ 0x13b, 2276 }, + /*II_0F_15*/{ 0x13a, 2308 }, + /*II_66_0F_15*/{ 0x13b, 2318 }, + /*II_66_0F_16*/{ 0x132, 2367 }, + /*II_F3_0F_16*/{ 0x13d, 2375 }, + /*II_0F_17*/{ 0x137, 2359 }, + /*II_66_0F_17*/{ 0x138, 2367 }, + /*II_0F_18_00*/{ 0x13e, 2424 }, + /*II_0F_18_01*/{ 0x13e, 2437 }, + /*II_0F_18_02*/{ 0x13e, 2449 }, + /*II_0F_18_03*/{ 0x13e, 2461 }, + /*II_0F_28*/{ 0x122, 2473 }, + /*II_66_0F_28*/{ 0x123, 2481 }, + /*II_0F_29*/{ 0x12a, 2473 }, + /*II_66_0F_29*/{ 0x12b, 2481 }, + /*II_0F_2A*/{ 0x13f, 2507 }, + /*II_66_0F_2A*/{ 0x140, 2517 }, + /*II_F3_0F_2A*/{ 0x141, 2527 }, + /*II_F2_0F_2A*/{ 0x142, 2537 }, + /*II_0F_2B*/{ 0x143, 2569 }, + /*II_66_0F_2B*/{ 0x144, 2578 }, + /*II_F3_0F_2B*/{ 0x145, 2587 }, + /*II_F2_0F_2B*/{ 0x146, 2596 }, + /*II_0F_2C*/{ 0x148, 2625 }, + /*II_66_0F_2C*/{ 0x149, 2636 }, + /*II_F3_0F_2C*/{ 0x14a, 2647 }, + /*II_F2_0F_2C*/{ 0x14b, 2658 }, + /*II_0F_2D*/{ 0x148, 2693 }, + /*II_66_0F_2D*/{ 0x13b, 2703 }, + /*II_F3_0F_2D*/{ 0x14a, 2713 }, + /*II_F2_0F_2D*/{ 0x14b, 2723 }, + /*II_0F_2E*/{ 0x14d, 2755 }, + /*II_66_0F_2E*/{ 0x14e, 2764 }, + /*II_0F_2F*/{ 0x14d, 2793 }, + /*II_66_0F_2F*/{ 0x14e, 2801 }, + /*II_0F_50*/{ 0x151, 2827 }, + /*II_66_0F_50*/{ 0x152, 2837 }, + /*II_0F_51*/{ 0x13a, 2869 }, + /*II_66_0F_51*/{ 0x13b, 2877 }, + /*II_F3_0F_51*/{ 0x154, 2885 }, + /*II_F2_0F_51*/{ 0x14e, 2893 }, + /*II_0F_52*/{ 0x13a, 2937 }, + /*II_F3_0F_52*/{ 0x154, 2946 }, + /*II_0F_53*/{ 0x13a, 2975 }, + /*II_F3_0F_53*/{ 0x154, 2982 }, + /*II_0F_54*/{ 0x13a, 3005 }, + /*II_66_0F_54*/{ 0x13b, 3012 }, + /*II_0F_55*/{ 0x13a, 3035 }, + /*II_66_0F_55*/{ 0x13b, 3043 }, + /*II_0F_56*/{ 0x13a, 3069 }, + /*II_66_0F_56*/{ 0x13b, 3075 }, + /*II_0F_57*/{ 0x13a, 3095 }, + /*II_66_0F_57*/{ 0x13b, 3102 }, + /*II_0F_58*/{ 0x13a, 3125 }, + /*II_66_0F_58*/{ 0x13b, 3132 }, + /*II_F3_0F_58*/{ 0x154, 3139 }, + /*II_F2_0F_58*/{ 0x14e, 3146 }, + /*II_0F_59*/{ 0x13a, 3185 }, + /*II_66_0F_59*/{ 0x13b, 3192 }, + /*II_F3_0F_59*/{ 0x154, 3199 }, + /*II_F2_0F_59*/{ 0x14e, 3206 }, + /*II_0F_5A*/{ 0x14e, 3245 }, + /*II_66_0F_5A*/{ 0x13b, 3255 }, + /*II_F3_0F_5A*/{ 0x155, 3265 }, + /*II_F2_0F_5A*/{ 0x14e, 3275 }, + /*II_0F_5B*/{ 0x13b, 3329 }, + /*II_66_0F_5B*/{ 0x13b, 3339 }, + /*II_F3_0F_5B*/{ 0x13b, 3349 }, + /*II_0F_5C*/{ 0x13a, 3394 }, + /*II_66_0F_5C*/{ 0x13b, 3401 }, + /*II_F3_0F_5C*/{ 0x154, 3408 }, + /*II_F2_0F_5C*/{ 0x14e, 3415 }, + /*II_0F_5D*/{ 0x13a, 3454 }, + /*II_66_0F_5D*/{ 0x13b, 3461 }, + /*II_F3_0F_5D*/{ 0x154, 3468 }, + /*II_F2_0F_5D*/{ 0x14e, 3475 }, + /*II_0F_5E*/{ 0x13a, 3514 }, + /*II_66_0F_5E*/{ 0x13b, 3521 }, + /*II_F3_0F_5E*/{ 0x154, 3528 }, + /*II_F2_0F_5E*/{ 0x14e, 3535 }, + /*II_0F_5F*/{ 0x13a, 3574 }, + /*II_66_0F_5F*/{ 0x13b, 3581 }, + /*II_F3_0F_5F*/{ 0x154, 3588 }, + /*II_F2_0F_5F*/{ 0x14e, 3595 }, + /*II_0F_60*/{ 0x158, 3634 }, + /*II_66_0F_60*/{ 0x13b, 3634 }, + /*II_0F_61*/{ 0x158, 3657 }, + /*II_66_0F_61*/{ 0x13b, 3657 }, + /*II_0F_62*/{ 0x158, 3680 }, + /*II_66_0F_62*/{ 0x13b, 3680 }, + /*II_0F_63*/{ 0x159, 3703 }, + /*II_66_0F_63*/{ 0x13b, 3703 }, + /*II_0F_64*/{ 0x159, 3724 }, + /*II_66_0F_64*/{ 0x13b, 3724 }, + /*II_0F_65*/{ 0x159, 3743 }, + /*II_66_0F_65*/{ 0x13b, 3743 }, + /*II_0F_66*/{ 0x159, 3762 }, + /*II_66_0F_66*/{ 0x13b, 3762 }, + /*II_0F_67*/{ 0x159, 3781 }, + /*II_66_0F_67*/{ 0x13b, 3781 }, + /*II_0F_68*/{ 0x159, 3802 }, + /*II_66_0F_68*/{ 0x13b, 3802 }, + /*II_0F_69*/{ 0x159, 3825 }, + /*II_66_0F_69*/{ 0x13b, 3825 }, + /*II_0F_6A*/{ 0x159, 3848 }, + /*II_66_0F_6A*/{ 0x13b, 3848 }, + /*II_0F_6B*/{ 0x159, 3871 }, + /*II_66_0F_6B*/{ 0x13b, 3871 }, + /*II_66_0F_6C*/{ 0x13b, 3892 }, + /*II_66_0F_6D*/{ 0x13b, 3917 }, + /*II_0F_6F*/{ 0x15d, 3948 }, + /*II_66_0F_6F*/{ 0x123, 3968 }, + /*II_F3_0F_6F*/{ 0x123, 3976 }, + /*II_0F_74*/{ 0x159, 4065 }, + /*II_66_0F_74*/{ 0x13b, 4065 }, + /*II_0F_75*/{ 0x159, 4084 }, + /*II_66_0F_75*/{ 0x13b, 4084 }, + /*II_0F_76*/{ 0x159, 4103 }, + /*II_66_0F_76*/{ 0x13b, 4103 }, + /*II_0F_77*/{ 0x161, 4122 }, + /*II_0F_78*/{ 0x163, 4150 }, + /*II_0F_79*/{ 0x166, 4174 }, + /*II_66_0F_79*/{ 0x167, 4158 }, + /*II_F2_0F_79*/{ 0x168, 4165 }, + /*II_0F_7A_30*/{ 0x169, 4183 }, + /*II_0F_7A_31*/{ 0x16a, 4193 }, + /*II_66_0F_7C*/{ 0x16b, 4203 }, + /*II_F2_0F_7C*/{ 0x16b, 4211 }, + /*II_66_0F_7D*/{ 0x16b, 4237 }, + /*II_F2_0F_7D*/{ 0x16b, 4245 }, + /*II_F3_0F_7E*/{ 0x125, 3948 }, + /*II_0F_7F*/{ 0x16f, 3948 }, + /*II_66_0F_7F*/{ 0x12b, 3968 }, + /*II_F3_0F_7F*/{ 0x12b, 3976 }, + /*II_F3_0F_B8*/{ 0x173, 4360 }, + /*II_0F_BA_04*/{ 0x174, 872 }, + /*II_0F_BA_05*/{ 0x175, 887 }, + /*II_0F_BA_06*/{ 0x175, 912 }, + /*II_0F_BA_07*/{ 0x175, 934 }, + /*II_0F_BC*/{ 0x176, 4368 }, + /*II_F3_0F_BC*/{ 0x177, 4373 }, + /*II_0F_BD*/{ 0x176, 4380 }, + /*II_F3_0F_BD*/{ 0x178, 4385 }, + /*II_0F_C7_07*/{ 0x188, 6407 }, + /*II_66_0F_D0*/{ 0x16b, 6416 }, + /*II_F2_0F_D0*/{ 0x16b, 6426 }, + /*II_0F_D1*/{ 0x159, 6458 }, + /*II_66_0F_D1*/{ 0x13b, 6458 }, + /*II_0F_D2*/{ 0x159, 6473 }, + /*II_66_0F_D2*/{ 0x13b, 6473 }, + /*II_0F_D3*/{ 0x159, 6488 }, + /*II_66_0F_D3*/{ 0x13b, 6488 }, + /*II_0F_D4*/{ 0x14e, 6503 }, + /*II_66_0F_D4*/{ 0x13b, 6503 }, + /*II_0F_D5*/{ 0x159, 6518 }, + /*II_66_0F_D5*/{ 0x13b, 6518 }, + /*II_66_0F_D6*/{ 0x12d, 3948 }, + /*II_F3_0F_D6*/{ 0x189, 6535 }, + /*II_F2_0F_D6*/{ 0x18a, 6544 }, + /*II_0F_D7*/{ 0x18c, 6553 }, + /*II_66_0F_D7*/{ 0x18d, 6553 }, + /*II_0F_D8*/{ 0x159, 6574 }, + /*II_66_0F_D8*/{ 0x13b, 6574 }, + /*II_0F_D9*/{ 0x159, 6593 }, + /*II_66_0F_D9*/{ 0x13b, 6593 }, + /*II_0F_DA*/{ 0x18f, 6612 }, + /*II_66_0F_DA*/{ 0x13b, 6612 }, + /*II_0F_DB*/{ 0x159, 6629 }, + /*II_66_0F_DB*/{ 0x13b, 6629 }, + /*II_0F_DC*/{ 0x159, 6642 }, + /*II_66_0F_DC*/{ 0x13b, 6642 }, + /*II_0F_DD*/{ 0x159, 6661 }, + /*II_66_0F_DD*/{ 0x13b, 6661 }, + /*II_0F_DE*/{ 0x18f, 6670 }, + /*II_66_0F_DE*/{ 0x13b, 6670 }, + /*II_0F_DF*/{ 0x159, 6687 }, + /*II_66_0F_DF*/{ 0x13b, 6687 }, + /*II_0F_E0*/{ 0x18f, 6702 }, + /*II_66_0F_E0*/{ 0x13b, 6702 }, + /*II_0F_E1*/{ 0x159, 6717 }, + /*II_66_0F_E1*/{ 0x13b, 6717 }, + /*II_0F_E2*/{ 0x159, 6732 }, + /*II_66_0F_E2*/{ 0x13b, 6732 }, + /*II_0F_E3*/{ 0x18f, 6747 }, + /*II_66_0F_E3*/{ 0x13b, 6747 }, + /*II_0F_E4*/{ 0x18f, 6762 }, + /*II_66_0F_E4*/{ 0x13b, 6762 }, + /*II_0F_E5*/{ 0x159, 6781 }, + /*II_66_0F_E5*/{ 0x13b, 6781 }, + /*II_66_0F_E6*/{ 0x13b, 6798 }, + /*II_F3_0F_E6*/{ 0x14e, 6809 }, + /*II_F2_0F_E6*/{ 0x13b, 6819 }, + /*II_0F_E7*/{ 0x190, 6863 }, + /*II_66_0F_E7*/{ 0x144, 6871 }, + /*II_0F_E8*/{ 0x159, 6890 }, + /*II_66_0F_E8*/{ 0x13b, 6890 }, + /*II_0F_E9*/{ 0x159, 6907 }, + /*II_66_0F_E9*/{ 0x13b, 6907 }, + /*II_0F_EA*/{ 0x18f, 6924 }, + /*II_66_0F_EA*/{ 0x13b, 6924 }, + /*II_0F_EB*/{ 0x159, 6941 }, + /*II_66_0F_EB*/{ 0x13b, 6941 }, + /*II_0F_EC*/{ 0x159, 6952 }, + /*II_66_0F_EC*/{ 0x13b, 6952 }, + /*II_0F_ED*/{ 0x159, 6969 }, + /*II_66_0F_ED*/{ 0x13b, 6969 }, + /*II_0F_EE*/{ 0x18f, 6986 }, + /*II_66_0F_EE*/{ 0x13b, 6986 }, + /*II_0F_EF*/{ 0x159, 7003 }, + /*II_66_0F_EF*/{ 0x13b, 7003 }, + /*II_F2_0F_F0*/{ 0x191, 7016 }, + /*II_0F_F1*/{ 0x159, 7031 }, + /*II_66_0F_F1*/{ 0x13b, 7031 }, + /*II_0F_F2*/{ 0x159, 7046 }, + /*II_66_0F_F2*/{ 0x13b, 7046 }, + /*II_0F_F3*/{ 0x159, 7061 }, + /*II_66_0F_F3*/{ 0x13b, 7061 }, + /*II_0F_F4*/{ 0x193, 7076 }, + /*II_66_0F_F4*/{ 0x13b, 7076 }, + /*II_0F_F5*/{ 0x159, 7095 }, + /*II_66_0F_F5*/{ 0x13b, 7095 }, + /*II_0F_F6*/{ 0x18f, 7114 }, + /*II_66_0F_F6*/{ 0x13b, 7114 }, + /*II_0F_F7*/{ 0x194, 7131 }, + /*II_66_0F_F7*/{ 0x195, 7141 }, + /*II_0F_F8*/{ 0x159, 7166 }, + /*II_66_0F_F8*/{ 0x13b, 7166 }, + /*II_0F_F9*/{ 0x159, 7181 }, + /*II_66_0F_F9*/{ 0x13b, 7181 }, + /*II_0F_FA*/{ 0x159, 7196 }, + /*II_66_0F_FA*/{ 0x13b, 7196 }, + /*II_0F_FB*/{ 0x193, 7211 }, + /*II_66_0F_FB*/{ 0x13b, 7211 }, + /*II_0F_FC*/{ 0x159, 7226 }, + /*II_66_0F_FC*/{ 0x13b, 7226 }, + /*II_0F_FD*/{ 0x159, 7241 }, + /*II_66_0F_FD*/{ 0x13b, 7241 }, + /*II_0F_FE*/{ 0x159, 7256 }, + /*II_66_0F_FE*/{ 0x13b, 7256 }, + /*II_D9_06*/{ 0x197, 7271 }, + /*II_9B_D9_06*/{ 0x198, 7280 }, + /*II_D9_07*/{ 0xfd, 7288 }, + /*II_9B_D9_07*/{ 0x199, 7296 }, + /*II_DB_E2*/{ 0xeb, 7303 }, + /*II_9B_DB_E2*/{ 0x19a, 7311 }, + /*II_DB_E3*/{ 0xeb, 7318 }, + /*II_9B_DB_E3*/{ 0x19a, 7326 }, + /*II_DD_06*/{ 0x197, 7333 }, + /*II_9B_DD_06*/{ 0x198, 7341 }, + /*II_DD_07*/{ 0xfd, 7348 }, + /*II_9B_DD_07*/{ 0x199, 7356 }, + /*II_DF_E0*/{ 0x19b, 7348 }, + /*II_9B_DF_E0*/{ 0x19c, 7356 }, + /*II_0F_38_00*/{ 0x19d, 7363 }, + /*II_66_0F_38_00*/{ 0x19e, 7363 }, + /*II_0F_38_01*/{ 0x19d, 7380 }, + /*II_66_0F_38_01*/{ 0x19e, 7380 }, + /*II_0F_38_02*/{ 0x19d, 7397 }, + /*II_66_0F_38_02*/{ 0x19e, 7397 }, + /*II_0F_38_03*/{ 0x19d, 7414 }, + /*II_66_0F_38_03*/{ 0x19e, 7414 }, + /*II_0F_38_04*/{ 0x19d, 7433 }, + /*II_66_0F_38_04*/{ 0x19e, 7433 }, + /*II_0F_38_05*/{ 0x19d, 7456 }, + /*II_66_0F_38_05*/{ 0x19e, 7456 }, + /*II_0F_38_06*/{ 0x19d, 7473 }, + /*II_66_0F_38_06*/{ 0x19e, 7473 }, + /*II_0F_38_07*/{ 0x19d, 7490 }, + /*II_66_0F_38_07*/{ 0x19e, 7490 }, + /*II_0F_38_08*/{ 0x19d, 7509 }, + /*II_66_0F_38_08*/{ 0x19e, 7509 }, + /*II_0F_38_09*/{ 0x19d, 7526 }, + /*II_66_0F_38_09*/{ 0x19e, 7526 }, + /*II_0F_38_0A*/{ 0x19d, 7543 }, + /*II_66_0F_38_0A*/{ 0x19e, 7543 }, + /*II_0F_38_0B*/{ 0x19d, 7560 }, + /*II_66_0F_38_0B*/{ 0x19e, 7560 }, + /*II_66_0F_38_17*/{ 0x1a0, 7651 }, + /*II_0F_38_1C*/{ 0x19d, 7710 }, + /*II_66_0F_38_1C*/{ 0x19e, 7710 }, + /*II_0F_38_1D*/{ 0x19d, 7725 }, + /*II_66_0F_38_1D*/{ 0x19e, 7725 }, + /*II_0F_38_1E*/{ 0x19d, 7740 }, + /*II_66_0F_38_1E*/{ 0x19e, 7740 }, + /*II_66_0F_38_20*/{ 0x1a5, 7755 }, + /*II_66_0F_38_21*/{ 0x1a6, 7776 }, + /*II_66_0F_38_22*/{ 0x1a7, 7797 }, + /*II_66_0F_38_23*/{ 0x1a5, 7818 }, + /*II_66_0F_38_24*/{ 0x1a6, 7839 }, + /*II_66_0F_38_25*/{ 0x1a5, 7860 }, + /*II_66_0F_38_28*/{ 0x1a9, 7881 }, + /*II_66_0F_38_29*/{ 0x1a9, 7898 }, + /*II_66_0F_38_2A*/{ 0x1aa, 7917 }, + /*II_66_0F_38_2B*/{ 0x1a9, 7938 }, + /*II_66_0F_38_30*/{ 0x1a5, 7983 }, + /*II_66_0F_38_31*/{ 0x1a6, 8004 }, + /*II_66_0F_38_32*/{ 0x1a7, 8025 }, + /*II_66_0F_38_33*/{ 0x1a5, 8046 }, + /*II_66_0F_38_34*/{ 0x1a6, 8067 }, + /*II_66_0F_38_35*/{ 0x1a5, 8088 }, + /*II_66_0F_38_37*/{ 0x1a0, 8109 }, + /*II_66_0F_38_38*/{ 0x1a9, 8128 }, + /*II_66_0F_38_39*/{ 0x1a9, 8145 }, + /*II_66_0F_38_3A*/{ 0x1a9, 8162 }, + /*II_66_0F_38_3B*/{ 0x1a9, 8179 }, + /*II_66_0F_38_3C*/{ 0x1a9, 8196 }, + /*II_66_0F_38_3D*/{ 0x1a9, 8213 }, + /*II_66_0F_38_3E*/{ 0x1a9, 8230 }, + /*II_66_0F_38_3F*/{ 0x1a9, 8247 }, + /*II_66_0F_38_40*/{ 0x1a9, 8264 }, + /*II_66_0F_38_41*/{ 0x1a9, 8281 }, + /*II_66_0F_38_80*/{ 0x1ad, 8306 }, + /*II_66_0F_38_81*/{ 0x1ad, 8314 }, + /*II_66_0F_38_82*/{ 0x1ad, 8323 }, + /*II_66_0F_38_DB*/{ 0x1b0, 9172 }, + /*II_66_0F_38_DC*/{ 0x1b0, 9189 }, + /*II_66_0F_38_DD*/{ 0x1b0, 9206 }, + /*II_66_0F_38_DE*/{ 0x1b0, 9231 }, + /*II_66_0F_38_DF*/{ 0x1b0, 9248 }, + /*II_0F_38_F0*/{ 0x1b3, 9273 }, + /*II_F2_0F_38_F0*/{ 0x1b4, 9280 }, + /*II_0F_38_F1*/{ 0x1b5, 9273 }, + /*II_F2_0F_38_F1*/{ 0x1b6, 9280 }, + /*II_0F_71_02*/{ 0x1cd, 6458 }, + /*II_66_0F_71_02*/{ 0x1ce, 6458 }, + /*II_0F_71_04*/{ 0x1cd, 6717 }, + /*II_66_0F_71_04*/{ 0x1ce, 6717 }, + /*II_0F_71_06*/{ 0x1cd, 7031 }, + /*II_66_0F_71_06*/{ 0x1ce, 7031 }, + /*II_0F_72_02*/{ 0x1cd, 6473 }, + /*II_66_0F_72_02*/{ 0x1ce, 6473 }, + /*II_0F_72_04*/{ 0x1cd, 6732 }, + /*II_66_0F_72_04*/{ 0x1ce, 6732 }, + /*II_0F_72_06*/{ 0x1cd, 7046 }, + /*II_66_0F_72_06*/{ 0x1ce, 7046 }, + /*II_0F_73_02*/{ 0x1cd, 6488 }, + /*II_66_0F_73_02*/{ 0x1ce, 6488 }, + /*II_66_0F_73_03*/{ 0x1ce, 9852 }, + /*II_0F_73_06*/{ 0x1cd, 7061 }, + /*II_66_0F_73_06*/{ 0x1ce, 7061 }, + /*II_66_0F_73_07*/{ 0x1ce, 9869 }, + /*II_F3_0F_AE_00*/{ 0x1d0, 9904 }, + /*II_F3_0F_AE_01*/{ 0x1d0, 9934 }, + /*II_0F_AE_02*/{ 0x116, 9944 }, + /*II_F3_0F_AE_02*/{ 0x1d0, 9953 }, + /*II_0F_AE_03*/{ 0x116, 9973 }, + /*II_F3_0F_AE_03*/{ 0x1d0, 9982 }, + /*II_0F_C7_06*/{ 0x1d2, 10002 }, + /*II_66_0F_C7_06*/{ 0x188, 10011 }, + /*II_F3_0F_C7_06*/{ 0x188, 10020 } +}; + +_InstInfoEx InstInfosEx[381] = { + /*II_69*/{ { 0x34, 117 }, 0x0, 3, 0, 0, 0 }, + /*II_6B*/{ { 0x34, 117 }, 0x0, 5, 0, 0, 0 }, + /*II_98*/{ { 0x4e, 228 }, 0x0, 0, 0, 233, 239 }, + /*II_99*/{ { 0x4e, 245 }, 0x0, 0, 0, 250, 255 }, + /*II_E3*/{ { 0x76, 427 }, 0x0, 0, 0, 433, 440 }, + /*II_0F_A4*/{ { 0xac, 876 }, 0x0, 1, 0, 0, 0 }, + /*II_0F_A5*/{ { 0xac, 876 }, 0x0, 52, 0, 0, 0 }, + /*II_0F_AC*/{ { 0xac, 892 }, 0x0, 1, 0, 0, 0 }, + /*II_0F_AD*/{ { 0xac, 892 }, 0x0, 52, 0, 0, 0 }, + /*II_V_0F_10*/{ { 0x126, 2139 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_10*/{ { 0x126, 2148 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_10*/{ { 0x127, 2157 }, 0x20, 69, 0, 0, 0 }, + /*II_V_F2_0F_10*/{ { 0x127, 2165 }, 0x20, 69, 0, 0, 0 }, + /*II_VRR_F3_0F_10*/{ { 0x128, 2157 }, 0x60, 0, 0, 0, 0 }, + /*II_VRR_F2_0F_10*/{ { 0x129, 2165 }, 0x60, 0, 0, 0, 0 }, + /*II_V_0F_11*/{ { 0x12e, 2139 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_11*/{ { 0x12e, 2148 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_11*/{ { 0x127, 2157 }, 0x20, 69, 0, 0, 0 }, + /*II_V_F2_0F_11*/{ { 0x127, 2165 }, 0x20, 69, 0, 0, 0 }, + /*II_VRR_F3_0F_11*/{ { 0x12f, 2157 }, 0x60, 0, 0, 0, 0 }, + /*II_VRR_F2_0F_11*/{ { 0x130, 2165 }, 0x60, 0, 0, 0, 0 }, + /*II_0F_12*/{ { 0x131, 2173 }, 0x0, 0, 0, 2182, 0 }, + /*II_V_0F_12*/{ { 0x134, 2217 }, 0x0, 72, 0, 2227, 0 }, + /*II_V_66_0F_12*/{ { 0x135, 2236 }, 0x0, 46, 0, 0, 0 }, + /*II_V_F3_0F_12*/{ { 0x126, 2245 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F2_0F_12*/{ { 0x136, 2256 }, 0x41, 0, 0, 0, 0 }, + /*II_V_0F_13*/{ { 0x139, 2227 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_13*/{ { 0x139, 2236 }, 0x40, 0, 0, 0, 0 }, + /*II_V_0F_14*/{ { 0x13c, 2286 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_14*/{ { 0x13c, 2297 }, 0x1, 90, 0, 0, 0 }, + /*II_V_0F_15*/{ { 0x13c, 2328 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_15*/{ { 0x13c, 2339 }, 0x1, 90, 0, 0, 0 }, + /*II_0F_16*/{ { 0x131, 2350 }, 0x0, 0, 0, 2359, 0 }, + /*II_V_0F_16*/{ { 0x134, 2385 }, 0x0, 72, 0, 2395, 0 }, + /*II_V_66_0F_16*/{ { 0x135, 2404 }, 0x0, 46, 0, 0, 0 }, + /*II_V_F3_0F_16*/{ { 0x126, 2413 }, 0x41, 0, 0, 0, 0 }, + /*II_V_0F_17*/{ { 0x139, 2395 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_17*/{ { 0x139, 2404 }, 0x40, 0, 0, 0, 0 }, + /*II_V_0F_28*/{ { 0x126, 2489 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_28*/{ { 0x126, 2498 }, 0x41, 0, 0, 0, 0 }, + /*II_V_0F_29*/{ { 0x12e, 2489 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_29*/{ { 0x12e, 2498 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_2A*/{ { 0x135, 2547 }, 0x2, 79, 0, 0, 0 }, + /*II_V_F2_0F_2A*/{ { 0x135, 2558 }, 0x2, 79, 0, 0, 0 }, + /*II_V_0F_2B*/{ { 0x147, 2605 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_2B*/{ { 0x147, 2615 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_2C*/{ { 0x14c, 2669 }, 0x42, 0, 0, 0, 0 }, + /*II_V_F2_0F_2C*/{ { 0x14c, 2681 }, 0x42, 0, 0, 0, 0 }, + /*II_V_F3_0F_2D*/{ { 0x14c, 2733 }, 0x42, 0, 0, 0, 0 }, + /*II_V_F2_0F_2D*/{ { 0x14c, 2744 }, 0x42, 0, 0, 0, 0 }, + /*II_V_0F_2E*/{ { 0x14f, 2773 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_2E*/{ { 0x150, 2783 }, 0x40, 0, 0, 0, 0 }, + /*II_V_0F_2F*/{ { 0x14f, 2809 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_2F*/{ { 0x150, 2818 }, 0x40, 0, 0, 0, 0 }, + /*II_V_0F_50*/{ { 0x153, 2847 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_50*/{ { 0x153, 2858 }, 0x41, 0, 0, 0, 0 }, + /*II_V_0F_51*/{ { 0x126, 2901 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_51*/{ { 0x126, 2910 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_51*/{ { 0x135, 2919 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_51*/{ { 0x135, 2928 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_52*/{ { 0x126, 2955 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_52*/{ { 0x135, 2965 }, 0x0, 71, 0, 0, 0 }, + /*II_V_0F_53*/{ { 0x126, 2989 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_53*/{ { 0x135, 2997 }, 0x0, 71, 0, 0, 0 }, + /*II_V_0F_54*/{ { 0x13c, 3019 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_54*/{ { 0x13c, 3027 }, 0x1, 90, 0, 0, 0 }, + /*II_V_0F_55*/{ { 0x13c, 3051 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_55*/{ { 0x13c, 3060 }, 0x1, 90, 0, 0, 0 }, + /*II_V_0F_56*/{ { 0x13c, 3081 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_56*/{ { 0x13c, 3088 }, 0x1, 90, 0, 0, 0 }, + /*II_V_0F_57*/{ { 0x13c, 3109 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_57*/{ { 0x13c, 3117 }, 0x1, 90, 0, 0, 0 }, + /*II_V_0F_58*/{ { 0x13c, 3153 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_58*/{ { 0x13c, 3161 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_58*/{ { 0x135, 3169 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_58*/{ { 0x135, 3177 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_59*/{ { 0x13c, 3213 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_59*/{ { 0x13c, 3221 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_59*/{ { 0x135, 3229 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_59*/{ { 0x135, 3237 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_5A*/{ { 0x156, 3285 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_5A*/{ { 0x157, 3296 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_5A*/{ { 0x135, 3307 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_5A*/{ { 0x135, 3318 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_5B*/{ { 0x126, 3360 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_5B*/{ { 0x126, 3371 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_5B*/{ { 0x126, 3382 }, 0x41, 0, 0, 0, 0 }, + /*II_V_0F_5C*/{ { 0x13c, 3422 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_5C*/{ { 0x13c, 3430 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_5C*/{ { 0x135, 3438 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_5C*/{ { 0x135, 3446 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_5D*/{ { 0x13c, 3482 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_5D*/{ { 0x13c, 3490 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_5D*/{ { 0x135, 3498 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_5D*/{ { 0x135, 3506 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_5E*/{ { 0x13c, 3542 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_5E*/{ { 0x13c, 3550 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_5E*/{ { 0x135, 3558 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_5E*/{ { 0x135, 3566 }, 0x0, 72, 0, 0, 0 }, + /*II_V_0F_5F*/{ { 0x13c, 3602 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_5F*/{ { 0x13c, 3610 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F3_0F_5F*/{ { 0x135, 3618 }, 0x0, 71, 0, 0, 0 }, + /*II_V_F2_0F_5F*/{ { 0x135, 3626 }, 0x0, 72, 0, 0, 0 }, + /*II_V_66_0F_60*/{ { 0x135, 3645 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_61*/{ { 0x135, 3668 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_62*/{ { 0x135, 3691 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_63*/{ { 0x135, 3713 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_64*/{ { 0x135, 3733 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_65*/{ { 0x135, 3752 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_66*/{ { 0x135, 3771 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_67*/{ { 0x135, 3791 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_68*/{ { 0x135, 3813 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_69*/{ { 0x135, 3836 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_6A*/{ { 0x135, 3859 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_6B*/{ { 0x135, 3881 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_6C*/{ { 0x135, 3904 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_6D*/{ { 0x135, 3929 }, 0x0, 73, 0, 0, 0 }, + /*II_0F_6E*/{ { 0x15a, 3942 }, 0x0, 0, 0, 0, 3948 }, + /*II_66_0F_6E*/{ { 0x15b, 3942 }, 0x0, 0, 0, 0, 3948 }, + /*II_V_66_0F_6E*/{ { 0x15c, 3954 }, 0x46, 0, 0, 3961, 0 }, + /*II_V_66_0F_6F*/{ { 0x126, 3984 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_6F*/{ { 0x126, 3993 }, 0x41, 0, 0, 0, 0 }, + /*II_0F_70*/{ { 0x15e, 4002 }, 0x0, 1, 0, 0, 0 }, + /*II_66_0F_70*/{ { 0x15f, 4010 }, 0x0, 1, 0, 0, 0 }, + /*II_F3_0F_70*/{ { 0x15f, 4018 }, 0x0, 1, 0, 0, 0 }, + /*II_F2_0F_70*/{ { 0x15f, 4027 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_70*/{ { 0x160, 4036 }, 0x40, 1, 0, 0, 0 }, + /*II_V_F3_0F_70*/{ { 0x160, 4045 }, 0x40, 1, 0, 0, 0 }, + /*II_V_F2_0F_70*/{ { 0x160, 4055 }, 0x40, 1, 0, 0, 0 }, + /*II_V_66_0F_74*/{ { 0x135, 4074 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_75*/{ { 0x135, 4093 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_76*/{ { 0x135, 4112 }, 0x0, 73, 0, 0, 0 }, + /*II_V_0F_77*/{ { 0x162, 4128 }, 0x49, 0, 0, 4140, 0 }, + /*II_66_0F_78*/{ { 0x164, 4158 }, 0x0, 8, 0, 0, 0 }, + /*II_F2_0F_78*/{ { 0x165, 4165 }, 0x0, 7, 8, 0, 0 }, + /*II_V_66_0F_7C*/{ { 0x13c, 4219 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F2_0F_7C*/{ { 0x13c, 4228 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_7D*/{ { 0x13c, 4253 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F2_0F_7D*/{ { 0x13c, 4262 }, 0x1, 90, 0, 0, 0 }, + /*II_0F_7E*/{ { 0x16c, 3942 }, 0x0, 0, 0, 0, 3948 }, + /*II_66_0F_7E*/{ { 0x16d, 3942 }, 0x0, 0, 0, 0, 3948 }, + /*II_V_66_0F_7E*/{ { 0x16e, 3954 }, 0x46, 0, 0, 3961, 0 }, + /*II_V_F3_0F_7E*/{ { 0x150, 3961 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_7F*/{ { 0x12e, 3984 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_7F*/{ { 0x12e, 3993 }, 0x41, 0, 0, 0, 0 }, + /*II_0F_AE_04*/{ { 0x170, 4271 }, 0x0, 0, 0, 0, 4278 }, + /*II_0F_AE_05*/{ { 0x171, 4287 }, 0x0, 0, 0, 4295, 4303 }, + /*II_0F_AE_06*/{ { 0x171, 4313 }, 0x0, 0, 0, 4321, 4331 }, + /*II_0F_AE_07*/{ { 0x172, 4343 }, 0x0, 0, 0, 4351, 0 }, + /*II_0F_C2*/{ { 0x179, 4392 }, 0x0, 0, 0, 4401, 4410 }, + /*II_66_0F_C2*/{ { 0x17a, 4471 }, 0x0, 0, 0, 4480, 4489 }, + /*II_F3_0F_C2*/{ { 0x17b, 4550 }, 0x0, 0, 0, 4559, 4568 }, + /*II_F2_0F_C2*/{ { 0x17c, 4629 }, 0x0, 0, 0, 4638, 4647 }, + /*II_V_0F_C2*/{ { 0x17d, 4708 }, 0x1, 90, 0, 4718, 4728 }, + /*II_V_66_0F_C2*/{ { 0x17d, 5110 }, 0x1, 90, 0, 5120, 5130 }, + /*II_V_F3_0F_C2*/{ { 0x17e, 5512 }, 0x0, 71, 0, 5522, 5532 }, + /*II_V_F2_0F_C2*/{ { 0x17e, 5914 }, 0x0, 72, 0, 5924, 5934 }, + /*II_0F_C4*/{ { 0x17f, 6316 }, 0x0, 1, 0, 0, 0 }, + /*II_66_0F_C4*/{ { 0x180, 6316 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_C4*/{ { 0x181, 6324 }, 0x0, 25, 1, 0, 0 }, + /*II_0F_C5*/{ { 0x182, 6333 }, 0x0, 1, 0, 0, 0 }, + /*II_66_0F_C5*/{ { 0x183, 6333 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_C5*/{ { 0x184, 6341 }, 0x40, 1, 0, 0, 0 }, + /*II_0F_C6*/{ { 0x185, 6350 }, 0x0, 1, 0, 0, 0 }, + /*II_66_0F_C6*/{ { 0x15f, 6358 }, 0x0, 1, 0, 0, 0 }, + /*II_V_0F_C6*/{ { 0x186, 6366 }, 0x1, 90, 1, 0, 0 }, + /*II_V_66_0F_C6*/{ { 0x186, 6375 }, 0x1, 90, 1, 0, 0 }, + /*II_0F_C7_01*/{ { 0x187, 6384 }, 0x0, 0, 0, 0, 6395 }, + /*II_V_66_0F_D0*/{ { 0x13c, 6436 }, 0x1, 90, 0, 0, 0 }, + /*II_V_F2_0F_D0*/{ { 0x13c, 6447 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_D1*/{ { 0x135, 6465 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D2*/{ { 0x135, 6480 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D3*/{ { 0x135, 6495 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D4*/{ { 0x135, 6510 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D5*/{ { 0x135, 6526 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D6*/{ { 0x18b, 3961 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_D7*/{ { 0x18e, 6563 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_D8*/{ { 0x135, 6583 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_D9*/{ { 0x135, 6602 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DA*/{ { 0x135, 6620 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DB*/{ { 0x135, 6635 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DC*/{ { 0x135, 6651 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DD*/{ { 0x135, 6651 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DE*/{ { 0x135, 6678 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_DF*/{ { 0x135, 6694 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E0*/{ { 0x135, 6709 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E1*/{ { 0x135, 6724 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E2*/{ { 0x135, 6739 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E3*/{ { 0x135, 6754 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E4*/{ { 0x135, 6771 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E5*/{ { 0x135, 6789 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E6*/{ { 0x157, 6829 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F3_0F_E6*/{ { 0x156, 6841 }, 0x41, 0, 0, 0, 0 }, + /*II_V_F2_0F_E6*/{ { 0x157, 6852 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_E7*/{ { 0x147, 6880 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_E8*/{ { 0x135, 6898 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_E9*/{ { 0x135, 6915 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_EA*/{ { 0x135, 6932 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_EB*/{ { 0x135, 6946 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_EC*/{ { 0x135, 6960 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_ED*/{ { 0x135, 6977 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_EE*/{ { 0x135, 6994 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_EF*/{ { 0x135, 7009 }, 0x0, 73, 0, 0, 0 }, + /*II_V_F2_0F_F0*/{ { 0x192, 7023 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_F1*/{ { 0x135, 7038 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F2*/{ { 0x135, 7053 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F3*/{ { 0x135, 7068 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F4*/{ { 0x135, 7085 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F5*/{ { 0x135, 7104 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F6*/{ { 0x135, 7122 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F7*/{ { 0x196, 7153 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_F8*/{ { 0x135, 7173 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_F9*/{ { 0x135, 7188 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_FA*/{ { 0x135, 7203 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_FB*/{ { 0x135, 7218 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_FC*/{ { 0x135, 7233 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_FD*/{ { 0x135, 7248 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_FE*/{ { 0x135, 7263 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_00*/{ { 0x135, 7371 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_01*/{ { 0x135, 7388 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_02*/{ { 0x135, 7405 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_03*/{ { 0x135, 7423 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_04*/{ { 0x135, 7444 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_05*/{ { 0x135, 7464 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_06*/{ { 0x135, 7481 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_07*/{ { 0x135, 7499 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_08*/{ { 0x135, 7517 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_09*/{ { 0x135, 7534 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_0A*/{ { 0x135, 7551 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_0B*/{ { 0x135, 7570 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_0C*/{ { 0x13c, 7581 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_38_0D*/{ { 0x13c, 7592 }, 0x1, 90, 0, 0, 0 }, + /*II_V_66_0F_38_0E*/{ { 0x126, 7603 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_38_0F*/{ { 0x126, 7612 }, 0x41, 0, 0, 0, 0 }, + /*II_66_0F_38_10*/{ { 0x19f, 7621 }, 0x0, 74, 0, 0, 0 }, + /*II_66_0F_38_14*/{ { 0x19f, 7631 }, 0x0, 74, 0, 0, 0 }, + /*II_66_0F_38_15*/{ { 0x19f, 7641 }, 0x0, 74, 0, 0, 0 }, + /*II_V_66_0F_38_17*/{ { 0x126, 7658 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_38_18*/{ { 0x1a1, 7666 }, 0x41, 0, 0, 0, 0 }, + /*II_V_66_0F_38_19*/{ { 0x1a2, 7680 }, 0x50, 0, 0, 0, 0 }, + /*II_V_66_0F_38_1A*/{ { 0x1a3, 7694 }, 0x50, 0, 0, 0, 0 }, + /*II_V_66_0F_38_1C*/{ { 0x1a4, 7717 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_1D*/{ { 0x1a4, 7732 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_1E*/{ { 0x1a4, 7747 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_20*/{ { 0x150, 7765 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_21*/{ { 0x14f, 7786 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_22*/{ { 0x1a8, 7807 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_23*/{ { 0x150, 7828 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_24*/{ { 0x14f, 7849 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_25*/{ { 0x150, 7870 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_28*/{ { 0x135, 7889 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_29*/{ { 0x135, 7907 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_2A*/{ { 0x1ab, 7927 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_2B*/{ { 0x135, 7948 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_2C*/{ { 0x13c, 7959 }, 0x1, 92, 0, 0, 0 }, + /*II_V_66_0F_38_2D*/{ { 0x13c, 7971 }, 0x1, 92, 0, 0, 0 }, + /*II_V_66_0F_38_2E*/{ { 0x1ac, 7959 }, 0x1, 83, 0, 0, 0 }, + /*II_V_66_0F_38_2F*/{ { 0x1ac, 7971 }, 0x1, 83, 0, 0, 0 }, + /*II_V_66_0F_38_30*/{ { 0x150, 7993 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_31*/{ { 0x14f, 8014 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_32*/{ { 0x1a8, 8035 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_33*/{ { 0x150, 8056 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_34*/{ { 0x14f, 8077 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_35*/{ { 0x150, 8098 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_37*/{ { 0x135, 8118 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_38*/{ { 0x135, 8136 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_39*/{ { 0x135, 8153 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3A*/{ { 0x135, 8170 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3B*/{ { 0x135, 8187 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3C*/{ { 0x135, 8204 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3D*/{ { 0x135, 8221 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3E*/{ { 0x135, 8238 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_3F*/{ { 0x135, 8255 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_40*/{ { 0x135, 8272 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_41*/{ { 0x1a4, 8293 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_96*/{ { 0x1ae, 8332 }, 0x7, 90, 0, 8348, 0 }, + /*II_V_66_0F_38_97*/{ { 0x1ae, 8364 }, 0x7, 90, 0, 8380, 0 }, + /*II_V_66_0F_38_98*/{ { 0x1ae, 8396 }, 0x7, 90, 0, 8409, 0 }, + /*II_V_66_0F_38_99*/{ { 0x1af, 8422 }, 0x6, 80, 0, 8435, 0 }, + /*II_V_66_0F_38_9A*/{ { 0x1ae, 8448 }, 0x7, 90, 0, 8461, 0 }, + /*II_V_66_0F_38_9B*/{ { 0x1af, 8474 }, 0x6, 80, 0, 8487, 0 }, + /*II_V_66_0F_38_9C*/{ { 0x1ae, 8500 }, 0x7, 90, 0, 8514, 0 }, + /*II_V_66_0F_38_9D*/{ { 0x1af, 8528 }, 0x6, 80, 0, 8542, 0 }, + /*II_V_66_0F_38_9E*/{ { 0x1ae, 8556 }, 0x7, 90, 0, 8570, 0 }, + /*II_V_66_0F_38_9F*/{ { 0x1af, 8584 }, 0x6, 80, 0, 8598, 0 }, + /*II_V_66_0F_38_A6*/{ { 0x1ae, 8612 }, 0x7, 90, 0, 8628, 0 }, + /*II_V_66_0F_38_A7*/{ { 0x1ae, 8644 }, 0x7, 90, 0, 8660, 0 }, + /*II_V_66_0F_38_A8*/{ { 0x1ae, 8676 }, 0x7, 90, 0, 8689, 0 }, + /*II_V_66_0F_38_A9*/{ { 0x1af, 8702 }, 0x6, 80, 0, 8715, 0 }, + /*II_V_66_0F_38_AA*/{ { 0x1ae, 8728 }, 0x7, 90, 0, 8741, 0 }, + /*II_V_66_0F_38_AB*/{ { 0x1af, 8754 }, 0x6, 80, 0, 8767, 0 }, + /*II_V_66_0F_38_AC*/{ { 0x1ae, 8780 }, 0x7, 90, 0, 8794, 0 }, + /*II_V_66_0F_38_AD*/{ { 0x1af, 8808 }, 0x6, 80, 0, 8822, 0 }, + /*II_V_66_0F_38_AE*/{ { 0x1ae, 8836 }, 0x7, 90, 0, 8850, 0 }, + /*II_V_66_0F_38_AF*/{ { 0x1af, 8864 }, 0x6, 80, 0, 8878, 0 }, + /*II_V_66_0F_38_B6*/{ { 0x1ae, 8892 }, 0x7, 90, 0, 8908, 0 }, + /*II_V_66_0F_38_B7*/{ { 0x1ae, 8924 }, 0x7, 90, 0, 8940, 0 }, + /*II_V_66_0F_38_B8*/{ { 0x1ae, 8956 }, 0x7, 90, 0, 8969, 0 }, + /*II_V_66_0F_38_B9*/{ { 0x1af, 8982 }, 0x6, 80, 0, 8995, 0 }, + /*II_V_66_0F_38_BA*/{ { 0x1ae, 9008 }, 0x7, 90, 0, 9021, 0 }, + /*II_V_66_0F_38_BB*/{ { 0x1af, 9034 }, 0x6, 80, 0, 9047, 0 }, + /*II_V_66_0F_38_BC*/{ { 0x1ae, 9060 }, 0x7, 90, 0, 9074, 0 }, + /*II_V_66_0F_38_BD*/{ { 0x1af, 9088 }, 0x6, 80, 0, 9102, 0 }, + /*II_V_66_0F_38_BE*/{ { 0x1ae, 9116 }, 0x7, 90, 0, 9130, 0 }, + /*II_V_66_0F_38_BF*/{ { 0x1af, 9144 }, 0x6, 80, 0, 9158, 0 }, + /*II_V_66_0F_38_DB*/{ { 0x1b1, 9180 }, 0x40, 0, 0, 0, 0 }, + /*II_V_66_0F_38_DC*/{ { 0x1b2, 9197 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_DD*/{ { 0x1b2, 9218 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_DE*/{ { 0x1b2, 9239 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_38_DF*/{ { 0x1b2, 9260 }, 0x0, 73, 0, 0, 0 }, + /*II_V_66_0F_3A_04*/{ { 0x1b7, 7581 }, 0x41, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_05*/{ { 0x1b7, 7592 }, 0x41, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_06*/{ { 0x1b8, 9287 }, 0x10, 86, 1, 0, 0 }, + /*II_66_0F_3A_08*/{ { 0x19f, 9299 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_08*/{ { 0x1b7, 9308 }, 0x41, 1, 0, 0, 0 }, + /*II_66_0F_3A_09*/{ { 0x19f, 9318 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_09*/{ { 0x1b7, 9327 }, 0x41, 1, 0, 0, 0 }, + /*II_66_0F_3A_0A*/{ { 0x1b9, 9337 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0A*/{ { 0x181, 9346 }, 0x0, 71, 1, 0, 0 }, + /*II_66_0F_3A_0B*/{ { 0x1ba, 9356 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0B*/{ { 0x181, 9365 }, 0x0, 72, 1, 0, 0 }, + /*II_66_0F_3A_0C*/{ { 0x19f, 9375 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0C*/{ { 0x186, 9384 }, 0x1, 90, 1, 0, 0 }, + /*II_66_0F_3A_0D*/{ { 0x19f, 9394 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0D*/{ { 0x186, 9403 }, 0x1, 90, 1, 0, 0 }, + /*II_66_0F_3A_0E*/{ { 0x19f, 9413 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0E*/{ { 0x181, 9422 }, 0x0, 73, 1, 0, 0 }, + /*II_0F_3A_0F*/{ { 0x1bb, 9432 }, 0x0, 1, 0, 0, 0 }, + /*II_66_0F_3A_0F*/{ { 0x1bc, 9432 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_0F*/{ { 0x181, 9441 }, 0x0, 73, 1, 0, 0 }, + /*II_66_0F_3A_14*/{ { 0x1bd, 9451 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_14*/{ { 0x1be, 9459 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_15*/{ { 0x1bf, 6333 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_15*/{ { 0x1c0, 6341 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_16*/{ { 0x1c1, 9468 }, 0x0, 1, 0, 0, 9476 }, + /*II_V_66_0F_3A_16*/{ { 0x1c2, 9484 }, 0x46, 1, 0, 9493, 0 }, + /*II_66_0F_3A_17*/{ { 0x1c3, 9502 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_17*/{ { 0x1c4, 9513 }, 0x40, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_18*/{ { 0x1b8, 9525 }, 0x10, 73, 1, 0, 0 }, + /*II_V_66_0F_3A_19*/{ { 0x1c5, 9538 }, 0x50, 1, 0, 0, 0 }, + /*II_66_0F_3A_20*/{ { 0x1c6, 9552 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_20*/{ { 0x181, 9560 }, 0x0, 76, 1, 0, 0 }, + /*II_66_0F_3A_21*/{ { 0x1b9, 9569 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_21*/{ { 0x181, 9579 }, 0x0, 71, 1, 0, 0 }, + /*II_66_0F_3A_22*/{ { 0x1c7, 9590 }, 0x0, 1, 0, 0, 9598 }, + /*II_V_66_0F_3A_22*/{ { 0x181, 9606 }, 0x6, 79, 1, 9615, 0 }, + /*II_66_0F_3A_40*/{ { 0x19f, 9624 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_40*/{ { 0x186, 9630 }, 0x1, 90, 1, 0, 0 }, + /*II_66_0F_3A_41*/{ { 0x19f, 9637 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_41*/{ { 0x181, 9643 }, 0x0, 73, 1, 0, 0 }, + /*II_66_0F_3A_42*/{ { 0x19f, 9650 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_42*/{ { 0x181, 9659 }, 0x0, 73, 1, 0, 0 }, + /*II_66_0F_3A_44*/{ { 0x1c8, 9669 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_44*/{ { 0x1c9, 9680 }, 0x0, 73, 1, 0, 0 }, + /*II_V_66_0F_3A_4A*/{ { 0x186, 9692 }, 0x1, 90, 84, 0, 0 }, + /*II_V_66_0F_3A_4B*/{ { 0x186, 9703 }, 0x1, 90, 84, 0, 0 }, + /*II_V_66_0F_3A_4C*/{ { 0x181, 9714 }, 0x0, 73, 82, 0, 0 }, + /*II_66_0F_3A_60*/{ { 0x1ca, 9725 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_60*/{ { 0x160, 9736 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_61*/{ { 0x1ca, 9748 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_61*/{ { 0x160, 9759 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_62*/{ { 0x1ca, 9771 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_62*/{ { 0x160, 9782 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_63*/{ { 0x1ca, 9794 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_63*/{ { 0x160, 9805 }, 0x40, 1, 0, 0, 0 }, + /*II_66_0F_3A_DF*/{ { 0x1cb, 9817 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_3A_DF*/{ { 0x1cc, 9834 }, 0x40, 1, 0, 0, 0 }, + /*II_V_66_0F_71_02*/{ { 0x1cf, 6465 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_71_04*/{ { 0x1cf, 6724 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_71_06*/{ { 0x1cf, 7038 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_72_02*/{ { 0x1cf, 6480 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_72_04*/{ { 0x1cf, 6739 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_72_06*/{ { 0x1cf, 7053 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_73_02*/{ { 0x1cf, 6495 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_73_03*/{ { 0x1cf, 9860 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_73_06*/{ { 0x1cf, 7068 }, 0x0, 1, 0, 0, 0 }, + /*II_V_66_0F_73_07*/{ { 0x1cf, 9877 }, 0x0, 1, 0, 0, 0 }, + /*II_0F_AE_00*/{ { 0x170, 9886 }, 0x0, 0, 0, 0, 9894 }, + /*II_0F_AE_01*/{ { 0x170, 9914 }, 0x0, 0, 0, 0, 9923 }, + /*II_V_0F_AE_02*/{ { 0x1d1, 9963 }, 0x40, 0, 0, 0, 0 }, + /*II_V_0F_AE_03*/{ { 0x1d1, 9992 }, 0x40, 0, 0, 0, 0 } +}; + +_InstNode InstructionsTree[5688] = { + /* 0 - _00 */ 0x2000, + /* 1 - _01 */ 0x2001, + /* 2 - _02 */ 0x2002, + /* 3 - _03 */ 0x2003, + /* 4 - _04 */ 0x2004, + /* 5 - _05 */ 0x2005, + /* 6 - _06 */ 0x2006, + /* 7 - _07 */ 0x2007, + /* 8 - _08 */ 0x2008, + /* 9 - _09 */ 0x2009, + /* a - _0A */ 0x200a, + /* b - _0B */ 0x200b, + /* c - _0C */ 0x200c, + /* d - _0D */ 0x200d, + /* e - _0E */ 0x200e, + /* f - _0F */ 0x8100, + /* 10 - _10 */ 0x200f, + /* 11 - _11 */ 0x2010, + /* 12 - _12 */ 0x2011, + /* 13 - _13 */ 0x2012, + /* 14 - _14 */ 0x2013, + /* 15 - _15 */ 0x2014, + /* 16 - _16 */ 0x2015, + /* 17 - _17 */ 0x2016, + /* 18 - _18 */ 0x2017, + /* 19 - _19 */ 0x2018, + /* 1a - _1A */ 0x2019, + /* 1b - _1B */ 0x201a, + /* 1c - _1C */ 0x201b, + /* 1d - _1D */ 0x201c, + /* 1e - _1E */ 0x201d, + /* 1f - _1F */ 0x201e, + /* 20 - _20 */ 0x201f, + /* 21 - _21 */ 0x2020, + /* 22 - _22 */ 0x2021, + /* 23 - _23 */ 0x2022, + /* 24 - _24 */ 0x2023, + /* 25 - _25 */ 0x2024, + /* 26 - */ 0, + /* 27 - _27 */ 0x2025, + /* 28 - _28 */ 0x2026, + /* 29 - _29 */ 0x2027, + /* 2a - _2A */ 0x2028, + /* 2b - _2B */ 0x2029, + /* 2c - _2C */ 0x202a, + /* 2d - _2D */ 0x202b, + /* 2e - */ 0, + /* 2f - _2F */ 0x202c, + /* 30 - _30 */ 0x202d, + /* 31 - _31 */ 0x202e, + /* 32 - _32 */ 0x202f, + /* 33 - _33 */ 0x2030, + /* 34 - _34 */ 0x2031, + /* 35 - _35 */ 0x2032, + /* 36 - */ 0, + /* 37 - _37 */ 0x2033, + /* 38 - _38 */ 0x2034, + /* 39 - _39 */ 0x2035, + /* 3a - _3A */ 0x2036, + /* 3b - _3B */ 0x2037, + /* 3c - _3C */ 0x2038, + /* 3d - _3D */ 0x2039, + /* 3e - */ 0, + /* 3f - _3F */ 0x203a, + /* 40 - _40 */ 0x203b, + /* 41 - _40 */ 0x203c, + /* 42 - _40 */ 0x203d, + /* 43 - _40 */ 0x203e, + /* 44 - _40 */ 0x203f, + /* 45 - _40 */ 0x2040, + /* 46 - _40 */ 0x2041, + /* 47 - _40 */ 0x2042, + /* 48 - _48 */ 0x2043, + /* 49 - _48 */ 0x2044, + /* 4a - _48 */ 0x2045, + /* 4b - _48 */ 0x2046, + /* 4c - _48 */ 0x2047, + /* 4d - _48 */ 0x2048, + /* 4e - _48 */ 0x2049, + /* 4f - _48 */ 0x204a, + /* 50 - _50 */ 0x204b, + /* 51 - _50 */ 0x204c, + /* 52 - _50 */ 0x204d, + /* 53 - _50 */ 0x204e, + /* 54 - _50 */ 0x204f, + /* 55 - _50 */ 0x2050, + /* 56 - _50 */ 0x2051, + /* 57 - _50 */ 0x2052, + /* 58 - _58 */ 0x2053, + /* 59 - _58 */ 0x2054, + /* 5a - _58 */ 0x2055, + /* 5b - _58 */ 0x2056, + /* 5c - _58 */ 0x2057, + /* 5d - _58 */ 0x2058, + /* 5e - _58 */ 0x2059, + /* 5f - _58 */ 0x205a, + /* 60 - _60 */ 0x205b, + /* 61 - _61 */ 0x205c, + /* 62 - _62 */ 0x205d, + /* 63 - _63 */ 0x205e, + /* 64 - */ 0, + /* 65 - */ 0, + /* 66 - */ 0, + /* 67 - */ 0, + /* 68 - _68 */ 0x205f, + /* 69 - _69 */ 0x4000, + /* 6a - _6A */ 0x2060, + /* 6b - _6B */ 0x4001, + /* 6c - _6C */ 0x2061, + /* 6d - _6D */ 0x2062, + /* 6e - _6E */ 0x2063, + /* 6f - _6F */ 0x2064, + /* 70 - _70 */ 0x2065, + /* 71 - _71 */ 0x2066, + /* 72 - _72 */ 0x2067, + /* 73 - _73 */ 0x2068, + /* 74 - _74 */ 0x2069, + /* 75 - _75 */ 0x206a, + /* 76 - _76 */ 0x206b, + /* 77 - _77 */ 0x206c, + /* 78 - _78 */ 0x206d, + /* 79 - _79 */ 0x206e, + /* 7a - _7A */ 0x206f, + /* 7b - _7B */ 0x2070, + /* 7c - _7C */ 0x2071, + /* 7d - _7D */ 0x2072, + /* 7e - _7E */ 0x2073, + /* 7f - _7F */ 0x2074, + /* 80 - _80 */ 0x6200, + /* 81 - _81 */ 0x6208, + /* 82 - _82 */ 0x6210, + /* 83 - _83 */ 0x6218, + /* 84 - _84 */ 0x2075, + /* 85 - _85 */ 0x2076, + /* 86 - _86 */ 0x2077, + /* 87 - _87 */ 0x2078, + /* 88 - _88 */ 0x2079, + /* 89 - _89 */ 0x207a, + /* 8a - _8A */ 0x207b, + /* 8b - _8B */ 0x207c, + /* 8c - _8C */ 0x207d, + /* 8d - _8D */ 0x207e, + /* 8e - _8E */ 0x207f, + /* 8f - _8F */ 0x6220, + /* 90 - _90 */ 0x2080, + /* 91 - _91 */ 0x2081, + /* 92 - _92 */ 0x2082, + /* 93 - _93 */ 0x2083, + /* 94 - _94 */ 0x2084, + /* 95 - _95 */ 0x2085, + /* 96 - _96 */ 0x2086, + /* 97 - _97 */ 0x2087, + /* 98 - _98 */ 0x4002, + /* 99 - _99 */ 0x4003, + /* 9a - _9A */ 0x2088, + /* 9b - */ 0, + /* 9c - _9C */ 0x2089, + /* 9d - _9D */ 0x208a, + /* 9e - _9E */ 0x208b, + /* 9f - _9F */ 0x208c, + /* a0 - _A0 */ 0x208d, + /* a1 - _A1 */ 0x208e, + /* a2 - _A2 */ 0x208f, + /* a3 - _A3 */ 0x2090, + /* a4 - _A4 */ 0x2091, + /* a5 - _A5 */ 0x2092, + /* a6 - _A6 */ 0x2093, + /* a7 - _A7 */ 0x2094, + /* a8 - _A8 */ 0x2095, + /* a9 - _A9 */ 0x2096, + /* aa - _AA */ 0x2097, + /* ab - _AB */ 0x2098, + /* ac - _AC */ 0x2099, + /* ad - _AD */ 0x209a, + /* ae - _AE */ 0x209b, + /* af - _AF */ 0x209c, + /* b0 - _B0 */ 0x209d, + /* b1 - _B0 */ 0x209e, + /* b2 - _B0 */ 0x209f, + /* b3 - _B0 */ 0x20a0, + /* b4 - _B0 */ 0x20a1, + /* b5 - _B0 */ 0x20a2, + /* b6 - _B0 */ 0x20a3, + /* b7 - _B0 */ 0x20a4, + /* b8 - _B8 */ 0x20a5, + /* b9 - _B8 */ 0x20a6, + /* ba - _B8 */ 0x20a7, + /* bb - _B8 */ 0x20a8, + /* bc - _B8 */ 0x20a9, + /* bd - _B8 */ 0x20aa, + /* be - _B8 */ 0x20ab, + /* bf - _B8 */ 0x20ac, + /* c0 - _C0 */ 0x6228, + /* c1 - _C1 */ 0x6230, + /* c2 - _C2 */ 0x20ad, + /* c3 - _C3 */ 0x20ae, + /* c4 - _C4 */ 0x20af, + /* c5 - _C5 */ 0x20b0, + /* c6 - _C6 */ 0xa238, + /* c7 - _C7 */ 0xa280, + /* c8 - _C8 */ 0x20b1, + /* c9 - _C9 */ 0x20b2, + /* ca - _CA */ 0x20b3, + /* cb - _CB */ 0x20b4, + /* cc - _CC */ 0x20b5, + /* cd - _CD */ 0x20b6, + /* ce - _CE */ 0x20b7, + /* cf - _CF */ 0x20b8, + /* d0 - _D0 */ 0x62c8, + /* d1 - _D1 */ 0x62d0, + /* d2 - _D2 */ 0x62d8, + /* d3 - _D3 */ 0x62e0, + /* d4 - _D4 */ 0x20b9, + /* d5 - _D5 */ 0x20ba, + /* d6 - _D6 */ 0x20bb, + /* d7 - _D7 */ 0x20bc, + /* d8 - _D8 */ 0xa2e8, + /* d9 - _D9 */ 0xa330, + /* da - _DA */ 0xa378, + /* db - _DB */ 0xa3c0, + /* dc - _DC */ 0xa408, + /* dd - _DD */ 0xa450, + /* de - _DE */ 0xa498, + /* df - _DF */ 0xa4e0, + /* e0 - _E0 */ 0x20bd, + /* e1 - _E1 */ 0x20be, + /* e2 - _E2 */ 0x20bf, + /* e3 - _E3 */ 0x4004, + /* e4 - _E4 */ 0x20c0, + /* e5 - _E5 */ 0x20c1, + /* e6 - _E6 */ 0x20c2, + /* e7 - _E7 */ 0x20c3, + /* e8 - _E8 */ 0x20c4, + /* e9 - _E9 */ 0x20c5, + /* ea - _EA */ 0x20c6, + /* eb - _EB */ 0x20c7, + /* ec - _EC */ 0x20c8, + /* ed - _ED */ 0x20c9, + /* ee - _EE */ 0x20ca, + /* ef - _EF */ 0x20cb, + /* f0 - */ 0, + /* f1 - _F1 */ 0x20cc, + /* f2 - */ 0, + /* f3 - */ 0, + /* f4 - _F4 */ 0x20cd, + /* f5 - _F5 */ 0x20ce, + /* f6 - _F6 */ 0x6528, + /* f7 - _F7 */ 0x6530, + /* f8 - _F8 */ 0x20cf, + /* f9 - _F9 */ 0x20d0, + /* fa - _FA */ 0x20d1, + /* fb - _FB */ 0x20d2, + /* fc - _FC */ 0x20d3, + /* fd - _FD */ 0x20d4, + /* fe - _FE */ 0x6538, + /* ff - _FF */ 0x6540, + /* 100 - _0F_00 */ 0x6548, + /* 101 - _0F_01 */ 0xa550, + /* 102 - _0F_02 */ 0x20d5, + /* 103 - _0F_03 */ 0x20d6, + /* 104 - */ 0, + /* 105 - _0F_05 */ 0x20d7, + /* 106 - _0F_06 */ 0x20d8, + /* 107 - _0F_07 */ 0x20d9, + /* 108 - _0F_08 */ 0x20da, + /* 109 - _0F_09 */ 0x20db, + /* 10a - */ 0, + /* 10b - _0F_0B */ 0x20dc, + /* 10c - */ 0, + /* 10d - _0F_0D */ 0x6598, + /* 10e - _0F_0E */ 0x20dd, + /* 10f - _0F_0F */ 0x85a0, + /* 110 - _0F_10 */ 0xc6a0, + /* 111 - _0F_11 */ 0xc6ac, + /* 112 - _0F_12 */ 0xc6b8, + /* 113 - _0F_13 */ 0xc6c4, + /* 114 - _0F_14 */ 0xc6d0, + /* 115 - _0F_15 */ 0xc6dc, + /* 116 - _0F_16 */ 0xc6e8, + /* 117 - _0F_17 */ 0xc6f4, + /* 118 - _0F_18 */ 0x6700, + /* 119 - */ 0, + /* 11a - */ 0, + /* 11b - */ 0, + /* 11c - */ 0, + /* 11d - */ 0, + /* 11e - */ 0, + /* 11f - _0F_1F */ 0x20de, + /* 120 - _0F_20 */ 0x20df, + /* 121 - _0F_21 */ 0x20e0, + /* 122 - _0F_22 */ 0x20e1, + /* 123 - _0F_23 */ 0x20e2, + /* 124 - */ 0, + /* 125 - */ 0, + /* 126 - */ 0, + /* 127 - */ 0, + /* 128 - _0F_28 */ 0xc708, + /* 129 - _0F_29 */ 0xc714, + /* 12a - _0F_2A */ 0xc720, + /* 12b - _0F_2B */ 0xc72c, + /* 12c - _0F_2C */ 0xc738, + /* 12d - _0F_2D */ 0xc744, + /* 12e - _0F_2E */ 0xc750, + /* 12f - _0F_2F */ 0xc75c, + /* 130 - _0F_30 */ 0x20e3, + /* 131 - _0F_31 */ 0x20e4, + /* 132 - _0F_32 */ 0x20e5, + /* 133 - _0F_33 */ 0x20e6, + /* 134 - _0F_34 */ 0x20e7, + /* 135 - _0F_35 */ 0x20e8, + /* 136 - */ 0, + /* 137 - _0F_37 */ 0x20e9, + /* 138 - _0F_38 */ 0x8768, + /* 139 - */ 0, + /* 13a - _0F_3A */ 0x8868, + /* 13b - */ 0, + /* 13c - */ 0, + /* 13d - */ 0, + /* 13e - */ 0, + /* 13f - */ 0, + /* 140 - _0F_40 */ 0x20ea, + /* 141 - _0F_41 */ 0x20eb, + /* 142 - _0F_42 */ 0x20ec, + /* 143 - _0F_43 */ 0x20ed, + /* 144 - _0F_44 */ 0x20ee, + /* 145 - _0F_45 */ 0x20ef, + /* 146 - _0F_46 */ 0x20f0, + /* 147 - _0F_47 */ 0x20f1, + /* 148 - _0F_48 */ 0x20f2, + /* 149 - _0F_49 */ 0x20f3, + /* 14a - _0F_4A */ 0x20f4, + /* 14b - _0F_4B */ 0x20f5, + /* 14c - _0F_4C */ 0x20f6, + /* 14d - _0F_4D */ 0x20f7, + /* 14e - _0F_4E */ 0x20f8, + /* 14f - _0F_4F */ 0x20f9, + /* 150 - _0F_50 */ 0xc968, + /* 151 - _0F_51 */ 0xc974, + /* 152 - _0F_52 */ 0xc980, + /* 153 - _0F_53 */ 0xc98c, + /* 154 - _0F_54 */ 0xc998, + /* 155 - _0F_55 */ 0xc9a4, + /* 156 - _0F_56 */ 0xc9b0, + /* 157 - _0F_57 */ 0xc9bc, + /* 158 - _0F_58 */ 0xc9c8, + /* 159 - _0F_59 */ 0xc9d4, + /* 15a - _0F_5A */ 0xc9e0, + /* 15b - _0F_5B */ 0xc9ec, + /* 15c - _0F_5C */ 0xc9f8, + /* 15d - _0F_5D */ 0xca04, + /* 15e - _0F_5E */ 0xca10, + /* 15f - _0F_5F */ 0xca1c, + /* 160 - _0F_60 */ 0xca28, + /* 161 - _0F_61 */ 0xca34, + /* 162 - _0F_62 */ 0xca40, + /* 163 - _0F_63 */ 0xca4c, + /* 164 - _0F_64 */ 0xca58, + /* 165 - _0F_65 */ 0xca64, + /* 166 - _0F_66 */ 0xca70, + /* 167 - _0F_67 */ 0xca7c, + /* 168 - _0F_68 */ 0xca88, + /* 169 - _0F_69 */ 0xca94, + /* 16a - _0F_6A */ 0xcaa0, + /* 16b - _0F_6B */ 0xcaac, + /* 16c - _0F_6C */ 0xcab8, + /* 16d - _0F_6D */ 0xcac4, + /* 16e - _0F_6E */ 0xcad0, + /* 16f - _0F_6F */ 0xcadc, + /* 170 - _0F_70 */ 0xcae8, + /* 171 - _0F_71 */ 0x6af4, + /* 172 - _0F_72 */ 0x6afc, + /* 173 - _0F_73 */ 0x6b04, + /* 174 - _0F_74 */ 0xcb0c, + /* 175 - _0F_75 */ 0xcb18, + /* 176 - _0F_76 */ 0xcb24, + /* 177 - _0F_77 */ 0xcb30, + /* 178 - _0F_78 */ 0xcb3c, + /* 179 - _0F_79 */ 0xcb48, + /* 17a - _0F_7A */ 0x8b54, + /* 17b - */ 0, + /* 17c - _0F_7C */ 0xcc54, + /* 17d - _0F_7D */ 0xcc60, + /* 17e - _0F_7E */ 0xcc6c, + /* 17f - _0F_7F */ 0xcc78, + /* 180 - _0F_80 */ 0x20fa, + /* 181 - _0F_81 */ 0x20fb, + /* 182 - _0F_82 */ 0x20fc, + /* 183 - _0F_83 */ 0x20fd, + /* 184 - _0F_84 */ 0x20fe, + /* 185 - _0F_85 */ 0x20ff, + /* 186 - _0F_86 */ 0x2100, + /* 187 - _0F_87 */ 0x2101, + /* 188 - _0F_88 */ 0x2102, + /* 189 - _0F_89 */ 0x2103, + /* 18a - _0F_8A */ 0x2104, + /* 18b - _0F_8B */ 0x2105, + /* 18c - _0F_8C */ 0x2106, + /* 18d - _0F_8D */ 0x2107, + /* 18e - _0F_8E */ 0x2108, + /* 18f - _0F_8F */ 0x2109, + /* 190 - _0F_90 */ 0x210a, + /* 191 - _0F_91 */ 0x210b, + /* 192 - _0F_92 */ 0x210c, + /* 193 - _0F_93 */ 0x210d, + /* 194 - _0F_94 */ 0x210e, + /* 195 - _0F_95 */ 0x210f, + /* 196 - _0F_96 */ 0x2110, + /* 197 - _0F_97 */ 0x2111, + /* 198 - _0F_98 */ 0x2112, + /* 199 - _0F_99 */ 0x2113, + /* 19a - _0F_9A */ 0x2114, + /* 19b - _0F_9B */ 0x2115, + /* 19c - _0F_9C */ 0x2116, + /* 19d - _0F_9D */ 0x2117, + /* 19e - _0F_9E */ 0x2118, + /* 19f - _0F_9F */ 0x2119, + /* 1a0 - _0F_A0 */ 0x211a, + /* 1a1 - _0F_A1 */ 0x211b, + /* 1a2 - _0F_A2 */ 0x211c, + /* 1a3 - _0F_A3 */ 0x211d, + /* 1a4 - _0F_A4 */ 0x4005, + /* 1a5 - _0F_A5 */ 0x4006, + /* 1a6 - */ 0, + /* 1a7 - */ 0, + /* 1a8 - _0F_A8 */ 0x211e, + /* 1a9 - _0F_A9 */ 0x211f, + /* 1aa - _0F_AA */ 0x2120, + /* 1ab - _0F_AB */ 0x2121, + /* 1ac - _0F_AC */ 0x4007, + /* 1ad - _0F_AD */ 0x4008, + /* 1ae - _0F_AE */ 0x6c84, + /* 1af - _0F_AF */ 0x2122, + /* 1b0 - _0F_B0 */ 0x2123, + /* 1b1 - _0F_B1 */ 0x2124, + /* 1b2 - _0F_B2 */ 0x2125, + /* 1b3 - _0F_B3 */ 0x2126, + /* 1b4 - _0F_B4 */ 0x2127, + /* 1b5 - _0F_B5 */ 0x2128, + /* 1b6 - _0F_B6 */ 0x2129, + /* 1b7 - _0F_B7 */ 0x212a, + /* 1b8 - _0F_B8 */ 0xcc8c, + /* 1b9 - _0F_B9 */ 0x212b, + /* 1ba - _0F_BA */ 0x6c98, + /* 1bb - _0F_BB */ 0x212c, + /* 1bc - _0F_BC */ 0xcca0, + /* 1bd - _0F_BD */ 0xccac, + /* 1be - _0F_BE */ 0x212d, + /* 1bf - _0F_BF */ 0x212e, + /* 1c0 - _0F_C0 */ 0x212f, + /* 1c1 - _0F_C1 */ 0x2130, + /* 1c2 - _0F_C2 */ 0xccb8, + /* 1c3 - _0F_C3 */ 0x2131, + /* 1c4 - _0F_C4 */ 0xccc4, + /* 1c5 - _0F_C5 */ 0xccd0, + /* 1c6 - _0F_C6 */ 0xccdc, + /* 1c7 - _0F_C7 */ 0x6ce8, + /* 1c8 - _0F_C8 */ 0x2132, + /* 1c9 - _0F_C8 */ 0x2133, + /* 1ca - _0F_C8 */ 0x2134, + /* 1cb - _0F_C8 */ 0x2135, + /* 1cc - _0F_C8 */ 0x2136, + /* 1cd - _0F_C8 */ 0x2137, + /* 1ce - _0F_C8 */ 0x2138, + /* 1cf - _0F_C8 */ 0x2139, + /* 1d0 - _0F_D0 */ 0xccf0, + /* 1d1 - _0F_D1 */ 0xccfc, + /* 1d2 - _0F_D2 */ 0xcd08, + /* 1d3 - _0F_D3 */ 0xcd14, + /* 1d4 - _0F_D4 */ 0xcd20, + /* 1d5 - _0F_D5 */ 0xcd2c, + /* 1d6 - _0F_D6 */ 0xcd38, + /* 1d7 - _0F_D7 */ 0xcd44, + /* 1d8 - _0F_D8 */ 0xcd50, + /* 1d9 - _0F_D9 */ 0xcd5c, + /* 1da - _0F_DA */ 0xcd68, + /* 1db - _0F_DB */ 0xcd74, + /* 1dc - _0F_DC */ 0xcd80, + /* 1dd - _0F_DD */ 0xcd8c, + /* 1de - _0F_DE */ 0xcd98, + /* 1df - _0F_DF */ 0xcda4, + /* 1e0 - _0F_E0 */ 0xcdb0, + /* 1e1 - _0F_E1 */ 0xcdbc, + /* 1e2 - _0F_E2 */ 0xcdc8, + /* 1e3 - _0F_E3 */ 0xcdd4, + /* 1e4 - _0F_E4 */ 0xcde0, + /* 1e5 - _0F_E5 */ 0xcdec, + /* 1e6 - _0F_E6 */ 0xcdf8, + /* 1e7 - _0F_E7 */ 0xce04, + /* 1e8 - _0F_E8 */ 0xce10, + /* 1e9 - _0F_E9 */ 0xce1c, + /* 1ea - _0F_EA */ 0xce28, + /* 1eb - _0F_EB */ 0xce34, + /* 1ec - _0F_EC */ 0xce40, + /* 1ed - _0F_ED */ 0xce4c, + /* 1ee - _0F_EE */ 0xce58, + /* 1ef - _0F_EF */ 0xce64, + /* 1f0 - _0F_F0 */ 0xce70, + /* 1f1 - _0F_F1 */ 0xce7c, + /* 1f2 - _0F_F2 */ 0xce88, + /* 1f3 - _0F_F3 */ 0xce94, + /* 1f4 - _0F_F4 */ 0xcea0, + /* 1f5 - _0F_F5 */ 0xceac, + /* 1f6 - _0F_F6 */ 0xceb8, + /* 1f7 - _0F_F7 */ 0xcec4, + /* 1f8 - _0F_F8 */ 0xced0, + /* 1f9 - _0F_F9 */ 0xcedc, + /* 1fa - _0F_FA */ 0xcee8, + /* 1fb - _0F_FB */ 0xcef4, + /* 1fc - _0F_FC */ 0xcf00, + /* 1fd - _0F_FD */ 0xcf0c, + /* 1fe - _0F_FE */ 0xcf18, + /* 1ff - */ 0, + /* 200 - _80_00 */ 0x213a, + /* 201 - _80_01 */ 0x213b, + /* 202 - _80_02 */ 0x213c, + /* 203 - _80_03 */ 0x213d, + /* 204 - _80_04 */ 0x213e, + /* 205 - _80_05 */ 0x213f, + /* 206 - _80_06 */ 0x2140, + /* 207 - _80_07 */ 0x2141, + /* 208 - _81_00 */ 0x2142, + /* 209 - _81_01 */ 0x2143, + /* 20a - _81_02 */ 0x2144, + /* 20b - _81_03 */ 0x2145, + /* 20c - _81_04 */ 0x2146, + /* 20d - _81_05 */ 0x2147, + /* 20e - _81_06 */ 0x2148, + /* 20f - _81_07 */ 0x2149, + /* 210 - _82_00 */ 0x214a, + /* 211 - _82_01 */ 0x214b, + /* 212 - _82_02 */ 0x214c, + /* 213 - _82_03 */ 0x214d, + /* 214 - _82_04 */ 0x214e, + /* 215 - _82_05 */ 0x214f, + /* 216 - _82_06 */ 0x2150, + /* 217 - _82_07 */ 0x2151, + /* 218 - _83_00 */ 0x2152, + /* 219 - _83_01 */ 0x2153, + /* 21a - _83_02 */ 0x2154, + /* 21b - _83_03 */ 0x2155, + /* 21c - _83_04 */ 0x2156, + /* 21d - _83_05 */ 0x2157, + /* 21e - _83_06 */ 0x2158, + /* 21f - _83_07 */ 0x2159, + /* 220 - _8F_00 */ 0x215a, + /* 221 - */ 0, + /* 222 - */ 0, + /* 223 - */ 0, + /* 224 - */ 0, + /* 225 - */ 0, + /* 226 - */ 0, + /* 227 - */ 0, + /* 228 - _C0_00 */ 0x215b, + /* 229 - _C0_01 */ 0x215c, + /* 22a - _C0_02 */ 0x215d, + /* 22b - _C0_03 */ 0x215e, + /* 22c - _C0_04 */ 0x215f, + /* 22d - _C0_05 */ 0x2160, + /* 22e - _C0_06 */ 0x2161, + /* 22f - _C0_07 */ 0x2162, + /* 230 - _C1_00 */ 0x2163, + /* 231 - _C1_01 */ 0x2164, + /* 232 - _C1_02 */ 0x2165, + /* 233 - _C1_03 */ 0x2166, + /* 234 - _C1_04 */ 0x2167, + /* 235 - _C1_05 */ 0x2168, + /* 236 - _C1_06 */ 0x2169, + /* 237 - _C1_07 */ 0x216a, + /* 238 - _C6_00 */ 0x216b, + /* 239 - */ 0, + /* 23a - */ 0, + /* 23b - */ 0, + /* 23c - */ 0, + /* 23d - */ 0, + /* 23e - */ 0, + /* 23f - */ 0, + /* 240 - */ 0, + /* 241 - */ 0, + /* 242 - */ 0, + /* 243 - */ 0, + /* 244 - */ 0, + /* 245 - */ 0, + /* 246 - */ 0, + /* 247 - */ 0, + /* 248 - */ 0, + /* 249 - */ 0, + /* 24a - */ 0, + /* 24b - */ 0, + /* 24c - */ 0, + /* 24d - */ 0, + /* 24e - */ 0, + /* 24f - */ 0, + /* 250 - */ 0, + /* 251 - */ 0, + /* 252 - */ 0, + /* 253 - */ 0, + /* 254 - */ 0, + /* 255 - */ 0, + /* 256 - */ 0, + /* 257 - */ 0, + /* 258 - */ 0, + /* 259 - */ 0, + /* 25a - */ 0, + /* 25b - */ 0, + /* 25c - */ 0, + /* 25d - */ 0, + /* 25e - */ 0, + /* 25f - */ 0, + /* 260 - */ 0, + /* 261 - */ 0, + /* 262 - */ 0, + /* 263 - */ 0, + /* 264 - */ 0, + /* 265 - */ 0, + /* 266 - */ 0, + /* 267 - */ 0, + /* 268 - */ 0, + /* 269 - */ 0, + /* 26a - */ 0, + /* 26b - */ 0, + /* 26c - */ 0, + /* 26d - */ 0, + /* 26e - */ 0, + /* 26f - */ 0, + /* 270 - */ 0, + /* 271 - */ 0, + /* 272 - */ 0, + /* 273 - */ 0, + /* 274 - */ 0, + /* 275 - */ 0, + /* 276 - */ 0, + /* 277 - */ 0, + /* 278 - _C6_F8 */ 0x216c, + /* 279 - */ 0, + /* 27a - */ 0, + /* 27b - */ 0, + /* 27c - */ 0, + /* 27d - */ 0, + /* 27e - */ 0, + /* 27f - */ 0, + /* 280 - _C7_00 */ 0x216d, + /* 281 - */ 0, + /* 282 - */ 0, + /* 283 - */ 0, + /* 284 - */ 0, + /* 285 - */ 0, + /* 286 - */ 0, + /* 287 - */ 0, + /* 288 - */ 0, + /* 289 - */ 0, + /* 28a - */ 0, + /* 28b - */ 0, + /* 28c - */ 0, + /* 28d - */ 0, + /* 28e - */ 0, + /* 28f - */ 0, + /* 290 - */ 0, + /* 291 - */ 0, + /* 292 - */ 0, + /* 293 - */ 0, + /* 294 - */ 0, + /* 295 - */ 0, + /* 296 - */ 0, + /* 297 - */ 0, + /* 298 - */ 0, + /* 299 - */ 0, + /* 29a - */ 0, + /* 29b - */ 0, + /* 29c - */ 0, + /* 29d - */ 0, + /* 29e - */ 0, + /* 29f - */ 0, + /* 2a0 - */ 0, + /* 2a1 - */ 0, + /* 2a2 - */ 0, + /* 2a3 - */ 0, + /* 2a4 - */ 0, + /* 2a5 - */ 0, + /* 2a6 - */ 0, + /* 2a7 - */ 0, + /* 2a8 - */ 0, + /* 2a9 - */ 0, + /* 2aa - */ 0, + /* 2ab - */ 0, + /* 2ac - */ 0, + /* 2ad - */ 0, + /* 2ae - */ 0, + /* 2af - */ 0, + /* 2b0 - */ 0, + /* 2b1 - */ 0, + /* 2b2 - */ 0, + /* 2b3 - */ 0, + /* 2b4 - */ 0, + /* 2b5 - */ 0, + /* 2b6 - */ 0, + /* 2b7 - */ 0, + /* 2b8 - */ 0, + /* 2b9 - */ 0, + /* 2ba - */ 0, + /* 2bb - */ 0, + /* 2bc - */ 0, + /* 2bd - */ 0, + /* 2be - */ 0, + /* 2bf - */ 0, + /* 2c0 - _C7_F8 */ 0x216e, + /* 2c1 - */ 0, + /* 2c2 - */ 0, + /* 2c3 - */ 0, + /* 2c4 - */ 0, + /* 2c5 - */ 0, + /* 2c6 - */ 0, + /* 2c7 - */ 0, + /* 2c8 - _D0_00 */ 0x216f, + /* 2c9 - _D0_01 */ 0x2170, + /* 2ca - _D0_02 */ 0x2171, + /* 2cb - _D0_03 */ 0x2172, + /* 2cc - _D0_04 */ 0x2173, + /* 2cd - _D0_05 */ 0x2174, + /* 2ce - _D0_06 */ 0x2175, + /* 2cf - _D0_07 */ 0x2176, + /* 2d0 - _D1_00 */ 0x2177, + /* 2d1 - _D1_01 */ 0x2178, + /* 2d2 - _D1_02 */ 0x2179, + /* 2d3 - _D1_03 */ 0x217a, + /* 2d4 - _D1_04 */ 0x217b, + /* 2d5 - _D1_05 */ 0x217c, + /* 2d6 - _D1_06 */ 0x217d, + /* 2d7 - _D1_07 */ 0x217e, + /* 2d8 - _D2_00 */ 0x217f, + /* 2d9 - _D2_01 */ 0x2180, + /* 2da - _D2_02 */ 0x2181, + /* 2db - _D2_03 */ 0x2182, + /* 2dc - _D2_04 */ 0x2183, + /* 2dd - _D2_05 */ 0x2184, + /* 2de - _D2_06 */ 0x2185, + /* 2df - _D2_07 */ 0x2186, + /* 2e0 - _D3_00 */ 0x2187, + /* 2e1 - _D3_01 */ 0x2188, + /* 2e2 - _D3_02 */ 0x2189, + /* 2e3 - _D3_03 */ 0x218a, + /* 2e4 - _D3_04 */ 0x218b, + /* 2e5 - _D3_05 */ 0x218c, + /* 2e6 - _D3_06 */ 0x218d, + /* 2e7 - _D3_07 */ 0x218e, + /* 2e8 - _D8_00 */ 0x218f, + /* 2e9 - _D8_01 */ 0x2190, + /* 2ea - _D8_02 */ 0x2191, + /* 2eb - _D8_03 */ 0x2192, + /* 2ec - _D8_04 */ 0x2193, + /* 2ed - _D8_05 */ 0x2194, + /* 2ee - _D8_06 */ 0x2195, + /* 2ef - _D8_07 */ 0x2196, + /* 2f0 - _D8_C0 */ 0x2197, + /* 2f1 - _D8_C0 */ 0x2198, + /* 2f2 - _D8_C0 */ 0x2199, + /* 2f3 - _D8_C0 */ 0x219a, + /* 2f4 - _D8_C0 */ 0x219b, + /* 2f5 - _D8_C0 */ 0x219c, + /* 2f6 - _D8_C0 */ 0x219d, + /* 2f7 - _D8_C0 */ 0x219e, + /* 2f8 - _D8_C8 */ 0x219f, + /* 2f9 - _D8_C8 */ 0x21a0, + /* 2fa - _D8_C8 */ 0x21a1, + /* 2fb - _D8_C8 */ 0x21a2, + /* 2fc - _D8_C8 */ 0x21a3, + /* 2fd - _D8_C8 */ 0x21a4, + /* 2fe - _D8_C8 */ 0x21a5, + /* 2ff - _D8_C8 */ 0x21a6, + /* 300 - _D8_D0 */ 0x21a7, + /* 301 - _D8_D0 */ 0x21a8, + /* 302 - _D8_D0 */ 0x21a9, + /* 303 - _D8_D0 */ 0x21aa, + /* 304 - _D8_D0 */ 0x21ab, + /* 305 - _D8_D0 */ 0x21ac, + /* 306 - _D8_D0 */ 0x21ad, + /* 307 - _D8_D0 */ 0x21ae, + /* 308 - _D8_D8 */ 0x21af, + /* 309 - _D8_D9 */ 0x21b0, + /* 30a - _D8_D8 */ 0x21b1, + /* 30b - _D8_D8 */ 0x21b2, + /* 30c - _D8_D8 */ 0x21b3, + /* 30d - _D8_D8 */ 0x21b4, + /* 30e - _D8_D8 */ 0x21b5, + /* 30f - _D8_D8 */ 0x21b6, + /* 310 - _D8_E0 */ 0x21b7, + /* 311 - _D8_E0 */ 0x21b8, + /* 312 - _D8_E0 */ 0x21b9, + /* 313 - _D8_E0 */ 0x21ba, + /* 314 - _D8_E0 */ 0x21bb, + /* 315 - _D8_E0 */ 0x21bc, + /* 316 - _D8_E0 */ 0x21bd, + /* 317 - _D8_E0 */ 0x21be, + /* 318 - _D8_E8 */ 0x21bf, + /* 319 - _D8_E8 */ 0x21c0, + /* 31a - _D8_E8 */ 0x21c1, + /* 31b - _D8_E8 */ 0x21c2, + /* 31c - _D8_E8 */ 0x21c3, + /* 31d - _D8_E8 */ 0x21c4, + /* 31e - _D8_E8 */ 0x21c5, + /* 31f - _D8_E8 */ 0x21c6, + /* 320 - _D8_F0 */ 0x21c7, + /* 321 - _D8_F0 */ 0x21c8, + /* 322 - _D8_F0 */ 0x21c9, + /* 323 - _D8_F0 */ 0x21ca, + /* 324 - _D8_F0 */ 0x21cb, + /* 325 - _D8_F0 */ 0x21cc, + /* 326 - _D8_F0 */ 0x21cd, + /* 327 - _D8_F0 */ 0x21ce, + /* 328 - _D8_F8 */ 0x21cf, + /* 329 - _D8_F8 */ 0x21d0, + /* 32a - _D8_F8 */ 0x21d1, + /* 32b - _D8_F8 */ 0x21d2, + /* 32c - _D8_F8 */ 0x21d3, + /* 32d - _D8_F8 */ 0x21d4, + /* 32e - _D8_F8 */ 0x21d5, + /* 32f - _D8_F8 */ 0x21d6, + /* 330 - _D9_00 */ 0x21d7, + /* 331 - */ 0, + /* 332 - _D9_02 */ 0x21d8, + /* 333 - _D9_03 */ 0x21d9, + /* 334 - _D9_04 */ 0x21da, + /* 335 - _D9_05 */ 0x21db, + /* 336 - _D9_06 */ 0xcf24, + /* 337 - _D9_07 */ 0xcf30, + /* 338 - _D9_C0 */ 0x21dc, + /* 339 - _D9_C0 */ 0x21dd, + /* 33a - _D9_C0 */ 0x21de, + /* 33b - _D9_C0 */ 0x21df, + /* 33c - _D9_C0 */ 0x21e0, + /* 33d - _D9_C0 */ 0x21e1, + /* 33e - _D9_C0 */ 0x21e2, + /* 33f - _D9_C0 */ 0x21e3, + /* 340 - _D9_C8 */ 0x21e4, + /* 341 - _D9_C9 */ 0x21e5, + /* 342 - _D9_C8 */ 0x21e6, + /* 343 - _D9_C8 */ 0x21e7, + /* 344 - _D9_C8 */ 0x21e8, + /* 345 - _D9_C8 */ 0x21e9, + /* 346 - _D9_C8 */ 0x21ea, + /* 347 - _D9_C8 */ 0x21eb, + /* 348 - _D9_D0 */ 0x21ec, + /* 349 - */ 0, + /* 34a - */ 0, + /* 34b - */ 0, + /* 34c - */ 0, + /* 34d - */ 0, + /* 34e - */ 0, + /* 34f - */ 0, + /* 350 - */ 0, + /* 351 - */ 0, + /* 352 - */ 0, + /* 353 - */ 0, + /* 354 - */ 0, + /* 355 - */ 0, + /* 356 - */ 0, + /* 357 - */ 0, + /* 358 - _D9_E0 */ 0x21ed, + /* 359 - _D9_E1 */ 0x21ee, + /* 35a - */ 0, + /* 35b - */ 0, + /* 35c - _D9_E4 */ 0x21ef, + /* 35d - _D9_E5 */ 0x21f0, + /* 35e - */ 0, + /* 35f - */ 0, + /* 360 - _D9_E8 */ 0x21f1, + /* 361 - _D9_E9 */ 0x21f2, + /* 362 - _D9_EA */ 0x21f3, + /* 363 - _D9_EB */ 0x21f4, + /* 364 - _D9_EC */ 0x21f5, + /* 365 - _D9_ED */ 0x21f6, + /* 366 - _D9_EE */ 0x21f7, + /* 367 - */ 0, + /* 368 - _D9_F0 */ 0x21f8, + /* 369 - _D9_F1 */ 0x21f9, + /* 36a - _D9_F2 */ 0x21fa, + /* 36b - _D9_F3 */ 0x21fb, + /* 36c - _D9_F4 */ 0x21fc, + /* 36d - _D9_F5 */ 0x21fd, + /* 36e - _D9_F6 */ 0x21fe, + /* 36f - _D9_F7 */ 0x21ff, + /* 370 - _D9_F8 */ 0x2200, + /* 371 - _D9_F9 */ 0x2201, + /* 372 - _D9_FA */ 0x2202, + /* 373 - _D9_FB */ 0x2203, + /* 374 - _D9_FC */ 0x2204, + /* 375 - _D9_FD */ 0x2205, + /* 376 - _D9_FE */ 0x2206, + /* 377 - _D9_FF */ 0x2207, + /* 378 - _DA_00 */ 0x2208, + /* 379 - _DA_01 */ 0x2209, + /* 37a - _DA_02 */ 0x220a, + /* 37b - _DA_03 */ 0x220b, + /* 37c - _DA_04 */ 0x220c, + /* 37d - _DA_05 */ 0x220d, + /* 37e - _DA_06 */ 0x220e, + /* 37f - _DA_07 */ 0x220f, + /* 380 - _DA_C0 */ 0x2210, + /* 381 - _DA_C0 */ 0x2211, + /* 382 - _DA_C0 */ 0x2212, + /* 383 - _DA_C0 */ 0x2213, + /* 384 - _DA_C0 */ 0x2214, + /* 385 - _DA_C0 */ 0x2215, + /* 386 - _DA_C0 */ 0x2216, + /* 387 - _DA_C0 */ 0x2217, + /* 388 - _DA_C8 */ 0x2218, + /* 389 - _DA_C8 */ 0x2219, + /* 38a - _DA_C8 */ 0x221a, + /* 38b - _DA_C8 */ 0x221b, + /* 38c - _DA_C8 */ 0x221c, + /* 38d - _DA_C8 */ 0x221d, + /* 38e - _DA_C8 */ 0x221e, + /* 38f - _DA_C8 */ 0x221f, + /* 390 - _DA_D0 */ 0x2220, + /* 391 - _DA_D0 */ 0x2221, + /* 392 - _DA_D0 */ 0x2222, + /* 393 - _DA_D0 */ 0x2223, + /* 394 - _DA_D0 */ 0x2224, + /* 395 - _DA_D0 */ 0x2225, + /* 396 - _DA_D0 */ 0x2226, + /* 397 - _DA_D0 */ 0x2227, + /* 398 - _DA_D8 */ 0x2228, + /* 399 - _DA_D8 */ 0x2229, + /* 39a - _DA_D8 */ 0x222a, + /* 39b - _DA_D8 */ 0x222b, + /* 39c - _DA_D8 */ 0x222c, + /* 39d - _DA_D8 */ 0x222d, + /* 39e - _DA_D8 */ 0x222e, + /* 39f - _DA_D8 */ 0x222f, + /* 3a0 - */ 0, + /* 3a1 - */ 0, + /* 3a2 - */ 0, + /* 3a3 - */ 0, + /* 3a4 - */ 0, + /* 3a5 - */ 0, + /* 3a6 - */ 0, + /* 3a7 - */ 0, + /* 3a8 - */ 0, + /* 3a9 - _DA_E9 */ 0x2230, + /* 3aa - */ 0, + /* 3ab - */ 0, + /* 3ac - */ 0, + /* 3ad - */ 0, + /* 3ae - */ 0, + /* 3af - */ 0, + /* 3b0 - */ 0, + /* 3b1 - */ 0, + /* 3b2 - */ 0, + /* 3b3 - */ 0, + /* 3b4 - */ 0, + /* 3b5 - */ 0, + /* 3b6 - */ 0, + /* 3b7 - */ 0, + /* 3b8 - */ 0, + /* 3b9 - */ 0, + /* 3ba - */ 0, + /* 3bb - */ 0, + /* 3bc - */ 0, + /* 3bd - */ 0, + /* 3be - */ 0, + /* 3bf - */ 0, + /* 3c0 - _DB_00 */ 0x2231, + /* 3c1 - _DB_01 */ 0x2232, + /* 3c2 - _DB_02 */ 0x2233, + /* 3c3 - _DB_03 */ 0x2234, + /* 3c4 - */ 0, + /* 3c5 - _DB_05 */ 0x2235, + /* 3c6 - */ 0, + /* 3c7 - _DB_07 */ 0x2236, + /* 3c8 - _DB_C0 */ 0x2237, + /* 3c9 - _DB_C0 */ 0x2238, + /* 3ca - _DB_C0 */ 0x2239, + /* 3cb - _DB_C0 */ 0x223a, + /* 3cc - _DB_C0 */ 0x223b, + /* 3cd - _DB_C0 */ 0x223c, + /* 3ce - _DB_C0 */ 0x223d, + /* 3cf - _DB_C0 */ 0x223e, + /* 3d0 - _DB_C8 */ 0x223f, + /* 3d1 - _DB_C8 */ 0x2240, + /* 3d2 - _DB_C8 */ 0x2241, + /* 3d3 - _DB_C8 */ 0x2242, + /* 3d4 - _DB_C8 */ 0x2243, + /* 3d5 - _DB_C8 */ 0x2244, + /* 3d6 - _DB_C8 */ 0x2245, + /* 3d7 - _DB_C8 */ 0x2246, + /* 3d8 - _DB_D0 */ 0x2247, + /* 3d9 - _DB_D0 */ 0x2248, + /* 3da - _DB_D0 */ 0x2249, + /* 3db - _DB_D0 */ 0x224a, + /* 3dc - _DB_D0 */ 0x224b, + /* 3dd - _DB_D0 */ 0x224c, + /* 3de - _DB_D0 */ 0x224d, + /* 3df - _DB_D0 */ 0x224e, + /* 3e0 - _DB_D8 */ 0x224f, + /* 3e1 - _DB_D8 */ 0x2250, + /* 3e2 - _DB_D8 */ 0x2251, + /* 3e3 - _DB_D8 */ 0x2252, + /* 3e4 - _DB_D8 */ 0x2253, + /* 3e5 - _DB_D8 */ 0x2254, + /* 3e6 - _DB_D8 */ 0x2255, + /* 3e7 - _DB_D8 */ 0x2256, + /* 3e8 - _DB_E0 */ 0x2257, + /* 3e9 - _DB_E1 */ 0x2258, + /* 3ea - _DB_E2 */ 0xcf3c, + /* 3eb - _DB_E3 */ 0xcf48, + /* 3ec - _DB_E4 */ 0x2259, + /* 3ed - */ 0, + /* 3ee - */ 0, + /* 3ef - */ 0, + /* 3f0 - _DB_E8 */ 0x225a, + /* 3f1 - _DB_E8 */ 0x225b, + /* 3f2 - _DB_E8 */ 0x225c, + /* 3f3 - _DB_E8 */ 0x225d, + /* 3f4 - _DB_E8 */ 0x225e, + /* 3f5 - _DB_E8 */ 0x225f, + /* 3f6 - _DB_E8 */ 0x2260, + /* 3f7 - _DB_E8 */ 0x2261, + /* 3f8 - _DB_F0 */ 0x2262, + /* 3f9 - _DB_F0 */ 0x2263, + /* 3fa - _DB_F0 */ 0x2264, + /* 3fb - _DB_F0 */ 0x2265, + /* 3fc - _DB_F0 */ 0x2266, + /* 3fd - _DB_F0 */ 0x2267, + /* 3fe - _DB_F0 */ 0x2268, + /* 3ff - _DB_F0 */ 0x2269, + /* 400 - */ 0, + /* 401 - */ 0, + /* 402 - */ 0, + /* 403 - */ 0, + /* 404 - */ 0, + /* 405 - */ 0, + /* 406 - */ 0, + /* 407 - */ 0, + /* 408 - _DC_00 */ 0x226a, + /* 409 - _DC_01 */ 0x226b, + /* 40a - _DC_02 */ 0x226c, + /* 40b - _DC_03 */ 0x226d, + /* 40c - _DC_04 */ 0x226e, + /* 40d - _DC_05 */ 0x226f, + /* 40e - _DC_06 */ 0x2270, + /* 40f - _DC_07 */ 0x2271, + /* 410 - _DC_C0 */ 0x2272, + /* 411 - _DC_C0 */ 0x2273, + /* 412 - _DC_C0 */ 0x2274, + /* 413 - _DC_C0 */ 0x2275, + /* 414 - _DC_C0 */ 0x2276, + /* 415 - _DC_C0 */ 0x2277, + /* 416 - _DC_C0 */ 0x2278, + /* 417 - _DC_C0 */ 0x2279, + /* 418 - _DC_C8 */ 0x227a, + /* 419 - _DC_C8 */ 0x227b, + /* 41a - _DC_C8 */ 0x227c, + /* 41b - _DC_C8 */ 0x227d, + /* 41c - _DC_C8 */ 0x227e, + /* 41d - _DC_C8 */ 0x227f, + /* 41e - _DC_C8 */ 0x2280, + /* 41f - _DC_C8 */ 0x2281, + /* 420 - */ 0, + /* 421 - */ 0, + /* 422 - */ 0, + /* 423 - */ 0, + /* 424 - */ 0, + /* 425 - */ 0, + /* 426 - */ 0, + /* 427 - */ 0, + /* 428 - */ 0, + /* 429 - */ 0, + /* 42a - */ 0, + /* 42b - */ 0, + /* 42c - */ 0, + /* 42d - */ 0, + /* 42e - */ 0, + /* 42f - */ 0, + /* 430 - _DC_E0 */ 0x2282, + /* 431 - _DC_E0 */ 0x2283, + /* 432 - _DC_E0 */ 0x2284, + /* 433 - _DC_E0 */ 0x2285, + /* 434 - _DC_E0 */ 0x2286, + /* 435 - _DC_E0 */ 0x2287, + /* 436 - _DC_E0 */ 0x2288, + /* 437 - _DC_E0 */ 0x2289, + /* 438 - _DC_E8 */ 0x228a, + /* 439 - _DC_E8 */ 0x228b, + /* 43a - _DC_E8 */ 0x228c, + /* 43b - _DC_E8 */ 0x228d, + /* 43c - _DC_E8 */ 0x228e, + /* 43d - _DC_E8 */ 0x228f, + /* 43e - _DC_E8 */ 0x2290, + /* 43f - _DC_E8 */ 0x2291, + /* 440 - _DC_F0 */ 0x2292, + /* 441 - _DC_F0 */ 0x2293, + /* 442 - _DC_F0 */ 0x2294, + /* 443 - _DC_F0 */ 0x2295, + /* 444 - _DC_F0 */ 0x2296, + /* 445 - _DC_F0 */ 0x2297, + /* 446 - _DC_F0 */ 0x2298, + /* 447 - _DC_F0 */ 0x2299, + /* 448 - _DC_F8 */ 0x229a, + /* 449 - _DC_F8 */ 0x229b, + /* 44a - _DC_F8 */ 0x229c, + /* 44b - _DC_F8 */ 0x229d, + /* 44c - _DC_F8 */ 0x229e, + /* 44d - _DC_F8 */ 0x229f, + /* 44e - _DC_F8 */ 0x22a0, + /* 44f - _DC_F8 */ 0x22a1, + /* 450 - _DD_00 */ 0x22a2, + /* 451 - _DD_01 */ 0x22a3, + /* 452 - _DD_02 */ 0x22a4, + /* 453 - _DD_03 */ 0x22a5, + /* 454 - _DD_04 */ 0x22a6, + /* 455 - */ 0, + /* 456 - _DD_06 */ 0xcf54, + /* 457 - _DD_07 */ 0xcf60, + /* 458 - _DD_C0 */ 0x22a7, + /* 459 - _DD_C0 */ 0x22a8, + /* 45a - _DD_C0 */ 0x22a9, + /* 45b - _DD_C0 */ 0x22aa, + /* 45c - _DD_C0 */ 0x22ab, + /* 45d - _DD_C0 */ 0x22ac, + /* 45e - _DD_C0 */ 0x22ad, + /* 45f - _DD_C0 */ 0x22ae, + /* 460 - */ 0, + /* 461 - */ 0, + /* 462 - */ 0, + /* 463 - */ 0, + /* 464 - */ 0, + /* 465 - */ 0, + /* 466 - */ 0, + /* 467 - */ 0, + /* 468 - _DD_D0 */ 0x22af, + /* 469 - _DD_D0 */ 0x22b0, + /* 46a - _DD_D0 */ 0x22b1, + /* 46b - _DD_D0 */ 0x22b2, + /* 46c - _DD_D0 */ 0x22b3, + /* 46d - _DD_D0 */ 0x22b4, + /* 46e - _DD_D0 */ 0x22b5, + /* 46f - _DD_D0 */ 0x22b6, + /* 470 - _DD_D8 */ 0x22b7, + /* 471 - _DD_D8 */ 0x22b8, + /* 472 - _DD_D8 */ 0x22b9, + /* 473 - _DD_D8 */ 0x22ba, + /* 474 - _DD_D8 */ 0x22bb, + /* 475 - _DD_D8 */ 0x22bc, + /* 476 - _DD_D8 */ 0x22bd, + /* 477 - _DD_D8 */ 0x22be, + /* 478 - _DD_E0 */ 0x22bf, + /* 479 - _DD_E1 */ 0x22c0, + /* 47a - _DD_E0 */ 0x22c1, + /* 47b - _DD_E0 */ 0x22c2, + /* 47c - _DD_E0 */ 0x22c3, + /* 47d - _DD_E0 */ 0x22c4, + /* 47e - _DD_E0 */ 0x22c5, + /* 47f - _DD_E0 */ 0x22c6, + /* 480 - _DD_E8 */ 0x22c7, + /* 481 - _DD_E9 */ 0x22c8, + /* 482 - _DD_E8 */ 0x22c9, + /* 483 - _DD_E8 */ 0x22ca, + /* 484 - _DD_E8 */ 0x22cb, + /* 485 - _DD_E8 */ 0x22cc, + /* 486 - _DD_E8 */ 0x22cd, + /* 487 - _DD_E8 */ 0x22ce, + /* 488 - */ 0, + /* 489 - */ 0, + /* 48a - */ 0, + /* 48b - */ 0, + /* 48c - */ 0, + /* 48d - */ 0, + /* 48e - */ 0, + /* 48f - */ 0, + /* 490 - */ 0, + /* 491 - */ 0, + /* 492 - */ 0, + /* 493 - */ 0, + /* 494 - */ 0, + /* 495 - */ 0, + /* 496 - */ 0, + /* 497 - */ 0, + /* 498 - _DE_00 */ 0x22cf, + /* 499 - _DE_01 */ 0x22d0, + /* 49a - _DE_02 */ 0x22d1, + /* 49b - _DE_03 */ 0x22d2, + /* 49c - _DE_04 */ 0x22d3, + /* 49d - _DE_05 */ 0x22d4, + /* 49e - _DE_06 */ 0x22d5, + /* 49f - _DE_07 */ 0x22d6, + /* 4a0 - _DE_C0 */ 0x22d7, + /* 4a1 - _DE_C1 */ 0x22d8, + /* 4a2 - _DE_C0 */ 0x22d9, + /* 4a3 - _DE_C0 */ 0x22da, + /* 4a4 - _DE_C0 */ 0x22db, + /* 4a5 - _DE_C0 */ 0x22dc, + /* 4a6 - _DE_C0 */ 0x22dd, + /* 4a7 - _DE_C0 */ 0x22de, + /* 4a8 - _DE_C8 */ 0x22df, + /* 4a9 - _DE_C9 */ 0x22e0, + /* 4aa - _DE_C8 */ 0x22e1, + /* 4ab - _DE_C8 */ 0x22e2, + /* 4ac - _DE_C8 */ 0x22e3, + /* 4ad - _DE_C8 */ 0x22e4, + /* 4ae - _DE_C8 */ 0x22e5, + /* 4af - _DE_C8 */ 0x22e6, + /* 4b0 - */ 0, + /* 4b1 - */ 0, + /* 4b2 - */ 0, + /* 4b3 - */ 0, + /* 4b4 - */ 0, + /* 4b5 - */ 0, + /* 4b6 - */ 0, + /* 4b7 - */ 0, + /* 4b8 - */ 0, + /* 4b9 - _DE_D9 */ 0x22e7, + /* 4ba - */ 0, + /* 4bb - */ 0, + /* 4bc - */ 0, + /* 4bd - */ 0, + /* 4be - */ 0, + /* 4bf - */ 0, + /* 4c0 - _DE_E0 */ 0x22e8, + /* 4c1 - _DE_E1 */ 0x22e9, + /* 4c2 - _DE_E0 */ 0x22ea, + /* 4c3 - _DE_E0 */ 0x22eb, + /* 4c4 - _DE_E0 */ 0x22ec, + /* 4c5 - _DE_E0 */ 0x22ed, + /* 4c6 - _DE_E0 */ 0x22ee, + /* 4c7 - _DE_E0 */ 0x22ef, + /* 4c8 - _DE_E8 */ 0x22f0, + /* 4c9 - _DE_E9 */ 0x22f1, + /* 4ca - _DE_E8 */ 0x22f2, + /* 4cb - _DE_E8 */ 0x22f3, + /* 4cc - _DE_E8 */ 0x22f4, + /* 4cd - _DE_E8 */ 0x22f5, + /* 4ce - _DE_E8 */ 0x22f6, + /* 4cf - _DE_E8 */ 0x22f7, + /* 4d0 - _DE_F0 */ 0x22f8, + /* 4d1 - _DE_F1 */ 0x22f9, + /* 4d2 - _DE_F0 */ 0x22fa, + /* 4d3 - _DE_F0 */ 0x22fb, + /* 4d4 - _DE_F0 */ 0x22fc, + /* 4d5 - _DE_F0 */ 0x22fd, + /* 4d6 - _DE_F0 */ 0x22fe, + /* 4d7 - _DE_F0 */ 0x22ff, + /* 4d8 - _DE_F8 */ 0x2300, + /* 4d9 - _DE_F9 */ 0x2301, + /* 4da - _DE_F8 */ 0x2302, + /* 4db - _DE_F8 */ 0x2303, + /* 4dc - _DE_F8 */ 0x2304, + /* 4dd - _DE_F8 */ 0x2305, + /* 4de - _DE_F8 */ 0x2306, + /* 4df - _DE_F8 */ 0x2307, + /* 4e0 - _DF_00 */ 0x2308, + /* 4e1 - _DF_01 */ 0x2309, + /* 4e2 - _DF_02 */ 0x230a, + /* 4e3 - _DF_03 */ 0x230b, + /* 4e4 - _DF_04 */ 0x230c, + /* 4e5 - _DF_05 */ 0x230d, + /* 4e6 - _DF_06 */ 0x230e, + /* 4e7 - _DF_07 */ 0x230f, + /* 4e8 - */ 0, + /* 4e9 - */ 0, + /* 4ea - */ 0, + /* 4eb - */ 0, + /* 4ec - */ 0, + /* 4ed - */ 0, + /* 4ee - */ 0, + /* 4ef - */ 0, + /* 4f0 - */ 0, + /* 4f1 - */ 0, + /* 4f2 - */ 0, + /* 4f3 - */ 0, + /* 4f4 - */ 0, + /* 4f5 - */ 0, + /* 4f6 - */ 0, + /* 4f7 - */ 0, + /* 4f8 - */ 0, + /* 4f9 - */ 0, + /* 4fa - */ 0, + /* 4fb - */ 0, + /* 4fc - */ 0, + /* 4fd - */ 0, + /* 4fe - */ 0, + /* 4ff - */ 0, + /* 500 - */ 0, + /* 501 - */ 0, + /* 502 - */ 0, + /* 503 - */ 0, + /* 504 - */ 0, + /* 505 - */ 0, + /* 506 - */ 0, + /* 507 - */ 0, + /* 508 - _DF_E0 */ 0xcf6c, + /* 509 - */ 0, + /* 50a - */ 0, + /* 50b - */ 0, + /* 50c - */ 0, + /* 50d - */ 0, + /* 50e - */ 0, + /* 50f - */ 0, + /* 510 - _DF_E8 */ 0x2310, + /* 511 - _DF_E8 */ 0x2311, + /* 512 - _DF_E8 */ 0x2312, + /* 513 - _DF_E8 */ 0x2313, + /* 514 - _DF_E8 */ 0x2314, + /* 515 - _DF_E8 */ 0x2315, + /* 516 - _DF_E8 */ 0x2316, + /* 517 - _DF_E8 */ 0x2317, + /* 518 - _DF_F0 */ 0x2318, + /* 519 - _DF_F0 */ 0x2319, + /* 51a - _DF_F0 */ 0x231a, + /* 51b - _DF_F0 */ 0x231b, + /* 51c - _DF_F0 */ 0x231c, + /* 51d - _DF_F0 */ 0x231d, + /* 51e - _DF_F0 */ 0x231e, + /* 51f - _DF_F0 */ 0x231f, + /* 520 - */ 0, + /* 521 - */ 0, + /* 522 - */ 0, + /* 523 - */ 0, + /* 524 - */ 0, + /* 525 - */ 0, + /* 526 - */ 0, + /* 527 - */ 0, + /* 528 - _F6_00 */ 0x2320, + /* 529 - */ 0, + /* 52a - _F6_02 */ 0x2321, + /* 52b - _F6_03 */ 0x2322, + /* 52c - _F6_04 */ 0x2323, + /* 52d - _F6_05 */ 0x2324, + /* 52e - _F6_06 */ 0x2325, + /* 52f - _F6_07 */ 0x2326, + /* 530 - _F7_00 */ 0x2327, + /* 531 - */ 0, + /* 532 - _F7_02 */ 0x2328, + /* 533 - _F7_03 */ 0x2329, + /* 534 - _F7_04 */ 0x232a, + /* 535 - _F7_05 */ 0x232b, + /* 536 - _F7_06 */ 0x232c, + /* 537 - _F7_07 */ 0x232d, + /* 538 - _FE_00 */ 0x232e, + /* 539 - _FE_01 */ 0x232f, + /* 53a - */ 0, + /* 53b - */ 0, + /* 53c - */ 0, + /* 53d - */ 0, + /* 53e - */ 0, + /* 53f - */ 0, + /* 540 - _FF_00 */ 0x2330, + /* 541 - _FF_01 */ 0x2331, + /* 542 - _FF_02 */ 0x2332, + /* 543 - _FF_03 */ 0x2333, + /* 544 - _FF_04 */ 0x2334, + /* 545 - _FF_05 */ 0x2335, + /* 546 - _FF_06 */ 0x2336, + /* 547 - */ 0, + /* 548 - _0F_00_00 */ 0x2337, + /* 549 - _0F_00_01 */ 0x2338, + /* 54a - _0F_00_02 */ 0x2339, + /* 54b - _0F_00_03 */ 0x233a, + /* 54c - _0F_00_04 */ 0x233b, + /* 54d - _0F_00_05 */ 0x233c, + /* 54e - */ 0, + /* 54f - */ 0, + /* 550 - _0F_01_00 */ 0x233d, + /* 551 - _0F_01_01 */ 0x233e, + /* 552 - _0F_01_02 */ 0x233f, + /* 553 - _0F_01_03 */ 0x2340, + /* 554 - _0F_01_04 */ 0x2341, + /* 555 - */ 0, + /* 556 - _0F_01_06 */ 0x2342, + /* 557 - _0F_01_07 */ 0x2343, + /* 558 - */ 0, + /* 559 - _0F_01_C1 */ 0x2344, + /* 55a - _0F_01_C2 */ 0x2345, + /* 55b - _0F_01_C3 */ 0x2346, + /* 55c - _0F_01_C4 */ 0x2347, + /* 55d - */ 0, + /* 55e - */ 0, + /* 55f - */ 0, + /* 560 - _0F_01_C8 */ 0x2348, + /* 561 - _0F_01_C9 */ 0x2349, + /* 562 - */ 0, + /* 563 - */ 0, + /* 564 - */ 0, + /* 565 - */ 0, + /* 566 - */ 0, + /* 567 - */ 0, + /* 568 - _0F_01_D0 */ 0x234a, + /* 569 - _0F_01_D1 */ 0x234b, + /* 56a - */ 0, + /* 56b - */ 0, + /* 56c - _0F_01_D4 */ 0x234c, + /* 56d - _0F_01_D5 */ 0x234d, + /* 56e - */ 0, + /* 56f - */ 0, + /* 570 - _0F_01_D8 */ 0x234e, + /* 571 - _0F_01_D9 */ 0x234f, + /* 572 - _0F_01_DA */ 0x2350, + /* 573 - _0F_01_DB */ 0x2351, + /* 574 - _0F_01_DC */ 0x2352, + /* 575 - _0F_01_DD */ 0x2353, + /* 576 - _0F_01_DE */ 0x2354, + /* 577 - _0F_01_DF */ 0x2355, + /* 578 - */ 0, + /* 579 - */ 0, + /* 57a - */ 0, + /* 57b - */ 0, + /* 57c - */ 0, + /* 57d - */ 0, + /* 57e - */ 0, + /* 57f - */ 0, + /* 580 - */ 0, + /* 581 - */ 0, + /* 582 - */ 0, + /* 583 - */ 0, + /* 584 - */ 0, + /* 585 - */ 0, + /* 586 - */ 0, + /* 587 - */ 0, + /* 588 - */ 0, + /* 589 - */ 0, + /* 58a - */ 0, + /* 58b - */ 0, + /* 58c - */ 0, + /* 58d - */ 0, + /* 58e - */ 0, + /* 58f - */ 0, + /* 590 - _0F_01_F8 */ 0x2356, + /* 591 - _0F_01_F9 */ 0x2357, + /* 592 - */ 0, + /* 593 - */ 0, + /* 594 - */ 0, + /* 595 - */ 0, + /* 596 - */ 0, + /* 597 - */ 0, + /* 598 - _0F_0D_00 */ 0x2358, + /* 599 - _0F_0D_01 */ 0x2359, + /* 59a - */ 0, + /* 59b - */ 0, + /* 59c - */ 0, + /* 59d - */ 0, + /* 59e - */ 0, + /* 59f - */ 0, + /* 5a0 - */ 0, + /* 5a1 - */ 0, + /* 5a2 - */ 0, + /* 5a3 - */ 0, + /* 5a4 - */ 0, + /* 5a5 - */ 0, + /* 5a6 - */ 0, + /* 5a7 - */ 0, + /* 5a8 - */ 0, + /* 5a9 - */ 0, + /* 5aa - */ 0, + /* 5ab - */ 0, + /* 5ac - _0F_0F_0C */ 0x235a, + /* 5ad - _0F_0F_0D */ 0x235b, + /* 5ae - */ 0, + /* 5af - */ 0, + /* 5b0 - */ 0, + /* 5b1 - */ 0, + /* 5b2 - */ 0, + /* 5b3 - */ 0, + /* 5b4 - */ 0, + /* 5b5 - */ 0, + /* 5b6 - */ 0, + /* 5b7 - */ 0, + /* 5b8 - */ 0, + /* 5b9 - */ 0, + /* 5ba - */ 0, + /* 5bb - */ 0, + /* 5bc - _0F_0F_1C */ 0x235c, + /* 5bd - _0F_0F_1D */ 0x235d, + /* 5be - */ 0, + /* 5bf - */ 0, + /* 5c0 - */ 0, + /* 5c1 - */ 0, + /* 5c2 - */ 0, + /* 5c3 - */ 0, + /* 5c4 - */ 0, + /* 5c5 - */ 0, + /* 5c6 - */ 0, + /* 5c7 - */ 0, + /* 5c8 - */ 0, + /* 5c9 - */ 0, + /* 5ca - */ 0, + /* 5cb - */ 0, + /* 5cc - */ 0, + /* 5cd - */ 0, + /* 5ce - */ 0, + /* 5cf - */ 0, + /* 5d0 - */ 0, + /* 5d1 - */ 0, + /* 5d2 - */ 0, + /* 5d3 - */ 0, + /* 5d4 - */ 0, + /* 5d5 - */ 0, + /* 5d6 - */ 0, + /* 5d7 - */ 0, + /* 5d8 - */ 0, + /* 5d9 - */ 0, + /* 5da - */ 0, + /* 5db - */ 0, + /* 5dc - */ 0, + /* 5dd - */ 0, + /* 5de - */ 0, + /* 5df - */ 0, + /* 5e0 - */ 0, + /* 5e1 - */ 0, + /* 5e2 - */ 0, + /* 5e3 - */ 0, + /* 5e4 - */ 0, + /* 5e5 - */ 0, + /* 5e6 - */ 0, + /* 5e7 - */ 0, + /* 5e8 - */ 0, + /* 5e9 - */ 0, + /* 5ea - */ 0, + /* 5eb - */ 0, + /* 5ec - */ 0, + /* 5ed - */ 0, + /* 5ee - */ 0, + /* 5ef - */ 0, + /* 5f0 - */ 0, + /* 5f1 - */ 0, + /* 5f2 - */ 0, + /* 5f3 - */ 0, + /* 5f4 - */ 0, + /* 5f5 - */ 0, + /* 5f6 - */ 0, + /* 5f7 - */ 0, + /* 5f8 - */ 0, + /* 5f9 - */ 0, + /* 5fa - */ 0, + /* 5fb - */ 0, + /* 5fc - */ 0, + /* 5fd - */ 0, + /* 5fe - */ 0, + /* 5ff - */ 0, + /* 600 - */ 0, + /* 601 - */ 0, + /* 602 - */ 0, + /* 603 - */ 0, + /* 604 - */ 0, + /* 605 - */ 0, + /* 606 - */ 0, + /* 607 - */ 0, + /* 608 - */ 0, + /* 609 - */ 0, + /* 60a - */ 0, + /* 60b - */ 0, + /* 60c - */ 0, + /* 60d - */ 0, + /* 60e - */ 0, + /* 60f - */ 0, + /* 610 - */ 0, + /* 611 - */ 0, + /* 612 - */ 0, + /* 613 - */ 0, + /* 614 - */ 0, + /* 615 - */ 0, + /* 616 - */ 0, + /* 617 - */ 0, + /* 618 - */ 0, + /* 619 - */ 0, + /* 61a - */ 0, + /* 61b - */ 0, + /* 61c - */ 0, + /* 61d - */ 0, + /* 61e - */ 0, + /* 61f - */ 0, + /* 620 - */ 0, + /* 621 - */ 0, + /* 622 - */ 0, + /* 623 - */ 0, + /* 624 - */ 0, + /* 625 - */ 0, + /* 626 - */ 0, + /* 627 - */ 0, + /* 628 - */ 0, + /* 629 - */ 0, + /* 62a - _0F_0F_8A */ 0x235e, + /* 62b - */ 0, + /* 62c - */ 0, + /* 62d - */ 0, + /* 62e - _0F_0F_8E */ 0x235f, + /* 62f - */ 0, + /* 630 - _0F_0F_90 */ 0x2360, + /* 631 - */ 0, + /* 632 - */ 0, + /* 633 - */ 0, + /* 634 - _0F_0F_94 */ 0x2361, + /* 635 - */ 0, + /* 636 - _0F_0F_96 */ 0x2362, + /* 637 - _0F_0F_97 */ 0x2363, + /* 638 - */ 0, + /* 639 - */ 0, + /* 63a - _0F_0F_9A */ 0x2364, + /* 63b - */ 0, + /* 63c - */ 0, + /* 63d - */ 0, + /* 63e - _0F_0F_9E */ 0x2365, + /* 63f - */ 0, + /* 640 - _0F_0F_A0 */ 0x2366, + /* 641 - */ 0, + /* 642 - */ 0, + /* 643 - */ 0, + /* 644 - _0F_0F_A4 */ 0x2367, + /* 645 - */ 0, + /* 646 - _0F_0F_A6 */ 0x2368, + /* 647 - _0F_0F_A7 */ 0x2369, + /* 648 - */ 0, + /* 649 - */ 0, + /* 64a - _0F_0F_AA */ 0x236a, + /* 64b - */ 0, + /* 64c - */ 0, + /* 64d - */ 0, + /* 64e - _0F_0F_AE */ 0x236b, + /* 64f - */ 0, + /* 650 - _0F_0F_B0 */ 0x236c, + /* 651 - */ 0, + /* 652 - */ 0, + /* 653 - */ 0, + /* 654 - _0F_0F_B4 */ 0x236d, + /* 655 - */ 0, + /* 656 - _0F_0F_B6 */ 0x236e, + /* 657 - _0F_0F_B7 */ 0x236f, + /* 658 - */ 0, + /* 659 - */ 0, + /* 65a - */ 0, + /* 65b - _0F_0F_BB */ 0x2370, + /* 65c - */ 0, + /* 65d - */ 0, + /* 65e - */ 0, + /* 65f - _0F_0F_BF */ 0x2371, + /* 660 - */ 0, + /* 661 - */ 0, + /* 662 - */ 0, + /* 663 - */ 0, + /* 664 - */ 0, + /* 665 - */ 0, + /* 666 - */ 0, + /* 667 - */ 0, + /* 668 - */ 0, + /* 669 - */ 0, + /* 66a - */ 0, + /* 66b - */ 0, + /* 66c - */ 0, + /* 66d - */ 0, + /* 66e - */ 0, + /* 66f - */ 0, + /* 670 - */ 0, + /* 671 - */ 0, + /* 672 - */ 0, + /* 673 - */ 0, + /* 674 - */ 0, + /* 675 - */ 0, + /* 676 - */ 0, + /* 677 - */ 0, + /* 678 - */ 0, + /* 679 - */ 0, + /* 67a - */ 0, + /* 67b - */ 0, + /* 67c - */ 0, + /* 67d - */ 0, + /* 67e - */ 0, + /* 67f - */ 0, + /* 680 - */ 0, + /* 681 - */ 0, + /* 682 - */ 0, + /* 683 - */ 0, + /* 684 - */ 0, + /* 685 - */ 0, + /* 686 - */ 0, + /* 687 - */ 0, + /* 688 - */ 0, + /* 689 - */ 0, + /* 68a - */ 0, + /* 68b - */ 0, + /* 68c - */ 0, + /* 68d - */ 0, + /* 68e - */ 0, + /* 68f - */ 0, + /* 690 - */ 0, + /* 691 - */ 0, + /* 692 - */ 0, + /* 693 - */ 0, + /* 694 - */ 0, + /* 695 - */ 0, + /* 696 - */ 0, + /* 697 - */ 0, + /* 698 - */ 0, + /* 699 - */ 0, + /* 69a - */ 0, + /* 69b - */ 0, + /* 69c - */ 0, + /* 69d - */ 0, + /* 69e - */ 0, + /* 69f - */ 0, + /* 6a0 - _0F_10 */ 0x2372, + /* 6a1 - _66_0F_10 */ 0x2373, + /* 6a2 - _F3_0F_10 */ 0x2374, + /* 6a3 - _F2_0F_10 */ 0x2375, + /* 6a4 - _V_0F_10 */ 0x4009, + /* 6a5 - _V_66_0F_10 */ 0x400a, + /* 6a6 - _V_F3_0F_10 */ 0x400b, + /* 6a7 - _V_F2_0F_10 */ 0x400c, + /* 6a8 - */ 0, + /* 6a9 - */ 0, + /* 6aa - _VRR_F3_0F_10 */ 0x400d, + /* 6ab - _VRR_F2_0F_10 */ 0x400e, + /* 6ac - _0F_11 */ 0x2376, + /* 6ad - _66_0F_11 */ 0x2377, + /* 6ae - _F3_0F_11 */ 0x2378, + /* 6af - _F2_0F_11 */ 0x2379, + /* 6b0 - _V_0F_11 */ 0x400f, + /* 6b1 - _V_66_0F_11 */ 0x4010, + /* 6b2 - _V_F3_0F_11 */ 0x4011, + /* 6b3 - _V_F2_0F_11 */ 0x4012, + /* 6b4 - */ 0, + /* 6b5 - */ 0, + /* 6b6 - _VRR_F3_0F_11 */ 0x4013, + /* 6b7 - _VRR_F2_0F_11 */ 0x4014, + /* 6b8 - _0F_12 */ 0x4015, + /* 6b9 - _66_0F_12 */ 0x237a, + /* 6ba - _F3_0F_12 */ 0x237b, + /* 6bb - _F2_0F_12 */ 0x237c, + /* 6bc - _V_0F_12 */ 0x4016, + /* 6bd - _V_66_0F_12 */ 0x4017, + /* 6be - _V_F3_0F_12 */ 0x4018, + /* 6bf - _V_F2_0F_12 */ 0x4019, + /* 6c0 - */ 0, + /* 6c1 - */ 0, + /* 6c2 - */ 0, + /* 6c3 - */ 0, + /* 6c4 - _0F_13 */ 0x237d, + /* 6c5 - _66_0F_13 */ 0x237e, + /* 6c6 - */ 0, + /* 6c7 - */ 0, + /* 6c8 - _V_0F_13 */ 0x401a, + /* 6c9 - _V_66_0F_13 */ 0x401b, + /* 6ca - */ 0, + /* 6cb - */ 0, + /* 6cc - */ 0, + /* 6cd - */ 0, + /* 6ce - */ 0, + /* 6cf - */ 0, + /* 6d0 - _0F_14 */ 0x237f, + /* 6d1 - _66_0F_14 */ 0x2380, + /* 6d2 - */ 0, + /* 6d3 - */ 0, + /* 6d4 - _V_0F_14 */ 0x401c, + /* 6d5 - _V_66_0F_14 */ 0x401d, + /* 6d6 - */ 0, + /* 6d7 - */ 0, + /* 6d8 - */ 0, + /* 6d9 - */ 0, + /* 6da - */ 0, + /* 6db - */ 0, + /* 6dc - _0F_15 */ 0x2381, + /* 6dd - _66_0F_15 */ 0x2382, + /* 6de - */ 0, + /* 6df - */ 0, + /* 6e0 - _V_0F_15 */ 0x401e, + /* 6e1 - _V_66_0F_15 */ 0x401f, + /* 6e2 - */ 0, + /* 6e3 - */ 0, + /* 6e4 - */ 0, + /* 6e5 - */ 0, + /* 6e6 - */ 0, + /* 6e7 - */ 0, + /* 6e8 - _0F_16 */ 0x4020, + /* 6e9 - _66_0F_16 */ 0x2383, + /* 6ea - _F3_0F_16 */ 0x2384, + /* 6eb - */ 0, + /* 6ec - _V_0F_16 */ 0x4021, + /* 6ed - _V_66_0F_16 */ 0x4022, + /* 6ee - _V_F3_0F_16 */ 0x4023, + /* 6ef - */ 0, + /* 6f0 - */ 0, + /* 6f1 - */ 0, + /* 6f2 - */ 0, + /* 6f3 - */ 0, + /* 6f4 - _0F_17 */ 0x2385, + /* 6f5 - _66_0F_17 */ 0x2386, + /* 6f6 - */ 0, + /* 6f7 - */ 0, + /* 6f8 - _V_0F_17 */ 0x4024, + /* 6f9 - _V_66_0F_17 */ 0x4025, + /* 6fa - */ 0, + /* 6fb - */ 0, + /* 6fc - */ 0, + /* 6fd - */ 0, + /* 6fe - */ 0, + /* 6ff - */ 0, + /* 700 - _0F_18_00 */ 0x2387, + /* 701 - _0F_18_01 */ 0x2388, + /* 702 - _0F_18_02 */ 0x2389, + /* 703 - _0F_18_03 */ 0x238a, + /* 704 - */ 0, + /* 705 - */ 0, + /* 706 - */ 0, + /* 707 - */ 0, + /* 708 - _0F_28 */ 0x238b, + /* 709 - _66_0F_28 */ 0x238c, + /* 70a - */ 0, + /* 70b - */ 0, + /* 70c - _V_0F_28 */ 0x4026, + /* 70d - _V_66_0F_28 */ 0x4027, + /* 70e - */ 0, + /* 70f - */ 0, + /* 710 - */ 0, + /* 711 - */ 0, + /* 712 - */ 0, + /* 713 - */ 0, + /* 714 - _0F_29 */ 0x238d, + /* 715 - _66_0F_29 */ 0x238e, + /* 716 - */ 0, + /* 717 - */ 0, + /* 718 - _V_0F_29 */ 0x4028, + /* 719 - _V_66_0F_29 */ 0x4029, + /* 71a - */ 0, + /* 71b - */ 0, + /* 71c - */ 0, + /* 71d - */ 0, + /* 71e - */ 0, + /* 71f - */ 0, + /* 720 - _0F_2A */ 0x238f, + /* 721 - _66_0F_2A */ 0x2390, + /* 722 - _F3_0F_2A */ 0x2391, + /* 723 - _F2_0F_2A */ 0x2392, + /* 724 - */ 0, + /* 725 - */ 0, + /* 726 - _V_F3_0F_2A */ 0x402a, + /* 727 - _V_F2_0F_2A */ 0x402b, + /* 728 - */ 0, + /* 729 - */ 0, + /* 72a - */ 0, + /* 72b - */ 0, + /* 72c - _0F_2B */ 0x2393, + /* 72d - _66_0F_2B */ 0x2394, + /* 72e - _F3_0F_2B */ 0x2395, + /* 72f - _F2_0F_2B */ 0x2396, + /* 730 - _V_0F_2B */ 0x402c, + /* 731 - _V_66_0F_2B */ 0x402d, + /* 732 - */ 0, + /* 733 - */ 0, + /* 734 - */ 0, + /* 735 - */ 0, + /* 736 - */ 0, + /* 737 - */ 0, + /* 738 - _0F_2C */ 0x2397, + /* 739 - _66_0F_2C */ 0x2398, + /* 73a - _F3_0F_2C */ 0x2399, + /* 73b - _F2_0F_2C */ 0x239a, + /* 73c - */ 0, + /* 73d - */ 0, + /* 73e - _V_F3_0F_2C */ 0x402e, + /* 73f - _V_F2_0F_2C */ 0x402f, + /* 740 - */ 0, + /* 741 - */ 0, + /* 742 - */ 0, + /* 743 - */ 0, + /* 744 - _0F_2D */ 0x239b, + /* 745 - _66_0F_2D */ 0x239c, + /* 746 - _F3_0F_2D */ 0x239d, + /* 747 - _F2_0F_2D */ 0x239e, + /* 748 - */ 0, + /* 749 - */ 0, + /* 74a - _V_F3_0F_2D */ 0x4030, + /* 74b - _V_F2_0F_2D */ 0x4031, + /* 74c - */ 0, + /* 74d - */ 0, + /* 74e - */ 0, + /* 74f - */ 0, + /* 750 - _0F_2E */ 0x239f, + /* 751 - _66_0F_2E */ 0x23a0, + /* 752 - */ 0, + /* 753 - */ 0, + /* 754 - _V_0F_2E */ 0x4032, + /* 755 - _V_66_0F_2E */ 0x4033, + /* 756 - */ 0, + /* 757 - */ 0, + /* 758 - */ 0, + /* 759 - */ 0, + /* 75a - */ 0, + /* 75b - */ 0, + /* 75c - _0F_2F */ 0x23a1, + /* 75d - _66_0F_2F */ 0x23a2, + /* 75e - */ 0, + /* 75f - */ 0, + /* 760 - _V_0F_2F */ 0x4034, + /* 761 - _V_66_0F_2F */ 0x4035, + /* 762 - */ 0, + /* 763 - */ 0, + /* 764 - */ 0, + /* 765 - */ 0, + /* 766 - */ 0, + /* 767 - */ 0, + /* 768 - _0F_38_00 */ 0xcf78, + /* 769 - _0F_38_01 */ 0xcf84, + /* 76a - _0F_38_02 */ 0xcf90, + /* 76b - _0F_38_03 */ 0xcf9c, + /* 76c - _0F_38_04 */ 0xcfa8, + /* 76d - _0F_38_05 */ 0xcfb4, + /* 76e - _0F_38_06 */ 0xcfc0, + /* 76f - _0F_38_07 */ 0xcfcc, + /* 770 - _0F_38_08 */ 0xcfd8, + /* 771 - _0F_38_09 */ 0xcfe4, + /* 772 - _0F_38_0A */ 0xcff0, + /* 773 - _0F_38_0B */ 0xcffc, + /* 774 - _0F_38_0C */ 0xd008, + /* 775 - _0F_38_0D */ 0xd014, + /* 776 - _0F_38_0E */ 0xd020, + /* 777 - _0F_38_0F */ 0xd02c, + /* 778 - _0F_38_10 */ 0xd038, + /* 779 - */ 0, + /* 77a - */ 0, + /* 77b - */ 0, + /* 77c - _0F_38_14 */ 0xd044, + /* 77d - _0F_38_15 */ 0xd050, + /* 77e - */ 0, + /* 77f - _0F_38_17 */ 0xd05c, + /* 780 - _0F_38_18 */ 0xd068, + /* 781 - _0F_38_19 */ 0xd074, + /* 782 - _0F_38_1A */ 0xd080, + /* 783 - */ 0, + /* 784 - _0F_38_1C */ 0xd08c, + /* 785 - _0F_38_1D */ 0xd098, + /* 786 - _0F_38_1E */ 0xd0a4, + /* 787 - */ 0, + /* 788 - _0F_38_20 */ 0xd0b0, + /* 789 - _0F_38_21 */ 0xd0bc, + /* 78a - _0F_38_22 */ 0xd0c8, + /* 78b - _0F_38_23 */ 0xd0d4, + /* 78c - _0F_38_24 */ 0xd0e0, + /* 78d - _0F_38_25 */ 0xd0ec, + /* 78e - */ 0, + /* 78f - */ 0, + /* 790 - _0F_38_28 */ 0xd0f8, + /* 791 - _0F_38_29 */ 0xd104, + /* 792 - _0F_38_2A */ 0xd110, + /* 793 - _0F_38_2B */ 0xd11c, + /* 794 - _0F_38_2C */ 0xd128, + /* 795 - _0F_38_2D */ 0xd134, + /* 796 - _0F_38_2E */ 0xd140, + /* 797 - _0F_38_2F */ 0xd14c, + /* 798 - _0F_38_30 */ 0xd158, + /* 799 - _0F_38_31 */ 0xd164, + /* 79a - _0F_38_32 */ 0xd170, + /* 79b - _0F_38_33 */ 0xd17c, + /* 79c - _0F_38_34 */ 0xd188, + /* 79d - _0F_38_35 */ 0xd194, + /* 79e - */ 0, + /* 79f - _0F_38_37 */ 0xd1a0, + /* 7a0 - _0F_38_38 */ 0xd1ac, + /* 7a1 - _0F_38_39 */ 0xd1b8, + /* 7a2 - _0F_38_3A */ 0xd1c4, + /* 7a3 - _0F_38_3B */ 0xd1d0, + /* 7a4 - _0F_38_3C */ 0xd1dc, + /* 7a5 - _0F_38_3D */ 0xd1e8, + /* 7a6 - _0F_38_3E */ 0xd1f4, + /* 7a7 - _0F_38_3F */ 0xd200, + /* 7a8 - _0F_38_40 */ 0xd20c, + /* 7a9 - _0F_38_41 */ 0xd218, + /* 7aa - */ 0, + /* 7ab - */ 0, + /* 7ac - */ 0, + /* 7ad - */ 0, + /* 7ae - */ 0, + /* 7af - */ 0, + /* 7b0 - */ 0, + /* 7b1 - */ 0, + /* 7b2 - */ 0, + /* 7b3 - */ 0, + /* 7b4 - */ 0, + /* 7b5 - */ 0, + /* 7b6 - */ 0, + /* 7b7 - */ 0, + /* 7b8 - */ 0, + /* 7b9 - */ 0, + /* 7ba - */ 0, + /* 7bb - */ 0, + /* 7bc - */ 0, + /* 7bd - */ 0, + /* 7be - */ 0, + /* 7bf - */ 0, + /* 7c0 - */ 0, + /* 7c1 - */ 0, + /* 7c2 - */ 0, + /* 7c3 - */ 0, + /* 7c4 - */ 0, + /* 7c5 - */ 0, + /* 7c6 - */ 0, + /* 7c7 - */ 0, + /* 7c8 - */ 0, + /* 7c9 - */ 0, + /* 7ca - */ 0, + /* 7cb - */ 0, + /* 7cc - */ 0, + /* 7cd - */ 0, + /* 7ce - */ 0, + /* 7cf - */ 0, + /* 7d0 - */ 0, + /* 7d1 - */ 0, + /* 7d2 - */ 0, + /* 7d3 - */ 0, + /* 7d4 - */ 0, + /* 7d5 - */ 0, + /* 7d6 - */ 0, + /* 7d7 - */ 0, + /* 7d8 - */ 0, + /* 7d9 - */ 0, + /* 7da - */ 0, + /* 7db - */ 0, + /* 7dc - */ 0, + /* 7dd - */ 0, + /* 7de - */ 0, + /* 7df - */ 0, + /* 7e0 - */ 0, + /* 7e1 - */ 0, + /* 7e2 - */ 0, + /* 7e3 - */ 0, + /* 7e4 - */ 0, + /* 7e5 - */ 0, + /* 7e6 - */ 0, + /* 7e7 - */ 0, + /* 7e8 - _0F_38_80 */ 0xd224, + /* 7e9 - _0F_38_81 */ 0xd230, + /* 7ea - _0F_38_82 */ 0xd23c, + /* 7eb - */ 0, + /* 7ec - */ 0, + /* 7ed - */ 0, + /* 7ee - */ 0, + /* 7ef - */ 0, + /* 7f0 - */ 0, + /* 7f1 - */ 0, + /* 7f2 - */ 0, + /* 7f3 - */ 0, + /* 7f4 - */ 0, + /* 7f5 - */ 0, + /* 7f6 - */ 0, + /* 7f7 - */ 0, + /* 7f8 - */ 0, + /* 7f9 - */ 0, + /* 7fa - */ 0, + /* 7fb - */ 0, + /* 7fc - */ 0, + /* 7fd - */ 0, + /* 7fe - _0F_38_96 */ 0xd248, + /* 7ff - _0F_38_97 */ 0xd254, + /* 800 - _0F_38_98 */ 0xd260, + /* 801 - _0F_38_99 */ 0xd26c, + /* 802 - _0F_38_9A */ 0xd278, + /* 803 - _0F_38_9B */ 0xd284, + /* 804 - _0F_38_9C */ 0xd290, + /* 805 - _0F_38_9D */ 0xd29c, + /* 806 - _0F_38_9E */ 0xd2a8, + /* 807 - _0F_38_9F */ 0xd2b4, + /* 808 - */ 0, + /* 809 - */ 0, + /* 80a - */ 0, + /* 80b - */ 0, + /* 80c - */ 0, + /* 80d - */ 0, + /* 80e - _0F_38_A6 */ 0xd2c0, + /* 80f - _0F_38_A7 */ 0xd2cc, + /* 810 - _0F_38_A8 */ 0xd2d8, + /* 811 - _0F_38_A9 */ 0xd2e4, + /* 812 - _0F_38_AA */ 0xd2f0, + /* 813 - _0F_38_AB */ 0xd2fc, + /* 814 - _0F_38_AC */ 0xd308, + /* 815 - _0F_38_AD */ 0xd314, + /* 816 - _0F_38_AE */ 0xd320, + /* 817 - _0F_38_AF */ 0xd32c, + /* 818 - */ 0, + /* 819 - */ 0, + /* 81a - */ 0, + /* 81b - */ 0, + /* 81c - */ 0, + /* 81d - */ 0, + /* 81e - _0F_38_B6 */ 0xd338, + /* 81f - _0F_38_B7 */ 0xd344, + /* 820 - _0F_38_B8 */ 0xd350, + /* 821 - _0F_38_B9 */ 0xd35c, + /* 822 - _0F_38_BA */ 0xd368, + /* 823 - _0F_38_BB */ 0xd374, + /* 824 - _0F_38_BC */ 0xd380, + /* 825 - _0F_38_BD */ 0xd38c, + /* 826 - _0F_38_BE */ 0xd398, + /* 827 - _0F_38_BF */ 0xd3a4, + /* 828 - */ 0, + /* 829 - */ 0, + /* 82a - */ 0, + /* 82b - */ 0, + /* 82c - */ 0, + /* 82d - */ 0, + /* 82e - */ 0, + /* 82f - */ 0, + /* 830 - */ 0, + /* 831 - */ 0, + /* 832 - */ 0, + /* 833 - */ 0, + /* 834 - */ 0, + /* 835 - */ 0, + /* 836 - */ 0, + /* 837 - */ 0, + /* 838 - */ 0, + /* 839 - */ 0, + /* 83a - */ 0, + /* 83b - */ 0, + /* 83c - */ 0, + /* 83d - */ 0, + /* 83e - */ 0, + /* 83f - */ 0, + /* 840 - */ 0, + /* 841 - */ 0, + /* 842 - */ 0, + /* 843 - _0F_38_DB */ 0xd3b0, + /* 844 - _0F_38_DC */ 0xd3bc, + /* 845 - _0F_38_DD */ 0xd3c8, + /* 846 - _0F_38_DE */ 0xd3d4, + /* 847 - _0F_38_DF */ 0xd3e0, + /* 848 - */ 0, + /* 849 - */ 0, + /* 84a - */ 0, + /* 84b - */ 0, + /* 84c - */ 0, + /* 84d - */ 0, + /* 84e - */ 0, + /* 84f - */ 0, + /* 850 - */ 0, + /* 851 - */ 0, + /* 852 - */ 0, + /* 853 - */ 0, + /* 854 - */ 0, + /* 855 - */ 0, + /* 856 - */ 0, + /* 857 - */ 0, + /* 858 - _0F_38_F0 */ 0xd3ec, + /* 859 - _0F_38_F1 */ 0xd3f8, + /* 85a - */ 0, + /* 85b - */ 0, + /* 85c - */ 0, + /* 85d - */ 0, + /* 85e - */ 0, + /* 85f - */ 0, + /* 860 - */ 0, + /* 861 - */ 0, + /* 862 - */ 0, + /* 863 - */ 0, + /* 864 - */ 0, + /* 865 - */ 0, + /* 866 - */ 0, + /* 867 - */ 0, + /* 868 - */ 0, + /* 869 - */ 0, + /* 86a - */ 0, + /* 86b - */ 0, + /* 86c - _0F_3A_04 */ 0xd404, + /* 86d - _0F_3A_05 */ 0xd410, + /* 86e - _0F_3A_06 */ 0xd41c, + /* 86f - */ 0, + /* 870 - _0F_3A_08 */ 0xd428, + /* 871 - _0F_3A_09 */ 0xd434, + /* 872 - _0F_3A_0A */ 0xd440, + /* 873 - _0F_3A_0B */ 0xd44c, + /* 874 - _0F_3A_0C */ 0xd458, + /* 875 - _0F_3A_0D */ 0xd464, + /* 876 - _0F_3A_0E */ 0xd470, + /* 877 - _0F_3A_0F */ 0xd47c, + /* 878 - */ 0, + /* 879 - */ 0, + /* 87a - */ 0, + /* 87b - */ 0, + /* 87c - _0F_3A_14 */ 0xd488, + /* 87d - _0F_3A_15 */ 0xd494, + /* 87e - _0F_3A_16 */ 0xd4a0, + /* 87f - _0F_3A_17 */ 0xd4ac, + /* 880 - _0F_3A_18 */ 0xd4b8, + /* 881 - _0F_3A_19 */ 0xd4c4, + /* 882 - */ 0, + /* 883 - */ 0, + /* 884 - */ 0, + /* 885 - */ 0, + /* 886 - */ 0, + /* 887 - */ 0, + /* 888 - _0F_3A_20 */ 0xd4d0, + /* 889 - _0F_3A_21 */ 0xd4dc, + /* 88a - _0F_3A_22 */ 0xd4e8, + /* 88b - */ 0, + /* 88c - */ 0, + /* 88d - */ 0, + /* 88e - */ 0, + /* 88f - */ 0, + /* 890 - */ 0, + /* 891 - */ 0, + /* 892 - */ 0, + /* 893 - */ 0, + /* 894 - */ 0, + /* 895 - */ 0, + /* 896 - */ 0, + /* 897 - */ 0, + /* 898 - */ 0, + /* 899 - */ 0, + /* 89a - */ 0, + /* 89b - */ 0, + /* 89c - */ 0, + /* 89d - */ 0, + /* 89e - */ 0, + /* 89f - */ 0, + /* 8a0 - */ 0, + /* 8a1 - */ 0, + /* 8a2 - */ 0, + /* 8a3 - */ 0, + /* 8a4 - */ 0, + /* 8a5 - */ 0, + /* 8a6 - */ 0, + /* 8a7 - */ 0, + /* 8a8 - _0F_3A_40 */ 0xd4f4, + /* 8a9 - _0F_3A_41 */ 0xd500, + /* 8aa - _0F_3A_42 */ 0xd50c, + /* 8ab - */ 0, + /* 8ac - _0F_3A_44 */ 0xd518, + /* 8ad - */ 0, + /* 8ae - */ 0, + /* 8af - */ 0, + /* 8b0 - */ 0, + /* 8b1 - */ 0, + /* 8b2 - _0F_3A_4A */ 0xd524, + /* 8b3 - _0F_3A_4B */ 0xd530, + /* 8b4 - _0F_3A_4C */ 0xd53c, + /* 8b5 - */ 0, + /* 8b6 - */ 0, + /* 8b7 - */ 0, + /* 8b8 - */ 0, + /* 8b9 - */ 0, + /* 8ba - */ 0, + /* 8bb - */ 0, + /* 8bc - */ 0, + /* 8bd - */ 0, + /* 8be - */ 0, + /* 8bf - */ 0, + /* 8c0 - */ 0, + /* 8c1 - */ 0, + /* 8c2 - */ 0, + /* 8c3 - */ 0, + /* 8c4 - */ 0, + /* 8c5 - */ 0, + /* 8c6 - */ 0, + /* 8c7 - */ 0, + /* 8c8 - _0F_3A_60 */ 0xd548, + /* 8c9 - _0F_3A_61 */ 0xd554, + /* 8ca - _0F_3A_62 */ 0xd560, + /* 8cb - _0F_3A_63 */ 0xd56c, + /* 8cc - */ 0, + /* 8cd - */ 0, + /* 8ce - */ 0, + /* 8cf - */ 0, + /* 8d0 - */ 0, + /* 8d1 - */ 0, + /* 8d2 - */ 0, + /* 8d3 - */ 0, + /* 8d4 - */ 0, + /* 8d5 - */ 0, + /* 8d6 - */ 0, + /* 8d7 - */ 0, + /* 8d8 - */ 0, + /* 8d9 - */ 0, + /* 8da - */ 0, + /* 8db - */ 0, + /* 8dc - */ 0, + /* 8dd - */ 0, + /* 8de - */ 0, + /* 8df - */ 0, + /* 8e0 - */ 0, + /* 8e1 - */ 0, + /* 8e2 - */ 0, + /* 8e3 - */ 0, + /* 8e4 - */ 0, + /* 8e5 - */ 0, + /* 8e6 - */ 0, + /* 8e7 - */ 0, + /* 8e8 - */ 0, + /* 8e9 - */ 0, + /* 8ea - */ 0, + /* 8eb - */ 0, + /* 8ec - */ 0, + /* 8ed - */ 0, + /* 8ee - */ 0, + /* 8ef - */ 0, + /* 8f0 - */ 0, + /* 8f1 - */ 0, + /* 8f2 - */ 0, + /* 8f3 - */ 0, + /* 8f4 - */ 0, + /* 8f5 - */ 0, + /* 8f6 - */ 0, + /* 8f7 - */ 0, + /* 8f8 - */ 0, + /* 8f9 - */ 0, + /* 8fa - */ 0, + /* 8fb - */ 0, + /* 8fc - */ 0, + /* 8fd - */ 0, + /* 8fe - */ 0, + /* 8ff - */ 0, + /* 900 - */ 0, + /* 901 - */ 0, + /* 902 - */ 0, + /* 903 - */ 0, + /* 904 - */ 0, + /* 905 - */ 0, + /* 906 - */ 0, + /* 907 - */ 0, + /* 908 - */ 0, + /* 909 - */ 0, + /* 90a - */ 0, + /* 90b - */ 0, + /* 90c - */ 0, + /* 90d - */ 0, + /* 90e - */ 0, + /* 90f - */ 0, + /* 910 - */ 0, + /* 911 - */ 0, + /* 912 - */ 0, + /* 913 - */ 0, + /* 914 - */ 0, + /* 915 - */ 0, + /* 916 - */ 0, + /* 917 - */ 0, + /* 918 - */ 0, + /* 919 - */ 0, + /* 91a - */ 0, + /* 91b - */ 0, + /* 91c - */ 0, + /* 91d - */ 0, + /* 91e - */ 0, + /* 91f - */ 0, + /* 920 - */ 0, + /* 921 - */ 0, + /* 922 - */ 0, + /* 923 - */ 0, + /* 924 - */ 0, + /* 925 - */ 0, + /* 926 - */ 0, + /* 927 - */ 0, + /* 928 - */ 0, + /* 929 - */ 0, + /* 92a - */ 0, + /* 92b - */ 0, + /* 92c - */ 0, + /* 92d - */ 0, + /* 92e - */ 0, + /* 92f - */ 0, + /* 930 - */ 0, + /* 931 - */ 0, + /* 932 - */ 0, + /* 933 - */ 0, + /* 934 - */ 0, + /* 935 - */ 0, + /* 936 - */ 0, + /* 937 - */ 0, + /* 938 - */ 0, + /* 939 - */ 0, + /* 93a - */ 0, + /* 93b - */ 0, + /* 93c - */ 0, + /* 93d - */ 0, + /* 93e - */ 0, + /* 93f - */ 0, + /* 940 - */ 0, + /* 941 - */ 0, + /* 942 - */ 0, + /* 943 - */ 0, + /* 944 - */ 0, + /* 945 - */ 0, + /* 946 - */ 0, + /* 947 - _0F_3A_DF */ 0xd578, + /* 948 - */ 0, + /* 949 - */ 0, + /* 94a - */ 0, + /* 94b - */ 0, + /* 94c - */ 0, + /* 94d - */ 0, + /* 94e - */ 0, + /* 94f - */ 0, + /* 950 - */ 0, + /* 951 - */ 0, + /* 952 - */ 0, + /* 953 - */ 0, + /* 954 - */ 0, + /* 955 - */ 0, + /* 956 - */ 0, + /* 957 - */ 0, + /* 958 - */ 0, + /* 959 - */ 0, + /* 95a - */ 0, + /* 95b - */ 0, + /* 95c - */ 0, + /* 95d - */ 0, + /* 95e - */ 0, + /* 95f - */ 0, + /* 960 - */ 0, + /* 961 - */ 0, + /* 962 - */ 0, + /* 963 - */ 0, + /* 964 - */ 0, + /* 965 - */ 0, + /* 966 - */ 0, + /* 967 - */ 0, + /* 968 - _0F_50 */ 0x23a3, + /* 969 - _66_0F_50 */ 0x23a4, + /* 96a - */ 0, + /* 96b - */ 0, + /* 96c - _V_0F_50 */ 0x4036, + /* 96d - _V_66_0F_50 */ 0x4037, + /* 96e - */ 0, + /* 96f - */ 0, + /* 970 - */ 0, + /* 971 - */ 0, + /* 972 - */ 0, + /* 973 - */ 0, + /* 974 - _0F_51 */ 0x23a5, + /* 975 - _66_0F_51 */ 0x23a6, + /* 976 - _F3_0F_51 */ 0x23a7, + /* 977 - _F2_0F_51 */ 0x23a8, + /* 978 - _V_0F_51 */ 0x4038, + /* 979 - _V_66_0F_51 */ 0x4039, + /* 97a - _V_F3_0F_51 */ 0x403a, + /* 97b - _V_F2_0F_51 */ 0x403b, + /* 97c - */ 0, + /* 97d - */ 0, + /* 97e - */ 0, + /* 97f - */ 0, + /* 980 - _0F_52 */ 0x23a9, + /* 981 - */ 0, + /* 982 - _F3_0F_52 */ 0x23aa, + /* 983 - */ 0, + /* 984 - _V_0F_52 */ 0x403c, + /* 985 - */ 0, + /* 986 - _V_F3_0F_52 */ 0x403d, + /* 987 - */ 0, + /* 988 - */ 0, + /* 989 - */ 0, + /* 98a - */ 0, + /* 98b - */ 0, + /* 98c - _0F_53 */ 0x23ab, + /* 98d - */ 0, + /* 98e - _F3_0F_53 */ 0x23ac, + /* 98f - */ 0, + /* 990 - _V_0F_53 */ 0x403e, + /* 991 - */ 0, + /* 992 - _V_F3_0F_53 */ 0x403f, + /* 993 - */ 0, + /* 994 - */ 0, + /* 995 - */ 0, + /* 996 - */ 0, + /* 997 - */ 0, + /* 998 - _0F_54 */ 0x23ad, + /* 999 - _66_0F_54 */ 0x23ae, + /* 99a - */ 0, + /* 99b - */ 0, + /* 99c - _V_0F_54 */ 0x4040, + /* 99d - _V_66_0F_54 */ 0x4041, + /* 99e - */ 0, + /* 99f - */ 0, + /* 9a0 - */ 0, + /* 9a1 - */ 0, + /* 9a2 - */ 0, + /* 9a3 - */ 0, + /* 9a4 - _0F_55 */ 0x23af, + /* 9a5 - _66_0F_55 */ 0x23b0, + /* 9a6 - */ 0, + /* 9a7 - */ 0, + /* 9a8 - _V_0F_55 */ 0x4042, + /* 9a9 - _V_66_0F_55 */ 0x4043, + /* 9aa - */ 0, + /* 9ab - */ 0, + /* 9ac - */ 0, + /* 9ad - */ 0, + /* 9ae - */ 0, + /* 9af - */ 0, + /* 9b0 - _0F_56 */ 0x23b1, + /* 9b1 - _66_0F_56 */ 0x23b2, + /* 9b2 - */ 0, + /* 9b3 - */ 0, + /* 9b4 - _V_0F_56 */ 0x4044, + /* 9b5 - _V_66_0F_56 */ 0x4045, + /* 9b6 - */ 0, + /* 9b7 - */ 0, + /* 9b8 - */ 0, + /* 9b9 - */ 0, + /* 9ba - */ 0, + /* 9bb - */ 0, + /* 9bc - _0F_57 */ 0x23b3, + /* 9bd - _66_0F_57 */ 0x23b4, + /* 9be - */ 0, + /* 9bf - */ 0, + /* 9c0 - _V_0F_57 */ 0x4046, + /* 9c1 - _V_66_0F_57 */ 0x4047, + /* 9c2 - */ 0, + /* 9c3 - */ 0, + /* 9c4 - */ 0, + /* 9c5 - */ 0, + /* 9c6 - */ 0, + /* 9c7 - */ 0, + /* 9c8 - _0F_58 */ 0x23b5, + /* 9c9 - _66_0F_58 */ 0x23b6, + /* 9ca - _F3_0F_58 */ 0x23b7, + /* 9cb - _F2_0F_58 */ 0x23b8, + /* 9cc - _V_0F_58 */ 0x4048, + /* 9cd - _V_66_0F_58 */ 0x4049, + /* 9ce - _V_F3_0F_58 */ 0x404a, + /* 9cf - _V_F2_0F_58 */ 0x404b, + /* 9d0 - */ 0, + /* 9d1 - */ 0, + /* 9d2 - */ 0, + /* 9d3 - */ 0, + /* 9d4 - _0F_59 */ 0x23b9, + /* 9d5 - _66_0F_59 */ 0x23ba, + /* 9d6 - _F3_0F_59 */ 0x23bb, + /* 9d7 - _F2_0F_59 */ 0x23bc, + /* 9d8 - _V_0F_59 */ 0x404c, + /* 9d9 - _V_66_0F_59 */ 0x404d, + /* 9da - _V_F3_0F_59 */ 0x404e, + /* 9db - _V_F2_0F_59 */ 0x404f, + /* 9dc - */ 0, + /* 9dd - */ 0, + /* 9de - */ 0, + /* 9df - */ 0, + /* 9e0 - _0F_5A */ 0x23bd, + /* 9e1 - _66_0F_5A */ 0x23be, + /* 9e2 - _F3_0F_5A */ 0x23bf, + /* 9e3 - _F2_0F_5A */ 0x23c0, + /* 9e4 - _V_0F_5A */ 0x4050, + /* 9e5 - _V_66_0F_5A */ 0x4051, + /* 9e6 - _V_F3_0F_5A */ 0x4052, + /* 9e7 - _V_F2_0F_5A */ 0x4053, + /* 9e8 - */ 0, + /* 9e9 - */ 0, + /* 9ea - */ 0, + /* 9eb - */ 0, + /* 9ec - _0F_5B */ 0x23c1, + /* 9ed - _66_0F_5B */ 0x23c2, + /* 9ee - _F3_0F_5B */ 0x23c3, + /* 9ef - */ 0, + /* 9f0 - _V_0F_5B */ 0x4054, + /* 9f1 - _V_66_0F_5B */ 0x4055, + /* 9f2 - _V_F3_0F_5B */ 0x4056, + /* 9f3 - */ 0, + /* 9f4 - */ 0, + /* 9f5 - */ 0, + /* 9f6 - */ 0, + /* 9f7 - */ 0, + /* 9f8 - _0F_5C */ 0x23c4, + /* 9f9 - _66_0F_5C */ 0x23c5, + /* 9fa - _F3_0F_5C */ 0x23c6, + /* 9fb - _F2_0F_5C */ 0x23c7, + /* 9fc - _V_0F_5C */ 0x4057, + /* 9fd - _V_66_0F_5C */ 0x4058, + /* 9fe - _V_F3_0F_5C */ 0x4059, + /* 9ff - _V_F2_0F_5C */ 0x405a, + /* a00 - */ 0, + /* a01 - */ 0, + /* a02 - */ 0, + /* a03 - */ 0, + /* a04 - _0F_5D */ 0x23c8, + /* a05 - _66_0F_5D */ 0x23c9, + /* a06 - _F3_0F_5D */ 0x23ca, + /* a07 - _F2_0F_5D */ 0x23cb, + /* a08 - _V_0F_5D */ 0x405b, + /* a09 - _V_66_0F_5D */ 0x405c, + /* a0a - _V_F3_0F_5D */ 0x405d, + /* a0b - _V_F2_0F_5D */ 0x405e, + /* a0c - */ 0, + /* a0d - */ 0, + /* a0e - */ 0, + /* a0f - */ 0, + /* a10 - _0F_5E */ 0x23cc, + /* a11 - _66_0F_5E */ 0x23cd, + /* a12 - _F3_0F_5E */ 0x23ce, + /* a13 - _F2_0F_5E */ 0x23cf, + /* a14 - _V_0F_5E */ 0x405f, + /* a15 - _V_66_0F_5E */ 0x4060, + /* a16 - _V_F3_0F_5E */ 0x4061, + /* a17 - _V_F2_0F_5E */ 0x4062, + /* a18 - */ 0, + /* a19 - */ 0, + /* a1a - */ 0, + /* a1b - */ 0, + /* a1c - _0F_5F */ 0x23d0, + /* a1d - _66_0F_5F */ 0x23d1, + /* a1e - _F3_0F_5F */ 0x23d2, + /* a1f - _F2_0F_5F */ 0x23d3, + /* a20 - _V_0F_5F */ 0x4063, + /* a21 - _V_66_0F_5F */ 0x4064, + /* a22 - _V_F3_0F_5F */ 0x4065, + /* a23 - _V_F2_0F_5F */ 0x4066, + /* a24 - */ 0, + /* a25 - */ 0, + /* a26 - */ 0, + /* a27 - */ 0, + /* a28 - _0F_60 */ 0x23d4, + /* a29 - _66_0F_60 */ 0x23d5, + /* a2a - */ 0, + /* a2b - */ 0, + /* a2c - */ 0, + /* a2d - _V_66_0F_60 */ 0x4067, + /* a2e - */ 0, + /* a2f - */ 0, + /* a30 - */ 0, + /* a31 - */ 0, + /* a32 - */ 0, + /* a33 - */ 0, + /* a34 - _0F_61 */ 0x23d6, + /* a35 - _66_0F_61 */ 0x23d7, + /* a36 - */ 0, + /* a37 - */ 0, + /* a38 - */ 0, + /* a39 - _V_66_0F_61 */ 0x4068, + /* a3a - */ 0, + /* a3b - */ 0, + /* a3c - */ 0, + /* a3d - */ 0, + /* a3e - */ 0, + /* a3f - */ 0, + /* a40 - _0F_62 */ 0x23d8, + /* a41 - _66_0F_62 */ 0x23d9, + /* a42 - */ 0, + /* a43 - */ 0, + /* a44 - */ 0, + /* a45 - _V_66_0F_62 */ 0x4069, + /* a46 - */ 0, + /* a47 - */ 0, + /* a48 - */ 0, + /* a49 - */ 0, + /* a4a - */ 0, + /* a4b - */ 0, + /* a4c - _0F_63 */ 0x23da, + /* a4d - _66_0F_63 */ 0x23db, + /* a4e - */ 0, + /* a4f - */ 0, + /* a50 - */ 0, + /* a51 - _V_66_0F_63 */ 0x406a, + /* a52 - */ 0, + /* a53 - */ 0, + /* a54 - */ 0, + /* a55 - */ 0, + /* a56 - */ 0, + /* a57 - */ 0, + /* a58 - _0F_64 */ 0x23dc, + /* a59 - _66_0F_64 */ 0x23dd, + /* a5a - */ 0, + /* a5b - */ 0, + /* a5c - */ 0, + /* a5d - _V_66_0F_64 */ 0x406b, + /* a5e - */ 0, + /* a5f - */ 0, + /* a60 - */ 0, + /* a61 - */ 0, + /* a62 - */ 0, + /* a63 - */ 0, + /* a64 - _0F_65 */ 0x23de, + /* a65 - _66_0F_65 */ 0x23df, + /* a66 - */ 0, + /* a67 - */ 0, + /* a68 - */ 0, + /* a69 - _V_66_0F_65 */ 0x406c, + /* a6a - */ 0, + /* a6b - */ 0, + /* a6c - */ 0, + /* a6d - */ 0, + /* a6e - */ 0, + /* a6f - */ 0, + /* a70 - _0F_66 */ 0x23e0, + /* a71 - _66_0F_66 */ 0x23e1, + /* a72 - */ 0, + /* a73 - */ 0, + /* a74 - */ 0, + /* a75 - _V_66_0F_66 */ 0x406d, + /* a76 - */ 0, + /* a77 - */ 0, + /* a78 - */ 0, + /* a79 - */ 0, + /* a7a - */ 0, + /* a7b - */ 0, + /* a7c - _0F_67 */ 0x23e2, + /* a7d - _66_0F_67 */ 0x23e3, + /* a7e - */ 0, + /* a7f - */ 0, + /* a80 - */ 0, + /* a81 - _V_66_0F_67 */ 0x406e, + /* a82 - */ 0, + /* a83 - */ 0, + /* a84 - */ 0, + /* a85 - */ 0, + /* a86 - */ 0, + /* a87 - */ 0, + /* a88 - _0F_68 */ 0x23e4, + /* a89 - _66_0F_68 */ 0x23e5, + /* a8a - */ 0, + /* a8b - */ 0, + /* a8c - */ 0, + /* a8d - _V_66_0F_68 */ 0x406f, + /* a8e - */ 0, + /* a8f - */ 0, + /* a90 - */ 0, + /* a91 - */ 0, + /* a92 - */ 0, + /* a93 - */ 0, + /* a94 - _0F_69 */ 0x23e6, + /* a95 - _66_0F_69 */ 0x23e7, + /* a96 - */ 0, + /* a97 - */ 0, + /* a98 - */ 0, + /* a99 - _V_66_0F_69 */ 0x4070, + /* a9a - */ 0, + /* a9b - */ 0, + /* a9c - */ 0, + /* a9d - */ 0, + /* a9e - */ 0, + /* a9f - */ 0, + /* aa0 - _0F_6A */ 0x23e8, + /* aa1 - _66_0F_6A */ 0x23e9, + /* aa2 - */ 0, + /* aa3 - */ 0, + /* aa4 - */ 0, + /* aa5 - _V_66_0F_6A */ 0x4071, + /* aa6 - */ 0, + /* aa7 - */ 0, + /* aa8 - */ 0, + /* aa9 - */ 0, + /* aaa - */ 0, + /* aab - */ 0, + /* aac - _0F_6B */ 0x23ea, + /* aad - _66_0F_6B */ 0x23eb, + /* aae - */ 0, + /* aaf - */ 0, + /* ab0 - */ 0, + /* ab1 - _V_66_0F_6B */ 0x4072, + /* ab2 - */ 0, + /* ab3 - */ 0, + /* ab4 - */ 0, + /* ab5 - */ 0, + /* ab6 - */ 0, + /* ab7 - */ 0, + /* ab8 - */ 0, + /* ab9 - _66_0F_6C */ 0x23ec, + /* aba - */ 0, + /* abb - */ 0, + /* abc - */ 0, + /* abd - _V_66_0F_6C */ 0x4073, + /* abe - */ 0, + /* abf - */ 0, + /* ac0 - */ 0, + /* ac1 - */ 0, + /* ac2 - */ 0, + /* ac3 - */ 0, + /* ac4 - */ 0, + /* ac5 - _66_0F_6D */ 0x23ed, + /* ac6 - */ 0, + /* ac7 - */ 0, + /* ac8 - */ 0, + /* ac9 - _V_66_0F_6D */ 0x4074, + /* aca - */ 0, + /* acb - */ 0, + /* acc - */ 0, + /* acd - */ 0, + /* ace - */ 0, + /* acf - */ 0, + /* ad0 - _0F_6E */ 0x4075, + /* ad1 - _66_0F_6E */ 0x4076, + /* ad2 - */ 0, + /* ad3 - */ 0, + /* ad4 - */ 0, + /* ad5 - _V_66_0F_6E */ 0x4077, + /* ad6 - */ 0, + /* ad7 - */ 0, + /* ad8 - */ 0, + /* ad9 - */ 0, + /* ada - */ 0, + /* adb - */ 0, + /* adc - _0F_6F */ 0x23ee, + /* add - _66_0F_6F */ 0x23ef, + /* ade - _F3_0F_6F */ 0x23f0, + /* adf - */ 0, + /* ae0 - */ 0, + /* ae1 - _V_66_0F_6F */ 0x4078, + /* ae2 - _V_F3_0F_6F */ 0x4079, + /* ae3 - */ 0, + /* ae4 - */ 0, + /* ae5 - */ 0, + /* ae6 - */ 0, + /* ae7 - */ 0, + /* ae8 - _0F_70 */ 0x407a, + /* ae9 - _66_0F_70 */ 0x407b, + /* aea - _F3_0F_70 */ 0x407c, + /* aeb - _F2_0F_70 */ 0x407d, + /* aec - */ 0, + /* aed - _V_66_0F_70 */ 0x407e, + /* aee - _V_F3_0F_70 */ 0x407f, + /* aef - _V_F2_0F_70 */ 0x4080, + /* af0 - */ 0, + /* af1 - */ 0, + /* af2 - */ 0, + /* af3 - */ 0, + /* af4 - */ 0, + /* af5 - */ 0, + /* af6 - _0F_71_02 */ 0xd584, + /* af7 - */ 0, + /* af8 - _0F_71_04 */ 0xd590, + /* af9 - */ 0, + /* afa - _0F_71_06 */ 0xd59c, + /* afb - */ 0, + /* afc - */ 0, + /* afd - */ 0, + /* afe - _0F_72_02 */ 0xd5a8, + /* aff - */ 0, + /* b00 - _0F_72_04 */ 0xd5b4, + /* b01 - */ 0, + /* b02 - _0F_72_06 */ 0xd5c0, + /* b03 - */ 0, + /* b04 - */ 0, + /* b05 - */ 0, + /* b06 - _0F_73_02 */ 0xd5cc, + /* b07 - _0F_73_03 */ 0xd5d8, + /* b08 - */ 0, + /* b09 - */ 0, + /* b0a - _0F_73_06 */ 0xd5e4, + /* b0b - _0F_73_07 */ 0xd5f0, + /* b0c - _0F_74 */ 0x23f1, + /* b0d - _66_0F_74 */ 0x23f2, + /* b0e - */ 0, + /* b0f - */ 0, + /* b10 - */ 0, + /* b11 - _V_66_0F_74 */ 0x4081, + /* b12 - */ 0, + /* b13 - */ 0, + /* b14 - */ 0, + /* b15 - */ 0, + /* b16 - */ 0, + /* b17 - */ 0, + /* b18 - _0F_75 */ 0x23f3, + /* b19 - _66_0F_75 */ 0x23f4, + /* b1a - */ 0, + /* b1b - */ 0, + /* b1c - */ 0, + /* b1d - _V_66_0F_75 */ 0x4082, + /* b1e - */ 0, + /* b1f - */ 0, + /* b20 - */ 0, + /* b21 - */ 0, + /* b22 - */ 0, + /* b23 - */ 0, + /* b24 - _0F_76 */ 0x23f5, + /* b25 - _66_0F_76 */ 0x23f6, + /* b26 - */ 0, + /* b27 - */ 0, + /* b28 - */ 0, + /* b29 - _V_66_0F_76 */ 0x4083, + /* b2a - */ 0, + /* b2b - */ 0, + /* b2c - */ 0, + /* b2d - */ 0, + /* b2e - */ 0, + /* b2f - */ 0, + /* b30 - _0F_77 */ 0x23f7, + /* b31 - */ 0, + /* b32 - */ 0, + /* b33 - */ 0, + /* b34 - _V_0F_77 */ 0x4084, + /* b35 - */ 0, + /* b36 - */ 0, + /* b37 - */ 0, + /* b38 - */ 0, + /* b39 - */ 0, + /* b3a - */ 0, + /* b3b - */ 0, + /* b3c - _0F_78 */ 0x23f8, + /* b3d - _66_0F_78 */ 0x4085, + /* b3e - */ 0, + /* b3f - _F2_0F_78 */ 0x4086, + /* b40 - */ 0, + /* b41 - */ 0, + /* b42 - */ 0, + /* b43 - */ 0, + /* b44 - */ 0, + /* b45 - */ 0, + /* b46 - */ 0, + /* b47 - */ 0, + /* b48 - _0F_79 */ 0x23f9, + /* b49 - _66_0F_79 */ 0x23fa, + /* b4a - */ 0, + /* b4b - _F2_0F_79 */ 0x23fb, + /* b4c - */ 0, + /* b4d - */ 0, + /* b4e - */ 0, + /* b4f - */ 0, + /* b50 - */ 0, + /* b51 - */ 0, + /* b52 - */ 0, + /* b53 - */ 0, + /* b54 - */ 0, + /* b55 - */ 0, + /* b56 - */ 0, + /* b57 - */ 0, + /* b58 - */ 0, + /* b59 - */ 0, + /* b5a - */ 0, + /* b5b - */ 0, + /* b5c - */ 0, + /* b5d - */ 0, + /* b5e - */ 0, + /* b5f - */ 0, + /* b60 - */ 0, + /* b61 - */ 0, + /* b62 - */ 0, + /* b63 - */ 0, + /* b64 - */ 0, + /* b65 - */ 0, + /* b66 - */ 0, + /* b67 - */ 0, + /* b68 - */ 0, + /* b69 - */ 0, + /* b6a - */ 0, + /* b6b - */ 0, + /* b6c - */ 0, + /* b6d - */ 0, + /* b6e - */ 0, + /* b6f - */ 0, + /* b70 - */ 0, + /* b71 - */ 0, + /* b72 - */ 0, + /* b73 - */ 0, + /* b74 - */ 0, + /* b75 - */ 0, + /* b76 - */ 0, + /* b77 - */ 0, + /* b78 - */ 0, + /* b79 - */ 0, + /* b7a - */ 0, + /* b7b - */ 0, + /* b7c - */ 0, + /* b7d - */ 0, + /* b7e - */ 0, + /* b7f - */ 0, + /* b80 - */ 0, + /* b81 - */ 0, + /* b82 - */ 0, + /* b83 - */ 0, + /* b84 - _0F_7A_30 */ 0x23fc, + /* b85 - _0F_7A_31 */ 0x23fd, + /* b86 - */ 0, + /* b87 - */ 0, + /* b88 - */ 0, + /* b89 - */ 0, + /* b8a - */ 0, + /* b8b - */ 0, + /* b8c - */ 0, + /* b8d - */ 0, + /* b8e - */ 0, + /* b8f - */ 0, + /* b90 - */ 0, + /* b91 - */ 0, + /* b92 - */ 0, + /* b93 - */ 0, + /* b94 - */ 0, + /* b95 - */ 0, + /* b96 - */ 0, + /* b97 - */ 0, + /* b98 - */ 0, + /* b99 - */ 0, + /* b9a - */ 0, + /* b9b - */ 0, + /* b9c - */ 0, + /* b9d - */ 0, + /* b9e - */ 0, + /* b9f - */ 0, + /* ba0 - */ 0, + /* ba1 - */ 0, + /* ba2 - */ 0, + /* ba3 - */ 0, + /* ba4 - */ 0, + /* ba5 - */ 0, + /* ba6 - */ 0, + /* ba7 - */ 0, + /* ba8 - */ 0, + /* ba9 - */ 0, + /* baa - */ 0, + /* bab - */ 0, + /* bac - */ 0, + /* bad - */ 0, + /* bae - */ 0, + /* baf - */ 0, + /* bb0 - */ 0, + /* bb1 - */ 0, + /* bb2 - */ 0, + /* bb3 - */ 0, + /* bb4 - */ 0, + /* bb5 - */ 0, + /* bb6 - */ 0, + /* bb7 - */ 0, + /* bb8 - */ 0, + /* bb9 - */ 0, + /* bba - */ 0, + /* bbb - */ 0, + /* bbc - */ 0, + /* bbd - */ 0, + /* bbe - */ 0, + /* bbf - */ 0, + /* bc0 - */ 0, + /* bc1 - */ 0, + /* bc2 - */ 0, + /* bc3 - */ 0, + /* bc4 - */ 0, + /* bc5 - */ 0, + /* bc6 - */ 0, + /* bc7 - */ 0, + /* bc8 - */ 0, + /* bc9 - */ 0, + /* bca - */ 0, + /* bcb - */ 0, + /* bcc - */ 0, + /* bcd - */ 0, + /* bce - */ 0, + /* bcf - */ 0, + /* bd0 - */ 0, + /* bd1 - */ 0, + /* bd2 - */ 0, + /* bd3 - */ 0, + /* bd4 - */ 0, + /* bd5 - */ 0, + /* bd6 - */ 0, + /* bd7 - */ 0, + /* bd8 - */ 0, + /* bd9 - */ 0, + /* bda - */ 0, + /* bdb - */ 0, + /* bdc - */ 0, + /* bdd - */ 0, + /* bde - */ 0, + /* bdf - */ 0, + /* be0 - */ 0, + /* be1 - */ 0, + /* be2 - */ 0, + /* be3 - */ 0, + /* be4 - */ 0, + /* be5 - */ 0, + /* be6 - */ 0, + /* be7 - */ 0, + /* be8 - */ 0, + /* be9 - */ 0, + /* bea - */ 0, + /* beb - */ 0, + /* bec - */ 0, + /* bed - */ 0, + /* bee - */ 0, + /* bef - */ 0, + /* bf0 - */ 0, + /* bf1 - */ 0, + /* bf2 - */ 0, + /* bf3 - */ 0, + /* bf4 - */ 0, + /* bf5 - */ 0, + /* bf6 - */ 0, + /* bf7 - */ 0, + /* bf8 - */ 0, + /* bf9 - */ 0, + /* bfa - */ 0, + /* bfb - */ 0, + /* bfc - */ 0, + /* bfd - */ 0, + /* bfe - */ 0, + /* bff - */ 0, + /* c00 - */ 0, + /* c01 - */ 0, + /* c02 - */ 0, + /* c03 - */ 0, + /* c04 - */ 0, + /* c05 - */ 0, + /* c06 - */ 0, + /* c07 - */ 0, + /* c08 - */ 0, + /* c09 - */ 0, + /* c0a - */ 0, + /* c0b - */ 0, + /* c0c - */ 0, + /* c0d - */ 0, + /* c0e - */ 0, + /* c0f - */ 0, + /* c10 - */ 0, + /* c11 - */ 0, + /* c12 - */ 0, + /* c13 - */ 0, + /* c14 - */ 0, + /* c15 - */ 0, + /* c16 - */ 0, + /* c17 - */ 0, + /* c18 - */ 0, + /* c19 - */ 0, + /* c1a - */ 0, + /* c1b - */ 0, + /* c1c - */ 0, + /* c1d - */ 0, + /* c1e - */ 0, + /* c1f - */ 0, + /* c20 - */ 0, + /* c21 - */ 0, + /* c22 - */ 0, + /* c23 - */ 0, + /* c24 - */ 0, + /* c25 - */ 0, + /* c26 - */ 0, + /* c27 - */ 0, + /* c28 - */ 0, + /* c29 - */ 0, + /* c2a - */ 0, + /* c2b - */ 0, + /* c2c - */ 0, + /* c2d - */ 0, + /* c2e - */ 0, + /* c2f - */ 0, + /* c30 - */ 0, + /* c31 - */ 0, + /* c32 - */ 0, + /* c33 - */ 0, + /* c34 - */ 0, + /* c35 - */ 0, + /* c36 - */ 0, + /* c37 - */ 0, + /* c38 - */ 0, + /* c39 - */ 0, + /* c3a - */ 0, + /* c3b - */ 0, + /* c3c - */ 0, + /* c3d - */ 0, + /* c3e - */ 0, + /* c3f - */ 0, + /* c40 - */ 0, + /* c41 - */ 0, + /* c42 - */ 0, + /* c43 - */ 0, + /* c44 - */ 0, + /* c45 - */ 0, + /* c46 - */ 0, + /* c47 - */ 0, + /* c48 - */ 0, + /* c49 - */ 0, + /* c4a - */ 0, + /* c4b - */ 0, + /* c4c - */ 0, + /* c4d - */ 0, + /* c4e - */ 0, + /* c4f - */ 0, + /* c50 - */ 0, + /* c51 - */ 0, + /* c52 - */ 0, + /* c53 - */ 0, + /* c54 - */ 0, + /* c55 - _66_0F_7C */ 0x23fe, + /* c56 - */ 0, + /* c57 - _F2_0F_7C */ 0x23ff, + /* c58 - */ 0, + /* c59 - _V_66_0F_7C */ 0x4087, + /* c5a - */ 0, + /* c5b - _V_F2_0F_7C */ 0x4088, + /* c5c - */ 0, + /* c5d - */ 0, + /* c5e - */ 0, + /* c5f - */ 0, + /* c60 - */ 0, + /* c61 - _66_0F_7D */ 0x2400, + /* c62 - */ 0, + /* c63 - _F2_0F_7D */ 0x2401, + /* c64 - */ 0, + /* c65 - _V_66_0F_7D */ 0x4089, + /* c66 - */ 0, + /* c67 - _V_F2_0F_7D */ 0x408a, + /* c68 - */ 0, + /* c69 - */ 0, + /* c6a - */ 0, + /* c6b - */ 0, + /* c6c - _0F_7E */ 0x408b, + /* c6d - _66_0F_7E */ 0x408c, + /* c6e - _F3_0F_7E */ 0x2402, + /* c6f - */ 0, + /* c70 - */ 0, + /* c71 - _V_66_0F_7E */ 0x408d, + /* c72 - _V_F3_0F_7E */ 0x408e, + /* c73 - */ 0, + /* c74 - */ 0, + /* c75 - */ 0, + /* c76 - */ 0, + /* c77 - */ 0, + /* c78 - _0F_7F */ 0x2403, + /* c79 - _66_0F_7F */ 0x2404, + /* c7a - _F3_0F_7F */ 0x2405, + /* c7b - */ 0, + /* c7c - */ 0, + /* c7d - _V_66_0F_7F */ 0x408f, + /* c7e - _V_F3_0F_7F */ 0x4090, + /* c7f - */ 0, + /* c80 - */ 0, + /* c81 - */ 0, + /* c82 - */ 0, + /* c83 - */ 0, + /* c84 - _0F_AE_00 */ 0xd5fc, + /* c85 - _0F_AE_01 */ 0xd608, + /* c86 - _0F_AE_02 */ 0xd614, + /* c87 - _0F_AE_03 */ 0xd620, + /* c88 - _0F_AE_04 */ 0x4091, + /* c89 - _0F_AE_05 */ 0x4092, + /* c8a - _0F_AE_06 */ 0x4093, + /* c8b - _0F_AE_07 */ 0x4094, + /* c8c - */ 0, + /* c8d - */ 0, + /* c8e - _F3_0F_B8 */ 0x2406, + /* c8f - */ 0, + /* c90 - */ 0, + /* c91 - */ 0, + /* c92 - */ 0, + /* c93 - */ 0, + /* c94 - */ 0, + /* c95 - */ 0, + /* c96 - */ 0, + /* c97 - */ 0, + /* c98 - */ 0, + /* c99 - */ 0, + /* c9a - */ 0, + /* c9b - */ 0, + /* c9c - _0F_BA_04 */ 0x2407, + /* c9d - _0F_BA_05 */ 0x2408, + /* c9e - _0F_BA_06 */ 0x2409, + /* c9f - _0F_BA_07 */ 0x240a, + /* ca0 - _0F_BC */ 0x240b, + /* ca1 - */ 0, + /* ca2 - _F3_0F_BC */ 0x240c, + /* ca3 - */ 0, + /* ca4 - */ 0, + /* ca5 - */ 0, + /* ca6 - */ 0, + /* ca7 - */ 0, + /* ca8 - */ 0, + /* ca9 - */ 0, + /* caa - */ 0, + /* cab - */ 0, + /* cac - _0F_BD */ 0x240d, + /* cad - */ 0, + /* cae - _F3_0F_BD */ 0x240e, + /* caf - */ 0, + /* cb0 - */ 0, + /* cb1 - */ 0, + /* cb2 - */ 0, + /* cb3 - */ 0, + /* cb4 - */ 0, + /* cb5 - */ 0, + /* cb6 - */ 0, + /* cb7 - */ 0, + /* cb8 - _0F_C2 */ 0x4095, + /* cb9 - _66_0F_C2 */ 0x4096, + /* cba - _F3_0F_C2 */ 0x4097, + /* cbb - _F2_0F_C2 */ 0x4098, + /* cbc - _V_0F_C2 */ 0x4099, + /* cbd - _V_66_0F_C2 */ 0x409a, + /* cbe - _V_F3_0F_C2 */ 0x409b, + /* cbf - _V_F2_0F_C2 */ 0x409c, + /* cc0 - */ 0, + /* cc1 - */ 0, + /* cc2 - */ 0, + /* cc3 - */ 0, + /* cc4 - _0F_C4 */ 0x409d, + /* cc5 - _66_0F_C4 */ 0x409e, + /* cc6 - */ 0, + /* cc7 - */ 0, + /* cc8 - */ 0, + /* cc9 - _V_66_0F_C4 */ 0x409f, + /* cca - */ 0, + /* ccb - */ 0, + /* ccc - */ 0, + /* ccd - */ 0, + /* cce - */ 0, + /* ccf - */ 0, + /* cd0 - _0F_C5 */ 0x40a0, + /* cd1 - _66_0F_C5 */ 0x40a1, + /* cd2 - */ 0, + /* cd3 - */ 0, + /* cd4 - */ 0, + /* cd5 - _V_66_0F_C5 */ 0x40a2, + /* cd6 - */ 0, + /* cd7 - */ 0, + /* cd8 - */ 0, + /* cd9 - */ 0, + /* cda - */ 0, + /* cdb - */ 0, + /* cdc - _0F_C6 */ 0x40a3, + /* cdd - _66_0F_C6 */ 0x40a4, + /* cde - */ 0, + /* cdf - */ 0, + /* ce0 - _V_0F_C6 */ 0x40a5, + /* ce1 - _V_66_0F_C6 */ 0x40a6, + /* ce2 - */ 0, + /* ce3 - */ 0, + /* ce4 - */ 0, + /* ce5 - */ 0, + /* ce6 - */ 0, + /* ce7 - */ 0, + /* ce8 - */ 0, + /* ce9 - _0F_C7_01 */ 0x40a7, + /* cea - */ 0, + /* ceb - */ 0, + /* cec - */ 0, + /* ced - */ 0, + /* cee - _0F_C7_06 */ 0xd62c, + /* cef - _0F_C7_07 */ 0x240f, + /* cf0 - */ 0, + /* cf1 - _66_0F_D0 */ 0x2410, + /* cf2 - */ 0, + /* cf3 - _F2_0F_D0 */ 0x2411, + /* cf4 - */ 0, + /* cf5 - _V_66_0F_D0 */ 0x40a8, + /* cf6 - */ 0, + /* cf7 - _V_F2_0F_D0 */ 0x40a9, + /* cf8 - */ 0, + /* cf9 - */ 0, + /* cfa - */ 0, + /* cfb - */ 0, + /* cfc - _0F_D1 */ 0x2412, + /* cfd - _66_0F_D1 */ 0x2413, + /* cfe - */ 0, + /* cff - */ 0, + /* d00 - */ 0, + /* d01 - _V_66_0F_D1 */ 0x40aa, + /* d02 - */ 0, + /* d03 - */ 0, + /* d04 - */ 0, + /* d05 - */ 0, + /* d06 - */ 0, + /* d07 - */ 0, + /* d08 - _0F_D2 */ 0x2414, + /* d09 - _66_0F_D2 */ 0x2415, + /* d0a - */ 0, + /* d0b - */ 0, + /* d0c - */ 0, + /* d0d - _V_66_0F_D2 */ 0x40ab, + /* d0e - */ 0, + /* d0f - */ 0, + /* d10 - */ 0, + /* d11 - */ 0, + /* d12 - */ 0, + /* d13 - */ 0, + /* d14 - _0F_D3 */ 0x2416, + /* d15 - _66_0F_D3 */ 0x2417, + /* d16 - */ 0, + /* d17 - */ 0, + /* d18 - */ 0, + /* d19 - _V_66_0F_D3 */ 0x40ac, + /* d1a - */ 0, + /* d1b - */ 0, + /* d1c - */ 0, + /* d1d - */ 0, + /* d1e - */ 0, + /* d1f - */ 0, + /* d20 - _0F_D4 */ 0x2418, + /* d21 - _66_0F_D4 */ 0x2419, + /* d22 - */ 0, + /* d23 - */ 0, + /* d24 - */ 0, + /* d25 - _V_66_0F_D4 */ 0x40ad, + /* d26 - */ 0, + /* d27 - */ 0, + /* d28 - */ 0, + /* d29 - */ 0, + /* d2a - */ 0, + /* d2b - */ 0, + /* d2c - _0F_D5 */ 0x241a, + /* d2d - _66_0F_D5 */ 0x241b, + /* d2e - */ 0, + /* d2f - */ 0, + /* d30 - */ 0, + /* d31 - _V_66_0F_D5 */ 0x40ae, + /* d32 - */ 0, + /* d33 - */ 0, + /* d34 - */ 0, + /* d35 - */ 0, + /* d36 - */ 0, + /* d37 - */ 0, + /* d38 - */ 0, + /* d39 - _66_0F_D6 */ 0x241c, + /* d3a - _F3_0F_D6 */ 0x241d, + /* d3b - _F2_0F_D6 */ 0x241e, + /* d3c - */ 0, + /* d3d - _V_66_0F_D6 */ 0x40af, + /* d3e - */ 0, + /* d3f - */ 0, + /* d40 - */ 0, + /* d41 - */ 0, + /* d42 - */ 0, + /* d43 - */ 0, + /* d44 - _0F_D7 */ 0x241f, + /* d45 - _66_0F_D7 */ 0x2420, + /* d46 - */ 0, + /* d47 - */ 0, + /* d48 - */ 0, + /* d49 - _V_66_0F_D7 */ 0x40b0, + /* d4a - */ 0, + /* d4b - */ 0, + /* d4c - */ 0, + /* d4d - */ 0, + /* d4e - */ 0, + /* d4f - */ 0, + /* d50 - _0F_D8 */ 0x2421, + /* d51 - _66_0F_D8 */ 0x2422, + /* d52 - */ 0, + /* d53 - */ 0, + /* d54 - */ 0, + /* d55 - _V_66_0F_D8 */ 0x40b1, + /* d56 - */ 0, + /* d57 - */ 0, + /* d58 - */ 0, + /* d59 - */ 0, + /* d5a - */ 0, + /* d5b - */ 0, + /* d5c - _0F_D9 */ 0x2423, + /* d5d - _66_0F_D9 */ 0x2424, + /* d5e - */ 0, + /* d5f - */ 0, + /* d60 - */ 0, + /* d61 - _V_66_0F_D9 */ 0x40b2, + /* d62 - */ 0, + /* d63 - */ 0, + /* d64 - */ 0, + /* d65 - */ 0, + /* d66 - */ 0, + /* d67 - */ 0, + /* d68 - _0F_DA */ 0x2425, + /* d69 - _66_0F_DA */ 0x2426, + /* d6a - */ 0, + /* d6b - */ 0, + /* d6c - */ 0, + /* d6d - _V_66_0F_DA */ 0x40b3, + /* d6e - */ 0, + /* d6f - */ 0, + /* d70 - */ 0, + /* d71 - */ 0, + /* d72 - */ 0, + /* d73 - */ 0, + /* d74 - _0F_DB */ 0x2427, + /* d75 - _66_0F_DB */ 0x2428, + /* d76 - */ 0, + /* d77 - */ 0, + /* d78 - */ 0, + /* d79 - _V_66_0F_DB */ 0x40b4, + /* d7a - */ 0, + /* d7b - */ 0, + /* d7c - */ 0, + /* d7d - */ 0, + /* d7e - */ 0, + /* d7f - */ 0, + /* d80 - _0F_DC */ 0x2429, + /* d81 - _66_0F_DC */ 0x242a, + /* d82 - */ 0, + /* d83 - */ 0, + /* d84 - */ 0, + /* d85 - _V_66_0F_DC */ 0x40b5, + /* d86 - */ 0, + /* d87 - */ 0, + /* d88 - */ 0, + /* d89 - */ 0, + /* d8a - */ 0, + /* d8b - */ 0, + /* d8c - _0F_DD */ 0x242b, + /* d8d - _66_0F_DD */ 0x242c, + /* d8e - */ 0, + /* d8f - */ 0, + /* d90 - */ 0, + /* d91 - _V_66_0F_DD */ 0x40b6, + /* d92 - */ 0, + /* d93 - */ 0, + /* d94 - */ 0, + /* d95 - */ 0, + /* d96 - */ 0, + /* d97 - */ 0, + /* d98 - _0F_DE */ 0x242d, + /* d99 - _66_0F_DE */ 0x242e, + /* d9a - */ 0, + /* d9b - */ 0, + /* d9c - */ 0, + /* d9d - _V_66_0F_DE */ 0x40b7, + /* d9e - */ 0, + /* d9f - */ 0, + /* da0 - */ 0, + /* da1 - */ 0, + /* da2 - */ 0, + /* da3 - */ 0, + /* da4 - _0F_DF */ 0x242f, + /* da5 - _66_0F_DF */ 0x2430, + /* da6 - */ 0, + /* da7 - */ 0, + /* da8 - */ 0, + /* da9 - _V_66_0F_DF */ 0x40b8, + /* daa - */ 0, + /* dab - */ 0, + /* dac - */ 0, + /* dad - */ 0, + /* dae - */ 0, + /* daf - */ 0, + /* db0 - _0F_E0 */ 0x2431, + /* db1 - _66_0F_E0 */ 0x2432, + /* db2 - */ 0, + /* db3 - */ 0, + /* db4 - */ 0, + /* db5 - _V_66_0F_E0 */ 0x40b9, + /* db6 - */ 0, + /* db7 - */ 0, + /* db8 - */ 0, + /* db9 - */ 0, + /* dba - */ 0, + /* dbb - */ 0, + /* dbc - _0F_E1 */ 0x2433, + /* dbd - _66_0F_E1 */ 0x2434, + /* dbe - */ 0, + /* dbf - */ 0, + /* dc0 - */ 0, + /* dc1 - _V_66_0F_E1 */ 0x40ba, + /* dc2 - */ 0, + /* dc3 - */ 0, + /* dc4 - */ 0, + /* dc5 - */ 0, + /* dc6 - */ 0, + /* dc7 - */ 0, + /* dc8 - _0F_E2 */ 0x2435, + /* dc9 - _66_0F_E2 */ 0x2436, + /* dca - */ 0, + /* dcb - */ 0, + /* dcc - */ 0, + /* dcd - _V_66_0F_E2 */ 0x40bb, + /* dce - */ 0, + /* dcf - */ 0, + /* dd0 - */ 0, + /* dd1 - */ 0, + /* dd2 - */ 0, + /* dd3 - */ 0, + /* dd4 - _0F_E3 */ 0x2437, + /* dd5 - _66_0F_E3 */ 0x2438, + /* dd6 - */ 0, + /* dd7 - */ 0, + /* dd8 - */ 0, + /* dd9 - _V_66_0F_E3 */ 0x40bc, + /* dda - */ 0, + /* ddb - */ 0, + /* ddc - */ 0, + /* ddd - */ 0, + /* dde - */ 0, + /* ddf - */ 0, + /* de0 - _0F_E4 */ 0x2439, + /* de1 - _66_0F_E4 */ 0x243a, + /* de2 - */ 0, + /* de3 - */ 0, + /* de4 - */ 0, + /* de5 - _V_66_0F_E4 */ 0x40bd, + /* de6 - */ 0, + /* de7 - */ 0, + /* de8 - */ 0, + /* de9 - */ 0, + /* dea - */ 0, + /* deb - */ 0, + /* dec - _0F_E5 */ 0x243b, + /* ded - _66_0F_E5 */ 0x243c, + /* dee - */ 0, + /* def - */ 0, + /* df0 - */ 0, + /* df1 - _V_66_0F_E5 */ 0x40be, + /* df2 - */ 0, + /* df3 - */ 0, + /* df4 - */ 0, + /* df5 - */ 0, + /* df6 - */ 0, + /* df7 - */ 0, + /* df8 - */ 0, + /* df9 - _66_0F_E6 */ 0x243d, + /* dfa - _F3_0F_E6 */ 0x243e, + /* dfb - _F2_0F_E6 */ 0x243f, + /* dfc - */ 0, + /* dfd - _V_66_0F_E6 */ 0x40bf, + /* dfe - _V_F3_0F_E6 */ 0x40c0, + /* dff - _V_F2_0F_E6 */ 0x40c1, + /* e00 - */ 0, + /* e01 - */ 0, + /* e02 - */ 0, + /* e03 - */ 0, + /* e04 - _0F_E7 */ 0x2440, + /* e05 - _66_0F_E7 */ 0x2441, + /* e06 - */ 0, + /* e07 - */ 0, + /* e08 - */ 0, + /* e09 - _V_66_0F_E7 */ 0x40c2, + /* e0a - */ 0, + /* e0b - */ 0, + /* e0c - */ 0, + /* e0d - */ 0, + /* e0e - */ 0, + /* e0f - */ 0, + /* e10 - _0F_E8 */ 0x2442, + /* e11 - _66_0F_E8 */ 0x2443, + /* e12 - */ 0, + /* e13 - */ 0, + /* e14 - */ 0, + /* e15 - _V_66_0F_E8 */ 0x40c3, + /* e16 - */ 0, + /* e17 - */ 0, + /* e18 - */ 0, + /* e19 - */ 0, + /* e1a - */ 0, + /* e1b - */ 0, + /* e1c - _0F_E9 */ 0x2444, + /* e1d - _66_0F_E9 */ 0x2445, + /* e1e - */ 0, + /* e1f - */ 0, + /* e20 - */ 0, + /* e21 - _V_66_0F_E9 */ 0x40c4, + /* e22 - */ 0, + /* e23 - */ 0, + /* e24 - */ 0, + /* e25 - */ 0, + /* e26 - */ 0, + /* e27 - */ 0, + /* e28 - _0F_EA */ 0x2446, + /* e29 - _66_0F_EA */ 0x2447, + /* e2a - */ 0, + /* e2b - */ 0, + /* e2c - */ 0, + /* e2d - _V_66_0F_EA */ 0x40c5, + /* e2e - */ 0, + /* e2f - */ 0, + /* e30 - */ 0, + /* e31 - */ 0, + /* e32 - */ 0, + /* e33 - */ 0, + /* e34 - _0F_EB */ 0x2448, + /* e35 - _66_0F_EB */ 0x2449, + /* e36 - */ 0, + /* e37 - */ 0, + /* e38 - */ 0, + /* e39 - _V_66_0F_EB */ 0x40c6, + /* e3a - */ 0, + /* e3b - */ 0, + /* e3c - */ 0, + /* e3d - */ 0, + /* e3e - */ 0, + /* e3f - */ 0, + /* e40 - _0F_EC */ 0x244a, + /* e41 - _66_0F_EC */ 0x244b, + /* e42 - */ 0, + /* e43 - */ 0, + /* e44 - */ 0, + /* e45 - _V_66_0F_EC */ 0x40c7, + /* e46 - */ 0, + /* e47 - */ 0, + /* e48 - */ 0, + /* e49 - */ 0, + /* e4a - */ 0, + /* e4b - */ 0, + /* e4c - _0F_ED */ 0x244c, + /* e4d - _66_0F_ED */ 0x244d, + /* e4e - */ 0, + /* e4f - */ 0, + /* e50 - */ 0, + /* e51 - _V_66_0F_ED */ 0x40c8, + /* e52 - */ 0, + /* e53 - */ 0, + /* e54 - */ 0, + /* e55 - */ 0, + /* e56 - */ 0, + /* e57 - */ 0, + /* e58 - _0F_EE */ 0x244e, + /* e59 - _66_0F_EE */ 0x244f, + /* e5a - */ 0, + /* e5b - */ 0, + /* e5c - */ 0, + /* e5d - _V_66_0F_EE */ 0x40c9, + /* e5e - */ 0, + /* e5f - */ 0, + /* e60 - */ 0, + /* e61 - */ 0, + /* e62 - */ 0, + /* e63 - */ 0, + /* e64 - _0F_EF */ 0x2450, + /* e65 - _66_0F_EF */ 0x2451, + /* e66 - */ 0, + /* e67 - */ 0, + /* e68 - */ 0, + /* e69 - _V_66_0F_EF */ 0x40ca, + /* e6a - */ 0, + /* e6b - */ 0, + /* e6c - */ 0, + /* e6d - */ 0, + /* e6e - */ 0, + /* e6f - */ 0, + /* e70 - */ 0, + /* e71 - */ 0, + /* e72 - */ 0, + /* e73 - _F2_0F_F0 */ 0x2452, + /* e74 - */ 0, + /* e75 - */ 0, + /* e76 - */ 0, + /* e77 - _V_F2_0F_F0 */ 0x40cb, + /* e78 - */ 0, + /* e79 - */ 0, + /* e7a - */ 0, + /* e7b - */ 0, + /* e7c - _0F_F1 */ 0x2453, + /* e7d - _66_0F_F1 */ 0x2454, + /* e7e - */ 0, + /* e7f - */ 0, + /* e80 - */ 0, + /* e81 - _V_66_0F_F1 */ 0x40cc, + /* e82 - */ 0, + /* e83 - */ 0, + /* e84 - */ 0, + /* e85 - */ 0, + /* e86 - */ 0, + /* e87 - */ 0, + /* e88 - _0F_F2 */ 0x2455, + /* e89 - _66_0F_F2 */ 0x2456, + /* e8a - */ 0, + /* e8b - */ 0, + /* e8c - */ 0, + /* e8d - _V_66_0F_F2 */ 0x40cd, + /* e8e - */ 0, + /* e8f - */ 0, + /* e90 - */ 0, + /* e91 - */ 0, + /* e92 - */ 0, + /* e93 - */ 0, + /* e94 - _0F_F3 */ 0x2457, + /* e95 - _66_0F_F3 */ 0x2458, + /* e96 - */ 0, + /* e97 - */ 0, + /* e98 - */ 0, + /* e99 - _V_66_0F_F3 */ 0x40ce, + /* e9a - */ 0, + /* e9b - */ 0, + /* e9c - */ 0, + /* e9d - */ 0, + /* e9e - */ 0, + /* e9f - */ 0, + /* ea0 - _0F_F4 */ 0x2459, + /* ea1 - _66_0F_F4 */ 0x245a, + /* ea2 - */ 0, + /* ea3 - */ 0, + /* ea4 - */ 0, + /* ea5 - _V_66_0F_F4 */ 0x40cf, + /* ea6 - */ 0, + /* ea7 - */ 0, + /* ea8 - */ 0, + /* ea9 - */ 0, + /* eaa - */ 0, + /* eab - */ 0, + /* eac - _0F_F5 */ 0x245b, + /* ead - _66_0F_F5 */ 0x245c, + /* eae - */ 0, + /* eaf - */ 0, + /* eb0 - */ 0, + /* eb1 - _V_66_0F_F5 */ 0x40d0, + /* eb2 - */ 0, + /* eb3 - */ 0, + /* eb4 - */ 0, + /* eb5 - */ 0, + /* eb6 - */ 0, + /* eb7 - */ 0, + /* eb8 - _0F_F6 */ 0x245d, + /* eb9 - _66_0F_F6 */ 0x245e, + /* eba - */ 0, + /* ebb - */ 0, + /* ebc - */ 0, + /* ebd - _V_66_0F_F6 */ 0x40d1, + /* ebe - */ 0, + /* ebf - */ 0, + /* ec0 - */ 0, + /* ec1 - */ 0, + /* ec2 - */ 0, + /* ec3 - */ 0, + /* ec4 - _0F_F7 */ 0x245f, + /* ec5 - _66_0F_F7 */ 0x2460, + /* ec6 - */ 0, + /* ec7 - */ 0, + /* ec8 - */ 0, + /* ec9 - _V_66_0F_F7 */ 0x40d2, + /* eca - */ 0, + /* ecb - */ 0, + /* ecc - */ 0, + /* ecd - */ 0, + /* ece - */ 0, + /* ecf - */ 0, + /* ed0 - _0F_F8 */ 0x2461, + /* ed1 - _66_0F_F8 */ 0x2462, + /* ed2 - */ 0, + /* ed3 - */ 0, + /* ed4 - */ 0, + /* ed5 - _V_66_0F_F8 */ 0x40d3, + /* ed6 - */ 0, + /* ed7 - */ 0, + /* ed8 - */ 0, + /* ed9 - */ 0, + /* eda - */ 0, + /* edb - */ 0, + /* edc - _0F_F9 */ 0x2463, + /* edd - _66_0F_F9 */ 0x2464, + /* ede - */ 0, + /* edf - */ 0, + /* ee0 - */ 0, + /* ee1 - _V_66_0F_F9 */ 0x40d4, + /* ee2 - */ 0, + /* ee3 - */ 0, + /* ee4 - */ 0, + /* ee5 - */ 0, + /* ee6 - */ 0, + /* ee7 - */ 0, + /* ee8 - _0F_FA */ 0x2465, + /* ee9 - _66_0F_FA */ 0x2466, + /* eea - */ 0, + /* eeb - */ 0, + /* eec - */ 0, + /* eed - _V_66_0F_FA */ 0x40d5, + /* eee - */ 0, + /* eef - */ 0, + /* ef0 - */ 0, + /* ef1 - */ 0, + /* ef2 - */ 0, + /* ef3 - */ 0, + /* ef4 - _0F_FB */ 0x2467, + /* ef5 - _66_0F_FB */ 0x2468, + /* ef6 - */ 0, + /* ef7 - */ 0, + /* ef8 - */ 0, + /* ef9 - _V_66_0F_FB */ 0x40d6, + /* efa - */ 0, + /* efb - */ 0, + /* efc - */ 0, + /* efd - */ 0, + /* efe - */ 0, + /* eff - */ 0, + /* f00 - _0F_FC */ 0x2469, + /* f01 - _66_0F_FC */ 0x246a, + /* f02 - */ 0, + /* f03 - */ 0, + /* f04 - */ 0, + /* f05 - _V_66_0F_FC */ 0x40d7, + /* f06 - */ 0, + /* f07 - */ 0, + /* f08 - */ 0, + /* f09 - */ 0, + /* f0a - */ 0, + /* f0b - */ 0, + /* f0c - _0F_FD */ 0x246b, + /* f0d - _66_0F_FD */ 0x246c, + /* f0e - */ 0, + /* f0f - */ 0, + /* f10 - */ 0, + /* f11 - _V_66_0F_FD */ 0x40d8, + /* f12 - */ 0, + /* f13 - */ 0, + /* f14 - */ 0, + /* f15 - */ 0, + /* f16 - */ 0, + /* f17 - */ 0, + /* f18 - _0F_FE */ 0x246d, + /* f19 - _66_0F_FE */ 0x246e, + /* f1a - */ 0, + /* f1b - */ 0, + /* f1c - */ 0, + /* f1d - _V_66_0F_FE */ 0x40d9, + /* f1e - */ 0, + /* f1f - */ 0, + /* f20 - */ 0, + /* f21 - */ 0, + /* f22 - */ 0, + /* f23 - */ 0, + /* f24 - _D9_06 */ 0x246f, + /* f25 - _9B_D9_06 */ 0x2470, + /* f26 - */ 0, + /* f27 - */ 0, + /* f28 - */ 0, + /* f29 - */ 0, + /* f2a - */ 0, + /* f2b - */ 0, + /* f2c - */ 0, + /* f2d - */ 0, + /* f2e - */ 0, + /* f2f - */ 0, + /* f30 - _D9_07 */ 0x2471, + /* f31 - _9B_D9_07 */ 0x2472, + /* f32 - */ 0, + /* f33 - */ 0, + /* f34 - */ 0, + /* f35 - */ 0, + /* f36 - */ 0, + /* f37 - */ 0, + /* f38 - */ 0, + /* f39 - */ 0, + /* f3a - */ 0, + /* f3b - */ 0, + /* f3c - _DB_E2 */ 0x2473, + /* f3d - _9B_DB_E2 */ 0x2474, + /* f3e - */ 0, + /* f3f - */ 0, + /* f40 - */ 0, + /* f41 - */ 0, + /* f42 - */ 0, + /* f43 - */ 0, + /* f44 - */ 0, + /* f45 - */ 0, + /* f46 - */ 0, + /* f47 - */ 0, + /* f48 - _DB_E3 */ 0x2475, + /* f49 - _9B_DB_E3 */ 0x2476, + /* f4a - */ 0, + /* f4b - */ 0, + /* f4c - */ 0, + /* f4d - */ 0, + /* f4e - */ 0, + /* f4f - */ 0, + /* f50 - */ 0, + /* f51 - */ 0, + /* f52 - */ 0, + /* f53 - */ 0, + /* f54 - _DD_06 */ 0x2477, + /* f55 - _9B_DD_06 */ 0x2478, + /* f56 - */ 0, + /* f57 - */ 0, + /* f58 - */ 0, + /* f59 - */ 0, + /* f5a - */ 0, + /* f5b - */ 0, + /* f5c - */ 0, + /* f5d - */ 0, + /* f5e - */ 0, + /* f5f - */ 0, + /* f60 - _DD_07 */ 0x2479, + /* f61 - _9B_DD_07 */ 0x247a, + /* f62 - */ 0, + /* f63 - */ 0, + /* f64 - */ 0, + /* f65 - */ 0, + /* f66 - */ 0, + /* f67 - */ 0, + /* f68 - */ 0, + /* f69 - */ 0, + /* f6a - */ 0, + /* f6b - */ 0, + /* f6c - _DF_E0 */ 0x247b, + /* f6d - _9B_DF_E0 */ 0x247c, + /* f6e - */ 0, + /* f6f - */ 0, + /* f70 - */ 0, + /* f71 - */ 0, + /* f72 - */ 0, + /* f73 - */ 0, + /* f74 - */ 0, + /* f75 - */ 0, + /* f76 - */ 0, + /* f77 - */ 0, + /* f78 - _0F_38_00 */ 0x247d, + /* f79 - _66_0F_38_00 */ 0x247e, + /* f7a - */ 0, + /* f7b - */ 0, + /* f7c - */ 0, + /* f7d - _V_66_0F_38_00 */ 0x40da, + /* f7e - */ 0, + /* f7f - */ 0, + /* f80 - */ 0, + /* f81 - */ 0, + /* f82 - */ 0, + /* f83 - */ 0, + /* f84 - _0F_38_01 */ 0x247f, + /* f85 - _66_0F_38_01 */ 0x2480, + /* f86 - */ 0, + /* f87 - */ 0, + /* f88 - */ 0, + /* f89 - _V_66_0F_38_01 */ 0x40db, + /* f8a - */ 0, + /* f8b - */ 0, + /* f8c - */ 0, + /* f8d - */ 0, + /* f8e - */ 0, + /* f8f - */ 0, + /* f90 - _0F_38_02 */ 0x2481, + /* f91 - _66_0F_38_02 */ 0x2482, + /* f92 - */ 0, + /* f93 - */ 0, + /* f94 - */ 0, + /* f95 - _V_66_0F_38_02 */ 0x40dc, + /* f96 - */ 0, + /* f97 - */ 0, + /* f98 - */ 0, + /* f99 - */ 0, + /* f9a - */ 0, + /* f9b - */ 0, + /* f9c - _0F_38_03 */ 0x2483, + /* f9d - _66_0F_38_03 */ 0x2484, + /* f9e - */ 0, + /* f9f - */ 0, + /* fa0 - */ 0, + /* fa1 - _V_66_0F_38_03 */ 0x40dd, + /* fa2 - */ 0, + /* fa3 - */ 0, + /* fa4 - */ 0, + /* fa5 - */ 0, + /* fa6 - */ 0, + /* fa7 - */ 0, + /* fa8 - _0F_38_04 */ 0x2485, + /* fa9 - _66_0F_38_04 */ 0x2486, + /* faa - */ 0, + /* fab - */ 0, + /* fac - */ 0, + /* fad - _V_66_0F_38_04 */ 0x40de, + /* fae - */ 0, + /* faf - */ 0, + /* fb0 - */ 0, + /* fb1 - */ 0, + /* fb2 - */ 0, + /* fb3 - */ 0, + /* fb4 - _0F_38_05 */ 0x2487, + /* fb5 - _66_0F_38_05 */ 0x2488, + /* fb6 - */ 0, + /* fb7 - */ 0, + /* fb8 - */ 0, + /* fb9 - _V_66_0F_38_05 */ 0x40df, + /* fba - */ 0, + /* fbb - */ 0, + /* fbc - */ 0, + /* fbd - */ 0, + /* fbe - */ 0, + /* fbf - */ 0, + /* fc0 - _0F_38_06 */ 0x2489, + /* fc1 - _66_0F_38_06 */ 0x248a, + /* fc2 - */ 0, + /* fc3 - */ 0, + /* fc4 - */ 0, + /* fc5 - _V_66_0F_38_06 */ 0x40e0, + /* fc6 - */ 0, + /* fc7 - */ 0, + /* fc8 - */ 0, + /* fc9 - */ 0, + /* fca - */ 0, + /* fcb - */ 0, + /* fcc - _0F_38_07 */ 0x248b, + /* fcd - _66_0F_38_07 */ 0x248c, + /* fce - */ 0, + /* fcf - */ 0, + /* fd0 - */ 0, + /* fd1 - _V_66_0F_38_07 */ 0x40e1, + /* fd2 - */ 0, + /* fd3 - */ 0, + /* fd4 - */ 0, + /* fd5 - */ 0, + /* fd6 - */ 0, + /* fd7 - */ 0, + /* fd8 - _0F_38_08 */ 0x248d, + /* fd9 - _66_0F_38_08 */ 0x248e, + /* fda - */ 0, + /* fdb - */ 0, + /* fdc - */ 0, + /* fdd - _V_66_0F_38_08 */ 0x40e2, + /* fde - */ 0, + /* fdf - */ 0, + /* fe0 - */ 0, + /* fe1 - */ 0, + /* fe2 - */ 0, + /* fe3 - */ 0, + /* fe4 - _0F_38_09 */ 0x248f, + /* fe5 - _66_0F_38_09 */ 0x2490, + /* fe6 - */ 0, + /* fe7 - */ 0, + /* fe8 - */ 0, + /* fe9 - _V_66_0F_38_09 */ 0x40e3, + /* fea - */ 0, + /* feb - */ 0, + /* fec - */ 0, + /* fed - */ 0, + /* fee - */ 0, + /* fef - */ 0, + /* ff0 - _0F_38_0A */ 0x2491, + /* ff1 - _66_0F_38_0A */ 0x2492, + /* ff2 - */ 0, + /* ff3 - */ 0, + /* ff4 - */ 0, + /* ff5 - _V_66_0F_38_0A */ 0x40e4, + /* ff6 - */ 0, + /* ff7 - */ 0, + /* ff8 - */ 0, + /* ff9 - */ 0, + /* ffa - */ 0, + /* ffb - */ 0, + /* ffc - _0F_38_0B */ 0x2493, + /* ffd - _66_0F_38_0B */ 0x2494, + /* ffe - */ 0, + /* fff - */ 0, + /* 1000 - */ 0, + /* 1001 - _V_66_0F_38_0B */ 0x40e5, + /* 1002 - */ 0, + /* 1003 - */ 0, + /* 1004 - */ 0, + /* 1005 - */ 0, + /* 1006 - */ 0, + /* 1007 - */ 0, + /* 1008 - */ 0, + /* 1009 - */ 0, + /* 100a - */ 0, + /* 100b - */ 0, + /* 100c - */ 0, + /* 100d - _V_66_0F_38_0C */ 0x40e6, + /* 100e - */ 0, + /* 100f - */ 0, + /* 1010 - */ 0, + /* 1011 - */ 0, + /* 1012 - */ 0, + /* 1013 - */ 0, + /* 1014 - */ 0, + /* 1015 - */ 0, + /* 1016 - */ 0, + /* 1017 - */ 0, + /* 1018 - */ 0, + /* 1019 - _V_66_0F_38_0D */ 0x40e7, + /* 101a - */ 0, + /* 101b - */ 0, + /* 101c - */ 0, + /* 101d - */ 0, + /* 101e - */ 0, + /* 101f - */ 0, + /* 1020 - */ 0, + /* 1021 - */ 0, + /* 1022 - */ 0, + /* 1023 - */ 0, + /* 1024 - */ 0, + /* 1025 - _V_66_0F_38_0E */ 0x40e8, + /* 1026 - */ 0, + /* 1027 - */ 0, + /* 1028 - */ 0, + /* 1029 - */ 0, + /* 102a - */ 0, + /* 102b - */ 0, + /* 102c - */ 0, + /* 102d - */ 0, + /* 102e - */ 0, + /* 102f - */ 0, + /* 1030 - */ 0, + /* 1031 - _V_66_0F_38_0F */ 0x40e9, + /* 1032 - */ 0, + /* 1033 - */ 0, + /* 1034 - */ 0, + /* 1035 - */ 0, + /* 1036 - */ 0, + /* 1037 - */ 0, + /* 1038 - */ 0, + /* 1039 - _66_0F_38_10 */ 0x40ea, + /* 103a - */ 0, + /* 103b - */ 0, + /* 103c - */ 0, + /* 103d - */ 0, + /* 103e - */ 0, + /* 103f - */ 0, + /* 1040 - */ 0, + /* 1041 - */ 0, + /* 1042 - */ 0, + /* 1043 - */ 0, + /* 1044 - */ 0, + /* 1045 - _66_0F_38_14 */ 0x40eb, + /* 1046 - */ 0, + /* 1047 - */ 0, + /* 1048 - */ 0, + /* 1049 - */ 0, + /* 104a - */ 0, + /* 104b - */ 0, + /* 104c - */ 0, + /* 104d - */ 0, + /* 104e - */ 0, + /* 104f - */ 0, + /* 1050 - */ 0, + /* 1051 - _66_0F_38_15 */ 0x40ec, + /* 1052 - */ 0, + /* 1053 - */ 0, + /* 1054 - */ 0, + /* 1055 - */ 0, + /* 1056 - */ 0, + /* 1057 - */ 0, + /* 1058 - */ 0, + /* 1059 - */ 0, + /* 105a - */ 0, + /* 105b - */ 0, + /* 105c - */ 0, + /* 105d - _66_0F_38_17 */ 0x2495, + /* 105e - */ 0, + /* 105f - */ 0, + /* 1060 - */ 0, + /* 1061 - _V_66_0F_38_17 */ 0x40ed, + /* 1062 - */ 0, + /* 1063 - */ 0, + /* 1064 - */ 0, + /* 1065 - */ 0, + /* 1066 - */ 0, + /* 1067 - */ 0, + /* 1068 - */ 0, + /* 1069 - */ 0, + /* 106a - */ 0, + /* 106b - */ 0, + /* 106c - */ 0, + /* 106d - _V_66_0F_38_18 */ 0x40ee, + /* 106e - */ 0, + /* 106f - */ 0, + /* 1070 - */ 0, + /* 1071 - */ 0, + /* 1072 - */ 0, + /* 1073 - */ 0, + /* 1074 - */ 0, + /* 1075 - */ 0, + /* 1076 - */ 0, + /* 1077 - */ 0, + /* 1078 - */ 0, + /* 1079 - _V_66_0F_38_19 */ 0x40ef, + /* 107a - */ 0, + /* 107b - */ 0, + /* 107c - */ 0, + /* 107d - */ 0, + /* 107e - */ 0, + /* 107f - */ 0, + /* 1080 - */ 0, + /* 1081 - */ 0, + /* 1082 - */ 0, + /* 1083 - */ 0, + /* 1084 - */ 0, + /* 1085 - _V_66_0F_38_1A */ 0x40f0, + /* 1086 - */ 0, + /* 1087 - */ 0, + /* 1088 - */ 0, + /* 1089 - */ 0, + /* 108a - */ 0, + /* 108b - */ 0, + /* 108c - _0F_38_1C */ 0x2496, + /* 108d - _66_0F_38_1C */ 0x2497, + /* 108e - */ 0, + /* 108f - */ 0, + /* 1090 - */ 0, + /* 1091 - _V_66_0F_38_1C */ 0x40f1, + /* 1092 - */ 0, + /* 1093 - */ 0, + /* 1094 - */ 0, + /* 1095 - */ 0, + /* 1096 - */ 0, + /* 1097 - */ 0, + /* 1098 - _0F_38_1D */ 0x2498, + /* 1099 - _66_0F_38_1D */ 0x2499, + /* 109a - */ 0, + /* 109b - */ 0, + /* 109c - */ 0, + /* 109d - _V_66_0F_38_1D */ 0x40f2, + /* 109e - */ 0, + /* 109f - */ 0, + /* 10a0 - */ 0, + /* 10a1 - */ 0, + /* 10a2 - */ 0, + /* 10a3 - */ 0, + /* 10a4 - _0F_38_1E */ 0x249a, + /* 10a5 - _66_0F_38_1E */ 0x249b, + /* 10a6 - */ 0, + /* 10a7 - */ 0, + /* 10a8 - */ 0, + /* 10a9 - _V_66_0F_38_1E */ 0x40f3, + /* 10aa - */ 0, + /* 10ab - */ 0, + /* 10ac - */ 0, + /* 10ad - */ 0, + /* 10ae - */ 0, + /* 10af - */ 0, + /* 10b0 - */ 0, + /* 10b1 - _66_0F_38_20 */ 0x249c, + /* 10b2 - */ 0, + /* 10b3 - */ 0, + /* 10b4 - */ 0, + /* 10b5 - _V_66_0F_38_20 */ 0x40f4, + /* 10b6 - */ 0, + /* 10b7 - */ 0, + /* 10b8 - */ 0, + /* 10b9 - */ 0, + /* 10ba - */ 0, + /* 10bb - */ 0, + /* 10bc - */ 0, + /* 10bd - _66_0F_38_21 */ 0x249d, + /* 10be - */ 0, + /* 10bf - */ 0, + /* 10c0 - */ 0, + /* 10c1 - _V_66_0F_38_21 */ 0x40f5, + /* 10c2 - */ 0, + /* 10c3 - */ 0, + /* 10c4 - */ 0, + /* 10c5 - */ 0, + /* 10c6 - */ 0, + /* 10c7 - */ 0, + /* 10c8 - */ 0, + /* 10c9 - _66_0F_38_22 */ 0x249e, + /* 10ca - */ 0, + /* 10cb - */ 0, + /* 10cc - */ 0, + /* 10cd - _V_66_0F_38_22 */ 0x40f6, + /* 10ce - */ 0, + /* 10cf - */ 0, + /* 10d0 - */ 0, + /* 10d1 - */ 0, + /* 10d2 - */ 0, + /* 10d3 - */ 0, + /* 10d4 - */ 0, + /* 10d5 - _66_0F_38_23 */ 0x249f, + /* 10d6 - */ 0, + /* 10d7 - */ 0, + /* 10d8 - */ 0, + /* 10d9 - _V_66_0F_38_23 */ 0x40f7, + /* 10da - */ 0, + /* 10db - */ 0, + /* 10dc - */ 0, + /* 10dd - */ 0, + /* 10de - */ 0, + /* 10df - */ 0, + /* 10e0 - */ 0, + /* 10e1 - _66_0F_38_24 */ 0x24a0, + /* 10e2 - */ 0, + /* 10e3 - */ 0, + /* 10e4 - */ 0, + /* 10e5 - _V_66_0F_38_24 */ 0x40f8, + /* 10e6 - */ 0, + /* 10e7 - */ 0, + /* 10e8 - */ 0, + /* 10e9 - */ 0, + /* 10ea - */ 0, + /* 10eb - */ 0, + /* 10ec - */ 0, + /* 10ed - _66_0F_38_25 */ 0x24a1, + /* 10ee - */ 0, + /* 10ef - */ 0, + /* 10f0 - */ 0, + /* 10f1 - _V_66_0F_38_25 */ 0x40f9, + /* 10f2 - */ 0, + /* 10f3 - */ 0, + /* 10f4 - */ 0, + /* 10f5 - */ 0, + /* 10f6 - */ 0, + /* 10f7 - */ 0, + /* 10f8 - */ 0, + /* 10f9 - _66_0F_38_28 */ 0x24a2, + /* 10fa - */ 0, + /* 10fb - */ 0, + /* 10fc - */ 0, + /* 10fd - _V_66_0F_38_28 */ 0x40fa, + /* 10fe - */ 0, + /* 10ff - */ 0, + /* 1100 - */ 0, + /* 1101 - */ 0, + /* 1102 - */ 0, + /* 1103 - */ 0, + /* 1104 - */ 0, + /* 1105 - _66_0F_38_29 */ 0x24a3, + /* 1106 - */ 0, + /* 1107 - */ 0, + /* 1108 - */ 0, + /* 1109 - _V_66_0F_38_29 */ 0x40fb, + /* 110a - */ 0, + /* 110b - */ 0, + /* 110c - */ 0, + /* 110d - */ 0, + /* 110e - */ 0, + /* 110f - */ 0, + /* 1110 - */ 0, + /* 1111 - _66_0F_38_2A */ 0x24a4, + /* 1112 - */ 0, + /* 1113 - */ 0, + /* 1114 - */ 0, + /* 1115 - _V_66_0F_38_2A */ 0x40fc, + /* 1116 - */ 0, + /* 1117 - */ 0, + /* 1118 - */ 0, + /* 1119 - */ 0, + /* 111a - */ 0, + /* 111b - */ 0, + /* 111c - */ 0, + /* 111d - _66_0F_38_2B */ 0x24a5, + /* 111e - */ 0, + /* 111f - */ 0, + /* 1120 - */ 0, + /* 1121 - _V_66_0F_38_2B */ 0x40fd, + /* 1122 - */ 0, + /* 1123 - */ 0, + /* 1124 - */ 0, + /* 1125 - */ 0, + /* 1126 - */ 0, + /* 1127 - */ 0, + /* 1128 - */ 0, + /* 1129 - */ 0, + /* 112a - */ 0, + /* 112b - */ 0, + /* 112c - */ 0, + /* 112d - _V_66_0F_38_2C */ 0x40fe, + /* 112e - */ 0, + /* 112f - */ 0, + /* 1130 - */ 0, + /* 1131 - */ 0, + /* 1132 - */ 0, + /* 1133 - */ 0, + /* 1134 - */ 0, + /* 1135 - */ 0, + /* 1136 - */ 0, + /* 1137 - */ 0, + /* 1138 - */ 0, + /* 1139 - _V_66_0F_38_2D */ 0x40ff, + /* 113a - */ 0, + /* 113b - */ 0, + /* 113c - */ 0, + /* 113d - */ 0, + /* 113e - */ 0, + /* 113f - */ 0, + /* 1140 - */ 0, + /* 1141 - */ 0, + /* 1142 - */ 0, + /* 1143 - */ 0, + /* 1144 - */ 0, + /* 1145 - _V_66_0F_38_2E */ 0x4100, + /* 1146 - */ 0, + /* 1147 - */ 0, + /* 1148 - */ 0, + /* 1149 - */ 0, + /* 114a - */ 0, + /* 114b - */ 0, + /* 114c - */ 0, + /* 114d - */ 0, + /* 114e - */ 0, + /* 114f - */ 0, + /* 1150 - */ 0, + /* 1151 - _V_66_0F_38_2F */ 0x4101, + /* 1152 - */ 0, + /* 1153 - */ 0, + /* 1154 - */ 0, + /* 1155 - */ 0, + /* 1156 - */ 0, + /* 1157 - */ 0, + /* 1158 - */ 0, + /* 1159 - _66_0F_38_30 */ 0x24a6, + /* 115a - */ 0, + /* 115b - */ 0, + /* 115c - */ 0, + /* 115d - _V_66_0F_38_30 */ 0x4102, + /* 115e - */ 0, + /* 115f - */ 0, + /* 1160 - */ 0, + /* 1161 - */ 0, + /* 1162 - */ 0, + /* 1163 - */ 0, + /* 1164 - */ 0, + /* 1165 - _66_0F_38_31 */ 0x24a7, + /* 1166 - */ 0, + /* 1167 - */ 0, + /* 1168 - */ 0, + /* 1169 - _V_66_0F_38_31 */ 0x4103, + /* 116a - */ 0, + /* 116b - */ 0, + /* 116c - */ 0, + /* 116d - */ 0, + /* 116e - */ 0, + /* 116f - */ 0, + /* 1170 - */ 0, + /* 1171 - _66_0F_38_32 */ 0x24a8, + /* 1172 - */ 0, + /* 1173 - */ 0, + /* 1174 - */ 0, + /* 1175 - _V_66_0F_38_32 */ 0x4104, + /* 1176 - */ 0, + /* 1177 - */ 0, + /* 1178 - */ 0, + /* 1179 - */ 0, + /* 117a - */ 0, + /* 117b - */ 0, + /* 117c - */ 0, + /* 117d - _66_0F_38_33 */ 0x24a9, + /* 117e - */ 0, + /* 117f - */ 0, + /* 1180 - */ 0, + /* 1181 - _V_66_0F_38_33 */ 0x4105, + /* 1182 - */ 0, + /* 1183 - */ 0, + /* 1184 - */ 0, + /* 1185 - */ 0, + /* 1186 - */ 0, + /* 1187 - */ 0, + /* 1188 - */ 0, + /* 1189 - _66_0F_38_34 */ 0x24aa, + /* 118a - */ 0, + /* 118b - */ 0, + /* 118c - */ 0, + /* 118d - _V_66_0F_38_34 */ 0x4106, + /* 118e - */ 0, + /* 118f - */ 0, + /* 1190 - */ 0, + /* 1191 - */ 0, + /* 1192 - */ 0, + /* 1193 - */ 0, + /* 1194 - */ 0, + /* 1195 - _66_0F_38_35 */ 0x24ab, + /* 1196 - */ 0, + /* 1197 - */ 0, + /* 1198 - */ 0, + /* 1199 - _V_66_0F_38_35 */ 0x4107, + /* 119a - */ 0, + /* 119b - */ 0, + /* 119c - */ 0, + /* 119d - */ 0, + /* 119e - */ 0, + /* 119f - */ 0, + /* 11a0 - */ 0, + /* 11a1 - _66_0F_38_37 */ 0x24ac, + /* 11a2 - */ 0, + /* 11a3 - */ 0, + /* 11a4 - */ 0, + /* 11a5 - _V_66_0F_38_37 */ 0x4108, + /* 11a6 - */ 0, + /* 11a7 - */ 0, + /* 11a8 - */ 0, + /* 11a9 - */ 0, + /* 11aa - */ 0, + /* 11ab - */ 0, + /* 11ac - */ 0, + /* 11ad - _66_0F_38_38 */ 0x24ad, + /* 11ae - */ 0, + /* 11af - */ 0, + /* 11b0 - */ 0, + /* 11b1 - _V_66_0F_38_38 */ 0x4109, + /* 11b2 - */ 0, + /* 11b3 - */ 0, + /* 11b4 - */ 0, + /* 11b5 - */ 0, + /* 11b6 - */ 0, + /* 11b7 - */ 0, + /* 11b8 - */ 0, + /* 11b9 - _66_0F_38_39 */ 0x24ae, + /* 11ba - */ 0, + /* 11bb - */ 0, + /* 11bc - */ 0, + /* 11bd - _V_66_0F_38_39 */ 0x410a, + /* 11be - */ 0, + /* 11bf - */ 0, + /* 11c0 - */ 0, + /* 11c1 - */ 0, + /* 11c2 - */ 0, + /* 11c3 - */ 0, + /* 11c4 - */ 0, + /* 11c5 - _66_0F_38_3A */ 0x24af, + /* 11c6 - */ 0, + /* 11c7 - */ 0, + /* 11c8 - */ 0, + /* 11c9 - _V_66_0F_38_3A */ 0x410b, + /* 11ca - */ 0, + /* 11cb - */ 0, + /* 11cc - */ 0, + /* 11cd - */ 0, + /* 11ce - */ 0, + /* 11cf - */ 0, + /* 11d0 - */ 0, + /* 11d1 - _66_0F_38_3B */ 0x24b0, + /* 11d2 - */ 0, + /* 11d3 - */ 0, + /* 11d4 - */ 0, + /* 11d5 - _V_66_0F_38_3B */ 0x410c, + /* 11d6 - */ 0, + /* 11d7 - */ 0, + /* 11d8 - */ 0, + /* 11d9 - */ 0, + /* 11da - */ 0, + /* 11db - */ 0, + /* 11dc - */ 0, + /* 11dd - _66_0F_38_3C */ 0x24b1, + /* 11de - */ 0, + /* 11df - */ 0, + /* 11e0 - */ 0, + /* 11e1 - _V_66_0F_38_3C */ 0x410d, + /* 11e2 - */ 0, + /* 11e3 - */ 0, + /* 11e4 - */ 0, + /* 11e5 - */ 0, + /* 11e6 - */ 0, + /* 11e7 - */ 0, + /* 11e8 - */ 0, + /* 11e9 - _66_0F_38_3D */ 0x24b2, + /* 11ea - */ 0, + /* 11eb - */ 0, + /* 11ec - */ 0, + /* 11ed - _V_66_0F_38_3D */ 0x410e, + /* 11ee - */ 0, + /* 11ef - */ 0, + /* 11f0 - */ 0, + /* 11f1 - */ 0, + /* 11f2 - */ 0, + /* 11f3 - */ 0, + /* 11f4 - */ 0, + /* 11f5 - _66_0F_38_3E */ 0x24b3, + /* 11f6 - */ 0, + /* 11f7 - */ 0, + /* 11f8 - */ 0, + /* 11f9 - _V_66_0F_38_3E */ 0x410f, + /* 11fa - */ 0, + /* 11fb - */ 0, + /* 11fc - */ 0, + /* 11fd - */ 0, + /* 11fe - */ 0, + /* 11ff - */ 0, + /* 1200 - */ 0, + /* 1201 - _66_0F_38_3F */ 0x24b4, + /* 1202 - */ 0, + /* 1203 - */ 0, + /* 1204 - */ 0, + /* 1205 - _V_66_0F_38_3F */ 0x4110, + /* 1206 - */ 0, + /* 1207 - */ 0, + /* 1208 - */ 0, + /* 1209 - */ 0, + /* 120a - */ 0, + /* 120b - */ 0, + /* 120c - */ 0, + /* 120d - _66_0F_38_40 */ 0x24b5, + /* 120e - */ 0, + /* 120f - */ 0, + /* 1210 - */ 0, + /* 1211 - _V_66_0F_38_40 */ 0x4111, + /* 1212 - */ 0, + /* 1213 - */ 0, + /* 1214 - */ 0, + /* 1215 - */ 0, + /* 1216 - */ 0, + /* 1217 - */ 0, + /* 1218 - */ 0, + /* 1219 - _66_0F_38_41 */ 0x24b6, + /* 121a - */ 0, + /* 121b - */ 0, + /* 121c - */ 0, + /* 121d - _V_66_0F_38_41 */ 0x4112, + /* 121e - */ 0, + /* 121f - */ 0, + /* 1220 - */ 0, + /* 1221 - */ 0, + /* 1222 - */ 0, + /* 1223 - */ 0, + /* 1224 - */ 0, + /* 1225 - _66_0F_38_80 */ 0x24b7, + /* 1226 - */ 0, + /* 1227 - */ 0, + /* 1228 - */ 0, + /* 1229 - */ 0, + /* 122a - */ 0, + /* 122b - */ 0, + /* 122c - */ 0, + /* 122d - */ 0, + /* 122e - */ 0, + /* 122f - */ 0, + /* 1230 - */ 0, + /* 1231 - _66_0F_38_81 */ 0x24b8, + /* 1232 - */ 0, + /* 1233 - */ 0, + /* 1234 - */ 0, + /* 1235 - */ 0, + /* 1236 - */ 0, + /* 1237 - */ 0, + /* 1238 - */ 0, + /* 1239 - */ 0, + /* 123a - */ 0, + /* 123b - */ 0, + /* 123c - */ 0, + /* 123d - _66_0F_38_82 */ 0x24b9, + /* 123e - */ 0, + /* 123f - */ 0, + /* 1240 - */ 0, + /* 1241 - */ 0, + /* 1242 - */ 0, + /* 1243 - */ 0, + /* 1244 - */ 0, + /* 1245 - */ 0, + /* 1246 - */ 0, + /* 1247 - */ 0, + /* 1248 - */ 0, + /* 1249 - */ 0, + /* 124a - */ 0, + /* 124b - */ 0, + /* 124c - */ 0, + /* 124d - _V_66_0F_38_96 */ 0x4113, + /* 124e - */ 0, + /* 124f - */ 0, + /* 1250 - */ 0, + /* 1251 - */ 0, + /* 1252 - */ 0, + /* 1253 - */ 0, + /* 1254 - */ 0, + /* 1255 - */ 0, + /* 1256 - */ 0, + /* 1257 - */ 0, + /* 1258 - */ 0, + /* 1259 - _V_66_0F_38_97 */ 0x4114, + /* 125a - */ 0, + /* 125b - */ 0, + /* 125c - */ 0, + /* 125d - */ 0, + /* 125e - */ 0, + /* 125f - */ 0, + /* 1260 - */ 0, + /* 1261 - */ 0, + /* 1262 - */ 0, + /* 1263 - */ 0, + /* 1264 - */ 0, + /* 1265 - _V_66_0F_38_98 */ 0x4115, + /* 1266 - */ 0, + /* 1267 - */ 0, + /* 1268 - */ 0, + /* 1269 - */ 0, + /* 126a - */ 0, + /* 126b - */ 0, + /* 126c - */ 0, + /* 126d - */ 0, + /* 126e - */ 0, + /* 126f - */ 0, + /* 1270 - */ 0, + /* 1271 - _V_66_0F_38_99 */ 0x4116, + /* 1272 - */ 0, + /* 1273 - */ 0, + /* 1274 - */ 0, + /* 1275 - */ 0, + /* 1276 - */ 0, + /* 1277 - */ 0, + /* 1278 - */ 0, + /* 1279 - */ 0, + /* 127a - */ 0, + /* 127b - */ 0, + /* 127c - */ 0, + /* 127d - _V_66_0F_38_9A */ 0x4117, + /* 127e - */ 0, + /* 127f - */ 0, + /* 1280 - */ 0, + /* 1281 - */ 0, + /* 1282 - */ 0, + /* 1283 - */ 0, + /* 1284 - */ 0, + /* 1285 - */ 0, + /* 1286 - */ 0, + /* 1287 - */ 0, + /* 1288 - */ 0, + /* 1289 - _V_66_0F_38_9B */ 0x4118, + /* 128a - */ 0, + /* 128b - */ 0, + /* 128c - */ 0, + /* 128d - */ 0, + /* 128e - */ 0, + /* 128f - */ 0, + /* 1290 - */ 0, + /* 1291 - */ 0, + /* 1292 - */ 0, + /* 1293 - */ 0, + /* 1294 - */ 0, + /* 1295 - _V_66_0F_38_9C */ 0x4119, + /* 1296 - */ 0, + /* 1297 - */ 0, + /* 1298 - */ 0, + /* 1299 - */ 0, + /* 129a - */ 0, + /* 129b - */ 0, + /* 129c - */ 0, + /* 129d - */ 0, + /* 129e - */ 0, + /* 129f - */ 0, + /* 12a0 - */ 0, + /* 12a1 - _V_66_0F_38_9D */ 0x411a, + /* 12a2 - */ 0, + /* 12a3 - */ 0, + /* 12a4 - */ 0, + /* 12a5 - */ 0, + /* 12a6 - */ 0, + /* 12a7 - */ 0, + /* 12a8 - */ 0, + /* 12a9 - */ 0, + /* 12aa - */ 0, + /* 12ab - */ 0, + /* 12ac - */ 0, + /* 12ad - _V_66_0F_38_9E */ 0x411b, + /* 12ae - */ 0, + /* 12af - */ 0, + /* 12b0 - */ 0, + /* 12b1 - */ 0, + /* 12b2 - */ 0, + /* 12b3 - */ 0, + /* 12b4 - */ 0, + /* 12b5 - */ 0, + /* 12b6 - */ 0, + /* 12b7 - */ 0, + /* 12b8 - */ 0, + /* 12b9 - _V_66_0F_38_9F */ 0x411c, + /* 12ba - */ 0, + /* 12bb - */ 0, + /* 12bc - */ 0, + /* 12bd - */ 0, + /* 12be - */ 0, + /* 12bf - */ 0, + /* 12c0 - */ 0, + /* 12c1 - */ 0, + /* 12c2 - */ 0, + /* 12c3 - */ 0, + /* 12c4 - */ 0, + /* 12c5 - _V_66_0F_38_A6 */ 0x411d, + /* 12c6 - */ 0, + /* 12c7 - */ 0, + /* 12c8 - */ 0, + /* 12c9 - */ 0, + /* 12ca - */ 0, + /* 12cb - */ 0, + /* 12cc - */ 0, + /* 12cd - */ 0, + /* 12ce - */ 0, + /* 12cf - */ 0, + /* 12d0 - */ 0, + /* 12d1 - _V_66_0F_38_A7 */ 0x411e, + /* 12d2 - */ 0, + /* 12d3 - */ 0, + /* 12d4 - */ 0, + /* 12d5 - */ 0, + /* 12d6 - */ 0, + /* 12d7 - */ 0, + /* 12d8 - */ 0, + /* 12d9 - */ 0, + /* 12da - */ 0, + /* 12db - */ 0, + /* 12dc - */ 0, + /* 12dd - _V_66_0F_38_A8 */ 0x411f, + /* 12de - */ 0, + /* 12df - */ 0, + /* 12e0 - */ 0, + /* 12e1 - */ 0, + /* 12e2 - */ 0, + /* 12e3 - */ 0, + /* 12e4 - */ 0, + /* 12e5 - */ 0, + /* 12e6 - */ 0, + /* 12e7 - */ 0, + /* 12e8 - */ 0, + /* 12e9 - _V_66_0F_38_A9 */ 0x4120, + /* 12ea - */ 0, + /* 12eb - */ 0, + /* 12ec - */ 0, + /* 12ed - */ 0, + /* 12ee - */ 0, + /* 12ef - */ 0, + /* 12f0 - */ 0, + /* 12f1 - */ 0, + /* 12f2 - */ 0, + /* 12f3 - */ 0, + /* 12f4 - */ 0, + /* 12f5 - _V_66_0F_38_AA */ 0x4121, + /* 12f6 - */ 0, + /* 12f7 - */ 0, + /* 12f8 - */ 0, + /* 12f9 - */ 0, + /* 12fa - */ 0, + /* 12fb - */ 0, + /* 12fc - */ 0, + /* 12fd - */ 0, + /* 12fe - */ 0, + /* 12ff - */ 0, + /* 1300 - */ 0, + /* 1301 - _V_66_0F_38_AB */ 0x4122, + /* 1302 - */ 0, + /* 1303 - */ 0, + /* 1304 - */ 0, + /* 1305 - */ 0, + /* 1306 - */ 0, + /* 1307 - */ 0, + /* 1308 - */ 0, + /* 1309 - */ 0, + /* 130a - */ 0, + /* 130b - */ 0, + /* 130c - */ 0, + /* 130d - _V_66_0F_38_AC */ 0x4123, + /* 130e - */ 0, + /* 130f - */ 0, + /* 1310 - */ 0, + /* 1311 - */ 0, + /* 1312 - */ 0, + /* 1313 - */ 0, + /* 1314 - */ 0, + /* 1315 - */ 0, + /* 1316 - */ 0, + /* 1317 - */ 0, + /* 1318 - */ 0, + /* 1319 - _V_66_0F_38_AD */ 0x4124, + /* 131a - */ 0, + /* 131b - */ 0, + /* 131c - */ 0, + /* 131d - */ 0, + /* 131e - */ 0, + /* 131f - */ 0, + /* 1320 - */ 0, + /* 1321 - */ 0, + /* 1322 - */ 0, + /* 1323 - */ 0, + /* 1324 - */ 0, + /* 1325 - _V_66_0F_38_AE */ 0x4125, + /* 1326 - */ 0, + /* 1327 - */ 0, + /* 1328 - */ 0, + /* 1329 - */ 0, + /* 132a - */ 0, + /* 132b - */ 0, + /* 132c - */ 0, + /* 132d - */ 0, + /* 132e - */ 0, + /* 132f - */ 0, + /* 1330 - */ 0, + /* 1331 - _V_66_0F_38_AF */ 0x4126, + /* 1332 - */ 0, + /* 1333 - */ 0, + /* 1334 - */ 0, + /* 1335 - */ 0, + /* 1336 - */ 0, + /* 1337 - */ 0, + /* 1338 - */ 0, + /* 1339 - */ 0, + /* 133a - */ 0, + /* 133b - */ 0, + /* 133c - */ 0, + /* 133d - _V_66_0F_38_B6 */ 0x4127, + /* 133e - */ 0, + /* 133f - */ 0, + /* 1340 - */ 0, + /* 1341 - */ 0, + /* 1342 - */ 0, + /* 1343 - */ 0, + /* 1344 - */ 0, + /* 1345 - */ 0, + /* 1346 - */ 0, + /* 1347 - */ 0, + /* 1348 - */ 0, + /* 1349 - _V_66_0F_38_B7 */ 0x4128, + /* 134a - */ 0, + /* 134b - */ 0, + /* 134c - */ 0, + /* 134d - */ 0, + /* 134e - */ 0, + /* 134f - */ 0, + /* 1350 - */ 0, + /* 1351 - */ 0, + /* 1352 - */ 0, + /* 1353 - */ 0, + /* 1354 - */ 0, + /* 1355 - _V_66_0F_38_B8 */ 0x4129, + /* 1356 - */ 0, + /* 1357 - */ 0, + /* 1358 - */ 0, + /* 1359 - */ 0, + /* 135a - */ 0, + /* 135b - */ 0, + /* 135c - */ 0, + /* 135d - */ 0, + /* 135e - */ 0, + /* 135f - */ 0, + /* 1360 - */ 0, + /* 1361 - _V_66_0F_38_B9 */ 0x412a, + /* 1362 - */ 0, + /* 1363 - */ 0, + /* 1364 - */ 0, + /* 1365 - */ 0, + /* 1366 - */ 0, + /* 1367 - */ 0, + /* 1368 - */ 0, + /* 1369 - */ 0, + /* 136a - */ 0, + /* 136b - */ 0, + /* 136c - */ 0, + /* 136d - _V_66_0F_38_BA */ 0x412b, + /* 136e - */ 0, + /* 136f - */ 0, + /* 1370 - */ 0, + /* 1371 - */ 0, + /* 1372 - */ 0, + /* 1373 - */ 0, + /* 1374 - */ 0, + /* 1375 - */ 0, + /* 1376 - */ 0, + /* 1377 - */ 0, + /* 1378 - */ 0, + /* 1379 - _V_66_0F_38_BB */ 0x412c, + /* 137a - */ 0, + /* 137b - */ 0, + /* 137c - */ 0, + /* 137d - */ 0, + /* 137e - */ 0, + /* 137f - */ 0, + /* 1380 - */ 0, + /* 1381 - */ 0, + /* 1382 - */ 0, + /* 1383 - */ 0, + /* 1384 - */ 0, + /* 1385 - _V_66_0F_38_BC */ 0x412d, + /* 1386 - */ 0, + /* 1387 - */ 0, + /* 1388 - */ 0, + /* 1389 - */ 0, + /* 138a - */ 0, + /* 138b - */ 0, + /* 138c - */ 0, + /* 138d - */ 0, + /* 138e - */ 0, + /* 138f - */ 0, + /* 1390 - */ 0, + /* 1391 - _V_66_0F_38_BD */ 0x412e, + /* 1392 - */ 0, + /* 1393 - */ 0, + /* 1394 - */ 0, + /* 1395 - */ 0, + /* 1396 - */ 0, + /* 1397 - */ 0, + /* 1398 - */ 0, + /* 1399 - */ 0, + /* 139a - */ 0, + /* 139b - */ 0, + /* 139c - */ 0, + /* 139d - _V_66_0F_38_BE */ 0x412f, + /* 139e - */ 0, + /* 139f - */ 0, + /* 13a0 - */ 0, + /* 13a1 - */ 0, + /* 13a2 - */ 0, + /* 13a3 - */ 0, + /* 13a4 - */ 0, + /* 13a5 - */ 0, + /* 13a6 - */ 0, + /* 13a7 - */ 0, + /* 13a8 - */ 0, + /* 13a9 - _V_66_0F_38_BF */ 0x4130, + /* 13aa - */ 0, + /* 13ab - */ 0, + /* 13ac - */ 0, + /* 13ad - */ 0, + /* 13ae - */ 0, + /* 13af - */ 0, + /* 13b0 - */ 0, + /* 13b1 - _66_0F_38_DB */ 0x24ba, + /* 13b2 - */ 0, + /* 13b3 - */ 0, + /* 13b4 - */ 0, + /* 13b5 - _V_66_0F_38_DB */ 0x4131, + /* 13b6 - */ 0, + /* 13b7 - */ 0, + /* 13b8 - */ 0, + /* 13b9 - */ 0, + /* 13ba - */ 0, + /* 13bb - */ 0, + /* 13bc - */ 0, + /* 13bd - _66_0F_38_DC */ 0x24bb, + /* 13be - */ 0, + /* 13bf - */ 0, + /* 13c0 - */ 0, + /* 13c1 - _V_66_0F_38_DC */ 0x4132, + /* 13c2 - */ 0, + /* 13c3 - */ 0, + /* 13c4 - */ 0, + /* 13c5 - */ 0, + /* 13c6 - */ 0, + /* 13c7 - */ 0, + /* 13c8 - */ 0, + /* 13c9 - _66_0F_38_DD */ 0x24bc, + /* 13ca - */ 0, + /* 13cb - */ 0, + /* 13cc - */ 0, + /* 13cd - _V_66_0F_38_DD */ 0x4133, + /* 13ce - */ 0, + /* 13cf - */ 0, + /* 13d0 - */ 0, + /* 13d1 - */ 0, + /* 13d2 - */ 0, + /* 13d3 - */ 0, + /* 13d4 - */ 0, + /* 13d5 - _66_0F_38_DE */ 0x24bd, + /* 13d6 - */ 0, + /* 13d7 - */ 0, + /* 13d8 - */ 0, + /* 13d9 - _V_66_0F_38_DE */ 0x4134, + /* 13da - */ 0, + /* 13db - */ 0, + /* 13dc - */ 0, + /* 13dd - */ 0, + /* 13de - */ 0, + /* 13df - */ 0, + /* 13e0 - */ 0, + /* 13e1 - _66_0F_38_DF */ 0x24be, + /* 13e2 - */ 0, + /* 13e3 - */ 0, + /* 13e4 - */ 0, + /* 13e5 - _V_66_0F_38_DF */ 0x4135, + /* 13e6 - */ 0, + /* 13e7 - */ 0, + /* 13e8 - */ 0, + /* 13e9 - */ 0, + /* 13ea - */ 0, + /* 13eb - */ 0, + /* 13ec - _0F_38_F0 */ 0x24bf, + /* 13ed - */ 0, + /* 13ee - */ 0, + /* 13ef - _F2_0F_38_F0 */ 0x24c0, + /* 13f0 - */ 0, + /* 13f1 - */ 0, + /* 13f2 - */ 0, + /* 13f3 - */ 0, + /* 13f4 - */ 0, + /* 13f5 - */ 0, + /* 13f6 - */ 0, + /* 13f7 - */ 0, + /* 13f8 - _0F_38_F1 */ 0x24c1, + /* 13f9 - */ 0, + /* 13fa - */ 0, + /* 13fb - _F2_0F_38_F1 */ 0x24c2, + /* 13fc - */ 0, + /* 13fd - */ 0, + /* 13fe - */ 0, + /* 13ff - */ 0, + /* 1400 - */ 0, + /* 1401 - */ 0, + /* 1402 - */ 0, + /* 1403 - */ 0, + /* 1404 - */ 0, + /* 1405 - */ 0, + /* 1406 - */ 0, + /* 1407 - */ 0, + /* 1408 - */ 0, + /* 1409 - _V_66_0F_3A_04 */ 0x4136, + /* 140a - */ 0, + /* 140b - */ 0, + /* 140c - */ 0, + /* 140d - */ 0, + /* 140e - */ 0, + /* 140f - */ 0, + /* 1410 - */ 0, + /* 1411 - */ 0, + /* 1412 - */ 0, + /* 1413 - */ 0, + /* 1414 - */ 0, + /* 1415 - _V_66_0F_3A_05 */ 0x4137, + /* 1416 - */ 0, + /* 1417 - */ 0, + /* 1418 - */ 0, + /* 1419 - */ 0, + /* 141a - */ 0, + /* 141b - */ 0, + /* 141c - */ 0, + /* 141d - */ 0, + /* 141e - */ 0, + /* 141f - */ 0, + /* 1420 - */ 0, + /* 1421 - _V_66_0F_3A_06 */ 0x4138, + /* 1422 - */ 0, + /* 1423 - */ 0, + /* 1424 - */ 0, + /* 1425 - */ 0, + /* 1426 - */ 0, + /* 1427 - */ 0, + /* 1428 - */ 0, + /* 1429 - _66_0F_3A_08 */ 0x4139, + /* 142a - */ 0, + /* 142b - */ 0, + /* 142c - */ 0, + /* 142d - _V_66_0F_3A_08 */ 0x413a, + /* 142e - */ 0, + /* 142f - */ 0, + /* 1430 - */ 0, + /* 1431 - */ 0, + /* 1432 - */ 0, + /* 1433 - */ 0, + /* 1434 - */ 0, + /* 1435 - _66_0F_3A_09 */ 0x413b, + /* 1436 - */ 0, + /* 1437 - */ 0, + /* 1438 - */ 0, + /* 1439 - _V_66_0F_3A_09 */ 0x413c, + /* 143a - */ 0, + /* 143b - */ 0, + /* 143c - */ 0, + /* 143d - */ 0, + /* 143e - */ 0, + /* 143f - */ 0, + /* 1440 - */ 0, + /* 1441 - _66_0F_3A_0A */ 0x413d, + /* 1442 - */ 0, + /* 1443 - */ 0, + /* 1444 - */ 0, + /* 1445 - _V_66_0F_3A_0A */ 0x413e, + /* 1446 - */ 0, + /* 1447 - */ 0, + /* 1448 - */ 0, + /* 1449 - */ 0, + /* 144a - */ 0, + /* 144b - */ 0, + /* 144c - */ 0, + /* 144d - _66_0F_3A_0B */ 0x413f, + /* 144e - */ 0, + /* 144f - */ 0, + /* 1450 - */ 0, + /* 1451 - _V_66_0F_3A_0B */ 0x4140, + /* 1452 - */ 0, + /* 1453 - */ 0, + /* 1454 - */ 0, + /* 1455 - */ 0, + /* 1456 - */ 0, + /* 1457 - */ 0, + /* 1458 - */ 0, + /* 1459 - _66_0F_3A_0C */ 0x4141, + /* 145a - */ 0, + /* 145b - */ 0, + /* 145c - */ 0, + /* 145d - _V_66_0F_3A_0C */ 0x4142, + /* 145e - */ 0, + /* 145f - */ 0, + /* 1460 - */ 0, + /* 1461 - */ 0, + /* 1462 - */ 0, + /* 1463 - */ 0, + /* 1464 - */ 0, + /* 1465 - _66_0F_3A_0D */ 0x4143, + /* 1466 - */ 0, + /* 1467 - */ 0, + /* 1468 - */ 0, + /* 1469 - _V_66_0F_3A_0D */ 0x4144, + /* 146a - */ 0, + /* 146b - */ 0, + /* 146c - */ 0, + /* 146d - */ 0, + /* 146e - */ 0, + /* 146f - */ 0, + /* 1470 - */ 0, + /* 1471 - _66_0F_3A_0E */ 0x4145, + /* 1472 - */ 0, + /* 1473 - */ 0, + /* 1474 - */ 0, + /* 1475 - _V_66_0F_3A_0E */ 0x4146, + /* 1476 - */ 0, + /* 1477 - */ 0, + /* 1478 - */ 0, + /* 1479 - */ 0, + /* 147a - */ 0, + /* 147b - */ 0, + /* 147c - _0F_3A_0F */ 0x4147, + /* 147d - _66_0F_3A_0F */ 0x4148, + /* 147e - */ 0, + /* 147f - */ 0, + /* 1480 - */ 0, + /* 1481 - _V_66_0F_3A_0F */ 0x4149, + /* 1482 - */ 0, + /* 1483 - */ 0, + /* 1484 - */ 0, + /* 1485 - */ 0, + /* 1486 - */ 0, + /* 1487 - */ 0, + /* 1488 - */ 0, + /* 1489 - _66_0F_3A_14 */ 0x414a, + /* 148a - */ 0, + /* 148b - */ 0, + /* 148c - */ 0, + /* 148d - _V_66_0F_3A_14 */ 0x414b, + /* 148e - */ 0, + /* 148f - */ 0, + /* 1490 - */ 0, + /* 1491 - */ 0, + /* 1492 - */ 0, + /* 1493 - */ 0, + /* 1494 - */ 0, + /* 1495 - _66_0F_3A_15 */ 0x414c, + /* 1496 - */ 0, + /* 1497 - */ 0, + /* 1498 - */ 0, + /* 1499 - _V_66_0F_3A_15 */ 0x414d, + /* 149a - */ 0, + /* 149b - */ 0, + /* 149c - */ 0, + /* 149d - */ 0, + /* 149e - */ 0, + /* 149f - */ 0, + /* 14a0 - */ 0, + /* 14a1 - _66_0F_3A_16 */ 0x414e, + /* 14a2 - */ 0, + /* 14a3 - */ 0, + /* 14a4 - */ 0, + /* 14a5 - _V_66_0F_3A_16 */ 0x414f, + /* 14a6 - */ 0, + /* 14a7 - */ 0, + /* 14a8 - */ 0, + /* 14a9 - */ 0, + /* 14aa - */ 0, + /* 14ab - */ 0, + /* 14ac - */ 0, + /* 14ad - _66_0F_3A_17 */ 0x4150, + /* 14ae - */ 0, + /* 14af - */ 0, + /* 14b0 - */ 0, + /* 14b1 - _V_66_0F_3A_17 */ 0x4151, + /* 14b2 - */ 0, + /* 14b3 - */ 0, + /* 14b4 - */ 0, + /* 14b5 - */ 0, + /* 14b6 - */ 0, + /* 14b7 - */ 0, + /* 14b8 - */ 0, + /* 14b9 - */ 0, + /* 14ba - */ 0, + /* 14bb - */ 0, + /* 14bc - */ 0, + /* 14bd - _V_66_0F_3A_18 */ 0x4152, + /* 14be - */ 0, + /* 14bf - */ 0, + /* 14c0 - */ 0, + /* 14c1 - */ 0, + /* 14c2 - */ 0, + /* 14c3 - */ 0, + /* 14c4 - */ 0, + /* 14c5 - */ 0, + /* 14c6 - */ 0, + /* 14c7 - */ 0, + /* 14c8 - */ 0, + /* 14c9 - _V_66_0F_3A_19 */ 0x4153, + /* 14ca - */ 0, + /* 14cb - */ 0, + /* 14cc - */ 0, + /* 14cd - */ 0, + /* 14ce - */ 0, + /* 14cf - */ 0, + /* 14d0 - */ 0, + /* 14d1 - _66_0F_3A_20 */ 0x4154, + /* 14d2 - */ 0, + /* 14d3 - */ 0, + /* 14d4 - */ 0, + /* 14d5 - _V_66_0F_3A_20 */ 0x4155, + /* 14d6 - */ 0, + /* 14d7 - */ 0, + /* 14d8 - */ 0, + /* 14d9 - */ 0, + /* 14da - */ 0, + /* 14db - */ 0, + /* 14dc - */ 0, + /* 14dd - _66_0F_3A_21 */ 0x4156, + /* 14de - */ 0, + /* 14df - */ 0, + /* 14e0 - */ 0, + /* 14e1 - _V_66_0F_3A_21 */ 0x4157, + /* 14e2 - */ 0, + /* 14e3 - */ 0, + /* 14e4 - */ 0, + /* 14e5 - */ 0, + /* 14e6 - */ 0, + /* 14e7 - */ 0, + /* 14e8 - */ 0, + /* 14e9 - _66_0F_3A_22 */ 0x4158, + /* 14ea - */ 0, + /* 14eb - */ 0, + /* 14ec - */ 0, + /* 14ed - _V_66_0F_3A_22 */ 0x4159, + /* 14ee - */ 0, + /* 14ef - */ 0, + /* 14f0 - */ 0, + /* 14f1 - */ 0, + /* 14f2 - */ 0, + /* 14f3 - */ 0, + /* 14f4 - */ 0, + /* 14f5 - _66_0F_3A_40 */ 0x415a, + /* 14f6 - */ 0, + /* 14f7 - */ 0, + /* 14f8 - */ 0, + /* 14f9 - _V_66_0F_3A_40 */ 0x415b, + /* 14fa - */ 0, + /* 14fb - */ 0, + /* 14fc - */ 0, + /* 14fd - */ 0, + /* 14fe - */ 0, + /* 14ff - */ 0, + /* 1500 - */ 0, + /* 1501 - _66_0F_3A_41 */ 0x415c, + /* 1502 - */ 0, + /* 1503 - */ 0, + /* 1504 - */ 0, + /* 1505 - _V_66_0F_3A_41 */ 0x415d, + /* 1506 - */ 0, + /* 1507 - */ 0, + /* 1508 - */ 0, + /* 1509 - */ 0, + /* 150a - */ 0, + /* 150b - */ 0, + /* 150c - */ 0, + /* 150d - _66_0F_3A_42 */ 0x415e, + /* 150e - */ 0, + /* 150f - */ 0, + /* 1510 - */ 0, + /* 1511 - _V_66_0F_3A_42 */ 0x415f, + /* 1512 - */ 0, + /* 1513 - */ 0, + /* 1514 - */ 0, + /* 1515 - */ 0, + /* 1516 - */ 0, + /* 1517 - */ 0, + /* 1518 - */ 0, + /* 1519 - _66_0F_3A_44 */ 0x4160, + /* 151a - */ 0, + /* 151b - */ 0, + /* 151c - */ 0, + /* 151d - _V_66_0F_3A_44 */ 0x4161, + /* 151e - */ 0, + /* 151f - */ 0, + /* 1520 - */ 0, + /* 1521 - */ 0, + /* 1522 - */ 0, + /* 1523 - */ 0, + /* 1524 - */ 0, + /* 1525 - */ 0, + /* 1526 - */ 0, + /* 1527 - */ 0, + /* 1528 - */ 0, + /* 1529 - _V_66_0F_3A_4A */ 0x4162, + /* 152a - */ 0, + /* 152b - */ 0, + /* 152c - */ 0, + /* 152d - */ 0, + /* 152e - */ 0, + /* 152f - */ 0, + /* 1530 - */ 0, + /* 1531 - */ 0, + /* 1532 - */ 0, + /* 1533 - */ 0, + /* 1534 - */ 0, + /* 1535 - _V_66_0F_3A_4B */ 0x4163, + /* 1536 - */ 0, + /* 1537 - */ 0, + /* 1538 - */ 0, + /* 1539 - */ 0, + /* 153a - */ 0, + /* 153b - */ 0, + /* 153c - */ 0, + /* 153d - */ 0, + /* 153e - */ 0, + /* 153f - */ 0, + /* 1540 - */ 0, + /* 1541 - _V_66_0F_3A_4C */ 0x4164, + /* 1542 - */ 0, + /* 1543 - */ 0, + /* 1544 - */ 0, + /* 1545 - */ 0, + /* 1546 - */ 0, + /* 1547 - */ 0, + /* 1548 - */ 0, + /* 1549 - _66_0F_3A_60 */ 0x4165, + /* 154a - */ 0, + /* 154b - */ 0, + /* 154c - */ 0, + /* 154d - _V_66_0F_3A_60 */ 0x4166, + /* 154e - */ 0, + /* 154f - */ 0, + /* 1550 - */ 0, + /* 1551 - */ 0, + /* 1552 - */ 0, + /* 1553 - */ 0, + /* 1554 - */ 0, + /* 1555 - _66_0F_3A_61 */ 0x4167, + /* 1556 - */ 0, + /* 1557 - */ 0, + /* 1558 - */ 0, + /* 1559 - _V_66_0F_3A_61 */ 0x4168, + /* 155a - */ 0, + /* 155b - */ 0, + /* 155c - */ 0, + /* 155d - */ 0, + /* 155e - */ 0, + /* 155f - */ 0, + /* 1560 - */ 0, + /* 1561 - _66_0F_3A_62 */ 0x4169, + /* 1562 - */ 0, + /* 1563 - */ 0, + /* 1564 - */ 0, + /* 1565 - _V_66_0F_3A_62 */ 0x416a, + /* 1566 - */ 0, + /* 1567 - */ 0, + /* 1568 - */ 0, + /* 1569 - */ 0, + /* 156a - */ 0, + /* 156b - */ 0, + /* 156c - */ 0, + /* 156d - _66_0F_3A_63 */ 0x416b, + /* 156e - */ 0, + /* 156f - */ 0, + /* 1570 - */ 0, + /* 1571 - _V_66_0F_3A_63 */ 0x416c, + /* 1572 - */ 0, + /* 1573 - */ 0, + /* 1574 - */ 0, + /* 1575 - */ 0, + /* 1576 - */ 0, + /* 1577 - */ 0, + /* 1578 - */ 0, + /* 1579 - _66_0F_3A_DF */ 0x416d, + /* 157a - */ 0, + /* 157b - */ 0, + /* 157c - */ 0, + /* 157d - _V_66_0F_3A_DF */ 0x416e, + /* 157e - */ 0, + /* 157f - */ 0, + /* 1580 - */ 0, + /* 1581 - */ 0, + /* 1582 - */ 0, + /* 1583 - */ 0, + /* 1584 - _0F_71_02 */ 0x24c3, + /* 1585 - _66_0F_71_02 */ 0x24c4, + /* 1586 - */ 0, + /* 1587 - */ 0, + /* 1588 - */ 0, + /* 1589 - _V_66_0F_71_02 */ 0x416f, + /* 158a - */ 0, + /* 158b - */ 0, + /* 158c - */ 0, + /* 158d - */ 0, + /* 158e - */ 0, + /* 158f - */ 0, + /* 1590 - _0F_71_04 */ 0x24c5, + /* 1591 - _66_0F_71_04 */ 0x24c6, + /* 1592 - */ 0, + /* 1593 - */ 0, + /* 1594 - */ 0, + /* 1595 - _V_66_0F_71_04 */ 0x4170, + /* 1596 - */ 0, + /* 1597 - */ 0, + /* 1598 - */ 0, + /* 1599 - */ 0, + /* 159a - */ 0, + /* 159b - */ 0, + /* 159c - _0F_71_06 */ 0x24c7, + /* 159d - _66_0F_71_06 */ 0x24c8, + /* 159e - */ 0, + /* 159f - */ 0, + /* 15a0 - */ 0, + /* 15a1 - _V_66_0F_71_06 */ 0x4171, + /* 15a2 - */ 0, + /* 15a3 - */ 0, + /* 15a4 - */ 0, + /* 15a5 - */ 0, + /* 15a6 - */ 0, + /* 15a7 - */ 0, + /* 15a8 - _0F_72_02 */ 0x24c9, + /* 15a9 - _66_0F_72_02 */ 0x24ca, + /* 15aa - */ 0, + /* 15ab - */ 0, + /* 15ac - */ 0, + /* 15ad - _V_66_0F_72_02 */ 0x4172, + /* 15ae - */ 0, + /* 15af - */ 0, + /* 15b0 - */ 0, + /* 15b1 - */ 0, + /* 15b2 - */ 0, + /* 15b3 - */ 0, + /* 15b4 - _0F_72_04 */ 0x24cb, + /* 15b5 - _66_0F_72_04 */ 0x24cc, + /* 15b6 - */ 0, + /* 15b7 - */ 0, + /* 15b8 - */ 0, + /* 15b9 - _V_66_0F_72_04 */ 0x4173, + /* 15ba - */ 0, + /* 15bb - */ 0, + /* 15bc - */ 0, + /* 15bd - */ 0, + /* 15be - */ 0, + /* 15bf - */ 0, + /* 15c0 - _0F_72_06 */ 0x24cd, + /* 15c1 - _66_0F_72_06 */ 0x24ce, + /* 15c2 - */ 0, + /* 15c3 - */ 0, + /* 15c4 - */ 0, + /* 15c5 - _V_66_0F_72_06 */ 0x4174, + /* 15c6 - */ 0, + /* 15c7 - */ 0, + /* 15c8 - */ 0, + /* 15c9 - */ 0, + /* 15ca - */ 0, + /* 15cb - */ 0, + /* 15cc - _0F_73_02 */ 0x24cf, + /* 15cd - _66_0F_73_02 */ 0x24d0, + /* 15ce - */ 0, + /* 15cf - */ 0, + /* 15d0 - */ 0, + /* 15d1 - _V_66_0F_73_02 */ 0x4175, + /* 15d2 - */ 0, + /* 15d3 - */ 0, + /* 15d4 - */ 0, + /* 15d5 - */ 0, + /* 15d6 - */ 0, + /* 15d7 - */ 0, + /* 15d8 - */ 0, + /* 15d9 - _66_0F_73_03 */ 0x24d1, + /* 15da - */ 0, + /* 15db - */ 0, + /* 15dc - */ 0, + /* 15dd - _V_66_0F_73_03 */ 0x4176, + /* 15de - */ 0, + /* 15df - */ 0, + /* 15e0 - */ 0, + /* 15e1 - */ 0, + /* 15e2 - */ 0, + /* 15e3 - */ 0, + /* 15e4 - _0F_73_06 */ 0x24d2, + /* 15e5 - _66_0F_73_06 */ 0x24d3, + /* 15e6 - */ 0, + /* 15e7 - */ 0, + /* 15e8 - */ 0, + /* 15e9 - _V_66_0F_73_06 */ 0x4177, + /* 15ea - */ 0, + /* 15eb - */ 0, + /* 15ec - */ 0, + /* 15ed - */ 0, + /* 15ee - */ 0, + /* 15ef - */ 0, + /* 15f0 - */ 0, + /* 15f1 - _66_0F_73_07 */ 0x24d4, + /* 15f2 - */ 0, + /* 15f3 - */ 0, + /* 15f4 - */ 0, + /* 15f5 - _V_66_0F_73_07 */ 0x4178, + /* 15f6 - */ 0, + /* 15f7 - */ 0, + /* 15f8 - */ 0, + /* 15f9 - */ 0, + /* 15fa - */ 0, + /* 15fb - */ 0, + /* 15fc - _0F_AE_00 */ 0x4179, + /* 15fd - */ 0, + /* 15fe - _F3_0F_AE_00 */ 0x24d5, + /* 15ff - */ 0, + /* 1600 - */ 0, + /* 1601 - */ 0, + /* 1602 - */ 0, + /* 1603 - */ 0, + /* 1604 - */ 0, + /* 1605 - */ 0, + /* 1606 - */ 0, + /* 1607 - */ 0, + /* 1608 - _0F_AE_01 */ 0x417a, + /* 1609 - */ 0, + /* 160a - _F3_0F_AE_01 */ 0x24d6, + /* 160b - */ 0, + /* 160c - */ 0, + /* 160d - */ 0, + /* 160e - */ 0, + /* 160f - */ 0, + /* 1610 - */ 0, + /* 1611 - */ 0, + /* 1612 - */ 0, + /* 1613 - */ 0, + /* 1614 - _0F_AE_02 */ 0x24d7, + /* 1615 - */ 0, + /* 1616 - _F3_0F_AE_02 */ 0x24d8, + /* 1617 - */ 0, + /* 1618 - _V_0F_AE_02 */ 0x417b, + /* 1619 - */ 0, + /* 161a - */ 0, + /* 161b - */ 0, + /* 161c - */ 0, + /* 161d - */ 0, + /* 161e - */ 0, + /* 161f - */ 0, + /* 1620 - _0F_AE_03 */ 0x24d9, + /* 1621 - */ 0, + /* 1622 - _F3_0F_AE_03 */ 0x24da, + /* 1623 - */ 0, + /* 1624 - _V_0F_AE_03 */ 0x417c, + /* 1625 - */ 0, + /* 1626 - */ 0, + /* 1627 - */ 0, + /* 1628 - */ 0, + /* 1629 - */ 0, + /* 162a - */ 0, + /* 162b - */ 0, + /* 162c - _0F_C7_06 */ 0x24db, + /* 162d - _66_0F_C7_06 */ 0x24dc, + /* 162e - _F3_0F_C7_06 */ 0x24dd, + /* 162f - */ 0, + /* 1630 - */ 0, + /* 1631 - */ 0, + /* 1632 - */ 0, + /* 1633 - */ 0, + /* 1634 - */ 0, + /* 1635 - */ 0, + /* 1636 - */ 0, + /* 1637 - */ 0 +}; + +_InstSharedInfo InstSharedInfoTable[470] = { + { 0, 9, 15, 8, 245, 0, 0 }, + { 0, 11, 17, 8, 245, 0, 0 }, + { 0, 15, 9, 8, 245, 0, 0 }, + { 0, 17, 11, 8, 245, 0, 0 }, + { 1, 1, 33, 8, 245, 0, 0 }, + { 1, 3, 35, 8, 245, 0, 0 }, + { 2, 0, 32, 8, 0, 0, 0 }, + { 3, 0, 32, 8, 0, 0, 0 }, + { 0, 9, 15, 8, 196, 16, 0 }, + { 0, 11, 17, 8, 196, 16, 0 }, + { 0, 15, 9, 8, 196, 16, 0 }, + { 0, 17, 11, 8, 196, 16, 0 }, + { 1, 1, 33, 8, 196, 16, 0 }, + { 1, 3, 35, 8, 196, 16, 0 }, + { 4, 0, 32, 8, 0, 0, 0 }, + { 0, 9, 15, 8, 245, 1, 0 }, + { 0, 11, 17, 8, 245, 1, 0 }, + { 0, 15, 9, 8, 245, 1, 0 }, + { 0, 17, 11, 8, 245, 1, 0 }, + { 1, 1, 33, 8, 245, 1, 0 }, + { 1, 3, 35, 8, 245, 1, 0 }, + { 5, 0, 32, 8, 0, 0, 0 }, + { 6, 0, 32, 8, 0, 0, 0 }, + { 7, 0, 32, 8, 0, 0, 0 }, + { 8, 0, 32, 8, 0, 0, 0 }, + { 0, 9, 15, 8, 229, 0, 16 }, + { 0, 11, 17, 8, 229, 0, 16 }, + { 0, 15, 9, 8, 229, 0, 16 }, + { 0, 17, 11, 8, 229, 0, 16 }, + { 1, 1, 33, 8, 229, 0, 16 }, + { 1, 3, 35, 8, 229, 0, 16 }, + { 9, 0, 0, 8, 213, 17, 32 }, + { 0, 9, 15, 8, 196, 0, 16 }, + { 0, 11, 17, 8, 196, 0, 16 }, + { 0, 15, 9, 8, 196, 0, 16 }, + { 0, 17, 11, 8, 196, 0, 16 }, + { 1, 1, 33, 8, 196, 0, 16 }, + { 1, 3, 35, 8, 196, 0, 16 }, + { 9, 0, 0, 8, 17, 16, 228 }, + { 10, 9, 15, 8, 245, 0, 0 }, + { 10, 11, 17, 8, 245, 0, 0 }, + { 10, 15, 9, 8, 245, 0, 0 }, + { 10, 17, 11, 8, 245, 0, 0 }, + { 11, 1, 33, 8, 245, 0, 0 }, + { 11, 3, 35, 8, 245, 0, 0 }, + { 12, 0, 54, 8, 244, 0, 0 }, + { 13, 0, 54, 8, 0, 0, 0 }, + { 14, 0, 54, 8, 0, 0, 0 }, + { 15, 0, 0, 8, 0, 0, 0 }, + { 16, 42, 11, 8, 0, 0, 0 }, + { 10, 10, 16, 8, 64, 0, 0 }, + { 13, 0, 3, 8, 0, 0, 0 }, + { 17, 17, 11, 8, 33, 0, 212 }, + { 18, 0, 5, 8, 0, 0, 0 }, + { 19, 59, 56, 8, 0, 8, 0 }, + { 20, 59, 56, 8, 0, 8, 0 }, + { 19, 55, 59, 8, 0, 8, 0 }, + { 20, 55, 59, 8, 0, 8, 0 }, + { 13, 0, 40, 13, 0, 32, 0 }, + { 13, 0, 40, 13, 0, 1, 0 }, + { 13, 0, 40, 13, 0, 64, 0 }, + { 13, 0, 40, 13, 0, 65, 0 }, + { 13, 0, 40, 13, 0, 128, 0 }, + { 13, 0, 40, 13, 0, 4, 0 }, + { 13, 0, 40, 13, 0, 160, 0 }, + { 13, 0, 40, 13, 0, 224, 0 }, + { 10, 9, 15, 8, 196, 0, 16 }, + { 10, 11, 17, 8, 196, 0, 16 }, + { 0, 9, 15, 8, 0, 0, 0 }, + { 0, 11, 17, 8, 0, 0, 0 }, + { 21, 9, 15, 8, 0, 0, 0 }, + { 21, 11, 17, 8, 0, 0, 0 }, + { 21, 15, 9, 8, 0, 0, 0 }, + { 21, 17, 11, 8, 0, 0, 0 }, + { 21, 31, 28, 8, 0, 0, 0 }, + { 21, 42, 11, 8, 0, 0, 0 }, + { 21, 28, 31, 8, 0, 0, 0 }, + { 1, 35, 54, 8, 0, 0, 0 }, + { 22, 0, 0, 8, 0, 0, 0 }, + { 9, 0, 38, 9, 0, 0, 0 }, + { 23, 0, 0, 8, 0, 0, 0 }, + { 23, 0, 0, 8, 255, 0, 0 }, + { 11, 0, 0, 8, 213, 0, 0 }, + { 11, 0, 0, 8, 0, 0, 0 }, + { 1, 49, 33, 8, 0, 0, 0 }, + { 1, 50, 35, 8, 0, 0, 0 }, + { 1, 33, 49, 8, 0, 0, 0 }, + { 1, 35, 50, 8, 0, 0, 0 }, + { 24, 55, 56, 8, 0, 8, 0 }, + { 25, 55, 56, 8, 0, 8, 0 }, + { 19, 56, 55, 8, 245, 8, 0 }, + { 26, 56, 55, 8, 245, 8, 0 }, + { 11, 1, 33, 8, 196, 0, 16 }, + { 11, 3, 35, 8, 196, 0, 16 }, + { 19, 33, 56, 8, 0, 8, 0 }, + { 26, 35, 56, 8, 0, 8, 0 }, + { 19, 55, 33, 8, 0, 8, 0 }, + { 26, 55, 35, 8, 0, 8, 0 }, + { 19, 33, 56, 8, 245, 8, 0 }, + { 26, 35, 56, 8, 245, 8, 0 }, + { 1, 1, 53, 8, 0, 0, 0 }, + { 27, 3, 54, 8, 0, 0, 0 }, + { 13, 0, 2, 10, 0, 0, 0 }, + { 13, 0, 0, 10, 0, 0, 0 }, + { 16, 37, 11, 8, 0, 0, 0 }, + { 13, 8, 6, 8, 0, 0, 0 }, + { 13, 0, 0, 8, 0, 0, 0 }, + { 28, 0, 2, 10, 0, 0, 0 }, + { 28, 0, 0, 10, 0, 0, 0 }, + { 11, 0, 0, 14, 0, 0, 0 }, + { 11, 0, 1, 14, 0, 0, 0 }, + { 9, 0, 0, 14, 0, 0, 0 }, + { 28, 0, 0, 10, 255, 0, 0 }, + { 9, 0, 1, 8, 196, 0, 49 }, + { 9, 0, 0, 8, 0, 0, 0 }, + { 29, 0, 57, 8, 0, 0, 0 }, + { 30, 0, 40, 13, 0, 64, 0 }, + { 30, 0, 40, 13, 0, 0, 0 }, + { 31, 0, 40, 13, 0, 0, 0 }, + { 1, 1, 33, 8, 0, 0, 0 }, + { 1, 1, 36, 8, 0, 0, 0 }, + { 11, 33, 1, 8, 0, 0, 0 }, + { 11, 36, 1, 8, 0, 0, 0 }, + { 13, 0, 41, 9, 0, 0, 0 }, + { 13, 0, 41, 12, 0, 0, 0 }, + { 9, 0, 38, 12, 0, 0, 0 }, + { 13, 0, 40, 12, 0, 0, 0 }, + { 1, 59, 33, 8, 0, 0, 0 }, + { 1, 59, 36, 8, 0, 0, 0 }, + { 11, 33, 59, 8, 0, 0, 0 }, + { 11, 36, 59, 8, 0, 0, 0 }, + { 11, 0, 0, 8, 1, 0, 0 }, + { 11, 0, 0, 8, 2, 0, 0 }, + { 11, 0, 0, 8, 8, 0, 0 }, + { 10, 16, 11, 8, 64, 0, 0 }, + { 32, 0, 0, 27, 0, 0, 0 }, + { 32, 0, 0, 8, 0, 0, 0 }, + { 32, 0, 0, 14, 0, 0, 0 }, + { 11, 0, 0, 96, 0, 0, 0 }, + { 10, 0, 17, 8, 0, 0, 0 }, + { 33, 29, 14, 8, 0, 0, 0 }, + { 33, 30, 14, 8, 0, 0, 0 }, + { 33, 14, 29, 8, 0, 0, 0 }, + { 33, 14, 30, 8, 0, 0, 0 }, + { 34, 0, 0, 8, 0, 0, 0 }, + { 35, 17, 11, 31, 0, 32, 0 }, + { 35, 17, 11, 31, 0, 1, 0 }, + { 35, 17, 11, 31, 0, 64, 0 }, + { 35, 17, 11, 31, 0, 65, 0 }, + { 35, 17, 11, 31, 0, 128, 0 }, + { 35, 17, 11, 31, 0, 4, 0 }, + { 35, 17, 11, 31, 0, 160, 0 }, + { 35, 17, 11, 31, 0, 224, 0 }, + { 32, 0, 41, 13, 0, 32, 0 }, + { 32, 0, 41, 13, 0, 1, 0 }, + { 32, 0, 41, 13, 0, 64, 0 }, + { 32, 0, 41, 13, 0, 65, 0 }, + { 32, 0, 41, 13, 0, 128, 0 }, + { 32, 0, 41, 13, 0, 4, 0 }, + { 32, 0, 41, 13, 0, 160, 0 }, + { 32, 0, 41, 13, 0, 224, 0 }, + { 35, 0, 15, 8, 0, 32, 0 }, + { 35, 0, 15, 8, 0, 1, 0 }, + { 35, 0, 15, 8, 0, 64, 0 }, + { 35, 0, 15, 8, 0, 65, 0 }, + { 35, 0, 15, 8, 0, 128, 0 }, + { 35, 0, 15, 8, 0, 4, 0 }, + { 35, 0, 15, 8, 0, 160, 0 }, + { 35, 0, 15, 8, 0, 224, 0 }, + { 36, 0, 32, 8, 0, 0, 0 }, + { 37, 0, 32, 8, 0, 0, 0 }, + { 35, 11, 17, 8, 1, 0, 244 }, + { 38, 11, 17, 8, 197, 0, 48 }, + { 39, 0, 32, 8, 0, 0, 0 }, + { 40, 0, 32, 8, 0, 0, 0 }, + { 32, 0, 0, 8, 255, 0, 0 }, + { 41, 11, 17, 8, 1, 0, 244 }, + { 35, 17, 11, 8, 33, 0, 212 }, + { 41, 9, 15, 8, 245, 0, 0 }, + { 41, 11, 17, 8, 245, 0, 0 }, + { 42, 37, 11, 8, 0, 0, 0 }, + { 35, 15, 11, 8, 0, 0, 0 }, + { 43, 16, 11, 8, 0, 0, 0 }, + { 43, 13, 45, 48, 0, 0, 0 }, + { 44, 0, 54, 8, 0, 0, 0 }, + { 45, 1, 15, 8, 245, 0, 0 }, + { 45, 1, 15, 8, 196, 16, 0 }, + { 45, 1, 15, 8, 245, 1, 0 }, + { 45, 1, 15, 8, 229, 0, 16 }, + { 45, 1, 15, 8, 196, 0, 16 }, + { 46, 1, 15, 8, 245, 0, 0 }, + { 45, 3, 17, 8, 245, 0, 0 }, + { 45, 3, 17, 8, 196, 16, 0 }, + { 45, 3, 17, 8, 245, 1, 0 }, + { 45, 3, 17, 8, 229, 0, 16 }, + { 45, 3, 17, 8, 196, 0, 16 }, + { 46, 3, 17, 8, 245, 0, 0 }, + { 47, 1, 15, 8, 245, 0, 0 }, + { 47, 1, 15, 8, 196, 16, 0 }, + { 47, 1, 15, 8, 245, 1, 0 }, + { 47, 1, 15, 8, 229, 0, 16 }, + { 47, 1, 15, 8, 196, 0, 16 }, + { 48, 1, 15, 8, 245, 0, 0 }, + { 45, 5, 17, 8, 245, 0, 0 }, + { 49, 5, 17, 8, 196, 16, 0 }, + { 45, 5, 17, 8, 245, 1, 0 }, + { 49, 5, 17, 8, 229, 0, 16 }, + { 49, 5, 17, 8, 196, 0, 16 }, + { 46, 5, 17, 8, 245, 0, 0 }, + { 50, 0, 17, 8, 0, 0, 0 }, + { 51, 1, 15, 8, 1, 0, 32 }, + { 51, 1, 15, 8, 1, 1, 32 }, + { 51, 1, 15, 8, 197, 0, 48 }, + { 51, 1, 17, 8, 1, 0, 32 }, + { 51, 1, 17, 8, 1, 1, 32 }, + { 51, 1, 17, 8, 197, 0, 48 }, + { 52, 1, 15, 8, 0, 0, 0 }, + { 53, 0, 1, 24, 0, 0, 0 }, + { 52, 3, 17, 8, 0, 0, 0 }, + { 53, 0, 41, 24, 0, 0, 0 }, + { 51, 51, 15, 8, 33, 0, 0 }, + { 51, 51, 15, 8, 33, 1, 0 }, + { 51, 51, 15, 8, 229, 0, 16 }, + { 51, 51, 17, 8, 33, 0, 0 }, + { 51, 51, 17, 8, 33, 1, 0 }, + { 51, 51, 17, 8, 229, 0, 16 }, + { 51, 52, 15, 8, 1, 0, 32 }, + { 51, 52, 15, 8, 1, 1, 32 }, + { 51, 52, 15, 8, 197, 0, 48 }, + { 51, 52, 17, 8, 1, 0, 32 }, + { 51, 52, 17, 8, 1, 1, 32 }, + { 51, 52, 17, 8, 197, 0, 48 }, + { 46, 0, 21, 16, 0, 0, 0 }, + { 54, 0, 62, 16, 0, 0, 0 }, + { 54, 0, 61, 16, 0, 0, 0 }, + { 54, 0, 0, 16, 0, 0, 0 }, + { 51, 0, 21, 16, 0, 0, 0 }, + { 46, 0, 42, 16, 0, 0, 0 }, + { 46, 0, 20, 16, 0, 0, 0 }, + { 55, 0, 62, 24, 0, 1, 0 }, + { 55, 0, 62, 24, 0, 64, 0 }, + { 55, 0, 62, 24, 0, 65, 0 }, + { 55, 0, 62, 24, 0, 4, 0 }, + { 56, 0, 21, 56, 0, 0, 0 }, + { 46, 0, 23, 16, 0, 0, 0 }, + { 51, 0, 23, 16, 0, 0, 0 }, + { 55, 0, 62, 16, 69, 0, 0 }, + { 55, 0, 62, 24, 69, 0, 0 }, + { 46, 0, 22, 16, 0, 0, 0 }, + { 54, 0, 63, 16, 0, 0, 0 }, + { 56, 0, 22, 56, 0, 0, 0 }, + { 51, 0, 22, 16, 0, 0, 0 }, + { 56, 0, 20, 56, 0, 0, 0 }, + { 51, 0, 20, 16, 0, 0, 0 }, + { 46, 1, 15, 8, 196, 0, 16 }, + { 45, 0, 15, 8, 0, 0, 0 }, + { 45, 0, 15, 8, 245, 0, 0 }, + { 51, 0, 15, 8, 33, 0, 212 }, + { 51, 0, 15, 8, 0, 0, 245 }, + { 46, 3, 17, 8, 196, 0, 16 }, + { 45, 0, 17, 8, 0, 0, 0 }, + { 45, 0, 17, 8, 245, 0, 0 }, + { 51, 0, 17, 8, 33, 0, 212 }, + { 51, 0, 17, 8, 0, 0, 245 }, + { 45, 0, 15, 8, 244, 0, 0 }, + { 45, 0, 17, 8, 244, 0, 0 }, + { 57, 0, 17, 9, 0, 0, 0 }, + { 58, 0, 37, 9, 0, 0, 0 }, + { 57, 0, 17, 12, 0, 0, 0 }, + { 58, 0, 37, 12, 0, 0, 0 }, + { 57, 0, 17, 8, 0, 0, 0 }, + { 46, 0, 17, 8, 0, 0, 0 }, + { 46, 0, 16, 8, 0, 0, 0 }, + { 56, 0, 16, 8, 0, 0, 0 }, + { 46, 0, 16, 8, 64, 0, 0 }, + { 57, 0, 39, 8, 0, 0, 0 }, + { 52, 0, 28, 8, 0, 0, 0 }, + { 59, 0, 16, 8, 0, 0, 0 }, + { 56, 0, 42, 8, 0, 0, 0 }, + { 55, 0, 0, 112, 0, 0, 0 }, + { 55, 0, 0, 8, 0, 0, 0 }, + { 13, 0, 0, 24, 0, 0, 0 }, + { 56, 0, 58, 120, 0, 0, 0 }, + { 55, 0, 0, 120, 0, 0, 0 }, + { 55, 0, 58, 120, 0, 0, 0 }, + { 55, 60, 58, 120, 0, 0, 0 }, + { 60, 0, 0, 8, 0, 0, 0 }, + { 56, 0, 42, 96, 0, 0, 0 }, + { 61, 67, 64, 104, 0, 0, 0 }, + { 61, 67, 64, 96, 0, 0, 0 }, + { 35, 73, 68, 40, 0, 0, 0 }, + { 35, 73, 68, 48, 0, 0, 0 }, + { 35, 71, 68, 40, 0, 0, 0 }, + { 35, 72, 68, 48, 0, 0, 0 }, + { 62, 90, 83, 128, 0, 0, 0 }, + { 63, 81, 68, 128, 0, 0, 0 }, + { 64, 44, 68, 128, 0, 0, 0 }, + { 64, 46, 68, 128, 0, 0, 0 }, + { 35, 68, 73, 40, 0, 0, 0 }, + { 35, 68, 73, 48, 0, 0, 0 }, + { 35, 68, 71, 40, 0, 0, 0 }, + { 35, 68, 72, 48, 0, 0, 0 }, + { 62, 83, 90, 128, 0, 0, 0 }, + { 64, 68, 44, 128, 0, 0, 0 }, + { 64, 68, 46, 128, 0, 0, 0 }, + { 65, 72, 68, 40, 0, 0, 0 }, + { 35, 46, 68, 48, 0, 0, 0 }, + { 35, 72, 68, 56, 0, 0, 0 }, + { 66, 81, 68, 128, 0, 0, 0 }, + { 67, 81, 68, 128, 0, 0, 0 }, + { 62, 89, 83, 128, 0, 0, 0 }, + { 35, 68, 46, 40, 0, 0, 0 }, + { 35, 68, 46, 48, 0, 0, 0 }, + { 62, 68, 46, 128, 0, 0, 0 }, + { 34, 73, 68, 40, 0, 0, 0 }, + { 34, 73, 68, 48, 0, 0, 0 }, + { 67, 88, 83, 128, 0, 0, 0 }, + { 35, 73, 68, 56, 0, 0, 0 }, + { 56, 0, 42, 40, 0, 0, 0 }, + { 34, 67, 68, 40, 0, 0, 0 }, + { 34, 67, 68, 48, 0, 0, 0 }, + { 42, 18, 68, 40, 0, 0, 0 }, + { 42, 18, 68, 48, 0, 0, 0 }, + { 35, 68, 47, 40, 0, 0, 0 }, + { 35, 68, 47, 48, 0, 0, 0 }, + { 35, 68, 44, 88, 0, 0, 0 }, + { 35, 68, 46, 88, 0, 0, 0 }, + { 62, 83, 92, 128, 0, 0, 0 }, + { 34, 72, 64, 40, 0, 0, 0 }, + { 34, 73, 64, 48, 0, 0, 0 }, + { 42, 71, 13, 40, 0, 0, 0 }, + { 42, 72, 13, 48, 0, 0, 0 }, + { 62, 80, 78, 128, 0, 0, 0 }, + { 34, 71, 68, 40, 69, 0, 0 }, + { 34, 72, 68, 48, 0, 0, 0 }, + { 62, 71, 68, 128, 0, 0, 0 }, + { 62, 72, 68, 128, 0, 0, 0 }, + { 68, 69, 12, 40, 0, 0, 0 }, + { 68, 69, 12, 48, 0, 0, 0 }, + { 69, 83, 13, 128, 0, 0, 0 }, + { 34, 71, 68, 40, 0, 0, 0 }, + { 34, 71, 68, 48, 0, 0, 0 }, + { 62, 91, 83, 128, 0, 0, 0 }, + { 62, 90, 68, 128, 0, 0, 0 }, + { 34, 66, 64, 32, 0, 0, 0 }, + { 34, 67, 64, 32, 0, 0, 0 }, + { 70, 18, 64, 32, 0, 0, 0 }, + { 70, 18, 68, 48, 0, 0, 0 }, + { 62, 79, 68, 128, 0, 0, 0 }, + { 35, 67, 64, 32, 0, 0, 0 }, + { 71, 67, 64, 40, 0, 0, 0 }, + { 71, 73, 68, 48, 0, 0, 0 }, + { 67, 73, 68, 128, 0, 0, 0 }, + { 32, 0, 0, 32, 0, 0, 0 }, + { 72, 0, 0, 128, 0, 0, 0 }, + { 73, 13, 18, 112, 0, 0, 0 }, + { 74, 7, 69, 88, 0, 0, 0 }, + { 75, 69, 68, 88, 0, 0, 0 }, + { 73, 18, 13, 112, 0, 0, 0 }, + { 34, 69, 68, 88, 0, 0, 0 }, + { 76, 69, 68, 88, 0, 0, 0 }, + { 32, 72, 68, 112, 0, 0, 0 }, + { 32, 68, 72, 112, 0, 0, 0 }, + { 34, 73, 68, 56, 0, 0, 0 }, + { 70, 64, 18, 32, 0, 0, 0 }, + { 70, 68, 18, 48, 0, 0, 0 }, + { 62, 68, 79, 128, 0, 0, 0 }, + { 35, 64, 67, 32, 0, 0, 0 }, + { 77, 0, 42, 8, 0, 0, 0 }, + { 78, 0, 43, 8, 0, 0, 0 }, + { 79, 0, 43, 8, 0, 0, 0 }, + { 80, 17, 11, 80, 64, 0, 0 }, + { 81, 1, 17, 8, 1, 0, 244 }, + { 49, 1, 17, 8, 1, 0, 244 }, + { 34, 17, 11, 8, 64, 0, 245 }, + { 82, 17, 11, 112, 0, 0, 0 }, + { 83, 17, 11, 8, 65, 0, 180 }, + { 84, 73, 68, 40, 0, 0, 0 }, + { 84, 73, 68, 48, 0, 0, 0 }, + { 84, 71, 68, 40, 0, 0, 0 }, + { 84, 72, 68, 48, 0, 0, 0 }, + { 85, 88, 83, 128, 0, 0, 0 }, + { 85, 81, 68, 128, 0, 0, 0 }, + { 71, 25, 64, 40, 0, 0, 0 }, + { 71, 25, 68, 48, 0, 0, 0 }, + { 86, 81, 68, 128, 0, 0, 0 }, + { 87, 65, 12, 40, 0, 0, 0 }, + { 71, 69, 12, 48, 0, 0, 0 }, + { 88, 68, 13, 128, 0, 0, 0 }, + { 71, 73, 68, 40, 0, 0, 0 }, + { 86, 88, 83, 128, 0, 0, 0 }, + { 89, 0, 48, 8, 64, 0, 0 }, + { 56, 0, 46, 112, 0, 0, 0 }, + { 68, 65, 68, 48, 0, 0, 0 }, + { 68, 69, 64, 48, 0, 0, 0 }, + { 62, 68, 72, 128, 0, 0, 0 }, + { 76, 65, 12, 40, 0, 0, 0 }, + { 76, 69, 12, 48, 0, 0, 0 }, + { 69, 68, 13, 128, 0, 0, 0 }, + { 34, 67, 64, 40, 0, 0, 0 }, + { 35, 64, 46, 40, 0, 0, 0 }, + { 34, 42, 68, 56, 0, 0, 0 }, + { 62, 92, 83, 128, 0, 0, 0 }, + { 34, 67, 64, 48, 0, 0, 0 }, + { 76, 65, 64, 40, 0, 0, 0 }, + { 76, 69, 68, 48, 0, 0, 0 }, + { 90, 69, 68, 128, 0, 0, 0 }, + { 51, 0, 42, 16, 0, 0, 0 }, + { 91, 0, 42, 16, 0, 0, 0 }, + { 91, 0, 20, 16, 0, 0, 0 }, + { 92, 0, 0, 16, 0, 0, 0 }, + { 93, 0, 34, 16, 0, 0, 0 }, + { 94, 0, 34, 16, 0, 0, 0 }, + { 34, 67, 64, 64, 0, 0, 0 }, + { 34, 73, 68, 64, 0, 0, 0 }, + { 71, 73, 68, 72, 0, 0, 0 }, + { 34, 73, 68, 80, 0, 0, 0 }, + { 62, 44, 83, 128, 0, 0, 0 }, + { 62, 46, 85, 128, 0, 0, 0 }, + { 62, 47, 85, 128, 0, 0, 0 }, + { 62, 73, 68, 128, 0, 0, 0 }, + { 34, 72, 68, 72, 0, 0, 0 }, + { 34, 71, 68, 72, 0, 0, 0 }, + { 34, 70, 68, 72, 0, 0, 0 }, + { 62, 70, 68, 128, 0, 0, 0 }, + { 34, 73, 68, 72, 0, 0, 0 }, + { 35, 47, 68, 72, 0, 0, 0 }, + { 62, 47, 68, 128, 0, 0, 0 }, + { 67, 88, 92, 128, 0, 0, 0 }, + { 73, 47, 13, 112, 0, 0, 0 }, + { 67, 88, 83, 136, 0, 0, 0 }, + { 67, 81, 68, 136, 0, 0, 0 }, + { 34, 73, 68, 152, 0, 0, 0 }, + { 62, 73, 68, 152, 0, 0, 0 }, + { 67, 81, 68, 152, 0, 0, 0 }, + { 35, 17, 11, 8, 0, 0, 0 }, + { 35, 15, 13, 80, 0, 0, 0 }, + { 35, 11, 17, 8, 0, 0, 0 }, + { 35, 17, 13, 80, 0, 0, 0 }, + { 67, 90, 83, 128, 0, 0, 0 }, + { 86, 87, 85, 128, 0, 0, 0 }, + { 71, 71, 68, 72, 0, 0, 0 }, + { 71, 72, 68, 72, 0, 0, 0 }, + { 71, 67, 64, 64, 0, 0, 0 }, + { 71, 73, 68, 64, 0, 0, 0 }, + { 71, 68, 26, 72, 0, 0, 0 }, + { 88, 68, 76, 128, 0, 0, 0 }, + { 71, 68, 27, 72, 0, 0, 0 }, + { 88, 68, 77, 128, 0, 0, 0 }, + { 95, 68, 18, 72, 0, 0, 0 }, + { 67, 68, 79, 128, 0, 0, 0 }, + { 71, 68, 18, 72, 0, 0, 0 }, + { 67, 68, 75, 128, 0, 0, 0 }, + { 67, 85, 73, 128, 0, 0, 0 }, + { 71, 24, 68, 72, 0, 0, 0 }, + { 95, 18, 68, 72, 0, 0, 0 }, + { 71, 73, 68, 144, 0, 0, 0 }, + { 86, 81, 68, 144, 0, 0, 0 }, + { 71, 73, 68, 80, 0, 0, 0 }, + { 71, 73, 68, 152, 0, 0, 0 }, + { 67, 73, 68, 152, 0, 0, 0 }, + { 96, 1, 65, 32, 0, 0, 0 }, + { 56, 1, 69, 48, 0, 0, 0 }, + { 97, 69, 81, 128, 0, 0, 0 }, + { 98, 0, 13, 112, 0, 0, 0 }, + { 64, 0, 44, 128, 0, 0, 0 }, + { 56, 0, 42, 112, 0, 0, 0 }, + { 99, 75, 13, 8, 0, 0, 0 }, + { 98, 0, 17, 8, 0, 0, 0 }, + { 100, 67, 64, 96, 0, 0, 0 } +}; + +uint16_t CmpMnemonicOffsets[8] = { + 0, 9, 18, 27, 39, 49, 59, 69 +}; +uint16_t VCmpMnemonicOffsets[32] = { + 0, 10, 20, 30, 43, 54, 65, 76, 87, 100, 111, 122, 135, 149, 159, 169, 181, 194, 207, 220, 235, 249, 263, 277, 290, 303, 317, 331, 347, 361, 374, 387 +}; diff --git a/distorm/src/insts.h b/distorm/src/insts.h new file mode 100644 index 0000000..946cacd --- /dev/null +++ b/distorm/src/insts.h @@ -0,0 +1,64 @@ +/* +insts.h + +diStorm3 - Powerful disassembler for X86/AMD64 +http://ragestorm.net/distorm/ +distorm at gmail dot com +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. +*/ + + +#ifndef INSTS_H +#define INSTS_H + +#include "instructions.h" + + +/* Flags Table */ +extern _iflags FlagsTable[]; + +/* Root Trie DB */ +extern _InstSharedInfo InstSharedInfoTable[]; +extern _InstInfo InstInfos[]; +extern _InstInfoEx InstInfosEx[]; +extern _InstNode InstructionsTree[]; + +/* 3DNow! Trie DB */ +extern _InstNode Table_0F_0F; +/* AVX related: */ +extern _InstNode Table_0F, Table_0F_38, Table_0F_3A; + +/* + * The inst_lookup will return on of these two instructions according to the specified decoding mode. + * ARPL or MOVSXD on 64 bits is one byte instruction at index 0x63. + */ +extern _InstInfo II_MOVSXD; + +/* + * The NOP instruction can be prefixed by REX in 64bits, therefore we have to decide in runtime whether it's an XCHG or NOP instruction. + * If 0x90 is prefixed by a usable REX it will become XCHG, otherwise it will become a NOP. + * Also note that if it's prefixed by 0xf3, it becomes a Pause. + */ +extern _InstInfo II_NOP; +extern _InstInfo II_PAUSE; + +/* + * RDRAND and VMPTRLD share same 2.3 bytes opcode, and then alternates on the MOD bits, + * RDRAND is OT_FULL_REG while VMPTRLD is OT_MEM, and there's no such mixed type. + * So a hack into the inst_lookup was added for this decision, the DB isn't flexible enough. :( + */ +extern _InstInfo II_RDRAND; + +/* + * Used for letting the extract operand know the type of operands without knowing the + * instruction itself yet, because of the way those instructions work. + * See function instructions.c!inst_lookup_3dnow. + */ +extern _InstInfo II_3DNOW; + +/* Helper tables for pseudo compare mnemonics. */ +extern uint16_t CmpMnemonicOffsets[8]; /* SSE */ +extern uint16_t VCmpMnemonicOffsets[32]; /* AVX */ + +#endif /* INSTS_H */ diff --git a/distorm3.2-package/src/mnemonics.c b/distorm/src/mnemonics.c similarity index 68% rename from distorm3.2-package/src/mnemonics.c rename to distorm/src/mnemonics.c index 0c39a21..ff00ac5 100644 --- a/distorm3.2-package/src/mnemonics.c +++ b/distorm/src/mnemonics.c @@ -4,20 +4,8 @@ mnemonics.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -59,65 +47,66 @@ const unsigned char _MNEMONICS[] = "\x03" "LFS\0" "\x03" "LGS\0" "\x05" "MOVZX\0" "\x03" "BTC\0" "\x05" "MOVSX\0" \ "\x04" "XADD\0" "\x06" "MOVNTI\0" "\x05" "BSWAP\0" "\x03" "ROL\0" "\x03" "ROR\0" \ "\x03" "RCL\0" "\x03" "RCR\0" "\x03" "SHL\0" "\x03" "SHR\0" "\x03" "SAL\0" \ -"\x03" "SAR\0" "\x04" "FADD\0" "\x04" "FMUL\0" "\x04" "FCOM\0" "\x05" "FCOMP\0" \ -"\x04" "FSUB\0" "\x05" "FSUBR\0" "\x04" "FDIV\0" "\x05" "FDIVR\0" "\x03" "FLD\0" \ -"\x03" "FST\0" "\x04" "FSTP\0" "\x06" "FLDENV\0" "\x05" "FLDCW\0" "\x04" "FXCH\0" \ -"\x04" "FNOP\0" "\x04" "FCHS\0" "\x04" "FABS\0" "\x04" "FTST\0" "\x04" "FXAM\0" \ -"\x04" "FLD1\0" "\x06" "FLDL2T\0" "\x06" "FLDL2E\0" "\x05" "FLDPI\0" "\x06" "FLDLG2\0" \ -"\x06" "FLDLN2\0" "\x04" "FLDZ\0" "\x05" "F2XM1\0" "\x05" "FYL2X\0" "\x05" "FPTAN\0" \ -"\x06" "FPATAN\0" "\x07" "FXTRACT\0" "\x06" "FPREM1\0" "\x07" "FDECSTP\0" "\x07" "FINCSTP\0" \ -"\x05" "FPREM\0" "\x07" "FYL2XP1\0" "\x05" "FSQRT\0" "\x07" "FSINCOS\0" "\x07" "FRNDINT\0" \ -"\x06" "FSCALE\0" "\x04" "FSIN\0" "\x04" "FCOS\0" "\x05" "FIADD\0" "\x05" "FIMUL\0" \ -"\x05" "FICOM\0" "\x06" "FICOMP\0" "\x05" "FISUB\0" "\x06" "FISUBR\0" "\x05" "FIDIV\0" \ -"\x06" "FIDIVR\0" "\x06" "FCMOVB\0" "\x06" "FCMOVE\0" "\x07" "FCMOVBE\0" "\x06" "FCMOVU\0" \ -"\x07" "FUCOMPP\0" "\x04" "FILD\0" "\x06" "FISTTP\0" "\x04" "FIST\0" "\x05" "FISTP\0" \ -"\x07" "FCMOVNB\0" "\x07" "FCMOVNE\0" "\x08" "FCMOVNBE\0" "\x07" "FCMOVNU\0" \ -"\x04" "FENI\0" "\x06" "FEDISI\0" "\x06" "FSETPM\0" "\x06" "FUCOMI\0" "\x05" "FCOMI\0" \ -"\x06" "FRSTOR\0" "\x05" "FFREE\0" "\x05" "FUCOM\0" "\x06" "FUCOMP\0" "\x05" "FADDP\0" \ -"\x05" "FMULP\0" "\x06" "FCOMPP\0" "\x06" "FSUBRP\0" "\x05" "FSUBP\0" "\x06" "FDIVRP\0" \ -"\x05" "FDIVP\0" "\x04" "FBLD\0" "\x05" "FBSTP\0" "\x07" "FUCOMIP\0" "\x06" "FCOMIP\0" \ -"\x03" "NOT\0" "\x03" "NEG\0" "\x03" "MUL\0" "\x03" "DIV\0" "\x04" "IDIV\0" \ -"\x04" "SLDT\0" "\x03" "STR\0" "\x04" "LLDT\0" "\x03" "LTR\0" "\x04" "VERR\0" \ -"\x04" "VERW\0" "\x04" "SGDT\0" "\x04" "SIDT\0" "\x04" "LGDT\0" "\x04" "LIDT\0" \ -"\x04" "SMSW\0" "\x04" "LMSW\0" "\x06" "INVLPG\0" "\x06" "VMCALL\0" "\x08" "VMLAUNCH\0" \ -"\x08" "VMRESUME\0" "\x06" "VMXOFF\0" "\x07" "MONITOR\0" "\x05" "MWAIT\0" "\x06" "XGETBV\0" \ -"\x06" "XSETBV\0" "\x06" "VMFUNC\0" "\x05" "VMRUN\0" "\x07" "VMMCALL\0" "\x06" "VMLOAD\0" \ -"\x06" "VMSAVE\0" "\x04" "STGI\0" "\x04" "CLGI\0" "\x06" "SKINIT\0" "\x07" "INVLPGA\0" \ -"\x06" "SWAPGS\0" "\x06" "RDTSCP\0" "\x08" "PREFETCH\0" "\x09" "PREFETCHW\0" \ -"\x05" "PI2FW\0" "\x05" "PI2FD\0" "\x05" "PF2IW\0" "\x05" "PF2ID\0" "\x06" "PFNACC\0" \ -"\x07" "PFPNACC\0" "\x07" "PFCMPGE\0" "\x05" "PFMIN\0" "\x05" "PFRCP\0" "\x07" "PFRSQRT\0" \ -"\x05" "PFSUB\0" "\x05" "PFADD\0" "\x07" "PFCMPGT\0" "\x05" "PFMAX\0" "\x08" "PFRCPIT1\0" \ -"\x08" "PFRSQIT1\0" "\x06" "PFSUBR\0" "\x05" "PFACC\0" "\x07" "PFCMPEQ\0" "\x05" "PFMUL\0" \ -"\x08" "PFRCPIT2\0" "\x07" "PMULHRW\0" "\x06" "PSWAPD\0" "\x07" "PAVGUSB\0" \ -"\x06" "MOVUPS\0" "\x06" "MOVUPD\0" "\x05" "MOVSS\0" "\x05" "MOVSD\0" "\x07" "VMOVUPS\0" \ -"\x07" "VMOVUPD\0" "\x06" "VMOVSS\0" "\x06" "VMOVSD\0" "\x07" "MOVHLPS\0" "\x06" "MOVLPS\0" \ -"\x06" "MOVLPD\0" "\x08" "MOVSLDUP\0" "\x07" "MOVDDUP\0" "\x08" "VMOVHLPS\0" \ -"\x07" "VMOVLPS\0" "\x07" "VMOVLPD\0" "\x09" "VMOVSLDUP\0" "\x08" "VMOVDDUP\0" \ -"\x08" "UNPCKLPS\0" "\x08" "UNPCKLPD\0" "\x09" "VUNPCKLPS\0" "\x09" "VUNPCKLPD\0" \ -"\x08" "UNPCKHPS\0" "\x08" "UNPCKHPD\0" "\x09" "VUNPCKHPS\0" "\x09" "VUNPCKHPD\0" \ -"\x07" "MOVLHPS\0" "\x06" "MOVHPS\0" "\x06" "MOVHPD\0" "\x08" "MOVSHDUP\0" \ -"\x08" "VMOVLHPS\0" "\x07" "VMOVHPS\0" "\x07" "VMOVHPD\0" "\x09" "VMOVSHDUP\0" \ -"\x0b" "PREFETCHNTA\0" "\x0a" "PREFETCHT0\0" "\x0a" "PREFETCHT1\0" "\x0a" "PREFETCHT2\0" \ -"\x06" "MOVAPS\0" "\x06" "MOVAPD\0" "\x07" "VMOVAPS\0" "\x07" "VMOVAPD\0" "\x08" "CVTPI2PS\0" \ -"\x08" "CVTPI2PD\0" "\x08" "CVTSI2SS\0" "\x08" "CVTSI2SD\0" "\x09" "VCVTSI2SS\0" \ -"\x09" "VCVTSI2SD\0" "\x07" "MOVNTPS\0" "\x07" "MOVNTPD\0" "\x07" "MOVNTSS\0" \ -"\x07" "MOVNTSD\0" "\x08" "VMOVNTPS\0" "\x08" "VMOVNTPD\0" "\x09" "CVTTPS2PI\0" \ -"\x09" "CVTTPD2PI\0" "\x09" "CVTTSS2SI\0" "\x09" "CVTTSD2SI\0" "\x0a" "VCVTTSS2SI\0" \ -"\x0a" "VCVTTSD2SI\0" "\x08" "CVTPS2PI\0" "\x08" "CVTPD2PI\0" "\x08" "CVTSS2SI\0" \ -"\x08" "CVTSD2SI\0" "\x09" "VCVTSS2SI\0" "\x09" "VCVTSD2SI\0" "\x07" "UCOMISS\0" \ -"\x07" "UCOMISD\0" "\x08" "VUCOMISS\0" "\x08" "VUCOMISD\0" "\x06" "COMISS\0" \ -"\x06" "COMISD\0" "\x07" "VCOMISS\0" "\x07" "VCOMISD\0" "\x08" "MOVMSKPS\0" \ -"\x08" "MOVMSKPD\0" "\x09" "VMOVMSKPS\0" "\x09" "VMOVMSKPD\0" "\x06" "SQRTPS\0" \ -"\x06" "SQRTPD\0" "\x06" "SQRTSS\0" "\x06" "SQRTSD\0" "\x07" "VSQRTPS\0" "\x07" "VSQRTPD\0" \ -"\x07" "VSQRTSS\0" "\x07" "VSQRTSD\0" "\x07" "RSQRTPS\0" "\x07" "RSQRTSS\0" \ -"\x08" "VRSQRTPS\0" "\x08" "VRSQRTSS\0" "\x05" "RCPPS\0" "\x05" "RCPSS\0" "\x06" "VRCPPS\0" \ -"\x06" "VRCPSS\0" "\x05" "ANDPS\0" "\x05" "ANDPD\0" "\x06" "VANDPS\0" "\x06" "VANDPD\0" \ -"\x06" "ANDNPS\0" "\x06" "ANDNPD\0" "\x07" "VANDNPS\0" "\x07" "VANDNPD\0" "\x04" "ORPS\0" \ -"\x04" "ORPD\0" "\x05" "VORPS\0" "\x05" "VORPD\0" "\x05" "XORPS\0" "\x05" "XORPD\0" \ -"\x06" "VXORPS\0" "\x06" "VXORPD\0" "\x05" "ADDPS\0" "\x05" "ADDPD\0" "\x05" "ADDSS\0" \ -"\x05" "ADDSD\0" "\x06" "VADDPS\0" "\x06" "VADDPD\0" "\x06" "VADDSS\0" "\x06" "VADDSD\0" \ -"\x05" "MULPS\0" "\x05" "MULPD\0" "\x05" "MULSS\0" "\x05" "MULSD\0" "\x06" "VMULPS\0" \ -"\x06" "VMULPD\0" "\x06" "VMULSS\0" "\x06" "VMULSD\0" "\x08" "CVTPS2PD\0" "\x08" "CVTPD2PS\0" \ +"\x03" "SAR\0" "\x06" "XABORT\0" "\x06" "XBEGIN\0" "\x04" "FADD\0" "\x04" "FMUL\0" \ +"\x04" "FCOM\0" "\x05" "FCOMP\0" "\x04" "FSUB\0" "\x05" "FSUBR\0" "\x04" "FDIV\0" \ +"\x05" "FDIVR\0" "\x03" "FLD\0" "\x03" "FST\0" "\x04" "FSTP\0" "\x06" "FLDENV\0" \ +"\x05" "FLDCW\0" "\x04" "FXCH\0" "\x04" "FNOP\0" "\x04" "FCHS\0" "\x04" "FABS\0" \ +"\x04" "FTST\0" "\x04" "FXAM\0" "\x04" "FLD1\0" "\x06" "FLDL2T\0" "\x06" "FLDL2E\0" \ +"\x05" "FLDPI\0" "\x06" "FLDLG2\0" "\x06" "FLDLN2\0" "\x04" "FLDZ\0" "\x05" "F2XM1\0" \ +"\x05" "FYL2X\0" "\x05" "FPTAN\0" "\x06" "FPATAN\0" "\x07" "FXTRACT\0" "\x06" "FPREM1\0" \ +"\x07" "FDECSTP\0" "\x07" "FINCSTP\0" "\x05" "FPREM\0" "\x07" "FYL2XP1\0" "\x05" "FSQRT\0" \ +"\x07" "FSINCOS\0" "\x07" "FRNDINT\0" "\x06" "FSCALE\0" "\x04" "FSIN\0" "\x04" "FCOS\0" \ +"\x05" "FIADD\0" "\x05" "FIMUL\0" "\x05" "FICOM\0" "\x06" "FICOMP\0" "\x05" "FISUB\0" \ +"\x06" "FISUBR\0" "\x05" "FIDIV\0" "\x06" "FIDIVR\0" "\x06" "FCMOVB\0" "\x06" "FCMOVE\0" \ +"\x07" "FCMOVBE\0" "\x06" "FCMOVU\0" "\x07" "FUCOMPP\0" "\x04" "FILD\0" "\x06" "FISTTP\0" \ +"\x04" "FIST\0" "\x05" "FISTP\0" "\x07" "FCMOVNB\0" "\x07" "FCMOVNE\0" "\x08" "FCMOVNBE\0" \ +"\x07" "FCMOVNU\0" "\x04" "FENI\0" "\x06" "FEDISI\0" "\x06" "FSETPM\0" "\x06" "FUCOMI\0" \ +"\x05" "FCOMI\0" "\x06" "FRSTOR\0" "\x05" "FFREE\0" "\x05" "FUCOM\0" "\x06" "FUCOMP\0" \ +"\x05" "FADDP\0" "\x05" "FMULP\0" "\x06" "FCOMPP\0" "\x06" "FSUBRP\0" "\x05" "FSUBP\0" \ +"\x06" "FDIVRP\0" "\x05" "FDIVP\0" "\x04" "FBLD\0" "\x05" "FBSTP\0" "\x07" "FUCOMIP\0" \ +"\x06" "FCOMIP\0" "\x03" "NOT\0" "\x03" "NEG\0" "\x03" "MUL\0" "\x03" "DIV\0" \ +"\x04" "IDIV\0" "\x04" "SLDT\0" "\x03" "STR\0" "\x04" "LLDT\0" "\x03" "LTR\0" \ +"\x04" "VERR\0" "\x04" "VERW\0" "\x04" "SGDT\0" "\x04" "SIDT\0" "\x04" "LGDT\0" \ +"\x04" "LIDT\0" "\x04" "SMSW\0" "\x04" "LMSW\0" "\x06" "INVLPG\0" "\x06" "VMCALL\0" \ +"\x08" "VMLAUNCH\0" "\x08" "VMRESUME\0" "\x06" "VMXOFF\0" "\x07" "MONITOR\0" \ +"\x05" "MWAIT\0" "\x06" "XGETBV\0" "\x06" "XSETBV\0" "\x06" "VMFUNC\0" "\x04" "XEND\0" \ +"\x05" "VMRUN\0" "\x07" "VMMCALL\0" "\x06" "VMLOAD\0" "\x06" "VMSAVE\0" "\x04" "STGI\0" \ +"\x04" "CLGI\0" "\x06" "SKINIT\0" "\x07" "INVLPGA\0" "\x06" "SWAPGS\0" "\x06" "RDTSCP\0" \ +"\x08" "PREFETCH\0" "\x09" "PREFETCHW\0" "\x05" "PI2FW\0" "\x05" "PI2FD\0" \ +"\x05" "PF2IW\0" "\x05" "PF2ID\0" "\x06" "PFNACC\0" "\x07" "PFPNACC\0" "\x07" "PFCMPGE\0" \ +"\x05" "PFMIN\0" "\x05" "PFRCP\0" "\x07" "PFRSQRT\0" "\x05" "PFSUB\0" "\x05" "PFADD\0" \ +"\x07" "PFCMPGT\0" "\x05" "PFMAX\0" "\x08" "PFRCPIT1\0" "\x08" "PFRSQIT1\0" \ +"\x06" "PFSUBR\0" "\x05" "PFACC\0" "\x07" "PFCMPEQ\0" "\x05" "PFMUL\0" "\x08" "PFRCPIT2\0" \ +"\x07" "PMULHRW\0" "\x06" "PSWAPD\0" "\x07" "PAVGUSB\0" "\x06" "MOVUPS\0" "\x06" "MOVUPD\0" \ +"\x05" "MOVSS\0" "\x05" "MOVSD\0" "\x07" "VMOVUPS\0" "\x07" "VMOVUPD\0" "\x06" "VMOVSS\0" \ +"\x06" "VMOVSD\0" "\x07" "MOVHLPS\0" "\x06" "MOVLPS\0" "\x06" "MOVLPD\0" "\x08" "MOVSLDUP\0" \ +"\x07" "MOVDDUP\0" "\x08" "VMOVHLPS\0" "\x07" "VMOVLPS\0" "\x07" "VMOVLPD\0" \ +"\x09" "VMOVSLDUP\0" "\x08" "VMOVDDUP\0" "\x08" "UNPCKLPS\0" "\x08" "UNPCKLPD\0" \ +"\x09" "VUNPCKLPS\0" "\x09" "VUNPCKLPD\0" "\x08" "UNPCKHPS\0" "\x08" "UNPCKHPD\0" \ +"\x09" "VUNPCKHPS\0" "\x09" "VUNPCKHPD\0" "\x07" "MOVLHPS\0" "\x06" "MOVHPS\0" \ +"\x06" "MOVHPD\0" "\x08" "MOVSHDUP\0" "\x08" "VMOVLHPS\0" "\x07" "VMOVHPS\0" \ +"\x07" "VMOVHPD\0" "\x09" "VMOVSHDUP\0" "\x0b" "PREFETCHNTA\0" "\x0a" "PREFETCHT0\0" \ +"\x0a" "PREFETCHT1\0" "\x0a" "PREFETCHT2\0" "\x06" "MOVAPS\0" "\x06" "MOVAPD\0" \ +"\x07" "VMOVAPS\0" "\x07" "VMOVAPD\0" "\x08" "CVTPI2PS\0" "\x08" "CVTPI2PD\0" \ +"\x08" "CVTSI2SS\0" "\x08" "CVTSI2SD\0" "\x09" "VCVTSI2SS\0" "\x09" "VCVTSI2SD\0" \ +"\x07" "MOVNTPS\0" "\x07" "MOVNTPD\0" "\x07" "MOVNTSS\0" "\x07" "MOVNTSD\0" \ +"\x08" "VMOVNTPS\0" "\x08" "VMOVNTPD\0" "\x09" "CVTTPS2PI\0" "\x09" "CVTTPD2PI\0" \ +"\x09" "CVTTSS2SI\0" "\x09" "CVTTSD2SI\0" "\x0a" "VCVTTSS2SI\0" "\x0a" "VCVTTSD2SI\0" \ +"\x08" "CVTPS2PI\0" "\x08" "CVTPD2PI\0" "\x08" "CVTSS2SI\0" "\x08" "CVTSD2SI\0" \ +"\x09" "VCVTSS2SI\0" "\x09" "VCVTSD2SI\0" "\x07" "UCOMISS\0" "\x07" "UCOMISD\0" \ +"\x08" "VUCOMISS\0" "\x08" "VUCOMISD\0" "\x06" "COMISS\0" "\x06" "COMISD\0" \ +"\x07" "VCOMISS\0" "\x07" "VCOMISD\0" "\x08" "MOVMSKPS\0" "\x08" "MOVMSKPD\0" \ +"\x09" "VMOVMSKPS\0" "\x09" "VMOVMSKPD\0" "\x06" "SQRTPS\0" "\x06" "SQRTPD\0" \ +"\x06" "SQRTSS\0" "\x06" "SQRTSD\0" "\x07" "VSQRTPS\0" "\x07" "VSQRTPD\0" "\x07" "VSQRTSS\0" \ +"\x07" "VSQRTSD\0" "\x07" "RSQRTPS\0" "\x07" "RSQRTSS\0" "\x08" "VRSQRTPS\0" \ +"\x08" "VRSQRTSS\0" "\x05" "RCPPS\0" "\x05" "RCPSS\0" "\x06" "VRCPPS\0" "\x06" "VRCPSS\0" \ +"\x05" "ANDPS\0" "\x05" "ANDPD\0" "\x06" "VANDPS\0" "\x06" "VANDPD\0" "\x06" "ANDNPS\0" \ +"\x06" "ANDNPD\0" "\x07" "VANDNPS\0" "\x07" "VANDNPD\0" "\x04" "ORPS\0" "\x04" "ORPD\0" \ +"\x05" "VORPS\0" "\x05" "VORPD\0" "\x05" "XORPS\0" "\x05" "XORPD\0" "\x06" "VXORPS\0" \ +"\x06" "VXORPD\0" "\x05" "ADDPS\0" "\x05" "ADDPD\0" "\x05" "ADDSS\0" "\x05" "ADDSD\0" \ +"\x06" "VADDPS\0" "\x06" "VADDPD\0" "\x06" "VADDSS\0" "\x06" "VADDSD\0" "\x05" "MULPS\0" \ +"\x05" "MULPD\0" "\x05" "MULSS\0" "\x05" "MULSD\0" "\x06" "VMULPS\0" "\x06" "VMULPD\0" \ +"\x06" "VMULSS\0" "\x06" "VMULSD\0" "\x08" "CVTPS2PD\0" "\x08" "CVTPD2PS\0" \ "\x08" "CVTSS2SD\0" "\x08" "CVTSD2SS\0" "\x09" "VCVTPS2PD\0" "\x09" "VCVTPD2PS\0" \ "\x09" "VCVTSS2SD\0" "\x09" "VCVTSD2SS\0" "\x08" "CVTDQ2PS\0" "\x08" "CVTPS2DQ\0" \ "\x09" "CVTTPS2DQ\0" "\x09" "VCVTDQ2PS\0" "\x09" "VCVTPS2DQ\0" "\x0a" "VCVTTPS2DQ\0" \ @@ -272,23 +261,24 @@ const unsigned char _MNEMONICS[] = "\x06" "PSLLDQ\0" "\x07" "VPSLLDQ\0" "\x06" "FXSAVE\0" "\x08" "FXSAVE64\0" \ "\x08" "RDFSBASE\0" "\x07" "FXRSTOR\0" "\x09" "FXRSTOR64\0" "\x08" "RDGSBASE\0" \ "\x07" "LDMXCSR\0" "\x08" "WRFSBASE\0" "\x08" "VLDMXCSR\0" "\x07" "STMXCSR\0" \ -"\x08" "WRGSBASE\0" "\x08" "VSTMXCSR\0" "\x06" "RDRAND\0" "\x07" "VMPTRLD\0" \ -"\x07" "VMCLEAR\0" "\x05" "VMXON\0" "\x04" "WAIT\0" "\x06" "MOVSXD\0" "\x05" "PAUSE\0"; +"\x08" "WRGSBASE\0" "\x08" "VSTMXCSR\0" "\x07" "VMPTRLD\0" "\x07" "VMCLEAR\0" \ +"\x05" "VMXON\0" "\x06" "MOVSXD\0" "\x05" "PAUSE\0" "\x04" "WAIT\0" "\x06" "RDRAND\0" \ +"\x06" "_3DNOW\0"; const _WRegister _REGISTERS[] = { - {3, "RAX"}, {3, "RCX"}, {3, "RDX"}, {3, "RBX"}, {3, "RSP"}, {3, "RBP"}, {3, "RSI"}, {3, "RDI"}, {2, "R8"}, {2, "R9"}, {3, "R10"}, {3, "R11"}, {3, "R12"}, {3, "R13"}, {3, "R14"}, {3, "R15"}, - {3, "EAX"}, {3, "ECX"}, {3, "EDX"}, {3, "EBX"}, {3, "ESP"}, {3, "EBP"}, {3, "ESI"}, {3, "EDI"}, {3, "R8D"}, {3, "R9D"}, {4, "R10D"}, {4, "R11D"}, {4, "R12D"}, {4, "R13D"}, {4, "R14D"}, {4, "R15D"}, - {2, "AX"}, {2, "CX"}, {2, "DX"}, {2, "BX"}, {2, "SP"}, {2, "BP"}, {2, "SI"}, {2, "DI"}, {3, "R8W"}, {3, "R9W"}, {4, "R10W"}, {4, "R11W"}, {4, "R12W"}, {4, "R13W"}, {4, "R14W"}, {4, "R15W"}, - {2, "AL"}, {2, "CL"}, {2, "DL"}, {2, "BL"}, {2, "AH"}, {2, "CH"}, {2, "DH"}, {2, "BH"}, {3, "R8B"}, {3, "R9B"}, {4, "R10B"}, {4, "R11B"}, {4, "R12B"}, {4, "R13B"}, {4, "R14B"}, {4, "R15B"}, - {3, "SPL"}, {3, "BPL"}, {3, "SIL"}, {3, "DIL"}, - {2, "ES"}, {2, "CS"}, {2, "SS"}, {2, "DS"}, {2, "FS"}, {2, "GS"}, - {3, "RIP"}, - {3, "ST0"}, {3, "ST1"}, {3, "ST2"}, {3, "ST3"}, {3, "ST4"}, {3, "ST5"}, {3, "ST6"}, {3, "ST7"}, - {3, "MM0"}, {3, "MM1"}, {3, "MM2"}, {3, "MM3"}, {3, "MM4"}, {3, "MM5"}, {3, "MM6"}, {3, "MM7"}, - {4, "XMM0"}, {4, "XMM1"}, {4, "XMM2"}, {4, "XMM3"}, {4, "XMM4"}, {4, "XMM5"}, {4, "XMM6"}, {4, "XMM7"}, {4, "XMM8"}, {4, "XMM9"}, {5, "XMM10"}, {5, "XMM11"}, {5, "XMM12"}, {5, "XMM13"}, {5, "XMM14"}, {5, "XMM15"}, - {4, "YMM0"}, {4, "YMM1"}, {4, "YMM2"}, {4, "YMM3"}, {4, "YMM4"}, {4, "YMM5"}, {4, "YMM6"}, {4, "YMM7"}, {4, "YMM8"}, {4, "YMM9"}, {5, "YMM10"}, {5, "YMM11"}, {5, "YMM12"}, {5, "YMM13"}, {5, "YMM14"}, {5, "YMM15"}, - {3, "CR0"}, {0, ""}, {3, "CR2"}, {3, "CR3"}, {3, "CR4"}, {0, ""}, {0, ""}, {0, ""}, {3, "CR8"}, - {3, "DR0"}, {3, "DR1"}, {3, "DR2"}, {3, "DR3"}, {0, ""}, {0, ""}, {3, "DR6"}, {3, "DR7"} + { 3, "RAX" }, { 3, "RCX" }, { 3, "RDX" }, { 3, "RBX" }, { 3, "RSP" }, { 3, "RBP" }, { 3, "RSI" }, { 3, "RDI" }, { 2, "R8" }, { 2, "R9" }, { 3, "R10" }, { 3, "R11" }, { 3, "R12" }, { 3, "R13" }, { 3, "R14" }, { 3, "R15" }, + { 3, "EAX" }, { 3, "ECX" }, { 3, "EDX" }, { 3, "EBX" }, { 3, "ESP" }, { 3, "EBP" }, { 3, "ESI" }, { 3, "EDI" }, { 3, "R8D" }, { 3, "R9D" }, { 4, "R10D" }, { 4, "R11D" }, { 4, "R12D" }, { 4, "R13D" }, { 4, "R14D" }, { 4, "R15D" }, + { 2, "AX" }, { 2, "CX" }, { 2, "DX" }, { 2, "BX" }, { 2, "SP" }, { 2, "BP" }, { 2, "SI" }, { 2, "DI" }, { 3, "R8W" }, { 3, "R9W" }, { 4, "R10W" }, { 4, "R11W" }, { 4, "R12W" }, { 4, "R13W" }, { 4, "R14W" }, { 4, "R15W" }, + { 2, "AL" }, { 2, "CL" }, { 2, "DL" }, { 2, "BL" }, { 2, "AH" }, { 2, "CH" }, { 2, "DH" }, { 2, "BH" }, { 3, "R8B" }, { 3, "R9B" }, { 4, "R10B" }, { 4, "R11B" }, { 4, "R12B" }, { 4, "R13B" }, { 4, "R14B" }, { 4, "R15B" }, + { 3, "SPL" }, { 3, "BPL" }, { 3, "SIL" }, { 3, "DIL" }, + { 2, "ES" }, { 2, "CS" }, { 2, "SS" }, { 2, "DS" }, { 2, "FS" }, { 2, "GS" }, + { 3, "RIP" }, + { 3, "ST0" }, { 3, "ST1" }, { 3, "ST2" }, { 3, "ST3" }, { 3, "ST4" }, { 3, "ST5" }, { 3, "ST6" }, { 3, "ST7" }, + { 3, "MM0" }, { 3, "MM1" }, { 3, "MM2" }, { 3, "MM3" }, { 3, "MM4" }, { 3, "MM5" }, { 3, "MM6" }, { 3, "MM7" }, + { 4, "XMM0" }, { 4, "XMM1" }, { 4, "XMM2" }, { 4, "XMM3" }, { 4, "XMM4" }, { 4, "XMM5" }, { 4, "XMM6" }, { 4, "XMM7" }, { 4, "XMM8" }, { 4, "XMM9" }, { 5, "XMM10" }, { 5, "XMM11" }, { 5, "XMM12" }, { 5, "XMM13" }, { 5, "XMM14" }, { 5, "XMM15" }, + { 4, "YMM0" }, { 4, "YMM1" }, { 4, "YMM2" }, { 4, "YMM3" }, { 4, "YMM4" }, { 4, "YMM5" }, { 4, "YMM6" }, { 4, "YMM7" }, { 4, "YMM8" }, { 4, "YMM9" }, { 5, "YMM10" }, { 5, "YMM11" }, { 5, "YMM12" }, { 5, "YMM13" }, { 5, "YMM14" }, { 5, "YMM15" }, + { 3, "CR0" }, { 0, "" }, { 3, "CR2" }, { 3, "CR3" }, { 3, "CR4" }, { 0, "" }, { 0, "" }, { 0, "" }, { 3, "CR8" }, + { 3, "DR0" }, { 3, "DR1" }, { 3, "DR2" }, { 3, "DR3" }, { 0, "" }, { 0, "" }, { 3, "DR6" }, { 3, "DR7" } }; #endif /* DISTORM_LIGHT */ diff --git a/distorm3.2-package/src/operands.c b/distorm/src/operands.c similarity index 97% rename from distorm3.2-package/src/operands.c rename to distorm/src/operands.c index 817a06e..03a0c66 100644 --- a/distorm3.2-package/src/operands.c +++ b/distorm/src/operands.c @@ -4,20 +4,8 @@ operands.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -29,11 +17,11 @@ along with this program. If not, see /* Maps a register to its register-class mask. */ -uint16_t _REGISTERTORCLASS[] = /* Based on _RegisterType enumeration! */ -{RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, 0, 0, 0, 0, 0, 0, 0, 0, - RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, 0, 0, 0, 0, 0, 0, 0, 0, - RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, 0, 0, 0, 0, 0, 0, 0, 0, - RM_AX, RM_CX, RM_DX, RM_BX, RM_AX, RM_CX, RM_DX, RM_BX, 0, 0, 0, 0, 0, 0, 0, 0, +uint32_t _REGISTERTORCLASS[] = /* Based on _RegisterType enumeration! */ +{RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, RM_R8, RM_R9, RM_R10, RM_R11, RM_R12, RM_R13, RM_R14, RM_R15, + RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, RM_R8, RM_R9, RM_R10, RM_R11, RM_R12, RM_R13, RM_R14, RM_R15, + RM_AX, RM_CX, RM_DX, RM_BX, RM_SP, RM_BP, RM_SI, RM_DI, RM_R8, RM_R9, RM_R10, RM_R11, RM_R12, RM_R13, RM_R14, RM_R15, + RM_AX, RM_CX, RM_DX, RM_BX, RM_AX, RM_CX, RM_DX, RM_BX, RM_R8, RM_R9, RM_R10, RM_R11, RM_R12, RM_R13, RM_R14, RM_R15, RM_SP, RM_BP, RM_SI, RM_DI, 0, 0, 0, 0, 0, 0, 0, @@ -501,14 +489,13 @@ static int operands_extract_modrm(_CodeInfo* ci, */ int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, - _OpType type, _OperandNumberType opNum, + _iflags instFlags, _OpType type, _OperandNumberType opNum, unsigned int modrm, _PrefixState* ps, _DecodeType effOpSz, _DecodeType effAdrSz, int* lockableInstruction) { int ret = 0; unsigned int mod = 0, reg = 0, rm = 0, vexV = ps->vexV; unsigned int vrex = ps->vrex, typeHandled = TRUE; - _iflags instFlags = INST_INFO_FLAGS(ii); _Operand* op = &di->ops[opNum]; /* Used to indicate the size of the MEMORY INDIRECTION only. */ @@ -733,8 +720,12 @@ int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, op->type = O_IMM; di->imm_encoded_size = 4; if (ci->dt == Decode64Bits) { - /* Imm32 is sign extended to 64 bits! */ - op->size = 64; + /* + * Imm32 is sign extended to 64 bits! + * Originally the op size was 64, but later was changed to reflect real size of imm. + */ + op->size = 32; + /* Use this as an indicator that it should be signed extended. */ di->flags |= FLAG_IMM_SIGNED; if (!read_stream_safe_sint(ci, &di->imm.sqword, sizeof(int32_t))) return FALSE; } else { @@ -788,7 +779,7 @@ int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, if (ps->prefixExtType) { /* * If REX prefix is valid then we will have to use low bytes. - * This is a PASSIVE behaviour changer of REX prefix, it affects operands even if its value is 0x40 ! + * This is a PASSIVE behavior changer of REX prefix, it affects operands even if its value is 0x40 ! */ ps->usedPrefixes |= INST_PRE_REX; op->index = (uint8_t)operands_fix_8bit_rex_base(reg + ((vrex & PREFIX_EX_R) ? EX_GPR_BASE : 0)); diff --git a/distorm/src/operands.h b/distorm/src/operands.h new file mode 100644 index 0000000..883d59b --- /dev/null +++ b/distorm/src/operands.h @@ -0,0 +1,28 @@ +/* +operands.h + +diStorm3 - Powerful disassembler for X86/AMD64 +http://ragestorm.net/distorm/ +distorm at gmail dot com +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. +*/ + + +#ifndef OPERANDS_H +#define OPERANDS_H + +#include "config.h" +#include "decoder.h" +#include "prefix.h" +#include "instructions.h" + + +extern uint32_t _REGISTERTORCLASS[]; + +int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, + _iflags instFlags, _OpType type, _OperandNumberType opNum, + unsigned int modrm, _PrefixState* ps, _DecodeType effOpSz, + _DecodeType effAdrSz, int* lockableInstruction); + +#endif /* OPERANDS_H */ diff --git a/distorm3.2-package/src/prefix.c b/distorm/src/prefix.c similarity index 94% rename from distorm3.2-package/src/prefix.c rename to distorm/src/prefix.c index 53f09b6..21a67f7 100644 --- a/distorm3.2-package/src/prefix.c +++ b/distorm/src/prefix.c @@ -4,20 +4,8 @@ prefix.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ diff --git a/distorm3.2-package/src/prefix.h b/distorm/src/prefix.h similarity index 77% rename from distorm3.2-package/src/prefix.h rename to distorm/src/prefix.h index 673aa50..f1f53c4 100644 --- a/distorm3.2-package/src/prefix.h +++ b/distorm/src/prefix.h @@ -4,20 +4,8 @@ prefix.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ diff --git a/distorm3.2-package/src/textdefs.c b/distorm/src/textdefs.c similarity index 90% rename from distorm3.2-package/src/textdefs.c rename to distorm/src/textdefs.c index eec26f1..d8cd75a 100644 --- a/distorm3.2-package/src/textdefs.c +++ b/distorm/src/textdefs.c @@ -4,20 +4,8 @@ textdefs.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ diff --git a/distorm3.2-package/src/textdefs.h b/distorm/src/textdefs.h similarity index 64% rename from distorm3.2-package/src/textdefs.h rename to distorm/src/textdefs.h index 275cf88..05cf8d7 100644 --- a/distorm3.2-package/src/textdefs.h +++ b/distorm/src/textdefs.h @@ -4,20 +4,8 @@ textdefs.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ @@ -55,8 +43,6 @@ Naming Convention: * all numbers are in HEX. */ -extern int8_t TextBTable[256][4]; - void _FASTCALL_ str_hex_b(_WString* s, unsigned int x); void _FASTCALL_ str_code_hb(_WString* s, unsigned int x); void _FASTCALL_ str_code_hdw(_WString* s, uint32_t x); diff --git a/distorm3.2-package/src/wstring.c b/distorm/src/wstring.c similarity index 54% rename from distorm3.2-package/src/wstring.c rename to distorm/src/wstring.c index 26b2260..5edce8f 100644 --- a/distorm3.2-package/src/wstring.c +++ b/distorm/src/wstring.c @@ -4,20 +4,8 @@ wstring.c diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ diff --git a/distorm3.2-package/src/wstring.h b/distorm/src/wstring.h similarity index 58% rename from distorm3.2-package/src/wstring.h rename to distorm/src/wstring.h index 6ff9ccf..1dbaa2f 100644 --- a/distorm3.2-package/src/wstring.h +++ b/distorm/src/wstring.h @@ -4,20 +4,8 @@ wstring.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ diff --git a/distorm3.2-package/src/x86defs.h b/distorm/src/x86defs.h similarity index 54% rename from distorm3.2-package/src/x86defs.h rename to distorm/src/x86defs.h index f35ff42..36fea6d 100644 --- a/distorm3.2-package/src/x86defs.h +++ b/distorm/src/x86defs.h @@ -4,29 +4,14 @@ x86defs.h diStorm3 - Powerful disassembler for X86/AMD64 http://ragestorm.net/distorm/ distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see +Copyright (C) 2003-2016 Gil Dabah +This library is licensed under the BSD license. See the file COPYING. */ #ifndef X86DEFS_H #define X86DEFS_H -#include "config.h" -#include "instructions.h" - #define SEG_REGS_MAX (6) #define CREGS_MAX (9) @@ -47,6 +32,12 @@ along with this program. If not, see /* Lea instruction byte code. */ #define INST_LEA_INDEX (0x8d) +/* NOP/XCHG instruction byte code. */ +#define INST_NOP_INDEX (0x90) + +/* ARPL/MOVSXD instruction byte code. */ +#define INST_ARPL_INDEX (0x63) + /* * Minimal MODR/M value of divided instructions. * It's 0xc0, two MSBs set, which indicates a general purpose register is used too. @@ -88,28 +79,4 @@ along with this program. If not, see /* Vector Lengh */ #define PREFIX_EX_L (0x10) -/* - * The inst_lookup will return on of these two instructions according to the specified decoding mode. - * ARPL or MOVSXD on 64 bits is one byte instruction at index 0x63. - */ -#define INST_ARPL_INDEX (0x63) -extern _InstInfo II_arpl; -extern _InstInfo II_movsxd; - -/* - * The NOP instruction can be prefixed by REX in 64bits, therefore we have to decide in runtime whether it's an XCHG or NOP instruction. - * If 0x90 is prefixed by a useable REX it will become XCHG, otherwise it will become a NOP. - * Also note that if it's prefixed by 0xf3, it becomes a Pause. - */ -#define INST_NOP_INDEX (0x90) -extern _InstInfo II_nop; -extern _InstInfo II_pause; - -/* - * Used for letting the extract operand know the type of operands without knowing the - * instruction itself yet, because of the way those instructions work. - * See function instructions.c!inst_lookup_3dnow. - */ -extern _InstInfo II_3dnow; - #endif /* X86DEFS_H */ diff --git a/distorm3.2-package/COPYING b/distorm3.2-package/COPYING deleted file mode 100644 index 94a9ed0..0000000 --- a/distorm3.2-package/COPYING +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/distorm3.2-package/include/mnemonics.h b/distorm3.2-package/include/mnemonics.h deleted file mode 100644 index 652d64b..0000000 --- a/distorm3.2-package/include/mnemonics.h +++ /dev/null @@ -1,312 +0,0 @@ -/* -mnemonics.h - -diStorm3 - Powerful disassembler for X86/AMD64 -http://ragestorm.net/distorm/ -distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - - -#ifndef MNEMONICS_H -#define MNEMONICS_H - -#ifdef __cplusplus - extern "C" { -#endif - -#ifndef DISTORM_LIGHT - -typedef struct WMnemonic { - unsigned char length; - unsigned char p[1]; /* p is a null terminated string, which contains 'length' characters. */ -} _WMnemonic; - -typedef struct WRegister { - unsigned int length; - unsigned char p[6]; /* p is a null terminated string. */ -} _WRegister; - -extern const unsigned char _MNEMONICS[]; -extern const _WRegister _REGISTERS[]; - -#endif /* DISTORM_LIGHT */ - -#ifdef __cplusplus -} /* End Of Extern */ -#endif - -#define GET_REGISTER_NAME(r) (unsigned char*)_REGISTERS[(r)].p -#define GET_MNEMONIC_NAME(m) ((_WMnemonic*)&_MNEMONICS[(m)])->p - -typedef enum { - I_UNDEFINED = 0, I_AAA = 66, I_AAD = 389, I_AAM = 384, I_AAS = 76, I_ADC = 31, I_ADD = 11, I_ADDPD = 3110, - I_ADDPS = 3103, I_ADDSD = 3124, I_ADDSS = 3117, I_ADDSUBPD = 6394, I_ADDSUBPS = 6404, - I_AESDEC = 9209, I_AESDECLAST = 9226, I_AESENC = 9167, I_AESENCLAST = 9184, - I_AESIMC = 9150, I_AESKEYGENASSIST = 9795, I_AND = 41, I_ANDNPD = 3021, I_ANDNPS = 3013, - I_ANDPD = 2990, I_ANDPS = 2983, I_ARPL = 111, I_BLENDPD = 9372, I_BLENDPS = 9353, - I_BLENDVPD = 7619, I_BLENDVPS = 7609, I_BOUND = 104, I_BSF = 4346, I_BSR = 4358, - I_BSWAP = 960, I_BT = 872, I_BTC = 934, I_BTR = 912, I_BTS = 887, I_CALL = 456, - I_CALL_FAR = 260, I_CBW = 228, I_CDQ = 250, I_CDQE = 239, I_CLC = 492, I_CLD = 512, - I_CLFLUSH = 4329, I_CLGI = 1833, I_CLI = 502, I_CLTS = 541, I_CMC = 487, I_CMOVA = 694, - I_CMOVAE = 663, I_CMOVB = 656, I_CMOVBE = 686, I_CMOVG = 754, I_CMOVGE = 738, - I_CMOVL = 731, I_CMOVLE = 746, I_CMOVNO = 648, I_CMOVNP = 723, I_CMOVNS = 708, - I_CMOVNZ = 678, I_CMOVO = 641, I_CMOVP = 716, I_CMOVS = 701, I_CMOVZ = 671, - I_CMP = 71, I_CMPEQPD = 4449, I_CMPEQPS = 4370, I_CMPEQSD = 4607, I_CMPEQSS = 4528, - I_CMPLEPD = 4467, I_CMPLEPS = 4388, I_CMPLESD = 4625, I_CMPLESS = 4546, I_CMPLTPD = 4458, - I_CMPLTPS = 4379, I_CMPLTSD = 4616, I_CMPLTSS = 4537, I_CMPNEQPD = 4488, I_CMPNEQPS = 4409, - I_CMPNEQSD = 4646, I_CMPNEQSS = 4567, I_CMPNLEPD = 4508, I_CMPNLEPS = 4429, - I_CMPNLESD = 4666, I_CMPNLESS = 4587, I_CMPNLTPD = 4498, I_CMPNLTPS = 4419, - I_CMPNLTSD = 4656, I_CMPNLTSS = 4577, I_CMPORDPD = 4518, I_CMPORDPS = 4439, - I_CMPORDSD = 4676, I_CMPORDSS = 4597, I_CMPS = 301, I_CMPUNORDPD = 4476, I_CMPUNORDPS = 4397, - I_CMPUNORDSD = 4634, I_CMPUNORDSS = 4555, I_CMPXCHG = 898, I_CMPXCHG16B = 6373, - I_CMPXCHG8B = 6362, I_COMISD = 2779, I_COMISS = 2771, I_CPUID = 865, I_CQO = 255, - I_CRC32 = 9258, I_CVTDQ2PD = 6787, I_CVTDQ2PS = 3307, I_CVTPD2DQ = 6797, I_CVTPD2PI = 2681, - I_CVTPD2PS = 3233, I_CVTPH2PS = 4161, I_CVTPI2PD = 2495, I_CVTPI2PS = 2485, - I_CVTPS2DQ = 3317, I_CVTPS2PD = 3223, I_CVTPS2PH = 4171, I_CVTPS2PI = 2671, - I_CVTSD2SI = 2701, I_CVTSD2SS = 3253, I_CVTSI2SD = 2515, I_CVTSI2SS = 2505, - I_CVTSS2SD = 3243, I_CVTSS2SI = 2691, I_CVTTPD2DQ = 6776, I_CVTTPD2PI = 2614, - I_CVTTPS2DQ = 3327, I_CVTTPS2PI = 2603, I_CVTTSD2SI = 2636, I_CVTTSS2SI = 2625, - I_CWD = 245, I_CWDE = 233, I_DAA = 46, I_DAS = 56, I_DEC = 86, I_DIV = 1630, - I_DIVPD = 3499, I_DIVPS = 3492, I_DIVSD = 3513, I_DIVSS = 3506, I_DPPD = 9615, - I_DPPS = 9602, I_EMMS = 4100, I_ENTER = 340, I_EXTRACTPS = 9480, I_EXTRQ = 4136, - I_F2XM1 = 1176, I_FABS = 1107, I_FADD = 1007, I_FADDP = 1533, I_FBLD = 1585, - I_FBSTP = 1591, I_FCHS = 1101, I_FCLEX = 7289, I_FCMOVB = 1360, I_FCMOVBE = 1376, - I_FCMOVE = 1368, I_FCMOVNB = 1429, I_FCMOVNBE = 1447, I_FCMOVNE = 1438, I_FCMOVNU = 1457, - I_FCMOVU = 1385, I_FCOM = 1019, I_FCOMI = 1496, I_FCOMIP = 1607, I_FCOMP = 1025, - I_FCOMPP = 1547, I_FCOS = 1295, I_FDECSTP = 1222, I_FDIV = 1045, I_FDIVP = 1578, - I_FDIVR = 1051, I_FDIVRP = 1570, I_FEDISI = 1472, I_FEMMS = 574, I_FENI = 1466, - I_FFREE = 1511, I_FIADD = 1301, I_FICOM = 1315, I_FICOMP = 1322, I_FIDIV = 1345, - I_FIDIVR = 1352, I_FILD = 1402, I_FIMUL = 1308, I_FINCSTP = 1231, I_FINIT = 7304, - I_FIST = 1416, I_FISTP = 1422, I_FISTTP = 1408, I_FISUB = 1330, I_FISUBR = 1337, - I_FLD = 1058, I_FLD1 = 1125, I_FLDCW = 1082, I_FLDENV = 1074, I_FLDL2E = 1139, - I_FLDL2T = 1131, I_FLDLG2 = 1154, I_FLDLN2 = 1162, I_FLDPI = 1147, I_FLDZ = 1170, - I_FMUL = 1013, I_FMULP = 1540, I_FNCLEX = 7281, I_FNINIT = 7296, I_FNOP = 1095, - I_FNSAVE = 7311, I_FNSTCW = 7266, I_FNSTENV = 7249, I_FNSTSW = 7326, I_FPATAN = 1197, - I_FPREM = 1240, I_FPREM1 = 1214, I_FPTAN = 1190, I_FRNDINT = 1272, I_FRSTOR = 1503, - I_FSAVE = 7319, I_FSCALE = 1281, I_FSETPM = 1480, I_FSIN = 1289, I_FSINCOS = 1263, - I_FSQRT = 1256, I_FST = 1063, I_FSTCW = 7274, I_FSTENV = 7258, I_FSTP = 1068, - I_FSTSW = 7334, I_FSUB = 1032, I_FSUBP = 1563, I_FSUBR = 1038, I_FSUBRP = 1555, - I_FTST = 1113, I_FUCOM = 1518, I_FUCOMI = 1488, I_FUCOMIP = 1598, I_FUCOMP = 1525, - I_FUCOMPP = 1393, I_FXAM = 1119, I_FXCH = 1089, I_FXRSTOR = 9892, I_FXRSTOR64 = 9901, - I_FXSAVE = 9864, I_FXSAVE64 = 9872, I_FXTRACT = 1205, I_FYL2X = 1183, I_FYL2XP1 = 1247, - I_GETSEC = 633, I_HADDPD = 4181, I_HADDPS = 4189, I_HLT = 482, I_HSUBPD = 4215, - I_HSUBPS = 4223, I_IDIV = 1635, I_IMUL = 117, I_IN = 447, I_INC = 81, I_INS = 123, - I_INSERTPS = 9547, I_INSERTQ = 4143, I_INT = 367, I_INT_3 = 360, I_INT1 = 476, - I_INTO = 372, I_INVD = 555, I_INVEPT = 8284, I_INVLPG = 1711, I_INVLPGA = 1847, - I_INVPCID = 8301, I_INVVPID = 8292, I_IRET = 378, I_JA = 166, I_JAE = 147, - I_JB = 143, I_JBE = 161, I_JCXZ = 427, I_JECXZ = 433, I_JG = 202, I_JGE = 192, - I_JL = 188, I_JLE = 197, I_JMP = 462, I_JMP_FAR = 467, I_JNO = 138, I_JNP = 183, - I_JNS = 174, I_JNZ = 156, I_JO = 134, I_JP = 179, I_JRCXZ = 440, I_JS = 170, - I_JZ = 152, I_LAHF = 289, I_LAR = 522, I_LDDQU = 6994, I_LDMXCSR = 9922, I_LDS = 335, - I_LEA = 223, I_LEAVE = 347, I_LES = 330, I_LFENCE = 4265, I_LFS = 917, I_LGDT = 1687, - I_LGS = 922, I_LIDT = 1693, I_LLDT = 1652, I_LMSW = 1705, I_LODS = 313, I_LOOP = 421, - I_LOOPNZ = 406, I_LOOPZ = 414, I_LSL = 527, I_LSS = 907, I_LTR = 1658, I_LZCNT = 4363, - I_MASKMOVDQU = 7119, I_MASKMOVQ = 7109, I_MAXPD = 3559, I_MAXPS = 3552, I_MAXSD = 3573, - I_MAXSS = 3566, I_MFENCE = 4291, I_MINPD = 3439, I_MINPS = 3432, I_MINSD = 3453, - I_MINSS = 3446, I_MONITOR = 1755, I_MOV = 218, I_MOVAPD = 2459, I_MOVAPS = 2451, - I_MOVBE = 9251, I_MOVD = 3920, I_MOVDDUP = 2186, I_MOVDQ2Q = 6522, I_MOVDQA = 3946, - I_MOVDQU = 3954, I_MOVHLPS = 2151, I_MOVHPD = 2345, I_MOVHPS = 2337, I_MOVLHPS = 2328, - I_MOVLPD = 2168, I_MOVLPS = 2160, I_MOVMSKPD = 2815, I_MOVMSKPS = 2805, I_MOVNTDQ = 6849, - I_MOVNTDQA = 7895, I_MOVNTI = 952, I_MOVNTPD = 2556, I_MOVNTPS = 2547, I_MOVNTQ = 6841, - I_MOVNTSD = 2574, I_MOVNTSS = 2565, I_MOVQ = 3926, I_MOVQ2DQ = 6513, I_MOVS = 295, - I_MOVSD = 2110, I_MOVSHDUP = 2353, I_MOVSLDUP = 2176, I_MOVSS = 2103, I_MOVSX = 939, - I_MOVSXD = 10019, I_MOVUPD = 2095, I_MOVUPS = 2087, I_MOVZX = 927, I_MPSADBW = 9628, - I_MUL = 1625, I_MULPD = 3170, I_MULPS = 3163, I_MULSD = 3184, I_MULSS = 3177, - I_MWAIT = 1764, I_NEG = 1620, I_NOP = 581, I_NOT = 1615, I_OR = 27, I_ORPD = 3053, - I_ORPS = 3047, I_OUT = 451, I_OUTS = 128, I_PABSB = 7688, I_PABSD = 7718, I_PABSW = 7703, - I_PACKSSDW = 3849, I_PACKSSWB = 3681, I_PACKUSDW = 7916, I_PACKUSWB = 3759, - I_PADDB = 7204, I_PADDD = 7234, I_PADDQ = 6481, I_PADDSB = 6930, I_PADDSW = 6947, - I_PADDUSB = 6620, I_PADDUSW = 6639, I_PADDW = 7219, I_PALIGNR = 9410, I_PAND = 6607, - I_PANDN = 6665, I_PAUSE = 10027, I_PAVGB = 6680, I_PAVGUSB = 2078, I_PAVGW = 6725, - I_PBLENDVB = 7599, I_PBLENDW = 9391, I_PCLMULQDQ = 9647, I_PCMPEQB = 4043, - I_PCMPEQD = 4081, I_PCMPEQQ = 7876, I_PCMPEQW = 4062, I_PCMPESTRI = 9726, - I_PCMPESTRM = 9703, I_PCMPGTB = 3702, I_PCMPGTD = 3740, I_PCMPGTQ = 8087, - I_PCMPGTW = 3721, I_PCMPISTRI = 9772, I_PCMPISTRM = 9749, I_PEXTRB = 9429, - I_PEXTRD = 9446, I_PEXTRQ = 9454, I_PEXTRW = 6311, I_PF2ID = 1914, I_PF2IW = 1907, - I_PFACC = 2028, I_PFADD = 1977, I_PFCMPEQ = 2035, I_PFCMPGE = 1938, I_PFCMPGT = 1984, - I_PFMAX = 1993, I_PFMIN = 1947, I_PFMUL = 2044, I_PFNACC = 1921, I_PFPNACC = 1929, - I_PFRCP = 1954, I_PFRCPIT1 = 2000, I_PFRCPIT2 = 2051, I_PFRSQIT1 = 2010, I_PFRSQRT = 1961, - I_PFSUB = 1970, I_PFSUBR = 2020, I_PHADDD = 7375, I_PHADDSW = 7392, I_PHADDW = 7358, - I_PHMINPOSUW = 8259, I_PHSUBD = 7451, I_PHSUBSW = 7468, I_PHSUBW = 7434, I_PI2FD = 1900, - I_PI2FW = 1893, I_PINSRB = 9530, I_PINSRD = 9568, I_PINSRQ = 9576, I_PINSRW = 6294, - I_PMADDUBSW = 7411, I_PMADDWD = 7073, I_PMAXSB = 8174, I_PMAXSD = 8191, I_PMAXSW = 6964, - I_PMAXUB = 6648, I_PMAXUD = 8225, I_PMAXUW = 8208, I_PMINSB = 8106, I_PMINSD = 8123, - I_PMINSW = 6902, I_PMINUB = 6590, I_PMINUD = 8157, I_PMINUW = 8140, I_PMOVMSKB = 6531, - I_PMOVSXBD = 7754, I_PMOVSXBQ = 7775, I_PMOVSXBW = 7733, I_PMOVSXDQ = 7838, - I_PMOVSXWD = 7796, I_PMOVSXWQ = 7817, I_PMOVZXBD = 7982, I_PMOVZXBQ = 8003, - I_PMOVZXBW = 7961, I_PMOVZXDQ = 8066, I_PMOVZXWD = 8024, I_PMOVZXWQ = 8045, - I_PMULDQ = 7859, I_PMULHRSW = 7538, I_PMULHRW = 2061, I_PMULHUW = 6740, I_PMULHW = 6759, - I_PMULLD = 8242, I_PMULLW = 6496, I_PMULUDQ = 7054, I_POP = 22, I_POPA = 98, - I_POPCNT = 4338, I_POPF = 277, I_POR = 6919, I_PREFETCH = 1872, I_PREFETCHNTA = 2402, - I_PREFETCHT0 = 2415, I_PREFETCHT1 = 2427, I_PREFETCHT2 = 2439, I_PREFETCHW = 1882, - I_PSADBW = 7092, I_PSHUFB = 7341, I_PSHUFD = 3988, I_PSHUFHW = 3996, I_PSHUFLW = 4005, - I_PSHUFW = 3980, I_PSIGNB = 7487, I_PSIGND = 7521, I_PSIGNW = 7504, I_PSLLD = 7024, - I_PSLLDQ = 9847, I_PSLLQ = 7039, I_PSLLW = 7009, I_PSRAD = 6710, I_PSRAW = 6695, - I_PSRLD = 6451, I_PSRLDQ = 9830, I_PSRLQ = 6466, I_PSRLW = 6436, I_PSUBB = 7144, - I_PSUBD = 7174, I_PSUBQ = 7189, I_PSUBSB = 6868, I_PSUBSW = 6885, I_PSUBUSB = 6552, - I_PSUBUSW = 6571, I_PSUBW = 7159, I_PSWAPD = 2070, I_PTEST = 7629, I_PUNPCKHBW = 3780, - I_PUNPCKHDQ = 3826, I_PUNPCKHQDQ = 3895, I_PUNPCKHWD = 3803, I_PUNPCKLBW = 3612, - I_PUNPCKLDQ = 3658, I_PUNPCKLQDQ = 3870, I_PUNPCKLWD = 3635, I_PUSH = 16, - I_PUSHA = 91, I_PUSHF = 270, I_PXOR = 6981, I_RCL = 977, I_RCPPS = 2953, I_RCPSS = 2960, - I_RCR = 982, I_RDFSBASE = 9882, I_RDGSBASE = 9912, I_RDMSR = 600, I_RDPMC = 607, - I_RDRAND = 9980, I_RDTSC = 593, I_RDTSCP = 1864, I_RET = 325, I_RETF = 354, - I_ROL = 967, I_ROR = 972, I_ROUNDPD = 9296, I_ROUNDPS = 9277, I_ROUNDSD = 9334, - I_ROUNDSS = 9315, I_RSM = 882, I_RSQRTPS = 2915, I_RSQRTSS = 2924, I_SAHF = 283, - I_SAL = 997, I_SALC = 394, I_SAR = 1002, I_SBB = 36, I_SCAS = 319, I_SETA = 807, - I_SETAE = 780, I_SETB = 774, I_SETBE = 800, I_SETG = 859, I_SETGE = 845, I_SETL = 839, - I_SETLE = 852, I_SETNO = 767, I_SETNP = 832, I_SETNS = 819, I_SETNZ = 793, - I_SETO = 761, I_SETP = 826, I_SETS = 813, I_SETZ = 787, I_SFENCE = 4321, I_SGDT = 1675, - I_SHL = 987, I_SHLD = 876, I_SHR = 992, I_SHRD = 892, I_SHUFPD = 6336, I_SHUFPS = 6328, - I_SIDT = 1681, I_SKINIT = 1839, I_SLDT = 1641, I_SMSW = 1699, I_SQRTPD = 2855, - I_SQRTPS = 2847, I_SQRTSD = 2871, I_SQRTSS = 2863, I_STC = 497, I_STD = 517, - I_STGI = 1827, I_STI = 507, I_STMXCSR = 9951, I_STOS = 307, I_STR = 1647, I_SUB = 51, - I_SUBPD = 3379, I_SUBPS = 3372, I_SUBSD = 3393, I_SUBSS = 3386, I_SWAPGS = 1856, - I_SYSCALL = 532, I_SYSENTER = 614, I_SYSEXIT = 624, I_SYSRET = 547, I_TEST = 206, - I_TZCNT = 4351, I_UCOMISD = 2742, I_UCOMISS = 2733, I_UD2 = 569, I_UNPCKHPD = 2296, - I_UNPCKHPS = 2286, I_UNPCKLPD = 2254, I_UNPCKLPS = 2244, I_VADDPD = 3139, - I_VADDPS = 3131, I_VADDSD = 3155, I_VADDSS = 3147, I_VADDSUBPD = 6414, I_VADDSUBPS = 6425, - I_VAESDEC = 9217, I_VAESDECLAST = 9238, I_VAESENC = 9175, I_VAESENCLAST = 9196, - I_VAESIMC = 9158, I_VAESKEYGENASSIST = 9812, I_VANDNPD = 3038, I_VANDNPS = 3029, - I_VANDPD = 3005, I_VANDPS = 2997, I_VBLENDPD = 9381, I_VBLENDPS = 9362, I_VBLENDVPD = 9681, - I_VBLENDVPS = 9670, I_VBROADCASTF128 = 7672, I_VBROADCASTSD = 7658, I_VBROADCASTSS = 7644, - I_VCMPEQPD = 5088, I_VCMPEQPS = 4686, I_VCMPEQSD = 5892, I_VCMPEQSS = 5490, - I_VCMPEQ_OSPD = 5269, I_VCMPEQ_OSPS = 4867, I_VCMPEQ_OSSD = 6073, I_VCMPEQ_OSSS = 5671, - I_VCMPEQ_UQPD = 5175, I_VCMPEQ_UQPS = 4773, I_VCMPEQ_UQSD = 5979, I_VCMPEQ_UQSS = 5577, - I_VCMPEQ_USPD = 5378, I_VCMPEQ_USPS = 4976, I_VCMPEQ_USSD = 6182, I_VCMPEQ_USSS = 5780, - I_VCMPFALSEPD = 5210, I_VCMPFALSEPS = 4808, I_VCMPFALSESD = 6014, I_VCMPFALSESS = 5612, - I_VCMPFALSE_OSPD = 5419, I_VCMPFALSE_OSPS = 5017, I_VCMPFALSE_OSSD = 6223, - I_VCMPFALSE_OSSS = 5821, I_VCMPGEPD = 5237, I_VCMPGEPS = 4835, I_VCMPGESD = 6041, - I_VCMPGESS = 5639, I_VCMPGE_OQPD = 5449, I_VCMPGE_OQPS = 5047, I_VCMPGE_OQSD = 6253, - I_VCMPGE_OQSS = 5851, I_VCMPGTPD = 5247, I_VCMPGTPS = 4845, I_VCMPGTSD = 6051, - I_VCMPGTSS = 5649, I_VCMPGT_OQPD = 5462, I_VCMPGT_OQPS = 5060, I_VCMPGT_OQSD = 6266, - I_VCMPGT_OQSS = 5864, I_VCMPLEPD = 5108, I_VCMPLEPS = 4706, I_VCMPLESD = 5912, - I_VCMPLESS = 5510, I_VCMPLE_OQPD = 5295, I_VCMPLE_OQPS = 4893, I_VCMPLE_OQSD = 6099, - I_VCMPLE_OQSS = 5697, I_VCMPLTPD = 5098, I_VCMPLTPS = 4696, I_VCMPLTSD = 5902, - I_VCMPLTSS = 5500, I_VCMPLT_OQPD = 5282, I_VCMPLT_OQPS = 4880, I_VCMPLT_OQSD = 6086, - I_VCMPLT_OQSS = 5684, I_VCMPNEQPD = 5131, I_VCMPNEQPS = 4729, I_VCMPNEQSD = 5935, - I_VCMPNEQSS = 5533, I_VCMPNEQ_OQPD = 5223, I_VCMPNEQ_OQPS = 4821, I_VCMPNEQ_OQSD = 6027, - I_VCMPNEQ_OQSS = 5625, I_VCMPNEQ_OSPD = 5435, I_VCMPNEQ_OSPS = 5033, I_VCMPNEQ_OSSD = 6239, - I_VCMPNEQ_OSSS = 5837, I_VCMPNEQ_USPD = 5323, I_VCMPNEQ_USPS = 4921, I_VCMPNEQ_USSD = 6127, - I_VCMPNEQ_USSS = 5725, I_VCMPNGEPD = 5188, I_VCMPNGEPS = 4786, I_VCMPNGESD = 5992, - I_VCMPNGESS = 5590, I_VCMPNGE_UQPD = 5391, I_VCMPNGE_UQPS = 4989, I_VCMPNGE_UQSD = 6195, - I_VCMPNGE_UQSS = 5793, I_VCMPNGTPD = 5199, I_VCMPNGTPS = 4797, I_VCMPNGTSD = 6003, - I_VCMPNGTSS = 5601, I_VCMPNGT_UQPD = 5405, I_VCMPNGT_UQPS = 5003, I_VCMPNGT_UQSD = 6209, - I_VCMPNGT_UQSS = 5807, I_VCMPNLEPD = 5153, I_VCMPNLEPS = 4751, I_VCMPNLESD = 5957, - I_VCMPNLESS = 5555, I_VCMPNLE_UQPD = 5351, I_VCMPNLE_UQPS = 4949, I_VCMPNLE_UQSD = 6155, - I_VCMPNLE_UQSS = 5753, I_VCMPNLTPD = 5142, I_VCMPNLTPS = 4740, I_VCMPNLTSD = 5946, - I_VCMPNLTSS = 5544, I_VCMPNLT_UQPD = 5337, I_VCMPNLT_UQPS = 4935, I_VCMPNLT_UQSD = 6141, - I_VCMPNLT_UQSS = 5739, I_VCMPORDPD = 5164, I_VCMPORDPS = 4762, I_VCMPORDSD = 5968, - I_VCMPORDSS = 5566, I_VCMPORD_SPD = 5365, I_VCMPORD_SPS = 4963, I_VCMPORD_SSD = 6169, - I_VCMPORD_SSS = 5767, I_VCMPTRUEPD = 5257, I_VCMPTRUEPS = 4855, I_VCMPTRUESD = 6061, - I_VCMPTRUESS = 5659, I_VCMPTRUE_USPD = 5475, I_VCMPTRUE_USPS = 5073, I_VCMPTRUE_USSD = 6279, - I_VCMPTRUE_USSS = 5877, I_VCMPUNORDPD = 5118, I_VCMPUNORDPS = 4716, I_VCMPUNORDSD = 5922, - I_VCMPUNORDSS = 5520, I_VCMPUNORD_SPD = 5308, I_VCMPUNORD_SPS = 4906, I_VCMPUNORD_SSD = 6112, - I_VCMPUNORD_SSS = 5710, I_VCOMISD = 2796, I_VCOMISS = 2787, I_VCVTDQ2PD = 6819, - I_VCVTDQ2PS = 3338, I_VCVTPD2DQ = 6830, I_VCVTPD2PS = 3274, I_VCVTPS2DQ = 3349, - I_VCVTPS2PD = 3263, I_VCVTSD2SI = 2722, I_VCVTSD2SS = 3296, I_VCVTSI2SD = 2536, - I_VCVTSI2SS = 2525, I_VCVTSS2SD = 3285, I_VCVTSS2SI = 2711, I_VCVTTPD2DQ = 6807, - I_VCVTTPS2DQ = 3360, I_VCVTTSD2SI = 2659, I_VCVTTSS2SI = 2647, I_VDIVPD = 3528, - I_VDIVPS = 3520, I_VDIVSD = 3544, I_VDIVSS = 3536, I_VDPPD = 9621, I_VDPPS = 9608, - I_VERR = 1663, I_VERW = 1669, I_VEXTRACTF128 = 9516, I_VEXTRACTPS = 9491, - I_VFMADD132PD = 8387, I_VFMADD132PS = 8374, I_VFMADD132SD = 8413, I_VFMADD132SS = 8400, - I_VFMADD213PD = 8667, I_VFMADD213PS = 8654, I_VFMADD213SD = 8693, I_VFMADD213SS = 8680, - I_VFMADD231PD = 8947, I_VFMADD231PS = 8934, I_VFMADD231SD = 8973, I_VFMADD231SS = 8960, - I_VFMADDSUB132PD = 8326, I_VFMADDSUB132PS = 8310, I_VFMADDSUB213PD = 8606, - I_VFMADDSUB213PS = 8590, I_VFMADDSUB231PD = 8886, I_VFMADDSUB231PS = 8870, - I_VFMSUB132PD = 8439, I_VFMSUB132PS = 8426, I_VFMSUB132SD = 8465, I_VFMSUB132SS = 8452, - I_VFMSUB213PD = 8719, I_VFMSUB213PS = 8706, I_VFMSUB213SD = 8745, I_VFMSUB213SS = 8732, - I_VFMSUB231PD = 8999, I_VFMSUB231PS = 8986, I_VFMSUB231SD = 9025, I_VFMSUB231SS = 9012, - I_VFMSUBADD132PD = 8358, I_VFMSUBADD132PS = 8342, I_VFMSUBADD213PD = 8638, - I_VFMSUBADD213PS = 8622, I_VFMSUBADD231PD = 8918, I_VFMSUBADD231PS = 8902, - I_VFNMADD132PD = 8492, I_VFNMADD132PS = 8478, I_VFNMADD132SD = 8520, I_VFNMADD132SS = 8506, - I_VFNMADD213PD = 8772, I_VFNMADD213PS = 8758, I_VFNMADD213SD = 8800, I_VFNMADD213SS = 8786, - I_VFNMADD231PD = 9052, I_VFNMADD231PS = 9038, I_VFNMADD231SD = 9080, I_VFNMADD231SS = 9066, - I_VFNMSUB132PD = 8548, I_VFNMSUB132PS = 8534, I_VFNMSUB132SD = 8576, I_VFNMSUB132SS = 8562, - I_VFNMSUB213PD = 8828, I_VFNMSUB213PS = 8814, I_VFNMSUB213SD = 8856, I_VFNMSUB213SS = 8842, - I_VFNMSUB231PD = 9108, I_VFNMSUB231PS = 9094, I_VFNMSUB231SD = 9136, I_VFNMSUB231SS = 9122, - I_VHADDPD = 4197, I_VHADDPS = 4206, I_VHSUBPD = 4231, I_VHSUBPS = 4240, I_VINSERTF128 = 9503, - I_VINSERTPS = 9557, I_VLDDQU = 7001, I_VLDMXCSR = 9941, I_VMASKMOVDQU = 7131, - I_VMASKMOVPD = 7949, I_VMASKMOVPS = 7937, I_VMAXPD = 3588, I_VMAXPS = 3580, - I_VMAXSD = 3604, I_VMAXSS = 3596, I_VMCALL = 1719, I_VMCLEAR = 9997, I_VMFUNC = 1787, - I_VMINPD = 3468, I_VMINPS = 3460, I_VMINSD = 3484, I_VMINSS = 3476, I_VMLAUNCH = 1727, - I_VMLOAD = 1811, I_VMMCALL = 1802, I_VMOVAPD = 2476, I_VMOVAPS = 2467, I_VMOVD = 3932, - I_VMOVDDUP = 2234, I_VMOVDQA = 3962, I_VMOVDQU = 3971, I_VMOVHLPS = 2195, - I_VMOVHPD = 2382, I_VMOVHPS = 2373, I_VMOVLHPS = 2363, I_VMOVLPD = 2214, I_VMOVLPS = 2205, - I_VMOVMSKPD = 2836, I_VMOVMSKPS = 2825, I_VMOVNTDQ = 6858, I_VMOVNTDQA = 7905, - I_VMOVNTPD = 2593, I_VMOVNTPS = 2583, I_VMOVQ = 3939, I_VMOVSD = 2143, I_VMOVSHDUP = 2391, - I_VMOVSLDUP = 2223, I_VMOVSS = 2135, I_VMOVUPD = 2126, I_VMOVUPS = 2117, I_VMPSADBW = 9637, - I_VMPTRLD = 9988, I_VMPTRST = 6385, I_VMREAD = 4128, I_VMRESUME = 1737, I_VMRUN = 1795, - I_VMSAVE = 1819, I_VMULPD = 3199, I_VMULPS = 3191, I_VMULSD = 3215, I_VMULSS = 3207, - I_VMWRITE = 4152, I_VMXOFF = 1747, I_VMXON = 10006, I_VORPD = 3066, I_VORPS = 3059, - I_VPABSB = 7695, I_VPABSD = 7725, I_VPABSW = 7710, I_VPACKSSDW = 3859, I_VPACKSSWB = 3691, - I_VPACKUSDW = 7926, I_VPACKUSWB = 3769, I_VPADDB = 7211, I_VPADDD = 7241, - I_VPADDQ = 6488, I_VPADDSB = 6938, I_VPADDSW = 6955, I_VPADDUSW = 6629, I_VPADDW = 7226, - I_VPALIGNR = 9419, I_VPAND = 6613, I_VPANDN = 6672, I_VPAVGB = 6687, I_VPAVGW = 6732, - I_VPBLENDVB = 9692, I_VPBLENDW = 9400, I_VPCLMULQDQ = 9658, I_VPCMPEQB = 4052, - I_VPCMPEQD = 4090, I_VPCMPEQQ = 7885, I_VPCMPEQW = 4071, I_VPCMPESTRI = 9737, - I_VPCMPESTRM = 9714, I_VPCMPGTB = 3711, I_VPCMPGTD = 3749, I_VPCMPGTQ = 8096, - I_VPCMPGTW = 3730, I_VPCMPISTRI = 9783, I_VPCMPISTRM = 9760, I_VPERM2F128 = 9265, - I_VPERMILPD = 7570, I_VPERMILPS = 7559, I_VPEXTRB = 9437, I_VPEXTRD = 9462, - I_VPEXTRQ = 9471, I_VPEXTRW = 6319, I_VPHADDD = 7383, I_VPHADDSW = 7401, I_VPHADDW = 7366, - I_VPHMINPOSUW = 8271, I_VPHSUBD = 7459, I_VPHSUBSW = 7477, I_VPHSUBW = 7442, - I_VPINSRB = 9538, I_VPINSRD = 9584, I_VPINSRQ = 9593, I_VPINSRW = 6302, I_VPMADDUBSW = 7422, - I_VPMADDWD = 7082, I_VPMAXSB = 8182, I_VPMAXSD = 8199, I_VPMAXSW = 6972, I_VPMAXUB = 6656, - I_VPMAXUD = 8233, I_VPMAXUW = 8216, I_VPMINSB = 8114, I_VPMINSD = 8131, I_VPMINSW = 6910, - I_VPMINUB = 6598, I_VPMINUD = 8165, I_VPMINUW = 8148, I_VPMOVMSKB = 6541, - I_VPMOVSXBD = 7764, I_VPMOVSXBQ = 7785, I_VPMOVSXBW = 7743, I_VPMOVSXDQ = 7848, - I_VPMOVSXWD = 7806, I_VPMOVSXWQ = 7827, I_VPMOVZXBD = 7992, I_VPMOVZXBQ = 8013, - I_VPMOVZXBW = 7971, I_VPMOVZXDQ = 8076, I_VPMOVZXWD = 8034, I_VPMOVZXWQ = 8055, - I_VPMULDQ = 7867, I_VPMULHRSW = 7548, I_VPMULHUW = 6749, I_VPMULHW = 6767, - I_VPMULLD = 8250, I_VPMULLW = 6504, I_VPMULUDQ = 7063, I_VPOR = 6924, I_VPSADBW = 7100, - I_VPSHUFB = 7349, I_VPSHUFD = 4014, I_VPSHUFHW = 4023, I_VPSHUFLW = 4033, - I_VPSIGNB = 7495, I_VPSIGND = 7529, I_VPSIGNW = 7512, I_VPSLLD = 7031, I_VPSLLDQ = 9855, - I_VPSLLQ = 7046, I_VPSLLW = 7016, I_VPSRAD = 6717, I_VPSRAW = 6702, I_VPSRLD = 6458, - I_VPSRLDQ = 9838, I_VPSRLQ = 6473, I_VPSRLW = 6443, I_VPSUBB = 7151, I_VPSUBD = 7181, - I_VPSUBQ = 7196, I_VPSUBSB = 6876, I_VPSUBSW = 6893, I_VPSUBUSB = 6561, I_VPSUBUSW = 6580, - I_VPSUBW = 7166, I_VPTEST = 7636, I_VPUNPCKHBW = 3791, I_VPUNPCKHDQ = 3837, - I_VPUNPCKHQDQ = 3907, I_VPUNPCKHWD = 3814, I_VPUNPCKLBW = 3623, I_VPUNPCKLDQ = 3669, - I_VPUNPCKLQDQ = 3882, I_VPUNPCKLWD = 3646, I_VPXOR = 6987, I_VRCPPS = 2967, - I_VRCPSS = 2975, I_VROUNDPD = 9305, I_VROUNDPS = 9286, I_VROUNDSD = 9343, - I_VROUNDSS = 9324, I_VRSQRTPS = 2933, I_VRSQRTSS = 2943, I_VSHUFPD = 6353, - I_VSHUFPS = 6344, I_VSQRTPD = 2888, I_VSQRTPS = 2879, I_VSQRTSD = 2906, I_VSQRTSS = 2897, - I_VSTMXCSR = 9970, I_VSUBPD = 3408, I_VSUBPS = 3400, I_VSUBSD = 3424, I_VSUBSS = 3416, - I_VTESTPD = 7590, I_VTESTPS = 7581, I_VUCOMISD = 2761, I_VUCOMISS = 2751, - I_VUNPCKHPD = 2317, I_VUNPCKHPS = 2306, I_VUNPCKLPD = 2275, I_VUNPCKLPS = 2264, - I_VXORPD = 3095, I_VXORPS = 3087, I_VZEROALL = 4118, I_VZEROUPPER = 4106, - I_WAIT = 10013, I_WBINVD = 561, I_WRFSBASE = 9931, I_WRGSBASE = 9960, I_WRMSR = 586, - I_XADD = 946, I_XCHG = 212, I_XGETBV = 1771, I_XLAT = 400, I_XOR = 61, I_XORPD = 3080, - I_XORPS = 3073, I_XRSTOR = 4273, I_XRSTOR64 = 4281, I_XSAVE = 4249, I_XSAVE64 = 4256, - I_XSAVEOPT = 4299, I_XSAVEOPT64 = 4309, I_XSETBV = 1779 -} _InstructionType; - -typedef enum { - R_RAX, R_RCX, R_RDX, R_RBX, R_RSP, R_RBP, R_RSI, R_RDI, R_R8, R_R9, R_R10, R_R11, R_R12, R_R13, R_R14, R_R15, - R_EAX, R_ECX, R_EDX, R_EBX, R_ESP, R_EBP, R_ESI, R_EDI, R_R8D, R_R9D, R_R10D, R_R11D, R_R12D, R_R13D, R_R14D, R_R15D, - R_AX, R_CX, R_DX, R_BX, R_SP, R_BP, R_SI, R_DI, R_R8W, R_R9W, R_R10W, R_R11W, R_R12W, R_R13W, R_R14W, R_R15W, - R_AL, R_CL, R_DL, R_BL, R_AH, R_CH, R_DH, R_BH, R_R8B, R_R9B, R_R10B, R_R11B, R_R12B, R_R13B, R_R14B, R_R15B, - R_SPL, R_BPL, R_SIL, R_DIL, - R_ES, R_CS, R_SS, R_DS, R_FS, R_GS, - R_RIP, - R_ST0, R_ST1, R_ST2, R_ST3, R_ST4, R_ST5, R_ST6, R_ST7, - R_MM0, R_MM1, R_MM2, R_MM3, R_MM4, R_MM5, R_MM6, R_MM7, - R_XMM0, R_XMM1, R_XMM2, R_XMM3, R_XMM4, R_XMM5, R_XMM6, R_XMM7, R_XMM8, R_XMM9, R_XMM10, R_XMM11, R_XMM12, R_XMM13, R_XMM14, R_XMM15, - R_YMM0, R_YMM1, R_YMM2, R_YMM3, R_YMM4, R_YMM5, R_YMM6, R_YMM7, R_YMM8, R_YMM9, R_YMM10, R_YMM11, R_YMM12, R_YMM13, R_YMM14, R_YMM15, - R_CR0, R_UNUSED0, R_CR2, R_CR3, R_CR4, R_UNUSED1, R_UNUSED2, R_UNUSED3, R_CR8, - R_DR0, R_DR1, R_DR2, R_DR3, R_UNUSED4, R_UNUSED5, R_DR6, R_DR7 -} _RegisterType; - -#endif /* MNEMONICS_H */ diff --git a/distorm3.2-package/src/insts.c b/distorm3.2-package/src/insts.c deleted file mode 100644 index 4c9179b..0000000 --- a/distorm3.2-package/src/insts.c +++ /dev/null @@ -1,7343 +0,0 @@ -/* -insts.c - -diStorm3 - Powerful disassembler for X86/AMD64 -http://ragestorm.net/distorm/ -distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - - -#include "config.h" -#include "insts.h" -#include "instructions.h" - - -/* - * GENERATED BY disOps at Mon May 07 05:39:59 2012 - */ - -/* See x86defs.c if you get an error here. */ -_iflags FlagsTable[97 + 5] = { -INST_MODRM_REQUIRED, -INST_MODRM_REQUIRED | INST_PRE_REX | INST_64BITS, -INST_FLAGS_NONE, -INST_FLAGS_NONE, -INST_32BITS | INST_MODRM_REQUIRED | INST_3DNOW_FETCH, -0x80000011, -0x80000000, -0x800400, -0x80800400, -0x800080, -0x800100, -0x80800100, -0x800200, -0x80800200, -0x800000, -0x1, -0x0, -0x80800000, -0x1000000, -0x81000000, -0x808000, -0x800001, -0x1000001, -0x80020001, -0x1002000, -0x60, -0x64, -0x80000001, -0x4010000, -0x1008000, -0x80000060, -0x83000064, -0x3000064, -0x83000000, -0x3008000, -0x200, -0xc000, -0x4014000, -0x8, -0x81000009, -0x9, -0x80000009, -0x1000808, -0x81000808, -0x80020009, -0x1001008, -0x81001008, -0x80000019, -0x3000009, -0x83000009, -0x83000008, -0xc0000011, -0x40000001, -0xc0800011, -0x40800001, -0xc0000019, -0xc1000001, -0xc0000001, -0x40000000, -0x40000008, -0x40000009, -0x41000001, -0x43000001, -0xc0000003, -0x40000003, -0x48000000, -0x200009, -0x20000009, -0x60020009, -0x60000009, -0x80090009, -0x200b0009, -0x20020009, -0x80100009, -0x21100009, -0x87000009, -0x20009, -0x20000008, -0x1000009, -0x10020009, -0x160009, -0x100009, -0x47000009, -0x47090009, -0x40090009, -0x80002009, -0xc0000009, -0x2001, -0x80002001, -0x410009, -0x20420009, -0x20060009, -0x120009, -0x21020009, -0xc7000019, -0x20100009, -0x40002009, -0x40002008, -0x4020009, -0x40100009, -0x60120009, -0x41000009 -}; - -_InstNode Table_0F = 256; -_InstNode Table_0F_0F = 1312; -_InstNode Table_0F_38 = 1768; -_InstNode Table_0F_3A = 2024; - -_InstInfo InstInfos[] = { - /*II_00*/ {0x5, 9, 15, 8, 11}, - /*II_01*/ {0x5, 11, 17, 8, 11}, - /*II_02*/ {0x5, 15, 9, 8, 11}, - /*II_03*/ {0x5, 17, 11, 8, 11}, - /*II_04*/ {0x6, 1, 33, 8, 11}, - /*II_05*/ {0x6, 3, 35, 8, 11}, - /*II_06*/ {0x7, 0, 32, 8, 16}, - /*II_07*/ {0x8, 0, 32, 8, 22}, - /*II_08*/ {0x5, 9, 15, 8, 27}, - /*II_09*/ {0x5, 11, 17, 8, 27}, - /*II_0A*/ {0x5, 15, 9, 8, 27}, - /*II_0B*/ {0x5, 17, 11, 8, 27}, - /*II_0C*/ {0x6, 1, 33, 8, 27}, - /*II_0D*/ {0x6, 3, 35, 8, 27}, - /*II_0E*/ {0x9, 0, 32, 8, 16}, - /*II_10*/ {0x5, 9, 15, 8, 31}, - /*II_11*/ {0x5, 11, 17, 8, 31}, - /*II_12*/ {0x5, 15, 9, 8, 31}, - /*II_13*/ {0x5, 17, 11, 8, 31}, - /*II_14*/ {0x6, 1, 33, 8, 31}, - /*II_15*/ {0x6, 3, 35, 8, 31}, - /*II_16*/ {0xa, 0, 32, 8, 16}, - /*II_17*/ {0xb, 0, 32, 8, 22}, - /*II_18*/ {0x5, 9, 15, 8, 36}, - /*II_19*/ {0x5, 11, 17, 8, 36}, - /*II_1A*/ {0x5, 15, 9, 8, 36}, - /*II_1B*/ {0x5, 17, 11, 8, 36}, - /*II_1C*/ {0x6, 1, 33, 8, 36}, - /*II_1D*/ {0x6, 3, 35, 8, 36}, - /*II_1E*/ {0xc, 0, 32, 8, 16}, - /*II_1F*/ {0xd, 0, 32, 8, 22}, - /*II_20*/ {0x5, 9, 15, 8, 41}, - /*II_21*/ {0x5, 11, 17, 8, 41}, - /*II_22*/ {0x5, 15, 9, 8, 41}, - /*II_23*/ {0x5, 17, 11, 8, 41}, - /*II_24*/ {0x6, 1, 33, 8, 41}, - /*II_25*/ {0x6, 3, 35, 8, 41}, - /*II_27*/ {0xe, 0, 0, 8, 46}, - /*II_28*/ {0x5, 9, 15, 8, 51}, - /*II_29*/ {0x5, 11, 17, 8, 51}, - /*II_2A*/ {0x5, 15, 9, 8, 51}, - /*II_2B*/ {0x5, 17, 11, 8, 51}, - /*II_2C*/ {0x6, 1, 33, 8, 51}, - /*II_2D*/ {0x6, 3, 35, 8, 51}, - /*II_2F*/ {0xe, 0, 0, 8, 56}, - /*II_30*/ {0x5, 9, 15, 8, 61}, - /*II_31*/ {0x5, 11, 17, 8, 61}, - /*II_32*/ {0x5, 15, 9, 8, 61}, - /*II_33*/ {0x5, 17, 11, 8, 61}, - /*II_34*/ {0x6, 1, 33, 8, 61}, - /*II_35*/ {0x6, 3, 35, 8, 61}, - /*II_37*/ {0xe, 0, 0, 8, 66}, - /*II_38*/ {0xf, 9, 15, 8, 71}, - /*II_39*/ {0xf, 11, 17, 8, 71}, - /*II_3A*/ {0xf, 15, 9, 8, 71}, - /*II_3B*/ {0xf, 17, 11, 8, 71}, - /*II_3C*/ {0x10, 1, 33, 8, 71}, - /*II_3D*/ {0x10, 3, 35, 8, 71}, - /*II_3F*/ {0xe, 0, 0, 8, 76}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_40*/ {0x11, 0, 54, 8, 81}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_48*/ {0x11, 0, 54, 8, 86}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_50*/ {0x12, 0, 54, 8, 16}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_58*/ {0x13, 0, 54, 8, 22}, - /*II_60*/ {0x14, 0, 0, 8, 91}, - /*II_61*/ {0x14, 0, 0, 8, 98}, - /*II_62*/ {0x15, 42, 11, 8, 104}, - /*II_63*/ {0x16, 10, 16, 8, 111}, - /*II_68*/ {0x12, 0, 3, 8, 16}, - /*II_6A*/ {0x18, 0, 5, 8, 16}, - /*II_6C*/ {0x19, 59, 56, 8, 123}, - /*II_6D*/ {0x1a, 59, 56, 8, 123}, - /*II_6E*/ {0x19, 55, 59, 8, 128}, - /*II_6F*/ {0x1a, 55, 59, 8, 128}, - /*II_70*/ {0x12, 0, 40, 13, 134}, - /*II_71*/ {0x12, 0, 40, 13, 138}, - /*II_72*/ {0x12, 0, 40, 13, 143}, - /*II_73*/ {0x12, 0, 40, 13, 147}, - /*II_74*/ {0x12, 0, 40, 13, 152}, - /*II_75*/ {0x12, 0, 40, 13, 156}, - /*II_76*/ {0x12, 0, 40, 13, 161}, - /*II_77*/ {0x12, 0, 40, 13, 166}, - /*II_78*/ {0x12, 0, 40, 13, 170}, - /*II_79*/ {0x12, 0, 40, 13, 174}, - /*II_7A*/ {0x12, 0, 40, 13, 179}, - /*II_7B*/ {0x12, 0, 40, 13, 183}, - /*II_7C*/ {0x12, 0, 40, 13, 188}, - /*II_7D*/ {0x12, 0, 40, 13, 192}, - /*II_7E*/ {0x12, 0, 40, 13, 197}, - /*II_7F*/ {0x12, 0, 40, 13, 202}, - /*II_84*/ {0xf, 9, 15, 8, 206}, - /*II_85*/ {0xf, 11, 17, 8, 206}, - /*II_86*/ {0x5, 9, 15, 8, 212}, - /*II_87*/ {0x5, 11, 17, 8, 212}, - /*II_88*/ {0x1b, 9, 15, 8, 218}, - /*II_89*/ {0x1b, 11, 17, 8, 218}, - /*II_8A*/ {0x1b, 15, 9, 8, 218}, - /*II_8B*/ {0x1b, 17, 11, 8, 218}, - /*II_8C*/ {0x1b, 31, 28, 8, 218}, - /*II_8D*/ {0x1b, 42, 11, 8, 223}, - /*II_8E*/ {0x1b, 28, 31, 8, 218}, - /*II_90*/ {0x6, 35, 54, 8, 212}, - /*II_91*/ {0x6, 35, 54, 8, 212}, - /*II_92*/ {0x6, 35, 54, 8, 212}, - /*II_93*/ {0x6, 35, 54, 8, 212}, - /*II_94*/ {0x6, 35, 54, 8, 212}, - /*II_95*/ {0x6, 35, 54, 8, 212}, - /*II_96*/ {0x6, 35, 54, 8, 212}, - /*II_97*/ {0x6, 35, 54, 8, 212}, - /*II_9A*/ {0xe, 0, 38, 9, 260}, - /*II_9C*/ {0x1d, 0, 0, 8, 270}, - /*II_9D*/ {0x1d, 0, 0, 8, 277}, - /*II_9E*/ {0x10, 0, 0, 8, 283}, - /*II_9F*/ {0x10, 0, 0, 8, 289}, - /*II_A0*/ {0x6, 49, 33, 8, 218}, - /*II_A1*/ {0x6, 50, 35, 8, 218}, - /*II_A2*/ {0x6, 33, 49, 8, 218}, - /*II_A3*/ {0x6, 35, 50, 8, 218}, - /*II_A4*/ {0x1e, 55, 56, 8, 295}, - /*II_A5*/ {0x1f, 55, 56, 8, 295}, - /*II_A6*/ {0x19, 56, 55, 8, 301}, - /*II_A7*/ {0x20, 56, 55, 8, 301}, - /*II_A8*/ {0x10, 1, 33, 8, 206}, - /*II_A9*/ {0x10, 3, 35, 8, 206}, - /*II_AA*/ {0x19, 33, 56, 8, 307}, - /*II_AB*/ {0x20, 35, 56, 8, 307}, - /*II_AC*/ {0x19, 55, 33, 8, 313}, - /*II_AD*/ {0x20, 55, 35, 8, 313}, - /*II_AE*/ {0x19, 33, 56, 8, 319}, - /*II_AF*/ {0x20, 35, 56, 8, 319}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B0*/ {0x6, 1, 53, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_B8*/ {0x21, 3, 54, 8, 218}, - /*II_C2*/ {0x12, 0, 2, 10, 325}, - /*II_C3*/ {0x12, 0, 0, 10, 325}, - /*II_C4*/ {0x15, 37, 11, 8, 330}, - /*II_C5*/ {0x15, 37, 11, 8, 335}, - /*II_C8*/ {0x12, 8, 6, 8, 340}, - /*II_C9*/ {0x12, 0, 0, 8, 347}, - /*II_CA*/ {0x22, 0, 2, 10, 354}, - /*II_CB*/ {0x22, 0, 0, 10, 354}, - /*II_CC*/ {0x10, 0, 0, 14, 360}, - /*II_CD*/ {0x10, 0, 1, 14, 367}, - /*II_CE*/ {0xe, 0, 0, 14, 372}, - /*II_CF*/ {0x22, 0, 0, 10, 378}, - /*II_D4*/ {0xe, 0, 1, 8, 384}, - /*II_D5*/ {0xe, 0, 1, 8, 389}, - /*II_D6*/ {0xe, 0, 0, 8, 394}, - /*II_D7*/ {0x23, 0, 57, 8, 400}, - /*II_E0*/ {0x24, 0, 40, 13, 406}, - /*II_E1*/ {0x24, 0, 40, 13, 414}, - /*II_E2*/ {0x24, 0, 40, 13, 421}, - /*II_E4*/ {0x6, 1, 33, 8, 447}, - /*II_E5*/ {0x6, 1, 36, 8, 447}, - /*II_E6*/ {0x10, 33, 1, 8, 451}, - /*II_E7*/ {0x10, 36, 1, 8, 451}, - /*II_E8*/ {0x12, 0, 41, 9, 456}, - /*II_E9*/ {0x12, 0, 41, 12, 462}, - /*II_EA*/ {0xe, 0, 38, 12, 467}, - /*II_EB*/ {0x12, 0, 40, 12, 462}, - /*II_EC*/ {0x6, 59, 33, 8, 447}, - /*II_ED*/ {0x6, 59, 36, 8, 447}, - /*II_EE*/ {0x10, 33, 59, 8, 451}, - /*II_EF*/ {0x10, 36, 59, 8, 451}, - /*II_F1*/ {0x10, 0, 0, 14, 476}, - /*II_F4*/ {0x10, 0, 0, 8, 482}, - /*II_F5*/ {0x10, 0, 0, 8, 487}, - /*II_F8*/ {0x10, 0, 0, 8, 492}, - /*II_F9*/ {0x10, 0, 0, 8, 497}, - /*II_FA*/ {0x10, 0, 0, 8, 502}, - /*II_FB*/ {0x10, 0, 0, 8, 507}, - /*II_FC*/ {0x10, 0, 0, 8, 512}, - /*II_FD*/ {0x10, 0, 0, 8, 517}, - /*II_0F_02*/ {0xf, 16, 11, 8, 522}, - /*II_0F_03*/ {0xf, 16, 11, 8, 527}, - /*II_0F_05*/ {0x26, 0, 0, 27, 532}, - /*II_0F_06*/ {0x26, 0, 0, 8, 541}, - /*II_0F_07*/ {0x26, 0, 0, 27, 547}, - /*II_0F_08*/ {0x26, 0, 0, 8, 555}, - /*II_0F_09*/ {0x26, 0, 0, 8, 561}, - /*II_0F_0B*/ {0x26, 0, 0, 14, 569}, - /*II_0F_0E*/ {0x10, 0, 0, 96, 574}, - /*II_0F_1F*/ {0xf, 0, 17, 8, 581}, - /*II_0F_20*/ {0x27, 29, 14, 8, 218}, - /*II_0F_21*/ {0x27, 30, 14, 8, 218}, - /*II_0F_22*/ {0x27, 14, 29, 8, 218}, - /*II_0F_23*/ {0x27, 14, 30, 8, 218}, - /*II_0F_30*/ {0x26, 0, 0, 8, 586}, - /*II_0F_31*/ {0x26, 0, 0, 8, 593}, - /*II_0F_32*/ {0x26, 0, 0, 8, 600}, - /*II_0F_33*/ {0x26, 0, 0, 8, 607}, - /*II_0F_34*/ {0x26, 0, 0, 27, 614}, - /*II_0F_35*/ {0x26, 0, 0, 27, 624}, - /*II_0F_37*/ {0x28, 0, 0, 8, 633}, - /*II_0F_40*/ {0x29, 17, 11, 31, 641}, - /*II_0F_41*/ {0x29, 17, 11, 31, 648}, - /*II_0F_42*/ {0x29, 17, 11, 31, 656}, - /*II_0F_43*/ {0x29, 17, 11, 31, 663}, - /*II_0F_44*/ {0x29, 17, 11, 31, 671}, - /*II_0F_45*/ {0x29, 17, 11, 31, 678}, - /*II_0F_46*/ {0x29, 17, 11, 31, 686}, - /*II_0F_47*/ {0x29, 17, 11, 31, 694}, - /*II_0F_48*/ {0x29, 17, 11, 31, 701}, - /*II_0F_49*/ {0x29, 17, 11, 31, 708}, - /*II_0F_4A*/ {0x29, 17, 11, 31, 716}, - /*II_0F_4B*/ {0x29, 17, 11, 31, 723}, - /*II_0F_4C*/ {0x29, 17, 11, 31, 731}, - /*II_0F_4D*/ {0x29, 17, 11, 31, 738}, - /*II_0F_4E*/ {0x29, 17, 11, 31, 746}, - /*II_0F_4F*/ {0x29, 17, 11, 31, 754}, - /*II_0F_80*/ {0x26, 0, 41, 13, 134}, - /*II_0F_81*/ {0x26, 0, 41, 13, 138}, - /*II_0F_82*/ {0x26, 0, 41, 13, 143}, - /*II_0F_83*/ {0x26, 0, 41, 13, 147}, - /*II_0F_84*/ {0x26, 0, 41, 13, 152}, - /*II_0F_85*/ {0x26, 0, 41, 13, 156}, - /*II_0F_86*/ {0x26, 0, 41, 13, 161}, - /*II_0F_87*/ {0x26, 0, 41, 13, 166}, - /*II_0F_88*/ {0x26, 0, 41, 13, 170}, - /*II_0F_89*/ {0x26, 0, 41, 13, 174}, - /*II_0F_8A*/ {0x26, 0, 41, 13, 179}, - /*II_0F_8B*/ {0x26, 0, 41, 13, 183}, - /*II_0F_8C*/ {0x26, 0, 41, 13, 188}, - /*II_0F_8D*/ {0x26, 0, 41, 13, 192}, - /*II_0F_8E*/ {0x26, 0, 41, 13, 197}, - /*II_0F_8F*/ {0x26, 0, 41, 13, 202}, - /*II_0F_90*/ {0x29, 0, 15, 8, 761}, - /*II_0F_91*/ {0x29, 0, 15, 8, 767}, - /*II_0F_92*/ {0x29, 0, 15, 8, 774}, - /*II_0F_93*/ {0x29, 0, 15, 8, 780}, - /*II_0F_94*/ {0x29, 0, 15, 8, 787}, - /*II_0F_95*/ {0x29, 0, 15, 8, 793}, - /*II_0F_96*/ {0x29, 0, 15, 8, 800}, - /*II_0F_97*/ {0x29, 0, 15, 8, 807}, - /*II_0F_98*/ {0x29, 0, 15, 8, 813}, - /*II_0F_99*/ {0x29, 0, 15, 8, 819}, - /*II_0F_9A*/ {0x29, 0, 15, 8, 826}, - /*II_0F_9B*/ {0x29, 0, 15, 8, 832}, - /*II_0F_9C*/ {0x29, 0, 15, 8, 839}, - /*II_0F_9D*/ {0x29, 0, 15, 8, 845}, - /*II_0F_9E*/ {0x29, 0, 15, 8, 852}, - /*II_0F_9F*/ {0x29, 0, 15, 8, 859}, - /*II_0F_A0*/ {0x2a, 0, 32, 8, 16}, - /*II_0F_A1*/ {0x2b, 0, 32, 8, 22}, - /*II_0F_A2*/ {0x26, 0, 0, 8, 865}, - /*II_0F_A3*/ {0x29, 11, 17, 8, 872}, - /*II_0F_A8*/ {0x2d, 0, 32, 8, 16}, - /*II_0F_A9*/ {0x2e, 0, 32, 8, 22}, - /*II_0F_AA*/ {0x26, 0, 0, 8, 882}, - /*II_0F_AB*/ {0x2f, 11, 17, 8, 887}, - /*II_0F_AF*/ {0x29, 17, 11, 8, 117}, - /*II_0F_B0*/ {0x2f, 9, 15, 8, 898}, - /*II_0F_B1*/ {0x2f, 11, 17, 8, 898}, - /*II_0F_B2*/ {0x30, 37, 11, 8, 907}, - /*II_0F_B3*/ {0x2f, 11, 17, 8, 912}, - /*II_0F_B4*/ {0x30, 37, 11, 8, 917}, - /*II_0F_B5*/ {0x30, 37, 11, 8, 922}, - /*II_0F_B6*/ {0x29, 15, 11, 8, 927}, - /*II_0F_B7*/ {0x31, 16, 11, 8, 927}, - /*II_0F_B9*/ {0x26, 0, 0, 14, 569}, - /*II_0F_BB*/ {0x2f, 11, 17, 8, 934}, - /*II_0F_BE*/ {0x29, 15, 11, 8, 939}, - /*II_0F_BF*/ {0x31, 16, 11, 8, 939}, - /*II_0F_C0*/ {0x2f, 9, 15, 8, 946}, - /*II_0F_C1*/ {0x2f, 11, 17, 8, 946}, - /*II_0F_C3*/ {0x31, 13, 45, 48, 952}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_0F_C8*/ {0x32, 0, 54, 8, 960}, - /*II_80_00*/ {0x33, 1, 15, 8, 11}, - /*II_80_01*/ {0x33, 1, 15, 8, 27}, - /*II_80_02*/ {0x33, 1, 15, 8, 31}, - /*II_80_03*/ {0x33, 1, 15, 8, 36}, - /*II_80_04*/ {0x33, 1, 15, 8, 41}, - /*II_80_05*/ {0x33, 1, 15, 8, 51}, - /*II_80_06*/ {0x33, 1, 15, 8, 61}, - /*II_80_07*/ {0x34, 1, 15, 8, 71}, - /*II_81_00*/ {0x33, 3, 17, 8, 11}, - /*II_81_01*/ {0x33, 3, 17, 8, 27}, - /*II_81_02*/ {0x33, 3, 17, 8, 31}, - /*II_81_03*/ {0x33, 3, 17, 8, 36}, - /*II_81_04*/ {0x33, 3, 17, 8, 41}, - /*II_81_05*/ {0x33, 3, 17, 8, 51}, - /*II_81_06*/ {0x33, 3, 17, 8, 61}, - /*II_81_07*/ {0x34, 3, 17, 8, 71}, - /*II_82_00*/ {0x35, 1, 15, 8, 11}, - /*II_82_01*/ {0x35, 1, 15, 8, 27}, - /*II_82_02*/ {0x35, 1, 15, 8, 31}, - /*II_82_03*/ {0x35, 1, 15, 8, 36}, - /*II_82_04*/ {0x35, 1, 15, 8, 41}, - /*II_82_05*/ {0x35, 1, 15, 8, 51}, - /*II_82_06*/ {0x35, 1, 15, 8, 61}, - /*II_82_07*/ {0x36, 1, 15, 8, 71}, - /*II_83_00*/ {0x33, 5, 17, 8, 11}, - /*II_83_01*/ {0x37, 5, 17, 8, 27}, - /*II_83_02*/ {0x33, 5, 17, 8, 31}, - /*II_83_03*/ {0x33, 5, 17, 8, 36}, - /*II_83_04*/ {0x37, 5, 17, 8, 41}, - /*II_83_05*/ {0x33, 5, 17, 8, 51}, - /*II_83_06*/ {0x37, 5, 17, 8, 61}, - /*II_83_07*/ {0x34, 5, 17, 8, 71}, - /*II_8F_00*/ {0x38, 0, 17, 8, 22}, - /*II_C0_00*/ {0x39, 1, 15, 8, 967}, - /*II_C0_01*/ {0x39, 1, 15, 8, 972}, - /*II_C0_02*/ {0x39, 1, 15, 8, 977}, - /*II_C0_03*/ {0x39, 1, 15, 8, 982}, - /*II_C0_04*/ {0x39, 1, 15, 8, 987}, - /*II_C0_05*/ {0x39, 1, 15, 8, 992}, - /*II_C0_06*/ {0x39, 1, 15, 8, 997}, - /*II_C0_07*/ {0x39, 1, 15, 8, 1002}, - /*II_C1_00*/ {0x39, 1, 17, 8, 967}, - /*II_C1_01*/ {0x39, 1, 17, 8, 972}, - /*II_C1_02*/ {0x39, 1, 17, 8, 977}, - /*II_C1_03*/ {0x39, 1, 17, 8, 982}, - /*II_C1_04*/ {0x39, 1, 17, 8, 987}, - /*II_C1_05*/ {0x39, 1, 17, 8, 992}, - /*II_C1_06*/ {0x39, 1, 17, 8, 997}, - /*II_C1_07*/ {0x39, 1, 17, 8, 1002}, - /*II_C6_00*/ {0x39, 1, 15, 8, 218}, - /*II_C7_00*/ {0x39, 3, 17, 8, 218}, - /*II_D0_00*/ {0x39, 51, 15, 8, 967}, - /*II_D0_01*/ {0x39, 51, 15, 8, 972}, - /*II_D0_02*/ {0x39, 51, 15, 8, 977}, - /*II_D0_03*/ {0x39, 51, 15, 8, 982}, - /*II_D0_04*/ {0x39, 51, 15, 8, 987}, - /*II_D0_05*/ {0x39, 51, 15, 8, 992}, - /*II_D0_06*/ {0x39, 51, 15, 8, 997}, - /*II_D0_07*/ {0x39, 51, 15, 8, 1002}, - /*II_D1_00*/ {0x39, 51, 17, 8, 967}, - /*II_D1_01*/ {0x39, 51, 17, 8, 972}, - /*II_D1_02*/ {0x39, 51, 17, 8, 977}, - /*II_D1_03*/ {0x39, 51, 17, 8, 982}, - /*II_D1_04*/ {0x39, 51, 17, 8, 987}, - /*II_D1_05*/ {0x39, 51, 17, 8, 992}, - /*II_D1_06*/ {0x39, 51, 17, 8, 997}, - /*II_D1_07*/ {0x39, 51, 17, 8, 1002}, - /*II_D2_00*/ {0x39, 52, 15, 8, 967}, - /*II_D2_01*/ {0x39, 52, 15, 8, 972}, - /*II_D2_02*/ {0x39, 52, 15, 8, 977}, - /*II_D2_03*/ {0x39, 52, 15, 8, 982}, - /*II_D2_04*/ {0x39, 52, 15, 8, 987}, - /*II_D2_05*/ {0x39, 52, 15, 8, 992}, - /*II_D2_06*/ {0x39, 52, 15, 8, 997}, - /*II_D2_07*/ {0x39, 52, 15, 8, 1002}, - /*II_D3_00*/ {0x39, 52, 17, 8, 967}, - /*II_D3_01*/ {0x39, 52, 17, 8, 972}, - /*II_D3_02*/ {0x39, 52, 17, 8, 977}, - /*II_D3_03*/ {0x39, 52, 17, 8, 982}, - /*II_D3_04*/ {0x39, 52, 17, 8, 987}, - /*II_D3_05*/ {0x39, 52, 17, 8, 992}, - /*II_D3_06*/ {0x39, 52, 17, 8, 997}, - /*II_D3_07*/ {0x39, 52, 17, 8, 1002}, - /*II_D8_00*/ {0x34, 0, 21, 16, 1007}, - /*II_D8_01*/ {0x34, 0, 21, 16, 1013}, - /*II_D8_02*/ {0x34, 0, 21, 16, 1019}, - /*II_D8_03*/ {0x34, 0, 21, 16, 1025}, - /*II_D8_04*/ {0x34, 0, 21, 16, 1032}, - /*II_D8_05*/ {0x34, 0, 21, 16, 1038}, - /*II_D8_06*/ {0x34, 0, 21, 16, 1045}, - /*II_D8_07*/ {0x34, 0, 21, 16, 1051}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C0*/ {0x3a, 0, 62, 16, 1007}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_C8*/ {0x3a, 0, 62, 16, 1013}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D0*/ {0x3a, 0, 61, 16, 1019}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D9*/ {0x3a, 0, 0, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_D8*/ {0x3a, 0, 61, 16, 1025}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E0*/ {0x3a, 0, 62, 16, 1032}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_E8*/ {0x3a, 0, 62, 16, 1038}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F0*/ {0x3a, 0, 62, 16, 1045}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D8_F8*/ {0x3a, 0, 62, 16, 1051}, - /*II_D9_00*/ {0x34, 0, 21, 16, 1058}, - /*II_D9_02*/ {0x34, 0, 21, 16, 1063}, - /*II_D9_03*/ {0x34, 0, 21, 16, 1068}, - /*II_D9_04*/ {0x34, 0, 42, 16, 1074}, - /*II_D9_05*/ {0x34, 0, 42, 16, 1082}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C0*/ {0x3a, 0, 61, 16, 1058}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C9*/ {0x3a, 0, 0, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_C8*/ {0x3a, 0, 61, 16, 1089}, - /*II_D9_D0*/ {0x3a, 0, 0, 16, 1095}, - /*II_D9_E0*/ {0x3a, 0, 0, 16, 1101}, - /*II_D9_E1*/ {0x3a, 0, 0, 16, 1107}, - /*II_D9_E4*/ {0x3a, 0, 0, 16, 1113}, - /*II_D9_E5*/ {0x3a, 0, 0, 16, 1119}, - /*II_D9_E8*/ {0x3a, 0, 0, 16, 1125}, - /*II_D9_E9*/ {0x3a, 0, 0, 16, 1131}, - /*II_D9_EA*/ {0x3a, 0, 0, 16, 1139}, - /*II_D9_EB*/ {0x3a, 0, 0, 16, 1147}, - /*II_D9_EC*/ {0x3a, 0, 0, 16, 1154}, - /*II_D9_ED*/ {0x3a, 0, 0, 16, 1162}, - /*II_D9_EE*/ {0x3a, 0, 0, 16, 1170}, - /*II_D9_F0*/ {0x3a, 0, 0, 16, 1176}, - /*II_D9_F1*/ {0x3a, 0, 0, 16, 1183}, - /*II_D9_F2*/ {0x3a, 0, 0, 16, 1190}, - /*II_D9_F3*/ {0x3a, 0, 0, 16, 1197}, - /*II_D9_F4*/ {0x3a, 0, 0, 16, 1205}, - /*II_D9_F5*/ {0x3a, 0, 0, 16, 1214}, - /*II_D9_F6*/ {0x3a, 0, 0, 16, 1222}, - /*II_D9_F7*/ {0x3a, 0, 0, 16, 1231}, - /*II_D9_F8*/ {0x3a, 0, 0, 16, 1240}, - /*II_D9_F9*/ {0x3a, 0, 0, 16, 1247}, - /*II_D9_FA*/ {0x3a, 0, 0, 16, 1256}, - /*II_D9_FB*/ {0x3a, 0, 0, 16, 1263}, - /*II_D9_FC*/ {0x3a, 0, 0, 16, 1272}, - /*II_D9_FD*/ {0x3a, 0, 0, 16, 1281}, - /*II_D9_FE*/ {0x3a, 0, 0, 16, 1289}, - /*II_D9_FF*/ {0x3a, 0, 0, 16, 1295}, - /*II_DA_00*/ {0x34, 0, 21, 16, 1301}, - /*II_DA_01*/ {0x34, 0, 21, 16, 1308}, - /*II_DA_02*/ {0x34, 0, 21, 16, 1315}, - /*II_DA_03*/ {0x34, 0, 21, 16, 1322}, - /*II_DA_04*/ {0x34, 0, 21, 16, 1330}, - /*II_DA_05*/ {0x34, 0, 21, 16, 1337}, - /*II_DA_06*/ {0x34, 0, 21, 16, 1345}, - /*II_DA_07*/ {0x34, 0, 21, 16, 1352}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C0*/ {0x3b, 0, 62, 24, 1360}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_C8*/ {0x3b, 0, 62, 24, 1368}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D0*/ {0x3b, 0, 62, 24, 1376}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_D8*/ {0x3b, 0, 62, 24, 1385}, - /*II_DA_E9*/ {0x3a, 0, 0, 16, 1393}, - /*II_DB_00*/ {0x34, 0, 21, 16, 1402}, - /*II_DB_01*/ {0x3c, 0, 21, 56, 1408}, - /*II_DB_02*/ {0x34, 0, 21, 16, 1416}, - /*II_DB_03*/ {0x34, 0, 21, 16, 1422}, - /*II_DB_05*/ {0x34, 0, 23, 16, 1058}, - /*II_DB_07*/ {0x34, 0, 23, 16, 1068}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C0*/ {0x3b, 0, 62, 24, 1429}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_C8*/ {0x3b, 0, 62, 24, 1438}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D0*/ {0x3b, 0, 62, 24, 1447}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_D8*/ {0x3b, 0, 62, 24, 1457}, - /*II_DB_E0*/ {0x3a, 0, 0, 16, 1466}, - /*II_DB_E1*/ {0x3a, 0, 0, 16, 1472}, - /*II_DB_E4*/ {0x3a, 0, 0, 16, 1480}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_E8*/ {0x3b, 0, 62, 16, 1488}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DB_F0*/ {0x3b, 0, 62, 24, 1496}, - /*II_DC_00*/ {0x34, 0, 22, 16, 1007}, - /*II_DC_01*/ {0x34, 0, 22, 16, 1013}, - /*II_DC_02*/ {0x34, 0, 22, 16, 1019}, - /*II_DC_03*/ {0x34, 0, 22, 16, 1025}, - /*II_DC_04*/ {0x34, 0, 22, 16, 1032}, - /*II_DC_05*/ {0x34, 0, 22, 16, 1038}, - /*II_DC_06*/ {0x34, 0, 22, 16, 1045}, - /*II_DC_07*/ {0x34, 0, 22, 16, 1051}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C0*/ {0x3a, 0, 63, 16, 1007}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_C8*/ {0x3a, 0, 63, 16, 1013}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E0*/ {0x3a, 0, 63, 16, 1038}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_E8*/ {0x3a, 0, 63, 16, 1032}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F0*/ {0x3a, 0, 63, 16, 1051}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DC_F8*/ {0x3a, 0, 63, 16, 1045}, - /*II_DD_00*/ {0x34, 0, 22, 16, 1058}, - /*II_DD_01*/ {0x3c, 0, 22, 56, 1408}, - /*II_DD_02*/ {0x34, 0, 22, 16, 1063}, - /*II_DD_03*/ {0x34, 0, 22, 16, 1068}, - /*II_DD_04*/ {0x34, 0, 42, 16, 1503}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_C0*/ {0x3a, 0, 61, 16, 1511}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D0*/ {0x3a, 0, 61, 16, 1063}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_D8*/ {0x3a, 0, 61, 16, 1068}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E1*/ {0x3a, 0, 0, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E0*/ {0x3a, 0, 63, 16, 1518}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E9*/ {0x3a, 0, 0, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DD_E8*/ {0x3a, 0, 61, 16, 1525}, - /*II_DE_00*/ {0x34, 0, 20, 16, 1301}, - /*II_DE_01*/ {0x34, 0, 20, 16, 1308}, - /*II_DE_02*/ {0x34, 0, 20, 16, 1315}, - /*II_DE_03*/ {0x34, 0, 20, 16, 1322}, - /*II_DE_04*/ {0x34, 0, 20, 16, 1330}, - /*II_DE_05*/ {0x34, 0, 20, 16, 1337}, - /*II_DE_06*/ {0x34, 0, 20, 16, 1345}, - /*II_DE_07*/ {0x34, 0, 20, 16, 1352}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C1*/ {0x3a, 0, 0, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C0*/ {0x3a, 0, 63, 16, 1533}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C9*/ {0x3a, 0, 0, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_C8*/ {0x3a, 0, 63, 16, 1540}, - /*II_DE_D9*/ {0x3a, 0, 0, 16, 1547}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E1*/ {0x3a, 0, 0, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E0*/ {0x3a, 0, 63, 16, 1555}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E9*/ {0x3a, 0, 0, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_E8*/ {0x3a, 0, 63, 16, 1563}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F1*/ {0x3a, 0, 0, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F0*/ {0x3a, 0, 63, 16, 1570}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F9*/ {0x3a, 0, 0, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DE_F8*/ {0x3a, 0, 63, 16, 1578}, - /*II_DF_00*/ {0x34, 0, 20, 16, 1402}, - /*II_DF_01*/ {0x3c, 0, 20, 56, 1408}, - /*II_DF_02*/ {0x34, 0, 20, 16, 1416}, - /*II_DF_03*/ {0x34, 0, 20, 16, 1422}, - /*II_DF_04*/ {0x34, 0, 23, 16, 1585}, - /*II_DF_05*/ {0x34, 0, 22, 16, 1402}, - /*II_DF_06*/ {0x34, 0, 23, 16, 1591}, - /*II_DF_07*/ {0x34, 0, 22, 16, 1422}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_E8*/ {0x3b, 0, 62, 16, 1598}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_DF_F0*/ {0x3b, 0, 62, 16, 1607}, - /*II_F6_00*/ {0x34, 1, 15, 8, 206}, - /*II_F6_02*/ {0x33, 0, 15, 8, 1615}, - /*II_F6_03*/ {0x33, 0, 15, 8, 1620}, - /*II_F6_04*/ {0x39, 0, 15, 8, 1625}, - /*II_F6_05*/ {0x39, 0, 15, 8, 117}, - /*II_F6_06*/ {0x39, 0, 15, 8, 1630}, - /*II_F6_07*/ {0x39, 0, 15, 8, 1635}, - /*II_F7_00*/ {0x34, 3, 17, 8, 206}, - /*II_F7_02*/ {0x33, 0, 17, 8, 1615}, - /*II_F7_03*/ {0x33, 0, 17, 8, 1620}, - /*II_F7_04*/ {0x39, 0, 17, 8, 1625}, - /*II_F7_05*/ {0x39, 0, 17, 8, 117}, - /*II_F7_06*/ {0x39, 0, 17, 8, 1630}, - /*II_F7_07*/ {0x39, 0, 17, 8, 1635}, - /*II_FE_00*/ {0x33, 0, 15, 8, 81}, - /*II_FE_01*/ {0x33, 0, 15, 8, 86}, - /*II_FF_00*/ {0x33, 0, 17, 8, 81}, - /*II_FF_01*/ {0x33, 0, 17, 8, 86}, - /*II_FF_02*/ {0x3d, 0, 17, 9, 456}, - /*II_FF_03*/ {0x3e, 0, 37, 9, 260}, - /*II_FF_04*/ {0x3d, 0, 17, 12, 462}, - /*II_FF_05*/ {0x3e, 0, 37, 12, 467}, - /*II_FF_06*/ {0x3d, 0, 17, 8, 16}, - /*II_0F_00_00*/ {0x34, 0, 17, 8, 1641}, - /*II_0F_00_01*/ {0x34, 0, 16, 8, 1647}, - /*II_0F_00_02*/ {0x34, 0, 16, 8, 1652}, - /*II_0F_00_03*/ {0x3c, 0, 16, 8, 1658}, - /*II_0F_00_04*/ {0x34, 0, 16, 8, 1663}, - /*II_0F_00_05*/ {0x34, 0, 16, 8, 1669}, - /*II_0F_01_00*/ {0x3d, 0, 39, 8, 1675}, - /*II_0F_01_01*/ {0x3d, 0, 39, 8, 1681}, - /*II_0F_01_02*/ {0x3d, 0, 39, 8, 1687}, - /*II_0F_01_03*/ {0x3d, 0, 39, 8, 1693}, - /*II_0F_01_04*/ {0x3f, 0, 28, 8, 1699}, - /*II_0F_01_06*/ {0x40, 0, 16, 8, 1705}, - /*II_0F_01_07*/ {0x3c, 0, 42, 8, 1711}, - /*II_0F_01_C1*/ {0x3b, 0, 0, 112, 1719}, - /*II_0F_01_C2*/ {0x3b, 0, 0, 112, 1727}, - /*II_0F_01_C3*/ {0x3b, 0, 0, 112, 1737}, - /*II_0F_01_C4*/ {0x3b, 0, 0, 112, 1747}, - /*II_0F_01_C8*/ {0x3b, 0, 0, 8, 1755}, - /*II_0F_01_C9*/ {0x3b, 0, 0, 8, 1764}, - /*II_0F_01_D0*/ {0x26, 0, 0, 8, 1771}, - /*II_0F_01_D1*/ {0x26, 0, 0, 8, 1779}, - /*II_0F_01_D4*/ {0x3b, 0, 0, 112, 1787}, - /*II_0F_01_D8*/ {0x3c, 0, 58, 120, 1795}, - /*II_0F_01_D9*/ {0x3b, 0, 0, 120, 1802}, - /*II_0F_01_DA*/ {0x3b, 0, 58, 120, 1811}, - /*II_0F_01_DB*/ {0x3b, 0, 58, 120, 1819}, - /*II_0F_01_DC*/ {0x3b, 0, 0, 120, 1827}, - /*II_0F_01_DD*/ {0x3b, 0, 0, 120, 1833}, - /*II_0F_01_DE*/ {0x3b, 0, 58, 120, 1839}, - /*II_0F_01_DF*/ {0x3b, 60, 58, 120, 1847}, - /*II_0F_01_F8*/ {0x41, 0, 0, 8, 1856}, - /*II_0F_01_F9*/ {0x41, 0, 0, 8, 1864}, - /*II_0F_0D_00*/ {0x3c, 0, 42, 96, 1872}, - /*II_0F_0D_01*/ {0x3c, 0, 42, 96, 1882}, - /*II_0F_0F_0C*/ {0x42, 67, 64, 104, 1893}, - /*II_0F_0F_0D*/ {0x42, 67, 64, 96, 1900}, - /*II_0F_0F_1C*/ {0x42, 67, 64, 104, 1907}, - /*II_0F_0F_1D*/ {0x42, 67, 64, 96, 1914}, - /*II_0F_0F_8A*/ {0x42, 67, 64, 104, 1921}, - /*II_0F_0F_8E*/ {0x42, 67, 64, 104, 1929}, - /*II_0F_0F_90*/ {0x42, 67, 64, 96, 1938}, - /*II_0F_0F_94*/ {0x42, 67, 64, 96, 1947}, - /*II_0F_0F_96*/ {0x42, 67, 64, 96, 1954}, - /*II_0F_0F_97*/ {0x42, 67, 64, 96, 1961}, - /*II_0F_0F_9A*/ {0x42, 67, 64, 96, 1970}, - /*II_0F_0F_9E*/ {0x42, 67, 64, 96, 1977}, - /*II_0F_0F_A0*/ {0x42, 67, 64, 96, 1984}, - /*II_0F_0F_A4*/ {0x42, 67, 64, 96, 1993}, - /*II_0F_0F_A6*/ {0x42, 67, 64, 96, 2000}, - /*II_0F_0F_A7*/ {0x42, 67, 64, 96, 2010}, - /*II_0F_0F_AA*/ {0x42, 67, 64, 96, 2020}, - /*II_0F_0F_AE*/ {0x42, 67, 64, 96, 2028}, - /*II_0F_0F_B0*/ {0x42, 67, 64, 96, 2035}, - /*II_0F_0F_B4*/ {0x42, 67, 64, 96, 2044}, - /*II_0F_0F_B6*/ {0x42, 67, 64, 96, 2051}, - /*II_0F_0F_B7*/ {0x42, 67, 64, 96, 2061}, - /*II_0F_0F_BB*/ {0x42, 67, 64, 104, 2070}, - /*II_0F_0F_BF*/ {0x42, 67, 64, 96, 2078}, - /*II_0F_10*/ {0x29, 73, 68, 40, 2087}, - /*II_66_0F_10*/ {0x29, 73, 68, 48, 2095}, - /*II_F3_0F_10*/ {0x29, 71, 68, 40, 2103}, - /*II_F2_0F_10*/ {0x29, 72, 68, 48, 2110}, - /*II_0F_11*/ {0x29, 68, 73, 40, 2087}, - /*II_66_0F_11*/ {0x29, 68, 73, 48, 2095}, - /*II_F3_0F_11*/ {0x29, 68, 71, 40, 2103}, - /*II_F2_0F_11*/ {0x29, 68, 72, 48, 2110}, - /*II_66_0F_12*/ {0x29, 46, 68, 48, 2168}, - /*II_F3_0F_12*/ {0x29, 72, 68, 56, 2176}, - /*II_F2_0F_12*/ {0x29, 72, 68, 56, 2186}, - /*II_0F_13*/ {0x29, 68, 46, 40, 2160}, - /*II_66_0F_13*/ {0x29, 68, 46, 48, 2168}, - /*II_0F_14*/ {0x28, 73, 68, 40, 2244}, - /*II_66_0F_14*/ {0x28, 73, 68, 48, 2254}, - /*II_0F_15*/ {0x28, 73, 68, 40, 2286}, - /*II_66_0F_15*/ {0x28, 73, 68, 48, 2296}, - /*II_66_0F_16*/ {0x29, 46, 68, 48, 2345}, - /*II_F3_0F_16*/ {0x29, 73, 68, 56, 2353}, - /*II_0F_17*/ {0x29, 68, 46, 40, 2337}, - /*II_66_0F_17*/ {0x29, 68, 46, 48, 2345}, - /*II_0F_18_00*/ {0x3c, 0, 42, 40, 2402}, - /*II_0F_18_01*/ {0x3c, 0, 42, 40, 2415}, - /*II_0F_18_02*/ {0x3c, 0, 42, 40, 2427}, - /*II_0F_18_03*/ {0x3c, 0, 42, 40, 2439}, - /*II_0F_28*/ {0x29, 73, 68, 40, 2451}, - /*II_66_0F_28*/ {0x29, 73, 68, 48, 2459}, - /*II_0F_29*/ {0x29, 68, 73, 40, 2451}, - /*II_66_0F_29*/ {0x29, 68, 73, 48, 2459}, - /*II_0F_2A*/ {0x28, 67, 68, 40, 2485}, - /*II_66_0F_2A*/ {0x28, 67, 68, 48, 2495}, - /*II_F3_0F_2A*/ {0x30, 18, 68, 40, 2505}, - /*II_F2_0F_2A*/ {0x30, 18, 68, 48, 2515}, - /*II_0F_2B*/ {0x29, 68, 47, 40, 2547}, - /*II_66_0F_2B*/ {0x29, 68, 47, 48, 2556}, - /*II_F3_0F_2B*/ {0x29, 68, 44, 88, 2565}, - /*II_F2_0F_2B*/ {0x29, 68, 46, 88, 2574}, - /*II_0F_2C*/ {0x28, 72, 64, 40, 2603}, - /*II_66_0F_2C*/ {0x28, 73, 64, 48, 2614}, - /*II_F3_0F_2C*/ {0x30, 71, 13, 40, 2625}, - /*II_F2_0F_2C*/ {0x30, 72, 13, 48, 2636}, - /*II_0F_2D*/ {0x28, 72, 64, 40, 2671}, - /*II_66_0F_2D*/ {0x28, 73, 68, 48, 2681}, - /*II_F3_0F_2D*/ {0x30, 71, 13, 40, 2691}, - /*II_F2_0F_2D*/ {0x30, 72, 13, 48, 2701}, - /*II_0F_2E*/ {0x28, 71, 68, 40, 2733}, - /*II_66_0F_2E*/ {0x28, 72, 68, 48, 2742}, - /*II_0F_2F*/ {0x28, 71, 68, 40, 2771}, - /*II_66_0F_2F*/ {0x28, 72, 68, 48, 2779}, - /*II_0F_50*/ {0x49, 69, 12, 40, 2805}, - /*II_66_0F_50*/ {0x49, 69, 12, 48, 2815}, - /*II_0F_51*/ {0x28, 73, 68, 40, 2847}, - /*II_66_0F_51*/ {0x28, 73, 68, 48, 2855}, - /*II_F3_0F_51*/ {0x28, 71, 68, 40, 2863}, - /*II_F2_0F_51*/ {0x28, 72, 68, 48, 2871}, - /*II_0F_52*/ {0x28, 73, 68, 40, 2915}, - /*II_F3_0F_52*/ {0x28, 71, 68, 40, 2924}, - /*II_0F_53*/ {0x28, 73, 68, 40, 2953}, - /*II_F3_0F_53*/ {0x28, 71, 68, 40, 2960}, - /*II_0F_54*/ {0x28, 73, 68, 40, 2983}, - /*II_66_0F_54*/ {0x28, 73, 68, 48, 2990}, - /*II_0F_55*/ {0x28, 73, 68, 40, 3013}, - /*II_66_0F_55*/ {0x28, 73, 68, 48, 3021}, - /*II_0F_56*/ {0x28, 73, 68, 40, 3047}, - /*II_66_0F_56*/ {0x28, 73, 68, 48, 3053}, - /*II_0F_57*/ {0x28, 73, 68, 40, 3073}, - /*II_66_0F_57*/ {0x28, 73, 68, 48, 3080}, - /*II_0F_58*/ {0x28, 73, 68, 40, 3103}, - /*II_66_0F_58*/ {0x28, 73, 68, 48, 3110}, - /*II_F3_0F_58*/ {0x28, 71, 68, 40, 3117}, - /*II_F2_0F_58*/ {0x28, 72, 68, 48, 3124}, - /*II_0F_59*/ {0x28, 73, 68, 40, 3163}, - /*II_66_0F_59*/ {0x28, 73, 68, 48, 3170}, - /*II_F3_0F_59*/ {0x28, 71, 68, 40, 3177}, - /*II_F2_0F_59*/ {0x28, 72, 68, 48, 3184}, - /*II_0F_5A*/ {0x28, 72, 68, 48, 3223}, - /*II_66_0F_5A*/ {0x28, 73, 68, 48, 3233}, - /*II_F3_0F_5A*/ {0x28, 71, 68, 48, 3243}, - /*II_F2_0F_5A*/ {0x28, 72, 68, 48, 3253}, - /*II_0F_5B*/ {0x28, 73, 68, 48, 3307}, - /*II_66_0F_5B*/ {0x28, 73, 68, 48, 3317}, - /*II_F3_0F_5B*/ {0x28, 73, 68, 48, 3327}, - /*II_0F_5C*/ {0x28, 73, 68, 40, 3372}, - /*II_66_0F_5C*/ {0x28, 73, 68, 48, 3379}, - /*II_F3_0F_5C*/ {0x28, 71, 68, 40, 3386}, - /*II_F2_0F_5C*/ {0x28, 72, 68, 48, 3393}, - /*II_0F_5D*/ {0x28, 73, 68, 40, 3432}, - /*II_66_0F_5D*/ {0x28, 73, 68, 48, 3439}, - /*II_F3_0F_5D*/ {0x28, 71, 68, 40, 3446}, - /*II_F2_0F_5D*/ {0x28, 72, 68, 48, 3453}, - /*II_0F_5E*/ {0x28, 73, 68, 40, 3492}, - /*II_66_0F_5E*/ {0x28, 73, 68, 48, 3499}, - /*II_F3_0F_5E*/ {0x28, 71, 68, 40, 3506}, - /*II_F2_0F_5E*/ {0x28, 72, 68, 48, 3513}, - /*II_0F_5F*/ {0x28, 73, 68, 40, 3552}, - /*II_66_0F_5F*/ {0x28, 73, 68, 48, 3559}, - /*II_F3_0F_5F*/ {0x28, 71, 68, 40, 3566}, - /*II_F2_0F_5F*/ {0x28, 72, 68, 48, 3573}, - /*II_0F_60*/ {0x28, 66, 64, 32, 3612}, - /*II_66_0F_60*/ {0x28, 73, 68, 48, 3612}, - /*II_0F_61*/ {0x28, 66, 64, 32, 3635}, - /*II_66_0F_61*/ {0x28, 73, 68, 48, 3635}, - /*II_0F_62*/ {0x28, 66, 64, 32, 3658}, - /*II_66_0F_62*/ {0x28, 73, 68, 48, 3658}, - /*II_0F_63*/ {0x28, 67, 64, 32, 3681}, - /*II_66_0F_63*/ {0x28, 73, 68, 48, 3681}, - /*II_0F_64*/ {0x28, 67, 64, 32, 3702}, - /*II_66_0F_64*/ {0x28, 73, 68, 48, 3702}, - /*II_0F_65*/ {0x28, 67, 64, 32, 3721}, - /*II_66_0F_65*/ {0x28, 73, 68, 48, 3721}, - /*II_0F_66*/ {0x28, 67, 64, 32, 3740}, - /*II_66_0F_66*/ {0x28, 73, 68, 48, 3740}, - /*II_0F_67*/ {0x28, 67, 64, 32, 3759}, - /*II_66_0F_67*/ {0x28, 73, 68, 48, 3759}, - /*II_0F_68*/ {0x28, 67, 64, 32, 3780}, - /*II_66_0F_68*/ {0x28, 73, 68, 48, 3780}, - /*II_0F_69*/ {0x28, 67, 64, 32, 3803}, - /*II_66_0F_69*/ {0x28, 73, 68, 48, 3803}, - /*II_0F_6A*/ {0x28, 67, 64, 32, 3826}, - /*II_66_0F_6A*/ {0x28, 73, 68, 48, 3826}, - /*II_0F_6B*/ {0x28, 67, 64, 32, 3849}, - /*II_66_0F_6B*/ {0x28, 73, 68, 48, 3849}, - /*II_66_0F_6C*/ {0x28, 73, 68, 48, 3870}, - /*II_66_0F_6D*/ {0x28, 73, 68, 48, 3895}, - /*II_0F_6F*/ {0x29, 67, 64, 32, 3926}, - /*II_66_0F_6F*/ {0x29, 73, 68, 48, 3946}, - /*II_F3_0F_6F*/ {0x29, 73, 68, 48, 3954}, - /*II_0F_74*/ {0x28, 67, 64, 32, 4043}, - /*II_66_0F_74*/ {0x28, 73, 68, 48, 4043}, - /*II_0F_75*/ {0x28, 67, 64, 32, 4062}, - /*II_66_0F_75*/ {0x28, 73, 68, 48, 4062}, - /*II_0F_76*/ {0x28, 67, 64, 32, 4081}, - /*II_66_0F_76*/ {0x28, 73, 68, 48, 4081}, - /*II_0F_77*/ {0x26, 0, 0, 32, 4100}, - /*II_0F_78*/ {0x4e, 13, 18, 112, 4128}, - /*II_0F_79*/ {0x4e, 18, 13, 112, 4152}, - /*II_66_0F_79*/ {0x28, 69, 68, 88, 4136}, - /*II_F2_0F_79*/ {0x51, 69, 68, 88, 4143}, - /*II_0F_7A_30*/ {0x26, 72, 68, 112, 4161}, - /*II_0F_7A_31*/ {0x26, 68, 72, 112, 4171}, - /*II_66_0F_7C*/ {0x28, 73, 68, 56, 4181}, - /*II_F2_0F_7C*/ {0x28, 73, 68, 56, 4189}, - /*II_66_0F_7D*/ {0x28, 73, 68, 56, 4215}, - /*II_F2_0F_7D*/ {0x28, 73, 68, 56, 4223}, - /*II_F3_0F_7E*/ {0x29, 72, 68, 48, 3926}, - /*II_0F_7F*/ {0x29, 64, 67, 32, 3926}, - /*II_66_0F_7F*/ {0x29, 68, 73, 48, 3946}, - /*II_F3_0F_7F*/ {0x29, 68, 73, 48, 3954}, - /*II_F3_0F_B8*/ {0x55, 17, 11, 80, 4338}, - /*II_0F_BA_04*/ {0x56, 1, 17, 8, 872}, - /*II_0F_BA_05*/ {0x37, 1, 17, 8, 887}, - /*II_0F_BA_06*/ {0x37, 1, 17, 8, 912}, - /*II_0F_BA_07*/ {0x37, 1, 17, 8, 934}, - /*II_0F_BC*/ {0x28, 17, 11, 8, 4346}, - /*II_F3_0F_BC*/ {0x57, 17, 11, 112, 4351}, - /*II_0F_BD*/ {0x28, 17, 11, 8, 4358}, - /*II_F3_0F_BD*/ {0x58, 17, 11, 8, 4363}, - /*II_0F_C7_07*/ {0x3c, 0, 46, 112, 6385}, - /*II_66_0F_D0*/ {0x28, 73, 68, 56, 6394}, - /*II_F2_0F_D0*/ {0x28, 73, 68, 56, 6404}, - /*II_0F_D1*/ {0x28, 67, 64, 32, 6436}, - /*II_66_0F_D1*/ {0x28, 73, 68, 48, 6436}, - /*II_0F_D2*/ {0x28, 67, 64, 32, 6451}, - /*II_66_0F_D2*/ {0x28, 73, 68, 48, 6451}, - /*II_0F_D3*/ {0x28, 67, 64, 32, 6466}, - /*II_66_0F_D3*/ {0x28, 73, 68, 48, 6466}, - /*II_0F_D4*/ {0x28, 72, 68, 48, 6481}, - /*II_66_0F_D4*/ {0x28, 73, 68, 48, 6481}, - /*II_0F_D5*/ {0x28, 67, 64, 32, 6496}, - /*II_66_0F_D5*/ {0x28, 73, 68, 48, 6496}, - /*II_66_0F_D6*/ {0x29, 68, 72, 48, 3926}, - /*II_F3_0F_D6*/ {0x49, 65, 68, 48, 6513}, - /*II_F2_0F_D6*/ {0x49, 69, 64, 48, 6522}, - /*II_0F_D7*/ {0x51, 65, 12, 40, 6531}, - /*II_66_0F_D7*/ {0x51, 69, 12, 48, 6531}, - /*II_0F_D8*/ {0x28, 67, 64, 32, 6552}, - /*II_66_0F_D8*/ {0x28, 73, 68, 48, 6552}, - /*II_0F_D9*/ {0x28, 67, 64, 32, 6571}, - /*II_66_0F_D9*/ {0x28, 73, 68, 48, 6571}, - /*II_0F_DA*/ {0x28, 67, 64, 40, 6590}, - /*II_66_0F_DA*/ {0x28, 73, 68, 48, 6590}, - /*II_0F_DB*/ {0x28, 67, 64, 32, 6607}, - /*II_66_0F_DB*/ {0x28, 73, 68, 48, 6607}, - /*II_0F_DC*/ {0x28, 67, 64, 32, 6620}, - /*II_66_0F_DC*/ {0x28, 73, 68, 48, 6620}, - /*II_0F_DD*/ {0x28, 67, 64, 32, 6639}, - /*II_66_0F_DD*/ {0x28, 73, 68, 48, 6639}, - /*II_0F_DE*/ {0x28, 67, 64, 40, 6648}, - /*II_66_0F_DE*/ {0x28, 73, 68, 48, 6648}, - /*II_0F_DF*/ {0x28, 67, 64, 32, 6665}, - /*II_66_0F_DF*/ {0x28, 73, 68, 48, 6665}, - /*II_0F_E0*/ {0x28, 67, 64, 40, 6680}, - /*II_66_0F_E0*/ {0x28, 73, 68, 48, 6680}, - /*II_0F_E1*/ {0x28, 67, 64, 32, 6695}, - /*II_66_0F_E1*/ {0x28, 73, 68, 48, 6695}, - /*II_0F_E2*/ {0x28, 67, 64, 32, 6710}, - /*II_66_0F_E2*/ {0x28, 73, 68, 48, 6710}, - /*II_0F_E3*/ {0x28, 67, 64, 40, 6725}, - /*II_66_0F_E3*/ {0x28, 73, 68, 48, 6725}, - /*II_0F_E4*/ {0x28, 67, 64, 40, 6740}, - /*II_66_0F_E4*/ {0x28, 73, 68, 48, 6740}, - /*II_0F_E5*/ {0x28, 67, 64, 32, 6759}, - /*II_66_0F_E5*/ {0x28, 73, 68, 48, 6759}, - /*II_66_0F_E6*/ {0x28, 73, 68, 48, 6776}, - /*II_F3_0F_E6*/ {0x28, 72, 68, 48, 6787}, - /*II_F2_0F_E6*/ {0x28, 73, 68, 48, 6797}, - /*II_0F_E7*/ {0x29, 64, 46, 40, 6841}, - /*II_66_0F_E7*/ {0x29, 68, 47, 48, 6849}, - /*II_0F_E8*/ {0x28, 67, 64, 32, 6868}, - /*II_66_0F_E8*/ {0x28, 73, 68, 48, 6868}, - /*II_0F_E9*/ {0x28, 67, 64, 32, 6885}, - /*II_66_0F_E9*/ {0x28, 73, 68, 48, 6885}, - /*II_0F_EA*/ {0x28, 67, 64, 40, 6902}, - /*II_66_0F_EA*/ {0x28, 73, 68, 48, 6902}, - /*II_0F_EB*/ {0x28, 67, 64, 32, 6919}, - /*II_66_0F_EB*/ {0x28, 73, 68, 48, 6919}, - /*II_0F_EC*/ {0x28, 67, 64, 32, 6930}, - /*II_66_0F_EC*/ {0x28, 73, 68, 48, 6930}, - /*II_0F_ED*/ {0x28, 67, 64, 32, 6947}, - /*II_66_0F_ED*/ {0x28, 73, 68, 48, 6947}, - /*II_0F_EE*/ {0x28, 67, 64, 40, 6964}, - /*II_66_0F_EE*/ {0x28, 73, 68, 48, 6964}, - /*II_0F_EF*/ {0x28, 67, 64, 32, 6981}, - /*II_66_0F_EF*/ {0x28, 73, 68, 48, 6981}, - /*II_F2_0F_F0*/ {0x28, 42, 68, 56, 6994}, - /*II_0F_F1*/ {0x28, 67, 64, 32, 7009}, - /*II_66_0F_F1*/ {0x28, 73, 68, 48, 7009}, - /*II_0F_F2*/ {0x28, 67, 64, 32, 7024}, - /*II_66_0F_F2*/ {0x28, 73, 68, 48, 7024}, - /*II_0F_F3*/ {0x28, 67, 64, 32, 7039}, - /*II_66_0F_F3*/ {0x28, 73, 68, 48, 7039}, - /*II_0F_F4*/ {0x28, 67, 64, 48, 7054}, - /*II_66_0F_F4*/ {0x28, 73, 68, 48, 7054}, - /*II_0F_F5*/ {0x28, 67, 64, 32, 7073}, - /*II_66_0F_F5*/ {0x28, 73, 68, 48, 7073}, - /*II_0F_F6*/ {0x28, 67, 64, 40, 7092}, - /*II_66_0F_F6*/ {0x28, 73, 68, 48, 7092}, - /*II_0F_F7*/ {0x51, 65, 64, 40, 7109}, - /*II_66_0F_F7*/ {0x51, 69, 68, 48, 7119}, - /*II_0F_F8*/ {0x28, 67, 64, 32, 7144}, - /*II_66_0F_F8*/ {0x28, 73, 68, 48, 7144}, - /*II_0F_F9*/ {0x28, 67, 64, 32, 7159}, - /*II_66_0F_F9*/ {0x28, 73, 68, 48, 7159}, - /*II_0F_FA*/ {0x28, 67, 64, 32, 7174}, - /*II_66_0F_FA*/ {0x28, 73, 68, 48, 7174}, - /*II_0F_FB*/ {0x28, 67, 64, 48, 7189}, - /*II_66_0F_FB*/ {0x28, 73, 68, 48, 7189}, - /*II_0F_FC*/ {0x28, 67, 64, 32, 7204}, - /*II_66_0F_FC*/ {0x28, 73, 68, 48, 7204}, - /*II_0F_FD*/ {0x28, 67, 64, 32, 7219}, - /*II_66_0F_FD*/ {0x28, 73, 68, 48, 7219}, - /*II_0F_FE*/ {0x28, 67, 64, 32, 7234}, - /*II_66_0F_FE*/ {0x28, 73, 68, 48, 7234}, - /*II_D9_06*/ {0x34, 0, 42, 16, 7249}, - /*II_9B_D9_06*/ {0x60, 0, 42, 16, 7258}, - /*II_D9_07*/ {0x34, 0, 42, 16, 7266}, - /*II_9B_D9_07*/ {0x60, 0, 42, 16, 7274}, - /*II_DB_E2*/ {0x3a, 0, 0, 16, 7281}, - /*II_9B_DB_E2*/ {0x61, 0, 0, 16, 7289}, - /*II_DB_E3*/ {0x3a, 0, 0, 16, 7296}, - /*II_9B_DB_E3*/ {0x61, 0, 0, 16, 7304}, - /*II_DD_06*/ {0x34, 0, 42, 16, 7311}, - /*II_9B_DD_06*/ {0x60, 0, 42, 16, 7319}, - /*II_DD_07*/ {0x34, 0, 42, 16, 7326}, - /*II_9B_DD_07*/ {0x60, 0, 42, 16, 7334}, - /*II_DF_E0*/ {0x3a, 0, 34, 16, 7326}, - /*II_9B_DF_E0*/ {0x61, 0, 34, 16, 7334}, - /*II_0F_38_00*/ {0x28, 67, 64, 64, 7341}, - /*II_66_0F_38_00*/ {0x28, 73, 68, 64, 7341}, - /*II_0F_38_01*/ {0x28, 67, 64, 64, 7358}, - /*II_66_0F_38_01*/ {0x28, 73, 68, 64, 7358}, - /*II_0F_38_02*/ {0x28, 67, 64, 64, 7375}, - /*II_66_0F_38_02*/ {0x28, 73, 68, 64, 7375}, - /*II_0F_38_03*/ {0x28, 67, 64, 64, 7392}, - /*II_66_0F_38_03*/ {0x28, 73, 68, 64, 7392}, - /*II_0F_38_04*/ {0x28, 67, 64, 64, 7411}, - /*II_66_0F_38_04*/ {0x28, 73, 68, 64, 7411}, - /*II_0F_38_05*/ {0x28, 67, 64, 64, 7434}, - /*II_66_0F_38_05*/ {0x28, 73, 68, 64, 7434}, - /*II_0F_38_06*/ {0x28, 67, 64, 64, 7451}, - /*II_66_0F_38_06*/ {0x28, 73, 68, 64, 7451}, - /*II_0F_38_07*/ {0x28, 67, 64, 64, 7468}, - /*II_66_0F_38_07*/ {0x28, 73, 68, 64, 7468}, - /*II_0F_38_08*/ {0x28, 67, 64, 64, 7487}, - /*II_66_0F_38_08*/ {0x28, 73, 68, 64, 7487}, - /*II_0F_38_09*/ {0x28, 67, 64, 64, 7504}, - /*II_66_0F_38_09*/ {0x28, 73, 68, 64, 7504}, - /*II_0F_38_0A*/ {0x28, 67, 64, 64, 7521}, - /*II_66_0F_38_0A*/ {0x28, 73, 68, 64, 7521}, - /*II_0F_38_0B*/ {0x28, 67, 64, 64, 7538}, - /*II_66_0F_38_0B*/ {0x28, 73, 68, 64, 7538}, - /*II_66_0F_38_17*/ {0x28, 73, 68, 80, 7629}, - /*II_0F_38_1C*/ {0x28, 67, 64, 64, 7688}, - /*II_66_0F_38_1C*/ {0x28, 73, 68, 64, 7688}, - /*II_0F_38_1D*/ {0x28, 67, 64, 64, 7703}, - /*II_66_0F_38_1D*/ {0x28, 73, 68, 64, 7703}, - /*II_0F_38_1E*/ {0x28, 67, 64, 64, 7718}, - /*II_66_0F_38_1E*/ {0x28, 73, 68, 64, 7718}, - /*II_66_0F_38_20*/ {0x28, 72, 68, 72, 7733}, - /*II_66_0F_38_21*/ {0x28, 71, 68, 72, 7754}, - /*II_66_0F_38_22*/ {0x28, 70, 68, 72, 7775}, - /*II_66_0F_38_23*/ {0x28, 72, 68, 72, 7796}, - /*II_66_0F_38_24*/ {0x28, 71, 68, 72, 7817}, - /*II_66_0F_38_25*/ {0x28, 72, 68, 72, 7838}, - /*II_66_0F_38_28*/ {0x28, 73, 68, 72, 7859}, - /*II_66_0F_38_29*/ {0x28, 73, 68, 72, 7876}, - /*II_66_0F_38_2A*/ {0x29, 47, 68, 72, 7895}, - /*II_66_0F_38_2B*/ {0x28, 73, 68, 72, 7916}, - /*II_66_0F_38_30*/ {0x28, 72, 68, 72, 7961}, - /*II_66_0F_38_31*/ {0x28, 71, 68, 72, 7982}, - /*II_66_0F_38_32*/ {0x28, 70, 68, 72, 8003}, - /*II_66_0F_38_33*/ {0x28, 72, 68, 72, 8024}, - /*II_66_0F_38_34*/ {0x28, 71, 68, 72, 8045}, - /*II_66_0F_38_35*/ {0x28, 72, 68, 72, 8066}, - /*II_66_0F_38_37*/ {0x28, 73, 68, 80, 8087}, - /*II_66_0F_38_38*/ {0x28, 73, 68, 72, 8106}, - /*II_66_0F_38_39*/ {0x28, 73, 68, 72, 8123}, - /*II_66_0F_38_3A*/ {0x28, 73, 68, 72, 8140}, - /*II_66_0F_38_3B*/ {0x28, 73, 68, 72, 8157}, - /*II_66_0F_38_3C*/ {0x28, 73, 68, 72, 8174}, - /*II_66_0F_38_3D*/ {0x28, 73, 68, 72, 8191}, - /*II_66_0F_38_3E*/ {0x28, 73, 68, 72, 8208}, - /*II_66_0F_38_3F*/ {0x28, 73, 68, 72, 8225}, - /*II_66_0F_38_40*/ {0x28, 73, 68, 72, 8242}, - /*II_66_0F_38_41*/ {0x28, 73, 68, 72, 8259}, - /*II_66_0F_38_80*/ {0x4e, 47, 13, 112, 8284}, - /*II_66_0F_38_81*/ {0x4e, 47, 13, 112, 8292}, - /*II_66_0F_38_82*/ {0x4e, 47, 13, 112, 8301}, - /*II_66_0F_38_DB*/ {0x28, 73, 68, 152, 9150}, - /*II_66_0F_38_DC*/ {0x28, 73, 68, 152, 9167}, - /*II_66_0F_38_DD*/ {0x28, 73, 68, 152, 9184}, - /*II_66_0F_38_DE*/ {0x28, 73, 68, 152, 9209}, - /*II_66_0F_38_DF*/ {0x28, 73, 68, 152, 9226}, - /*II_0F_38_F0*/ {0x29, 17, 11, 8, 9251}, - /*II_F2_0F_38_F0*/ {0x29, 15, 13, 80, 9258}, - /*II_0F_38_F1*/ {0x29, 11, 17, 8, 9251}, - /*II_F2_0F_38_F1*/ {0x29, 17, 13, 80, 9258}, - /*II_0F_71_02*/ {0x63, 1, 65, 32, 6436}, - /*II_66_0F_71_02*/ {0x3c, 1, 69, 48, 6436}, - /*II_0F_71_04*/ {0x63, 1, 65, 32, 6695}, - /*II_66_0F_71_04*/ {0x3c, 1, 69, 48, 6695}, - /*II_0F_71_06*/ {0x63, 1, 65, 32, 7009}, - /*II_66_0F_71_06*/ {0x3c, 1, 69, 48, 7009}, - /*II_0F_72_02*/ {0x63, 1, 65, 32, 6451}, - /*II_66_0F_72_02*/ {0x3c, 1, 69, 48, 6451}, - /*II_0F_72_04*/ {0x63, 1, 65, 32, 6710}, - /*II_66_0F_72_04*/ {0x3c, 1, 69, 48, 6710}, - /*II_0F_72_06*/ {0x63, 1, 65, 32, 7024}, - /*II_66_0F_72_06*/ {0x3c, 1, 69, 48, 7024}, - /*II_0F_73_02*/ {0x63, 1, 65, 32, 6466}, - /*II_66_0F_73_02*/ {0x3c, 1, 69, 48, 6466}, - /*II_66_0F_73_03*/ {0x3c, 1, 69, 48, 9830}, - /*II_0F_73_06*/ {0x63, 1, 65, 32, 7039}, - /*II_66_0F_73_06*/ {0x3c, 1, 69, 48, 7039}, - /*II_66_0F_73_07*/ {0x3c, 1, 69, 48, 9847}, - /*II_F3_0F_AE_00*/ {0x65, 0, 13, 112, 9882}, - /*II_F3_0F_AE_01*/ {0x65, 0, 13, 112, 9912}, - /*II_0F_AE_02*/ {0x3c, 0, 42, 8, 9922}, - /*II_F3_0F_AE_02*/ {0x65, 0, 13, 112, 9931}, - /*II_0F_AE_03*/ {0x3c, 0, 42, 8, 9951}, - /*II_F3_0F_AE_03*/ {0x65, 0, 13, 112, 9960}, - /*II_66_0F_C7_06*/ {0x3c, 0, 46, 112, 9997}, - /*II_F3_0F_C7_06*/ {0x3c, 0, 46, 112, 10006} -}; - -_InstInfoEx InstInfosEx[] = { - /*II_69*/ {{0x17, 17, 11, 8, 117}, 0x0, 3, 0, 0, 0}, - /*II_6B*/ {{0x17, 17, 11, 8, 117}, 0x0, 5, 0, 0, 0}, - /*II_98*/ {{0x1c, 0, 0, 8, 228}, 0x0, 0, 0, 233, 239}, - /*II_99*/ {{0x1c, 0, 0, 8, 245}, 0x0, 0, 0, 250, 255}, - /*II_E3*/ {{0x25, 0, 40, 13, 427}, 0x0, 0, 0, 433, 440}, - /*II_0F_A4*/ {{0x2c, 11, 17, 8, 876}, 0x0, 1, 0, 0, 0}, - /*II_0F_A5*/ {{0x2c, 11, 17, 8, 876}, 0x0, 52, 0, 0, 0}, - /*II_0F_AC*/ {{0x2c, 11, 17, 8, 892}, 0x0, 1, 0, 0, 0}, - /*II_0F_AD*/ {{0x2c, 11, 17, 8, 892}, 0x0, 52, 0, 0, 0}, - /*II_V_0F_10*/ {{0x43, 90, 83, 128, 2117}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_10*/ {{0x43, 90, 83, 128, 2126}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_10*/ {{0x44, 81, 68, 128, 2135}, 0x20, 69, 0, 0, 0}, - /*II_V_F2_0F_10*/ {{0x44, 81, 68, 128, 2143}, 0x20, 69, 0, 0, 0}, - /*II_VRR_F3_0F_10*/ {{0x45, 44, 68, 128, 2135}, 0x60, 0, 0, 0, 0}, - /*II_VRR_F2_0F_10*/ {{0x45, 46, 68, 128, 2143}, 0x60, 0, 0, 0, 0}, - /*II_V_0F_11*/ {{0x43, 83, 90, 128, 2117}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_11*/ {{0x43, 83, 90, 128, 2126}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_11*/ {{0x44, 81, 68, 128, 2135}, 0x20, 69, 0, 0, 0}, - /*II_V_F2_0F_11*/ {{0x44, 81, 68, 128, 2143}, 0x20, 69, 0, 0, 0}, - /*II_VRR_F3_0F_11*/ {{0x45, 68, 44, 128, 2135}, 0x60, 0, 0, 0, 0}, - /*II_VRR_F2_0F_11*/ {{0x45, 68, 46, 128, 2143}, 0x60, 0, 0, 0, 0}, - /*II_0F_12*/ {{0x46, 72, 68, 40, 2151}, 0x0, 0, 0, 2160, 0}, - /*II_V_0F_12*/ {{0x47, 81, 68, 128, 2195}, 0x0, 72, 0, 2205, 0}, - /*II_V_66_0F_12*/ {{0x48, 81, 68, 128, 2214}, 0x0, 46, 0, 0, 0}, - /*II_V_F3_0F_12*/ {{0x43, 90, 83, 128, 2223}, 0x41, 0, 0, 0, 0}, - /*II_V_F2_0F_12*/ {{0x43, 89, 83, 128, 2234}, 0x41, 0, 0, 0, 0}, - /*II_V_0F_13*/ {{0x43, 68, 46, 128, 2205}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_13*/ {{0x43, 68, 46, 128, 2214}, 0x40, 0, 0, 0, 0}, - /*II_V_0F_14*/ {{0x48, 88, 83, 128, 2264}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_14*/ {{0x48, 88, 83, 128, 2275}, 0x1, 90, 0, 0, 0}, - /*II_V_0F_15*/ {{0x48, 88, 83, 128, 2306}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_15*/ {{0x48, 88, 83, 128, 2317}, 0x1, 90, 0, 0, 0}, - /*II_0F_16*/ {{0x46, 72, 68, 40, 2328}, 0x0, 0, 0, 2337, 0}, - /*II_V_0F_16*/ {{0x47, 81, 68, 128, 2363}, 0x0, 72, 0, 2373, 0}, - /*II_V_66_0F_16*/ {{0x48, 81, 68, 128, 2382}, 0x0, 46, 0, 0, 0}, - /*II_V_F3_0F_16*/ {{0x43, 90, 83, 128, 2391}, 0x41, 0, 0, 0, 0}, - /*II_V_0F_17*/ {{0x43, 68, 46, 128, 2373}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_17*/ {{0x43, 68, 46, 128, 2382}, 0x40, 0, 0, 0, 0}, - /*II_V_0F_28*/ {{0x43, 90, 83, 128, 2467}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_28*/ {{0x43, 90, 83, 128, 2476}, 0x41, 0, 0, 0, 0}, - /*II_V_0F_29*/ {{0x43, 83, 90, 128, 2467}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_29*/ {{0x43, 83, 90, 128, 2476}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_2A*/ {{0x48, 81, 68, 128, 2525}, 0x2, 79, 0, 0, 0}, - /*II_V_F2_0F_2A*/ {{0x48, 81, 68, 128, 2536}, 0x2, 79, 0, 0, 0}, - /*II_V_0F_2B*/ {{0x43, 83, 92, 128, 2583}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_2B*/ {{0x43, 83, 92, 128, 2593}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_2C*/ {{0x43, 80, 78, 128, 2647}, 0x42, 0, 0, 0, 0}, - /*II_V_F2_0F_2C*/ {{0x43, 80, 78, 128, 2659}, 0x42, 0, 0, 0, 0}, - /*II_V_F3_0F_2D*/ {{0x43, 80, 78, 128, 2711}, 0x42, 0, 0, 0, 0}, - /*II_V_F2_0F_2D*/ {{0x43, 80, 78, 128, 2722}, 0x42, 0, 0, 0, 0}, - /*II_V_0F_2E*/ {{0x43, 71, 68, 128, 2751}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_2E*/ {{0x43, 72, 68, 128, 2761}, 0x40, 0, 0, 0, 0}, - /*II_V_0F_2F*/ {{0x43, 71, 68, 128, 2787}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_2F*/ {{0x43, 72, 68, 128, 2796}, 0x40, 0, 0, 0, 0}, - /*II_V_0F_50*/ {{0x4a, 83, 13, 128, 2825}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_50*/ {{0x4a, 83, 13, 128, 2836}, 0x41, 0, 0, 0, 0}, - /*II_V_0F_51*/ {{0x43, 90, 83, 128, 2879}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_51*/ {{0x43, 90, 83, 128, 2888}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_51*/ {{0x48, 81, 68, 128, 2897}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_51*/ {{0x48, 81, 68, 128, 2906}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_52*/ {{0x43, 90, 83, 128, 2933}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_52*/ {{0x48, 81, 68, 128, 2943}, 0x0, 71, 0, 0, 0}, - /*II_V_0F_53*/ {{0x43, 90, 83, 128, 2967}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_53*/ {{0x48, 81, 68, 128, 2975}, 0x0, 71, 0, 0, 0}, - /*II_V_0F_54*/ {{0x48, 88, 83, 128, 2997}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_54*/ {{0x48, 88, 83, 128, 3005}, 0x1, 90, 0, 0, 0}, - /*II_V_0F_55*/ {{0x48, 88, 83, 128, 3029}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_55*/ {{0x48, 88, 83, 128, 3038}, 0x1, 90, 0, 0, 0}, - /*II_V_0F_56*/ {{0x48, 88, 83, 128, 3059}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_56*/ {{0x48, 88, 83, 128, 3066}, 0x1, 90, 0, 0, 0}, - /*II_V_0F_57*/ {{0x48, 88, 83, 128, 3087}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_57*/ {{0x48, 88, 83, 128, 3095}, 0x1, 90, 0, 0, 0}, - /*II_V_0F_58*/ {{0x48, 88, 83, 128, 3131}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_58*/ {{0x48, 88, 83, 128, 3139}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_58*/ {{0x48, 81, 68, 128, 3147}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_58*/ {{0x48, 81, 68, 128, 3155}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_59*/ {{0x48, 88, 83, 128, 3191}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_59*/ {{0x48, 88, 83, 128, 3199}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_59*/ {{0x48, 81, 68, 128, 3207}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_59*/ {{0x48, 81, 68, 128, 3215}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_5A*/ {{0x43, 91, 83, 128, 3263}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_5A*/ {{0x43, 90, 68, 128, 3274}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_5A*/ {{0x48, 81, 68, 128, 3285}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_5A*/ {{0x48, 81, 68, 128, 3296}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_5B*/ {{0x43, 90, 83, 128, 3338}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_5B*/ {{0x43, 90, 83, 128, 3349}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_5B*/ {{0x43, 90, 83, 128, 3360}, 0x41, 0, 0, 0, 0}, - /*II_V_0F_5C*/ {{0x48, 88, 83, 128, 3400}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_5C*/ {{0x48, 88, 83, 128, 3408}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_5C*/ {{0x48, 81, 68, 128, 3416}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_5C*/ {{0x48, 81, 68, 128, 3424}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_5D*/ {{0x48, 88, 83, 128, 3460}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_5D*/ {{0x48, 88, 83, 128, 3468}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_5D*/ {{0x48, 81, 68, 128, 3476}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_5D*/ {{0x48, 81, 68, 128, 3484}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_5E*/ {{0x48, 88, 83, 128, 3520}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_5E*/ {{0x48, 88, 83, 128, 3528}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_5E*/ {{0x48, 81, 68, 128, 3536}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_5E*/ {{0x48, 81, 68, 128, 3544}, 0x0, 72, 0, 0, 0}, - /*II_V_0F_5F*/ {{0x48, 88, 83, 128, 3580}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_5F*/ {{0x48, 88, 83, 128, 3588}, 0x1, 90, 0, 0, 0}, - /*II_V_F3_0F_5F*/ {{0x48, 81, 68, 128, 3596}, 0x0, 71, 0, 0, 0}, - /*II_V_F2_0F_5F*/ {{0x48, 81, 68, 128, 3604}, 0x0, 72, 0, 0, 0}, - /*II_V_66_0F_60*/ {{0x48, 81, 68, 128, 3623}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_61*/ {{0x48, 81, 68, 128, 3646}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_62*/ {{0x48, 81, 68, 128, 3669}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_63*/ {{0x48, 81, 68, 128, 3691}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_64*/ {{0x48, 81, 68, 128, 3711}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_65*/ {{0x48, 81, 68, 128, 3730}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_66*/ {{0x48, 81, 68, 128, 3749}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_67*/ {{0x48, 81, 68, 128, 3769}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_68*/ {{0x48, 81, 68, 128, 3791}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_69*/ {{0x48, 81, 68, 128, 3814}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_6A*/ {{0x48, 81, 68, 128, 3837}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_6B*/ {{0x48, 81, 68, 128, 3859}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_6C*/ {{0x48, 81, 68, 128, 3882}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_6D*/ {{0x48, 81, 68, 128, 3907}, 0x0, 73, 0, 0, 0}, - /*II_0F_6E*/ {{0x4b, 18, 64, 32, 3920}, 0x0, 0, 0, 0, 3926}, - /*II_66_0F_6E*/ {{0x4b, 18, 68, 48, 3920}, 0x0, 0, 0, 0, 3926}, - /*II_V_66_0F_6E*/ {{0x43, 79, 68, 128, 3932}, 0x46, 0, 0, 3939, 0}, - /*II_V_66_0F_6F*/ {{0x43, 90, 83, 128, 3962}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_6F*/ {{0x43, 90, 83, 128, 3971}, 0x41, 0, 0, 0, 0}, - /*II_0F_70*/ {{0x4c, 67, 64, 40, 3980}, 0x0, 1, 0, 0, 0}, - /*II_66_0F_70*/ {{0x4c, 73, 68, 48, 3988}, 0x0, 1, 0, 0, 0}, - /*II_F3_0F_70*/ {{0x4c, 73, 68, 48, 3996}, 0x0, 1, 0, 0, 0}, - /*II_F2_0F_70*/ {{0x4c, 73, 68, 48, 4005}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_70*/ {{0x48, 73, 68, 128, 4014}, 0x40, 1, 0, 0, 0}, - /*II_V_F3_0F_70*/ {{0x48, 73, 68, 128, 4023}, 0x40, 1, 0, 0, 0}, - /*II_V_F2_0F_70*/ {{0x48, 73, 68, 128, 4033}, 0x40, 1, 0, 0, 0}, - /*II_V_66_0F_74*/ {{0x48, 81, 68, 128, 4052}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_75*/ {{0x48, 81, 68, 128, 4071}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_76*/ {{0x48, 81, 68, 128, 4090}, 0x0, 73, 0, 0, 0}, - /*II_V_0F_77*/ {{0x4d, 0, 0, 128, 4106}, 0x49, 0, 0, 4118, 0}, - /*II_66_0F_78*/ {{0x4f, 7, 69, 88, 4136}, 0x0, 8, 0, 0, 0}, - /*II_F2_0F_78*/ {{0x50, 69, 68, 88, 4143}, 0x0, 7, 8, 0, 0}, - /*II_V_66_0F_7C*/ {{0x48, 88, 83, 128, 4197}, 0x1, 90, 0, 0, 0}, - /*II_V_F2_0F_7C*/ {{0x48, 88, 83, 128, 4206}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_7D*/ {{0x48, 88, 83, 128, 4231}, 0x1, 90, 0, 0, 0}, - /*II_V_F2_0F_7D*/ {{0x48, 88, 83, 128, 4240}, 0x1, 90, 0, 0, 0}, - /*II_0F_7E*/ {{0x4b, 64, 18, 32, 3920}, 0x0, 0, 0, 0, 3926}, - /*II_66_0F_7E*/ {{0x4b, 68, 18, 48, 3920}, 0x0, 0, 0, 0, 3926}, - /*II_V_66_0F_7E*/ {{0x43, 68, 79, 128, 3932}, 0x46, 0, 0, 3939, 0}, - /*II_V_F3_0F_7E*/ {{0x43, 72, 68, 128, 3939}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_7F*/ {{0x43, 83, 90, 128, 3962}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_7F*/ {{0x43, 83, 90, 128, 3971}, 0x41, 0, 0, 0, 0}, - /*II_0F_AE_04*/ {{0x52, 0, 42, 8, 4249}, 0x0, 0, 0, 0, 4256}, - /*II_0F_AE_05*/ {{0x53, 0, 43, 8, 4265}, 0x0, 0, 0, 4273, 4281}, - /*II_0F_AE_06*/ {{0x53, 0, 43, 8, 4291}, 0x0, 0, 0, 4299, 4309}, - /*II_0F_AE_07*/ {{0x54, 0, 43, 8, 4321}, 0x0, 0, 0, 4329, 0}, - /*II_0F_C2*/ {{0x59, 73, 68, 40, 4370}, 0x0, 0, 0, 4379, 4388}, - /*II_66_0F_C2*/ {{0x59, 73, 68, 48, 4449}, 0x0, 0, 0, 4458, 4467}, - /*II_F3_0F_C2*/ {{0x59, 71, 68, 40, 4528}, 0x0, 0, 0, 4537, 4546}, - /*II_F2_0F_C2*/ {{0x59, 72, 68, 48, 4607}, 0x0, 0, 0, 4616, 4625}, - /*II_V_0F_C2*/ {{0x5a, 88, 83, 128, 4686}, 0x1, 90, 0, 4696, 4706}, - /*II_V_66_0F_C2*/ {{0x5a, 88, 83, 128, 5088}, 0x1, 90, 0, 5098, 5108}, - /*II_V_F3_0F_C2*/ {{0x5a, 81, 68, 128, 5490}, 0x0, 71, 0, 5500, 5510}, - /*II_V_F2_0F_C2*/ {{0x5a, 81, 68, 128, 5892}, 0x0, 72, 0, 5902, 5912}, - /*II_0F_C4*/ {{0x4c, 25, 64, 40, 6294}, 0x0, 1, 0, 0, 0}, - /*II_66_0F_C4*/ {{0x4c, 25, 68, 48, 6294}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_C4*/ {{0x5b, 81, 68, 128, 6302}, 0x0, 25, 1, 0, 0}, - /*II_0F_C5*/ {{0x5c, 65, 12, 40, 6311}, 0x0, 1, 0, 0, 0}, - /*II_66_0F_C5*/ {{0x4c, 69, 12, 48, 6311}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_C5*/ {{0x5d, 68, 13, 128, 6319}, 0x40, 1, 0, 0, 0}, - /*II_0F_C6*/ {{0x4c, 73, 68, 40, 6328}, 0x0, 1, 0, 0, 0}, - /*II_66_0F_C6*/ {{0x4c, 73, 68, 48, 6336}, 0x0, 1, 0, 0, 0}, - /*II_V_0F_C6*/ {{0x5b, 88, 83, 128, 6344}, 0x1, 90, 1, 0, 0}, - /*II_V_66_0F_C6*/ {{0x5b, 88, 83, 128, 6353}, 0x1, 90, 1, 0, 0}, - /*II_0F_C7_01*/ {{0x5e, 0, 48, 8, 6362}, 0x0, 0, 0, 0, 6373}, - /*II_V_66_0F_D0*/ {{0x48, 88, 83, 128, 6414}, 0x1, 90, 0, 0, 0}, - /*II_V_F2_0F_D0*/ {{0x48, 88, 83, 128, 6425}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_D1*/ {{0x48, 81, 68, 128, 6443}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D2*/ {{0x48, 81, 68, 128, 6458}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D3*/ {{0x48, 81, 68, 128, 6473}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D4*/ {{0x48, 81, 68, 128, 6488}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D5*/ {{0x48, 81, 68, 128, 6504}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D6*/ {{0x43, 68, 72, 128, 3939}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_D7*/ {{0x4a, 68, 13, 128, 6541}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_D8*/ {{0x48, 81, 68, 128, 6561}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_D9*/ {{0x48, 81, 68, 128, 6580}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DA*/ {{0x48, 81, 68, 128, 6598}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DB*/ {{0x48, 81, 68, 128, 6613}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DC*/ {{0x48, 81, 68, 128, 6629}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DD*/ {{0x48, 81, 68, 128, 6629}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DE*/ {{0x48, 81, 68, 128, 6656}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_DF*/ {{0x48, 81, 68, 128, 6672}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E0*/ {{0x48, 81, 68, 128, 6687}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E1*/ {{0x48, 81, 68, 128, 6702}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E2*/ {{0x48, 81, 68, 128, 6717}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E3*/ {{0x48, 81, 68, 128, 6732}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E4*/ {{0x48, 81, 68, 128, 6749}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E5*/ {{0x48, 81, 68, 128, 6767}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E6*/ {{0x43, 90, 68, 128, 6807}, 0x41, 0, 0, 0, 0}, - /*II_V_F3_0F_E6*/ {{0x43, 91, 83, 128, 6819}, 0x41, 0, 0, 0, 0}, - /*II_V_F2_0F_E6*/ {{0x43, 90, 68, 128, 6830}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_E7*/ {{0x43, 83, 92, 128, 6858}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_E8*/ {{0x48, 81, 68, 128, 6876}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_E9*/ {{0x48, 81, 68, 128, 6893}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_EA*/ {{0x48, 81, 68, 128, 6910}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_EB*/ {{0x48, 81, 68, 128, 6924}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_EC*/ {{0x48, 81, 68, 128, 6938}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_ED*/ {{0x48, 81, 68, 128, 6955}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_EE*/ {{0x48, 81, 68, 128, 6972}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_EF*/ {{0x48, 81, 68, 128, 6987}, 0x0, 73, 0, 0, 0}, - /*II_V_F2_0F_F0*/ {{0x43, 92, 83, 128, 7001}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_F1*/ {{0x48, 81, 68, 128, 7016}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F2*/ {{0x48, 81, 68, 128, 7031}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F3*/ {{0x48, 81, 68, 128, 7046}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F4*/ {{0x48, 81, 68, 128, 7063}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F5*/ {{0x48, 81, 68, 128, 7082}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F6*/ {{0x48, 81, 68, 128, 7100}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F7*/ {{0x5f, 69, 68, 128, 7131}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_F8*/ {{0x48, 81, 68, 128, 7151}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_F9*/ {{0x48, 81, 68, 128, 7166}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_FA*/ {{0x48, 81, 68, 128, 7181}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_FB*/ {{0x48, 81, 68, 128, 7196}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_FC*/ {{0x48, 81, 68, 128, 7211}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_FD*/ {{0x48, 81, 68, 128, 7226}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_FE*/ {{0x48, 81, 68, 128, 7241}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_00*/ {{0x48, 81, 68, 128, 7349}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_01*/ {{0x48, 81, 68, 128, 7366}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_02*/ {{0x48, 81, 68, 128, 7383}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_03*/ {{0x48, 81, 68, 128, 7401}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_04*/ {{0x48, 81, 68, 128, 7422}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_05*/ {{0x48, 81, 68, 128, 7442}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_06*/ {{0x48, 81, 68, 128, 7459}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_07*/ {{0x48, 81, 68, 128, 7477}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_08*/ {{0x48, 81, 68, 128, 7495}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_09*/ {{0x48, 81, 68, 128, 7512}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_0A*/ {{0x48, 81, 68, 128, 7529}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_0B*/ {{0x48, 81, 68, 128, 7548}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_0C*/ {{0x48, 88, 83, 128, 7559}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_38_0D*/ {{0x48, 88, 83, 128, 7570}, 0x1, 90, 0, 0, 0}, - /*II_V_66_0F_38_0E*/ {{0x43, 90, 83, 128, 7581}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_38_0F*/ {{0x43, 90, 83, 128, 7590}, 0x41, 0, 0, 0, 0}, - /*II_66_0F_38_10*/ {{0x4c, 73, 68, 72, 7599}, 0x0, 74, 0, 0, 0}, - /*II_66_0F_38_14*/ {{0x4c, 73, 68, 72, 7609}, 0x0, 74, 0, 0, 0}, - /*II_66_0F_38_15*/ {{0x4c, 73, 68, 72, 7619}, 0x0, 74, 0, 0, 0}, - /*II_V_66_0F_38_17*/ {{0x43, 90, 83, 128, 7636}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_38_18*/ {{0x43, 44, 83, 128, 7644}, 0x41, 0, 0, 0, 0}, - /*II_V_66_0F_38_19*/ {{0x43, 46, 85, 128, 7658}, 0x50, 0, 0, 0, 0}, - /*II_V_66_0F_38_1A*/ {{0x43, 47, 85, 128, 7672}, 0x50, 0, 0, 0, 0}, - /*II_V_66_0F_38_1C*/ {{0x43, 73, 68, 128, 7695}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_1D*/ {{0x43, 73, 68, 128, 7710}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_1E*/ {{0x43, 73, 68, 128, 7725}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_20*/ {{0x43, 72, 68, 128, 7743}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_21*/ {{0x43, 71, 68, 128, 7764}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_22*/ {{0x43, 70, 68, 128, 7785}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_23*/ {{0x43, 72, 68, 128, 7806}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_24*/ {{0x43, 71, 68, 128, 7827}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_25*/ {{0x43, 72, 68, 128, 7848}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_28*/ {{0x48, 81, 68, 128, 7867}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_29*/ {{0x48, 81, 68, 128, 7885}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_2A*/ {{0x43, 47, 68, 128, 7905}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_2B*/ {{0x48, 81, 68, 128, 7926}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_2C*/ {{0x48, 88, 83, 128, 7937}, 0x1, 92, 0, 0, 0}, - /*II_V_66_0F_38_2D*/ {{0x48, 88, 83, 128, 7949}, 0x1, 92, 0, 0, 0}, - /*II_V_66_0F_38_2E*/ {{0x48, 88, 92, 128, 7937}, 0x1, 83, 0, 0, 0}, - /*II_V_66_0F_38_2F*/ {{0x48, 88, 92, 128, 7949}, 0x1, 83, 0, 0, 0}, - /*II_V_66_0F_38_30*/ {{0x43, 72, 68, 128, 7971}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_31*/ {{0x43, 71, 68, 128, 7992}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_32*/ {{0x43, 70, 68, 128, 8013}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_33*/ {{0x43, 72, 68, 128, 8034}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_34*/ {{0x43, 71, 68, 128, 8055}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_35*/ {{0x43, 72, 68, 128, 8076}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_37*/ {{0x48, 81, 68, 128, 8096}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_38*/ {{0x48, 81, 68, 128, 8114}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_39*/ {{0x48, 81, 68, 128, 8131}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3A*/ {{0x48, 81, 68, 128, 8148}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3B*/ {{0x48, 81, 68, 128, 8165}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3C*/ {{0x48, 81, 68, 128, 8182}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3D*/ {{0x48, 81, 68, 128, 8199}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3E*/ {{0x48, 81, 68, 128, 8216}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_3F*/ {{0x48, 81, 68, 128, 8233}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_40*/ {{0x48, 81, 68, 128, 8250}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_41*/ {{0x43, 73, 68, 128, 8271}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_96*/ {{0x48, 88, 83, 136, 8310}, 0x7, 90, 0, 8326, 0}, - /*II_V_66_0F_38_97*/ {{0x48, 88, 83, 136, 8342}, 0x7, 90, 0, 8358, 0}, - /*II_V_66_0F_38_98*/ {{0x48, 88, 83, 136, 8374}, 0x7, 90, 0, 8387, 0}, - /*II_V_66_0F_38_99*/ {{0x48, 81, 68, 136, 8400}, 0x6, 80, 0, 8413, 0}, - /*II_V_66_0F_38_9A*/ {{0x48, 88, 83, 136, 8426}, 0x7, 90, 0, 8439, 0}, - /*II_V_66_0F_38_9B*/ {{0x48, 81, 68, 136, 8452}, 0x6, 80, 0, 8465, 0}, - /*II_V_66_0F_38_9C*/ {{0x48, 88, 83, 136, 8478}, 0x7, 90, 0, 8492, 0}, - /*II_V_66_0F_38_9D*/ {{0x48, 81, 68, 136, 8506}, 0x6, 80, 0, 8520, 0}, - /*II_V_66_0F_38_9E*/ {{0x48, 88, 83, 136, 8534}, 0x7, 90, 0, 8548, 0}, - /*II_V_66_0F_38_9F*/ {{0x48, 81, 68, 136, 8562}, 0x6, 80, 0, 8576, 0}, - /*II_V_66_0F_38_A6*/ {{0x48, 88, 83, 136, 8590}, 0x7, 90, 0, 8606, 0}, - /*II_V_66_0F_38_A7*/ {{0x48, 88, 83, 136, 8622}, 0x7, 90, 0, 8638, 0}, - /*II_V_66_0F_38_A8*/ {{0x48, 88, 83, 136, 8654}, 0x7, 90, 0, 8667, 0}, - /*II_V_66_0F_38_A9*/ {{0x48, 81, 68, 136, 8680}, 0x6, 80, 0, 8693, 0}, - /*II_V_66_0F_38_AA*/ {{0x48, 88, 83, 136, 8706}, 0x7, 90, 0, 8719, 0}, - /*II_V_66_0F_38_AB*/ {{0x48, 81, 68, 136, 8732}, 0x6, 80, 0, 8745, 0}, - /*II_V_66_0F_38_AC*/ {{0x48, 88, 83, 136, 8758}, 0x7, 90, 0, 8772, 0}, - /*II_V_66_0F_38_AD*/ {{0x48, 81, 68, 136, 8786}, 0x6, 80, 0, 8800, 0}, - /*II_V_66_0F_38_AE*/ {{0x48, 88, 83, 136, 8814}, 0x7, 90, 0, 8828, 0}, - /*II_V_66_0F_38_AF*/ {{0x48, 81, 68, 136, 8842}, 0x6, 80, 0, 8856, 0}, - /*II_V_66_0F_38_B6*/ {{0x48, 88, 83, 136, 8870}, 0x7, 90, 0, 8886, 0}, - /*II_V_66_0F_38_B7*/ {{0x48, 88, 83, 136, 8902}, 0x7, 90, 0, 8918, 0}, - /*II_V_66_0F_38_B8*/ {{0x48, 88, 83, 136, 8934}, 0x7, 90, 0, 8947, 0}, - /*II_V_66_0F_38_B9*/ {{0x48, 81, 68, 136, 8960}, 0x6, 80, 0, 8973, 0}, - /*II_V_66_0F_38_BA*/ {{0x48, 88, 83, 136, 8986}, 0x7, 90, 0, 8999, 0}, - /*II_V_66_0F_38_BB*/ {{0x48, 81, 68, 136, 9012}, 0x6, 80, 0, 9025, 0}, - /*II_V_66_0F_38_BC*/ {{0x48, 88, 83, 136, 9038}, 0x7, 90, 0, 9052, 0}, - /*II_V_66_0F_38_BD*/ {{0x48, 81, 68, 136, 9066}, 0x6, 80, 0, 9080, 0}, - /*II_V_66_0F_38_BE*/ {{0x48, 88, 83, 136, 9094}, 0x7, 90, 0, 9108, 0}, - /*II_V_66_0F_38_BF*/ {{0x48, 81, 68, 136, 9122}, 0x6, 80, 0, 9136, 0}, - /*II_V_66_0F_38_DB*/ {{0x43, 73, 68, 152, 9158}, 0x40, 0, 0, 0, 0}, - /*II_V_66_0F_38_DC*/ {{0x48, 81, 68, 152, 9175}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_DD*/ {{0x48, 81, 68, 152, 9196}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_DE*/ {{0x48, 81, 68, 152, 9217}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_38_DF*/ {{0x48, 81, 68, 152, 9238}, 0x0, 73, 0, 0, 0}, - /*II_V_66_0F_3A_04*/ {{0x48, 90, 83, 128, 7559}, 0x41, 1, 0, 0, 0}, - /*II_V_66_0F_3A_05*/ {{0x48, 90, 83, 128, 7570}, 0x41, 1, 0, 0, 0}, - /*II_V_66_0F_3A_06*/ {{0x5b, 87, 85, 128, 9265}, 0x10, 86, 1, 0, 0}, - /*II_66_0F_3A_08*/ {{0x4c, 73, 68, 72, 9277}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_08*/ {{0x48, 90, 83, 128, 9286}, 0x41, 1, 0, 0, 0}, - /*II_66_0F_3A_09*/ {{0x4c, 73, 68, 72, 9296}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_09*/ {{0x48, 90, 83, 128, 9305}, 0x41, 1, 0, 0, 0}, - /*II_66_0F_3A_0A*/ {{0x4c, 71, 68, 72, 9315}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0A*/ {{0x5b, 81, 68, 128, 9324}, 0x0, 71, 1, 0, 0}, - /*II_66_0F_3A_0B*/ {{0x4c, 72, 68, 72, 9334}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0B*/ {{0x5b, 81, 68, 128, 9343}, 0x0, 72, 1, 0, 0}, - /*II_66_0F_3A_0C*/ {{0x4c, 73, 68, 72, 9353}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0C*/ {{0x5b, 88, 83, 128, 9362}, 0x1, 90, 1, 0, 0}, - /*II_66_0F_3A_0D*/ {{0x4c, 73, 68, 72, 9372}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0D*/ {{0x5b, 88, 83, 128, 9381}, 0x1, 90, 1, 0, 0}, - /*II_66_0F_3A_0E*/ {{0x4c, 73, 68, 72, 9391}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0E*/ {{0x5b, 81, 68, 128, 9400}, 0x0, 73, 1, 0, 0}, - /*II_0F_3A_0F*/ {{0x4c, 67, 64, 64, 9410}, 0x0, 1, 0, 0, 0}, - /*II_66_0F_3A_0F*/ {{0x4c, 73, 68, 64, 9410}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_0F*/ {{0x5b, 81, 68, 128, 9419}, 0x0, 73, 1, 0, 0}, - /*II_66_0F_3A_14*/ {{0x4c, 68, 26, 72, 9429}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_14*/ {{0x5d, 68, 76, 128, 9437}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_15*/ {{0x4c, 68, 27, 72, 6311}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_15*/ {{0x5d, 68, 77, 128, 6319}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_16*/ {{0x62, 68, 18, 72, 9446}, 0x0, 1, 0, 0, 9454}, - /*II_V_66_0F_3A_16*/ {{0x48, 68, 79, 128, 9462}, 0x46, 1, 0, 9471, 0}, - /*II_66_0F_3A_17*/ {{0x4c, 68, 18, 72, 9480}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_17*/ {{0x48, 68, 75, 128, 9491}, 0x40, 1, 0, 0, 0}, - /*II_V_66_0F_3A_18*/ {{0x5b, 87, 85, 128, 9503}, 0x10, 73, 1, 0, 0}, - /*II_V_66_0F_3A_19*/ {{0x48, 85, 73, 128, 9516}, 0x50, 1, 0, 0, 0}, - /*II_66_0F_3A_20*/ {{0x4c, 24, 68, 72, 9530}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_20*/ {{0x5b, 81, 68, 128, 9538}, 0x0, 76, 1, 0, 0}, - /*II_66_0F_3A_21*/ {{0x4c, 71, 68, 72, 9547}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_21*/ {{0x5b, 81, 68, 128, 9557}, 0x0, 71, 1, 0, 0}, - /*II_66_0F_3A_22*/ {{0x62, 18, 68, 72, 9568}, 0x0, 1, 0, 0, 9576}, - /*II_V_66_0F_3A_22*/ {{0x5b, 81, 68, 128, 9584}, 0x6, 79, 1, 9593, 0}, - /*II_66_0F_3A_40*/ {{0x4c, 73, 68, 72, 9602}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_40*/ {{0x5b, 88, 83, 128, 9608}, 0x1, 90, 1, 0, 0}, - /*II_66_0F_3A_41*/ {{0x4c, 73, 68, 72, 9615}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_41*/ {{0x5b, 81, 68, 128, 9621}, 0x0, 73, 1, 0, 0}, - /*II_66_0F_3A_42*/ {{0x4c, 73, 68, 72, 9628}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_42*/ {{0x5b, 81, 68, 128, 9637}, 0x0, 73, 1, 0, 0}, - /*II_66_0F_3A_44*/ {{0x4c, 73, 68, 144, 9647}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_44*/ {{0x5b, 81, 68, 144, 9658}, 0x0, 73, 1, 0, 0}, - /*II_V_66_0F_3A_4A*/ {{0x5b, 88, 83, 128, 9670}, 0x1, 90, 84, 0, 0}, - /*II_V_66_0F_3A_4B*/ {{0x5b, 88, 83, 128, 9681}, 0x1, 90, 84, 0, 0}, - /*II_V_66_0F_3A_4C*/ {{0x5b, 81, 68, 128, 9692}, 0x0, 73, 82, 0, 0}, - /*II_66_0F_3A_60*/ {{0x4c, 73, 68, 80, 9703}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_60*/ {{0x48, 73, 68, 128, 9714}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_61*/ {{0x4c, 73, 68, 80, 9726}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_61*/ {{0x48, 73, 68, 128, 9737}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_62*/ {{0x4c, 73, 68, 80, 9749}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_62*/ {{0x48, 73, 68, 128, 9760}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_63*/ {{0x4c, 73, 68, 80, 9772}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_63*/ {{0x48, 73, 68, 128, 9783}, 0x40, 1, 0, 0, 0}, - /*II_66_0F_3A_DF*/ {{0x4c, 73, 68, 152, 9795}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_3A_DF*/ {{0x48, 73, 68, 152, 9812}, 0x40, 1, 0, 0, 0}, - /*II_V_66_0F_71_02*/ {{0x64, 69, 81, 128, 6443}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_71_04*/ {{0x64, 69, 81, 128, 6702}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_71_06*/ {{0x64, 69, 81, 128, 7016}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_72_02*/ {{0x64, 69, 81, 128, 6458}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_72_04*/ {{0x64, 69, 81, 128, 6717}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_72_06*/ {{0x64, 69, 81, 128, 7031}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_73_02*/ {{0x64, 69, 81, 128, 6473}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_73_03*/ {{0x64, 69, 81, 128, 9838}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_73_06*/ {{0x64, 69, 81, 128, 7046}, 0x0, 1, 0, 0, 0}, - /*II_V_66_0F_73_07*/ {{0x64, 69, 81, 128, 9855}, 0x0, 1, 0, 0, 0}, - /*II_0F_AE_00*/ {{0x52, 0, 42, 8, 9864}, 0x0, 0, 0, 0, 9872}, - /*II_0F_AE_01*/ {{0x52, 0, 42, 8, 9892}, 0x0, 0, 0, 0, 9901}, - /*II_V_0F_AE_02*/ {{0x45, 0, 44, 128, 9941}, 0x40, 0, 0, 0, 0}, - /*II_V_0F_AE_03*/ {{0x45, 0, 44, 128, 9970}, 0x40, 0, 0, 0, 0}, - /*II_0F_C7_06*/ {{0x54, 0, 43, 112, 9980}, 0x0, 0, 0, 9988, 0} -}; - -_InstNode InstructionsTree[] = { -/* 0 - _00 */ 0x2000, -/* 1 - _01 */ 0x2001, -/* 2 - _02 */ 0x2002, -/* 3 - _03 */ 0x2003, -/* 4 - _04 */ 0x2004, -/* 5 - _05 */ 0x2005, -/* 6 - _06 */ 0x2006, -/* 7 - _07 */ 0x2007, -/* 8 - _08 */ 0x2008, -/* 9 - _09 */ 0x2009, -/* a - _0A */ 0x200a, -/* b - _0B */ 0x200b, -/* c - _0C */ 0x200c, -/* d - _0D */ 0x200d, -/* e - _0E */ 0x200e, -/* f - _0F */ 0x8100, -/* 10 - _10 */ 0x200f, -/* 11 - _11 */ 0x2010, -/* 12 - _12 */ 0x2011, -/* 13 - _13 */ 0x2012, -/* 14 - _14 */ 0x2013, -/* 15 - _15 */ 0x2014, -/* 16 - _16 */ 0x2015, -/* 17 - _17 */ 0x2016, -/* 18 - _18 */ 0x2017, -/* 19 - _19 */ 0x2018, -/* 1a - _1A */ 0x2019, -/* 1b - _1B */ 0x201a, -/* 1c - _1C */ 0x201b, -/* 1d - _1D */ 0x201c, -/* 1e - _1E */ 0x201d, -/* 1f - _1F */ 0x201e, -/* 20 - _20 */ 0x201f, -/* 21 - _21 */ 0x2020, -/* 22 - _22 */ 0x2021, -/* 23 - _23 */ 0x2022, -/* 24 - _24 */ 0x2023, -/* 25 - _25 */ 0x2024, -/* 26 - */ 0, -/* 27 - _27 */ 0x2025, -/* 28 - _28 */ 0x2026, -/* 29 - _29 */ 0x2027, -/* 2a - _2A */ 0x2028, -/* 2b - _2B */ 0x2029, -/* 2c - _2C */ 0x202a, -/* 2d - _2D */ 0x202b, -/* 2e - */ 0, -/* 2f - _2F */ 0x202c, -/* 30 - _30 */ 0x202d, -/* 31 - _31 */ 0x202e, -/* 32 - _32 */ 0x202f, -/* 33 - _33 */ 0x2030, -/* 34 - _34 */ 0x2031, -/* 35 - _35 */ 0x2032, -/* 36 - */ 0, -/* 37 - _37 */ 0x2033, -/* 38 - _38 */ 0x2034, -/* 39 - _39 */ 0x2035, -/* 3a - _3A */ 0x2036, -/* 3b - _3B */ 0x2037, -/* 3c - _3C */ 0x2038, -/* 3d - _3D */ 0x2039, -/* 3e - */ 0, -/* 3f - _3F */ 0x203a, -/* 40 - _40 */ 0x203b, -/* 41 - _40 */ 0x203c, -/* 42 - _40 */ 0x203d, -/* 43 - _40 */ 0x203e, -/* 44 - _40 */ 0x203f, -/* 45 - _40 */ 0x2040, -/* 46 - _40 */ 0x2041, -/* 47 - _40 */ 0x2042, -/* 48 - _48 */ 0x2043, -/* 49 - _48 */ 0x2044, -/* 4a - _48 */ 0x2045, -/* 4b - _48 */ 0x2046, -/* 4c - _48 */ 0x2047, -/* 4d - _48 */ 0x2048, -/* 4e - _48 */ 0x2049, -/* 4f - _48 */ 0x204a, -/* 50 - _50 */ 0x204b, -/* 51 - _50 */ 0x204c, -/* 52 - _50 */ 0x204d, -/* 53 - _50 */ 0x204e, -/* 54 - _50 */ 0x204f, -/* 55 - _50 */ 0x2050, -/* 56 - _50 */ 0x2051, -/* 57 - _50 */ 0x2052, -/* 58 - _58 */ 0x2053, -/* 59 - _58 */ 0x2054, -/* 5a - _58 */ 0x2055, -/* 5b - _58 */ 0x2056, -/* 5c - _58 */ 0x2057, -/* 5d - _58 */ 0x2058, -/* 5e - _58 */ 0x2059, -/* 5f - _58 */ 0x205a, -/* 60 - _60 */ 0x205b, -/* 61 - _61 */ 0x205c, -/* 62 - _62 */ 0x205d, -/* 63 - _63 */ 0x205e, -/* 64 - */ 0, -/* 65 - */ 0, -/* 66 - */ 0, -/* 67 - */ 0, -/* 68 - _68 */ 0x205f, -/* 69 - _69 */ 0x4000, -/* 6a - _6A */ 0x2060, -/* 6b - _6B */ 0x4001, -/* 6c - _6C */ 0x2061, -/* 6d - _6D */ 0x2062, -/* 6e - _6E */ 0x2063, -/* 6f - _6F */ 0x2064, -/* 70 - _70 */ 0x2065, -/* 71 - _71 */ 0x2066, -/* 72 - _72 */ 0x2067, -/* 73 - _73 */ 0x2068, -/* 74 - _74 */ 0x2069, -/* 75 - _75 */ 0x206a, -/* 76 - _76 */ 0x206b, -/* 77 - _77 */ 0x206c, -/* 78 - _78 */ 0x206d, -/* 79 - _79 */ 0x206e, -/* 7a - _7A */ 0x206f, -/* 7b - _7B */ 0x2070, -/* 7c - _7C */ 0x2071, -/* 7d - _7D */ 0x2072, -/* 7e - _7E */ 0x2073, -/* 7f - _7F */ 0x2074, -/* 80 - _80 */ 0x6200, -/* 81 - _81 */ 0x6208, -/* 82 - _82 */ 0x6210, -/* 83 - _83 */ 0x6218, -/* 84 - _84 */ 0x2075, -/* 85 - _85 */ 0x2076, -/* 86 - _86 */ 0x2077, -/* 87 - _87 */ 0x2078, -/* 88 - _88 */ 0x2079, -/* 89 - _89 */ 0x207a, -/* 8a - _8A */ 0x207b, -/* 8b - _8B */ 0x207c, -/* 8c - _8C */ 0x207d, -/* 8d - _8D */ 0x207e, -/* 8e - _8E */ 0x207f, -/* 8f - _8F */ 0x6220, -/* 90 - _90 */ 0x2080, -/* 91 - _91 */ 0x2081, -/* 92 - _92 */ 0x2082, -/* 93 - _93 */ 0x2083, -/* 94 - _94 */ 0x2084, -/* 95 - _95 */ 0x2085, -/* 96 - _96 */ 0x2086, -/* 97 - _97 */ 0x2087, -/* 98 - _98 */ 0x4002, -/* 99 - _99 */ 0x4003, -/* 9a - _9A */ 0x2088, -/* 9b - */ 0, -/* 9c - _9C */ 0x2089, -/* 9d - _9D */ 0x208a, -/* 9e - _9E */ 0x208b, -/* 9f - _9F */ 0x208c, -/* a0 - _A0 */ 0x208d, -/* a1 - _A1 */ 0x208e, -/* a2 - _A2 */ 0x208f, -/* a3 - _A3 */ 0x2090, -/* a4 - _A4 */ 0x2091, -/* a5 - _A5 */ 0x2092, -/* a6 - _A6 */ 0x2093, -/* a7 - _A7 */ 0x2094, -/* a8 - _A8 */ 0x2095, -/* a9 - _A9 */ 0x2096, -/* aa - _AA */ 0x2097, -/* ab - _AB */ 0x2098, -/* ac - _AC */ 0x2099, -/* ad - _AD */ 0x209a, -/* ae - _AE */ 0x209b, -/* af - _AF */ 0x209c, -/* b0 - _B0 */ 0x209d, -/* b1 - _B0 */ 0x209e, -/* b2 - _B0 */ 0x209f, -/* b3 - _B0 */ 0x20a0, -/* b4 - _B0 */ 0x20a1, -/* b5 - _B0 */ 0x20a2, -/* b6 - _B0 */ 0x20a3, -/* b7 - _B0 */ 0x20a4, -/* b8 - _B8 */ 0x20a5, -/* b9 - _B8 */ 0x20a6, -/* ba - _B8 */ 0x20a7, -/* bb - _B8 */ 0x20a8, -/* bc - _B8 */ 0x20a9, -/* bd - _B8 */ 0x20aa, -/* be - _B8 */ 0x20ab, -/* bf - _B8 */ 0x20ac, -/* c0 - _C0 */ 0x6228, -/* c1 - _C1 */ 0x6230, -/* c2 - _C2 */ 0x20ad, -/* c3 - _C3 */ 0x20ae, -/* c4 - _C4 */ 0x20af, -/* c5 - _C5 */ 0x20b0, -/* c6 - _C6 */ 0x6238, -/* c7 - _C7 */ 0x6240, -/* c8 - _C8 */ 0x20b1, -/* c9 - _C9 */ 0x20b2, -/* ca - _CA */ 0x20b3, -/* cb - _CB */ 0x20b4, -/* cc - _CC */ 0x20b5, -/* cd - _CD */ 0x20b6, -/* ce - _CE */ 0x20b7, -/* cf - _CF */ 0x20b8, -/* d0 - _D0 */ 0x6248, -/* d1 - _D1 */ 0x6250, -/* d2 - _D2 */ 0x6258, -/* d3 - _D3 */ 0x6260, -/* d4 - _D4 */ 0x20b9, -/* d5 - _D5 */ 0x20ba, -/* d6 - _D6 */ 0x20bb, -/* d7 - _D7 */ 0x20bc, -/* d8 - _D8 */ 0xa268, -/* d9 - _D9 */ 0xa2b0, -/* da - _DA */ 0xa2f8, -/* db - _DB */ 0xa340, -/* dc - _DC */ 0xa388, -/* dd - _DD */ 0xa3d0, -/* de - _DE */ 0xa418, -/* df - _DF */ 0xa460, -/* e0 - _E0 */ 0x20bd, -/* e1 - _E1 */ 0x20be, -/* e2 - _E2 */ 0x20bf, -/* e3 - _E3 */ 0x4004, -/* e4 - _E4 */ 0x20c0, -/* e5 - _E5 */ 0x20c1, -/* e6 - _E6 */ 0x20c2, -/* e7 - _E7 */ 0x20c3, -/* e8 - _E8 */ 0x20c4, -/* e9 - _E9 */ 0x20c5, -/* ea - _EA */ 0x20c6, -/* eb - _EB */ 0x20c7, -/* ec - _EC */ 0x20c8, -/* ed - _ED */ 0x20c9, -/* ee - _EE */ 0x20ca, -/* ef - _EF */ 0x20cb, -/* f0 - */ 0, -/* f1 - _F1 */ 0x20cc, -/* f2 - */ 0, -/* f3 - */ 0, -/* f4 - _F4 */ 0x20cd, -/* f5 - _F5 */ 0x20ce, -/* f6 - _F6 */ 0x64a8, -/* f7 - _F7 */ 0x64b0, -/* f8 - _F8 */ 0x20cf, -/* f9 - _F9 */ 0x20d0, -/* fa - _FA */ 0x20d1, -/* fb - _FB */ 0x20d2, -/* fc - _FC */ 0x20d3, -/* fd - _FD */ 0x20d4, -/* fe - _FE */ 0x64b8, -/* ff - _FF */ 0x64c0, -/* 100 - _0F_00 */ 0x64c8, -/* 101 - _0F_01 */ 0xa4d0, -/* 102 - _0F_02 */ 0x20d5, -/* 103 - _0F_03 */ 0x20d6, -/* 104 - */ 0, -/* 105 - _0F_05 */ 0x20d7, -/* 106 - _0F_06 */ 0x20d8, -/* 107 - _0F_07 */ 0x20d9, -/* 108 - _0F_08 */ 0x20da, -/* 109 - _0F_09 */ 0x20db, -/* 10a - */ 0, -/* 10b - _0F_0B */ 0x20dc, -/* 10c - */ 0, -/* 10d - _0F_0D */ 0x6518, -/* 10e - _0F_0E */ 0x20dd, -/* 10f - _0F_0F */ 0x8520, -/* 110 - _0F_10 */ 0xc620, -/* 111 - _0F_11 */ 0xc62c, -/* 112 - _0F_12 */ 0xc638, -/* 113 - _0F_13 */ 0xc644, -/* 114 - _0F_14 */ 0xc650, -/* 115 - _0F_15 */ 0xc65c, -/* 116 - _0F_16 */ 0xc668, -/* 117 - _0F_17 */ 0xc674, -/* 118 - _0F_18 */ 0x6680, -/* 119 - */ 0, -/* 11a - */ 0, -/* 11b - */ 0, -/* 11c - */ 0, -/* 11d - */ 0, -/* 11e - */ 0, -/* 11f - _0F_1F */ 0x20de, -/* 120 - _0F_20 */ 0x20df, -/* 121 - _0F_21 */ 0x20e0, -/* 122 - _0F_22 */ 0x20e1, -/* 123 - _0F_23 */ 0x20e2, -/* 124 - */ 0, -/* 125 - */ 0, -/* 126 - */ 0, -/* 127 - */ 0, -/* 128 - _0F_28 */ 0xc688, -/* 129 - _0F_29 */ 0xc694, -/* 12a - _0F_2A */ 0xc6a0, -/* 12b - _0F_2B */ 0xc6ac, -/* 12c - _0F_2C */ 0xc6b8, -/* 12d - _0F_2D */ 0xc6c4, -/* 12e - _0F_2E */ 0xc6d0, -/* 12f - _0F_2F */ 0xc6dc, -/* 130 - _0F_30 */ 0x20e3, -/* 131 - _0F_31 */ 0x20e4, -/* 132 - _0F_32 */ 0x20e5, -/* 133 - _0F_33 */ 0x20e6, -/* 134 - _0F_34 */ 0x20e7, -/* 135 - _0F_35 */ 0x20e8, -/* 136 - */ 0, -/* 137 - _0F_37 */ 0x20e9, -/* 138 - _0F_38 */ 0x86e8, -/* 139 - */ 0, -/* 13a - _0F_3A */ 0x87e8, -/* 13b - */ 0, -/* 13c - */ 0, -/* 13d - */ 0, -/* 13e - */ 0, -/* 13f - */ 0, -/* 140 - _0F_40 */ 0x20ea, -/* 141 - _0F_41 */ 0x20eb, -/* 142 - _0F_42 */ 0x20ec, -/* 143 - _0F_43 */ 0x20ed, -/* 144 - _0F_44 */ 0x20ee, -/* 145 - _0F_45 */ 0x20ef, -/* 146 - _0F_46 */ 0x20f0, -/* 147 - _0F_47 */ 0x20f1, -/* 148 - _0F_48 */ 0x20f2, -/* 149 - _0F_49 */ 0x20f3, -/* 14a - _0F_4A */ 0x20f4, -/* 14b - _0F_4B */ 0x20f5, -/* 14c - _0F_4C */ 0x20f6, -/* 14d - _0F_4D */ 0x20f7, -/* 14e - _0F_4E */ 0x20f8, -/* 14f - _0F_4F */ 0x20f9, -/* 150 - _0F_50 */ 0xc8e8, -/* 151 - _0F_51 */ 0xc8f4, -/* 152 - _0F_52 */ 0xc900, -/* 153 - _0F_53 */ 0xc90c, -/* 154 - _0F_54 */ 0xc918, -/* 155 - _0F_55 */ 0xc924, -/* 156 - _0F_56 */ 0xc930, -/* 157 - _0F_57 */ 0xc93c, -/* 158 - _0F_58 */ 0xc948, -/* 159 - _0F_59 */ 0xc954, -/* 15a - _0F_5A */ 0xc960, -/* 15b - _0F_5B */ 0xc96c, -/* 15c - _0F_5C */ 0xc978, -/* 15d - _0F_5D */ 0xc984, -/* 15e - _0F_5E */ 0xc990, -/* 15f - _0F_5F */ 0xc99c, -/* 160 - _0F_60 */ 0xc9a8, -/* 161 - _0F_61 */ 0xc9b4, -/* 162 - _0F_62 */ 0xc9c0, -/* 163 - _0F_63 */ 0xc9cc, -/* 164 - _0F_64 */ 0xc9d8, -/* 165 - _0F_65 */ 0xc9e4, -/* 166 - _0F_66 */ 0xc9f0, -/* 167 - _0F_67 */ 0xc9fc, -/* 168 - _0F_68 */ 0xca08, -/* 169 - _0F_69 */ 0xca14, -/* 16a - _0F_6A */ 0xca20, -/* 16b - _0F_6B */ 0xca2c, -/* 16c - _0F_6C */ 0xca38, -/* 16d - _0F_6D */ 0xca44, -/* 16e - _0F_6E */ 0xca50, -/* 16f - _0F_6F */ 0xca5c, -/* 170 - _0F_70 */ 0xca68, -/* 171 - _0F_71 */ 0x6a74, -/* 172 - _0F_72 */ 0x6a7c, -/* 173 - _0F_73 */ 0x6a84, -/* 174 - _0F_74 */ 0xca8c, -/* 175 - _0F_75 */ 0xca98, -/* 176 - _0F_76 */ 0xcaa4, -/* 177 - _0F_77 */ 0xcab0, -/* 178 - _0F_78 */ 0xcabc, -/* 179 - _0F_79 */ 0xcac8, -/* 17a - _0F_7A */ 0x8ad4, -/* 17b - */ 0, -/* 17c - _0F_7C */ 0xcbd4, -/* 17d - _0F_7D */ 0xcbe0, -/* 17e - _0F_7E */ 0xcbec, -/* 17f - _0F_7F */ 0xcbf8, -/* 180 - _0F_80 */ 0x20fa, -/* 181 - _0F_81 */ 0x20fb, -/* 182 - _0F_82 */ 0x20fc, -/* 183 - _0F_83 */ 0x20fd, -/* 184 - _0F_84 */ 0x20fe, -/* 185 - _0F_85 */ 0x20ff, -/* 186 - _0F_86 */ 0x2100, -/* 187 - _0F_87 */ 0x2101, -/* 188 - _0F_88 */ 0x2102, -/* 189 - _0F_89 */ 0x2103, -/* 18a - _0F_8A */ 0x2104, -/* 18b - _0F_8B */ 0x2105, -/* 18c - _0F_8C */ 0x2106, -/* 18d - _0F_8D */ 0x2107, -/* 18e - _0F_8E */ 0x2108, -/* 18f - _0F_8F */ 0x2109, -/* 190 - _0F_90 */ 0x210a, -/* 191 - _0F_91 */ 0x210b, -/* 192 - _0F_92 */ 0x210c, -/* 193 - _0F_93 */ 0x210d, -/* 194 - _0F_94 */ 0x210e, -/* 195 - _0F_95 */ 0x210f, -/* 196 - _0F_96 */ 0x2110, -/* 197 - _0F_97 */ 0x2111, -/* 198 - _0F_98 */ 0x2112, -/* 199 - _0F_99 */ 0x2113, -/* 19a - _0F_9A */ 0x2114, -/* 19b - _0F_9B */ 0x2115, -/* 19c - _0F_9C */ 0x2116, -/* 19d - _0F_9D */ 0x2117, -/* 19e - _0F_9E */ 0x2118, -/* 19f - _0F_9F */ 0x2119, -/* 1a0 - _0F_A0 */ 0x211a, -/* 1a1 - _0F_A1 */ 0x211b, -/* 1a2 - _0F_A2 */ 0x211c, -/* 1a3 - _0F_A3 */ 0x211d, -/* 1a4 - _0F_A4 */ 0x4005, -/* 1a5 - _0F_A5 */ 0x4006, -/* 1a6 - */ 0, -/* 1a7 - */ 0, -/* 1a8 - _0F_A8 */ 0x211e, -/* 1a9 - _0F_A9 */ 0x211f, -/* 1aa - _0F_AA */ 0x2120, -/* 1ab - _0F_AB */ 0x2121, -/* 1ac - _0F_AC */ 0x4007, -/* 1ad - _0F_AD */ 0x4008, -/* 1ae - _0F_AE */ 0x6c04, -/* 1af - _0F_AF */ 0x2122, -/* 1b0 - _0F_B0 */ 0x2123, -/* 1b1 - _0F_B1 */ 0x2124, -/* 1b2 - _0F_B2 */ 0x2125, -/* 1b3 - _0F_B3 */ 0x2126, -/* 1b4 - _0F_B4 */ 0x2127, -/* 1b5 - _0F_B5 */ 0x2128, -/* 1b6 - _0F_B6 */ 0x2129, -/* 1b7 - _0F_B7 */ 0x212a, -/* 1b8 - _0F_B8 */ 0xcc0c, -/* 1b9 - _0F_B9 */ 0x212b, -/* 1ba - _0F_BA */ 0x6c18, -/* 1bb - _0F_BB */ 0x212c, -/* 1bc - _0F_BC */ 0xcc20, -/* 1bd - _0F_BD */ 0xcc2c, -/* 1be - _0F_BE */ 0x212d, -/* 1bf - _0F_BF */ 0x212e, -/* 1c0 - _0F_C0 */ 0x212f, -/* 1c1 - _0F_C1 */ 0x2130, -/* 1c2 - _0F_C2 */ 0xcc38, -/* 1c3 - _0F_C3 */ 0x2131, -/* 1c4 - _0F_C4 */ 0xcc44, -/* 1c5 - _0F_C5 */ 0xcc50, -/* 1c6 - _0F_C6 */ 0xcc5c, -/* 1c7 - _0F_C7 */ 0x6c68, -/* 1c8 - _0F_C8 */ 0x2132, -/* 1c9 - _0F_C8 */ 0x2133, -/* 1ca - _0F_C8 */ 0x2134, -/* 1cb - _0F_C8 */ 0x2135, -/* 1cc - _0F_C8 */ 0x2136, -/* 1cd - _0F_C8 */ 0x2137, -/* 1ce - _0F_C8 */ 0x2138, -/* 1cf - _0F_C8 */ 0x2139, -/* 1d0 - _0F_D0 */ 0xcc70, -/* 1d1 - _0F_D1 */ 0xcc7c, -/* 1d2 - _0F_D2 */ 0xcc88, -/* 1d3 - _0F_D3 */ 0xcc94, -/* 1d4 - _0F_D4 */ 0xcca0, -/* 1d5 - _0F_D5 */ 0xccac, -/* 1d6 - _0F_D6 */ 0xccb8, -/* 1d7 - _0F_D7 */ 0xccc4, -/* 1d8 - _0F_D8 */ 0xccd0, -/* 1d9 - _0F_D9 */ 0xccdc, -/* 1da - _0F_DA */ 0xcce8, -/* 1db - _0F_DB */ 0xccf4, -/* 1dc - _0F_DC */ 0xcd00, -/* 1dd - _0F_DD */ 0xcd0c, -/* 1de - _0F_DE */ 0xcd18, -/* 1df - _0F_DF */ 0xcd24, -/* 1e0 - _0F_E0 */ 0xcd30, -/* 1e1 - _0F_E1 */ 0xcd3c, -/* 1e2 - _0F_E2 */ 0xcd48, -/* 1e3 - _0F_E3 */ 0xcd54, -/* 1e4 - _0F_E4 */ 0xcd60, -/* 1e5 - _0F_E5 */ 0xcd6c, -/* 1e6 - _0F_E6 */ 0xcd78, -/* 1e7 - _0F_E7 */ 0xcd84, -/* 1e8 - _0F_E8 */ 0xcd90, -/* 1e9 - _0F_E9 */ 0xcd9c, -/* 1ea - _0F_EA */ 0xcda8, -/* 1eb - _0F_EB */ 0xcdb4, -/* 1ec - _0F_EC */ 0xcdc0, -/* 1ed - _0F_ED */ 0xcdcc, -/* 1ee - _0F_EE */ 0xcdd8, -/* 1ef - _0F_EF */ 0xcde4, -/* 1f0 - _0F_F0 */ 0xcdf0, -/* 1f1 - _0F_F1 */ 0xcdfc, -/* 1f2 - _0F_F2 */ 0xce08, -/* 1f3 - _0F_F3 */ 0xce14, -/* 1f4 - _0F_F4 */ 0xce20, -/* 1f5 - _0F_F5 */ 0xce2c, -/* 1f6 - _0F_F6 */ 0xce38, -/* 1f7 - _0F_F7 */ 0xce44, -/* 1f8 - _0F_F8 */ 0xce50, -/* 1f9 - _0F_F9 */ 0xce5c, -/* 1fa - _0F_FA */ 0xce68, -/* 1fb - _0F_FB */ 0xce74, -/* 1fc - _0F_FC */ 0xce80, -/* 1fd - _0F_FD */ 0xce8c, -/* 1fe - _0F_FE */ 0xce98, -/* 1ff - */ 0, -/* 200 - _80_00 */ 0x213a, -/* 201 - _80_01 */ 0x213b, -/* 202 - _80_02 */ 0x213c, -/* 203 - _80_03 */ 0x213d, -/* 204 - _80_04 */ 0x213e, -/* 205 - _80_05 */ 0x213f, -/* 206 - _80_06 */ 0x2140, -/* 207 - _80_07 */ 0x2141, -/* 208 - _81_00 */ 0x2142, -/* 209 - _81_01 */ 0x2143, -/* 20a - _81_02 */ 0x2144, -/* 20b - _81_03 */ 0x2145, -/* 20c - _81_04 */ 0x2146, -/* 20d - _81_05 */ 0x2147, -/* 20e - _81_06 */ 0x2148, -/* 20f - _81_07 */ 0x2149, -/* 210 - _82_00 */ 0x214a, -/* 211 - _82_01 */ 0x214b, -/* 212 - _82_02 */ 0x214c, -/* 213 - _82_03 */ 0x214d, -/* 214 - _82_04 */ 0x214e, -/* 215 - _82_05 */ 0x214f, -/* 216 - _82_06 */ 0x2150, -/* 217 - _82_07 */ 0x2151, -/* 218 - _83_00 */ 0x2152, -/* 219 - _83_01 */ 0x2153, -/* 21a - _83_02 */ 0x2154, -/* 21b - _83_03 */ 0x2155, -/* 21c - _83_04 */ 0x2156, -/* 21d - _83_05 */ 0x2157, -/* 21e - _83_06 */ 0x2158, -/* 21f - _83_07 */ 0x2159, -/* 220 - _8F_00 */ 0x215a, -/* 221 - */ 0, -/* 222 - */ 0, -/* 223 - */ 0, -/* 224 - */ 0, -/* 225 - */ 0, -/* 226 - */ 0, -/* 227 - */ 0, -/* 228 - _C0_00 */ 0x215b, -/* 229 - _C0_01 */ 0x215c, -/* 22a - _C0_02 */ 0x215d, -/* 22b - _C0_03 */ 0x215e, -/* 22c - _C0_04 */ 0x215f, -/* 22d - _C0_05 */ 0x2160, -/* 22e - _C0_06 */ 0x2161, -/* 22f - _C0_07 */ 0x2162, -/* 230 - _C1_00 */ 0x2163, -/* 231 - _C1_01 */ 0x2164, -/* 232 - _C1_02 */ 0x2165, -/* 233 - _C1_03 */ 0x2166, -/* 234 - _C1_04 */ 0x2167, -/* 235 - _C1_05 */ 0x2168, -/* 236 - _C1_06 */ 0x2169, -/* 237 - _C1_07 */ 0x216a, -/* 238 - _C6_00 */ 0x216b, -/* 239 - */ 0, -/* 23a - */ 0, -/* 23b - */ 0, -/* 23c - */ 0, -/* 23d - */ 0, -/* 23e - */ 0, -/* 23f - */ 0, -/* 240 - _C7_00 */ 0x216c, -/* 241 - */ 0, -/* 242 - */ 0, -/* 243 - */ 0, -/* 244 - */ 0, -/* 245 - */ 0, -/* 246 - */ 0, -/* 247 - */ 0, -/* 248 - _D0_00 */ 0x216d, -/* 249 - _D0_01 */ 0x216e, -/* 24a - _D0_02 */ 0x216f, -/* 24b - _D0_03 */ 0x2170, -/* 24c - _D0_04 */ 0x2171, -/* 24d - _D0_05 */ 0x2172, -/* 24e - _D0_06 */ 0x2173, -/* 24f - _D0_07 */ 0x2174, -/* 250 - _D1_00 */ 0x2175, -/* 251 - _D1_01 */ 0x2176, -/* 252 - _D1_02 */ 0x2177, -/* 253 - _D1_03 */ 0x2178, -/* 254 - _D1_04 */ 0x2179, -/* 255 - _D1_05 */ 0x217a, -/* 256 - _D1_06 */ 0x217b, -/* 257 - _D1_07 */ 0x217c, -/* 258 - _D2_00 */ 0x217d, -/* 259 - _D2_01 */ 0x217e, -/* 25a - _D2_02 */ 0x217f, -/* 25b - _D2_03 */ 0x2180, -/* 25c - _D2_04 */ 0x2181, -/* 25d - _D2_05 */ 0x2182, -/* 25e - _D2_06 */ 0x2183, -/* 25f - _D2_07 */ 0x2184, -/* 260 - _D3_00 */ 0x2185, -/* 261 - _D3_01 */ 0x2186, -/* 262 - _D3_02 */ 0x2187, -/* 263 - _D3_03 */ 0x2188, -/* 264 - _D3_04 */ 0x2189, -/* 265 - _D3_05 */ 0x218a, -/* 266 - _D3_06 */ 0x218b, -/* 267 - _D3_07 */ 0x218c, -/* 268 - _D8_00 */ 0x218d, -/* 269 - _D8_01 */ 0x218e, -/* 26a - _D8_02 */ 0x218f, -/* 26b - _D8_03 */ 0x2190, -/* 26c - _D8_04 */ 0x2191, -/* 26d - _D8_05 */ 0x2192, -/* 26e - _D8_06 */ 0x2193, -/* 26f - _D8_07 */ 0x2194, -/* 270 - _D8_C0 */ 0x2195, -/* 271 - _D8_C0 */ 0x2196, -/* 272 - _D8_C0 */ 0x2197, -/* 273 - _D8_C0 */ 0x2198, -/* 274 - _D8_C0 */ 0x2199, -/* 275 - _D8_C0 */ 0x219a, -/* 276 - _D8_C0 */ 0x219b, -/* 277 - _D8_C0 */ 0x219c, -/* 278 - _D8_C8 */ 0x219d, -/* 279 - _D8_C8 */ 0x219e, -/* 27a - _D8_C8 */ 0x219f, -/* 27b - _D8_C8 */ 0x21a0, -/* 27c - _D8_C8 */ 0x21a1, -/* 27d - _D8_C8 */ 0x21a2, -/* 27e - _D8_C8 */ 0x21a3, -/* 27f - _D8_C8 */ 0x21a4, -/* 280 - _D8_D0 */ 0x21a5, -/* 281 - _D8_D0 */ 0x21a6, -/* 282 - _D8_D0 */ 0x21a7, -/* 283 - _D8_D0 */ 0x21a8, -/* 284 - _D8_D0 */ 0x21a9, -/* 285 - _D8_D0 */ 0x21aa, -/* 286 - _D8_D0 */ 0x21ab, -/* 287 - _D8_D0 */ 0x21ac, -/* 288 - _D8_D8 */ 0x21ad, -/* 289 - _D8_D9 */ 0x21ae, -/* 28a - _D8_D8 */ 0x21af, -/* 28b - _D8_D8 */ 0x21b0, -/* 28c - _D8_D8 */ 0x21b1, -/* 28d - _D8_D8 */ 0x21b2, -/* 28e - _D8_D8 */ 0x21b3, -/* 28f - _D8_D8 */ 0x21b4, -/* 290 - _D8_E0 */ 0x21b5, -/* 291 - _D8_E0 */ 0x21b6, -/* 292 - _D8_E0 */ 0x21b7, -/* 293 - _D8_E0 */ 0x21b8, -/* 294 - _D8_E0 */ 0x21b9, -/* 295 - _D8_E0 */ 0x21ba, -/* 296 - _D8_E0 */ 0x21bb, -/* 297 - _D8_E0 */ 0x21bc, -/* 298 - _D8_E8 */ 0x21bd, -/* 299 - _D8_E8 */ 0x21be, -/* 29a - _D8_E8 */ 0x21bf, -/* 29b - _D8_E8 */ 0x21c0, -/* 29c - _D8_E8 */ 0x21c1, -/* 29d - _D8_E8 */ 0x21c2, -/* 29e - _D8_E8 */ 0x21c3, -/* 29f - _D8_E8 */ 0x21c4, -/* 2a0 - _D8_F0 */ 0x21c5, -/* 2a1 - _D8_F0 */ 0x21c6, -/* 2a2 - _D8_F0 */ 0x21c7, -/* 2a3 - _D8_F0 */ 0x21c8, -/* 2a4 - _D8_F0 */ 0x21c9, -/* 2a5 - _D8_F0 */ 0x21ca, -/* 2a6 - _D8_F0 */ 0x21cb, -/* 2a7 - _D8_F0 */ 0x21cc, -/* 2a8 - _D8_F8 */ 0x21cd, -/* 2a9 - _D8_F8 */ 0x21ce, -/* 2aa - _D8_F8 */ 0x21cf, -/* 2ab - _D8_F8 */ 0x21d0, -/* 2ac - _D8_F8 */ 0x21d1, -/* 2ad - _D8_F8 */ 0x21d2, -/* 2ae - _D8_F8 */ 0x21d3, -/* 2af - _D8_F8 */ 0x21d4, -/* 2b0 - _D9_00 */ 0x21d5, -/* 2b1 - */ 0, -/* 2b2 - _D9_02 */ 0x21d6, -/* 2b3 - _D9_03 */ 0x21d7, -/* 2b4 - _D9_04 */ 0x21d8, -/* 2b5 - _D9_05 */ 0x21d9, -/* 2b6 - _D9_06 */ 0xcea4, -/* 2b7 - _D9_07 */ 0xceb0, -/* 2b8 - _D9_C0 */ 0x21da, -/* 2b9 - _D9_C0 */ 0x21db, -/* 2ba - _D9_C0 */ 0x21dc, -/* 2bb - _D9_C0 */ 0x21dd, -/* 2bc - _D9_C0 */ 0x21de, -/* 2bd - _D9_C0 */ 0x21df, -/* 2be - _D9_C0 */ 0x21e0, -/* 2bf - _D9_C0 */ 0x21e1, -/* 2c0 - _D9_C8 */ 0x21e2, -/* 2c1 - _D9_C9 */ 0x21e3, -/* 2c2 - _D9_C8 */ 0x21e4, -/* 2c3 - _D9_C8 */ 0x21e5, -/* 2c4 - _D9_C8 */ 0x21e6, -/* 2c5 - _D9_C8 */ 0x21e7, -/* 2c6 - _D9_C8 */ 0x21e8, -/* 2c7 - _D9_C8 */ 0x21e9, -/* 2c8 - _D9_D0 */ 0x21ea, -/* 2c9 - */ 0, -/* 2ca - */ 0, -/* 2cb - */ 0, -/* 2cc - */ 0, -/* 2cd - */ 0, -/* 2ce - */ 0, -/* 2cf - */ 0, -/* 2d0 - */ 0, -/* 2d1 - */ 0, -/* 2d2 - */ 0, -/* 2d3 - */ 0, -/* 2d4 - */ 0, -/* 2d5 - */ 0, -/* 2d6 - */ 0, -/* 2d7 - */ 0, -/* 2d8 - _D9_E0 */ 0x21eb, -/* 2d9 - _D9_E1 */ 0x21ec, -/* 2da - */ 0, -/* 2db - */ 0, -/* 2dc - _D9_E4 */ 0x21ed, -/* 2dd - _D9_E5 */ 0x21ee, -/* 2de - */ 0, -/* 2df - */ 0, -/* 2e0 - _D9_E8 */ 0x21ef, -/* 2e1 - _D9_E9 */ 0x21f0, -/* 2e2 - _D9_EA */ 0x21f1, -/* 2e3 - _D9_EB */ 0x21f2, -/* 2e4 - _D9_EC */ 0x21f3, -/* 2e5 - _D9_ED */ 0x21f4, -/* 2e6 - _D9_EE */ 0x21f5, -/* 2e7 - */ 0, -/* 2e8 - _D9_F0 */ 0x21f6, -/* 2e9 - _D9_F1 */ 0x21f7, -/* 2ea - _D9_F2 */ 0x21f8, -/* 2eb - _D9_F3 */ 0x21f9, -/* 2ec - _D9_F4 */ 0x21fa, -/* 2ed - _D9_F5 */ 0x21fb, -/* 2ee - _D9_F6 */ 0x21fc, -/* 2ef - _D9_F7 */ 0x21fd, -/* 2f0 - _D9_F8 */ 0x21fe, -/* 2f1 - _D9_F9 */ 0x21ff, -/* 2f2 - _D9_FA */ 0x2200, -/* 2f3 - _D9_FB */ 0x2201, -/* 2f4 - _D9_FC */ 0x2202, -/* 2f5 - _D9_FD */ 0x2203, -/* 2f6 - _D9_FE */ 0x2204, -/* 2f7 - _D9_FF */ 0x2205, -/* 2f8 - _DA_00 */ 0x2206, -/* 2f9 - _DA_01 */ 0x2207, -/* 2fa - _DA_02 */ 0x2208, -/* 2fb - _DA_03 */ 0x2209, -/* 2fc - _DA_04 */ 0x220a, -/* 2fd - _DA_05 */ 0x220b, -/* 2fe - _DA_06 */ 0x220c, -/* 2ff - _DA_07 */ 0x220d, -/* 300 - _DA_C0 */ 0x220e, -/* 301 - _DA_C0 */ 0x220f, -/* 302 - _DA_C0 */ 0x2210, -/* 303 - _DA_C0 */ 0x2211, -/* 304 - _DA_C0 */ 0x2212, -/* 305 - _DA_C0 */ 0x2213, -/* 306 - _DA_C0 */ 0x2214, -/* 307 - _DA_C0 */ 0x2215, -/* 308 - _DA_C8 */ 0x2216, -/* 309 - _DA_C8 */ 0x2217, -/* 30a - _DA_C8 */ 0x2218, -/* 30b - _DA_C8 */ 0x2219, -/* 30c - _DA_C8 */ 0x221a, -/* 30d - _DA_C8 */ 0x221b, -/* 30e - _DA_C8 */ 0x221c, -/* 30f - _DA_C8 */ 0x221d, -/* 310 - _DA_D0 */ 0x221e, -/* 311 - _DA_D0 */ 0x221f, -/* 312 - _DA_D0 */ 0x2220, -/* 313 - _DA_D0 */ 0x2221, -/* 314 - _DA_D0 */ 0x2222, -/* 315 - _DA_D0 */ 0x2223, -/* 316 - _DA_D0 */ 0x2224, -/* 317 - _DA_D0 */ 0x2225, -/* 318 - _DA_D8 */ 0x2226, -/* 319 - _DA_D8 */ 0x2227, -/* 31a - _DA_D8 */ 0x2228, -/* 31b - _DA_D8 */ 0x2229, -/* 31c - _DA_D8 */ 0x222a, -/* 31d - _DA_D8 */ 0x222b, -/* 31e - _DA_D8 */ 0x222c, -/* 31f - _DA_D8 */ 0x222d, -/* 320 - */ 0, -/* 321 - */ 0, -/* 322 - */ 0, -/* 323 - */ 0, -/* 324 - */ 0, -/* 325 - */ 0, -/* 326 - */ 0, -/* 327 - */ 0, -/* 328 - */ 0, -/* 329 - _DA_E9 */ 0x222e, -/* 32a - */ 0, -/* 32b - */ 0, -/* 32c - */ 0, -/* 32d - */ 0, -/* 32e - */ 0, -/* 32f - */ 0, -/* 330 - */ 0, -/* 331 - */ 0, -/* 332 - */ 0, -/* 333 - */ 0, -/* 334 - */ 0, -/* 335 - */ 0, -/* 336 - */ 0, -/* 337 - */ 0, -/* 338 - */ 0, -/* 339 - */ 0, -/* 33a - */ 0, -/* 33b - */ 0, -/* 33c - */ 0, -/* 33d - */ 0, -/* 33e - */ 0, -/* 33f - */ 0, -/* 340 - _DB_00 */ 0x222f, -/* 341 - _DB_01 */ 0x2230, -/* 342 - _DB_02 */ 0x2231, -/* 343 - _DB_03 */ 0x2232, -/* 344 - */ 0, -/* 345 - _DB_05 */ 0x2233, -/* 346 - */ 0, -/* 347 - _DB_07 */ 0x2234, -/* 348 - _DB_C0 */ 0x2235, -/* 349 - _DB_C0 */ 0x2236, -/* 34a - _DB_C0 */ 0x2237, -/* 34b - _DB_C0 */ 0x2238, -/* 34c - _DB_C0 */ 0x2239, -/* 34d - _DB_C0 */ 0x223a, -/* 34e - _DB_C0 */ 0x223b, -/* 34f - _DB_C0 */ 0x223c, -/* 350 - _DB_C8 */ 0x223d, -/* 351 - _DB_C8 */ 0x223e, -/* 352 - _DB_C8 */ 0x223f, -/* 353 - _DB_C8 */ 0x2240, -/* 354 - _DB_C8 */ 0x2241, -/* 355 - _DB_C8 */ 0x2242, -/* 356 - _DB_C8 */ 0x2243, -/* 357 - _DB_C8 */ 0x2244, -/* 358 - _DB_D0 */ 0x2245, -/* 359 - _DB_D0 */ 0x2246, -/* 35a - _DB_D0 */ 0x2247, -/* 35b - _DB_D0 */ 0x2248, -/* 35c - _DB_D0 */ 0x2249, -/* 35d - _DB_D0 */ 0x224a, -/* 35e - _DB_D0 */ 0x224b, -/* 35f - _DB_D0 */ 0x224c, -/* 360 - _DB_D8 */ 0x224d, -/* 361 - _DB_D8 */ 0x224e, -/* 362 - _DB_D8 */ 0x224f, -/* 363 - _DB_D8 */ 0x2250, -/* 364 - _DB_D8 */ 0x2251, -/* 365 - _DB_D8 */ 0x2252, -/* 366 - _DB_D8 */ 0x2253, -/* 367 - _DB_D8 */ 0x2254, -/* 368 - _DB_E0 */ 0x2255, -/* 369 - _DB_E1 */ 0x2256, -/* 36a - _DB_E2 */ 0xcebc, -/* 36b - _DB_E3 */ 0xcec8, -/* 36c - _DB_E4 */ 0x2257, -/* 36d - */ 0, -/* 36e - */ 0, -/* 36f - */ 0, -/* 370 - _DB_E8 */ 0x2258, -/* 371 - _DB_E8 */ 0x2259, -/* 372 - _DB_E8 */ 0x225a, -/* 373 - _DB_E8 */ 0x225b, -/* 374 - _DB_E8 */ 0x225c, -/* 375 - _DB_E8 */ 0x225d, -/* 376 - _DB_E8 */ 0x225e, -/* 377 - _DB_E8 */ 0x225f, -/* 378 - _DB_F0 */ 0x2260, -/* 379 - _DB_F0 */ 0x2261, -/* 37a - _DB_F0 */ 0x2262, -/* 37b - _DB_F0 */ 0x2263, -/* 37c - _DB_F0 */ 0x2264, -/* 37d - _DB_F0 */ 0x2265, -/* 37e - _DB_F0 */ 0x2266, -/* 37f - _DB_F0 */ 0x2267, -/* 380 - */ 0, -/* 381 - */ 0, -/* 382 - */ 0, -/* 383 - */ 0, -/* 384 - */ 0, -/* 385 - */ 0, -/* 386 - */ 0, -/* 387 - */ 0, -/* 388 - _DC_00 */ 0x2268, -/* 389 - _DC_01 */ 0x2269, -/* 38a - _DC_02 */ 0x226a, -/* 38b - _DC_03 */ 0x226b, -/* 38c - _DC_04 */ 0x226c, -/* 38d - _DC_05 */ 0x226d, -/* 38e - _DC_06 */ 0x226e, -/* 38f - _DC_07 */ 0x226f, -/* 390 - _DC_C0 */ 0x2270, -/* 391 - _DC_C0 */ 0x2271, -/* 392 - _DC_C0 */ 0x2272, -/* 393 - _DC_C0 */ 0x2273, -/* 394 - _DC_C0 */ 0x2274, -/* 395 - _DC_C0 */ 0x2275, -/* 396 - _DC_C0 */ 0x2276, -/* 397 - _DC_C0 */ 0x2277, -/* 398 - _DC_C8 */ 0x2278, -/* 399 - _DC_C8 */ 0x2279, -/* 39a - _DC_C8 */ 0x227a, -/* 39b - _DC_C8 */ 0x227b, -/* 39c - _DC_C8 */ 0x227c, -/* 39d - _DC_C8 */ 0x227d, -/* 39e - _DC_C8 */ 0x227e, -/* 39f - _DC_C8 */ 0x227f, -/* 3a0 - */ 0, -/* 3a1 - */ 0, -/* 3a2 - */ 0, -/* 3a3 - */ 0, -/* 3a4 - */ 0, -/* 3a5 - */ 0, -/* 3a6 - */ 0, -/* 3a7 - */ 0, -/* 3a8 - */ 0, -/* 3a9 - */ 0, -/* 3aa - */ 0, -/* 3ab - */ 0, -/* 3ac - */ 0, -/* 3ad - */ 0, -/* 3ae - */ 0, -/* 3af - */ 0, -/* 3b0 - _DC_E0 */ 0x2280, -/* 3b1 - _DC_E0 */ 0x2281, -/* 3b2 - _DC_E0 */ 0x2282, -/* 3b3 - _DC_E0 */ 0x2283, -/* 3b4 - _DC_E0 */ 0x2284, -/* 3b5 - _DC_E0 */ 0x2285, -/* 3b6 - _DC_E0 */ 0x2286, -/* 3b7 - _DC_E0 */ 0x2287, -/* 3b8 - _DC_E8 */ 0x2288, -/* 3b9 - _DC_E8 */ 0x2289, -/* 3ba - _DC_E8 */ 0x228a, -/* 3bb - _DC_E8 */ 0x228b, -/* 3bc - _DC_E8 */ 0x228c, -/* 3bd - _DC_E8 */ 0x228d, -/* 3be - _DC_E8 */ 0x228e, -/* 3bf - _DC_E8 */ 0x228f, -/* 3c0 - _DC_F0 */ 0x2290, -/* 3c1 - _DC_F0 */ 0x2291, -/* 3c2 - _DC_F0 */ 0x2292, -/* 3c3 - _DC_F0 */ 0x2293, -/* 3c4 - _DC_F0 */ 0x2294, -/* 3c5 - _DC_F0 */ 0x2295, -/* 3c6 - _DC_F0 */ 0x2296, -/* 3c7 - _DC_F0 */ 0x2297, -/* 3c8 - _DC_F8 */ 0x2298, -/* 3c9 - _DC_F8 */ 0x2299, -/* 3ca - _DC_F8 */ 0x229a, -/* 3cb - _DC_F8 */ 0x229b, -/* 3cc - _DC_F8 */ 0x229c, -/* 3cd - _DC_F8 */ 0x229d, -/* 3ce - _DC_F8 */ 0x229e, -/* 3cf - _DC_F8 */ 0x229f, -/* 3d0 - _DD_00 */ 0x22a0, -/* 3d1 - _DD_01 */ 0x22a1, -/* 3d2 - _DD_02 */ 0x22a2, -/* 3d3 - _DD_03 */ 0x22a3, -/* 3d4 - _DD_04 */ 0x22a4, -/* 3d5 - */ 0, -/* 3d6 - _DD_06 */ 0xced4, -/* 3d7 - _DD_07 */ 0xcee0, -/* 3d8 - _DD_C0 */ 0x22a5, -/* 3d9 - _DD_C0 */ 0x22a6, -/* 3da - _DD_C0 */ 0x22a7, -/* 3db - _DD_C0 */ 0x22a8, -/* 3dc - _DD_C0 */ 0x22a9, -/* 3dd - _DD_C0 */ 0x22aa, -/* 3de - _DD_C0 */ 0x22ab, -/* 3df - _DD_C0 */ 0x22ac, -/* 3e0 - */ 0, -/* 3e1 - */ 0, -/* 3e2 - */ 0, -/* 3e3 - */ 0, -/* 3e4 - */ 0, -/* 3e5 - */ 0, -/* 3e6 - */ 0, -/* 3e7 - */ 0, -/* 3e8 - _DD_D0 */ 0x22ad, -/* 3e9 - _DD_D0 */ 0x22ae, -/* 3ea - _DD_D0 */ 0x22af, -/* 3eb - _DD_D0 */ 0x22b0, -/* 3ec - _DD_D0 */ 0x22b1, -/* 3ed - _DD_D0 */ 0x22b2, -/* 3ee - _DD_D0 */ 0x22b3, -/* 3ef - _DD_D0 */ 0x22b4, -/* 3f0 - _DD_D8 */ 0x22b5, -/* 3f1 - _DD_D8 */ 0x22b6, -/* 3f2 - _DD_D8 */ 0x22b7, -/* 3f3 - _DD_D8 */ 0x22b8, -/* 3f4 - _DD_D8 */ 0x22b9, -/* 3f5 - _DD_D8 */ 0x22ba, -/* 3f6 - _DD_D8 */ 0x22bb, -/* 3f7 - _DD_D8 */ 0x22bc, -/* 3f8 - _DD_E0 */ 0x22bd, -/* 3f9 - _DD_E1 */ 0x22be, -/* 3fa - _DD_E0 */ 0x22bf, -/* 3fb - _DD_E0 */ 0x22c0, -/* 3fc - _DD_E0 */ 0x22c1, -/* 3fd - _DD_E0 */ 0x22c2, -/* 3fe - _DD_E0 */ 0x22c3, -/* 3ff - _DD_E0 */ 0x22c4, -/* 400 - _DD_E8 */ 0x22c5, -/* 401 - _DD_E9 */ 0x22c6, -/* 402 - _DD_E8 */ 0x22c7, -/* 403 - _DD_E8 */ 0x22c8, -/* 404 - _DD_E8 */ 0x22c9, -/* 405 - _DD_E8 */ 0x22ca, -/* 406 - _DD_E8 */ 0x22cb, -/* 407 - _DD_E8 */ 0x22cc, -/* 408 - */ 0, -/* 409 - */ 0, -/* 40a - */ 0, -/* 40b - */ 0, -/* 40c - */ 0, -/* 40d - */ 0, -/* 40e - */ 0, -/* 40f - */ 0, -/* 410 - */ 0, -/* 411 - */ 0, -/* 412 - */ 0, -/* 413 - */ 0, -/* 414 - */ 0, -/* 415 - */ 0, -/* 416 - */ 0, -/* 417 - */ 0, -/* 418 - _DE_00 */ 0x22cd, -/* 419 - _DE_01 */ 0x22ce, -/* 41a - _DE_02 */ 0x22cf, -/* 41b - _DE_03 */ 0x22d0, -/* 41c - _DE_04 */ 0x22d1, -/* 41d - _DE_05 */ 0x22d2, -/* 41e - _DE_06 */ 0x22d3, -/* 41f - _DE_07 */ 0x22d4, -/* 420 - _DE_C0 */ 0x22d5, -/* 421 - _DE_C1 */ 0x22d6, -/* 422 - _DE_C0 */ 0x22d7, -/* 423 - _DE_C0 */ 0x22d8, -/* 424 - _DE_C0 */ 0x22d9, -/* 425 - _DE_C0 */ 0x22da, -/* 426 - _DE_C0 */ 0x22db, -/* 427 - _DE_C0 */ 0x22dc, -/* 428 - _DE_C8 */ 0x22dd, -/* 429 - _DE_C9 */ 0x22de, -/* 42a - _DE_C8 */ 0x22df, -/* 42b - _DE_C8 */ 0x22e0, -/* 42c - _DE_C8 */ 0x22e1, -/* 42d - _DE_C8 */ 0x22e2, -/* 42e - _DE_C8 */ 0x22e3, -/* 42f - _DE_C8 */ 0x22e4, -/* 430 - */ 0, -/* 431 - */ 0, -/* 432 - */ 0, -/* 433 - */ 0, -/* 434 - */ 0, -/* 435 - */ 0, -/* 436 - */ 0, -/* 437 - */ 0, -/* 438 - */ 0, -/* 439 - _DE_D9 */ 0x22e5, -/* 43a - */ 0, -/* 43b - */ 0, -/* 43c - */ 0, -/* 43d - */ 0, -/* 43e - */ 0, -/* 43f - */ 0, -/* 440 - _DE_E0 */ 0x22e6, -/* 441 - _DE_E1 */ 0x22e7, -/* 442 - _DE_E0 */ 0x22e8, -/* 443 - _DE_E0 */ 0x22e9, -/* 444 - _DE_E0 */ 0x22ea, -/* 445 - _DE_E0 */ 0x22eb, -/* 446 - _DE_E0 */ 0x22ec, -/* 447 - _DE_E0 */ 0x22ed, -/* 448 - _DE_E8 */ 0x22ee, -/* 449 - _DE_E9 */ 0x22ef, -/* 44a - _DE_E8 */ 0x22f0, -/* 44b - _DE_E8 */ 0x22f1, -/* 44c - _DE_E8 */ 0x22f2, -/* 44d - _DE_E8 */ 0x22f3, -/* 44e - _DE_E8 */ 0x22f4, -/* 44f - _DE_E8 */ 0x22f5, -/* 450 - _DE_F0 */ 0x22f6, -/* 451 - _DE_F1 */ 0x22f7, -/* 452 - _DE_F0 */ 0x22f8, -/* 453 - _DE_F0 */ 0x22f9, -/* 454 - _DE_F0 */ 0x22fa, -/* 455 - _DE_F0 */ 0x22fb, -/* 456 - _DE_F0 */ 0x22fc, -/* 457 - _DE_F0 */ 0x22fd, -/* 458 - _DE_F8 */ 0x22fe, -/* 459 - _DE_F9 */ 0x22ff, -/* 45a - _DE_F8 */ 0x2300, -/* 45b - _DE_F8 */ 0x2301, -/* 45c - _DE_F8 */ 0x2302, -/* 45d - _DE_F8 */ 0x2303, -/* 45e - _DE_F8 */ 0x2304, -/* 45f - _DE_F8 */ 0x2305, -/* 460 - _DF_00 */ 0x2306, -/* 461 - _DF_01 */ 0x2307, -/* 462 - _DF_02 */ 0x2308, -/* 463 - _DF_03 */ 0x2309, -/* 464 - _DF_04 */ 0x230a, -/* 465 - _DF_05 */ 0x230b, -/* 466 - _DF_06 */ 0x230c, -/* 467 - _DF_07 */ 0x230d, -/* 468 - */ 0, -/* 469 - */ 0, -/* 46a - */ 0, -/* 46b - */ 0, -/* 46c - */ 0, -/* 46d - */ 0, -/* 46e - */ 0, -/* 46f - */ 0, -/* 470 - */ 0, -/* 471 - */ 0, -/* 472 - */ 0, -/* 473 - */ 0, -/* 474 - */ 0, -/* 475 - */ 0, -/* 476 - */ 0, -/* 477 - */ 0, -/* 478 - */ 0, -/* 479 - */ 0, -/* 47a - */ 0, -/* 47b - */ 0, -/* 47c - */ 0, -/* 47d - */ 0, -/* 47e - */ 0, -/* 47f - */ 0, -/* 480 - */ 0, -/* 481 - */ 0, -/* 482 - */ 0, -/* 483 - */ 0, -/* 484 - */ 0, -/* 485 - */ 0, -/* 486 - */ 0, -/* 487 - */ 0, -/* 488 - _DF_E0 */ 0xceec, -/* 489 - */ 0, -/* 48a - */ 0, -/* 48b - */ 0, -/* 48c - */ 0, -/* 48d - */ 0, -/* 48e - */ 0, -/* 48f - */ 0, -/* 490 - _DF_E8 */ 0x230e, -/* 491 - _DF_E8 */ 0x230f, -/* 492 - _DF_E8 */ 0x2310, -/* 493 - _DF_E8 */ 0x2311, -/* 494 - _DF_E8 */ 0x2312, -/* 495 - _DF_E8 */ 0x2313, -/* 496 - _DF_E8 */ 0x2314, -/* 497 - _DF_E8 */ 0x2315, -/* 498 - _DF_F0 */ 0x2316, -/* 499 - _DF_F0 */ 0x2317, -/* 49a - _DF_F0 */ 0x2318, -/* 49b - _DF_F0 */ 0x2319, -/* 49c - _DF_F0 */ 0x231a, -/* 49d - _DF_F0 */ 0x231b, -/* 49e - _DF_F0 */ 0x231c, -/* 49f - _DF_F0 */ 0x231d, -/* 4a0 - */ 0, -/* 4a1 - */ 0, -/* 4a2 - */ 0, -/* 4a3 - */ 0, -/* 4a4 - */ 0, -/* 4a5 - */ 0, -/* 4a6 - */ 0, -/* 4a7 - */ 0, -/* 4a8 - _F6_00 */ 0x231e, -/* 4a9 - */ 0, -/* 4aa - _F6_02 */ 0x231f, -/* 4ab - _F6_03 */ 0x2320, -/* 4ac - _F6_04 */ 0x2321, -/* 4ad - _F6_05 */ 0x2322, -/* 4ae - _F6_06 */ 0x2323, -/* 4af - _F6_07 */ 0x2324, -/* 4b0 - _F7_00 */ 0x2325, -/* 4b1 - */ 0, -/* 4b2 - _F7_02 */ 0x2326, -/* 4b3 - _F7_03 */ 0x2327, -/* 4b4 - _F7_04 */ 0x2328, -/* 4b5 - _F7_05 */ 0x2329, -/* 4b6 - _F7_06 */ 0x232a, -/* 4b7 - _F7_07 */ 0x232b, -/* 4b8 - _FE_00 */ 0x232c, -/* 4b9 - _FE_01 */ 0x232d, -/* 4ba - */ 0, -/* 4bb - */ 0, -/* 4bc - */ 0, -/* 4bd - */ 0, -/* 4be - */ 0, -/* 4bf - */ 0, -/* 4c0 - _FF_00 */ 0x232e, -/* 4c1 - _FF_01 */ 0x232f, -/* 4c2 - _FF_02 */ 0x2330, -/* 4c3 - _FF_03 */ 0x2331, -/* 4c4 - _FF_04 */ 0x2332, -/* 4c5 - _FF_05 */ 0x2333, -/* 4c6 - _FF_06 */ 0x2334, -/* 4c7 - */ 0, -/* 4c8 - _0F_00_00 */ 0x2335, -/* 4c9 - _0F_00_01 */ 0x2336, -/* 4ca - _0F_00_02 */ 0x2337, -/* 4cb - _0F_00_03 */ 0x2338, -/* 4cc - _0F_00_04 */ 0x2339, -/* 4cd - _0F_00_05 */ 0x233a, -/* 4ce - */ 0, -/* 4cf - */ 0, -/* 4d0 - _0F_01_00 */ 0x233b, -/* 4d1 - _0F_01_01 */ 0x233c, -/* 4d2 - _0F_01_02 */ 0x233d, -/* 4d3 - _0F_01_03 */ 0x233e, -/* 4d4 - _0F_01_04 */ 0x233f, -/* 4d5 - */ 0, -/* 4d6 - _0F_01_06 */ 0x2340, -/* 4d7 - _0F_01_07 */ 0x2341, -/* 4d8 - */ 0, -/* 4d9 - _0F_01_C1 */ 0x2342, -/* 4da - _0F_01_C2 */ 0x2343, -/* 4db - _0F_01_C3 */ 0x2344, -/* 4dc - _0F_01_C4 */ 0x2345, -/* 4dd - */ 0, -/* 4de - */ 0, -/* 4df - */ 0, -/* 4e0 - _0F_01_C8 */ 0x2346, -/* 4e1 - _0F_01_C9 */ 0x2347, -/* 4e2 - */ 0, -/* 4e3 - */ 0, -/* 4e4 - */ 0, -/* 4e5 - */ 0, -/* 4e6 - */ 0, -/* 4e7 - */ 0, -/* 4e8 - _0F_01_D0 */ 0x2348, -/* 4e9 - _0F_01_D1 */ 0x2349, -/* 4ea - */ 0, -/* 4eb - */ 0, -/* 4ec - _0F_01_D4 */ 0x234a, -/* 4ed - */ 0, -/* 4ee - */ 0, -/* 4ef - */ 0, -/* 4f0 - _0F_01_D8 */ 0x234b, -/* 4f1 - _0F_01_D9 */ 0x234c, -/* 4f2 - _0F_01_DA */ 0x234d, -/* 4f3 - _0F_01_DB */ 0x234e, -/* 4f4 - _0F_01_DC */ 0x234f, -/* 4f5 - _0F_01_DD */ 0x2350, -/* 4f6 - _0F_01_DE */ 0x2351, -/* 4f7 - _0F_01_DF */ 0x2352, -/* 4f8 - */ 0, -/* 4f9 - */ 0, -/* 4fa - */ 0, -/* 4fb - */ 0, -/* 4fc - */ 0, -/* 4fd - */ 0, -/* 4fe - */ 0, -/* 4ff - */ 0, -/* 500 - */ 0, -/* 501 - */ 0, -/* 502 - */ 0, -/* 503 - */ 0, -/* 504 - */ 0, -/* 505 - */ 0, -/* 506 - */ 0, -/* 507 - */ 0, -/* 508 - */ 0, -/* 509 - */ 0, -/* 50a - */ 0, -/* 50b - */ 0, -/* 50c - */ 0, -/* 50d - */ 0, -/* 50e - */ 0, -/* 50f - */ 0, -/* 510 - _0F_01_F8 */ 0x2353, -/* 511 - _0F_01_F9 */ 0x2354, -/* 512 - */ 0, -/* 513 - */ 0, -/* 514 - */ 0, -/* 515 - */ 0, -/* 516 - */ 0, -/* 517 - */ 0, -/* 518 - _0F_0D_00 */ 0x2355, -/* 519 - _0F_0D_01 */ 0x2356, -/* 51a - */ 0, -/* 51b - */ 0, -/* 51c - */ 0, -/* 51d - */ 0, -/* 51e - */ 0, -/* 51f - */ 0, -/* 520 - */ 0, -/* 521 - */ 0, -/* 522 - */ 0, -/* 523 - */ 0, -/* 524 - */ 0, -/* 525 - */ 0, -/* 526 - */ 0, -/* 527 - */ 0, -/* 528 - */ 0, -/* 529 - */ 0, -/* 52a - */ 0, -/* 52b - */ 0, -/* 52c - _0F_0F_0C */ 0x2357, -/* 52d - _0F_0F_0D */ 0x2358, -/* 52e - */ 0, -/* 52f - */ 0, -/* 530 - */ 0, -/* 531 - */ 0, -/* 532 - */ 0, -/* 533 - */ 0, -/* 534 - */ 0, -/* 535 - */ 0, -/* 536 - */ 0, -/* 537 - */ 0, -/* 538 - */ 0, -/* 539 - */ 0, -/* 53a - */ 0, -/* 53b - */ 0, -/* 53c - _0F_0F_1C */ 0x2359, -/* 53d - _0F_0F_1D */ 0x235a, -/* 53e - */ 0, -/* 53f - */ 0, -/* 540 - */ 0, -/* 541 - */ 0, -/* 542 - */ 0, -/* 543 - */ 0, -/* 544 - */ 0, -/* 545 - */ 0, -/* 546 - */ 0, -/* 547 - */ 0, -/* 548 - */ 0, -/* 549 - */ 0, -/* 54a - */ 0, -/* 54b - */ 0, -/* 54c - */ 0, -/* 54d - */ 0, -/* 54e - */ 0, -/* 54f - */ 0, -/* 550 - */ 0, -/* 551 - */ 0, -/* 552 - */ 0, -/* 553 - */ 0, -/* 554 - */ 0, -/* 555 - */ 0, -/* 556 - */ 0, -/* 557 - */ 0, -/* 558 - */ 0, -/* 559 - */ 0, -/* 55a - */ 0, -/* 55b - */ 0, -/* 55c - */ 0, -/* 55d - */ 0, -/* 55e - */ 0, -/* 55f - */ 0, -/* 560 - */ 0, -/* 561 - */ 0, -/* 562 - */ 0, -/* 563 - */ 0, -/* 564 - */ 0, -/* 565 - */ 0, -/* 566 - */ 0, -/* 567 - */ 0, -/* 568 - */ 0, -/* 569 - */ 0, -/* 56a - */ 0, -/* 56b - */ 0, -/* 56c - */ 0, -/* 56d - */ 0, -/* 56e - */ 0, -/* 56f - */ 0, -/* 570 - */ 0, -/* 571 - */ 0, -/* 572 - */ 0, -/* 573 - */ 0, -/* 574 - */ 0, -/* 575 - */ 0, -/* 576 - */ 0, -/* 577 - */ 0, -/* 578 - */ 0, -/* 579 - */ 0, -/* 57a - */ 0, -/* 57b - */ 0, -/* 57c - */ 0, -/* 57d - */ 0, -/* 57e - */ 0, -/* 57f - */ 0, -/* 580 - */ 0, -/* 581 - */ 0, -/* 582 - */ 0, -/* 583 - */ 0, -/* 584 - */ 0, -/* 585 - */ 0, -/* 586 - */ 0, -/* 587 - */ 0, -/* 588 - */ 0, -/* 589 - */ 0, -/* 58a - */ 0, -/* 58b - */ 0, -/* 58c - */ 0, -/* 58d - */ 0, -/* 58e - */ 0, -/* 58f - */ 0, -/* 590 - */ 0, -/* 591 - */ 0, -/* 592 - */ 0, -/* 593 - */ 0, -/* 594 - */ 0, -/* 595 - */ 0, -/* 596 - */ 0, -/* 597 - */ 0, -/* 598 - */ 0, -/* 599 - */ 0, -/* 59a - */ 0, -/* 59b - */ 0, -/* 59c - */ 0, -/* 59d - */ 0, -/* 59e - */ 0, -/* 59f - */ 0, -/* 5a0 - */ 0, -/* 5a1 - */ 0, -/* 5a2 - */ 0, -/* 5a3 - */ 0, -/* 5a4 - */ 0, -/* 5a5 - */ 0, -/* 5a6 - */ 0, -/* 5a7 - */ 0, -/* 5a8 - */ 0, -/* 5a9 - */ 0, -/* 5aa - _0F_0F_8A */ 0x235b, -/* 5ab - */ 0, -/* 5ac - */ 0, -/* 5ad - */ 0, -/* 5ae - _0F_0F_8E */ 0x235c, -/* 5af - */ 0, -/* 5b0 - _0F_0F_90 */ 0x235d, -/* 5b1 - */ 0, -/* 5b2 - */ 0, -/* 5b3 - */ 0, -/* 5b4 - _0F_0F_94 */ 0x235e, -/* 5b5 - */ 0, -/* 5b6 - _0F_0F_96 */ 0x235f, -/* 5b7 - _0F_0F_97 */ 0x2360, -/* 5b8 - */ 0, -/* 5b9 - */ 0, -/* 5ba - _0F_0F_9A */ 0x2361, -/* 5bb - */ 0, -/* 5bc - */ 0, -/* 5bd - */ 0, -/* 5be - _0F_0F_9E */ 0x2362, -/* 5bf - */ 0, -/* 5c0 - _0F_0F_A0 */ 0x2363, -/* 5c1 - */ 0, -/* 5c2 - */ 0, -/* 5c3 - */ 0, -/* 5c4 - _0F_0F_A4 */ 0x2364, -/* 5c5 - */ 0, -/* 5c6 - _0F_0F_A6 */ 0x2365, -/* 5c7 - _0F_0F_A7 */ 0x2366, -/* 5c8 - */ 0, -/* 5c9 - */ 0, -/* 5ca - _0F_0F_AA */ 0x2367, -/* 5cb - */ 0, -/* 5cc - */ 0, -/* 5cd - */ 0, -/* 5ce - _0F_0F_AE */ 0x2368, -/* 5cf - */ 0, -/* 5d0 - _0F_0F_B0 */ 0x2369, -/* 5d1 - */ 0, -/* 5d2 - */ 0, -/* 5d3 - */ 0, -/* 5d4 - _0F_0F_B4 */ 0x236a, -/* 5d5 - */ 0, -/* 5d6 - _0F_0F_B6 */ 0x236b, -/* 5d7 - _0F_0F_B7 */ 0x236c, -/* 5d8 - */ 0, -/* 5d9 - */ 0, -/* 5da - */ 0, -/* 5db - _0F_0F_BB */ 0x236d, -/* 5dc - */ 0, -/* 5dd - */ 0, -/* 5de - */ 0, -/* 5df - _0F_0F_BF */ 0x236e, -/* 5e0 - */ 0, -/* 5e1 - */ 0, -/* 5e2 - */ 0, -/* 5e3 - */ 0, -/* 5e4 - */ 0, -/* 5e5 - */ 0, -/* 5e6 - */ 0, -/* 5e7 - */ 0, -/* 5e8 - */ 0, -/* 5e9 - */ 0, -/* 5ea - */ 0, -/* 5eb - */ 0, -/* 5ec - */ 0, -/* 5ed - */ 0, -/* 5ee - */ 0, -/* 5ef - */ 0, -/* 5f0 - */ 0, -/* 5f1 - */ 0, -/* 5f2 - */ 0, -/* 5f3 - */ 0, -/* 5f4 - */ 0, -/* 5f5 - */ 0, -/* 5f6 - */ 0, -/* 5f7 - */ 0, -/* 5f8 - */ 0, -/* 5f9 - */ 0, -/* 5fa - */ 0, -/* 5fb - */ 0, -/* 5fc - */ 0, -/* 5fd - */ 0, -/* 5fe - */ 0, -/* 5ff - */ 0, -/* 600 - */ 0, -/* 601 - */ 0, -/* 602 - */ 0, -/* 603 - */ 0, -/* 604 - */ 0, -/* 605 - */ 0, -/* 606 - */ 0, -/* 607 - */ 0, -/* 608 - */ 0, -/* 609 - */ 0, -/* 60a - */ 0, -/* 60b - */ 0, -/* 60c - */ 0, -/* 60d - */ 0, -/* 60e - */ 0, -/* 60f - */ 0, -/* 610 - */ 0, -/* 611 - */ 0, -/* 612 - */ 0, -/* 613 - */ 0, -/* 614 - */ 0, -/* 615 - */ 0, -/* 616 - */ 0, -/* 617 - */ 0, -/* 618 - */ 0, -/* 619 - */ 0, -/* 61a - */ 0, -/* 61b - */ 0, -/* 61c - */ 0, -/* 61d - */ 0, -/* 61e - */ 0, -/* 61f - */ 0, -/* 620 - _0F_10 */ 0x236f, -/* 621 - _66_0F_10 */ 0x2370, -/* 622 - _F3_0F_10 */ 0x2371, -/* 623 - _F2_0F_10 */ 0x2372, -/* 624 - _V_0F_10 */ 0x4009, -/* 625 - _V_66_0F_10 */ 0x400a, -/* 626 - _V_F3_0F_10 */ 0x400b, -/* 627 - _V_F2_0F_10 */ 0x400c, -/* 628 - */ 0, -/* 629 - */ 0, -/* 62a - _VRR_F3_0F_10 */ 0x400d, -/* 62b - _VRR_F2_0F_10 */ 0x400e, -/* 62c - _0F_11 */ 0x2373, -/* 62d - _66_0F_11 */ 0x2374, -/* 62e - _F3_0F_11 */ 0x2375, -/* 62f - _F2_0F_11 */ 0x2376, -/* 630 - _V_0F_11 */ 0x400f, -/* 631 - _V_66_0F_11 */ 0x4010, -/* 632 - _V_F3_0F_11 */ 0x4011, -/* 633 - _V_F2_0F_11 */ 0x4012, -/* 634 - */ 0, -/* 635 - */ 0, -/* 636 - _VRR_F3_0F_11 */ 0x4013, -/* 637 - _VRR_F2_0F_11 */ 0x4014, -/* 638 - _0F_12 */ 0x4015, -/* 639 - _66_0F_12 */ 0x2377, -/* 63a - _F3_0F_12 */ 0x2378, -/* 63b - _F2_0F_12 */ 0x2379, -/* 63c - _V_0F_12 */ 0x4016, -/* 63d - _V_66_0F_12 */ 0x4017, -/* 63e - _V_F3_0F_12 */ 0x4018, -/* 63f - _V_F2_0F_12 */ 0x4019, -/* 640 - */ 0, -/* 641 - */ 0, -/* 642 - */ 0, -/* 643 - */ 0, -/* 644 - _0F_13 */ 0x237a, -/* 645 - _66_0F_13 */ 0x237b, -/* 646 - */ 0, -/* 647 - */ 0, -/* 648 - _V_0F_13 */ 0x401a, -/* 649 - _V_66_0F_13 */ 0x401b, -/* 64a - */ 0, -/* 64b - */ 0, -/* 64c - */ 0, -/* 64d - */ 0, -/* 64e - */ 0, -/* 64f - */ 0, -/* 650 - _0F_14 */ 0x237c, -/* 651 - _66_0F_14 */ 0x237d, -/* 652 - */ 0, -/* 653 - */ 0, -/* 654 - _V_0F_14 */ 0x401c, -/* 655 - _V_66_0F_14 */ 0x401d, -/* 656 - */ 0, -/* 657 - */ 0, -/* 658 - */ 0, -/* 659 - */ 0, -/* 65a - */ 0, -/* 65b - */ 0, -/* 65c - _0F_15 */ 0x237e, -/* 65d - _66_0F_15 */ 0x237f, -/* 65e - */ 0, -/* 65f - */ 0, -/* 660 - _V_0F_15 */ 0x401e, -/* 661 - _V_66_0F_15 */ 0x401f, -/* 662 - */ 0, -/* 663 - */ 0, -/* 664 - */ 0, -/* 665 - */ 0, -/* 666 - */ 0, -/* 667 - */ 0, -/* 668 - _0F_16 */ 0x4020, -/* 669 - _66_0F_16 */ 0x2380, -/* 66a - _F3_0F_16 */ 0x2381, -/* 66b - */ 0, -/* 66c - _V_0F_16 */ 0x4021, -/* 66d - _V_66_0F_16 */ 0x4022, -/* 66e - _V_F3_0F_16 */ 0x4023, -/* 66f - */ 0, -/* 670 - */ 0, -/* 671 - */ 0, -/* 672 - */ 0, -/* 673 - */ 0, -/* 674 - _0F_17 */ 0x2382, -/* 675 - _66_0F_17 */ 0x2383, -/* 676 - */ 0, -/* 677 - */ 0, -/* 678 - _V_0F_17 */ 0x4024, -/* 679 - _V_66_0F_17 */ 0x4025, -/* 67a - */ 0, -/* 67b - */ 0, -/* 67c - */ 0, -/* 67d - */ 0, -/* 67e - */ 0, -/* 67f - */ 0, -/* 680 - _0F_18_00 */ 0x2384, -/* 681 - _0F_18_01 */ 0x2385, -/* 682 - _0F_18_02 */ 0x2386, -/* 683 - _0F_18_03 */ 0x2387, -/* 684 - */ 0, -/* 685 - */ 0, -/* 686 - */ 0, -/* 687 - */ 0, -/* 688 - _0F_28 */ 0x2388, -/* 689 - _66_0F_28 */ 0x2389, -/* 68a - */ 0, -/* 68b - */ 0, -/* 68c - _V_0F_28 */ 0x4026, -/* 68d - _V_66_0F_28 */ 0x4027, -/* 68e - */ 0, -/* 68f - */ 0, -/* 690 - */ 0, -/* 691 - */ 0, -/* 692 - */ 0, -/* 693 - */ 0, -/* 694 - _0F_29 */ 0x238a, -/* 695 - _66_0F_29 */ 0x238b, -/* 696 - */ 0, -/* 697 - */ 0, -/* 698 - _V_0F_29 */ 0x4028, -/* 699 - _V_66_0F_29 */ 0x4029, -/* 69a - */ 0, -/* 69b - */ 0, -/* 69c - */ 0, -/* 69d - */ 0, -/* 69e - */ 0, -/* 69f - */ 0, -/* 6a0 - _0F_2A */ 0x238c, -/* 6a1 - _66_0F_2A */ 0x238d, -/* 6a2 - _F3_0F_2A */ 0x238e, -/* 6a3 - _F2_0F_2A */ 0x238f, -/* 6a4 - */ 0, -/* 6a5 - */ 0, -/* 6a6 - _V_F3_0F_2A */ 0x402a, -/* 6a7 - _V_F2_0F_2A */ 0x402b, -/* 6a8 - */ 0, -/* 6a9 - */ 0, -/* 6aa - */ 0, -/* 6ab - */ 0, -/* 6ac - _0F_2B */ 0x2390, -/* 6ad - _66_0F_2B */ 0x2391, -/* 6ae - _F3_0F_2B */ 0x2392, -/* 6af - _F2_0F_2B */ 0x2393, -/* 6b0 - _V_0F_2B */ 0x402c, -/* 6b1 - _V_66_0F_2B */ 0x402d, -/* 6b2 - */ 0, -/* 6b3 - */ 0, -/* 6b4 - */ 0, -/* 6b5 - */ 0, -/* 6b6 - */ 0, -/* 6b7 - */ 0, -/* 6b8 - _0F_2C */ 0x2394, -/* 6b9 - _66_0F_2C */ 0x2395, -/* 6ba - _F3_0F_2C */ 0x2396, -/* 6bb - _F2_0F_2C */ 0x2397, -/* 6bc - */ 0, -/* 6bd - */ 0, -/* 6be - _V_F3_0F_2C */ 0x402e, -/* 6bf - _V_F2_0F_2C */ 0x402f, -/* 6c0 - */ 0, -/* 6c1 - */ 0, -/* 6c2 - */ 0, -/* 6c3 - */ 0, -/* 6c4 - _0F_2D */ 0x2398, -/* 6c5 - _66_0F_2D */ 0x2399, -/* 6c6 - _F3_0F_2D */ 0x239a, -/* 6c7 - _F2_0F_2D */ 0x239b, -/* 6c8 - */ 0, -/* 6c9 - */ 0, -/* 6ca - _V_F3_0F_2D */ 0x4030, -/* 6cb - _V_F2_0F_2D */ 0x4031, -/* 6cc - */ 0, -/* 6cd - */ 0, -/* 6ce - */ 0, -/* 6cf - */ 0, -/* 6d0 - _0F_2E */ 0x239c, -/* 6d1 - _66_0F_2E */ 0x239d, -/* 6d2 - */ 0, -/* 6d3 - */ 0, -/* 6d4 - _V_0F_2E */ 0x4032, -/* 6d5 - _V_66_0F_2E */ 0x4033, -/* 6d6 - */ 0, -/* 6d7 - */ 0, -/* 6d8 - */ 0, -/* 6d9 - */ 0, -/* 6da - */ 0, -/* 6db - */ 0, -/* 6dc - _0F_2F */ 0x239e, -/* 6dd - _66_0F_2F */ 0x239f, -/* 6de - */ 0, -/* 6df - */ 0, -/* 6e0 - _V_0F_2F */ 0x4034, -/* 6e1 - _V_66_0F_2F */ 0x4035, -/* 6e2 - */ 0, -/* 6e3 - */ 0, -/* 6e4 - */ 0, -/* 6e5 - */ 0, -/* 6e6 - */ 0, -/* 6e7 - */ 0, -/* 6e8 - _0F_38_00 */ 0xcef8, -/* 6e9 - _0F_38_01 */ 0xcf04, -/* 6ea - _0F_38_02 */ 0xcf10, -/* 6eb - _0F_38_03 */ 0xcf1c, -/* 6ec - _0F_38_04 */ 0xcf28, -/* 6ed - _0F_38_05 */ 0xcf34, -/* 6ee - _0F_38_06 */ 0xcf40, -/* 6ef - _0F_38_07 */ 0xcf4c, -/* 6f0 - _0F_38_08 */ 0xcf58, -/* 6f1 - _0F_38_09 */ 0xcf64, -/* 6f2 - _0F_38_0A */ 0xcf70, -/* 6f3 - _0F_38_0B */ 0xcf7c, -/* 6f4 - _0F_38_0C */ 0xcf88, -/* 6f5 - _0F_38_0D */ 0xcf94, -/* 6f6 - _0F_38_0E */ 0xcfa0, -/* 6f7 - _0F_38_0F */ 0xcfac, -/* 6f8 - _0F_38_10 */ 0xcfb8, -/* 6f9 - */ 0, -/* 6fa - */ 0, -/* 6fb - */ 0, -/* 6fc - _0F_38_14 */ 0xcfc4, -/* 6fd - _0F_38_15 */ 0xcfd0, -/* 6fe - */ 0, -/* 6ff - _0F_38_17 */ 0xcfdc, -/* 700 - _0F_38_18 */ 0xcfe8, -/* 701 - _0F_38_19 */ 0xcff4, -/* 702 - _0F_38_1A */ 0xd000, -/* 703 - */ 0, -/* 704 - _0F_38_1C */ 0xd00c, -/* 705 - _0F_38_1D */ 0xd018, -/* 706 - _0F_38_1E */ 0xd024, -/* 707 - */ 0, -/* 708 - _0F_38_20 */ 0xd030, -/* 709 - _0F_38_21 */ 0xd03c, -/* 70a - _0F_38_22 */ 0xd048, -/* 70b - _0F_38_23 */ 0xd054, -/* 70c - _0F_38_24 */ 0xd060, -/* 70d - _0F_38_25 */ 0xd06c, -/* 70e - */ 0, -/* 70f - */ 0, -/* 710 - _0F_38_28 */ 0xd078, -/* 711 - _0F_38_29 */ 0xd084, -/* 712 - _0F_38_2A */ 0xd090, -/* 713 - _0F_38_2B */ 0xd09c, -/* 714 - _0F_38_2C */ 0xd0a8, -/* 715 - _0F_38_2D */ 0xd0b4, -/* 716 - _0F_38_2E */ 0xd0c0, -/* 717 - _0F_38_2F */ 0xd0cc, -/* 718 - _0F_38_30 */ 0xd0d8, -/* 719 - _0F_38_31 */ 0xd0e4, -/* 71a - _0F_38_32 */ 0xd0f0, -/* 71b - _0F_38_33 */ 0xd0fc, -/* 71c - _0F_38_34 */ 0xd108, -/* 71d - _0F_38_35 */ 0xd114, -/* 71e - */ 0, -/* 71f - _0F_38_37 */ 0xd120, -/* 720 - _0F_38_38 */ 0xd12c, -/* 721 - _0F_38_39 */ 0xd138, -/* 722 - _0F_38_3A */ 0xd144, -/* 723 - _0F_38_3B */ 0xd150, -/* 724 - _0F_38_3C */ 0xd15c, -/* 725 - _0F_38_3D */ 0xd168, -/* 726 - _0F_38_3E */ 0xd174, -/* 727 - _0F_38_3F */ 0xd180, -/* 728 - _0F_38_40 */ 0xd18c, -/* 729 - _0F_38_41 */ 0xd198, -/* 72a - */ 0, -/* 72b - */ 0, -/* 72c - */ 0, -/* 72d - */ 0, -/* 72e - */ 0, -/* 72f - */ 0, -/* 730 - */ 0, -/* 731 - */ 0, -/* 732 - */ 0, -/* 733 - */ 0, -/* 734 - */ 0, -/* 735 - */ 0, -/* 736 - */ 0, -/* 737 - */ 0, -/* 738 - */ 0, -/* 739 - */ 0, -/* 73a - */ 0, -/* 73b - */ 0, -/* 73c - */ 0, -/* 73d - */ 0, -/* 73e - */ 0, -/* 73f - */ 0, -/* 740 - */ 0, -/* 741 - */ 0, -/* 742 - */ 0, -/* 743 - */ 0, -/* 744 - */ 0, -/* 745 - */ 0, -/* 746 - */ 0, -/* 747 - */ 0, -/* 748 - */ 0, -/* 749 - */ 0, -/* 74a - */ 0, -/* 74b - */ 0, -/* 74c - */ 0, -/* 74d - */ 0, -/* 74e - */ 0, -/* 74f - */ 0, -/* 750 - */ 0, -/* 751 - */ 0, -/* 752 - */ 0, -/* 753 - */ 0, -/* 754 - */ 0, -/* 755 - */ 0, -/* 756 - */ 0, -/* 757 - */ 0, -/* 758 - */ 0, -/* 759 - */ 0, -/* 75a - */ 0, -/* 75b - */ 0, -/* 75c - */ 0, -/* 75d - */ 0, -/* 75e - */ 0, -/* 75f - */ 0, -/* 760 - */ 0, -/* 761 - */ 0, -/* 762 - */ 0, -/* 763 - */ 0, -/* 764 - */ 0, -/* 765 - */ 0, -/* 766 - */ 0, -/* 767 - */ 0, -/* 768 - _0F_38_80 */ 0xd1a4, -/* 769 - _0F_38_81 */ 0xd1b0, -/* 76a - _0F_38_82 */ 0xd1bc, -/* 76b - */ 0, -/* 76c - */ 0, -/* 76d - */ 0, -/* 76e - */ 0, -/* 76f - */ 0, -/* 770 - */ 0, -/* 771 - */ 0, -/* 772 - */ 0, -/* 773 - */ 0, -/* 774 - */ 0, -/* 775 - */ 0, -/* 776 - */ 0, -/* 777 - */ 0, -/* 778 - */ 0, -/* 779 - */ 0, -/* 77a - */ 0, -/* 77b - */ 0, -/* 77c - */ 0, -/* 77d - */ 0, -/* 77e - _0F_38_96 */ 0xd1c8, -/* 77f - _0F_38_97 */ 0xd1d4, -/* 780 - _0F_38_98 */ 0xd1e0, -/* 781 - _0F_38_99 */ 0xd1ec, -/* 782 - _0F_38_9A */ 0xd1f8, -/* 783 - _0F_38_9B */ 0xd204, -/* 784 - _0F_38_9C */ 0xd210, -/* 785 - _0F_38_9D */ 0xd21c, -/* 786 - _0F_38_9E */ 0xd228, -/* 787 - _0F_38_9F */ 0xd234, -/* 788 - */ 0, -/* 789 - */ 0, -/* 78a - */ 0, -/* 78b - */ 0, -/* 78c - */ 0, -/* 78d - */ 0, -/* 78e - _0F_38_A6 */ 0xd240, -/* 78f - _0F_38_A7 */ 0xd24c, -/* 790 - _0F_38_A8 */ 0xd258, -/* 791 - _0F_38_A9 */ 0xd264, -/* 792 - _0F_38_AA */ 0xd270, -/* 793 - _0F_38_AB */ 0xd27c, -/* 794 - _0F_38_AC */ 0xd288, -/* 795 - _0F_38_AD */ 0xd294, -/* 796 - _0F_38_AE */ 0xd2a0, -/* 797 - _0F_38_AF */ 0xd2ac, -/* 798 - */ 0, -/* 799 - */ 0, -/* 79a - */ 0, -/* 79b - */ 0, -/* 79c - */ 0, -/* 79d - */ 0, -/* 79e - _0F_38_B6 */ 0xd2b8, -/* 79f - _0F_38_B7 */ 0xd2c4, -/* 7a0 - _0F_38_B8 */ 0xd2d0, -/* 7a1 - _0F_38_B9 */ 0xd2dc, -/* 7a2 - _0F_38_BA */ 0xd2e8, -/* 7a3 - _0F_38_BB */ 0xd2f4, -/* 7a4 - _0F_38_BC */ 0xd300, -/* 7a5 - _0F_38_BD */ 0xd30c, -/* 7a6 - _0F_38_BE */ 0xd318, -/* 7a7 - _0F_38_BF */ 0xd324, -/* 7a8 - */ 0, -/* 7a9 - */ 0, -/* 7aa - */ 0, -/* 7ab - */ 0, -/* 7ac - */ 0, -/* 7ad - */ 0, -/* 7ae - */ 0, -/* 7af - */ 0, -/* 7b0 - */ 0, -/* 7b1 - */ 0, -/* 7b2 - */ 0, -/* 7b3 - */ 0, -/* 7b4 - */ 0, -/* 7b5 - */ 0, -/* 7b6 - */ 0, -/* 7b7 - */ 0, -/* 7b8 - */ 0, -/* 7b9 - */ 0, -/* 7ba - */ 0, -/* 7bb - */ 0, -/* 7bc - */ 0, -/* 7bd - */ 0, -/* 7be - */ 0, -/* 7bf - */ 0, -/* 7c0 - */ 0, -/* 7c1 - */ 0, -/* 7c2 - */ 0, -/* 7c3 - _0F_38_DB */ 0xd330, -/* 7c4 - _0F_38_DC */ 0xd33c, -/* 7c5 - _0F_38_DD */ 0xd348, -/* 7c6 - _0F_38_DE */ 0xd354, -/* 7c7 - _0F_38_DF */ 0xd360, -/* 7c8 - */ 0, -/* 7c9 - */ 0, -/* 7ca - */ 0, -/* 7cb - */ 0, -/* 7cc - */ 0, -/* 7cd - */ 0, -/* 7ce - */ 0, -/* 7cf - */ 0, -/* 7d0 - */ 0, -/* 7d1 - */ 0, -/* 7d2 - */ 0, -/* 7d3 - */ 0, -/* 7d4 - */ 0, -/* 7d5 - */ 0, -/* 7d6 - */ 0, -/* 7d7 - */ 0, -/* 7d8 - _0F_38_F0 */ 0xd36c, -/* 7d9 - _0F_38_F1 */ 0xd378, -/* 7da - */ 0, -/* 7db - */ 0, -/* 7dc - */ 0, -/* 7dd - */ 0, -/* 7de - */ 0, -/* 7df - */ 0, -/* 7e0 - */ 0, -/* 7e1 - */ 0, -/* 7e2 - */ 0, -/* 7e3 - */ 0, -/* 7e4 - */ 0, -/* 7e5 - */ 0, -/* 7e6 - */ 0, -/* 7e7 - */ 0, -/* 7e8 - */ 0, -/* 7e9 - */ 0, -/* 7ea - */ 0, -/* 7eb - */ 0, -/* 7ec - _0F_3A_04 */ 0xd384, -/* 7ed - _0F_3A_05 */ 0xd390, -/* 7ee - _0F_3A_06 */ 0xd39c, -/* 7ef - */ 0, -/* 7f0 - _0F_3A_08 */ 0xd3a8, -/* 7f1 - _0F_3A_09 */ 0xd3b4, -/* 7f2 - _0F_3A_0A */ 0xd3c0, -/* 7f3 - _0F_3A_0B */ 0xd3cc, -/* 7f4 - _0F_3A_0C */ 0xd3d8, -/* 7f5 - _0F_3A_0D */ 0xd3e4, -/* 7f6 - _0F_3A_0E */ 0xd3f0, -/* 7f7 - _0F_3A_0F */ 0xd3fc, -/* 7f8 - */ 0, -/* 7f9 - */ 0, -/* 7fa - */ 0, -/* 7fb - */ 0, -/* 7fc - _0F_3A_14 */ 0xd408, -/* 7fd - _0F_3A_15 */ 0xd414, -/* 7fe - _0F_3A_16 */ 0xd420, -/* 7ff - _0F_3A_17 */ 0xd42c, -/* 800 - _0F_3A_18 */ 0xd438, -/* 801 - _0F_3A_19 */ 0xd444, -/* 802 - */ 0, -/* 803 - */ 0, -/* 804 - */ 0, -/* 805 - */ 0, -/* 806 - */ 0, -/* 807 - */ 0, -/* 808 - _0F_3A_20 */ 0xd450, -/* 809 - _0F_3A_21 */ 0xd45c, -/* 80a - _0F_3A_22 */ 0xd468, -/* 80b - */ 0, -/* 80c - */ 0, -/* 80d - */ 0, -/* 80e - */ 0, -/* 80f - */ 0, -/* 810 - */ 0, -/* 811 - */ 0, -/* 812 - */ 0, -/* 813 - */ 0, -/* 814 - */ 0, -/* 815 - */ 0, -/* 816 - */ 0, -/* 817 - */ 0, -/* 818 - */ 0, -/* 819 - */ 0, -/* 81a - */ 0, -/* 81b - */ 0, -/* 81c - */ 0, -/* 81d - */ 0, -/* 81e - */ 0, -/* 81f - */ 0, -/* 820 - */ 0, -/* 821 - */ 0, -/* 822 - */ 0, -/* 823 - */ 0, -/* 824 - */ 0, -/* 825 - */ 0, -/* 826 - */ 0, -/* 827 - */ 0, -/* 828 - _0F_3A_40 */ 0xd474, -/* 829 - _0F_3A_41 */ 0xd480, -/* 82a - _0F_3A_42 */ 0xd48c, -/* 82b - */ 0, -/* 82c - _0F_3A_44 */ 0xd498, -/* 82d - */ 0, -/* 82e - */ 0, -/* 82f - */ 0, -/* 830 - */ 0, -/* 831 - */ 0, -/* 832 - _0F_3A_4A */ 0xd4a4, -/* 833 - _0F_3A_4B */ 0xd4b0, -/* 834 - _0F_3A_4C */ 0xd4bc, -/* 835 - */ 0, -/* 836 - */ 0, -/* 837 - */ 0, -/* 838 - */ 0, -/* 839 - */ 0, -/* 83a - */ 0, -/* 83b - */ 0, -/* 83c - */ 0, -/* 83d - */ 0, -/* 83e - */ 0, -/* 83f - */ 0, -/* 840 - */ 0, -/* 841 - */ 0, -/* 842 - */ 0, -/* 843 - */ 0, -/* 844 - */ 0, -/* 845 - */ 0, -/* 846 - */ 0, -/* 847 - */ 0, -/* 848 - _0F_3A_60 */ 0xd4c8, -/* 849 - _0F_3A_61 */ 0xd4d4, -/* 84a - _0F_3A_62 */ 0xd4e0, -/* 84b - _0F_3A_63 */ 0xd4ec, -/* 84c - */ 0, -/* 84d - */ 0, -/* 84e - */ 0, -/* 84f - */ 0, -/* 850 - */ 0, -/* 851 - */ 0, -/* 852 - */ 0, -/* 853 - */ 0, -/* 854 - */ 0, -/* 855 - */ 0, -/* 856 - */ 0, -/* 857 - */ 0, -/* 858 - */ 0, -/* 859 - */ 0, -/* 85a - */ 0, -/* 85b - */ 0, -/* 85c - */ 0, -/* 85d - */ 0, -/* 85e - */ 0, -/* 85f - */ 0, -/* 860 - */ 0, -/* 861 - */ 0, -/* 862 - */ 0, -/* 863 - */ 0, -/* 864 - */ 0, -/* 865 - */ 0, -/* 866 - */ 0, -/* 867 - */ 0, -/* 868 - */ 0, -/* 869 - */ 0, -/* 86a - */ 0, -/* 86b - */ 0, -/* 86c - */ 0, -/* 86d - */ 0, -/* 86e - */ 0, -/* 86f - */ 0, -/* 870 - */ 0, -/* 871 - */ 0, -/* 872 - */ 0, -/* 873 - */ 0, -/* 874 - */ 0, -/* 875 - */ 0, -/* 876 - */ 0, -/* 877 - */ 0, -/* 878 - */ 0, -/* 879 - */ 0, -/* 87a - */ 0, -/* 87b - */ 0, -/* 87c - */ 0, -/* 87d - */ 0, -/* 87e - */ 0, -/* 87f - */ 0, -/* 880 - */ 0, -/* 881 - */ 0, -/* 882 - */ 0, -/* 883 - */ 0, -/* 884 - */ 0, -/* 885 - */ 0, -/* 886 - */ 0, -/* 887 - */ 0, -/* 888 - */ 0, -/* 889 - */ 0, -/* 88a - */ 0, -/* 88b - */ 0, -/* 88c - */ 0, -/* 88d - */ 0, -/* 88e - */ 0, -/* 88f - */ 0, -/* 890 - */ 0, -/* 891 - */ 0, -/* 892 - */ 0, -/* 893 - */ 0, -/* 894 - */ 0, -/* 895 - */ 0, -/* 896 - */ 0, -/* 897 - */ 0, -/* 898 - */ 0, -/* 899 - */ 0, -/* 89a - */ 0, -/* 89b - */ 0, -/* 89c - */ 0, -/* 89d - */ 0, -/* 89e - */ 0, -/* 89f - */ 0, -/* 8a0 - */ 0, -/* 8a1 - */ 0, -/* 8a2 - */ 0, -/* 8a3 - */ 0, -/* 8a4 - */ 0, -/* 8a5 - */ 0, -/* 8a6 - */ 0, -/* 8a7 - */ 0, -/* 8a8 - */ 0, -/* 8a9 - */ 0, -/* 8aa - */ 0, -/* 8ab - */ 0, -/* 8ac - */ 0, -/* 8ad - */ 0, -/* 8ae - */ 0, -/* 8af - */ 0, -/* 8b0 - */ 0, -/* 8b1 - */ 0, -/* 8b2 - */ 0, -/* 8b3 - */ 0, -/* 8b4 - */ 0, -/* 8b5 - */ 0, -/* 8b6 - */ 0, -/* 8b7 - */ 0, -/* 8b8 - */ 0, -/* 8b9 - */ 0, -/* 8ba - */ 0, -/* 8bb - */ 0, -/* 8bc - */ 0, -/* 8bd - */ 0, -/* 8be - */ 0, -/* 8bf - */ 0, -/* 8c0 - */ 0, -/* 8c1 - */ 0, -/* 8c2 - */ 0, -/* 8c3 - */ 0, -/* 8c4 - */ 0, -/* 8c5 - */ 0, -/* 8c6 - */ 0, -/* 8c7 - _0F_3A_DF */ 0xd4f8, -/* 8c8 - */ 0, -/* 8c9 - */ 0, -/* 8ca - */ 0, -/* 8cb - */ 0, -/* 8cc - */ 0, -/* 8cd - */ 0, -/* 8ce - */ 0, -/* 8cf - */ 0, -/* 8d0 - */ 0, -/* 8d1 - */ 0, -/* 8d2 - */ 0, -/* 8d3 - */ 0, -/* 8d4 - */ 0, -/* 8d5 - */ 0, -/* 8d6 - */ 0, -/* 8d7 - */ 0, -/* 8d8 - */ 0, -/* 8d9 - */ 0, -/* 8da - */ 0, -/* 8db - */ 0, -/* 8dc - */ 0, -/* 8dd - */ 0, -/* 8de - */ 0, -/* 8df - */ 0, -/* 8e0 - */ 0, -/* 8e1 - */ 0, -/* 8e2 - */ 0, -/* 8e3 - */ 0, -/* 8e4 - */ 0, -/* 8e5 - */ 0, -/* 8e6 - */ 0, -/* 8e7 - */ 0, -/* 8e8 - _0F_50 */ 0x23a0, -/* 8e9 - _66_0F_50 */ 0x23a1, -/* 8ea - */ 0, -/* 8eb - */ 0, -/* 8ec - _V_0F_50 */ 0x4036, -/* 8ed - _V_66_0F_50 */ 0x4037, -/* 8ee - */ 0, -/* 8ef - */ 0, -/* 8f0 - */ 0, -/* 8f1 - */ 0, -/* 8f2 - */ 0, -/* 8f3 - */ 0, -/* 8f4 - _0F_51 */ 0x23a2, -/* 8f5 - _66_0F_51 */ 0x23a3, -/* 8f6 - _F3_0F_51 */ 0x23a4, -/* 8f7 - _F2_0F_51 */ 0x23a5, -/* 8f8 - _V_0F_51 */ 0x4038, -/* 8f9 - _V_66_0F_51 */ 0x4039, -/* 8fa - _V_F3_0F_51 */ 0x403a, -/* 8fb - _V_F2_0F_51 */ 0x403b, -/* 8fc - */ 0, -/* 8fd - */ 0, -/* 8fe - */ 0, -/* 8ff - */ 0, -/* 900 - _0F_52 */ 0x23a6, -/* 901 - */ 0, -/* 902 - _F3_0F_52 */ 0x23a7, -/* 903 - */ 0, -/* 904 - _V_0F_52 */ 0x403c, -/* 905 - */ 0, -/* 906 - _V_F3_0F_52 */ 0x403d, -/* 907 - */ 0, -/* 908 - */ 0, -/* 909 - */ 0, -/* 90a - */ 0, -/* 90b - */ 0, -/* 90c - _0F_53 */ 0x23a8, -/* 90d - */ 0, -/* 90e - _F3_0F_53 */ 0x23a9, -/* 90f - */ 0, -/* 910 - _V_0F_53 */ 0x403e, -/* 911 - */ 0, -/* 912 - _V_F3_0F_53 */ 0x403f, -/* 913 - */ 0, -/* 914 - */ 0, -/* 915 - */ 0, -/* 916 - */ 0, -/* 917 - */ 0, -/* 918 - _0F_54 */ 0x23aa, -/* 919 - _66_0F_54 */ 0x23ab, -/* 91a - */ 0, -/* 91b - */ 0, -/* 91c - _V_0F_54 */ 0x4040, -/* 91d - _V_66_0F_54 */ 0x4041, -/* 91e - */ 0, -/* 91f - */ 0, -/* 920 - */ 0, -/* 921 - */ 0, -/* 922 - */ 0, -/* 923 - */ 0, -/* 924 - _0F_55 */ 0x23ac, -/* 925 - _66_0F_55 */ 0x23ad, -/* 926 - */ 0, -/* 927 - */ 0, -/* 928 - _V_0F_55 */ 0x4042, -/* 929 - _V_66_0F_55 */ 0x4043, -/* 92a - */ 0, -/* 92b - */ 0, -/* 92c - */ 0, -/* 92d - */ 0, -/* 92e - */ 0, -/* 92f - */ 0, -/* 930 - _0F_56 */ 0x23ae, -/* 931 - _66_0F_56 */ 0x23af, -/* 932 - */ 0, -/* 933 - */ 0, -/* 934 - _V_0F_56 */ 0x4044, -/* 935 - _V_66_0F_56 */ 0x4045, -/* 936 - */ 0, -/* 937 - */ 0, -/* 938 - */ 0, -/* 939 - */ 0, -/* 93a - */ 0, -/* 93b - */ 0, -/* 93c - _0F_57 */ 0x23b0, -/* 93d - _66_0F_57 */ 0x23b1, -/* 93e - */ 0, -/* 93f - */ 0, -/* 940 - _V_0F_57 */ 0x4046, -/* 941 - _V_66_0F_57 */ 0x4047, -/* 942 - */ 0, -/* 943 - */ 0, -/* 944 - */ 0, -/* 945 - */ 0, -/* 946 - */ 0, -/* 947 - */ 0, -/* 948 - _0F_58 */ 0x23b2, -/* 949 - _66_0F_58 */ 0x23b3, -/* 94a - _F3_0F_58 */ 0x23b4, -/* 94b - _F2_0F_58 */ 0x23b5, -/* 94c - _V_0F_58 */ 0x4048, -/* 94d - _V_66_0F_58 */ 0x4049, -/* 94e - _V_F3_0F_58 */ 0x404a, -/* 94f - _V_F2_0F_58 */ 0x404b, -/* 950 - */ 0, -/* 951 - */ 0, -/* 952 - */ 0, -/* 953 - */ 0, -/* 954 - _0F_59 */ 0x23b6, -/* 955 - _66_0F_59 */ 0x23b7, -/* 956 - _F3_0F_59 */ 0x23b8, -/* 957 - _F2_0F_59 */ 0x23b9, -/* 958 - _V_0F_59 */ 0x404c, -/* 959 - _V_66_0F_59 */ 0x404d, -/* 95a - _V_F3_0F_59 */ 0x404e, -/* 95b - _V_F2_0F_59 */ 0x404f, -/* 95c - */ 0, -/* 95d - */ 0, -/* 95e - */ 0, -/* 95f - */ 0, -/* 960 - _0F_5A */ 0x23ba, -/* 961 - _66_0F_5A */ 0x23bb, -/* 962 - _F3_0F_5A */ 0x23bc, -/* 963 - _F2_0F_5A */ 0x23bd, -/* 964 - _V_0F_5A */ 0x4050, -/* 965 - _V_66_0F_5A */ 0x4051, -/* 966 - _V_F3_0F_5A */ 0x4052, -/* 967 - _V_F2_0F_5A */ 0x4053, -/* 968 - */ 0, -/* 969 - */ 0, -/* 96a - */ 0, -/* 96b - */ 0, -/* 96c - _0F_5B */ 0x23be, -/* 96d - _66_0F_5B */ 0x23bf, -/* 96e - _F3_0F_5B */ 0x23c0, -/* 96f - */ 0, -/* 970 - _V_0F_5B */ 0x4054, -/* 971 - _V_66_0F_5B */ 0x4055, -/* 972 - _V_F3_0F_5B */ 0x4056, -/* 973 - */ 0, -/* 974 - */ 0, -/* 975 - */ 0, -/* 976 - */ 0, -/* 977 - */ 0, -/* 978 - _0F_5C */ 0x23c1, -/* 979 - _66_0F_5C */ 0x23c2, -/* 97a - _F3_0F_5C */ 0x23c3, -/* 97b - _F2_0F_5C */ 0x23c4, -/* 97c - _V_0F_5C */ 0x4057, -/* 97d - _V_66_0F_5C */ 0x4058, -/* 97e - _V_F3_0F_5C */ 0x4059, -/* 97f - _V_F2_0F_5C */ 0x405a, -/* 980 - */ 0, -/* 981 - */ 0, -/* 982 - */ 0, -/* 983 - */ 0, -/* 984 - _0F_5D */ 0x23c5, -/* 985 - _66_0F_5D */ 0x23c6, -/* 986 - _F3_0F_5D */ 0x23c7, -/* 987 - _F2_0F_5D */ 0x23c8, -/* 988 - _V_0F_5D */ 0x405b, -/* 989 - _V_66_0F_5D */ 0x405c, -/* 98a - _V_F3_0F_5D */ 0x405d, -/* 98b - _V_F2_0F_5D */ 0x405e, -/* 98c - */ 0, -/* 98d - */ 0, -/* 98e - */ 0, -/* 98f - */ 0, -/* 990 - _0F_5E */ 0x23c9, -/* 991 - _66_0F_5E */ 0x23ca, -/* 992 - _F3_0F_5E */ 0x23cb, -/* 993 - _F2_0F_5E */ 0x23cc, -/* 994 - _V_0F_5E */ 0x405f, -/* 995 - _V_66_0F_5E */ 0x4060, -/* 996 - _V_F3_0F_5E */ 0x4061, -/* 997 - _V_F2_0F_5E */ 0x4062, -/* 998 - */ 0, -/* 999 - */ 0, -/* 99a - */ 0, -/* 99b - */ 0, -/* 99c - _0F_5F */ 0x23cd, -/* 99d - _66_0F_5F */ 0x23ce, -/* 99e - _F3_0F_5F */ 0x23cf, -/* 99f - _F2_0F_5F */ 0x23d0, -/* 9a0 - _V_0F_5F */ 0x4063, -/* 9a1 - _V_66_0F_5F */ 0x4064, -/* 9a2 - _V_F3_0F_5F */ 0x4065, -/* 9a3 - _V_F2_0F_5F */ 0x4066, -/* 9a4 - */ 0, -/* 9a5 - */ 0, -/* 9a6 - */ 0, -/* 9a7 - */ 0, -/* 9a8 - _0F_60 */ 0x23d1, -/* 9a9 - _66_0F_60 */ 0x23d2, -/* 9aa - */ 0, -/* 9ab - */ 0, -/* 9ac - */ 0, -/* 9ad - _V_66_0F_60 */ 0x4067, -/* 9ae - */ 0, -/* 9af - */ 0, -/* 9b0 - */ 0, -/* 9b1 - */ 0, -/* 9b2 - */ 0, -/* 9b3 - */ 0, -/* 9b4 - _0F_61 */ 0x23d3, -/* 9b5 - _66_0F_61 */ 0x23d4, -/* 9b6 - */ 0, -/* 9b7 - */ 0, -/* 9b8 - */ 0, -/* 9b9 - _V_66_0F_61 */ 0x4068, -/* 9ba - */ 0, -/* 9bb - */ 0, -/* 9bc - */ 0, -/* 9bd - */ 0, -/* 9be - */ 0, -/* 9bf - */ 0, -/* 9c0 - _0F_62 */ 0x23d5, -/* 9c1 - _66_0F_62 */ 0x23d6, -/* 9c2 - */ 0, -/* 9c3 - */ 0, -/* 9c4 - */ 0, -/* 9c5 - _V_66_0F_62 */ 0x4069, -/* 9c6 - */ 0, -/* 9c7 - */ 0, -/* 9c8 - */ 0, -/* 9c9 - */ 0, -/* 9ca - */ 0, -/* 9cb - */ 0, -/* 9cc - _0F_63 */ 0x23d7, -/* 9cd - _66_0F_63 */ 0x23d8, -/* 9ce - */ 0, -/* 9cf - */ 0, -/* 9d0 - */ 0, -/* 9d1 - _V_66_0F_63 */ 0x406a, -/* 9d2 - */ 0, -/* 9d3 - */ 0, -/* 9d4 - */ 0, -/* 9d5 - */ 0, -/* 9d6 - */ 0, -/* 9d7 - */ 0, -/* 9d8 - _0F_64 */ 0x23d9, -/* 9d9 - _66_0F_64 */ 0x23da, -/* 9da - */ 0, -/* 9db - */ 0, -/* 9dc - */ 0, -/* 9dd - _V_66_0F_64 */ 0x406b, -/* 9de - */ 0, -/* 9df - */ 0, -/* 9e0 - */ 0, -/* 9e1 - */ 0, -/* 9e2 - */ 0, -/* 9e3 - */ 0, -/* 9e4 - _0F_65 */ 0x23db, -/* 9e5 - _66_0F_65 */ 0x23dc, -/* 9e6 - */ 0, -/* 9e7 - */ 0, -/* 9e8 - */ 0, -/* 9e9 - _V_66_0F_65 */ 0x406c, -/* 9ea - */ 0, -/* 9eb - */ 0, -/* 9ec - */ 0, -/* 9ed - */ 0, -/* 9ee - */ 0, -/* 9ef - */ 0, -/* 9f0 - _0F_66 */ 0x23dd, -/* 9f1 - _66_0F_66 */ 0x23de, -/* 9f2 - */ 0, -/* 9f3 - */ 0, -/* 9f4 - */ 0, -/* 9f5 - _V_66_0F_66 */ 0x406d, -/* 9f6 - */ 0, -/* 9f7 - */ 0, -/* 9f8 - */ 0, -/* 9f9 - */ 0, -/* 9fa - */ 0, -/* 9fb - */ 0, -/* 9fc - _0F_67 */ 0x23df, -/* 9fd - _66_0F_67 */ 0x23e0, -/* 9fe - */ 0, -/* 9ff - */ 0, -/* a00 - */ 0, -/* a01 - _V_66_0F_67 */ 0x406e, -/* a02 - */ 0, -/* a03 - */ 0, -/* a04 - */ 0, -/* a05 - */ 0, -/* a06 - */ 0, -/* a07 - */ 0, -/* a08 - _0F_68 */ 0x23e1, -/* a09 - _66_0F_68 */ 0x23e2, -/* a0a - */ 0, -/* a0b - */ 0, -/* a0c - */ 0, -/* a0d - _V_66_0F_68 */ 0x406f, -/* a0e - */ 0, -/* a0f - */ 0, -/* a10 - */ 0, -/* a11 - */ 0, -/* a12 - */ 0, -/* a13 - */ 0, -/* a14 - _0F_69 */ 0x23e3, -/* a15 - _66_0F_69 */ 0x23e4, -/* a16 - */ 0, -/* a17 - */ 0, -/* a18 - */ 0, -/* a19 - _V_66_0F_69 */ 0x4070, -/* a1a - */ 0, -/* a1b - */ 0, -/* a1c - */ 0, -/* a1d - */ 0, -/* a1e - */ 0, -/* a1f - */ 0, -/* a20 - _0F_6A */ 0x23e5, -/* a21 - _66_0F_6A */ 0x23e6, -/* a22 - */ 0, -/* a23 - */ 0, -/* a24 - */ 0, -/* a25 - _V_66_0F_6A */ 0x4071, -/* a26 - */ 0, -/* a27 - */ 0, -/* a28 - */ 0, -/* a29 - */ 0, -/* a2a - */ 0, -/* a2b - */ 0, -/* a2c - _0F_6B */ 0x23e7, -/* a2d - _66_0F_6B */ 0x23e8, -/* a2e - */ 0, -/* a2f - */ 0, -/* a30 - */ 0, -/* a31 - _V_66_0F_6B */ 0x4072, -/* a32 - */ 0, -/* a33 - */ 0, -/* a34 - */ 0, -/* a35 - */ 0, -/* a36 - */ 0, -/* a37 - */ 0, -/* a38 - */ 0, -/* a39 - _66_0F_6C */ 0x23e9, -/* a3a - */ 0, -/* a3b - */ 0, -/* a3c - */ 0, -/* a3d - _V_66_0F_6C */ 0x4073, -/* a3e - */ 0, -/* a3f - */ 0, -/* a40 - */ 0, -/* a41 - */ 0, -/* a42 - */ 0, -/* a43 - */ 0, -/* a44 - */ 0, -/* a45 - _66_0F_6D */ 0x23ea, -/* a46 - */ 0, -/* a47 - */ 0, -/* a48 - */ 0, -/* a49 - _V_66_0F_6D */ 0x4074, -/* a4a - */ 0, -/* a4b - */ 0, -/* a4c - */ 0, -/* a4d - */ 0, -/* a4e - */ 0, -/* a4f - */ 0, -/* a50 - _0F_6E */ 0x4075, -/* a51 - _66_0F_6E */ 0x4076, -/* a52 - */ 0, -/* a53 - */ 0, -/* a54 - */ 0, -/* a55 - _V_66_0F_6E */ 0x4077, -/* a56 - */ 0, -/* a57 - */ 0, -/* a58 - */ 0, -/* a59 - */ 0, -/* a5a - */ 0, -/* a5b - */ 0, -/* a5c - _0F_6F */ 0x23eb, -/* a5d - _66_0F_6F */ 0x23ec, -/* a5e - _F3_0F_6F */ 0x23ed, -/* a5f - */ 0, -/* a60 - */ 0, -/* a61 - _V_66_0F_6F */ 0x4078, -/* a62 - _V_F3_0F_6F */ 0x4079, -/* a63 - */ 0, -/* a64 - */ 0, -/* a65 - */ 0, -/* a66 - */ 0, -/* a67 - */ 0, -/* a68 - _0F_70 */ 0x407a, -/* a69 - _66_0F_70 */ 0x407b, -/* a6a - _F3_0F_70 */ 0x407c, -/* a6b - _F2_0F_70 */ 0x407d, -/* a6c - */ 0, -/* a6d - _V_66_0F_70 */ 0x407e, -/* a6e - _V_F3_0F_70 */ 0x407f, -/* a6f - _V_F2_0F_70 */ 0x4080, -/* a70 - */ 0, -/* a71 - */ 0, -/* a72 - */ 0, -/* a73 - */ 0, -/* a74 - */ 0, -/* a75 - */ 0, -/* a76 - _0F_71_02 */ 0xd504, -/* a77 - */ 0, -/* a78 - _0F_71_04 */ 0xd510, -/* a79 - */ 0, -/* a7a - _0F_71_06 */ 0xd51c, -/* a7b - */ 0, -/* a7c - */ 0, -/* a7d - */ 0, -/* a7e - _0F_72_02 */ 0xd528, -/* a7f - */ 0, -/* a80 - _0F_72_04 */ 0xd534, -/* a81 - */ 0, -/* a82 - _0F_72_06 */ 0xd540, -/* a83 - */ 0, -/* a84 - */ 0, -/* a85 - */ 0, -/* a86 - _0F_73_02 */ 0xd54c, -/* a87 - _0F_73_03 */ 0xd558, -/* a88 - */ 0, -/* a89 - */ 0, -/* a8a - _0F_73_06 */ 0xd564, -/* a8b - _0F_73_07 */ 0xd570, -/* a8c - _0F_74 */ 0x23ee, -/* a8d - _66_0F_74 */ 0x23ef, -/* a8e - */ 0, -/* a8f - */ 0, -/* a90 - */ 0, -/* a91 - _V_66_0F_74 */ 0x4081, -/* a92 - */ 0, -/* a93 - */ 0, -/* a94 - */ 0, -/* a95 - */ 0, -/* a96 - */ 0, -/* a97 - */ 0, -/* a98 - _0F_75 */ 0x23f0, -/* a99 - _66_0F_75 */ 0x23f1, -/* a9a - */ 0, -/* a9b - */ 0, -/* a9c - */ 0, -/* a9d - _V_66_0F_75 */ 0x4082, -/* a9e - */ 0, -/* a9f - */ 0, -/* aa0 - */ 0, -/* aa1 - */ 0, -/* aa2 - */ 0, -/* aa3 - */ 0, -/* aa4 - _0F_76 */ 0x23f2, -/* aa5 - _66_0F_76 */ 0x23f3, -/* aa6 - */ 0, -/* aa7 - */ 0, -/* aa8 - */ 0, -/* aa9 - _V_66_0F_76 */ 0x4083, -/* aaa - */ 0, -/* aab - */ 0, -/* aac - */ 0, -/* aad - */ 0, -/* aae - */ 0, -/* aaf - */ 0, -/* ab0 - _0F_77 */ 0x23f4, -/* ab1 - */ 0, -/* ab2 - */ 0, -/* ab3 - */ 0, -/* ab4 - _V_0F_77 */ 0x4084, -/* ab5 - */ 0, -/* ab6 - */ 0, -/* ab7 - */ 0, -/* ab8 - */ 0, -/* ab9 - */ 0, -/* aba - */ 0, -/* abb - */ 0, -/* abc - _0F_78 */ 0x23f5, -/* abd - _66_0F_78 */ 0x4085, -/* abe - */ 0, -/* abf - _F2_0F_78 */ 0x4086, -/* ac0 - */ 0, -/* ac1 - */ 0, -/* ac2 - */ 0, -/* ac3 - */ 0, -/* ac4 - */ 0, -/* ac5 - */ 0, -/* ac6 - */ 0, -/* ac7 - */ 0, -/* ac8 - _0F_79 */ 0x23f6, -/* ac9 - _66_0F_79 */ 0x23f7, -/* aca - */ 0, -/* acb - _F2_0F_79 */ 0x23f8, -/* acc - */ 0, -/* acd - */ 0, -/* ace - */ 0, -/* acf - */ 0, -/* ad0 - */ 0, -/* ad1 - */ 0, -/* ad2 - */ 0, -/* ad3 - */ 0, -/* ad4 - */ 0, -/* ad5 - */ 0, -/* ad6 - */ 0, -/* ad7 - */ 0, -/* ad8 - */ 0, -/* ad9 - */ 0, -/* ada - */ 0, -/* adb - */ 0, -/* adc - */ 0, -/* add - */ 0, -/* ade - */ 0, -/* adf - */ 0, -/* ae0 - */ 0, -/* ae1 - */ 0, -/* ae2 - */ 0, -/* ae3 - */ 0, -/* ae4 - */ 0, -/* ae5 - */ 0, -/* ae6 - */ 0, -/* ae7 - */ 0, -/* ae8 - */ 0, -/* ae9 - */ 0, -/* aea - */ 0, -/* aeb - */ 0, -/* aec - */ 0, -/* aed - */ 0, -/* aee - */ 0, -/* aef - */ 0, -/* af0 - */ 0, -/* af1 - */ 0, -/* af2 - */ 0, -/* af3 - */ 0, -/* af4 - */ 0, -/* af5 - */ 0, -/* af6 - */ 0, -/* af7 - */ 0, -/* af8 - */ 0, -/* af9 - */ 0, -/* afa - */ 0, -/* afb - */ 0, -/* afc - */ 0, -/* afd - */ 0, -/* afe - */ 0, -/* aff - */ 0, -/* b00 - */ 0, -/* b01 - */ 0, -/* b02 - */ 0, -/* b03 - */ 0, -/* b04 - _0F_7A_30 */ 0x23f9, -/* b05 - _0F_7A_31 */ 0x23fa, -/* b06 - */ 0, -/* b07 - */ 0, -/* b08 - */ 0, -/* b09 - */ 0, -/* b0a - */ 0, -/* b0b - */ 0, -/* b0c - */ 0, -/* b0d - */ 0, -/* b0e - */ 0, -/* b0f - */ 0, -/* b10 - */ 0, -/* b11 - */ 0, -/* b12 - */ 0, -/* b13 - */ 0, -/* b14 - */ 0, -/* b15 - */ 0, -/* b16 - */ 0, -/* b17 - */ 0, -/* b18 - */ 0, -/* b19 - */ 0, -/* b1a - */ 0, -/* b1b - */ 0, -/* b1c - */ 0, -/* b1d - */ 0, -/* b1e - */ 0, -/* b1f - */ 0, -/* b20 - */ 0, -/* b21 - */ 0, -/* b22 - */ 0, -/* b23 - */ 0, -/* b24 - */ 0, -/* b25 - */ 0, -/* b26 - */ 0, -/* b27 - */ 0, -/* b28 - */ 0, -/* b29 - */ 0, -/* b2a - */ 0, -/* b2b - */ 0, -/* b2c - */ 0, -/* b2d - */ 0, -/* b2e - */ 0, -/* b2f - */ 0, -/* b30 - */ 0, -/* b31 - */ 0, -/* b32 - */ 0, -/* b33 - */ 0, -/* b34 - */ 0, -/* b35 - */ 0, -/* b36 - */ 0, -/* b37 - */ 0, -/* b38 - */ 0, -/* b39 - */ 0, -/* b3a - */ 0, -/* b3b - */ 0, -/* b3c - */ 0, -/* b3d - */ 0, -/* b3e - */ 0, -/* b3f - */ 0, -/* b40 - */ 0, -/* b41 - */ 0, -/* b42 - */ 0, -/* b43 - */ 0, -/* b44 - */ 0, -/* b45 - */ 0, -/* b46 - */ 0, -/* b47 - */ 0, -/* b48 - */ 0, -/* b49 - */ 0, -/* b4a - */ 0, -/* b4b - */ 0, -/* b4c - */ 0, -/* b4d - */ 0, -/* b4e - */ 0, -/* b4f - */ 0, -/* b50 - */ 0, -/* b51 - */ 0, -/* b52 - */ 0, -/* b53 - */ 0, -/* b54 - */ 0, -/* b55 - */ 0, -/* b56 - */ 0, -/* b57 - */ 0, -/* b58 - */ 0, -/* b59 - */ 0, -/* b5a - */ 0, -/* b5b - */ 0, -/* b5c - */ 0, -/* b5d - */ 0, -/* b5e - */ 0, -/* b5f - */ 0, -/* b60 - */ 0, -/* b61 - */ 0, -/* b62 - */ 0, -/* b63 - */ 0, -/* b64 - */ 0, -/* b65 - */ 0, -/* b66 - */ 0, -/* b67 - */ 0, -/* b68 - */ 0, -/* b69 - */ 0, -/* b6a - */ 0, -/* b6b - */ 0, -/* b6c - */ 0, -/* b6d - */ 0, -/* b6e - */ 0, -/* b6f - */ 0, -/* b70 - */ 0, -/* b71 - */ 0, -/* b72 - */ 0, -/* b73 - */ 0, -/* b74 - */ 0, -/* b75 - */ 0, -/* b76 - */ 0, -/* b77 - */ 0, -/* b78 - */ 0, -/* b79 - */ 0, -/* b7a - */ 0, -/* b7b - */ 0, -/* b7c - */ 0, -/* b7d - */ 0, -/* b7e - */ 0, -/* b7f - */ 0, -/* b80 - */ 0, -/* b81 - */ 0, -/* b82 - */ 0, -/* b83 - */ 0, -/* b84 - */ 0, -/* b85 - */ 0, -/* b86 - */ 0, -/* b87 - */ 0, -/* b88 - */ 0, -/* b89 - */ 0, -/* b8a - */ 0, -/* b8b - */ 0, -/* b8c - */ 0, -/* b8d - */ 0, -/* b8e - */ 0, -/* b8f - */ 0, -/* b90 - */ 0, -/* b91 - */ 0, -/* b92 - */ 0, -/* b93 - */ 0, -/* b94 - */ 0, -/* b95 - */ 0, -/* b96 - */ 0, -/* b97 - */ 0, -/* b98 - */ 0, -/* b99 - */ 0, -/* b9a - */ 0, -/* b9b - */ 0, -/* b9c - */ 0, -/* b9d - */ 0, -/* b9e - */ 0, -/* b9f - */ 0, -/* ba0 - */ 0, -/* ba1 - */ 0, -/* ba2 - */ 0, -/* ba3 - */ 0, -/* ba4 - */ 0, -/* ba5 - */ 0, -/* ba6 - */ 0, -/* ba7 - */ 0, -/* ba8 - */ 0, -/* ba9 - */ 0, -/* baa - */ 0, -/* bab - */ 0, -/* bac - */ 0, -/* bad - */ 0, -/* bae - */ 0, -/* baf - */ 0, -/* bb0 - */ 0, -/* bb1 - */ 0, -/* bb2 - */ 0, -/* bb3 - */ 0, -/* bb4 - */ 0, -/* bb5 - */ 0, -/* bb6 - */ 0, -/* bb7 - */ 0, -/* bb8 - */ 0, -/* bb9 - */ 0, -/* bba - */ 0, -/* bbb - */ 0, -/* bbc - */ 0, -/* bbd - */ 0, -/* bbe - */ 0, -/* bbf - */ 0, -/* bc0 - */ 0, -/* bc1 - */ 0, -/* bc2 - */ 0, -/* bc3 - */ 0, -/* bc4 - */ 0, -/* bc5 - */ 0, -/* bc6 - */ 0, -/* bc7 - */ 0, -/* bc8 - */ 0, -/* bc9 - */ 0, -/* bca - */ 0, -/* bcb - */ 0, -/* bcc - */ 0, -/* bcd - */ 0, -/* bce - */ 0, -/* bcf - */ 0, -/* bd0 - */ 0, -/* bd1 - */ 0, -/* bd2 - */ 0, -/* bd3 - */ 0, -/* bd4 - */ 0, -/* bd5 - _66_0F_7C */ 0x23fb, -/* bd6 - */ 0, -/* bd7 - _F2_0F_7C */ 0x23fc, -/* bd8 - */ 0, -/* bd9 - _V_66_0F_7C */ 0x4087, -/* bda - */ 0, -/* bdb - _V_F2_0F_7C */ 0x4088, -/* bdc - */ 0, -/* bdd - */ 0, -/* bde - */ 0, -/* bdf - */ 0, -/* be0 - */ 0, -/* be1 - _66_0F_7D */ 0x23fd, -/* be2 - */ 0, -/* be3 - _F2_0F_7D */ 0x23fe, -/* be4 - */ 0, -/* be5 - _V_66_0F_7D */ 0x4089, -/* be6 - */ 0, -/* be7 - _V_F2_0F_7D */ 0x408a, -/* be8 - */ 0, -/* be9 - */ 0, -/* bea - */ 0, -/* beb - */ 0, -/* bec - _0F_7E */ 0x408b, -/* bed - _66_0F_7E */ 0x408c, -/* bee - _F3_0F_7E */ 0x23ff, -/* bef - */ 0, -/* bf0 - */ 0, -/* bf1 - _V_66_0F_7E */ 0x408d, -/* bf2 - _V_F3_0F_7E */ 0x408e, -/* bf3 - */ 0, -/* bf4 - */ 0, -/* bf5 - */ 0, -/* bf6 - */ 0, -/* bf7 - */ 0, -/* bf8 - _0F_7F */ 0x2400, -/* bf9 - _66_0F_7F */ 0x2401, -/* bfa - _F3_0F_7F */ 0x2402, -/* bfb - */ 0, -/* bfc - */ 0, -/* bfd - _V_66_0F_7F */ 0x408f, -/* bfe - _V_F3_0F_7F */ 0x4090, -/* bff - */ 0, -/* c00 - */ 0, -/* c01 - */ 0, -/* c02 - */ 0, -/* c03 - */ 0, -/* c04 - _0F_AE_00 */ 0xd57c, -/* c05 - _0F_AE_01 */ 0xd588, -/* c06 - _0F_AE_02 */ 0xd594, -/* c07 - _0F_AE_03 */ 0xd5a0, -/* c08 - _0F_AE_04 */ 0x4091, -/* c09 - _0F_AE_05 */ 0x4092, -/* c0a - _0F_AE_06 */ 0x4093, -/* c0b - _0F_AE_07 */ 0x4094, -/* c0c - */ 0, -/* c0d - */ 0, -/* c0e - _F3_0F_B8 */ 0x2403, -/* c0f - */ 0, -/* c10 - */ 0, -/* c11 - */ 0, -/* c12 - */ 0, -/* c13 - */ 0, -/* c14 - */ 0, -/* c15 - */ 0, -/* c16 - */ 0, -/* c17 - */ 0, -/* c18 - */ 0, -/* c19 - */ 0, -/* c1a - */ 0, -/* c1b - */ 0, -/* c1c - _0F_BA_04 */ 0x2404, -/* c1d - _0F_BA_05 */ 0x2405, -/* c1e - _0F_BA_06 */ 0x2406, -/* c1f - _0F_BA_07 */ 0x2407, -/* c20 - _0F_BC */ 0x2408, -/* c21 - */ 0, -/* c22 - _F3_0F_BC */ 0x2409, -/* c23 - */ 0, -/* c24 - */ 0, -/* c25 - */ 0, -/* c26 - */ 0, -/* c27 - */ 0, -/* c28 - */ 0, -/* c29 - */ 0, -/* c2a - */ 0, -/* c2b - */ 0, -/* c2c - _0F_BD */ 0x240a, -/* c2d - */ 0, -/* c2e - _F3_0F_BD */ 0x240b, -/* c2f - */ 0, -/* c30 - */ 0, -/* c31 - */ 0, -/* c32 - */ 0, -/* c33 - */ 0, -/* c34 - */ 0, -/* c35 - */ 0, -/* c36 - */ 0, -/* c37 - */ 0, -/* c38 - _0F_C2 */ 0x4095, -/* c39 - _66_0F_C2 */ 0x4096, -/* c3a - _F3_0F_C2 */ 0x4097, -/* c3b - _F2_0F_C2 */ 0x4098, -/* c3c - _V_0F_C2 */ 0x4099, -/* c3d - _V_66_0F_C2 */ 0x409a, -/* c3e - _V_F3_0F_C2 */ 0x409b, -/* c3f - _V_F2_0F_C2 */ 0x409c, -/* c40 - */ 0, -/* c41 - */ 0, -/* c42 - */ 0, -/* c43 - */ 0, -/* c44 - _0F_C4 */ 0x409d, -/* c45 - _66_0F_C4 */ 0x409e, -/* c46 - */ 0, -/* c47 - */ 0, -/* c48 - */ 0, -/* c49 - _V_66_0F_C4 */ 0x409f, -/* c4a - */ 0, -/* c4b - */ 0, -/* c4c - */ 0, -/* c4d - */ 0, -/* c4e - */ 0, -/* c4f - */ 0, -/* c50 - _0F_C5 */ 0x40a0, -/* c51 - _66_0F_C5 */ 0x40a1, -/* c52 - */ 0, -/* c53 - */ 0, -/* c54 - */ 0, -/* c55 - _V_66_0F_C5 */ 0x40a2, -/* c56 - */ 0, -/* c57 - */ 0, -/* c58 - */ 0, -/* c59 - */ 0, -/* c5a - */ 0, -/* c5b - */ 0, -/* c5c - _0F_C6 */ 0x40a3, -/* c5d - _66_0F_C6 */ 0x40a4, -/* c5e - */ 0, -/* c5f - */ 0, -/* c60 - _V_0F_C6 */ 0x40a5, -/* c61 - _V_66_0F_C6 */ 0x40a6, -/* c62 - */ 0, -/* c63 - */ 0, -/* c64 - */ 0, -/* c65 - */ 0, -/* c66 - */ 0, -/* c67 - */ 0, -/* c68 - */ 0, -/* c69 - _0F_C7_01 */ 0x40a7, -/* c6a - */ 0, -/* c6b - */ 0, -/* c6c - */ 0, -/* c6d - */ 0, -/* c6e - _0F_C7_06 */ 0xd5ac, -/* c6f - _0F_C7_07 */ 0x240c, -/* c70 - */ 0, -/* c71 - _66_0F_D0 */ 0x240d, -/* c72 - */ 0, -/* c73 - _F2_0F_D0 */ 0x240e, -/* c74 - */ 0, -/* c75 - _V_66_0F_D0 */ 0x40a8, -/* c76 - */ 0, -/* c77 - _V_F2_0F_D0 */ 0x40a9, -/* c78 - */ 0, -/* c79 - */ 0, -/* c7a - */ 0, -/* c7b - */ 0, -/* c7c - _0F_D1 */ 0x240f, -/* c7d - _66_0F_D1 */ 0x2410, -/* c7e - */ 0, -/* c7f - */ 0, -/* c80 - */ 0, -/* c81 - _V_66_0F_D1 */ 0x40aa, -/* c82 - */ 0, -/* c83 - */ 0, -/* c84 - */ 0, -/* c85 - */ 0, -/* c86 - */ 0, -/* c87 - */ 0, -/* c88 - _0F_D2 */ 0x2411, -/* c89 - _66_0F_D2 */ 0x2412, -/* c8a - */ 0, -/* c8b - */ 0, -/* c8c - */ 0, -/* c8d - _V_66_0F_D2 */ 0x40ab, -/* c8e - */ 0, -/* c8f - */ 0, -/* c90 - */ 0, -/* c91 - */ 0, -/* c92 - */ 0, -/* c93 - */ 0, -/* c94 - _0F_D3 */ 0x2413, -/* c95 - _66_0F_D3 */ 0x2414, -/* c96 - */ 0, -/* c97 - */ 0, -/* c98 - */ 0, -/* c99 - _V_66_0F_D3 */ 0x40ac, -/* c9a - */ 0, -/* c9b - */ 0, -/* c9c - */ 0, -/* c9d - */ 0, -/* c9e - */ 0, -/* c9f - */ 0, -/* ca0 - _0F_D4 */ 0x2415, -/* ca1 - _66_0F_D4 */ 0x2416, -/* ca2 - */ 0, -/* ca3 - */ 0, -/* ca4 - */ 0, -/* ca5 - _V_66_0F_D4 */ 0x40ad, -/* ca6 - */ 0, -/* ca7 - */ 0, -/* ca8 - */ 0, -/* ca9 - */ 0, -/* caa - */ 0, -/* cab - */ 0, -/* cac - _0F_D5 */ 0x2417, -/* cad - _66_0F_D5 */ 0x2418, -/* cae - */ 0, -/* caf - */ 0, -/* cb0 - */ 0, -/* cb1 - _V_66_0F_D5 */ 0x40ae, -/* cb2 - */ 0, -/* cb3 - */ 0, -/* cb4 - */ 0, -/* cb5 - */ 0, -/* cb6 - */ 0, -/* cb7 - */ 0, -/* cb8 - */ 0, -/* cb9 - _66_0F_D6 */ 0x2419, -/* cba - _F3_0F_D6 */ 0x241a, -/* cbb - _F2_0F_D6 */ 0x241b, -/* cbc - */ 0, -/* cbd - _V_66_0F_D6 */ 0x40af, -/* cbe - */ 0, -/* cbf - */ 0, -/* cc0 - */ 0, -/* cc1 - */ 0, -/* cc2 - */ 0, -/* cc3 - */ 0, -/* cc4 - _0F_D7 */ 0x241c, -/* cc5 - _66_0F_D7 */ 0x241d, -/* cc6 - */ 0, -/* cc7 - */ 0, -/* cc8 - */ 0, -/* cc9 - _V_66_0F_D7 */ 0x40b0, -/* cca - */ 0, -/* ccb - */ 0, -/* ccc - */ 0, -/* ccd - */ 0, -/* cce - */ 0, -/* ccf - */ 0, -/* cd0 - _0F_D8 */ 0x241e, -/* cd1 - _66_0F_D8 */ 0x241f, -/* cd2 - */ 0, -/* cd3 - */ 0, -/* cd4 - */ 0, -/* cd5 - _V_66_0F_D8 */ 0x40b1, -/* cd6 - */ 0, -/* cd7 - */ 0, -/* cd8 - */ 0, -/* cd9 - */ 0, -/* cda - */ 0, -/* cdb - */ 0, -/* cdc - _0F_D9 */ 0x2420, -/* cdd - _66_0F_D9 */ 0x2421, -/* cde - */ 0, -/* cdf - */ 0, -/* ce0 - */ 0, -/* ce1 - _V_66_0F_D9 */ 0x40b2, -/* ce2 - */ 0, -/* ce3 - */ 0, -/* ce4 - */ 0, -/* ce5 - */ 0, -/* ce6 - */ 0, -/* ce7 - */ 0, -/* ce8 - _0F_DA */ 0x2422, -/* ce9 - _66_0F_DA */ 0x2423, -/* cea - */ 0, -/* ceb - */ 0, -/* cec - */ 0, -/* ced - _V_66_0F_DA */ 0x40b3, -/* cee - */ 0, -/* cef - */ 0, -/* cf0 - */ 0, -/* cf1 - */ 0, -/* cf2 - */ 0, -/* cf3 - */ 0, -/* cf4 - _0F_DB */ 0x2424, -/* cf5 - _66_0F_DB */ 0x2425, -/* cf6 - */ 0, -/* cf7 - */ 0, -/* cf8 - */ 0, -/* cf9 - _V_66_0F_DB */ 0x40b4, -/* cfa - */ 0, -/* cfb - */ 0, -/* cfc - */ 0, -/* cfd - */ 0, -/* cfe - */ 0, -/* cff - */ 0, -/* d00 - _0F_DC */ 0x2426, -/* d01 - _66_0F_DC */ 0x2427, -/* d02 - */ 0, -/* d03 - */ 0, -/* d04 - */ 0, -/* d05 - _V_66_0F_DC */ 0x40b5, -/* d06 - */ 0, -/* d07 - */ 0, -/* d08 - */ 0, -/* d09 - */ 0, -/* d0a - */ 0, -/* d0b - */ 0, -/* d0c - _0F_DD */ 0x2428, -/* d0d - _66_0F_DD */ 0x2429, -/* d0e - */ 0, -/* d0f - */ 0, -/* d10 - */ 0, -/* d11 - _V_66_0F_DD */ 0x40b6, -/* d12 - */ 0, -/* d13 - */ 0, -/* d14 - */ 0, -/* d15 - */ 0, -/* d16 - */ 0, -/* d17 - */ 0, -/* d18 - _0F_DE */ 0x242a, -/* d19 - _66_0F_DE */ 0x242b, -/* d1a - */ 0, -/* d1b - */ 0, -/* d1c - */ 0, -/* d1d - _V_66_0F_DE */ 0x40b7, -/* d1e - */ 0, -/* d1f - */ 0, -/* d20 - */ 0, -/* d21 - */ 0, -/* d22 - */ 0, -/* d23 - */ 0, -/* d24 - _0F_DF */ 0x242c, -/* d25 - _66_0F_DF */ 0x242d, -/* d26 - */ 0, -/* d27 - */ 0, -/* d28 - */ 0, -/* d29 - _V_66_0F_DF */ 0x40b8, -/* d2a - */ 0, -/* d2b - */ 0, -/* d2c - */ 0, -/* d2d - */ 0, -/* d2e - */ 0, -/* d2f - */ 0, -/* d30 - _0F_E0 */ 0x242e, -/* d31 - _66_0F_E0 */ 0x242f, -/* d32 - */ 0, -/* d33 - */ 0, -/* d34 - */ 0, -/* d35 - _V_66_0F_E0 */ 0x40b9, -/* d36 - */ 0, -/* d37 - */ 0, -/* d38 - */ 0, -/* d39 - */ 0, -/* d3a - */ 0, -/* d3b - */ 0, -/* d3c - _0F_E1 */ 0x2430, -/* d3d - _66_0F_E1 */ 0x2431, -/* d3e - */ 0, -/* d3f - */ 0, -/* d40 - */ 0, -/* d41 - _V_66_0F_E1 */ 0x40ba, -/* d42 - */ 0, -/* d43 - */ 0, -/* d44 - */ 0, -/* d45 - */ 0, -/* d46 - */ 0, -/* d47 - */ 0, -/* d48 - _0F_E2 */ 0x2432, -/* d49 - _66_0F_E2 */ 0x2433, -/* d4a - */ 0, -/* d4b - */ 0, -/* d4c - */ 0, -/* d4d - _V_66_0F_E2 */ 0x40bb, -/* d4e - */ 0, -/* d4f - */ 0, -/* d50 - */ 0, -/* d51 - */ 0, -/* d52 - */ 0, -/* d53 - */ 0, -/* d54 - _0F_E3 */ 0x2434, -/* d55 - _66_0F_E3 */ 0x2435, -/* d56 - */ 0, -/* d57 - */ 0, -/* d58 - */ 0, -/* d59 - _V_66_0F_E3 */ 0x40bc, -/* d5a - */ 0, -/* d5b - */ 0, -/* d5c - */ 0, -/* d5d - */ 0, -/* d5e - */ 0, -/* d5f - */ 0, -/* d60 - _0F_E4 */ 0x2436, -/* d61 - _66_0F_E4 */ 0x2437, -/* d62 - */ 0, -/* d63 - */ 0, -/* d64 - */ 0, -/* d65 - _V_66_0F_E4 */ 0x40bd, -/* d66 - */ 0, -/* d67 - */ 0, -/* d68 - */ 0, -/* d69 - */ 0, -/* d6a - */ 0, -/* d6b - */ 0, -/* d6c - _0F_E5 */ 0x2438, -/* d6d - _66_0F_E5 */ 0x2439, -/* d6e - */ 0, -/* d6f - */ 0, -/* d70 - */ 0, -/* d71 - _V_66_0F_E5 */ 0x40be, -/* d72 - */ 0, -/* d73 - */ 0, -/* d74 - */ 0, -/* d75 - */ 0, -/* d76 - */ 0, -/* d77 - */ 0, -/* d78 - */ 0, -/* d79 - _66_0F_E6 */ 0x243a, -/* d7a - _F3_0F_E6 */ 0x243b, -/* d7b - _F2_0F_E6 */ 0x243c, -/* d7c - */ 0, -/* d7d - _V_66_0F_E6 */ 0x40bf, -/* d7e - _V_F3_0F_E6 */ 0x40c0, -/* d7f - _V_F2_0F_E6 */ 0x40c1, -/* d80 - */ 0, -/* d81 - */ 0, -/* d82 - */ 0, -/* d83 - */ 0, -/* d84 - _0F_E7 */ 0x243d, -/* d85 - _66_0F_E7 */ 0x243e, -/* d86 - */ 0, -/* d87 - */ 0, -/* d88 - */ 0, -/* d89 - _V_66_0F_E7 */ 0x40c2, -/* d8a - */ 0, -/* d8b - */ 0, -/* d8c - */ 0, -/* d8d - */ 0, -/* d8e - */ 0, -/* d8f - */ 0, -/* d90 - _0F_E8 */ 0x243f, -/* d91 - _66_0F_E8 */ 0x2440, -/* d92 - */ 0, -/* d93 - */ 0, -/* d94 - */ 0, -/* d95 - _V_66_0F_E8 */ 0x40c3, -/* d96 - */ 0, -/* d97 - */ 0, -/* d98 - */ 0, -/* d99 - */ 0, -/* d9a - */ 0, -/* d9b - */ 0, -/* d9c - _0F_E9 */ 0x2441, -/* d9d - _66_0F_E9 */ 0x2442, -/* d9e - */ 0, -/* d9f - */ 0, -/* da0 - */ 0, -/* da1 - _V_66_0F_E9 */ 0x40c4, -/* da2 - */ 0, -/* da3 - */ 0, -/* da4 - */ 0, -/* da5 - */ 0, -/* da6 - */ 0, -/* da7 - */ 0, -/* da8 - _0F_EA */ 0x2443, -/* da9 - _66_0F_EA */ 0x2444, -/* daa - */ 0, -/* dab - */ 0, -/* dac - */ 0, -/* dad - _V_66_0F_EA */ 0x40c5, -/* dae - */ 0, -/* daf - */ 0, -/* db0 - */ 0, -/* db1 - */ 0, -/* db2 - */ 0, -/* db3 - */ 0, -/* db4 - _0F_EB */ 0x2445, -/* db5 - _66_0F_EB */ 0x2446, -/* db6 - */ 0, -/* db7 - */ 0, -/* db8 - */ 0, -/* db9 - _V_66_0F_EB */ 0x40c6, -/* dba - */ 0, -/* dbb - */ 0, -/* dbc - */ 0, -/* dbd - */ 0, -/* dbe - */ 0, -/* dbf - */ 0, -/* dc0 - _0F_EC */ 0x2447, -/* dc1 - _66_0F_EC */ 0x2448, -/* dc2 - */ 0, -/* dc3 - */ 0, -/* dc4 - */ 0, -/* dc5 - _V_66_0F_EC */ 0x40c7, -/* dc6 - */ 0, -/* dc7 - */ 0, -/* dc8 - */ 0, -/* dc9 - */ 0, -/* dca - */ 0, -/* dcb - */ 0, -/* dcc - _0F_ED */ 0x2449, -/* dcd - _66_0F_ED */ 0x244a, -/* dce - */ 0, -/* dcf - */ 0, -/* dd0 - */ 0, -/* dd1 - _V_66_0F_ED */ 0x40c8, -/* dd2 - */ 0, -/* dd3 - */ 0, -/* dd4 - */ 0, -/* dd5 - */ 0, -/* dd6 - */ 0, -/* dd7 - */ 0, -/* dd8 - _0F_EE */ 0x244b, -/* dd9 - _66_0F_EE */ 0x244c, -/* dda - */ 0, -/* ddb - */ 0, -/* ddc - */ 0, -/* ddd - _V_66_0F_EE */ 0x40c9, -/* dde - */ 0, -/* ddf - */ 0, -/* de0 - */ 0, -/* de1 - */ 0, -/* de2 - */ 0, -/* de3 - */ 0, -/* de4 - _0F_EF */ 0x244d, -/* de5 - _66_0F_EF */ 0x244e, -/* de6 - */ 0, -/* de7 - */ 0, -/* de8 - */ 0, -/* de9 - _V_66_0F_EF */ 0x40ca, -/* dea - */ 0, -/* deb - */ 0, -/* dec - */ 0, -/* ded - */ 0, -/* dee - */ 0, -/* def - */ 0, -/* df0 - */ 0, -/* df1 - */ 0, -/* df2 - */ 0, -/* df3 - _F2_0F_F0 */ 0x244f, -/* df4 - */ 0, -/* df5 - */ 0, -/* df6 - */ 0, -/* df7 - _V_F2_0F_F0 */ 0x40cb, -/* df8 - */ 0, -/* df9 - */ 0, -/* dfa - */ 0, -/* dfb - */ 0, -/* dfc - _0F_F1 */ 0x2450, -/* dfd - _66_0F_F1 */ 0x2451, -/* dfe - */ 0, -/* dff - */ 0, -/* e00 - */ 0, -/* e01 - _V_66_0F_F1 */ 0x40cc, -/* e02 - */ 0, -/* e03 - */ 0, -/* e04 - */ 0, -/* e05 - */ 0, -/* e06 - */ 0, -/* e07 - */ 0, -/* e08 - _0F_F2 */ 0x2452, -/* e09 - _66_0F_F2 */ 0x2453, -/* e0a - */ 0, -/* e0b - */ 0, -/* e0c - */ 0, -/* e0d - _V_66_0F_F2 */ 0x40cd, -/* e0e - */ 0, -/* e0f - */ 0, -/* e10 - */ 0, -/* e11 - */ 0, -/* e12 - */ 0, -/* e13 - */ 0, -/* e14 - _0F_F3 */ 0x2454, -/* e15 - _66_0F_F3 */ 0x2455, -/* e16 - */ 0, -/* e17 - */ 0, -/* e18 - */ 0, -/* e19 - _V_66_0F_F3 */ 0x40ce, -/* e1a - */ 0, -/* e1b - */ 0, -/* e1c - */ 0, -/* e1d - */ 0, -/* e1e - */ 0, -/* e1f - */ 0, -/* e20 - _0F_F4 */ 0x2456, -/* e21 - _66_0F_F4 */ 0x2457, -/* e22 - */ 0, -/* e23 - */ 0, -/* e24 - */ 0, -/* e25 - _V_66_0F_F4 */ 0x40cf, -/* e26 - */ 0, -/* e27 - */ 0, -/* e28 - */ 0, -/* e29 - */ 0, -/* e2a - */ 0, -/* e2b - */ 0, -/* e2c - _0F_F5 */ 0x2458, -/* e2d - _66_0F_F5 */ 0x2459, -/* e2e - */ 0, -/* e2f - */ 0, -/* e30 - */ 0, -/* e31 - _V_66_0F_F5 */ 0x40d0, -/* e32 - */ 0, -/* e33 - */ 0, -/* e34 - */ 0, -/* e35 - */ 0, -/* e36 - */ 0, -/* e37 - */ 0, -/* e38 - _0F_F6 */ 0x245a, -/* e39 - _66_0F_F6 */ 0x245b, -/* e3a - */ 0, -/* e3b - */ 0, -/* e3c - */ 0, -/* e3d - _V_66_0F_F6 */ 0x40d1, -/* e3e - */ 0, -/* e3f - */ 0, -/* e40 - */ 0, -/* e41 - */ 0, -/* e42 - */ 0, -/* e43 - */ 0, -/* e44 - _0F_F7 */ 0x245c, -/* e45 - _66_0F_F7 */ 0x245d, -/* e46 - */ 0, -/* e47 - */ 0, -/* e48 - */ 0, -/* e49 - _V_66_0F_F7 */ 0x40d2, -/* e4a - */ 0, -/* e4b - */ 0, -/* e4c - */ 0, -/* e4d - */ 0, -/* e4e - */ 0, -/* e4f - */ 0, -/* e50 - _0F_F8 */ 0x245e, -/* e51 - _66_0F_F8 */ 0x245f, -/* e52 - */ 0, -/* e53 - */ 0, -/* e54 - */ 0, -/* e55 - _V_66_0F_F8 */ 0x40d3, -/* e56 - */ 0, -/* e57 - */ 0, -/* e58 - */ 0, -/* e59 - */ 0, -/* e5a - */ 0, -/* e5b - */ 0, -/* e5c - _0F_F9 */ 0x2460, -/* e5d - _66_0F_F9 */ 0x2461, -/* e5e - */ 0, -/* e5f - */ 0, -/* e60 - */ 0, -/* e61 - _V_66_0F_F9 */ 0x40d4, -/* e62 - */ 0, -/* e63 - */ 0, -/* e64 - */ 0, -/* e65 - */ 0, -/* e66 - */ 0, -/* e67 - */ 0, -/* e68 - _0F_FA */ 0x2462, -/* e69 - _66_0F_FA */ 0x2463, -/* e6a - */ 0, -/* e6b - */ 0, -/* e6c - */ 0, -/* e6d - _V_66_0F_FA */ 0x40d5, -/* e6e - */ 0, -/* e6f - */ 0, -/* e70 - */ 0, -/* e71 - */ 0, -/* e72 - */ 0, -/* e73 - */ 0, -/* e74 - _0F_FB */ 0x2464, -/* e75 - _66_0F_FB */ 0x2465, -/* e76 - */ 0, -/* e77 - */ 0, -/* e78 - */ 0, -/* e79 - _V_66_0F_FB */ 0x40d6, -/* e7a - */ 0, -/* e7b - */ 0, -/* e7c - */ 0, -/* e7d - */ 0, -/* e7e - */ 0, -/* e7f - */ 0, -/* e80 - _0F_FC */ 0x2466, -/* e81 - _66_0F_FC */ 0x2467, -/* e82 - */ 0, -/* e83 - */ 0, -/* e84 - */ 0, -/* e85 - _V_66_0F_FC */ 0x40d7, -/* e86 - */ 0, -/* e87 - */ 0, -/* e88 - */ 0, -/* e89 - */ 0, -/* e8a - */ 0, -/* e8b - */ 0, -/* e8c - _0F_FD */ 0x2468, -/* e8d - _66_0F_FD */ 0x2469, -/* e8e - */ 0, -/* e8f - */ 0, -/* e90 - */ 0, -/* e91 - _V_66_0F_FD */ 0x40d8, -/* e92 - */ 0, -/* e93 - */ 0, -/* e94 - */ 0, -/* e95 - */ 0, -/* e96 - */ 0, -/* e97 - */ 0, -/* e98 - _0F_FE */ 0x246a, -/* e99 - _66_0F_FE */ 0x246b, -/* e9a - */ 0, -/* e9b - */ 0, -/* e9c - */ 0, -/* e9d - _V_66_0F_FE */ 0x40d9, -/* e9e - */ 0, -/* e9f - */ 0, -/* ea0 - */ 0, -/* ea1 - */ 0, -/* ea2 - */ 0, -/* ea3 - */ 0, -/* ea4 - _D9_06 */ 0x246c, -/* ea5 - _9B_D9_06 */ 0x246d, -/* ea6 - */ 0, -/* ea7 - */ 0, -/* ea8 - */ 0, -/* ea9 - */ 0, -/* eaa - */ 0, -/* eab - */ 0, -/* eac - */ 0, -/* ead - */ 0, -/* eae - */ 0, -/* eaf - */ 0, -/* eb0 - _D9_07 */ 0x246e, -/* eb1 - _9B_D9_07 */ 0x246f, -/* eb2 - */ 0, -/* eb3 - */ 0, -/* eb4 - */ 0, -/* eb5 - */ 0, -/* eb6 - */ 0, -/* eb7 - */ 0, -/* eb8 - */ 0, -/* eb9 - */ 0, -/* eba - */ 0, -/* ebb - */ 0, -/* ebc - _DB_E2 */ 0x2470, -/* ebd - _9B_DB_E2 */ 0x2471, -/* ebe - */ 0, -/* ebf - */ 0, -/* ec0 - */ 0, -/* ec1 - */ 0, -/* ec2 - */ 0, -/* ec3 - */ 0, -/* ec4 - */ 0, -/* ec5 - */ 0, -/* ec6 - */ 0, -/* ec7 - */ 0, -/* ec8 - _DB_E3 */ 0x2472, -/* ec9 - _9B_DB_E3 */ 0x2473, -/* eca - */ 0, -/* ecb - */ 0, -/* ecc - */ 0, -/* ecd - */ 0, -/* ece - */ 0, -/* ecf - */ 0, -/* ed0 - */ 0, -/* ed1 - */ 0, -/* ed2 - */ 0, -/* ed3 - */ 0, -/* ed4 - _DD_06 */ 0x2474, -/* ed5 - _9B_DD_06 */ 0x2475, -/* ed6 - */ 0, -/* ed7 - */ 0, -/* ed8 - */ 0, -/* ed9 - */ 0, -/* eda - */ 0, -/* edb - */ 0, -/* edc - */ 0, -/* edd - */ 0, -/* ede - */ 0, -/* edf - */ 0, -/* ee0 - _DD_07 */ 0x2476, -/* ee1 - _9B_DD_07 */ 0x2477, -/* ee2 - */ 0, -/* ee3 - */ 0, -/* ee4 - */ 0, -/* ee5 - */ 0, -/* ee6 - */ 0, -/* ee7 - */ 0, -/* ee8 - */ 0, -/* ee9 - */ 0, -/* eea - */ 0, -/* eeb - */ 0, -/* eec - _DF_E0 */ 0x2478, -/* eed - _9B_DF_E0 */ 0x2479, -/* eee - */ 0, -/* eef - */ 0, -/* ef0 - */ 0, -/* ef1 - */ 0, -/* ef2 - */ 0, -/* ef3 - */ 0, -/* ef4 - */ 0, -/* ef5 - */ 0, -/* ef6 - */ 0, -/* ef7 - */ 0, -/* ef8 - _0F_38_00 */ 0x247a, -/* ef9 - _66_0F_38_00 */ 0x247b, -/* efa - */ 0, -/* efb - */ 0, -/* efc - */ 0, -/* efd - _V_66_0F_38_00 */ 0x40da, -/* efe - */ 0, -/* eff - */ 0, -/* f00 - */ 0, -/* f01 - */ 0, -/* f02 - */ 0, -/* f03 - */ 0, -/* f04 - _0F_38_01 */ 0x247c, -/* f05 - _66_0F_38_01 */ 0x247d, -/* f06 - */ 0, -/* f07 - */ 0, -/* f08 - */ 0, -/* f09 - _V_66_0F_38_01 */ 0x40db, -/* f0a - */ 0, -/* f0b - */ 0, -/* f0c - */ 0, -/* f0d - */ 0, -/* f0e - */ 0, -/* f0f - */ 0, -/* f10 - _0F_38_02 */ 0x247e, -/* f11 - _66_0F_38_02 */ 0x247f, -/* f12 - */ 0, -/* f13 - */ 0, -/* f14 - */ 0, -/* f15 - _V_66_0F_38_02 */ 0x40dc, -/* f16 - */ 0, -/* f17 - */ 0, -/* f18 - */ 0, -/* f19 - */ 0, -/* f1a - */ 0, -/* f1b - */ 0, -/* f1c - _0F_38_03 */ 0x2480, -/* f1d - _66_0F_38_03 */ 0x2481, -/* f1e - */ 0, -/* f1f - */ 0, -/* f20 - */ 0, -/* f21 - _V_66_0F_38_03 */ 0x40dd, -/* f22 - */ 0, -/* f23 - */ 0, -/* f24 - */ 0, -/* f25 - */ 0, -/* f26 - */ 0, -/* f27 - */ 0, -/* f28 - _0F_38_04 */ 0x2482, -/* f29 - _66_0F_38_04 */ 0x2483, -/* f2a - */ 0, -/* f2b - */ 0, -/* f2c - */ 0, -/* f2d - _V_66_0F_38_04 */ 0x40de, -/* f2e - */ 0, -/* f2f - */ 0, -/* f30 - */ 0, -/* f31 - */ 0, -/* f32 - */ 0, -/* f33 - */ 0, -/* f34 - _0F_38_05 */ 0x2484, -/* f35 - _66_0F_38_05 */ 0x2485, -/* f36 - */ 0, -/* f37 - */ 0, -/* f38 - */ 0, -/* f39 - _V_66_0F_38_05 */ 0x40df, -/* f3a - */ 0, -/* f3b - */ 0, -/* f3c - */ 0, -/* f3d - */ 0, -/* f3e - */ 0, -/* f3f - */ 0, -/* f40 - _0F_38_06 */ 0x2486, -/* f41 - _66_0F_38_06 */ 0x2487, -/* f42 - */ 0, -/* f43 - */ 0, -/* f44 - */ 0, -/* f45 - _V_66_0F_38_06 */ 0x40e0, -/* f46 - */ 0, -/* f47 - */ 0, -/* f48 - */ 0, -/* f49 - */ 0, -/* f4a - */ 0, -/* f4b - */ 0, -/* f4c - _0F_38_07 */ 0x2488, -/* f4d - _66_0F_38_07 */ 0x2489, -/* f4e - */ 0, -/* f4f - */ 0, -/* f50 - */ 0, -/* f51 - _V_66_0F_38_07 */ 0x40e1, -/* f52 - */ 0, -/* f53 - */ 0, -/* f54 - */ 0, -/* f55 - */ 0, -/* f56 - */ 0, -/* f57 - */ 0, -/* f58 - _0F_38_08 */ 0x248a, -/* f59 - _66_0F_38_08 */ 0x248b, -/* f5a - */ 0, -/* f5b - */ 0, -/* f5c - */ 0, -/* f5d - _V_66_0F_38_08 */ 0x40e2, -/* f5e - */ 0, -/* f5f - */ 0, -/* f60 - */ 0, -/* f61 - */ 0, -/* f62 - */ 0, -/* f63 - */ 0, -/* f64 - _0F_38_09 */ 0x248c, -/* f65 - _66_0F_38_09 */ 0x248d, -/* f66 - */ 0, -/* f67 - */ 0, -/* f68 - */ 0, -/* f69 - _V_66_0F_38_09 */ 0x40e3, -/* f6a - */ 0, -/* f6b - */ 0, -/* f6c - */ 0, -/* f6d - */ 0, -/* f6e - */ 0, -/* f6f - */ 0, -/* f70 - _0F_38_0A */ 0x248e, -/* f71 - _66_0F_38_0A */ 0x248f, -/* f72 - */ 0, -/* f73 - */ 0, -/* f74 - */ 0, -/* f75 - _V_66_0F_38_0A */ 0x40e4, -/* f76 - */ 0, -/* f77 - */ 0, -/* f78 - */ 0, -/* f79 - */ 0, -/* f7a - */ 0, -/* f7b - */ 0, -/* f7c - _0F_38_0B */ 0x2490, -/* f7d - _66_0F_38_0B */ 0x2491, -/* f7e - */ 0, -/* f7f - */ 0, -/* f80 - */ 0, -/* f81 - _V_66_0F_38_0B */ 0x40e5, -/* f82 - */ 0, -/* f83 - */ 0, -/* f84 - */ 0, -/* f85 - */ 0, -/* f86 - */ 0, -/* f87 - */ 0, -/* f88 - */ 0, -/* f89 - */ 0, -/* f8a - */ 0, -/* f8b - */ 0, -/* f8c - */ 0, -/* f8d - _V_66_0F_38_0C */ 0x40e6, -/* f8e - */ 0, -/* f8f - */ 0, -/* f90 - */ 0, -/* f91 - */ 0, -/* f92 - */ 0, -/* f93 - */ 0, -/* f94 - */ 0, -/* f95 - */ 0, -/* f96 - */ 0, -/* f97 - */ 0, -/* f98 - */ 0, -/* f99 - _V_66_0F_38_0D */ 0x40e7, -/* f9a - */ 0, -/* f9b - */ 0, -/* f9c - */ 0, -/* f9d - */ 0, -/* f9e - */ 0, -/* f9f - */ 0, -/* fa0 - */ 0, -/* fa1 - */ 0, -/* fa2 - */ 0, -/* fa3 - */ 0, -/* fa4 - */ 0, -/* fa5 - _V_66_0F_38_0E */ 0x40e8, -/* fa6 - */ 0, -/* fa7 - */ 0, -/* fa8 - */ 0, -/* fa9 - */ 0, -/* faa - */ 0, -/* fab - */ 0, -/* fac - */ 0, -/* fad - */ 0, -/* fae - */ 0, -/* faf - */ 0, -/* fb0 - */ 0, -/* fb1 - _V_66_0F_38_0F */ 0x40e9, -/* fb2 - */ 0, -/* fb3 - */ 0, -/* fb4 - */ 0, -/* fb5 - */ 0, -/* fb6 - */ 0, -/* fb7 - */ 0, -/* fb8 - */ 0, -/* fb9 - _66_0F_38_10 */ 0x40ea, -/* fba - */ 0, -/* fbb - */ 0, -/* fbc - */ 0, -/* fbd - */ 0, -/* fbe - */ 0, -/* fbf - */ 0, -/* fc0 - */ 0, -/* fc1 - */ 0, -/* fc2 - */ 0, -/* fc3 - */ 0, -/* fc4 - */ 0, -/* fc5 - _66_0F_38_14 */ 0x40eb, -/* fc6 - */ 0, -/* fc7 - */ 0, -/* fc8 - */ 0, -/* fc9 - */ 0, -/* fca - */ 0, -/* fcb - */ 0, -/* fcc - */ 0, -/* fcd - */ 0, -/* fce - */ 0, -/* fcf - */ 0, -/* fd0 - */ 0, -/* fd1 - _66_0F_38_15 */ 0x40ec, -/* fd2 - */ 0, -/* fd3 - */ 0, -/* fd4 - */ 0, -/* fd5 - */ 0, -/* fd6 - */ 0, -/* fd7 - */ 0, -/* fd8 - */ 0, -/* fd9 - */ 0, -/* fda - */ 0, -/* fdb - */ 0, -/* fdc - */ 0, -/* fdd - _66_0F_38_17 */ 0x2492, -/* fde - */ 0, -/* fdf - */ 0, -/* fe0 - */ 0, -/* fe1 - _V_66_0F_38_17 */ 0x40ed, -/* fe2 - */ 0, -/* fe3 - */ 0, -/* fe4 - */ 0, -/* fe5 - */ 0, -/* fe6 - */ 0, -/* fe7 - */ 0, -/* fe8 - */ 0, -/* fe9 - */ 0, -/* fea - */ 0, -/* feb - */ 0, -/* fec - */ 0, -/* fed - _V_66_0F_38_18 */ 0x40ee, -/* fee - */ 0, -/* fef - */ 0, -/* ff0 - */ 0, -/* ff1 - */ 0, -/* ff2 - */ 0, -/* ff3 - */ 0, -/* ff4 - */ 0, -/* ff5 - */ 0, -/* ff6 - */ 0, -/* ff7 - */ 0, -/* ff8 - */ 0, -/* ff9 - _V_66_0F_38_19 */ 0x40ef, -/* ffa - */ 0, -/* ffb - */ 0, -/* ffc - */ 0, -/* ffd - */ 0, -/* ffe - */ 0, -/* fff - */ 0, -/* 1000 - */ 0, -/* 1001 - */ 0, -/* 1002 - */ 0, -/* 1003 - */ 0, -/* 1004 - */ 0, -/* 1005 - _V_66_0F_38_1A */ 0x40f0, -/* 1006 - */ 0, -/* 1007 - */ 0, -/* 1008 - */ 0, -/* 1009 - */ 0, -/* 100a - */ 0, -/* 100b - */ 0, -/* 100c - _0F_38_1C */ 0x2493, -/* 100d - _66_0F_38_1C */ 0x2494, -/* 100e - */ 0, -/* 100f - */ 0, -/* 1010 - */ 0, -/* 1011 - _V_66_0F_38_1C */ 0x40f1, -/* 1012 - */ 0, -/* 1013 - */ 0, -/* 1014 - */ 0, -/* 1015 - */ 0, -/* 1016 - */ 0, -/* 1017 - */ 0, -/* 1018 - _0F_38_1D */ 0x2495, -/* 1019 - _66_0F_38_1D */ 0x2496, -/* 101a - */ 0, -/* 101b - */ 0, -/* 101c - */ 0, -/* 101d - _V_66_0F_38_1D */ 0x40f2, -/* 101e - */ 0, -/* 101f - */ 0, -/* 1020 - */ 0, -/* 1021 - */ 0, -/* 1022 - */ 0, -/* 1023 - */ 0, -/* 1024 - _0F_38_1E */ 0x2497, -/* 1025 - _66_0F_38_1E */ 0x2498, -/* 1026 - */ 0, -/* 1027 - */ 0, -/* 1028 - */ 0, -/* 1029 - _V_66_0F_38_1E */ 0x40f3, -/* 102a - */ 0, -/* 102b - */ 0, -/* 102c - */ 0, -/* 102d - */ 0, -/* 102e - */ 0, -/* 102f - */ 0, -/* 1030 - */ 0, -/* 1031 - _66_0F_38_20 */ 0x2499, -/* 1032 - */ 0, -/* 1033 - */ 0, -/* 1034 - */ 0, -/* 1035 - _V_66_0F_38_20 */ 0x40f4, -/* 1036 - */ 0, -/* 1037 - */ 0, -/* 1038 - */ 0, -/* 1039 - */ 0, -/* 103a - */ 0, -/* 103b - */ 0, -/* 103c - */ 0, -/* 103d - _66_0F_38_21 */ 0x249a, -/* 103e - */ 0, -/* 103f - */ 0, -/* 1040 - */ 0, -/* 1041 - _V_66_0F_38_21 */ 0x40f5, -/* 1042 - */ 0, -/* 1043 - */ 0, -/* 1044 - */ 0, -/* 1045 - */ 0, -/* 1046 - */ 0, -/* 1047 - */ 0, -/* 1048 - */ 0, -/* 1049 - _66_0F_38_22 */ 0x249b, -/* 104a - */ 0, -/* 104b - */ 0, -/* 104c - */ 0, -/* 104d - _V_66_0F_38_22 */ 0x40f6, -/* 104e - */ 0, -/* 104f - */ 0, -/* 1050 - */ 0, -/* 1051 - */ 0, -/* 1052 - */ 0, -/* 1053 - */ 0, -/* 1054 - */ 0, -/* 1055 - _66_0F_38_23 */ 0x249c, -/* 1056 - */ 0, -/* 1057 - */ 0, -/* 1058 - */ 0, -/* 1059 - _V_66_0F_38_23 */ 0x40f7, -/* 105a - */ 0, -/* 105b - */ 0, -/* 105c - */ 0, -/* 105d - */ 0, -/* 105e - */ 0, -/* 105f - */ 0, -/* 1060 - */ 0, -/* 1061 - _66_0F_38_24 */ 0x249d, -/* 1062 - */ 0, -/* 1063 - */ 0, -/* 1064 - */ 0, -/* 1065 - _V_66_0F_38_24 */ 0x40f8, -/* 1066 - */ 0, -/* 1067 - */ 0, -/* 1068 - */ 0, -/* 1069 - */ 0, -/* 106a - */ 0, -/* 106b - */ 0, -/* 106c - */ 0, -/* 106d - _66_0F_38_25 */ 0x249e, -/* 106e - */ 0, -/* 106f - */ 0, -/* 1070 - */ 0, -/* 1071 - _V_66_0F_38_25 */ 0x40f9, -/* 1072 - */ 0, -/* 1073 - */ 0, -/* 1074 - */ 0, -/* 1075 - */ 0, -/* 1076 - */ 0, -/* 1077 - */ 0, -/* 1078 - */ 0, -/* 1079 - _66_0F_38_28 */ 0x249f, -/* 107a - */ 0, -/* 107b - */ 0, -/* 107c - */ 0, -/* 107d - _V_66_0F_38_28 */ 0x40fa, -/* 107e - */ 0, -/* 107f - */ 0, -/* 1080 - */ 0, -/* 1081 - */ 0, -/* 1082 - */ 0, -/* 1083 - */ 0, -/* 1084 - */ 0, -/* 1085 - _66_0F_38_29 */ 0x24a0, -/* 1086 - */ 0, -/* 1087 - */ 0, -/* 1088 - */ 0, -/* 1089 - _V_66_0F_38_29 */ 0x40fb, -/* 108a - */ 0, -/* 108b - */ 0, -/* 108c - */ 0, -/* 108d - */ 0, -/* 108e - */ 0, -/* 108f - */ 0, -/* 1090 - */ 0, -/* 1091 - _66_0F_38_2A */ 0x24a1, -/* 1092 - */ 0, -/* 1093 - */ 0, -/* 1094 - */ 0, -/* 1095 - _V_66_0F_38_2A */ 0x40fc, -/* 1096 - */ 0, -/* 1097 - */ 0, -/* 1098 - */ 0, -/* 1099 - */ 0, -/* 109a - */ 0, -/* 109b - */ 0, -/* 109c - */ 0, -/* 109d - _66_0F_38_2B */ 0x24a2, -/* 109e - */ 0, -/* 109f - */ 0, -/* 10a0 - */ 0, -/* 10a1 - _V_66_0F_38_2B */ 0x40fd, -/* 10a2 - */ 0, -/* 10a3 - */ 0, -/* 10a4 - */ 0, -/* 10a5 - */ 0, -/* 10a6 - */ 0, -/* 10a7 - */ 0, -/* 10a8 - */ 0, -/* 10a9 - */ 0, -/* 10aa - */ 0, -/* 10ab - */ 0, -/* 10ac - */ 0, -/* 10ad - _V_66_0F_38_2C */ 0x40fe, -/* 10ae - */ 0, -/* 10af - */ 0, -/* 10b0 - */ 0, -/* 10b1 - */ 0, -/* 10b2 - */ 0, -/* 10b3 - */ 0, -/* 10b4 - */ 0, -/* 10b5 - */ 0, -/* 10b6 - */ 0, -/* 10b7 - */ 0, -/* 10b8 - */ 0, -/* 10b9 - _V_66_0F_38_2D */ 0x40ff, -/* 10ba - */ 0, -/* 10bb - */ 0, -/* 10bc - */ 0, -/* 10bd - */ 0, -/* 10be - */ 0, -/* 10bf - */ 0, -/* 10c0 - */ 0, -/* 10c1 - */ 0, -/* 10c2 - */ 0, -/* 10c3 - */ 0, -/* 10c4 - */ 0, -/* 10c5 - _V_66_0F_38_2E */ 0x4100, -/* 10c6 - */ 0, -/* 10c7 - */ 0, -/* 10c8 - */ 0, -/* 10c9 - */ 0, -/* 10ca - */ 0, -/* 10cb - */ 0, -/* 10cc - */ 0, -/* 10cd - */ 0, -/* 10ce - */ 0, -/* 10cf - */ 0, -/* 10d0 - */ 0, -/* 10d1 - _V_66_0F_38_2F */ 0x4101, -/* 10d2 - */ 0, -/* 10d3 - */ 0, -/* 10d4 - */ 0, -/* 10d5 - */ 0, -/* 10d6 - */ 0, -/* 10d7 - */ 0, -/* 10d8 - */ 0, -/* 10d9 - _66_0F_38_30 */ 0x24a3, -/* 10da - */ 0, -/* 10db - */ 0, -/* 10dc - */ 0, -/* 10dd - _V_66_0F_38_30 */ 0x4102, -/* 10de - */ 0, -/* 10df - */ 0, -/* 10e0 - */ 0, -/* 10e1 - */ 0, -/* 10e2 - */ 0, -/* 10e3 - */ 0, -/* 10e4 - */ 0, -/* 10e5 - _66_0F_38_31 */ 0x24a4, -/* 10e6 - */ 0, -/* 10e7 - */ 0, -/* 10e8 - */ 0, -/* 10e9 - _V_66_0F_38_31 */ 0x4103, -/* 10ea - */ 0, -/* 10eb - */ 0, -/* 10ec - */ 0, -/* 10ed - */ 0, -/* 10ee - */ 0, -/* 10ef - */ 0, -/* 10f0 - */ 0, -/* 10f1 - _66_0F_38_32 */ 0x24a5, -/* 10f2 - */ 0, -/* 10f3 - */ 0, -/* 10f4 - */ 0, -/* 10f5 - _V_66_0F_38_32 */ 0x4104, -/* 10f6 - */ 0, -/* 10f7 - */ 0, -/* 10f8 - */ 0, -/* 10f9 - */ 0, -/* 10fa - */ 0, -/* 10fb - */ 0, -/* 10fc - */ 0, -/* 10fd - _66_0F_38_33 */ 0x24a6, -/* 10fe - */ 0, -/* 10ff - */ 0, -/* 1100 - */ 0, -/* 1101 - _V_66_0F_38_33 */ 0x4105, -/* 1102 - */ 0, -/* 1103 - */ 0, -/* 1104 - */ 0, -/* 1105 - */ 0, -/* 1106 - */ 0, -/* 1107 - */ 0, -/* 1108 - */ 0, -/* 1109 - _66_0F_38_34 */ 0x24a7, -/* 110a - */ 0, -/* 110b - */ 0, -/* 110c - */ 0, -/* 110d - _V_66_0F_38_34 */ 0x4106, -/* 110e - */ 0, -/* 110f - */ 0, -/* 1110 - */ 0, -/* 1111 - */ 0, -/* 1112 - */ 0, -/* 1113 - */ 0, -/* 1114 - */ 0, -/* 1115 - _66_0F_38_35 */ 0x24a8, -/* 1116 - */ 0, -/* 1117 - */ 0, -/* 1118 - */ 0, -/* 1119 - _V_66_0F_38_35 */ 0x4107, -/* 111a - */ 0, -/* 111b - */ 0, -/* 111c - */ 0, -/* 111d - */ 0, -/* 111e - */ 0, -/* 111f - */ 0, -/* 1120 - */ 0, -/* 1121 - _66_0F_38_37 */ 0x24a9, -/* 1122 - */ 0, -/* 1123 - */ 0, -/* 1124 - */ 0, -/* 1125 - _V_66_0F_38_37 */ 0x4108, -/* 1126 - */ 0, -/* 1127 - */ 0, -/* 1128 - */ 0, -/* 1129 - */ 0, -/* 112a - */ 0, -/* 112b - */ 0, -/* 112c - */ 0, -/* 112d - _66_0F_38_38 */ 0x24aa, -/* 112e - */ 0, -/* 112f - */ 0, -/* 1130 - */ 0, -/* 1131 - _V_66_0F_38_38 */ 0x4109, -/* 1132 - */ 0, -/* 1133 - */ 0, -/* 1134 - */ 0, -/* 1135 - */ 0, -/* 1136 - */ 0, -/* 1137 - */ 0, -/* 1138 - */ 0, -/* 1139 - _66_0F_38_39 */ 0x24ab, -/* 113a - */ 0, -/* 113b - */ 0, -/* 113c - */ 0, -/* 113d - _V_66_0F_38_39 */ 0x410a, -/* 113e - */ 0, -/* 113f - */ 0, -/* 1140 - */ 0, -/* 1141 - */ 0, -/* 1142 - */ 0, -/* 1143 - */ 0, -/* 1144 - */ 0, -/* 1145 - _66_0F_38_3A */ 0x24ac, -/* 1146 - */ 0, -/* 1147 - */ 0, -/* 1148 - */ 0, -/* 1149 - _V_66_0F_38_3A */ 0x410b, -/* 114a - */ 0, -/* 114b - */ 0, -/* 114c - */ 0, -/* 114d - */ 0, -/* 114e - */ 0, -/* 114f - */ 0, -/* 1150 - */ 0, -/* 1151 - _66_0F_38_3B */ 0x24ad, -/* 1152 - */ 0, -/* 1153 - */ 0, -/* 1154 - */ 0, -/* 1155 - _V_66_0F_38_3B */ 0x410c, -/* 1156 - */ 0, -/* 1157 - */ 0, -/* 1158 - */ 0, -/* 1159 - */ 0, -/* 115a - */ 0, -/* 115b - */ 0, -/* 115c - */ 0, -/* 115d - _66_0F_38_3C */ 0x24ae, -/* 115e - */ 0, -/* 115f - */ 0, -/* 1160 - */ 0, -/* 1161 - _V_66_0F_38_3C */ 0x410d, -/* 1162 - */ 0, -/* 1163 - */ 0, -/* 1164 - */ 0, -/* 1165 - */ 0, -/* 1166 - */ 0, -/* 1167 - */ 0, -/* 1168 - */ 0, -/* 1169 - _66_0F_38_3D */ 0x24af, -/* 116a - */ 0, -/* 116b - */ 0, -/* 116c - */ 0, -/* 116d - _V_66_0F_38_3D */ 0x410e, -/* 116e - */ 0, -/* 116f - */ 0, -/* 1170 - */ 0, -/* 1171 - */ 0, -/* 1172 - */ 0, -/* 1173 - */ 0, -/* 1174 - */ 0, -/* 1175 - _66_0F_38_3E */ 0x24b0, -/* 1176 - */ 0, -/* 1177 - */ 0, -/* 1178 - */ 0, -/* 1179 - _V_66_0F_38_3E */ 0x410f, -/* 117a - */ 0, -/* 117b - */ 0, -/* 117c - */ 0, -/* 117d - */ 0, -/* 117e - */ 0, -/* 117f - */ 0, -/* 1180 - */ 0, -/* 1181 - _66_0F_38_3F */ 0x24b1, -/* 1182 - */ 0, -/* 1183 - */ 0, -/* 1184 - */ 0, -/* 1185 - _V_66_0F_38_3F */ 0x4110, -/* 1186 - */ 0, -/* 1187 - */ 0, -/* 1188 - */ 0, -/* 1189 - */ 0, -/* 118a - */ 0, -/* 118b - */ 0, -/* 118c - */ 0, -/* 118d - _66_0F_38_40 */ 0x24b2, -/* 118e - */ 0, -/* 118f - */ 0, -/* 1190 - */ 0, -/* 1191 - _V_66_0F_38_40 */ 0x4111, -/* 1192 - */ 0, -/* 1193 - */ 0, -/* 1194 - */ 0, -/* 1195 - */ 0, -/* 1196 - */ 0, -/* 1197 - */ 0, -/* 1198 - */ 0, -/* 1199 - _66_0F_38_41 */ 0x24b3, -/* 119a - */ 0, -/* 119b - */ 0, -/* 119c - */ 0, -/* 119d - _V_66_0F_38_41 */ 0x4112, -/* 119e - */ 0, -/* 119f - */ 0, -/* 11a0 - */ 0, -/* 11a1 - */ 0, -/* 11a2 - */ 0, -/* 11a3 - */ 0, -/* 11a4 - */ 0, -/* 11a5 - _66_0F_38_80 */ 0x24b4, -/* 11a6 - */ 0, -/* 11a7 - */ 0, -/* 11a8 - */ 0, -/* 11a9 - */ 0, -/* 11aa - */ 0, -/* 11ab - */ 0, -/* 11ac - */ 0, -/* 11ad - */ 0, -/* 11ae - */ 0, -/* 11af - */ 0, -/* 11b0 - */ 0, -/* 11b1 - _66_0F_38_81 */ 0x24b5, -/* 11b2 - */ 0, -/* 11b3 - */ 0, -/* 11b4 - */ 0, -/* 11b5 - */ 0, -/* 11b6 - */ 0, -/* 11b7 - */ 0, -/* 11b8 - */ 0, -/* 11b9 - */ 0, -/* 11ba - */ 0, -/* 11bb - */ 0, -/* 11bc - */ 0, -/* 11bd - _66_0F_38_82 */ 0x24b6, -/* 11be - */ 0, -/* 11bf - */ 0, -/* 11c0 - */ 0, -/* 11c1 - */ 0, -/* 11c2 - */ 0, -/* 11c3 - */ 0, -/* 11c4 - */ 0, -/* 11c5 - */ 0, -/* 11c6 - */ 0, -/* 11c7 - */ 0, -/* 11c8 - */ 0, -/* 11c9 - */ 0, -/* 11ca - */ 0, -/* 11cb - */ 0, -/* 11cc - */ 0, -/* 11cd - _V_66_0F_38_96 */ 0x4113, -/* 11ce - */ 0, -/* 11cf - */ 0, -/* 11d0 - */ 0, -/* 11d1 - */ 0, -/* 11d2 - */ 0, -/* 11d3 - */ 0, -/* 11d4 - */ 0, -/* 11d5 - */ 0, -/* 11d6 - */ 0, -/* 11d7 - */ 0, -/* 11d8 - */ 0, -/* 11d9 - _V_66_0F_38_97 */ 0x4114, -/* 11da - */ 0, -/* 11db - */ 0, -/* 11dc - */ 0, -/* 11dd - */ 0, -/* 11de - */ 0, -/* 11df - */ 0, -/* 11e0 - */ 0, -/* 11e1 - */ 0, -/* 11e2 - */ 0, -/* 11e3 - */ 0, -/* 11e4 - */ 0, -/* 11e5 - _V_66_0F_38_98 */ 0x4115, -/* 11e6 - */ 0, -/* 11e7 - */ 0, -/* 11e8 - */ 0, -/* 11e9 - */ 0, -/* 11ea - */ 0, -/* 11eb - */ 0, -/* 11ec - */ 0, -/* 11ed - */ 0, -/* 11ee - */ 0, -/* 11ef - */ 0, -/* 11f0 - */ 0, -/* 11f1 - _V_66_0F_38_99 */ 0x4116, -/* 11f2 - */ 0, -/* 11f3 - */ 0, -/* 11f4 - */ 0, -/* 11f5 - */ 0, -/* 11f6 - */ 0, -/* 11f7 - */ 0, -/* 11f8 - */ 0, -/* 11f9 - */ 0, -/* 11fa - */ 0, -/* 11fb - */ 0, -/* 11fc - */ 0, -/* 11fd - _V_66_0F_38_9A */ 0x4117, -/* 11fe - */ 0, -/* 11ff - */ 0, -/* 1200 - */ 0, -/* 1201 - */ 0, -/* 1202 - */ 0, -/* 1203 - */ 0, -/* 1204 - */ 0, -/* 1205 - */ 0, -/* 1206 - */ 0, -/* 1207 - */ 0, -/* 1208 - */ 0, -/* 1209 - _V_66_0F_38_9B */ 0x4118, -/* 120a - */ 0, -/* 120b - */ 0, -/* 120c - */ 0, -/* 120d - */ 0, -/* 120e - */ 0, -/* 120f - */ 0, -/* 1210 - */ 0, -/* 1211 - */ 0, -/* 1212 - */ 0, -/* 1213 - */ 0, -/* 1214 - */ 0, -/* 1215 - _V_66_0F_38_9C */ 0x4119, -/* 1216 - */ 0, -/* 1217 - */ 0, -/* 1218 - */ 0, -/* 1219 - */ 0, -/* 121a - */ 0, -/* 121b - */ 0, -/* 121c - */ 0, -/* 121d - */ 0, -/* 121e - */ 0, -/* 121f - */ 0, -/* 1220 - */ 0, -/* 1221 - _V_66_0F_38_9D */ 0x411a, -/* 1222 - */ 0, -/* 1223 - */ 0, -/* 1224 - */ 0, -/* 1225 - */ 0, -/* 1226 - */ 0, -/* 1227 - */ 0, -/* 1228 - */ 0, -/* 1229 - */ 0, -/* 122a - */ 0, -/* 122b - */ 0, -/* 122c - */ 0, -/* 122d - _V_66_0F_38_9E */ 0x411b, -/* 122e - */ 0, -/* 122f - */ 0, -/* 1230 - */ 0, -/* 1231 - */ 0, -/* 1232 - */ 0, -/* 1233 - */ 0, -/* 1234 - */ 0, -/* 1235 - */ 0, -/* 1236 - */ 0, -/* 1237 - */ 0, -/* 1238 - */ 0, -/* 1239 - _V_66_0F_38_9F */ 0x411c, -/* 123a - */ 0, -/* 123b - */ 0, -/* 123c - */ 0, -/* 123d - */ 0, -/* 123e - */ 0, -/* 123f - */ 0, -/* 1240 - */ 0, -/* 1241 - */ 0, -/* 1242 - */ 0, -/* 1243 - */ 0, -/* 1244 - */ 0, -/* 1245 - _V_66_0F_38_A6 */ 0x411d, -/* 1246 - */ 0, -/* 1247 - */ 0, -/* 1248 - */ 0, -/* 1249 - */ 0, -/* 124a - */ 0, -/* 124b - */ 0, -/* 124c - */ 0, -/* 124d - */ 0, -/* 124e - */ 0, -/* 124f - */ 0, -/* 1250 - */ 0, -/* 1251 - _V_66_0F_38_A7 */ 0x411e, -/* 1252 - */ 0, -/* 1253 - */ 0, -/* 1254 - */ 0, -/* 1255 - */ 0, -/* 1256 - */ 0, -/* 1257 - */ 0, -/* 1258 - */ 0, -/* 1259 - */ 0, -/* 125a - */ 0, -/* 125b - */ 0, -/* 125c - */ 0, -/* 125d - _V_66_0F_38_A8 */ 0x411f, -/* 125e - */ 0, -/* 125f - */ 0, -/* 1260 - */ 0, -/* 1261 - */ 0, -/* 1262 - */ 0, -/* 1263 - */ 0, -/* 1264 - */ 0, -/* 1265 - */ 0, -/* 1266 - */ 0, -/* 1267 - */ 0, -/* 1268 - */ 0, -/* 1269 - _V_66_0F_38_A9 */ 0x4120, -/* 126a - */ 0, -/* 126b - */ 0, -/* 126c - */ 0, -/* 126d - */ 0, -/* 126e - */ 0, -/* 126f - */ 0, -/* 1270 - */ 0, -/* 1271 - */ 0, -/* 1272 - */ 0, -/* 1273 - */ 0, -/* 1274 - */ 0, -/* 1275 - _V_66_0F_38_AA */ 0x4121, -/* 1276 - */ 0, -/* 1277 - */ 0, -/* 1278 - */ 0, -/* 1279 - */ 0, -/* 127a - */ 0, -/* 127b - */ 0, -/* 127c - */ 0, -/* 127d - */ 0, -/* 127e - */ 0, -/* 127f - */ 0, -/* 1280 - */ 0, -/* 1281 - _V_66_0F_38_AB */ 0x4122, -/* 1282 - */ 0, -/* 1283 - */ 0, -/* 1284 - */ 0, -/* 1285 - */ 0, -/* 1286 - */ 0, -/* 1287 - */ 0, -/* 1288 - */ 0, -/* 1289 - */ 0, -/* 128a - */ 0, -/* 128b - */ 0, -/* 128c - */ 0, -/* 128d - _V_66_0F_38_AC */ 0x4123, -/* 128e - */ 0, -/* 128f - */ 0, -/* 1290 - */ 0, -/* 1291 - */ 0, -/* 1292 - */ 0, -/* 1293 - */ 0, -/* 1294 - */ 0, -/* 1295 - */ 0, -/* 1296 - */ 0, -/* 1297 - */ 0, -/* 1298 - */ 0, -/* 1299 - _V_66_0F_38_AD */ 0x4124, -/* 129a - */ 0, -/* 129b - */ 0, -/* 129c - */ 0, -/* 129d - */ 0, -/* 129e - */ 0, -/* 129f - */ 0, -/* 12a0 - */ 0, -/* 12a1 - */ 0, -/* 12a2 - */ 0, -/* 12a3 - */ 0, -/* 12a4 - */ 0, -/* 12a5 - _V_66_0F_38_AE */ 0x4125, -/* 12a6 - */ 0, -/* 12a7 - */ 0, -/* 12a8 - */ 0, -/* 12a9 - */ 0, -/* 12aa - */ 0, -/* 12ab - */ 0, -/* 12ac - */ 0, -/* 12ad - */ 0, -/* 12ae - */ 0, -/* 12af - */ 0, -/* 12b0 - */ 0, -/* 12b1 - _V_66_0F_38_AF */ 0x4126, -/* 12b2 - */ 0, -/* 12b3 - */ 0, -/* 12b4 - */ 0, -/* 12b5 - */ 0, -/* 12b6 - */ 0, -/* 12b7 - */ 0, -/* 12b8 - */ 0, -/* 12b9 - */ 0, -/* 12ba - */ 0, -/* 12bb - */ 0, -/* 12bc - */ 0, -/* 12bd - _V_66_0F_38_B6 */ 0x4127, -/* 12be - */ 0, -/* 12bf - */ 0, -/* 12c0 - */ 0, -/* 12c1 - */ 0, -/* 12c2 - */ 0, -/* 12c3 - */ 0, -/* 12c4 - */ 0, -/* 12c5 - */ 0, -/* 12c6 - */ 0, -/* 12c7 - */ 0, -/* 12c8 - */ 0, -/* 12c9 - _V_66_0F_38_B7 */ 0x4128, -/* 12ca - */ 0, -/* 12cb - */ 0, -/* 12cc - */ 0, -/* 12cd - */ 0, -/* 12ce - */ 0, -/* 12cf - */ 0, -/* 12d0 - */ 0, -/* 12d1 - */ 0, -/* 12d2 - */ 0, -/* 12d3 - */ 0, -/* 12d4 - */ 0, -/* 12d5 - _V_66_0F_38_B8 */ 0x4129, -/* 12d6 - */ 0, -/* 12d7 - */ 0, -/* 12d8 - */ 0, -/* 12d9 - */ 0, -/* 12da - */ 0, -/* 12db - */ 0, -/* 12dc - */ 0, -/* 12dd - */ 0, -/* 12de - */ 0, -/* 12df - */ 0, -/* 12e0 - */ 0, -/* 12e1 - _V_66_0F_38_B9 */ 0x412a, -/* 12e2 - */ 0, -/* 12e3 - */ 0, -/* 12e4 - */ 0, -/* 12e5 - */ 0, -/* 12e6 - */ 0, -/* 12e7 - */ 0, -/* 12e8 - */ 0, -/* 12e9 - */ 0, -/* 12ea - */ 0, -/* 12eb - */ 0, -/* 12ec - */ 0, -/* 12ed - _V_66_0F_38_BA */ 0x412b, -/* 12ee - */ 0, -/* 12ef - */ 0, -/* 12f0 - */ 0, -/* 12f1 - */ 0, -/* 12f2 - */ 0, -/* 12f3 - */ 0, -/* 12f4 - */ 0, -/* 12f5 - */ 0, -/* 12f6 - */ 0, -/* 12f7 - */ 0, -/* 12f8 - */ 0, -/* 12f9 - _V_66_0F_38_BB */ 0x412c, -/* 12fa - */ 0, -/* 12fb - */ 0, -/* 12fc - */ 0, -/* 12fd - */ 0, -/* 12fe - */ 0, -/* 12ff - */ 0, -/* 1300 - */ 0, -/* 1301 - */ 0, -/* 1302 - */ 0, -/* 1303 - */ 0, -/* 1304 - */ 0, -/* 1305 - _V_66_0F_38_BC */ 0x412d, -/* 1306 - */ 0, -/* 1307 - */ 0, -/* 1308 - */ 0, -/* 1309 - */ 0, -/* 130a - */ 0, -/* 130b - */ 0, -/* 130c - */ 0, -/* 130d - */ 0, -/* 130e - */ 0, -/* 130f - */ 0, -/* 1310 - */ 0, -/* 1311 - _V_66_0F_38_BD */ 0x412e, -/* 1312 - */ 0, -/* 1313 - */ 0, -/* 1314 - */ 0, -/* 1315 - */ 0, -/* 1316 - */ 0, -/* 1317 - */ 0, -/* 1318 - */ 0, -/* 1319 - */ 0, -/* 131a - */ 0, -/* 131b - */ 0, -/* 131c - */ 0, -/* 131d - _V_66_0F_38_BE */ 0x412f, -/* 131e - */ 0, -/* 131f - */ 0, -/* 1320 - */ 0, -/* 1321 - */ 0, -/* 1322 - */ 0, -/* 1323 - */ 0, -/* 1324 - */ 0, -/* 1325 - */ 0, -/* 1326 - */ 0, -/* 1327 - */ 0, -/* 1328 - */ 0, -/* 1329 - _V_66_0F_38_BF */ 0x4130, -/* 132a - */ 0, -/* 132b - */ 0, -/* 132c - */ 0, -/* 132d - */ 0, -/* 132e - */ 0, -/* 132f - */ 0, -/* 1330 - */ 0, -/* 1331 - _66_0F_38_DB */ 0x24b7, -/* 1332 - */ 0, -/* 1333 - */ 0, -/* 1334 - */ 0, -/* 1335 - _V_66_0F_38_DB */ 0x4131, -/* 1336 - */ 0, -/* 1337 - */ 0, -/* 1338 - */ 0, -/* 1339 - */ 0, -/* 133a - */ 0, -/* 133b - */ 0, -/* 133c - */ 0, -/* 133d - _66_0F_38_DC */ 0x24b8, -/* 133e - */ 0, -/* 133f - */ 0, -/* 1340 - */ 0, -/* 1341 - _V_66_0F_38_DC */ 0x4132, -/* 1342 - */ 0, -/* 1343 - */ 0, -/* 1344 - */ 0, -/* 1345 - */ 0, -/* 1346 - */ 0, -/* 1347 - */ 0, -/* 1348 - */ 0, -/* 1349 - _66_0F_38_DD */ 0x24b9, -/* 134a - */ 0, -/* 134b - */ 0, -/* 134c - */ 0, -/* 134d - _V_66_0F_38_DD */ 0x4133, -/* 134e - */ 0, -/* 134f - */ 0, -/* 1350 - */ 0, -/* 1351 - */ 0, -/* 1352 - */ 0, -/* 1353 - */ 0, -/* 1354 - */ 0, -/* 1355 - _66_0F_38_DE */ 0x24ba, -/* 1356 - */ 0, -/* 1357 - */ 0, -/* 1358 - */ 0, -/* 1359 - _V_66_0F_38_DE */ 0x4134, -/* 135a - */ 0, -/* 135b - */ 0, -/* 135c - */ 0, -/* 135d - */ 0, -/* 135e - */ 0, -/* 135f - */ 0, -/* 1360 - */ 0, -/* 1361 - _66_0F_38_DF */ 0x24bb, -/* 1362 - */ 0, -/* 1363 - */ 0, -/* 1364 - */ 0, -/* 1365 - _V_66_0F_38_DF */ 0x4135, -/* 1366 - */ 0, -/* 1367 - */ 0, -/* 1368 - */ 0, -/* 1369 - */ 0, -/* 136a - */ 0, -/* 136b - */ 0, -/* 136c - _0F_38_F0 */ 0x24bc, -/* 136d - */ 0, -/* 136e - */ 0, -/* 136f - _F2_0F_38_F0 */ 0x24bd, -/* 1370 - */ 0, -/* 1371 - */ 0, -/* 1372 - */ 0, -/* 1373 - */ 0, -/* 1374 - */ 0, -/* 1375 - */ 0, -/* 1376 - */ 0, -/* 1377 - */ 0, -/* 1378 - _0F_38_F1 */ 0x24be, -/* 1379 - */ 0, -/* 137a - */ 0, -/* 137b - _F2_0F_38_F1 */ 0x24bf, -/* 137c - */ 0, -/* 137d - */ 0, -/* 137e - */ 0, -/* 137f - */ 0, -/* 1380 - */ 0, -/* 1381 - */ 0, -/* 1382 - */ 0, -/* 1383 - */ 0, -/* 1384 - */ 0, -/* 1385 - */ 0, -/* 1386 - */ 0, -/* 1387 - */ 0, -/* 1388 - */ 0, -/* 1389 - _V_66_0F_3A_04 */ 0x4136, -/* 138a - */ 0, -/* 138b - */ 0, -/* 138c - */ 0, -/* 138d - */ 0, -/* 138e - */ 0, -/* 138f - */ 0, -/* 1390 - */ 0, -/* 1391 - */ 0, -/* 1392 - */ 0, -/* 1393 - */ 0, -/* 1394 - */ 0, -/* 1395 - _V_66_0F_3A_05 */ 0x4137, -/* 1396 - */ 0, -/* 1397 - */ 0, -/* 1398 - */ 0, -/* 1399 - */ 0, -/* 139a - */ 0, -/* 139b - */ 0, -/* 139c - */ 0, -/* 139d - */ 0, -/* 139e - */ 0, -/* 139f - */ 0, -/* 13a0 - */ 0, -/* 13a1 - _V_66_0F_3A_06 */ 0x4138, -/* 13a2 - */ 0, -/* 13a3 - */ 0, -/* 13a4 - */ 0, -/* 13a5 - */ 0, -/* 13a6 - */ 0, -/* 13a7 - */ 0, -/* 13a8 - */ 0, -/* 13a9 - _66_0F_3A_08 */ 0x4139, -/* 13aa - */ 0, -/* 13ab - */ 0, -/* 13ac - */ 0, -/* 13ad - _V_66_0F_3A_08 */ 0x413a, -/* 13ae - */ 0, -/* 13af - */ 0, -/* 13b0 - */ 0, -/* 13b1 - */ 0, -/* 13b2 - */ 0, -/* 13b3 - */ 0, -/* 13b4 - */ 0, -/* 13b5 - _66_0F_3A_09 */ 0x413b, -/* 13b6 - */ 0, -/* 13b7 - */ 0, -/* 13b8 - */ 0, -/* 13b9 - _V_66_0F_3A_09 */ 0x413c, -/* 13ba - */ 0, -/* 13bb - */ 0, -/* 13bc - */ 0, -/* 13bd - */ 0, -/* 13be - */ 0, -/* 13bf - */ 0, -/* 13c0 - */ 0, -/* 13c1 - _66_0F_3A_0A */ 0x413d, -/* 13c2 - */ 0, -/* 13c3 - */ 0, -/* 13c4 - */ 0, -/* 13c5 - _V_66_0F_3A_0A */ 0x413e, -/* 13c6 - */ 0, -/* 13c7 - */ 0, -/* 13c8 - */ 0, -/* 13c9 - */ 0, -/* 13ca - */ 0, -/* 13cb - */ 0, -/* 13cc - */ 0, -/* 13cd - _66_0F_3A_0B */ 0x413f, -/* 13ce - */ 0, -/* 13cf - */ 0, -/* 13d0 - */ 0, -/* 13d1 - _V_66_0F_3A_0B */ 0x4140, -/* 13d2 - */ 0, -/* 13d3 - */ 0, -/* 13d4 - */ 0, -/* 13d5 - */ 0, -/* 13d6 - */ 0, -/* 13d7 - */ 0, -/* 13d8 - */ 0, -/* 13d9 - _66_0F_3A_0C */ 0x4141, -/* 13da - */ 0, -/* 13db - */ 0, -/* 13dc - */ 0, -/* 13dd - _V_66_0F_3A_0C */ 0x4142, -/* 13de - */ 0, -/* 13df - */ 0, -/* 13e0 - */ 0, -/* 13e1 - */ 0, -/* 13e2 - */ 0, -/* 13e3 - */ 0, -/* 13e4 - */ 0, -/* 13e5 - _66_0F_3A_0D */ 0x4143, -/* 13e6 - */ 0, -/* 13e7 - */ 0, -/* 13e8 - */ 0, -/* 13e9 - _V_66_0F_3A_0D */ 0x4144, -/* 13ea - */ 0, -/* 13eb - */ 0, -/* 13ec - */ 0, -/* 13ed - */ 0, -/* 13ee - */ 0, -/* 13ef - */ 0, -/* 13f0 - */ 0, -/* 13f1 - _66_0F_3A_0E */ 0x4145, -/* 13f2 - */ 0, -/* 13f3 - */ 0, -/* 13f4 - */ 0, -/* 13f5 - _V_66_0F_3A_0E */ 0x4146, -/* 13f6 - */ 0, -/* 13f7 - */ 0, -/* 13f8 - */ 0, -/* 13f9 - */ 0, -/* 13fa - */ 0, -/* 13fb - */ 0, -/* 13fc - _0F_3A_0F */ 0x4147, -/* 13fd - _66_0F_3A_0F */ 0x4148, -/* 13fe - */ 0, -/* 13ff - */ 0, -/* 1400 - */ 0, -/* 1401 - _V_66_0F_3A_0F */ 0x4149, -/* 1402 - */ 0, -/* 1403 - */ 0, -/* 1404 - */ 0, -/* 1405 - */ 0, -/* 1406 - */ 0, -/* 1407 - */ 0, -/* 1408 - */ 0, -/* 1409 - _66_0F_3A_14 */ 0x414a, -/* 140a - */ 0, -/* 140b - */ 0, -/* 140c - */ 0, -/* 140d - _V_66_0F_3A_14 */ 0x414b, -/* 140e - */ 0, -/* 140f - */ 0, -/* 1410 - */ 0, -/* 1411 - */ 0, -/* 1412 - */ 0, -/* 1413 - */ 0, -/* 1414 - */ 0, -/* 1415 - _66_0F_3A_15 */ 0x414c, -/* 1416 - */ 0, -/* 1417 - */ 0, -/* 1418 - */ 0, -/* 1419 - _V_66_0F_3A_15 */ 0x414d, -/* 141a - */ 0, -/* 141b - */ 0, -/* 141c - */ 0, -/* 141d - */ 0, -/* 141e - */ 0, -/* 141f - */ 0, -/* 1420 - */ 0, -/* 1421 - _66_0F_3A_16 */ 0x414e, -/* 1422 - */ 0, -/* 1423 - */ 0, -/* 1424 - */ 0, -/* 1425 - _V_66_0F_3A_16 */ 0x414f, -/* 1426 - */ 0, -/* 1427 - */ 0, -/* 1428 - */ 0, -/* 1429 - */ 0, -/* 142a - */ 0, -/* 142b - */ 0, -/* 142c - */ 0, -/* 142d - _66_0F_3A_17 */ 0x4150, -/* 142e - */ 0, -/* 142f - */ 0, -/* 1430 - */ 0, -/* 1431 - _V_66_0F_3A_17 */ 0x4151, -/* 1432 - */ 0, -/* 1433 - */ 0, -/* 1434 - */ 0, -/* 1435 - */ 0, -/* 1436 - */ 0, -/* 1437 - */ 0, -/* 1438 - */ 0, -/* 1439 - */ 0, -/* 143a - */ 0, -/* 143b - */ 0, -/* 143c - */ 0, -/* 143d - _V_66_0F_3A_18 */ 0x4152, -/* 143e - */ 0, -/* 143f - */ 0, -/* 1440 - */ 0, -/* 1441 - */ 0, -/* 1442 - */ 0, -/* 1443 - */ 0, -/* 1444 - */ 0, -/* 1445 - */ 0, -/* 1446 - */ 0, -/* 1447 - */ 0, -/* 1448 - */ 0, -/* 1449 - _V_66_0F_3A_19 */ 0x4153, -/* 144a - */ 0, -/* 144b - */ 0, -/* 144c - */ 0, -/* 144d - */ 0, -/* 144e - */ 0, -/* 144f - */ 0, -/* 1450 - */ 0, -/* 1451 - _66_0F_3A_20 */ 0x4154, -/* 1452 - */ 0, -/* 1453 - */ 0, -/* 1454 - */ 0, -/* 1455 - _V_66_0F_3A_20 */ 0x4155, -/* 1456 - */ 0, -/* 1457 - */ 0, -/* 1458 - */ 0, -/* 1459 - */ 0, -/* 145a - */ 0, -/* 145b - */ 0, -/* 145c - */ 0, -/* 145d - _66_0F_3A_21 */ 0x4156, -/* 145e - */ 0, -/* 145f - */ 0, -/* 1460 - */ 0, -/* 1461 - _V_66_0F_3A_21 */ 0x4157, -/* 1462 - */ 0, -/* 1463 - */ 0, -/* 1464 - */ 0, -/* 1465 - */ 0, -/* 1466 - */ 0, -/* 1467 - */ 0, -/* 1468 - */ 0, -/* 1469 - _66_0F_3A_22 */ 0x4158, -/* 146a - */ 0, -/* 146b - */ 0, -/* 146c - */ 0, -/* 146d - _V_66_0F_3A_22 */ 0x4159, -/* 146e - */ 0, -/* 146f - */ 0, -/* 1470 - */ 0, -/* 1471 - */ 0, -/* 1472 - */ 0, -/* 1473 - */ 0, -/* 1474 - */ 0, -/* 1475 - _66_0F_3A_40 */ 0x415a, -/* 1476 - */ 0, -/* 1477 - */ 0, -/* 1478 - */ 0, -/* 1479 - _V_66_0F_3A_40 */ 0x415b, -/* 147a - */ 0, -/* 147b - */ 0, -/* 147c - */ 0, -/* 147d - */ 0, -/* 147e - */ 0, -/* 147f - */ 0, -/* 1480 - */ 0, -/* 1481 - _66_0F_3A_41 */ 0x415c, -/* 1482 - */ 0, -/* 1483 - */ 0, -/* 1484 - */ 0, -/* 1485 - _V_66_0F_3A_41 */ 0x415d, -/* 1486 - */ 0, -/* 1487 - */ 0, -/* 1488 - */ 0, -/* 1489 - */ 0, -/* 148a - */ 0, -/* 148b - */ 0, -/* 148c - */ 0, -/* 148d - _66_0F_3A_42 */ 0x415e, -/* 148e - */ 0, -/* 148f - */ 0, -/* 1490 - */ 0, -/* 1491 - _V_66_0F_3A_42 */ 0x415f, -/* 1492 - */ 0, -/* 1493 - */ 0, -/* 1494 - */ 0, -/* 1495 - */ 0, -/* 1496 - */ 0, -/* 1497 - */ 0, -/* 1498 - */ 0, -/* 1499 - _66_0F_3A_44 */ 0x4160, -/* 149a - */ 0, -/* 149b - */ 0, -/* 149c - */ 0, -/* 149d - _V_66_0F_3A_44 */ 0x4161, -/* 149e - */ 0, -/* 149f - */ 0, -/* 14a0 - */ 0, -/* 14a1 - */ 0, -/* 14a2 - */ 0, -/* 14a3 - */ 0, -/* 14a4 - */ 0, -/* 14a5 - */ 0, -/* 14a6 - */ 0, -/* 14a7 - */ 0, -/* 14a8 - */ 0, -/* 14a9 - _V_66_0F_3A_4A */ 0x4162, -/* 14aa - */ 0, -/* 14ab - */ 0, -/* 14ac - */ 0, -/* 14ad - */ 0, -/* 14ae - */ 0, -/* 14af - */ 0, -/* 14b0 - */ 0, -/* 14b1 - */ 0, -/* 14b2 - */ 0, -/* 14b3 - */ 0, -/* 14b4 - */ 0, -/* 14b5 - _V_66_0F_3A_4B */ 0x4163, -/* 14b6 - */ 0, -/* 14b7 - */ 0, -/* 14b8 - */ 0, -/* 14b9 - */ 0, -/* 14ba - */ 0, -/* 14bb - */ 0, -/* 14bc - */ 0, -/* 14bd - */ 0, -/* 14be - */ 0, -/* 14bf - */ 0, -/* 14c0 - */ 0, -/* 14c1 - _V_66_0F_3A_4C */ 0x4164, -/* 14c2 - */ 0, -/* 14c3 - */ 0, -/* 14c4 - */ 0, -/* 14c5 - */ 0, -/* 14c6 - */ 0, -/* 14c7 - */ 0, -/* 14c8 - */ 0, -/* 14c9 - _66_0F_3A_60 */ 0x4165, -/* 14ca - */ 0, -/* 14cb - */ 0, -/* 14cc - */ 0, -/* 14cd - _V_66_0F_3A_60 */ 0x4166, -/* 14ce - */ 0, -/* 14cf - */ 0, -/* 14d0 - */ 0, -/* 14d1 - */ 0, -/* 14d2 - */ 0, -/* 14d3 - */ 0, -/* 14d4 - */ 0, -/* 14d5 - _66_0F_3A_61 */ 0x4167, -/* 14d6 - */ 0, -/* 14d7 - */ 0, -/* 14d8 - */ 0, -/* 14d9 - _V_66_0F_3A_61 */ 0x4168, -/* 14da - */ 0, -/* 14db - */ 0, -/* 14dc - */ 0, -/* 14dd - */ 0, -/* 14de - */ 0, -/* 14df - */ 0, -/* 14e0 - */ 0, -/* 14e1 - _66_0F_3A_62 */ 0x4169, -/* 14e2 - */ 0, -/* 14e3 - */ 0, -/* 14e4 - */ 0, -/* 14e5 - _V_66_0F_3A_62 */ 0x416a, -/* 14e6 - */ 0, -/* 14e7 - */ 0, -/* 14e8 - */ 0, -/* 14e9 - */ 0, -/* 14ea - */ 0, -/* 14eb - */ 0, -/* 14ec - */ 0, -/* 14ed - _66_0F_3A_63 */ 0x416b, -/* 14ee - */ 0, -/* 14ef - */ 0, -/* 14f0 - */ 0, -/* 14f1 - _V_66_0F_3A_63 */ 0x416c, -/* 14f2 - */ 0, -/* 14f3 - */ 0, -/* 14f4 - */ 0, -/* 14f5 - */ 0, -/* 14f6 - */ 0, -/* 14f7 - */ 0, -/* 14f8 - */ 0, -/* 14f9 - _66_0F_3A_DF */ 0x416d, -/* 14fa - */ 0, -/* 14fb - */ 0, -/* 14fc - */ 0, -/* 14fd - _V_66_0F_3A_DF */ 0x416e, -/* 14fe - */ 0, -/* 14ff - */ 0, -/* 1500 - */ 0, -/* 1501 - */ 0, -/* 1502 - */ 0, -/* 1503 - */ 0, -/* 1504 - _0F_71_02 */ 0x24c0, -/* 1505 - _66_0F_71_02 */ 0x24c1, -/* 1506 - */ 0, -/* 1507 - */ 0, -/* 1508 - */ 0, -/* 1509 - _V_66_0F_71_02 */ 0x416f, -/* 150a - */ 0, -/* 150b - */ 0, -/* 150c - */ 0, -/* 150d - */ 0, -/* 150e - */ 0, -/* 150f - */ 0, -/* 1510 - _0F_71_04 */ 0x24c2, -/* 1511 - _66_0F_71_04 */ 0x24c3, -/* 1512 - */ 0, -/* 1513 - */ 0, -/* 1514 - */ 0, -/* 1515 - _V_66_0F_71_04 */ 0x4170, -/* 1516 - */ 0, -/* 1517 - */ 0, -/* 1518 - */ 0, -/* 1519 - */ 0, -/* 151a - */ 0, -/* 151b - */ 0, -/* 151c - _0F_71_06 */ 0x24c4, -/* 151d - _66_0F_71_06 */ 0x24c5, -/* 151e - */ 0, -/* 151f - */ 0, -/* 1520 - */ 0, -/* 1521 - _V_66_0F_71_06 */ 0x4171, -/* 1522 - */ 0, -/* 1523 - */ 0, -/* 1524 - */ 0, -/* 1525 - */ 0, -/* 1526 - */ 0, -/* 1527 - */ 0, -/* 1528 - _0F_72_02 */ 0x24c6, -/* 1529 - _66_0F_72_02 */ 0x24c7, -/* 152a - */ 0, -/* 152b - */ 0, -/* 152c - */ 0, -/* 152d - _V_66_0F_72_02 */ 0x4172, -/* 152e - */ 0, -/* 152f - */ 0, -/* 1530 - */ 0, -/* 1531 - */ 0, -/* 1532 - */ 0, -/* 1533 - */ 0, -/* 1534 - _0F_72_04 */ 0x24c8, -/* 1535 - _66_0F_72_04 */ 0x24c9, -/* 1536 - */ 0, -/* 1537 - */ 0, -/* 1538 - */ 0, -/* 1539 - _V_66_0F_72_04 */ 0x4173, -/* 153a - */ 0, -/* 153b - */ 0, -/* 153c - */ 0, -/* 153d - */ 0, -/* 153e - */ 0, -/* 153f - */ 0, -/* 1540 - _0F_72_06 */ 0x24ca, -/* 1541 - _66_0F_72_06 */ 0x24cb, -/* 1542 - */ 0, -/* 1543 - */ 0, -/* 1544 - */ 0, -/* 1545 - _V_66_0F_72_06 */ 0x4174, -/* 1546 - */ 0, -/* 1547 - */ 0, -/* 1548 - */ 0, -/* 1549 - */ 0, -/* 154a - */ 0, -/* 154b - */ 0, -/* 154c - _0F_73_02 */ 0x24cc, -/* 154d - _66_0F_73_02 */ 0x24cd, -/* 154e - */ 0, -/* 154f - */ 0, -/* 1550 - */ 0, -/* 1551 - _V_66_0F_73_02 */ 0x4175, -/* 1552 - */ 0, -/* 1553 - */ 0, -/* 1554 - */ 0, -/* 1555 - */ 0, -/* 1556 - */ 0, -/* 1557 - */ 0, -/* 1558 - */ 0, -/* 1559 - _66_0F_73_03 */ 0x24ce, -/* 155a - */ 0, -/* 155b - */ 0, -/* 155c - */ 0, -/* 155d - _V_66_0F_73_03 */ 0x4176, -/* 155e - */ 0, -/* 155f - */ 0, -/* 1560 - */ 0, -/* 1561 - */ 0, -/* 1562 - */ 0, -/* 1563 - */ 0, -/* 1564 - _0F_73_06 */ 0x24cf, -/* 1565 - _66_0F_73_06 */ 0x24d0, -/* 1566 - */ 0, -/* 1567 - */ 0, -/* 1568 - */ 0, -/* 1569 - _V_66_0F_73_06 */ 0x4177, -/* 156a - */ 0, -/* 156b - */ 0, -/* 156c - */ 0, -/* 156d - */ 0, -/* 156e - */ 0, -/* 156f - */ 0, -/* 1570 - */ 0, -/* 1571 - _66_0F_73_07 */ 0x24d1, -/* 1572 - */ 0, -/* 1573 - */ 0, -/* 1574 - */ 0, -/* 1575 - _V_66_0F_73_07 */ 0x4178, -/* 1576 - */ 0, -/* 1577 - */ 0, -/* 1578 - */ 0, -/* 1579 - */ 0, -/* 157a - */ 0, -/* 157b - */ 0, -/* 157c - _0F_AE_00 */ 0x4179, -/* 157d - */ 0, -/* 157e - _F3_0F_AE_00 */ 0x24d2, -/* 157f - */ 0, -/* 1580 - */ 0, -/* 1581 - */ 0, -/* 1582 - */ 0, -/* 1583 - */ 0, -/* 1584 - */ 0, -/* 1585 - */ 0, -/* 1586 - */ 0, -/* 1587 - */ 0, -/* 1588 - _0F_AE_01 */ 0x417a, -/* 1589 - */ 0, -/* 158a - _F3_0F_AE_01 */ 0x24d3, -/* 158b - */ 0, -/* 158c - */ 0, -/* 158d - */ 0, -/* 158e - */ 0, -/* 158f - */ 0, -/* 1590 - */ 0, -/* 1591 - */ 0, -/* 1592 - */ 0, -/* 1593 - */ 0, -/* 1594 - _0F_AE_02 */ 0x24d4, -/* 1595 - */ 0, -/* 1596 - _F3_0F_AE_02 */ 0x24d5, -/* 1597 - */ 0, -/* 1598 - _V_0F_AE_02 */ 0x417b, -/* 1599 - */ 0, -/* 159a - */ 0, -/* 159b - */ 0, -/* 159c - */ 0, -/* 159d - */ 0, -/* 159e - */ 0, -/* 159f - */ 0, -/* 15a0 - _0F_AE_03 */ 0x24d6, -/* 15a1 - */ 0, -/* 15a2 - _F3_0F_AE_03 */ 0x24d7, -/* 15a3 - */ 0, -/* 15a4 - _V_0F_AE_03 */ 0x417c, -/* 15a5 - */ 0, -/* 15a6 - */ 0, -/* 15a7 - */ 0, -/* 15a8 - */ 0, -/* 15a9 - */ 0, -/* 15aa - */ 0, -/* 15ab - */ 0, -/* 15ac - _0F_C7_06 */ 0x417d, -/* 15ad - _66_0F_C7_06 */ 0x24d8, -/* 15ae - _F3_0F_C7_06 */ 0x24d9, -/* 15af - */ 0, -/* 15b0 - */ 0, -/* 15b1 - */ 0, -/* 15b2 - */ 0, -/* 15b3 - */ 0, -/* 15b4 - */ 0, -/* 15b5 - */ 0, -/* 15b6 - */ 0, -/* 15b7 - */ 0 -}; - -uint16_t CmpMnemonicOffsets[8] = { -0, 9, 18, 27, 39, 49, 59, 69 -}; -uint16_t VCmpMnemonicOffsets[32] = { -0, 10, 20, 30, 43, 54, 65, 76, 87, 100, 111, 122, 135, 149, 159, 169, 181, -194, 207, 220, 235, 249, 263, 277, 290, 303, 317, 331, 347, 361, 374, 387 -}; diff --git a/distorm3.2-package/src/insts.h b/distorm3.2-package/src/insts.h deleted file mode 100644 index 0cdf2ef..0000000 --- a/distorm3.2-package/src/insts.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -insts.h - -diStorm3 - Powerful disassembler for X86/AMD64 -http://ragestorm.net/distorm/ -distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - - -#ifndef INSTS_H -#define INSTS_H - -#include "instructions.h" - - -/* Flags Table */ -extern _iflags FlagsTable[]; - -/* Root Trie DB */ -extern _InstInfo InstInfos[]; -extern _InstInfoEx InstInfosEx[]; -extern _InstNode InstructionsTree[]; - -/* 3DNow! Trie DB */ -extern _InstNode Table_0F_0F; -/* AVX related: */ -extern _InstNode Table_0F, Table_0F_38, Table_0F_3A; - -/* Helper tables for pesudo compare mnemonics. */ -extern uint16_t CmpMnemonicOffsets[8]; /* SSE */ -extern uint16_t VCmpMnemonicOffsets[32]; /* AVX */ - -#endif /* INSTS_H */ diff --git a/distorm3.2-package/src/operands.h b/distorm3.2-package/src/operands.h deleted file mode 100644 index e1beb6f..0000000 --- a/distorm3.2-package/src/operands.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -operands.h - -diStorm3 - Powerful disassembler for X86/AMD64 -http://ragestorm.net/distorm/ -distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - - -#ifndef OPERANDS_H -#define OPERANDS_H - -#include "config.h" -#include "decoder.h" -#include "prefix.h" -#include "instructions.h" - - -extern uint16_t _REGISTERTORCLASS[]; - -int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, - _OpType type, _OperandNumberType opNum, - unsigned int modrm, _PrefixState* ps, _DecodeType effOpSz, - _DecodeType effAdrSz, int* lockableInstruction); - -#endif /* OPERANDS_H */ diff --git a/distorm3.2-package/src/x86defs.c b/distorm3.2-package/src/x86defs.c deleted file mode 100644 index 4ee7e42..0000000 --- a/distorm3.2-package/src/x86defs.c +++ /dev/null @@ -1,50 +0,0 @@ -/* -x86defs.c - -diStorm3 - Powerful disassembler for X86/AMD64 -http://ragestorm.net/distorm/ -distorm at gmail dot com -Copyright (C) 2003-2012 Gil Dabah - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - - -#include "x86defs.h" -#include "instructions.h" -#include "../include/mnemonics.h" - - -/* - * The first field of an _InstInfo is the flagsInex, which goes into FlagsTable in insts.c - * Since this table is auto generated in disOps, we have to make sure that the first 5 entries - * are reserved for our use here. - * The following defined inst-infos have to be synced manually every time you change insts.c. - */ - -_InstInfo II_arpl = {0 /* INST_MODRM_REQUIRED */, OT_REG16, OT_RM16, ISC_INTEGER << 3, I_ARPL}; -/* - * MOVSXD: - * This is the worst defined instruction ever. It has so many variations. - * I decided after a third review, to make it like MOVSXD RAX, EAX when there IS a REX.W. - * Otherwise it will be MOVSXD EAX, EAX, which really zero extends to RAX. - * Completely ignoring DB 0x66, which is possible by the docs, BTW. - */ -_InstInfo II_movsxd = {1 /* INST_MODRM_REQUIRED | INST_PRE_REX | INST_64BITS */, OT_RM32, OT_REG32_64, ISC_INTEGER << 3, I_MOVSXD}; - -_InstInfo II_nop = {2 /* INST_FLAGS_NONE */, OT_NONE, OT_NONE, ISC_INTEGER << 3, I_NOP}; - -_InstInfo II_pause = {3 /* INST_FLAGS_NONE */, OT_NONE, OT_NONE, ISC_INTEGER << 3, I_PAUSE}; - -_InstInfo II_3dnow = {4 /* INST_32BITS | INST_MODRM_REQUIRED | INST_3DNOW_FETCH */, OT_MM64, OT_MM, ISC_3DNOW << 3, I_UNDEFINED}; diff --git a/hook_misc.c b/hook_misc.c index 2e80868..07e8acd 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -593,6 +593,7 @@ HOOKDEF(SHORT, WINAPI, GetAsyncKeyState, return ret; } +#ifndef CAPE_COMPRESSION HOOKDEF(NTSTATUS, WINAPI, RtlDecompressBuffer, __in USHORT CompressionFormat, __out PUCHAR UncompressedBuffer, @@ -615,6 +616,7 @@ HOOKDEF(NTSTATUS, WINAPI, RtlDecompressBuffer, return ret; } +#endif HOOKDEF(NTSTATUS, WINAPI, RtlCompressBuffer, _In_ USHORT CompressionFormatAndEngine, @@ -1401,3 +1403,74 @@ HOOKDEF(BOOL, WINAPI, RtlSetCurrentTransaction, LOQ_bool("misc", "p", "TransactionHandle", TransactionHandle); return ret; } + +HOOKDEF(HRESULT, WINAPI, OleConvertOLESTREAMToIStorage, + IN LPOLESTREAM lpolestream, + OUT LPSTORAGE pstg, + IN const DVTARGETDEVICE *ptd +) { + void *buf = NULL; uintptr_t len = 0; + + HRESULT ret = Old_OleConvertOLESTREAMToIStorage(lpolestream, pstg, ptd); + +#ifndef _WIN64 + if (lpolestream != NULL) { + buf = (PVOID)*((uint8_t *) lpolestream + 8); + len = *((uint8_t *) lpolestream + 12); + } +#endif + + LOQ_bool("misc", "b", "OLE2", len, buf); + return ret; +} +HOOKDEF(BOOL, WINAPI, FlsAlloc, + _In_ PFLS_CALLBACK_FUNCTION lpCallback +) { + BOOL ret = Old_FlsAlloc(lpCallback); + LOQ_bool("misc", "p", "Callback", lpCallback); + return ret; +} + +HOOKDEF(BOOL, WINAPI, FlsSetValue, + _In_ DWORD dwFlsIndex, + _In_opt_ PVOID lpFlsData +) { + BOOL ret = Old_FlsSetValue(dwFlsIndex, lpFlsData); + LOQ_bool("misc", "ip", "Index", dwFlsIndex, "Data", lpFlsData); + return ret; +} + + +HOOKDEF(PVOID, WINAPI, FlsGetValue, + _In_ DWORD dwFlsIndex +) { + PVOID ret = Old_FlsGetValue(dwFlsIndex); + LOQ_nonnull("misc", "ip", "Index", dwFlsIndex, "ReturnValue", ret); + return ret; +} + +HOOKDEF(BOOL, WINAPI, FlsFree, + _In_ DWORD dwFlsIndex +) { + BOOL ret = Old_FlsFree(dwFlsIndex); + LOQ_bool("misc", "ip", "Index", dwFlsIndex); + return ret; +} + + +HOOKDEF(PVOID, WINAPI, LocalAlloc, + _In_ UINT uFlags, + _In_ SIZE_T uBytes) +{ + PVOID ret = Old_LocalAlloc(uFlags, uBytes); + LOQ_nonnull("misc", "ii", "Flags", uFlags, "Bytes", uBytes); + return ret; +} + +HOOKDEF(VOID, WINAPI, LocalFree, + HLOCAL hMem) +{ + int ret = 0; + Old_LocalFree(hMem); + LOQ_void("misc", "p", "SourceBuffer", hMem); +} diff --git a/hook_process.c b/hook_process.c index 861f53d..1434af6 100644 --- a/hook_process.c +++ b/hook_process.c @@ -27,11 +27,13 @@ along with this program. If not, see . #include "hook_sleep.h" #include "unhook.h" #include "config.h" +#ifdef CAPE_EXTRACTION +#include "CAPE\Debugger.h" +#endif extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); -extern void file_handle_terminate(); -extern int RoutineProcessDump(); -extern BOOL ProcessDumped; +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); + #ifdef CAPE_INJECTION extern void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid); extern void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid); @@ -39,6 +41,17 @@ extern void UnmapSectionViewHandler(PVOID BaseAddress); extern void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID BaseAddress, SIZE_T ViewSize); extern void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer, SIZE_T NumberOfBytesWritten); #endif +#ifdef CAPE_EXTRACTION +extern struct TrackedRegion *TrackedRegionList; +extern void AllocationHandler(PVOID BaseAddress, SIZE_T RegionSize, ULONG AllocationType, ULONG Protect); +extern void ProtectionHandler(PVOID BaseAddress, SIZE_T RegionSize, ULONG Protect, ULONG OldProtect); +extern void FreeHandler(PVOID BaseAddress); +extern void ProcessTrackedRegion(); +#endif + +extern void file_handle_terminate(); +extern int RoutineProcessDump(); +extern BOOL ProcessDumped; HOOKDEF(HANDLE, WINAPI, CreateToolhelp32Snapshot, __in DWORD dwFlags, @@ -408,6 +421,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, // we mark this here as this termination type will kill all threads but ours, including // the logging thread. By setting this, we'll switch into a direct logging mode // for the subsequent call to NtTerminateProcess against our own process handle +#ifdef CAPE_EXTRACTION + ProcessTrackedRegion(); +#endif if (g_config.procdump && !ProcessDumped) { DoOutputDebugString("NtTerminateProcess hook: Attempting to dump process %d\n", GetCurrentProcessId()); @@ -418,6 +434,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtTerminateProcess, file_handle_terminate(); } else if (GetCurrentProcessId() == our_getprocessid(ProcessHandle)) { +#ifdef CAPE_EXTRACTION + ProcessTrackedRegion(); +#endif if (g_config.procdump && !ProcessDumped) { DoOutputDebugString("NtTerminateProcess hook: Attempting to dump process %d\n", GetCurrentProcessId()); @@ -536,10 +555,6 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, __in ULONG AllocationType, __in ULONG Win32Protect ) { - PVOID InputAddress = *BaseAddress; - LARGE_INTEGER InputOffset = *SectionOffset; - SIZE_T InputSize = *ViewSize; - NTSTATUS ret = Old_NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect); @@ -552,6 +567,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtMapViewOfSection, if (NT_SUCCESS(ret)) { #ifdef CAPE_INJECTION MapSectionViewHandler(ProcessHandle, SectionHandle, *BaseAddress, *ViewSize); +#endif +#ifdef CAPE_EXTRACTION + ProtectionHandler(*BaseAddress, ViewSize, Win32Protect, 0); #endif if (pid != GetCurrentProcessId()) { pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); @@ -576,10 +594,13 @@ HOOKDEF(NTSTATUS, WINAPI, NtAllocateVirtualMemory, NTSTATUS ret = Old_NtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect); - if (ret != STATUS_CONFLICTING_ADDRESSES) { - LOQ_ntstatus("process", "pPPhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, - "RegionSize", RegionSize, "Protection", Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); - } +#ifdef CAPE_EXTRACTION + if (NT_SUCCESS(ret) && !called_by_hook() && GetCurrentProcessId() == our_getprocessid(ProcessHandle)) + AllocationHandler(*BaseAddress, *RegionSize, AllocationType, Protect); +#endif + + LOQ_ntstatus("process", "pPPhs", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, + "RegionSize", RegionSize, "Protection", Protect, "StackPivoted", is_stack_pivoted() ? "yes" : "no"); return ret; } @@ -645,7 +666,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtWriteVirtualMemory, if (NT_SUCCESS(ret)) { #ifdef CAPE_INJECTION WriteMemoryHandler(ProcessHandle, BaseAddress, Buffer, *NumberOfBytesWritten); -#endif +#endif pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); } @@ -677,7 +698,7 @@ HOOKDEF(BOOL, WINAPI, WriteProcessMemory, if (ret) { #ifdef CAPE_INJECTION WriteMemoryHandler(hProcess, lpBaseAddress, lpBuffer, *lpNumberOfBytesWritten); -#endif +#endif pipe("PROCESS:%d:%d", is_suspended(pid, 0), pid); disable_sleep_skip(); } @@ -748,6 +769,21 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, ) { NTSTATUS ret; MEMORY_BASIC_INFORMATION meminfo; +#ifdef CAPE_EXTRACTION + PTRACKEDREGION TrackedRegion; +#endif + + if (NewAccessProtection == PAGE_EXECUTE_READWRITE && BaseAddress && NumberOfBytesToProtect && + GetCurrentProcessId() == our_getprocessid(ProcessHandle) && is_in_dll_range((ULONG_PTR)*BaseAddress)) { + unsigned int offset; + char *dllname = convert_address_to_dll_name_and_offset((ULONG_PTR)*BaseAddress, &offset); + if (dllname && !strcmp(dllname, "ntdll.dll")) { + // don't allow writes, this will cause memory access violations + // that we are going to handle in the RtlDispatchException hook + NewAccessProtection = PAGE_EXECUTE_READ; + } + if (dllname) free(dllname); + } if (NewAccessProtection == PAGE_EXECUTE_READ && BaseAddress && NumberOfBytesToProtect && GetCurrentProcessId() == our_getprocessid(ProcessHandle) && is_in_dll_range((ULONG_PTR)*BaseAddress)) @@ -764,6 +800,16 @@ HOOKDEF(NTSTATUS, WINAPI, NtProtectVirtualMemory, set_lasterrors(&lasterrors); } +#ifdef CAPE_EXTRACTION + if (NT_SUCCESS(ret) && !called_by_hook() && GetCurrentProcessId() == our_getprocessid(ProcessHandle)) + { + ProtectionHandler(*BaseAddress, *NumberOfBytesToProtect, NewAccessProtection, *OldAccessProtection); + + if ((TrackedRegion = GetTrackedRegion(*BaseAddress)) && TrackedRegion->Guarded) + *OldAccessProtection &= (~PAGE_GUARD); + } +#endif + if (NewAccessProtection == PAGE_EXECUTE_READWRITE && (ULONG_PTR)meminfo.AllocationBase >= get_stack_bottom() && (((ULONG_PTR)meminfo.AllocationBase + meminfo.RegionSize) <= get_stack_top())) { LOQ_ntstatus("process", "pPPhhHss", "ProcessHandle", ProcessHandle, "BaseAddress", BaseAddress, @@ -791,6 +837,9 @@ HOOKDEF(BOOL, WINAPI, VirtualProtectEx, ) { BOOL ret; MEMORY_BASIC_INFORMATION meminfo; +#ifdef CAPE_EXTRACTION + PTRACKEDREGION TrackedRegion; +#endif if (flNewProtect == PAGE_EXECUTE_READ && GetCurrentProcessId() == our_getprocessid(hProcess) && is_in_dll_range((ULONG_PTR)lpAddress)) @@ -807,6 +856,16 @@ HOOKDEF(BOOL, WINAPI, VirtualProtectEx, set_lasterrors(&lasterrors); } +#ifdef CAPE_EXTRACTION + if (NT_SUCCESS(ret) && !called_by_hook() && GetCurrentProcessId() == our_getprocessid(hProcess)) + { + ProtectionHandler(lpAddress, dwSize, flNewProtect, *lpflOldProtect); + + if ((TrackedRegion = GetTrackedRegion(lpAddress)) && TrackedRegion->Guarded) + *lpflOldProtect &= (~PAGE_GUARD); + } +#endif + if (flNewProtect == PAGE_EXECUTE_READWRITE && GetCurrentProcessId() == our_getprocessid(hProcess) && (ULONG_PTR)meminfo.AllocationBase >= get_stack_bottom() && (((ULONG_PTR)meminfo.AllocationBase + meminfo.RegionSize) <= get_stack_top())) { LOQ_bool("process", "ppphhHss", "ProcessHandle", hProcess, "Address", lpAddress, @@ -826,6 +885,11 @@ HOOKDEF(NTSTATUS, WINAPI, NtFreeVirtualMemory, IN OUT PSIZE_T RegionSize, IN ULONG FreeType ) { +#ifdef CAPE_EXTRACTION + if (!called_by_hook() && GetCurrentProcessId() == our_getprocessid(ProcessHandle) && *RegionSize == 0 && (FreeType & MEM_RELEASE)) + FreeHandler(*BaseAddress); +#endif + NTSTATUS ret = Old_NtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType); @@ -906,11 +970,24 @@ HOOKDEF(NTSTATUS, WINAPI, DbgUiWaitStateChange, return ret; } -HOOKDEF_NOTAIL(WINAPI, RtlDispatchException, +HOOKDEF(BOOLEAN, WINAPI, RtlDispatchException, __in PEXCEPTION_RECORD ExceptionRecord, __in PCONTEXT Context) { #ifndef _WIN64 + if (ExceptionRecord && ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && ExceptionRecord->ExceptionFlags == 0 && + ExceptionRecord->NumberParameters == 2 && ExceptionRecord->ExceptionInformation[0] == 1) { + unsigned int offset; + char *dllname = convert_address_to_dll_name_and_offset(ExceptionRecord->ExceptionInformation[1], &offset); + if (dllname && !strcmp(dllname, "ntdll.dll")) { + free(dllname); + // if trying to write to ntdll.dll, then just skip the instruction + Context->Eip += lde((void *)Context->Eip); + return TRUE; + } + if (dllname) free(dllname); + } + if (ExceptionRecord && (ULONG_PTR)ExceptionRecord->ExceptionAddress >= g_our_dll_base && (ULONG_PTR)ExceptionRecord->ExceptionAddress < (g_our_dll_base + g_our_dll_size)) { char buf[160]; ULONG_PTR seh = 0; @@ -919,7 +996,7 @@ HOOKDEF_NOTAIL(WINAPI, RtlDispatchException, seh = ((DWORD *)tebtmp[0])[1]; if (seh < g_our_dll_base || seh >= (g_our_dll_base + g_our_dll_size)) { _snprintf(buf, sizeof(buf), "Exception 0x%x reported at offset 0x%x in capemon itself while accessing 0x%x from hook %s", ExceptionRecord->ExceptionCode, (DWORD)((ULONG_PTR)ExceptionRecord->ExceptionAddress - g_our_dll_base), ExceptionRecord->ExceptionInformation[1], hook_info()->current_hook ? hook_info()->current_hook->funcname : "unknown"); - log_anomaly("cuckoocrash", buf); + log_anomaly("capemon crash", buf); } } #endif @@ -927,7 +1004,7 @@ HOOKDEF_NOTAIL(WINAPI, RtlDispatchException, // flush logs prior to handling of an exception without having to register a vectored exception handler log_flush(); - return 0; + return Old_RtlDispatchException(ExceptionRecord, Context); } HOOKDEF_NOTAIL(WINAPI, NtRaiseException, diff --git a/hook_sleep.c b/hook_sleep.c index 9f08c1e..6ac4fc5 100644 --- a/hook_sleep.c +++ b/hook_sleep.c @@ -23,10 +23,14 @@ along with this program. If not, see . #include "pipe.h" #include "config.h" #include "misc.h" +#include "CAPE\CAPE.h" +#include "CAPE\Debugger.h" -// only skip Sleep()'s the first five seconds +// only skip Sleep()s the first five seconds #define MAX_SLEEP_SKIP_DIFF 5000 +extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); +extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); // skipping sleep calls is done while this variable is set to true static int sleep_skip_active = 1; @@ -587,6 +591,38 @@ HOOKDEF(void, WINAPI, GetSystemTimeAsFileTime, return; } +WAITORTIMERCALLBACK HookedCallback; + +typedef VOID(CALLBACK *_WaitOrTimerCallback)( + _In_ PVOID lpParameter, + _In_ BOOLEAN TimerOrWaitFired +); + +VOID CALLBACK CallbackHook( + _In_ PVOID lpParameter, + _In_ BOOLEAN TimerOrWaitFired +) +{ + _WaitOrTimerCallback pWaitOrTimerCallback; + + if (!HookedCallback) { + DoOutputDebugString("Timer callback hook: error, HookedCallback NULL.\n"); + return; + } + + if (DEBUGGER_ENABLED) { + DWORD Tid = GetCurrentThreadId(); + DoOutputDebugString("Timer callback hook: Initialising breakpoints for thread %d.\n", Tid); + InitNewThreadBreakpoints(Tid); + } + else + DoOutputDebugString("Timer callback hook: passing to callback at 0x%p.\n", HookedCallback); + + *(FARPROC*)&pWaitOrTimerCallback = (FARPROC)HookedCallback; + HookedCallback = NULL; + pWaitOrTimerCallback(lpParameter, TimerOrWaitFired); +} + HOOKDEF(BOOL, WINAPI, CreateTimerQueueTimer, _Out_ PHANDLE phNewTimer, _In_opt_ HANDLE TimerQueue, @@ -596,7 +632,18 @@ HOOKDEF(BOOL, WINAPI, CreateTimerQueueTimer, _In_ DWORD Period, _In_ ULONG Flags ) { - BOOL ret = Old_CreateTimerQueueTimer(phNewTimer, TimerQueue, Callback, Parameter, DueTime, Period, Flags); + BOOL ret; + + if (Callback && !HookedCallback) { + HookedCallback = Callback; + Callback = &CallbackHook; + } + + ret = Old_CreateTimerQueueTimer(phNewTimer, TimerQueue, Callback, Parameter, DueTime, Period, Flags); + + if (HookedCallback) + Callback = HookedCallback; + LOQ_bool("system", "Pphhiii", "phNewTimer", phNewTimer, "TimerQueue", TimerQueue, "Callback", Callback, "Parameter", Parameter, "DueTime", DueTime, "Period", Period, "Flags", Flags); return ret; } diff --git a/hook_thread.c b/hook_thread.c index 8952eb9..b528f75 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -553,3 +553,12 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueryInformationThread, return ret; } + +HOOKDEF(NTSTATUS, WINAPI, NtYieldExecution, + VOID +) { + NTSTATUS ret = 0; + LOQ_void("threading", ""); + ret = Old_NtYieldExecution(); + return ret; +} diff --git a/hooking.c b/hooking.c index 61b785f..d1d8d4f 100644 --- a/hooking.c +++ b/hooking.c @@ -225,6 +225,9 @@ int WINAPI enter_hook(hook_t *h, ULONG_PTR sp, ULONG_PTR ebp_or_rip) #ifdef CAPE_DUMP_ON_API dump_on_api(h); #endif +#ifdef CAPE_TRACE + base_on_api(h); +#endif return 1; } diff --git a/hooking_32.c b/hooking_32.c index cfd41f7..a2d7246 100644 --- a/hooking_32.c +++ b/hooking_32.c @@ -30,7 +30,7 @@ along with this program. If not, see . #include "config.h" // length disassembler engine -static int lde(void *addr) +int lde(void *addr) { // the length of an instruction is 16 bytes max, but there can also be // 16 instructions of length one, so.. we support "decomposing" 16 diff --git a/hooks.h b/hooks.h index c36ad2e..185b58a 100644 --- a/hooks.h +++ b/hooks.h @@ -1096,7 +1096,7 @@ extern HOOKDEF(NTSTATUS, WINAPI, DbgUiWaitStateChange, __in_opt PLARGE_INTEGER Timeout ); -extern HOOKDEF_NOTAIL(WINAPI, RtlDispatchException, +extern HOOKDEF(BOOLEAN, WINAPI, RtlDispatchException, __in PEXCEPTION_RECORD ExceptionRecord, __in PCONTEXT Context ); @@ -3008,3 +3008,13 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtCommitTransaction, extern HOOKDEF(BOOL, WINAPI, RtlSetCurrentTransaction, _In_ HANDLE TransactionHandle ); + +extern HOOKDEF(NTSTATUS, WINAPI, NtYieldExecution, + VOID +); + +extern HOOKDEF(HRESULT, WINAPI, OleConvertOLESTREAMToIStorage, + IN LPOLESTREAM lpolestream, + OUT LPSTORAGE pstg, + IN const DVTARGETDEVICE *ptd +); \ No newline at end of file diff --git a/loader/loader/loader.vcxproj b/loader/loader/loader.vcxproj index 95dc696..cea11b9 100644 --- a/loader/loader/loader.vcxproj +++ b/loader/loader/loader.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -28,26 +28,26 @@ Application true - v140_xp + v141_xp NotSet Application true - v140_xp + v141_xp Unicode Application false - v140_xp + v141_xp true NotSet Application false - v140_xp + v141_xp true NotSet From 98efedff89e73fdc43a9955f59d67f7db7375859 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 31 Oct 2018 17:16:07 +0000 Subject: [PATCH 37/39] Improve handling of injection via named shared sections with different handles and remote thread invocation. --- CAPE/CAPE.c | 728 ++++++++++++++++++++++++++++------------------- CAPE/CAPE.h | 4 + CAPE/Injection.c | 161 +++++++---- hook_misc.c | 3 + hook_thread.c | 7 +- misc.c | 2 +- 6 files changed, 550 insertions(+), 355 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index c9f0c99..470065b 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -15,17 +15,18 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.If not, see . */ -#define _CRT_RAND_S +#define _CRT_RAND_S #define MD5LEN 16 #define MAX_PRETRAMP_SIZE 320 #define MAX_TRAMP_SIZE 128 +#define MAX_UNICODE_PATH 32768 #define BUFSIZE 1024 // For hashing -#define DUMP_MAX 100 +#define DUMP_MAX 100 #define CAPE_OUTPUT_FILE "CapeOutput.bin" -#include +#include #include #include #include @@ -100,7 +101,7 @@ typedef struct _hook_info_t { ULONG_PTR main_caller_retaddr; ULONG_PTR parent_caller_retaddr; } hook_info_t; - + extern uint32_t path_from_handle(HANDLE handle, wchar_t *path, uint32_t path_buffer_len); extern int called_by_hook(void); extern int operate_on_backtrace(ULONG_PTR _esp, ULONG_PTR _ebp, void *extra, int(*func)(void *, ULONG_PTR)); @@ -160,7 +161,7 @@ BOOL InsideHook(LPVOID* ReturnAddress, LPVOID Address) *ReturnAddress = Address; return TRUE; } - + return FALSE; } @@ -184,8 +185,8 @@ LPVOID GetReturnAddress(hook_info_t *hookinfo) operate_on_backtrace(hookinfo->stack_pointer, hookinfo->frame_pointer, &ReturnAddress, GetCurrentFrame); return ReturnAddress; } - __except(EXCEPTION_EXECUTE_HANDLER) - { + __except(EXCEPTION_EXECUTE_HANDLER) + { #ifdef _WIN64 DoOutputDebugString("GetReturnAddress: Exception trying to get return address with Rip 0x%p.\n", hookinfo->frame_pointer); #else @@ -212,7 +213,7 @@ PVOID GetHookCallerBase() if (ReturnAddress) { DWORD ThreadId = GetCurrentThreadId(); - + AllocationBase = GetAllocationBase(ReturnAddress); DoOutputDebugString("GetHookCallerBase: thread %d (handle 0x%x), return address 0x%p, allocation base 0x%p.\n", ThreadId, GetThreadHandle(ThreadId), ReturnAddress, AllocationBase); @@ -234,15 +235,15 @@ void PrintHexBytes(__in char* TextBuffer, __in BYTE* HexBuffer, __in unsigned in //************************************************************************************** { unsigned int i; - + if (HexBuffer == NULL) return; - + for (i=0; iTargetPid = TargetPid; - + if (CapeMetaData->TargetProcess == NULL) { DoOutputDebugString("SetCapeMetaData: failed to allocate memory for target process string.\n"); return FALSE; } - + if (CapeMetaData->TargetProcess == NULL && !GetModuleFileNameEx(hTargetProcess, NULL, CapeMetaData->TargetProcess, MAX_PATH)) { CapeMetaData->TargetProcess = (char*)malloc(MAX_PATH); @@ -427,7 +428,7 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) { LARGE_INTEGER LargeFileSize; DWORD dwBytesRead; - + if (!GetFileSizeEx(hFile, &LargeFileSize)) { DoOutputErrorString("MapFile: Cannot get file size"); @@ -447,23 +448,23 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) } *FileSize = LargeFileSize.LowPart; - + DoOutputDebugString("File size: 0x%x", *FileSize); - + *Buffer = malloc(*FileSize); - + if (SetFilePointer(hFile, 0, 0, FILE_BEGIN)) { DoOutputErrorString("MapFile: Failed to set file pointer"); - return FALSE; + return FALSE; } - + if (*Buffer == NULL) { DoOutputErrorString("MapFile: Memory allocation error in MapFile"); return FALSE; } - + if (FALSE == ReadFile(hFile, (LPVOID)*Buffer, *FileSize, &dwBytesRead, NULL)) { DoOutputErrorString("ReadFile error"); @@ -484,7 +485,7 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) free(Buffer); return FALSE; } - + return TRUE; } @@ -492,19 +493,39 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) //************************************************************************************** { - DWORD CurrentProcessId; - + DWORD CurrentProcessId; + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; while (CurrentInjectionInfo) { CurrentProcessId = CurrentInjectionInfo->ProcessId; - + if (CurrentProcessId == ProcessId) return CurrentInjectionInfo; else CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; } - + + return NULL; +} + +//************************************************************************************** +PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle) +//************************************************************************************** +{ + HANDLE CurrentProcessHandle; + + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; + while (CurrentInjectionInfo) + { + CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; + + if (CurrentProcessHandle == ProcessHandle) + return CurrentInjectionInfo; + else + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + return NULL; } @@ -515,73 +536,130 @@ PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) PINJECTIONINFO CurrentInjectionInfo, PreviousInjectionInfo; PreviousInjectionInfo = NULL; - + if (InjectionInfoList == NULL) { InjectionInfoList = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); - + if (InjectionInfoList == NULL) { DoOutputDebugString("CreateInjectionInfo: failed to allocate memory for initial injection info list.\n"); return NULL; } - + memset(InjectionInfoList, 0, sizeof(struct InjectionInfo)); - + InjectionInfoList->ProcessId = ProcessId; } CurrentInjectionInfo = InjectionInfoList; - + while (CurrentInjectionInfo) - { + { if ((CurrentInjectionInfo->ProcessId) == ProcessId) - break; - + break; + PreviousInjectionInfo = CurrentInjectionInfo; CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; } - + if (!CurrentInjectionInfo) { // We haven't found it in the linked list, so create a new one CurrentInjectionInfo = PreviousInjectionInfo; - + CurrentInjectionInfo->NextInjectionInfo = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); - + if (CurrentInjectionInfo->NextInjectionInfo == NULL) { DoOutputDebugString("CreateInjectionInfo: Failed to allocate new thread breakpoints.\n"); return NULL; } - + memset(CurrentInjectionInfo->NextInjectionInfo, 0, sizeof(struct InjectionInfo)); - + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - + CurrentInjectionInfo->ProcessId = ProcessId; } - + return CurrentInjectionInfo; } +//************************************************************************************** +BOOL DropInjectionInfo(HANDLE ProcessHandle) +//************************************************************************************** +{ + HANDLE CurrentProcessHandle; + PINJECTIONINFO PreviousInjectionInfo, CurrentInjectionInfo = InjectionInfoList; + + PreviousInjectionInfo = NULL; + + while (CurrentInjectionInfo) + { + CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; + + if (CurrentProcessHandle == ProcessHandle) + { + // Unlink this from the list and free the memory + if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo) + { + PreviousInjectionInfo->NextInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d.\n", CurrentInjectionInfo->ProcessId); + } + else if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo == NULL) + { + PreviousInjectionInfo->NextInjectionInfo = NULL; + DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d from the end of the section view list.\n", CurrentInjectionInfo->ProcessId); + } + else if (!PreviousInjectionInfo) + { + InjectionInfoList = NULL; + DoOutputDebugString("DropInjectionInfo: removed the head of the injection info list for pid %d.\n", CurrentInjectionInfo->ProcessId); + } + + free(CurrentInjectionInfo); + + return TRUE; + } + + PreviousInjectionInfo = CurrentInjectionInfo; + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return FALSE; +} + //************************************************************************************** PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) //************************************************************************************** { PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - + while (CurrentSectionView) { + wchar_t *SectionName; + if (CurrentSectionView->SectionHandle == SectionHandle) - { - DoOutputDebugString("GetSectionView: returning section view pointer 0x%x.\n", CurrentSectionView); return CurrentSectionView; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + return CurrentSectionView; + } + free(SectionName); } CurrentSectionView = CurrentSectionView->NextSectionView; } - + return NULL; } @@ -592,56 +670,76 @@ PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; PreviousSectionView = NULL; - + if (SectionViewList == NULL) { SectionViewList = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); - + if (SectionViewList == NULL) { DoOutputDebugString("AddSectionView: failed to allocate memory for initial section view list.\n"); return NULL; } - + memset(SectionViewList, 0, sizeof(struct InjectionSectionView)); - + SectionViewList->SectionHandle = SectionHandle; SectionViewList->LocalView = LocalView; SectionViewList->ViewSize = ViewSize; + SectionViewList->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + if (SectionViewList->SectionName) + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); } CurrentSectionView = SectionViewList; - + while (CurrentSectionView) { + wchar_t *SectionName; + if ((CurrentSectionView->SectionHandle) == SectionHandle) - break; - - PreviousSectionView = CurrentSectionView; + break; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + break; + } + free(SectionName); + } + + PreviousSectionView = CurrentSectionView; CurrentSectionView = CurrentSectionView->NextSectionView; } - + if (!CurrentSectionView) { // We haven't found it in the linked list, so create a new one CurrentSectionView = PreviousSectionView; - + CurrentSectionView->NextSectionView = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); - + if (CurrentSectionView->NextSectionView == NULL) { DoOutputDebugString("CreateSectionView: Failed to allocate new injection sectionview structure.\n"); return NULL; } - + memset(CurrentSectionView->NextSectionView, 0, sizeof(struct InjectionSectionView)); - + CurrentSectionView = CurrentSectionView->NextSectionView; CurrentSectionView->SectionHandle = SectionHandle; - CurrentSectionView->LocalView = LocalView; - CurrentSectionView->ViewSize = ViewSize; + CurrentSectionView->LocalView = LocalView; + CurrentSectionView->ViewSize = ViewSize; + CurrentSectionView->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + path_from_handle(SectionHandle, CurrentSectionView->SectionName, MAX_UNICODE_PATH); } - + return CurrentSectionView; } @@ -652,7 +750,7 @@ BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; PreviousSectionView = NULL; - + if (SectionViewList == NULL) { DoOutputDebugString("DropSectionView: failed to obtain initial section view list.\n"); @@ -660,7 +758,7 @@ BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) } CurrentSectionView = SectionViewList; - + while (CurrentSectionView) { if (CurrentSectionView == SectionView) @@ -681,16 +779,16 @@ BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) SectionViewList = NULL; DoOutputDebugString("DropSectionView: removed the head of the section view list.\n"); } - + free(CurrentSectionView); - - return TRUE; + + return TRUE; } - + PreviousSectionView = CurrentSectionView; CurrentSectionView = CurrentSectionView->NextSectionView; } - + return FALSE; } @@ -703,7 +801,7 @@ void DumpSectionViewsForPid(DWORD Pid) DWORD BufferSize = MAX_PATH; LPVOID PEPointer = NULL; BOOL Dumped = FALSE; - + CurrentInjectionInfo = GetInjectionInfo(Pid); if (CurrentInjectionInfo == NULL) @@ -719,13 +817,13 @@ void DumpSectionViewsForPid(DWORD Pid) if (CurrentSectionView->TargetProcessId == Pid && CurrentSectionView->LocalView) { DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d, local address 0x%p.\n", Pid); - + PEPointer = CurrentSectionView->LocalView; - + while (ScanForDisguisedPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) { DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); - + CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = Pid; CapeMetaData->Address = PEPointer; @@ -737,35 +835,35 @@ void DumpSectionViewsForPid(DWORD Pid) } else DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); - + ((BYTE*)PEPointer)++; } - + if (Dumped == FALSE) { DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); - + CapeMetaData->DumpType = INJECTION_SHELLCODE; - + CapeMetaData->TargetPid = Pid; - + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) { DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); Dumped = TRUE; } else - DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); } } - + //DropSectionView(CurrentSectionView); - + CurrentSectionView = CurrentSectionView->NextSectionView; } - + if (Dumped == FALSE) - DoOutputDebugString("DumpSectionViewsForPid: no shared section views found for pid %d.\n", Pid); + DoOutputDebugString("DumpSectionViewsForPid: no shared section views found for pid %d.\n", Pid); return; } @@ -777,7 +875,7 @@ void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) DWORD BufferSize = MAX_PATH; LPVOID PEPointer = NULL; BOOL Dumped = FALSE; - + if (!SectionView->LocalView) { DoOutputDebugString("DumpSectionView: Section view local view address not set.\n"); @@ -789,31 +887,67 @@ void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) DoOutputDebugString("DumpSectionView: Section view has no target process - error.\n"); return; } - + Dumped = DumpPEsInRange(SectionView->LocalView, SectionView->ViewSize); - + if (Dumped) DoOutputDebugString("DumpSectionView: Dumped PE image from shared section view, local address 0x%p.\n", SectionView->LocalView); else { DoOutputDebugString("DumpSectionView: no PE file found in shared section view, attempting raw dump.\n"); - + CapeMetaData->DumpType = INJECTION_SHELLCODE; - + CapeMetaData->TargetPid = SectionView->TargetProcessId; - + if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) { DoOutputDebugString("DumpSectionView: Dumped shared section view."); Dumped = TRUE; } else - DoOutputDebugString("DumpSectionView: Failed to dump shared section view."); + DoOutputDebugString("DumpSectionView: Failed to dump shared section view."); } - + if (Dumped == TRUE) DropSectionView(SectionView); - + + return; +} + +//************************************************************************************** +void DumpSectionViewsForHandle(HANDLE SectionHandle) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + wchar_t *SectionName; + + if (CurrentSectionView->SectionHandle == SectionHandle) + break; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + break; + } + free(SectionName); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (CurrentSectionView) + DumpSectionView(CurrentSectionView); + return; } @@ -825,42 +959,42 @@ char* GetName() SYSTEMTIME Time; DWORD RetVal; unsigned int random; - + FullPathName = (char*) malloc(MAX_PATH); if (FullPathName == NULL) { DoOutputErrorString("GetName: Error allocating memory for full path string"); - return 0; + return 0; } - + OutputFilename = (char*)malloc(MAX_PATH); - + if (OutputFilename == NULL) { DoOutputErrorString("GetName: failed to allocate memory for file name string"); return 0; } - + GetSystemTime(&Time); - + if (rand_s(&random)) { DoOutputErrorString("GetName: failed to obtain a random number"); return 0; } - + sprintf_s(OutputFilename, MAX_PATH*sizeof(char), "%d_%d%d%d%d%d%d%d%d", GetCurrentProcessId(), abs(random * Time.wMilliseconds), Time.wSecond, Time.wMinute, Time.wHour, Time.wDay, Time.wDayOfWeek, Time.wMonth, Time.wYear); - + // We want to dump CAPE output to the 'analyzer' directory memset(FullPathName, 0, MAX_PATH); - + strncpy_s(FullPathName, MAX_PATH, g_config.analyzer, strlen(g_config.analyzer)+1); if (strlen(FullPathName) + strlen("\\CAPE\\") + strlen(OutputFilename) >= MAX_PATH) { DoOutputDebugString("GetName: Error, CAPE destination path too long."); - free(OutputFilename); + free(OutputFilename); free(FullPathName); return 0; } @@ -872,7 +1006,7 @@ char* GetName() if (RetVal == 0 && GetLastError() != ERROR_ALREADY_EXISTS) { DoOutputDebugString("GetName: Error creating output directory"); - free(OutputFilename); + free(OutputFilename); free(FullPathName); return 0; } @@ -902,14 +1036,14 @@ BOOL GetHash(unsigned char* Buffer, unsigned int Size, char* OutputFilenameBuffe if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) { - DoOutputErrorString("CryptCreateHash failed"); + DoOutputErrorString("CryptCreateHash failed"); CryptReleaseContext(hProv, 0); return 0; } if (!CryptHashData(hHash, Buffer, Size, 0)) { - DoOutputErrorString("CryptHashData failed"); + DoOutputErrorString("CryptHashData failed"); CryptReleaseContext(hProv, 0); CryptDestroyHash(hHash); return 0; @@ -918,17 +1052,17 @@ BOOL GetHash(unsigned char* Buffer, unsigned int Size, char* OutputFilenameBuffe cbHash = MD5LEN; if (!CryptGetHashParam(hHash, HP_HASHVAL, MD5Hash, &cbHash, 0)) { - DoOutputErrorString("CryptGetHashParam failed"); + DoOutputErrorString("CryptGetHashParam failed"); } CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); - + for (i = 0; i < cbHash; i++) { PrintHexBytes(OutputFilenameBuffer, MD5Hash, MD5LEN); } - + return 1; } @@ -943,25 +1077,25 @@ char* GetHashFromHandle(HANDLE hFile) char * OutputFilenameBuffer; if (!MapFile(hFile, &Buffer, &FileSize)) - { + { DoOutputErrorString("MapFile error - check the path is valid and the file has size."); return 0; } - + OutputFilenameBuffer = (char*) malloc(MAX_PATH); if (OutputFilenameBuffer == NULL) { DoOutputErrorString("Error allocating memory for hash string"); - return 0; + return 0; } - + if (!GetHash(Buffer, FileSize, (char*)OutputFilenameBuffer)) { DoOutputErrorString("GetHashFromHandle: GetHash function failed"); - return 0; + return 0; } - + DoOutputDebugString("GetHash returned: %s", OutputFilenameBuffer); // Check if we have a valid DOS and PE header at the beginning of Buffer @@ -989,12 +1123,12 @@ char* GetHashFromHandle(HANDLE hFile) } } } - + CloseHandle(hFile); - + // We don't need the file buffer any more free(Buffer); - + // We leak the OutputFilenameBuffer return OutputFilenameBuffer; } @@ -1018,23 +1152,23 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) e_lfanew = (LONG)*(DWORD*)(Buffer+0x3c); DoOutputDebugString("Encrypted e_lfanew: 0x%x", e_lfanew); - + for (j=0; j PE_HEADER_LIMIT) - { + { DoOutputDebugString("The pointer to the PE header seems a tad large: 0x%x", e_lfanew); //return FALSE; } // let's get the NT signature a.k.a PE header memcpy(&NT_Signature, Buffer+e_lfanew, 4); - + DoOutputDebugString("Encrypted NT_Signature: 0x%x", NT_Signature); - + // let's try decrypting it with the key for (k=0; k<4; k++) *((BYTE*)&NT_Signature+k) = *((BYTE*)&NT_Signature+k)^i; @@ -1045,23 +1179,23 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) if (NT_Signature == IMAGE_NT_SIGNATURE) { DoOutputDebugString("Xor-encrypted PE detected, about to dump.\n"); - + DecryptedBuffer = (BYTE*)malloc(Size); - + if (DecryptedBuffer == NULL) { DoOutputErrorString("Error allocating memory for decrypted PE binary"); return FALSE; } - + memcpy(DecryptedBuffer, Buffer, Size); - + for (k=0; kAddress = DecryptedBuffer; DumpImageInCurrentProcess(DecryptedBuffer); - + free(DecryptedBuffer); return i; } @@ -1072,11 +1206,11 @@ int DumpXorPE(LPBYTE Buffer, unsigned int Size) } } } - + // We free can free DecryptedBuffer as it's no longer needed if(DecryptedBuffer) free(DecryptedBuffer); - + return FALSE; } @@ -1086,32 +1220,32 @@ int ScanPageForNonZero(LPVOID Address) { unsigned int p; DWORD_PTR AddressOfPage; - + if (!Address) - { + { DoOutputDebugString("ScanPageForNonZero: Error - Supplied address zero.\n"); return 0; } - + if (!SystemInfo.dwPageSize) GetSystemInfo(&SystemInfo); - + if (!SystemInfo.dwPageSize) { DoOutputErrorString("ScanPageForNonZero: Failed to obtain system page size.\n"); return 0; } - + AddressOfPage = ((DWORD_PTR)Address/SystemInfo.dwPageSize)*SystemInfo.dwPageSize; - - __try - { + + __try + { for (p=0; pe_lfanew == 0) + if ((ULONG)pDosHeader->e_lfanew == 0) { // e_lfanew is zero continue; @@ -1201,39 +1335,39 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) // e_lfanew points beyond end of region continue; } - + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - - if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { // No 'PE' header - continue; + continue; } - - if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) { // Basic requirements DoOutputDebugString("ScanForPE: Basic requirements failure.\n"); continue; } - + if (Offset) { *Offset = (LPVOID)((char*)Buffer+p); } - + DoOutputDebugString("ScanForPE: PE image located at: 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); - + return 1; } - } - __except(EXCEPTION_EXECUTE_HANDLER) - { + } + __except(EXCEPTION_EXECUTE_HANDLER) + { DoOutputDebugString("ScanForPE: Exception occured reading memory address 0x%x\n", (DWORD_PTR)((char*)Buffer+p)); return 0; } } - + DoOutputDebugString("ScanForPE: No PE image located at 0x%x.\n", Buffer); return 0; } @@ -1242,8 +1376,8 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) BOOL TestPERequirements(PIMAGE_NT_HEADERS pNtHeader) //************************************************************************************** { - __try - { + __try + { if ((pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (pNtHeader->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)) { //DoOutputDebugString("TestPERequirements: OptionalHeader.Magic bad. (0x%x)", (DWORD_PTR)pNtHeader); // extremely noisy @@ -1251,49 +1385,49 @@ BOOL TestPERequirements(PIMAGE_NT_HEADERS pNtHeader) } //else // DoOutputDebugString("TestPERequirements: OptionalHeader.Magic ok!: 0x%x (0x%x)", pNtHeader->OptionalHeader.Magic, (DWORD_PTR)pNtHeader); - + // Basic requirements - if + if ( - pNtHeader->FileHeader.Machine == 0 || - pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || + pNtHeader->FileHeader.Machine == 0 || + pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0 //|| //pNtHeader->OptionalHeader.FileAlignment == 0 - ) + ) { - //DoOutputDebugString("TestPERequirements: Basic requirements failure (0x%x).\n", (DWORD_PTR)pNtHeader); // very noisy + //DoOutputDebugString("TestPERequirements: Basic requirements failure (0x%x).\n", (DWORD_PTR)pNtHeader); // very noisy return FALSE; } - if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) + if (!(pNtHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) { DoOutputDebugString("TestPERequirements: Characteristics bad. (0x%x)", (DWORD_PTR)pNtHeader); return FALSE; } - if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) + if (pNtHeader->FileHeader.SizeOfOptionalHeader & (sizeof (ULONG_PTR) - 1)) { DoOutputDebugString("TestPERequirements: SizeOfOptionalHeader bad. (0x%x)", (DWORD_PTR)pNtHeader); return FALSE; } - - if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) + + if (((pNtHeader->OptionalHeader.FileAlignment-1) & pNtHeader->OptionalHeader.FileAlignment) != 0) { DoOutputDebugString("TestPERequirements: FileAlignment invalid. (0x%x)", (DWORD_PTR)pNtHeader); return FALSE; } - - if (pNtHeader->OptionalHeader.SectionAlignment < pNtHeader->OptionalHeader.FileAlignment) - { + + if (pNtHeader->OptionalHeader.SectionAlignment < pNtHeader->OptionalHeader.FileAlignment) + { DoOutputDebugString("TestPERequirements: FileAlignment greater than SectionAlignment.\n (0x%x)", (DWORD_PTR)pNtHeader); - return FALSE; - } + return FALSE; + } // To pass the above tests it should now be safe to assume it's a PE image return TRUE; - } - __except(EXCEPTION_EXECUTE_HANDLER) - { + } + __except(EXCEPTION_EXECUTE_HANDLER) + { DoOutputDebugString("TestPERequirements: Exception occured reading region at 0x%x\n", (DWORD_PTR)(pNtHeader)); return FALSE; } @@ -1306,14 +1440,14 @@ int IsDisguisedPEHeader(LPVOID Buffer) PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader = NULL; WORD* MachineProbe; - - __try - { + + __try + { pDosHeader = (PIMAGE_DOS_HEADER)Buffer; if (pDosHeader->e_lfanew && (ULONG)pDosHeader->e_lfanew < PE_HEADER_LIMIT && ((ULONG)pDosHeader->e_lfanew & 3) == 0) pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - + if (!pDosHeader->e_lfanew) { // In case the header until and including 'PE' has been zeroed @@ -1326,7 +1460,7 @@ int IsDisguisedPEHeader(LPVOID Buffer) break; } MachineProbe += sizeof(WORD); - } + } } if (pNtHeader && TestPERequirements(pNtHeader)) @@ -1346,17 +1480,17 @@ int IsDisguisedPEHeader(LPVOID Buffer) } } MachineProbe += sizeof(WORD); - } + } if (pNtHeader && TestPERequirements(pNtHeader)) - return 1; - } - __except(EXCEPTION_EXECUTE_HANDLER) - { + return 1; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { DoOutputDebugString("IsDisguisedPEHeader: Exception occured reading region at 0x%x\n", (DWORD_PTR)(Buffer)); return -1; } - + //DoOutputDebugString("IsDisguisedPEHeader: No PE image located\n (0x%x)", (DWORD_PTR)Buffer); return 0; } @@ -1367,17 +1501,17 @@ int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) { SIZE_T p; int RetVal; - + if (Size == 0) { DoOutputDebugString("ScanForDisguisedPE: Error, zero size given\n"); return 0; } - + for (p=0; p < Size - PE_HEADER_LIMIT; p++) // we want to stop short of the max look-ahead in IsDisguisedPEHeader { RetVal = IsDisguisedPEHeader((BYTE*)Buffer+p); - + if (!RetVal) continue; else if (RetVal == -1) @@ -1385,17 +1519,17 @@ int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset) DoOutputDebugString("ScanForDisguisedPE: Exception occured scanning buffer at 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); return 0; } - + if (Offset) { *Offset = (LPVOID)((BYTE*)Buffer+p); } - + DoOutputDebugString("ScanForDisguisedPE: PE image located at: 0x%x\n", (DWORD_PTR)((BYTE*)Buffer+p)); - + return 1; } - + DoOutputDebugString("ScanForDisguisedPE: No PE image located in range 0x%x-0x%x.\n", Buffer, (DWORD_PTR)Buffer + Size); return 0; } @@ -1407,20 +1541,20 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) PBYTE PEImage; PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader = NULL; - + BOOL RetVal = FALSE; LPVOID PEPointer = Buffer; - + DoOutputDebugString("DumpPEsInRange: Scanning range 0x%x - 0x%x.\n", Buffer, (BYTE*)Buffer + Size); while (ScanForDisguisedPE(PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), &PEPointer)) { pDosHeader = (PIMAGE_DOS_HEADER)PEPointer; - + if (*(WORD*)PEPointer != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) - { + { DoOutputDebugString("DumpPEsInRange: Disguised PE image (bad MZ and/or PE headers) at 0x%x.\n", PEPointer); - + // We want to fix the PE header in the dump (for e.g. disassembly etc) PEImage = (BYTE*)calloc(Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer), sizeof(PUCHAR)); memcpy(PEImage, PEPointer, Size - ((DWORD_PTR)PEPointer - (DWORD_PTR)Buffer)); @@ -1439,7 +1573,7 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) } MachineProbe += sizeof(WORD); } - + if (pNtHeader) pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); } @@ -1459,8 +1593,9 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) //break; } } + MachineProbe += sizeof(WORD); - + if (pNtHeader && (PUCHAR)pNtHeader == (PUCHAR)pDosHeader && pNtHeader->OptionalHeader.SizeOfHeaders) { SIZE_T HeaderShift = sizeof(IMAGE_DOS_HEADER); @@ -1471,14 +1606,16 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) pDosHeader->e_lfanew = (LONG)((PUCHAR)pNtHeader - (PUCHAR)pDosHeader); DoOutputDebugString("DumpPEsInRange: pNtHeader moved from 0x%x to 0x%x, e_lfanew 0x%x\n", pDosHeader, pNtHeader, pDosHeader->e_lfanew); } - } + } } - + *(WORD*)pDosHeader = IMAGE_DOS_SIGNATURE; *(DWORD*)((PUCHAR)pDosHeader + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; +#ifdef CAPE_INJECTION SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)pDosHeader); - +#endif + if (DumpImageInCurrentProcess((LPVOID)pDosHeader)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", pDosHeader); @@ -1488,12 +1625,12 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", pDosHeader); if (PEImage) - free(PEImage); + free(PEImage); } else { SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)PEPointer); - + if (DumpImageInCurrentProcess((LPVOID)PEPointer)) { DoOutputDebugString("DumpPEsInRange: Dumped PE image from 0x%x.\n", PEPointer); @@ -1502,10 +1639,10 @@ BOOL DumpPEsInRange(LPVOID Buffer, SIZE_T Size) else DoOutputDebugString("DumpPEsInRange: Failed to dump PE image from 0x%x.\n", PEPointer); } - + (BYTE*)PEPointer += PE_HEADER_LIMIT; } - + return RetVal; } @@ -1521,7 +1658,7 @@ int DumpMemory(LPVOID Buffer, SIZE_T Size) FullPathName = GetName(); hOutputFile = CreateFile(FullPathName, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); - + if (hOutputFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS) { DoOutputDebugString("DumpMemory: CAPE output filename exists already: %s", FullPathName); @@ -1533,35 +1670,35 @@ int DumpMemory(LPVOID Buffer, SIZE_T Size) { DoOutputErrorString("DumpMemory: Could not create CAPE output file"); free(FullPathName); - return 0; - } - + return 0; + } + dwBytesWritten = 0; - + DoOutputDebugString("DumpMemory: CAPE output file successfully created: %s", FullPathName); BufferCopy = (LPVOID)((BYTE*)malloc(Size)); - + if (BufferCopy == NULL) { DoOutputDebugString("DumpMemory: Failed to allocate memory for buffer copy.\n"); return FALSE; } - - __try - { + + __try + { memcpy(BufferCopy, Buffer, Size); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { + } + __except(EXCEPTION_EXECUTE_HANDLER) + { DoOutputDebugString("DumpMemory: Exception occured reading memory address 0x%x\n", Buffer); return 0; } - + if (FALSE == WriteFile(hOutputFile, BufferCopy, (DWORD)Size, &dwBytesWritten, NULL)) { DoOutputErrorString("DumpMemory: WriteFile error on CAPE output file"); - free(FullPathName); + free(FullPathName); free(BufferCopy); return 0; } @@ -1570,13 +1707,13 @@ int DumpMemory(LPVOID Buffer, SIZE_T Size) CapeMetaData->Address = Buffer; CapeMetaData->Size = Size; - + CapeOutputFile(FullPathName); - + // We can free the filename buffers - free(FullPathName); + free(FullPathName); free(BufferCopy); - + return 1; } @@ -1587,10 +1724,10 @@ BOOL DumpRegion(PVOID Address) MEMORY_BASIC_INFORMATION MemInfo; PVOID OriginalAllocationBase, OriginalBaseAddress, AddressOfPage; SIZE_T AllocationSize, OriginalRegionSize; - + if (!SystemInfo.dwPageSize) GetSystemInfo(&SystemInfo); - + if (!SystemInfo.dwPageSize) { DoOutputErrorString("DumpRegion: Failed to obtain system page size.\n"); @@ -1602,12 +1739,12 @@ BOOL DumpRegion(PVOID Address) DoOutputErrorString("DumpRegion: unable to query memory address 0x%x", Address); return 0; } - + OriginalAllocationBase = MemInfo.AllocationBase; OriginalBaseAddress = MemInfo.BaseAddress; OriginalRegionSize = MemInfo.RegionSize; AddressOfPage = OriginalAllocationBase; - + while (MemInfo.AllocationBase == OriginalAllocationBase) { (PUCHAR)AddressOfPage += SystemInfo.dwPageSize; @@ -1616,9 +1753,9 @@ BOOL DumpRegion(PVOID Address) { DoOutputErrorString("DumpRegion: unable to query memory page 0x%x", AddressOfPage); return 0; - } + } } - + AllocationSize = (SIZE_T)((DWORD_PTR)AddressOfPage - (DWORD_PTR)OriginalAllocationBase); SetCapeMetaData(EXTRACTION_SHELLCODE, 0, NULL, (PVOID)OriginalAllocationBase); @@ -1634,9 +1771,9 @@ BOOL DumpRegion(PVOID Address) else { DoOutputDebugString("DumpRegion: Failed to dump entire allocation from 0x%p size 0x%x.\n", OriginalAllocationBase, AllocationSize); - + SetCapeMetaData(EXTRACTION_SHELLCODE, 0, NULL, (PVOID)OriginalBaseAddress); - + if (DumpMemory(OriginalBaseAddress, OriginalRegionSize)) { if (address_is_in_stack(Address)) @@ -1703,30 +1840,34 @@ int DumpModuleInCurrentProcess(LPVOID ModuleBase) DoOutputDebugString("DumpModuleInCurrentProcess: Not a valid image at 0x%p - cannot dump.\n", ModuleBase); return 0; } - + pDosHeader = (PIMAGE_DOS_HEADER)ModuleBase; - + if (*(WORD*)ModuleBase != IMAGE_DOS_SIGNATURE || (*(DWORD*)((BYTE*)pDosHeader + pDosHeader->e_lfanew) != IMAGE_NT_SIGNATURE)) - { + { PBYTE PEImage; SIZE_T ImageSize; - + DoOutputDebugString("DumpModuleInCurrentProcess: Disguised PE image (bad MZ and/or PE headers) at 0x%p.\n", ModuleBase); - + // We want to fix the PE header in the dump (for e.g. disassembly etc) ImageSize = GetPESize(ModuleBase); PEImage = (BYTE*)malloc(ImageSize); memcpy(PEImage, ModuleBase, ImageSize); pDosHeader = (PIMAGE_DOS_HEADER)PEImage; - + *(WORD*)PEImage = IMAGE_DOS_SIGNATURE; *(DWORD*)(PEImage + pDosHeader->e_lfanew) = IMAGE_NT_SIGNATURE; - + ModuleBase = PEImage; } +#ifdef CAPE_INJECTION + SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)ModuleBase); +#else SetCapeMetaData(EXTRACTION_PE, 0, NULL, (PVOID)ModuleBase); - +#endif + if (DumpCount < DUMP_MAX && ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ModuleBase, 0)) { DumpCount++; @@ -1742,7 +1883,7 @@ int DumpImageInCurrentProcess(LPVOID ImageBase) { PIMAGE_DOS_HEADER pDosHeader; PIMAGE_NT_HEADERS pNtHeader; - + pDosHeader = (PIMAGE_DOS_HEADER)ImageBase; if (DumpCount >= DUMP_MAX) @@ -1756,56 +1897,56 @@ int DumpImageInCurrentProcess(LPVOID ImageBase) DoOutputDebugString("DumpImageInCurrentProcess: No DOS signature in header.\n"); return 0; } - + if (!pDosHeader->e_lfanew || pDosHeader->e_lfanew > PE_HEADER_LIMIT) { DoOutputDebugString("DumpImageInCurrentProcess: bad e_lfanew.\n"); - return 0; + return 0; } - + pNtHeader = (PIMAGE_NT_HEADERS)((PUCHAR)pDosHeader + (ULONG)pDosHeader->e_lfanew); - - if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) + + if (pNtHeader->Signature != IMAGE_NT_SIGNATURE) { // No 'PE' header DoOutputDebugString("DumpImageInCurrentProcess: Invalid PE signature in header.\n"); return 0; } - - if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) + + if ((pNtHeader->FileHeader.Machine == 0) || (pNtHeader->FileHeader.SizeOfOptionalHeader == 0 || pNtHeader->OptionalHeader.SizeOfHeaders == 0)) { // Basic requirements DoOutputDebugString("DumpImageInCurrentProcess: PE image invalid.\n"); return 0; } - + if (IsPeImageVirtual(ImageBase) == FALSE) { DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump 'raw' PE image.\n"); - + if (ScyllaDumpPE((DWORD_PTR)ImageBase)) { DumpCount++; - return 1; + return 1; } else { // failed to dump pe image DoOutputDebugString("DumpImageInCurrentProcess: Failed to dump 'raw' PE image.\n"); - return 0; + return 0; } } DoOutputDebugString("DumpImageInCurrentProcess: Attempting to dump virtual PE image.\n"); - + if (!ScyllaDumpProcess(GetCurrentProcess(), (DWORD_PTR)ImageBase, 0)) { DoOutputDebugString("DumpImageInCurrentProcess: Failed to dump PE as virtual image.\n"); - return 0; + return 0; } DumpCount++; - return 1; + return 1; } //************************************************************************************** @@ -1826,7 +1967,7 @@ int DumpPE(LPVOID Buffer) //************************************************************************************** { SetCapeMetaData(INJECTION_PE, 0, NULL, (PVOID)Buffer); - + if (DumpCount < DUMP_MAX && ScyllaDumpPE((DWORD_PTR)Buffer)) { DumpCount++; @@ -1872,10 +2013,10 @@ void init_CAPE() // #ifndef STANDALONE CapeMetaData = (PCAPEMETADATA)malloc(sizeof(CAPEMETADATA)); - CapeMetaData->Pid = GetCurrentProcessId(); + CapeMetaData->Pid = GetCurrentProcessId(); CapeMetaData->ProcessPath = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_process_path, (int)wcslen(our_process_path)+1, CapeMetaData->ProcessPath, MAX_PATH, NULL, NULL); - + CommandLine = (char*)malloc(MAX_PATH); WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)our_commandline, (int)wcslen(our_commandline)+1, CommandLine, MAX_PATH, NULL, NULL); @@ -1909,5 +2050,6 @@ void init_CAPE() #endif DoOutputDebugString("Commandline: %s.\n", CommandLine); + return; } diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 4449577..7f2e7e4 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -40,6 +40,7 @@ int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); int DumpImageInCurrentProcess(LPVOID ImageBase); void DumpSectionViewsForPid(DWORD Pid); +void DumpSectionViewsForHandle(HANDLE SectionHandle); SYSTEM_INFO SystemInfo; PVOID CallingModule; @@ -50,6 +51,7 @@ typedef struct InjectionSectionView PVOID LocalView; SIZE_T ViewSize; int TargetProcessId; + wchar_t *SectionName; struct InjectionSectionView *NextSectionView; } INJECTIONSECTIONVIEW, *PINJECTIONSECTIONVIEW; @@ -78,7 +80,9 @@ typedef struct InjectionInfo struct InjectionInfo *InjectionInfoList; PINJECTIONINFO GetInjectionInfo(DWORD ProcessId); +PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle); PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId); +BOOL DropInjectionInfo(HANDLE ProcessHandle); struct InjectionSectionView *SectionViewList; diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 44990bc..83bf449 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -53,7 +53,7 @@ void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context) #ifdef _WIN64 if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) CurrentInjectionInfo->EntryPoint = Context->Rcx - CurrentInjectionInfo->ImageBase; // rcx holds ep on 64-bit - + if (Context->Rip == (DWORD_PTR)GetProcAddress(GetModuleHandle("ntdll"), "NtMapViewOfSection")) DoOutputDebugString("SetThreadContextHandler: Hollow process entry point set to NtMapViewOfSection (process %d).\n", Pid); else @@ -79,16 +79,16 @@ void ResumeThreadHandler(DWORD Pid) DoOutputDebugString("ResumeThreadHandler: CurrentInjectionInfo 0x%x (Pid %d).\n", CurrentInjectionInfo, Pid); return; } - + if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { CapeMetaData->DumpType = INJECTION_PE; CapeMetaData->TargetPid = Pid; - + DoOutputDebugString("ResumeThreadHandler: Dumping hollowed process %d, image base 0x%p.\n", Pid, CurrentInjectionInfo->ImageBase); - + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); - + if (CurrentInjectionInfo->ImageDumped) { DoOutputDebugString("ResumeThreadHandler: Dumped PE image from buffer.\n"); @@ -96,24 +96,24 @@ void ResumeThreadHandler(DWORD Pid) else DoOutputDebugString("ResumeThreadHandler: Failed to dump PE image from buffer.\n"); } - + DumpSectionViewsForPid(Pid); } void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROCESS_INFORMATION lpProcessInformation) { - WCHAR TargetProcess[MAX_PATH]; - struct InjectionInfo *CurrentInjectionInfo; + WCHAR TargetProcess[MAX_PATH]; + struct InjectionInfo *CurrentInjectionInfo; // Create 'injection info' struct for the newly created process CurrentInjectionInfo = CreateInjectionInfo(lpProcessInformation->dwProcessId); - + if (CurrentInjectionInfo == NULL) { DoOutputDebugString("CreateProcessHandler: Failed to create injection info for new process %d, ImageBase: 0x%p", lpProcessInformation->dwProcessId, CurrentInjectionInfo->ImageBase); return; } - + CurrentInjectionInfo->ProcessHandle = lpProcessInformation->hProcess; CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(lpProcessInformation->hProcess); CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; @@ -129,20 +129,51 @@ void CreateProcessHandler(LPWSTR lpApplicationName, LPWSTR lpCommandLine, LPPROC DoOutputDebugString("CreateProcessHandler: using lpCommandLine: %ws.\n", lpCommandLine); if (*lpCommandLine == L'\"') wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine+1, (rsize_t)((wcschr(lpCommandLine+1, '\"') - lpCommandLine)-1)); - else + else { if (wcschr(lpCommandLine, ' ')) wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, (rsize_t)((wcschr(lpCommandLine, ' ') - lpCommandLine)+1)); - else + else wcsncpy_s(TargetProcess, MAX_PATH, lpCommandLine, wcslen(lpCommandLine)+1); } } WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, (LPCWSTR)TargetProcess, (int)wcslen(TargetProcess)+1, CapeMetaData->TargetProcess, MAX_PATH, NULL, NULL); - + DoOutputDebugString("CreateProcessHandler: Injection info set for new process %d, ImageBase: 0x%p", CurrentInjectionInfo->ProcessId, CurrentInjectionInfo->ImageBase); } +void CreateRemoteThreadHandler(DWORD Pid) +{ + struct InjectionInfo *CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!CurrentInjectionInfo) + { + DoOutputDebugString("CreateRemoteThreadHandler: CurrentInjectionInfo 0x%x (Pid %d).\n", CurrentInjectionInfo, Pid); + return; + } + + //if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) + if (CurrentInjectionInfo->ImageDumped == FALSE) + { + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + + DoOutputDebugString("CreateRemoteThreadHandler: Dumping hollowed process %d, image base 0x%p.\n", Pid, CurrentInjectionInfo->ImageBase); + + CurrentInjectionInfo->ImageDumped = DumpProcess(CurrentInjectionInfo->ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); + + if (CurrentInjectionInfo->ImageDumped) + { + DoOutputDebugString("CreateRemoteThreadHandler: Dumped PE image from buffer.\n"); + } + else + DoOutputDebugString("CreateRemoteThreadHandler: Failed to dump PE image from buffer.\n"); + } + + DumpSectionViewsForPid(Pid); +} + void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid) { struct InjectionInfo *CurrentInjectionInfo; @@ -151,13 +182,13 @@ void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid) unsigned int PathLength; CurrentInjectionInfo = GetInjectionInfo(Pid); - + if (CurrentInjectionInfo == NULL) { // First call for this process, create new info CurrentInjectionInfo = CreateInjectionInfo(Pid); - - DoOutputDebugString("OpenProcessHandler: Injection info created for Pid %d.\n", Pid); - + + DoOutputDebugString("OpenProcessHandler: Injection info created for Pid %d, handle 0x%x.\n", Pid, ProcessHandle); + if (CurrentInjectionInfo == NULL) { DoOutputDebugString("OpenProcessHandler: Error - cannot create new injection info.\n"); @@ -181,8 +212,8 @@ void OpenProcessHandler(HANDLE ProcessHandle, DWORD Pid) DoOutputErrorString("OpenProcessHandler: Error obtaining target process name"); _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); } - else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) - DoOutputErrorString("OpenProcessHandler: Error translating target process path"); + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("OpenProcessHandler: Error translating target process path"); } } else if (CurrentInjectionInfo->ImageBase == (DWORD_PTR)NULL) @@ -199,17 +230,17 @@ void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid) struct InjectionInfo *CurrentInjectionInfo; CurrentInjectionInfo = GetInjectionInfo(Pid); - + if (CurrentInjectionInfo) { if (CurrentInjectionInfo->ImageBase && CurrentInjectionInfo->WriteDetected && CurrentInjectionInfo->ImageDumped == FALSE) { SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); - + DoOutputDebugString("ResumeProcessHandler: Dumping hollowed process %d, image base 0x%p.\n", Pid, CurrentInjectionInfo->ImageBase); - + CurrentInjectionInfo->ImageDumped = DumpProcess(ProcessHandle, (PVOID)CurrentInjectionInfo->ImageBase); - + if (CurrentInjectionInfo->ImageDumped) { DoOutputDebugString("ResumeProcessHandler: Dumped PE image from buffer.\n"); @@ -225,23 +256,33 @@ void ResumeProcessHandler(HANDLE ProcessHandle, DWORD Pid) void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID BaseAddress, SIZE_T ViewSize) { struct InjectionInfo *CurrentInjectionInfo; - struct InjectionSectionView *CurrentSectionViewInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; char DevicePath[MAX_PATH]; unsigned int PathLength; DWORD BufferSize = MAX_PATH; - + DWORD Pid = pid_from_process_handle(ProcessHandle); - - CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!Pid) + { + DoOutputErrorString("MapSectionViewHandler: Failed to obtain pid from process handle 0x%x", ProcessHandle); + CurrentInjectionInfo = GetInjectionInfoFromHandle(ProcessHandle); + Pid = CurrentInjectionInfo->ProcessId; + } + else + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!Pid) + DoOutputDebugString("MapSectionViewHandler: Failed to find injection info pid from process handle 0x%x.\n", ProcessHandle); if (Pid == GetCurrentProcessId()) { - PINJECTIONSECTIONVIEW CurrentSectionView = GetSectionView(SectionHandle); - + CurrentSectionView = GetSectionView(SectionHandle); + if (!CurrentSectionView) { - AddSectionView(SectionHandle, BaseAddress, ViewSize); - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%p to global list.\n", SectionHandle, BaseAddress); + CurrentSectionView = AddSectionView(SectionHandle, BaseAddress, ViewSize); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%p to global list (%ws).\n", SectionHandle, BaseAddress, CurrentSectionView->SectionName); } else { @@ -249,28 +290,28 @@ void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID Bas { CurrentSectionView->LocalView = BaseAddress; CurrentSectionView->ViewSize = ViewSize; - DoOutputDebugString("MapSectionViewHandler: Updated local view to 0x%p for section view with handle 0x%x.\n", BaseAddress, SectionHandle); + DoOutputDebugString("MapSectionViewHandler: Updated local view to 0x%p for section view with handle 0x%x (%ws).\n", BaseAddress, SectionHandle, CurrentSectionView->SectionName); } } } else if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) { - CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, ViewSize); + CurrentSectionView = AddSectionView(SectionHandle, BaseAddress, ViewSize); - if (CurrentSectionViewInfo) + if (CurrentSectionView) { - CurrentSectionViewInfo->TargetProcessId = Pid; - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d.\n", SectionHandle, Pid); + CurrentSectionView->TargetProcessId = Pid; + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d (%ws).\n", SectionHandle, Pid, CurrentSectionView->SectionName); } else { - DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, Pid); + DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d (%ws).\n", SectionHandle, Pid, CurrentSectionView->SectionName); } - } + } else if (!CurrentInjectionInfo && Pid != GetCurrentProcessId()) { CurrentInjectionInfo = CreateInjectionInfo(Pid); - + if (CurrentInjectionInfo == NULL) { DoOutputDebugString("MapSectionViewHandler: Cannot create new injection info - error.\n"); @@ -297,23 +338,23 @@ void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID Bas } else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) DoOutputErrorString("MapSectionViewHandler: Error translating target process path"); - - CurrentSectionViewInfo = AddSectionView(SectionHandle, BaseAddress, ViewSize); - if (CurrentSectionViewInfo) + CurrentSectionView = AddSectionView(SectionHandle, BaseAddress, ViewSize); + + if (CurrentSectionView) { - CurrentSectionViewInfo->TargetProcessId = Pid; - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d.\n", SectionHandle, Pid); + CurrentSectionView->TargetProcessId = Pid; + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x to target process %d (%ws).\n", SectionHandle, Pid, CurrentSectionView->SectionName); } else - DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d.\n", SectionHandle, Pid); + DoOutputDebugString("MapSectionViewHandler: Error, failed to add section view with handle 0x%x and target process %d (%ws).\n", SectionHandle, Pid, CurrentSectionView->SectionName); } } } void UnmapSectionViewHandler(PVOID BaseAddress) { - PINJECTIONSECTIONVIEW CurrentSectionView; + PINJECTIONSECTIONVIEW CurrentSectionView; CurrentSectionView = SectionViewList; @@ -342,9 +383,9 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer DWORD BufferSize = MAX_PATH; Pid = pid_from_process_handle(ProcessHandle); - + CurrentInjectionInfo = GetInjectionInfo(Pid); - + if (NumberOfBytesWritten == 0) return; @@ -385,16 +426,16 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer return; CurrentInjectionInfo->WriteDetected = TRUE; - + // Check if we have a valid DOS and PE header at the beginning of Buffer if (IsDisguisedPEHeader((PVOID)Buffer)) { pDosHeader = (PIMAGE_DOS_HEADER)((char*)Buffer); - + pNtHeader = (PIMAGE_NT_HEADERS)((char*)Buffer + pDosHeader->e_lfanew); - + CurrentInjectionInfo->ImageBase = (DWORD_PTR)BaseAddress; - + DoOutputDebugString("WriteMemoryHandler: Executable binary injected into process %d (ImageBase 0x%x)\n", Pid, CurrentInjectionInfo->ImageBase); if (CurrentInjectionInfo->ImageDumped == FALSE) @@ -402,7 +443,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer SetCapeMetaData(INJECTION_PE, Pid, ProcessHandle, NULL); CurrentInjectionInfo->ImageDumped = DumpImageInCurrentProcess((PVOID)Buffer); - + if (CurrentInjectionInfo->ImageDumped) { CurrentInjectionInfo->BufferBase = (LPVOID)Buffer; @@ -412,23 +453,23 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer else { DoOutputDebugString("WriteMemoryHandler: Failed to dump PE image from buffer, attempting raw dump.\n"); - + CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = Pid; if (DumpMemory((LPVOID)Buffer, NumberOfBytesWritten)) DoOutputDebugString("WriteMemoryHandler: Dumped malformed PE image from buffer."); else - DoOutputDebugString("WriteMemoryHandler: Failed to dump malformed PE image from buffer."); + DoOutputDebugString("WriteMemoryHandler: Failed to dump malformed PE image from buffer."); } - } + } } else - { + { if (NumberOfBytesWritten > 0x10) // We assign some lower limit { - if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && + if (CurrentInjectionInfo->BufferBase && Buffer > CurrentInjectionInfo->BufferBase && Buffer < (LPVOID)((UINT_PTR)CurrentInjectionInfo->BufferBase + CurrentInjectionInfo->BufferSizeOfImage) && CurrentInjectionInfo->ImageDumped == TRUE) - { + { // Looks like a previously dumped PE image is being written a section at a time to the target process. // We don't want to dump these writes. DoOutputDebugString("WriteMemoryHandler: injection of section of PE image which has already been dumped.\n"); @@ -436,7 +477,7 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer else { DoOutputDebugString("WriteMemoryHandler: shellcode at 0x%p (size 0x%x) injected into process %d.\n", Buffer, NumberOfBytesWritten, Pid); - + // dump injected code/data CapeMetaData->DumpType = INJECTION_SHELLCODE; CapeMetaData->TargetPid = Pid; diff --git a/hook_misc.c b/hook_misc.c index 07e8acd..f223898 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -362,6 +362,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtClose, if(NT_SUCCESS(ret)) { remove_file_from_log_tracking(Handle); file_close(Handle); +#ifdef CAPE_INJECTION + DumpSectionViewsForHandle(Handle); +#endif } return ret; } diff --git a/hook_thread.c b/hook_thread.c index b528f75..d36eba9 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -33,6 +33,7 @@ extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void GetThreadContextHandler(DWORD Pid, LPCONTEXT Context); extern void SetThreadContextHandler(DWORD Pid, const CONTEXT *Context); extern void ResumeThreadHandler(DWORD Pid); +extern void CreateRemoteThreadHandler(DWORD Pid); #endif static lookup_t g_ignored_threads; @@ -437,8 +438,12 @@ HOOKDEF(HANDLE, WINAPI, CreateRemoteThread, lpThreadId); if (ret != NULL) { - if (pid != GetCurrentProcessId()) + if (pid != GetCurrentProcessId()) { pipe("PROCESS:%d:%d,%d", is_suspended(pid, *lpThreadId), pid, *lpThreadId); +#ifdef CAPE_INJECTION + CreateRemoteThreadHandler(pid); +#endif + } else if (DEBUGGER_ENABLED && !called_by_hook()) { DoOutputDebugString("CreateRemoteThread: Initialising breakpoints for (local) thread %d.\n", *lpThreadId); InitNewThreadBreakpoints(*lpThreadId); diff --git a/misc.c b/misc.c index 769f1e7..af0049e 100644 --- a/misc.c +++ b/misc.c @@ -516,7 +516,7 @@ DWORD pid_from_process_handle(HANDLE process_handle) duped = DuplicateHandle(GetCurrentProcess(), process_handle, GetCurrentProcess(), &dup_handle, PROCESS_QUERY_INFORMATION, FALSE, 0); - if(pNtQueryInformationProcess(dup_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) + if (pNtQueryInformationProcess(dup_handle, 0, &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi)) PID = (DWORD)pbi.UniqueProcessId; if (duped) From cab5588c12161f447ac001f2aa64fb5a4a8318f9 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Nov 2018 11:36:29 +0000 Subject: [PATCH 38/39] Fix a bug introduced recently with DumpSectionViewsForHandle. --- CAPE/CAPE.c | 15 ++++++++++++--- CAPE/Injection.c | 2 ++ hook_thread.c | 9 ++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 470065b..79a5218 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -884,7 +884,13 @@ void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) if (!SectionView->TargetProcessId) { - DoOutputDebugString("DumpSectionView: Section view has no target process - error.\n"); + DoOutputDebugString("DumpSectionView: Section with local view 0x%p has no target process - error.\n", SectionView->LocalView); + return; + } + + if (!SectionView->ViewSize) + { + DoOutputDebugString("DumpSectionView: Section with local view 0x%p has zero size - error.\n", SectionView->LocalView); return; } @@ -935,7 +941,7 @@ void DumpSectionViewsForHandle(HANDLE SectionHandle) path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) { - DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + DoOutputDebugString("DumpSectionViewsForHandle: New section handle for existing named section %ws.\n", SectionHandle, SectionName); free(SectionName); break; } @@ -945,8 +951,11 @@ void DumpSectionViewsForHandle(HANDLE SectionHandle) CurrentSectionView = CurrentSectionView->NextSectionView; } - if (CurrentSectionView) + if (CurrentSectionView && CurrentSectionView->TargetProcessId) + { + DoOutputDebugString("DumpSectionViewsForHandle: Dumping section view at 0x%p for handle 0x%x (target process %d).\n", CurrentSectionView->LocalView, SectionHandle, CurrentSectionView->TargetProcessId); DumpSectionView(CurrentSectionView); + } return; } diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 83bf449..61e6587 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -97,6 +97,8 @@ void ResumeThreadHandler(DWORD Pid) DoOutputDebugString("ResumeThreadHandler: Failed to dump PE image from buffer.\n"); } + DoOutputDebugString("ResumeThreadHandler: Dumping section view for process %d.\n", Pid); + DumpSectionViewsForPid(Pid); } diff --git a/hook_thread.c b/hook_thread.c index d36eba9..ed5a8f7 100644 --- a/hook_thread.c +++ b/hook_thread.c @@ -271,7 +271,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtGetContextThread, LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); #ifdef CAPE_INJECTION DWORD pid = pid_from_thread_handle(ThreadHandle); - GetThreadContextHandler(pid, Context); + if (pid != GetCurrentProcessId()) + GetThreadContextHandler(pid, Context); #endif return ret; } @@ -295,7 +296,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetContextThread, else LOQ_ntstatus("threading", "p", "ThreadHandle", ThreadHandle); #ifdef CAPE_INJECTION - SetThreadContextHandler(pid, Context); + if (pid != GetCurrentProcessId()) + SetThreadContextHandler(pid, Context); #endif if (pid != GetCurrentProcessId()) pipe("PROCESS:%d:%d,%d", is_suspended(pid, tid), pid, tid); @@ -337,7 +339,8 @@ HOOKDEF(NTSTATUS, WINAPI, NtResumeThread, NTSTATUS ret; ENSURE_ULONG(SuspendCount); #ifdef CAPE_INJECTION - ResumeThreadHandler(pid); + if (pid != GetCurrentProcessId()) + ResumeThreadHandler(pid); #endif pipe("RESUME:%d,%d", pid, tid); From c4e611905506d167cfe8a65b314f3ac22cfb66c2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Dec 2018 17:57:52 +0000 Subject: [PATCH 39/39] Improve handling of injection tricks with unmapped section views and duplicated handles. --- .gitignore | 3 +- CAPE/CAPE.c | 472 ------------------------------------ CAPE/CAPE.h | 43 ---- CAPE/Injection.c | 606 ++++++++++++++++++++++++++++++++++++++++++++++- CAPE/Injection.h | 67 ++++++ hook_misc.c | 13 +- misc.c | 4 +- misc.h | 11 + 8 files changed, 698 insertions(+), 521 deletions(-) create mode 100644 CAPE/Injection.h diff --git a/.gitignore b/.gitignore index ffc88da..418e99b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ Release tests/logging-test.* *.suo *.opendb -*.VC.db \ No newline at end of file +*.VC.db +.vs/* diff --git a/CAPE/CAPE.c b/CAPE/CAPE.c index 79a5218..1145a39 100644 --- a/CAPE/CAPE.c +++ b/CAPE/CAPE.c @@ -20,7 +20,6 @@ along with this program.If not, see . #define MAX_PRETRAMP_SIZE 320 #define MAX_TRAMP_SIZE 128 -#define MAX_UNICODE_PATH 32768 #define BUFSIZE 1024 // For hashing #define DUMP_MAX 100 @@ -489,477 +488,6 @@ BOOL MapFile(HANDLE hFile, unsigned char **Buffer, DWORD* FileSize) return TRUE; } -//************************************************************************************** -PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) -//************************************************************************************** -{ - DWORD CurrentProcessId; - - PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; - while (CurrentInjectionInfo) - { - CurrentProcessId = CurrentInjectionInfo->ProcessId; - - if (CurrentProcessId == ProcessId) - return CurrentInjectionInfo; - else - CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - } - - return NULL; -} - -//************************************************************************************** -PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle) -//************************************************************************************** -{ - HANDLE CurrentProcessHandle; - - PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; - while (CurrentInjectionInfo) - { - CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; - - if (CurrentProcessHandle == ProcessHandle) - return CurrentInjectionInfo; - else - CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - } - - return NULL; -} - -//************************************************************************************** -PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) -//************************************************************************************** -{ - PINJECTIONINFO CurrentInjectionInfo, PreviousInjectionInfo; - - PreviousInjectionInfo = NULL; - - if (InjectionInfoList == NULL) - { - InjectionInfoList = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); - - if (InjectionInfoList == NULL) - { - DoOutputDebugString("CreateInjectionInfo: failed to allocate memory for initial injection info list.\n"); - return NULL; - } - - memset(InjectionInfoList, 0, sizeof(struct InjectionInfo)); - - InjectionInfoList->ProcessId = ProcessId; - } - - CurrentInjectionInfo = InjectionInfoList; - - while (CurrentInjectionInfo) - { - if ((CurrentInjectionInfo->ProcessId) == ProcessId) - break; - - PreviousInjectionInfo = CurrentInjectionInfo; - CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - } - - if (!CurrentInjectionInfo) - { - // We haven't found it in the linked list, so create a new one - CurrentInjectionInfo = PreviousInjectionInfo; - - CurrentInjectionInfo->NextInjectionInfo = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); - - if (CurrentInjectionInfo->NextInjectionInfo == NULL) - { - DoOutputDebugString("CreateInjectionInfo: Failed to allocate new thread breakpoints.\n"); - return NULL; - } - - memset(CurrentInjectionInfo->NextInjectionInfo, 0, sizeof(struct InjectionInfo)); - - CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - - CurrentInjectionInfo->ProcessId = ProcessId; - } - - return CurrentInjectionInfo; -} - -//************************************************************************************** -BOOL DropInjectionInfo(HANDLE ProcessHandle) -//************************************************************************************** -{ - HANDLE CurrentProcessHandle; - PINJECTIONINFO PreviousInjectionInfo, CurrentInjectionInfo = InjectionInfoList; - - PreviousInjectionInfo = NULL; - - while (CurrentInjectionInfo) - { - CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; - - if (CurrentProcessHandle == ProcessHandle) - { - // Unlink this from the list and free the memory - if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo) - { - PreviousInjectionInfo->NextInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d.\n", CurrentInjectionInfo->ProcessId); - } - else if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo == NULL) - { - PreviousInjectionInfo->NextInjectionInfo = NULL; - DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d from the end of the section view list.\n", CurrentInjectionInfo->ProcessId); - } - else if (!PreviousInjectionInfo) - { - InjectionInfoList = NULL; - DoOutputDebugString("DropInjectionInfo: removed the head of the injection info list for pid %d.\n", CurrentInjectionInfo->ProcessId); - } - - free(CurrentInjectionInfo); - - return TRUE; - } - - PreviousInjectionInfo = CurrentInjectionInfo; - CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; - } - - return FALSE; -} - -//************************************************************************************** -PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) -//************************************************************************************** -{ - PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - wchar_t *SectionName; - - if (CurrentSectionView->SectionHandle == SectionHandle) - return CurrentSectionView; - - SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); - - if (SectionName) - { - path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); - if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) - { - DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); - free(SectionName); - return CurrentSectionView; - } - free(SectionName); - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } - - return NULL; -} - -//************************************************************************************** -PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize) -//************************************************************************************** -{ - PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; - - PreviousSectionView = NULL; - - if (SectionViewList == NULL) - { - SectionViewList = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); - - if (SectionViewList == NULL) - { - DoOutputDebugString("AddSectionView: failed to allocate memory for initial section view list.\n"); - return NULL; - } - - memset(SectionViewList, 0, sizeof(struct InjectionSectionView)); - - SectionViewList->SectionHandle = SectionHandle; - SectionViewList->LocalView = LocalView; - SectionViewList->ViewSize = ViewSize; - SectionViewList->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); - if (SectionViewList->SectionName) - path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); - } - - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - wchar_t *SectionName; - - if ((CurrentSectionView->SectionHandle) == SectionHandle) - break; - - SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); - if (SectionName) - { - path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); - if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) - { - DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); - free(SectionName); - break; - } - free(SectionName); - } - - PreviousSectionView = CurrentSectionView; - CurrentSectionView = CurrentSectionView->NextSectionView; - } - - if (!CurrentSectionView) - { - // We haven't found it in the linked list, so create a new one - CurrentSectionView = PreviousSectionView; - - CurrentSectionView->NextSectionView = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); - - if (CurrentSectionView->NextSectionView == NULL) - { - DoOutputDebugString("CreateSectionView: Failed to allocate new injection sectionview structure.\n"); - return NULL; - } - - memset(CurrentSectionView->NextSectionView, 0, sizeof(struct InjectionSectionView)); - - CurrentSectionView = CurrentSectionView->NextSectionView; - CurrentSectionView->SectionHandle = SectionHandle; - CurrentSectionView->LocalView = LocalView; - CurrentSectionView->ViewSize = ViewSize; - CurrentSectionView->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); - path_from_handle(SectionHandle, CurrentSectionView->SectionName, MAX_UNICODE_PATH); - } - - return CurrentSectionView; -} - -//************************************************************************************** -BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) -//************************************************************************************** -{ - PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; - - PreviousSectionView = NULL; - - if (SectionViewList == NULL) - { - DoOutputDebugString("DropSectionView: failed to obtain initial section view list.\n"); - return FALSE; - } - - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - if (CurrentSectionView == SectionView) - { - // Unlink this from the list and free the memory - if (PreviousSectionView && CurrentSectionView->NextSectionView) - { - PreviousSectionView->NextSectionView = CurrentSectionView->NextSectionView; - DoOutputDebugString("DropSectionView: removed a view from section view list.\n"); - } - else if (PreviousSectionView && CurrentSectionView->NextSectionView == NULL) - { - PreviousSectionView->NextSectionView = NULL; - DoOutputDebugString("DropSectionView: removed the view from the end of the section view list.\n"); - } - else if (!PreviousSectionView) - { - SectionViewList = NULL; - DoOutputDebugString("DropSectionView: removed the head of the section view list.\n"); - } - - free(CurrentSectionView); - - return TRUE; - } - - PreviousSectionView = CurrentSectionView; - CurrentSectionView = CurrentSectionView->NextSectionView; - } - - return FALSE; -} - -//************************************************************************************** -void DumpSectionViewsForPid(DWORD Pid) -//************************************************************************************** -{ - struct InjectionInfo *CurrentInjectionInfo; - PINJECTIONSECTIONVIEW CurrentSectionView; - DWORD BufferSize = MAX_PATH; - LPVOID PEPointer = NULL; - BOOL Dumped = FALSE; - - CurrentInjectionInfo = GetInjectionInfo(Pid); - - if (CurrentInjectionInfo == NULL) - { - DoOutputDebugString("DumpSectionViewsForPid: No injection info for pid %d.\n", Pid); - return; - } - - CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - if (CurrentSectionView->TargetProcessId == Pid && CurrentSectionView->LocalView) - { - DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d, local address 0x%p.\n", Pid); - - PEPointer = CurrentSectionView->LocalView; - - while (ScanForDisguisedPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); - - CapeMetaData->DumpType = INJECTION_PE; - CapeMetaData->TargetPid = Pid; - CapeMetaData->Address = PEPointer; - - if (DumpImageInCurrentProcess(PEPointer)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); - - ((BYTE*)PEPointer)++; - } - - if (Dumped == FALSE) - { - DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = Pid; - - if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) - { - DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); - } - } - - //DropSectionView(CurrentSectionView); - - CurrentSectionView = CurrentSectionView->NextSectionView; - } - - if (Dumped == FALSE) - DoOutputDebugString("DumpSectionViewsForPid: no shared section views found for pid %d.\n", Pid); - - return; -} - -//************************************************************************************** -void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) -//************************************************************************************** -{ - DWORD BufferSize = MAX_PATH; - LPVOID PEPointer = NULL; - BOOL Dumped = FALSE; - - if (!SectionView->LocalView) - { - DoOutputDebugString("DumpSectionView: Section view local view address not set.\n"); - return; - } - - if (!SectionView->TargetProcessId) - { - DoOutputDebugString("DumpSectionView: Section with local view 0x%p has no target process - error.\n", SectionView->LocalView); - return; - } - - if (!SectionView->ViewSize) - { - DoOutputDebugString("DumpSectionView: Section with local view 0x%p has zero size - error.\n", SectionView->LocalView); - return; - } - - Dumped = DumpPEsInRange(SectionView->LocalView, SectionView->ViewSize); - - if (Dumped) - DoOutputDebugString("DumpSectionView: Dumped PE image from shared section view, local address 0x%p.\n", SectionView->LocalView); - else - { - DoOutputDebugString("DumpSectionView: no PE file found in shared section view, attempting raw dump.\n"); - - CapeMetaData->DumpType = INJECTION_SHELLCODE; - - CapeMetaData->TargetPid = SectionView->TargetProcessId; - - if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) - { - DoOutputDebugString("DumpSectionView: Dumped shared section view."); - Dumped = TRUE; - } - else - DoOutputDebugString("DumpSectionView: Failed to dump shared section view."); - } - - if (Dumped == TRUE) - DropSectionView(SectionView); - - return; -} - -//************************************************************************************** -void DumpSectionViewsForHandle(HANDLE SectionHandle) -//************************************************************************************** -{ - PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; - - while (CurrentSectionView) - { - wchar_t *SectionName; - - if (CurrentSectionView->SectionHandle == SectionHandle) - break; - - SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); - - if (SectionName) - { - path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); - if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) - { - DoOutputDebugString("DumpSectionViewsForHandle: New section handle for existing named section %ws.\n", SectionHandle, SectionName); - free(SectionName); - break; - } - free(SectionName); - } - - CurrentSectionView = CurrentSectionView->NextSectionView; - } - - if (CurrentSectionView && CurrentSectionView->TargetProcessId) - { - DoOutputDebugString("DumpSectionViewsForHandle: Dumping section view at 0x%p for handle 0x%x (target process %d).\n", CurrentSectionView->LocalView, SectionHandle, CurrentSectionView->TargetProcessId); - DumpSectionView(CurrentSectionView); - } - - return; -} - //************************************************************************************** char* GetName() //************************************************************************************** diff --git a/CAPE/CAPE.h b/CAPE/CAPE.h index 7f2e7e4..e086532 100644 --- a/CAPE/CAPE.h +++ b/CAPE/CAPE.h @@ -39,53 +39,10 @@ int ScanForPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int ScanForDisguisedPE(LPVOID Buffer, SIZE_T Size, LPVOID* Offset); int IsDisguisedPEHeader(LPVOID Buffer); int DumpImageInCurrentProcess(LPVOID ImageBase); -void DumpSectionViewsForPid(DWORD Pid); -void DumpSectionViewsForHandle(HANDLE SectionHandle); SYSTEM_INFO SystemInfo; PVOID CallingModule; -typedef struct InjectionSectionView -{ - HANDLE SectionHandle; - PVOID LocalView; - SIZE_T ViewSize; - int TargetProcessId; - wchar_t *SectionName; - struct InjectionSectionView *NextSectionView; -} INJECTIONSECTIONVIEW, *PINJECTIONSECTIONVIEW; - -PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); -PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); -BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); -void DumpSectionViewsForPid(DWORD Pid); -void DumpSectionView(PINJECTIONSECTIONVIEW SectionView); - -typedef struct InjectionInfo -{ - int ProcessId; - HANDLE ProcessHandle; - DWORD_PTR ImageBase; - DWORD_PTR EntryPoint; - BOOL WriteDetected; - BOOL ImageDumped; - LPVOID BufferBase; - LPVOID StackPointer; - unsigned int BufferSizeOfImage; - HANDLE SectionHandle; -// struct InjectionSectionView *SectionViewList; - struct InjectionInfo *NextInjectionInfo; -} INJECTIONINFO, *PINJECTIONINFO; - -struct InjectionInfo *InjectionInfoList; - -PINJECTIONINFO GetInjectionInfo(DWORD ProcessId); -PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle); -PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId); -BOOL DropInjectionInfo(HANDLE ProcessHandle); - -struct InjectionSectionView *SectionViewList; - // // MessageId: STATUS_SUCCESS // diff --git a/CAPE/Injection.c b/CAPE/Injection.c index 61e6587..eb5d991 100644 --- a/CAPE/Injection.c +++ b/CAPE/Injection.c @@ -24,12 +24,525 @@ along with this program.If not, see . #include "..\log.h" #include "Debugger.h" #include "CAPE.h" +#include "Injection.h" + +extern _NtMapViewOfSection pNtMapViewOfSection; +extern _NtUnmapViewOfSection pNtUnmapViewOfSection; extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void TestDoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); extern void DoOutputErrorString(_In_ LPCTSTR lpOutputString, ...); extern PVOID get_process_image_base(HANDLE process_handle); +//************************************************************************************** +PINJECTIONINFO GetInjectionInfo(DWORD ProcessId) +//************************************************************************************** +{ + DWORD CurrentProcessId; + + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; + while (CurrentInjectionInfo) + { + CurrentProcessId = CurrentInjectionInfo->ProcessId; + + if (CurrentProcessId == ProcessId) + return CurrentInjectionInfo; + else + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return NULL; +} + +//************************************************************************************** +PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle) +//************************************************************************************** +{ + HANDLE CurrentProcessHandle; + + PINJECTIONINFO CurrentInjectionInfo = InjectionInfoList; + while (CurrentInjectionInfo) + { + CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; + + if (CurrentProcessHandle == ProcessHandle) + return CurrentInjectionInfo; + else + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return NULL; +} + +//************************************************************************************** +PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId) +//************************************************************************************** +{ + PINJECTIONINFO CurrentInjectionInfo, PreviousInjectionInfo; + + PreviousInjectionInfo = NULL; + + if (InjectionInfoList == NULL) + { + InjectionInfoList = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); + + if (InjectionInfoList == NULL) + { + DoOutputDebugString("CreateInjectionInfo: failed to allocate memory for initial injection info list.\n"); + return NULL; + } + + memset(InjectionInfoList, 0, sizeof(struct InjectionInfo)); + + InjectionInfoList->ProcessId = ProcessId; + } + + CurrentInjectionInfo = InjectionInfoList; + + while (CurrentInjectionInfo) + { + if ((CurrentInjectionInfo->ProcessId) == ProcessId) + break; + + PreviousInjectionInfo = CurrentInjectionInfo; + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + if (!CurrentInjectionInfo) + { + // We haven't found it in the linked list, so create a new one + CurrentInjectionInfo = PreviousInjectionInfo; + + CurrentInjectionInfo->NextInjectionInfo = ((struct InjectionInfo*)malloc(sizeof(struct InjectionInfo))); + + if (CurrentInjectionInfo->NextInjectionInfo == NULL) + { + DoOutputDebugString("CreateInjectionInfo: Failed to allocate new thread breakpoints.\n"); + return NULL; + } + + memset(CurrentInjectionInfo->NextInjectionInfo, 0, sizeof(struct InjectionInfo)); + + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + + CurrentInjectionInfo->ProcessId = ProcessId; + } + + return CurrentInjectionInfo; +} + +//************************************************************************************** +BOOL DropInjectionInfo(HANDLE ProcessHandle) +//************************************************************************************** +{ + HANDLE CurrentProcessHandle; + PINJECTIONINFO PreviousInjectionInfo, CurrentInjectionInfo = InjectionInfoList; + + PreviousInjectionInfo = NULL; + + while (CurrentInjectionInfo) + { + CurrentProcessHandle = CurrentInjectionInfo->ProcessHandle; + + if (CurrentProcessHandle == ProcessHandle) + { + // Unlink this from the list and free the memory + if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo) + { + PreviousInjectionInfo->NextInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d.\n", CurrentInjectionInfo->ProcessId); + } + else if (PreviousInjectionInfo && CurrentInjectionInfo->NextInjectionInfo == NULL) + { + PreviousInjectionInfo->NextInjectionInfo = NULL; + DoOutputDebugString("DropInjectionInfo: removed injection info for pid %d from the end of the section view list.\n", CurrentInjectionInfo->ProcessId); + } + else if (!PreviousInjectionInfo) + { + InjectionInfoList = NULL; + DoOutputDebugString("DropInjectionInfo: removed the head of the injection info list for pid %d.\n", CurrentInjectionInfo->ProcessId); + } + + free(CurrentInjectionInfo); + + return TRUE; + } + + PreviousInjectionInfo = CurrentInjectionInfo; + CurrentInjectionInfo = CurrentInjectionInfo->NextInjectionInfo; + } + + return FALSE; +} + +//************************************************************************************** +PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + wchar_t *SectionName; + + if (CurrentSectionView->SectionHandle == SectionHandle) + return CurrentSectionView; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + return CurrentSectionView; + } + free(SectionName); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + return NULL; +} + +//************************************************************************************** +PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; + + PreviousSectionView = NULL; + + if (SectionViewList == NULL) + { + SectionViewList = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); + + if (SectionViewList == NULL) + { + DoOutputDebugString("AddSectionView: failed to allocate memory for initial section view list.\n"); + return NULL; + } + + memset(SectionViewList, 0, sizeof(struct InjectionSectionView)); + + SectionViewList->SectionHandle = SectionHandle; + SectionViewList->LocalView = LocalView; + SectionViewList->ViewSize = ViewSize; + SectionViewList->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + if (SectionViewList->SectionName) + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + wchar_t *SectionName; + + if ((CurrentSectionView->SectionHandle) == SectionHandle) + break; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("AddSectionView: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + break; + } + free(SectionName); + } + + PreviousSectionView = CurrentSectionView; + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (!CurrentSectionView) + { + // We haven't found it in the linked list, so create a new one + CurrentSectionView = PreviousSectionView; + + CurrentSectionView->NextSectionView = ((struct InjectionSectionView*)malloc(sizeof(struct InjectionSectionView))); + + if (CurrentSectionView->NextSectionView == NULL) + { + DoOutputDebugString("CreateSectionView: Failed to allocate new injection sectionview structure.\n"); + return NULL; + } + + memset(CurrentSectionView->NextSectionView, 0, sizeof(struct InjectionSectionView)); + + CurrentSectionView = CurrentSectionView->NextSectionView; + CurrentSectionView->SectionHandle = SectionHandle; + CurrentSectionView->LocalView = LocalView; + CurrentSectionView->ViewSize = ViewSize; + CurrentSectionView->SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + path_from_handle(SectionHandle, CurrentSectionView->SectionName, MAX_UNICODE_PATH); + } + + return CurrentSectionView; +} + +//************************************************************************************** +BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView, PreviousSectionView; + + PreviousSectionView = NULL; + + if (SectionViewList == NULL) + { + DoOutputDebugString("DropSectionView: failed to obtain initial section view list.\n"); + return FALSE; + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView == SectionView) + { + // Unlink this from the list and free the memory + if (PreviousSectionView && CurrentSectionView->NextSectionView) + { + PreviousSectionView->NextSectionView = CurrentSectionView->NextSectionView; + DoOutputDebugString("DropSectionView: removed a view from section view list.\n"); + } + else if (PreviousSectionView && CurrentSectionView->NextSectionView == NULL) + { + PreviousSectionView->NextSectionView = NULL; + DoOutputDebugString("DropSectionView: removed the view from the end of the section view list.\n"); + } + else if (!PreviousSectionView) + { + SectionViewList = NULL; + DoOutputDebugString("DropSectionView: removed the head of the section view list.\n"); + } + + free(CurrentSectionView); + + return TRUE; + } + + PreviousSectionView = CurrentSectionView; + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + return FALSE; +} + +//************************************************************************************** +void DumpSectionViewsForPid(DWORD Pid) +//************************************************************************************** +{ + struct InjectionInfo *CurrentInjectionInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; + DWORD BufferSize = MAX_PATH; + LPVOID PEPointer = NULL; + BOOL Dumped = FALSE; + + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("DumpSectionViewsForPid: No injection info for pid %d.\n", Pid); + return; + } + + CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + if (CurrentSectionView->TargetProcessId == Pid && CurrentSectionView->LocalView) + { + DoOutputDebugString("DumpSectionViewsForPid: Shared section view found with pid %d, local address 0x%p.\n", Pid); + + PEPointer = CurrentSectionView->LocalView; + + while (ScanForDisguisedPE(PEPointer, CurrentSectionView->ViewSize - ((DWORD_PTR)PEPointer - (DWORD_PTR)CurrentSectionView->LocalView), &PEPointer)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumping PE image from shared section view, local address 0x%p.\n", PEPointer); + + CapeMetaData->DumpType = INJECTION_PE; + CapeMetaData->TargetPid = Pid; + CapeMetaData->Address = PEPointer; + + if (DumpImageInCurrentProcess(PEPointer)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumped PE image from shared section view.\n"); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump PE image from shared section view.\n"); + + ((BYTE*)PEPointer)++; + } + + if (Dumped == FALSE) + { + DoOutputDebugString("DumpSectionViewsForPid: no PE file found in shared section view, attempting raw dump.\n"); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = Pid; + + if (DumpMemory(CurrentSectionView->LocalView, CurrentSectionView->ViewSize)) + { + DoOutputDebugString("DumpSectionViewsForPid: Dumped shared section view."); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionViewsForPid: Failed to dump shared section view."); + } + } + + //DropSectionView(CurrentSectionView); + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (Dumped == FALSE) + DoOutputDebugString("DumpSectionViewsForPid: no shared section views found for pid %d.\n", Pid); + + return; +} + +//************************************************************************************** +void DumpSectionView(PINJECTIONSECTIONVIEW SectionView) +//************************************************************************************** +{ + DWORD BufferSize = MAX_PATH; + LPVOID PEPointer = NULL; + BOOL Dumped = FALSE; + + if (!SectionView->LocalView) + { + DoOutputDebugString("DumpSectionView: Section view local view address not set.\n"); + return; + } + + if (!SectionView->TargetProcessId) + { + DoOutputDebugString("DumpSectionView: Section with local view 0x%p has no target process - error.\n", SectionView->LocalView); + return; + } + + if (!SectionView->ViewSize) + { + DoOutputDebugString("DumpSectionView: Section with local view 0x%p has zero commit size - error.\n", SectionView->LocalView); + return; + } + + Dumped = DumpPEsInRange(SectionView->LocalView, SectionView->ViewSize); + + if (Dumped) + DoOutputDebugString("DumpSectionView: Dumped PE image from shared section view with local address 0x%p.\n", SectionView->LocalView); + else + { + DoOutputDebugString("DumpSectionView: no PE file found in shared section view with local address 0x%p, attempting raw dump.\n", SectionView->LocalView); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = SectionView->TargetProcessId; + + if (DumpMemory(SectionView->LocalView, SectionView->ViewSize)) + { + DoOutputDebugString("DumpSectionView: Dumped shared section view with local address at 0x%p", SectionView->LocalView); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionView: Failed to dump shared section view with address view at 0x%p", SectionView->LocalView); + } + + if (Dumped == TRUE) + DropSectionView(SectionView); + else + { // This may indicate the view has been unmapped already + // Let's try and remap it. + SIZE_T ViewSize = 0; + PVOID BaseAddress = NULL; + + DoOutputDebugString("DumpSectionView: About to remap section with handle 0x%x, size 0x%x.\n", SectionView->SectionHandle, SectionView->ViewSize); + + NTSTATUS ret = pNtMapViewOfSection(SectionView->SectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, 0, &ViewSize, ViewUnmap, 0, PAGE_READWRITE); + + if (NT_SUCCESS(ret)) + { + Dumped = DumpPEsInRange(BaseAddress, ViewSize); + + if (Dumped) + DoOutputDebugString("DumpSectionView: Remapped and dumped section view with handle 0x%x.\n", SectionView->SectionHandle); + else + { + DoOutputDebugString("DumpSectionView: no PE file found in remapped section view with handle 0x%x, attempting raw dump.\n", SectionView->SectionHandle); + + CapeMetaData->DumpType = INJECTION_SHELLCODE; + + CapeMetaData->TargetPid = SectionView->TargetProcessId; + + if (DumpMemory(BaseAddress, ViewSize)) + { + DoOutputDebugString("DumpSectionView: Dumped remapped section view with handle 0x%x.\n", SectionView->SectionHandle); + Dumped = TRUE; + } + else + DoOutputDebugString("DumpSectionView: Failed to dump remapped section view with handle 0x%x.\n", SectionView->SectionHandle); + } + + pNtUnmapViewOfSection(SectionView->SectionHandle, BaseAddress); + } + else + DoOutputDebugString("DumpSectionView: Failed to remap section with handle 0x%x - error code 0x%x\n", SectionView->SectionHandle, ret); + } + + return; +} + +//************************************************************************************** +void DumpSectionViewsForHandle(HANDLE SectionHandle) +//************************************************************************************** +{ + PINJECTIONSECTIONVIEW CurrentSectionView = SectionViewList; + + while (CurrentSectionView) + { + wchar_t *SectionName; + + if (CurrentSectionView->SectionHandle == SectionHandle) + break; + + SectionName = malloc(MAX_UNICODE_PATH * sizeof(wchar_t)); + + if (SectionName) + { + path_from_handle(SectionHandle, SectionViewList->SectionName, MAX_UNICODE_PATH); + if ((!wcscmp(CurrentSectionView->SectionName, SectionName))) + { + DoOutputDebugString("DumpSectionViewsForHandle: New section handle for existing named section %ws.\n", SectionHandle, SectionName); + free(SectionName); + break; + } + free(SectionName); + } + + CurrentSectionView = CurrentSectionView->NextSectionView; + } + + if (CurrentSectionView && CurrentSectionView->TargetProcessId) + { + DoOutputDebugString("DumpSectionViewsForHandle: Dumping section view at 0x%p for handle 0x%x (target process %d).\n", CurrentSectionView->LocalView, SectionHandle, CurrentSectionView->TargetProcessId); + DumpSectionView(CurrentSectionView); + } + + return; +} + void GetThreadContextHandler(DWORD Pid, LPCONTEXT Context) { if (Context && Context->ContextFlags & CONTEXT_CONTROL) @@ -284,7 +797,7 @@ void MapSectionViewHandler(HANDLE ProcessHandle, HANDLE SectionHandle, PVOID Bas if (!CurrentSectionView) { CurrentSectionView = AddSectionView(SectionHandle, BaseAddress, ViewSize); - DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x and local view 0x%p to global list (%ws).\n", SectionHandle, BaseAddress, CurrentSectionView->SectionName); + DoOutputDebugString("MapSectionViewHandler: Added section view with handle 0x%x amd local view 0x%p to global list (%ws).\n", SectionHandle, BaseAddress, CurrentSectionView->SectionName); } else { @@ -491,3 +1004,94 @@ void WriteMemoryHandler(HANDLE ProcessHandle, LPVOID BaseAddress, LPCVOID Buffer } } } + +void DuplicationHandler(HANDLE SourceHandle, HANDLE TargetHandle) +{ + struct InjectionInfo *CurrentInjectionInfo; + PINJECTIONSECTIONVIEW CurrentSectionView; + char DevicePath[MAX_PATH]; + unsigned int PathLength; + DWORD BufferSize = MAX_PATH; + + DWORD Pid = pid_from_process_handle(TargetHandle); + + if (Pid == GetCurrentProcessId()) + return; + + if (!Pid) + { + DoOutputErrorString("DuplicationHandler: Failed to obtain pid from target process handle 0x%x", TargetHandle); + CurrentInjectionInfo = GetInjectionInfoFromHandle(TargetHandle); + Pid = CurrentInjectionInfo->ProcessId; + } + else + CurrentInjectionInfo = GetInjectionInfo(Pid); + + if (!Pid) + { + DoOutputDebugString("DuplicationHandler: Failed to find pid for target process handle 0x%x in injection info list 0x%x.\n", TargetHandle); + return; + } + + //if (!CurrentInjectionInfo) + //{ + // DoOutputDebugString("DuplicationHandler: Failed to find injection info for target process %d.\n", Pid); + // return; + //} + + CurrentSectionView = GetSectionView(SourceHandle); + + if (!CurrentSectionView) + { + DoOutputDebugString("DuplicationHandler: Failed to find section view with source handle 0x%x.\n", SourceHandle); + return; + } + + if (CurrentInjectionInfo && CurrentInjectionInfo->ProcessId == Pid) + { + CurrentSectionView->TargetProcessId = Pid; + DoOutputDebugString("DuplicationHandler: Added section view with source handle 0x%x to target process %d (%ws).\n", SourceHandle, Pid, CurrentSectionView->SectionName); + } + else if (!CurrentInjectionInfo && Pid != GetCurrentProcessId()) + { + CurrentInjectionInfo = CreateInjectionInfo(Pid); + + if (CurrentInjectionInfo == NULL) + { + DoOutputDebugString("DuplicationHandler: Cannot create new injection info - error.\n"); + } + else + { + CurrentInjectionInfo->ProcessHandle = SourceHandle; + CurrentInjectionInfo->ProcessId = Pid; + CurrentInjectionInfo->EntryPoint = (DWORD_PTR)NULL; + CurrentInjectionInfo->ImageDumped = FALSE; + CapeMetaData->TargetProcess = (char*)malloc(BufferSize); + + CurrentInjectionInfo->ImageBase = (DWORD_PTR)get_process_image_base(SourceHandle); + + if (CurrentInjectionInfo->ImageBase) + DoOutputDebugString("DuplicationHandler: Image base for process %d (handle 0x%x): 0x%p.\n", Pid, SourceHandle, CurrentInjectionInfo->ImageBase); + + PathLength = GetProcessImageFileName(SourceHandle, DevicePath, BufferSize); + + if (!PathLength) + { + DoOutputErrorString("DuplicationHandler: Error obtaining target process name"); + _snprintf(CapeMetaData->TargetProcess, BufferSize, "Error obtaining target process name"); + } + else if (!TranslatePathFromDeviceToLetter(DevicePath, CapeMetaData->TargetProcess, &BufferSize)) + DoOutputErrorString("DuplicationHandler: Error translating target process path"); + + CurrentSectionView = AddSectionView(SourceHandle, NULL, 0); + + if (CurrentSectionView) + { + CurrentSectionView->TargetProcessId = Pid; + DoOutputDebugString("DuplicationHandler: Added section view with handle 0x%x to target process %d (%ws).\n", SourceHandle, Pid, CurrentSectionView->SectionName); + } + else + DoOutputDebugString("DuplicationHandler: Error, failed to add section view with handle 0x%x and target process %d (%ws).\n", SourceHandle, Pid, CurrentSectionView->SectionName); + } + } +} diff --git a/CAPE/Injection.h b/CAPE/Injection.h new file mode 100644 index 0000000..94909a8 --- /dev/null +++ b/CAPE/Injection.h @@ -0,0 +1,67 @@ +/* +CAPE - Config And Payload Extraction +Copyright(C) 2015-2018 Context Information Security. (kevin.oreilly@contextis.com) + +This program is free software : you can redistribute it and / or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.If not, see . +*/ +#define MAX_UNICODE_PATH 32768 + +void DumpSectionViewsForPid(DWORD Pid); +void DumpSectionViewsForHandle(HANDLE SectionHandle); + +typedef enum _SECTION_INHERIT { + ViewShare = 1, + ViewUnmap = 2 +} SECTION_INHERIT; + +typedef struct InjectionSectionView +{ + HANDLE SectionHandle; + PVOID LocalView; + SIZE_T ViewSize; + int TargetProcessId; + wchar_t *SectionName; + struct InjectionSectionView *NextSectionView; +} INJECTIONSECTIONVIEW, *PINJECTIONSECTIONVIEW; + +PINJECTIONSECTIONVIEW AddSectionView(HANDLE SectionHandle, PVOID LocalView, SIZE_T ViewSize); +PINJECTIONSECTIONVIEW GetSectionView(HANDLE SectionHandle); +BOOL DropSectionView(PINJECTIONSECTIONVIEW SectionView); +void DumpSectionViewsForPid(DWORD Pid); +void DumpSectionView(PINJECTIONSECTIONVIEW SectionView); + +typedef struct InjectionInfo +{ + int ProcessId; + HANDLE ProcessHandle; + DWORD_PTR ImageBase; + DWORD_PTR EntryPoint; + BOOL WriteDetected; + BOOL ImageDumped; + LPVOID BufferBase; + LPVOID StackPointer; + unsigned int BufferSizeOfImage; + HANDLE SectionHandle; +// struct InjectionSectionView *SectionViewList; + struct InjectionInfo *NextInjectionInfo; +} INJECTIONINFO, *PINJECTIONINFO; + +struct InjectionInfo *InjectionInfoList; + +PINJECTIONINFO GetInjectionInfo(DWORD ProcessId); +PINJECTIONINFO GetInjectionInfoFromHandle(HANDLE ProcessHandle); +PINJECTIONINFO CreateInjectionInfo(DWORD ProcessId); +BOOL DropInjectionInfo(HANDLE ProcessHandle); + +struct InjectionSectionView *SectionViewList; diff --git a/hook_misc.c b/hook_misc.c index f223898..47c9201 100644 --- a/hook_misc.c +++ b/hook_misc.c @@ -31,6 +31,10 @@ along with this program. If not, see . #define STATUS_BAD_COMPRESSION_BUFFER ((NTSTATUS)0xC0000242L) +#ifdef CAPE_INJECTION +extern void DuplicationHandler(HANDLE SourceProcessHandle, HANDLE TargetHandle); +#endif + extern void DoOutputDebugString(_In_ LPCTSTR lpOutputString, ...); HOOKDEF(HHOOK, WINAPI, SetWindowsHookExA, @@ -357,14 +361,14 @@ HOOKDEF(NTSTATUS, WINAPI, NtClose, LOQ_ntstatus("system", "ps", "Handle", Handle, "Alert", "Tried to close Cuckoo's log handle"); return ret; } +#ifdef CAPE_INJECTION + DumpSectionViewsForHandle(Handle); +#endif ret = Old_NtClose(Handle); LOQ_ntstatus("system", "p", "Handle", Handle); if(NT_SUCCESS(ret)) { remove_file_from_log_tracking(Handle); file_close(Handle); -#ifdef CAPE_INJECTION - DumpSectionViewsForHandle(Handle); -#endif } return ret; } @@ -394,6 +398,9 @@ HOOKDEF(NTSTATUS, WINAPI, NtDuplicateObject, remove_file_from_log_tracking(SourceHandle); file_close(SourceHandle); } +#ifdef CAPE_INJECTION + DuplicationHandler(SourceHandle, TargetProcessHandle); +#endif } return ret; } diff --git a/misc.c b/misc.c index af0049e..4822a8c 100644 --- a/misc.c +++ b/misc.c @@ -38,7 +38,8 @@ static _NtQueryObject pNtQueryObject; static _NtQueryKey pNtQueryKey; static _NtDelayExecution pNtDelayExecution; static _NtQuerySystemInformation pNtQuerySystemInformation; -static _NtUnmapViewOfSection pNtUnmapViewOfSection; +_NtMapViewOfSection pNtMapViewOfSection; +_NtUnmapViewOfSection pNtUnmapViewOfSection; _NtAllocateVirtualMemory pNtAllocateVirtualMemory; _NtProtectVirtualMemory pNtProtectVirtualMemory; _NtFreeVirtualMemory pNtFreeVirtualMemory; @@ -60,6 +61,7 @@ void resolve_runtime_apis(void) *(FARPROC *)&pNtFreeVirtualMemory = GetProcAddress(ntdllbase, "NtFreeVirtualMemory"); *(FARPROC *)&pLdrRegisterDllNotification = GetProcAddress(ntdllbase, "LdrRegisterDllNotification"); *(FARPROC *)&pRtlGenRandom = GetProcAddress(GetModuleHandle("advapi32"), "SystemFunction036"); + *(FARPROC *)&pNtMapViewOfSection = GetProcAddress(ntdllbase, "NtMapViewOfSection"); *(FARPROC *)&pNtUnmapViewOfSection = GetProcAddress(ntdllbase, "NtUnmapViewOfSection"); } diff --git a/misc.h b/misc.h index d81a2f3..87a5465 100644 --- a/misc.h +++ b/misc.h @@ -50,6 +50,17 @@ typedef NTSTATUS(WINAPI *_NtDelayExecution)( typedef NTSTATUS(WINAPI *_NtUnmapViewOfSection)( HANDLE ProcessHandle, PVOID BaseAddress); +typedef NTSTATUS(WINAPI *_NtMapViewOfSection)( + _In_ HANDLE SectionHandle, + _In_ HANDLE ProcessHandle, + __inout PVOID *BaseAddress, + _In_ ULONG_PTR ZeroBits, + _In_ SIZE_T CommitSize, + __inout PLARGE_INTEGER SectionOffset, + __inout PSIZE_T ViewSize, + __in UINT InheritDisposition, + __in ULONG AllocationType, + __in ULONG Win32Protect); typedef struct _LDR_DLL_LOADED_NOTIFICATION_DATA { ULONG Flags;