Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SecureZeroMemory in Delphi

I understand there is a SecureZeroMemory function in C. The function implementation is defined in <WinnNT.h> as RtlSecureZeroMemory function.

QNS: How can SecureZeroMemory be used in Delphi? Did Delphi release a library that contains that function? I'm using Delphi 7. Windows.pas only has ZeroMemory but not SecureZeroMemory.

like image 804
seveleven Avatar asked Dec 28 '22 05:12

seveleven


2 Answers

As far as I understand, the only difference between ZeroMemory and SecureZeroMemory is SecureZeroMemory is implemented as an inline function, ensuring it won't be optimised out by the compiler.

I don't think Delphi performs the same level of compiler optimisation, so ZeroMemory calls shouldn't be optimised out.

like image 144
glob Avatar answered Dec 31 '22 14:12

glob


Since according to MSDN, SecureZeroMemory() is actually defined as the RtlSecureZeroMemory(), you can declare SecureZeroMemory() as follows:

  procedure SecureZeroMemory(_ptr: Pointer; cnt: Longint); external 'kernel32.dll' name 'RtlSecureZeroMemory';

SecureZeroMemory() is merely an alias of RtlSecureZeroMemory().

like image 22
Vantomex Avatar answered Dec 31 '22 13:12

Vantomex