typedef struct _HOTPATCH_HEADER { DWORD Signature;//"HOT1" DWORD Version;// = 0x00010000 DWORD FixupRgnCount;// x86 , RtlpApplyRelocationFixups DWORD FixupRgnRva;//RVA DWORD ValidationCount;// RtlpValidateTargetRanges DWORD ValidationArrayRva;//RVA DWORD HookCount;//, . , DWORD HookArrayRva;// , RtlReadHookInformation ULONGLONG OrigHotpBaseAddress;// 86 . ULONGLONG OrigTargetBaseAddress;// , DWORD TargetNameRva;//, , DWORD ModuleIdMethod;// union { ULONGLONG Quad; GUID Guid; struct { GUID Guid; DWORD Age; } PdbSig; BYTE Hash128[16]; BYTE Hash160[20]; } TargetModuleIdValue; } HOTPATCH_HEADER, *PHOTPATCH_HEADER;
typedef struct _HOTPATCH_HOOK { WORD HookType;// HOTPATCH_HOOK_TIPE WORD HookOptions; DWORD HookRva; DWORD HotpRva; DWORD ValidationRva; } HOTPATCH_HOOK, *PHOTPATCH_HOOK; typedef enum _HOTPATCH_HOOK_TYPE { HOTP_Hook_None = 0, HOTP_Hook_VA32 = 1, HOTP_Hook_X86_JMP = 2, HOTP_Hook_PCREL32 = 3, //not yet implemented HOTP_Hook_X86_JMP2B = 4, HOTP_Hook_VA64 = 16, HOTP_Hook_IA64_BRL = 32, HOTP_Hook_IA64_BR = 33, //not yet implemented HOTP_Hook_AMD64_IND = 48, HOTP_Hook_AMD64_CNT = 49 } HOTPATCH_HOOK_TYPE;
#pragma section (".hotp1 ") __declspec(allocate(".hotp1 ")) struct Hotp_Header { ULONG Signature; ULONG Version; ULONG FixupRgnCount; ULONG FixupRgnRva; ULONG ValidationCount; ULONG ValidationArrayRva; ULONG HookCount; ULONG HookArrayRva; ULONGLONG OrigHotpBaseAddress; ULONGLONG OrigTargetBaseAddress; ULONG TargetNameRva; ULONG ModuleIdMethod; union { ULONGLONG Quad; GUID Guid; struct { GUID guid; ULONG Age; } PdbSig; UCHAR Hash128[16]; UCHAR Hash160[20]; } TargetModuleIdValue; CHAR TagretName[13]; struct { USHORT HookType; USHORT HookOptions; ULONG HookRva; ULONG HotpRva; ULONG ValidationRva; } Hook; } hpHeader = { 0x31544F48, // "1TOH" 0x00010000, // 1.0 0x00000000, // FixupRgn 0x00000000, // FixupRgn Rva 0x00000000, // Validations 0x00000000, // Validation Rva 0x00000001, // 1 Hook 0x00005060, // HookRva 0x0000000000010000, // HotpBase 0x0000000000010000, // TargetBase 0x00005050, // Targetname Rva 0x00000000, // ModuleID 0x0000000000000000, // Quad "fastfat.sys", { 0x0030, // hook type HOTP_Hook_AMD64_IND 0x8000, // hook option +- 2GB 0x0002B6F0, // hook rva 0x0004392A, // hotp rva 0x00000000 // valid rva } }; NTSTATUS FatCommonWrite() { PINT32 p = 0; INT32 a = *p;// , (: return a; }
typedef struct _SYSTEM_HOTPATCH_CODE_INFORMATION { ULONG Flags; ULONG InfoSize; USHORT NameOffset; USHORT NameLength; } SYSTEM_HOTPATCH_CODE_INFORMATION; // //... // PatchInfo , , KB914389 // // // . OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken); SetPrivilege(hToken, SE_DEBUG_NAME, TRUE); SetPrivilege(hToken, SE_LOAD_DRIVER_NAME, TRUE); ZwSetSystemInformation(69, PatchInfo, PatchInfo->InfoSize);
Source: https://habr.com/ru/post/252275/
All Articles