сплайсю сабж: Код (Text): library libr32; uses Windows, winsock,sysutils; type ntstatus=cardinal; unicode_string=packed record Length:WORD; MaximumLength:WORD; Buffer:PWideChar; end; PUNICODE_STRING=^unicode_string; _KEY_VALUE_BASIC_INFORMATION=packed record TitleIndex:dword; _Type:dword; NameLength:dword; Name:array[0..0] of widechar; end; PKEY_VALUE_BASIC_INFORMATION=^_KEY_VALUE_BASIC_INFORMATION; tramp_=function (KeyHandle:THANDLE;ValueName:PUNICODE_STRING; KeyValueInformationClass:DWORD; KeyValueInformation:Pointer;Length:DWORD;ResultLength:pointer):ntstatus;stdcall; OldCode = packed record two: byte; One: dword; end; far_jmp = packed record jmpOp: byte; jmpoffset: pointer; end; var JmpMba: far_jmp; OldMba: OldCode; MbaAdr: pointer; tramp_pr: tramp_; Procedure Unhook(); var Bytes: dword; begin WriteProcessMemory(INVALID_HANDLE_VALUE, MbaAdr, @OldMba, SizeOf(OldCode), Bytes); end; function ZwQueryKey(KeyHandle:thandle;KeyInformationClass:dword;KeyInformation:pointer;Length:dword; ResultLength:pointer):ntstatus;stdcall; external 'ntdll.dll' name 'ZwQueryKey'; function newquery(KeyHandle:THANDLE;ValueName:PUNICODE_STRING; KeyValueInformationClass:DWORD; KeyValueInformation:Pointer;Length:DWORD;ResultLength:pointer):ntstatus;stdcall; var kinfo:_KEY_VALUE_BASIC_INFORMATION; len:dword; begin unhook; messagebox(0,pchar(inttohex(ZwQueryKey(keyhandle,0,@kinfo,sizeof(_KEY_VALUE_BASIC_INFORMATION),@len),8)),nil,0); messageboxw(0,pwidechar(addr(kinfo.Name)),valuename^.buffer,0); Result := tramp_pr(keyhandle,valuename,keyvalueinformationclass,KeyValueInformation,length,resultlength); end; Procedure SetFFHook(); var hUser32: dword; Bytes: dword; begin hUser32 := GetModuleHandle('ntdll.dll'); if hUser32<=0 then exit; MbaAdr := GetProcAddress(hUser32, 'ZwQueryValueKey'); if DWORD(MbaAdr)<=0 then exit; ReadProcessMemory(INVALID_HANDLE_VALUE, MbaAdr, @OldMba, SizeOf(OldCode), Bytes); WriteProcessMemory(invalid_handle_value,@tramp_pr,@oldmba,sizeof(oldcode),bytes) JmpMba.jmpOp := $E9; JmpMba.jmpoffset := pointer(dword(mbaadr)- dword(@tramp_pr)-5); WriteProcessMemory(INVALID_HANDLE_VALUE, pointer(Dword(@tramp_pr)+sizeof(oldcode)), @JmpMba, SizeOf(far_jmp), Bytes); jmpmba.jmpOp:=$E9; jmpmba.jmpoffset:=pointer(Dword(@newquery)-dword(mbaadr)-5); WriteProcessMemory(invalid_handle_value,mbaadr,@jmpmba,sizeof(far_jmp),bytes); end; Function MessageProc(code : integer; wParam : word; lParam : longint) : longint; stdcall; begin CallNextHookEx(0, Code, wParam, lparam); Result := 0; end; Procedure SetGlobalHookProc(); begin SetWindowsHookEx(WH_GETMESSAGE, @MessageProc, HInstance, 0); Sleep(INFINITE); end; // Procedure SetGlobalHook(); var hMutex: dword; TrId: dword; begin hMutex := CreateMutex(nil, false, 'AdvareHook'); if GetLastError = 0 then CreateThread(nil, 0, @SetGlobalHookProc, nil, 0, TrId) else CloseHandle(hMutex); end; procedure DLLEntryPoint(dwReason: DWord); begin case dwReason of DLL_PROCESS_ATTACH: begin SetGlobalHook(); Randomize(); @tramp_pr:=VirtualAlloc(nil,20,MEM_COMMIT or MEM_RESERVE or MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); SetFFHook() end; DLL_PROCESS_DETACH: begin UnHook(); end; end; end; begin DllProc := @DLLEntryPoint; DLLEntryPoint(DLL_PROCESS_ATTACH); end. проблема в том что zwquerykey, которая используется чтоб определить раздел возвращает STATUS_DATATYPE_MISALIGNMENT. вроде все правильно объявил. valuename выводитсья как надо, а имя ключа кракозябрами что ихменить здесь?пробовал вместо Name:array[0..0] of widechar pwidechar писать - не помогло. или может внутренее выравнивание включить(убрать packed) ?
вот, так вроде работает, но только часть имени раздела показывает(первых букв нету): Код (Text): library libr32; uses Windows, winsock,sysutils; type ntstatus=cardinal; unicode_string=packed record Length:WORD; MaximumLength:WORD; Buffer:PWideChar; end; PUNICODE_STRING=^unicode_string; _LARGE_INTEGER = record case Integer of 0: ( LowPart: DWORD; HighPart: Longint); 1: ( QuadPart: LONGLONG); end; LARGE_INTEGER = _LARGE_INTEGER; _KEY_VALUE_BASIC_INFORMATION=record LastWriteTime:LARGE_INTEGER; TitleIndex:dword; _Type:dword; NameLength:dword; Name:array[0..4*1024] of Widechar; end; PKEY_VALUE_BASIC_INFORMATION=^_KEY_VALUE_BASIC_INFORMATION; tramp_=function (KeyHandle:THANDLE;ValueName:PUNICODE_STRING; KeyValueInformationClass:DWORD; KeyValueInformation:Pointer;Length:DWORD;ResultLength:pointer):ntstatus;stdcall; OldCode = packed record two: byte; One: dword; end; far_jmp = packed record jmpOp: byte; jmpoffset: pointer; end; var JmpMba: far_jmp; OldMba: OldCode; MbaAdr: pointer; tramp_pr: tramp_; Procedure Unhook(); var Bytes: dword; begin WriteProcessMemory(INVALID_HANDLE_VALUE, MbaAdr, @OldMba, SizeOf(OldCode), Bytes); end; function ZwQueryKey(KeyHandle:thandle;KeyInformationClass:dword;KeyInformation:pointer;Length:dword; ResultLength:pointer):ntstatus;stdcall; external 'ntdll.dll' name 'ZwQueryKey'; function newquery(KeyHandle:THANDLE;ValueName:PUNICODE_STRING; KeyValueInformationClass:DWORD; KeyValueInformation:Pointer;Length:DWORD;ResultLength:pointer):ntstatus;stdcall; var kinfo:_KEY_VALUE_BASIC_INFORMATION; len:dword; begin unhook; ZwQueryKey(keyhandle,0,@kinfo,sizeof(_KEY_VALUE_BASIC_INFORMATION),@len); messageboxw(0,kinfo.Name,valuename^.buffer,0); Result := tramp_pr(keyhandle,valuename,keyvalueinformationclass,KeyValueInformation,length,resultlength); //äåðãàåì ôóíêöèþ ÷åðåç òðàìïëèí end; Procedure SetFFHook(); var hUser32: dword; Bytes: dword; begin hUser32 := GetModuleHandle('ntdll.dll'); if hUser32<=0 then exit; MbaAdr := GetProcAddress(hUser32, 'ZwQueryValueKey'); if DWORD(MbaAdr)<=0 then exit; ReadProcessMemory(INVALID_HANDLE_VALUE, MbaAdr, @OldMba, SizeOf(OldCode), Bytes);//â àïè ôóíêöèÿõ ñïåöèàëüíî îñòàâèëè 5 áàéò äëÿ ñïëàéñèíãà,ïîýòîìó äèçàñåìáëåð äëèí íå íóæåí WriteProcessMemory(invalid_handle_value,@tramp_pr,@oldmba,sizeof(oldcode),bytes);//â òðàìïëèí JmpMba.jmpOp := $E9; JmpMba.jmpoffset := pointer(dword(mbaadr)- dword(@tramp_pr)-5);//ñìåíùåíèå äëÿ ïðûæêà WriteProcessMemory(INVALID_HANDLE_VALUE, pointer(Dword(@tramp_pr)+sizeof(oldcode)), @JmpMba, SizeOf(far_jmp), Bytes); jmpmba.jmpOp:=$E9; jmpmba.jmpoffset:=pointer(Dword(@newquery)-dword(mbaadr)-5); WriteProcessMemory(invalid_handle_value,mbaadr,@jmpmba,sizeof(far_jmp),bytes); end; // çàëåïà Function MessageProc(code : integer; wParam : word; lParam : longint) : longint; stdcall; begin CallNextHookEx(0, Code, wParam, lparam); Result := 0; end; Procedure SetGlobalHookProc(); begin SetWindowsHookEx(WH_GETMESSAGE, @MessageProc, HInstance, 0); Sleep(INFINITE); end; // Procedure SetGlobalHook(); var hMutex: dword; TrId: dword; begin hMutex := CreateMutex(nil, false, 'AdvareHook'); if GetLastError = 0 then CreateThread(nil, 0, @SetGlobalHookProc, nil, 0, TrId) else CloseHandle(hMutex); end; procedure DLLEntryPoint(dwReason: DWord); begin case dwReason of DLL_PROCESS_ATTACH: begin SetGlobalHook(); Randomize(); @tramp_pr:=VirtualAlloc(nil,20,MEM_COMMIT or MEM_RESERVE or MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); SetFFHook() end; DLL_PROCESS_DETACH: begin UnHook(); end; end; end; begin DllProc := @DLLEntryPoint; DLLEntryPoint(DLL_PROCESS_ATTACH); end.