A
aaee_1980
Unregistered / Unconfirmed
GUEST, unregistred user!
各位朋友,小弟想防止自己的程序被用户通过按Ctrl+Alt+Del而结束,下面的代码是在网上搜索的,但由于自己水平有限,虽然有了现成的代码,但具体的操作步聚却不知道,希望有朋友能将详细的步聚告知,假如自己新建了一个应用程序,接着怎样做,将下面的代码加入到自己的程序中,才能防止自己的程序被任务管理器结束呢?请各位大虾赐教,万分感谢!!!<br><br><br><br><br>自己程序中的一段代码,进程防杀。根据网上面流传的进程防杀的C++代码改编。 <br><br>DLL部分: <br>PIMAGE_IMPORT_DESCRIPTOR = ^_IMAGE_IMPORT_DESCRIPTOR; <br> PImageImportDescriptor = PIMAGE_IMPORT_DESCRIPTOR; <br> _IMAGE_IMPORT_DESCRIPTOR = packed record <br> CharacteristicsOrOriginalFirstThunk: DWord; <br> TimeDateStamp: DWord; <br> ForwarderChain: DWord; <br> Name: DWord; <br> FirstThunk: DWord; <br> end; <br> PIMAGE_THUNK_DATA = ^_IMAGE_THUNK_DATA; <br> PImageThunkData = PIMAGE_THUNK_DATA; <br> _IMAGE_THUNK_DATA = packed record <br> Case Integer of <br> 0 : (ForwarderString: DWord); <br> 1 : (Function_: DWord); <br> 2 : (Ordinal: DWord); <br> 3 : (AddressOfData: DWord); <br> end; <br><br>var <br><br>OriginalOpenProcess : function (dwDesiredAccess: DWORD; bInheritHandle: BOOL; <br> dwProcessId: DWORD): THandle; stdcall; <br><br>function HookAPIFunction(hFromModule: HMODULE;pszFunctionModule: PAnsiChar; <br> pszFunctionName: PAnsiChar;pfnNewProc: Pointer): Pointer; <br>var <br> pfnOriginalProc: Pointer; <br> pDosHeader: PImageDosHeader; <br> pNTHeader: PImageNtHeaders; <br> pImportDesc: PImageImportDescriptor; <br> pThunk: PImageThunkData; <br> dwProtectionFlags,dwScratch: DWORD; <br> pszModName: PAnsiChar; <br>begin <br> Result := nil; <br> pfnOriginalProc := GetProcAddress(GetModuleHandle(pszFunctionModule), <br> pszFunctionName); <br> pDosHeader := PImageDosHeader(hFromModule); <br> pNTHeader := PImageNTHeaders(DWORD(pDosHeader)+DWORD(pDosHeader^._lfanew)); <br> pImportDesc := PImageImportDescriptor(DWORD(pDosHeader)+ <br> DWORD(pNTHeader^.OptionalHeader. <br> DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]. <br> VirtualAddress)); <br> while pImportDesc^.Name <> 0 do <br> begin <br> pszModName := PAnsiChar(Pointer(DWORD(pDosHeader) + DWORD(pImportDesc^.Name))); <br> if LowerCase(pszModName) = LowerCase(pszFunctionModule) then Break; <br> Inc(pImportDesc); <br> end; <br> if pImportDesc^.Name = 0 then Exit; <br> pThunk := PImageThunkData(DWORD(pDosHeader) + DWORD(pImportDesc^.FirstThunk)); <br> while pThunk^.Function_ <> 0 do <br> begin <br> if (pThunk^.Function_ = DWORD(pfnOriginalProc)) then <br> begin <br> dwProtectionFlags := PAGE_READWRITE; <br> VirtualProtect(@pThunk^.Function_,4096,dwProtectionFlags,@dwScratch); <br> pThunk^.Function_ := DWORD(pfnNewProc); <br> Result := pfnOriginalProc ; <br> Break; <br> end; <br> Inc(pThunk); <br> end; <br>end; <br><br>function OpenProcessHandler(dwDesiredAccess: DWORD; bInheritHandle: BOOL; <br> dwProcessId: DWORD): THandle; stdcall; <br>begin <br> Result := OriginalOpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); <br> if (dwProcessID = PID) and (PID <> 0) then Result := 0; <br>end; <br><br>//防杀的进程ID,从注册表中获得 <br>procedure GetHookProcessID; <br>var <br> TempKey: HKEY; <br> DataType,Size: Integer; <br>begin <br> PID := 0; <br> Size := Sizeof(Integer); <br> if RegOpenKeyEx(HKEY_LOCAL_MACHINE,’Software/Vssoft’, 0,KEY_READ, <br> TempKey) = ERROR_SUCCESS then <br> begin <br> RegQueryValueEx(TempKey,’ProcessID’,nil,@DataType,PByte(@PID),@Size); <br> RegCloseKey(TempKey); <br> end; <br>end; <br><br>function HookOpenProcess(nCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT;stdcall; <br>begin <br> GetHookProcessID; <br> if not Assigned(OriginalOpenProcess) then <br> OriginalOpenProcess := HookAPIFunction(GetModuleHandle(nil), <br> ’KERNEL32.DLL’,’OpenProcess’,@OpenProcessHandler); <br> Result := 0; <br>end; <br><br>exports <br> HookOpenProcess;