Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define, DEP is ON in system

Tags:

delphi

dep

DelphiXe; Xp,Vista,Win7,WSrv2008R2;

enter image description here

0.DEP(Data Execution Prevention) CPU supported

Function isCpuDEP:bool; 
begin
Result:=... //???
end;

1.How to define, DEP is ON in system?

Function isEnableDEP:bool; // Win Xp comparable
begin
Result:=false;if isCpuDEP=false then exit;
Result:=... //???
end;

2.To define, that if DEP it is enabled, and also enabled for ALL programs and services?

Function isEnableDEPForAllProgram:bool;
begin
Result:=false;if isEnableDEP=false then exit;
Result:=... //???
end;

3.Get DEP program list?

Function GetDEPProgramList:TStringList;
begin
Result:=nil;if isEnableDEPForAllProgram=false then exit;
Result:=Tstringlist.Create;
Result:=... //???
end;
like image 785
Gu. Avatar asked Nov 30 '22 07:11

Gu.


1 Answers

The below uses GetProcessDEPPolicy for point (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;


For point (2), you can use GetSystemDEPPolicy in a similar fashion.

For point (3), you can enumerate processes and find out the ones running with DEP.

like image 67
Sertac Akyuz Avatar answered Dec 09 '22 15:12

Sertac Akyuz