德尔福; XP、Vista、Win7、WSrv2008R2;
0.DEP(数据执行保护)CPU支持
Function isCpuDEP:bool;
begin
Result:=... //???
end;
1.如何定义,DEP在系统中是ON?
Function isEnableDEP:bool; // Win Xp comparable
begin
Result:=false;if isCpuDEP=false then exit;
Result:=... //???
end;
2.要定义,如果 DEP 已启用,并且还为所有程序和服务启用?
Function isEnableDEPForAllProgram:bool;
begin
Result:=false;if isEnableDEP=false then exit;
Result:=... //???
end;
3.获取DEP程序列表?
Function GetDEPProgramList:TStringList;
begin
Result:=nil;if isEnableDEPForAllProgram=false then exit;
Result:=Tstringlist.Create;
Result:=... //???
end;
最佳答案
下面将 GetProcessDEPPolicy
用于点 (1):
type
TGetProcessDEPPolicy =
function(Process: THandle; out Flags: DWORD; out Permanent: Bool): Bool; stdcall;
const
PROCESS_DEP_ENABLE = $00000001;
PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION = $00000002;
procedure TForm1.Button1Click(Sender: TObject);
var
GetProcessDEPPolicy: TGetProcessDEPPolicy;
DEPFlags: DWORD;
IsPermanent: Bool;
begin
@GetProcessDEPPolicy :=
GetProcAddress(GetModuleHandle(kernel32), 'GetProcessDEPPolicy');
if Assigned(GetProcessDEPPolicy) then begin
if GetProcessDEPPolicy(GetCurrentProcess, DEPFlags, IsPermanent) then begin
if (DEPFlags and PROCESS_DEP_ENABLE) = PROCESS_DEP_ENABLE then
ShowMessage('DEP enabled')
else
ShowMessage('DEP disabled');
end else
raise EOSError.Create(SysErrorMessage(GetLastError));
end else
raise EOSError.Create('Unsupported OS');
end;
对于第 (2) 点,您可以以类似的方式使用
GetSystemDEPPolicy
。对于第 (3) 点,您可以枚举进程并找出使用 DEP 运行的进程。
关于delphi - 如何定义,DEP在系统中是ON,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7057636/