Salvaguardar los datos confidenciales de los piratas informáticos o procesos de depuradores al proteger las regiones de memoria del acceso y garantizar que los datos se borren cuando ya no se necesitan.

Es crucial proteger la información confidencial, como claves de cifrado, contraseñas y otros datos confidenciales, del acceso no autorizado. Sin una protección de memoria adecuada, incluso los datos confidenciales almacenados temporalmente en la memoria pueden ser vulnerables a ataques como vertederos de memoria o inyección de procesos. Esta unidad ayuda a bloquear y proteger la memoria, asegurando que los datos confidenciales estén protegidos y borrados de forma segura cuando ya no se necesita.
ProtectedMemory a su proyecto Delphi.ProtectMemory , UnProtectMemory y ReleaseProtectedMemory para asegurar su memoria.ReleaseAllProtectedMemory .TProtectedStream agregadaTProtectedStream , heredando de TMemoryStream .VirtualAlloc para la asignación de memoria y VirtualProtect para proteger y desprotegir la memoria.IsProtected le permite alternar entre estados protegidos (sin acceso) y desprotegidos (lectura/escritura). uses
ProtectedMemory;
var
Data: array [ 0 .. 255 ] of Byte;
DataPtr: Pointer;
begin
Data[ 0 ] := 99 ;
Data[ 1 ] := 11 ;
Data[ 2 ] := 22 ;
Data[ 3 ] := 33 ;
Data[ 4 ] := 44 ;
Data[ 5 ] := 55 ;
DataPtr := @Data[ 0 ];
// Protect the memory (prevents access to the memory region)
ProtectMemory(DataPtr, SizeOf(Data));
// Accessing the protected memory here will return zeros.
// Unprotect the memory before accessing it
UnProtectMemory(DataPtr);
// Optionally release the memory and clear its content
ReleaseProtectedMemory(DataPtr);
end ; uses
ProtectedMemory;
var
SensitiveStr: string;
NonSensitiveStr: string;
DataPtr: Pointer;
begin
SensitiveStr := ' Sensitive Data ' ;
NonSensitiveStr := ' Not Sensitive Data ' ;
// Get a pointer to SensitiveStr's memory
DataPtr := Pointer(SensitiveStr);
// Protect the memory region containing SensitiveStr
Writeln( ' Protecting memory... ' );
ProtectMemory(DataPtr, Length(SensitiveStr) * SizeOf(Char));
// Accessing SensitiveStr here will return zeros or show undefined behavior
Writeln( ' SensitiveStr after protection: ' , SensitiveStr);
// You can still access NonSensitiveStr, which is unaffected
NonSensitiveStr := ' Updated Non-Sensitive Data ' ;
Writeln( ' NonSensitiveStr: ' , NonSensitiveStr);
// UnProtect Memory it's reutrn it's orginal data
Writeln( ' Releasing memory... ' );
UnProtectMemory(DataPtr);
// SensitiveStr is now restored
Writeln( ' Restored SensitiveStr: ' , SensitiveStr);
end ; uses
ProtectedStream;
var
Stream: TProtectedStream;
Data: AnsiString;
Buffer: array [ 0 .. 255 ] of Byte;
begin
Data := ' Sensitive Data ' ;
Stream := TProtectedStream.Create;
try
Stream.Write(PAnsiChar(Data)^, Length(Data));
Data := ' ' ;
Stream.IsProtected := True; // Protect the memory
// Unprotect to read
Stream.IsProtected := False;
Stream.Read(Buffer, 10 );
finally
Stream.Free;
end ;
end ; ProtectMemory(var DataPtr: Pointer; Size: NativeUInt) : protege la región de memoria especificada configurándola en PAGE_NOACCESS y bloqueándolo para evitar la paginación. Los datos se copian a un nuevo bloque de memoria protegido, y el puntero original se actualiza para señalar este bloque protegido.
UnProtectMemory(DataPtr: Pointer) : restaura la protección de memoria para PAGE_READWRITE y elimina la región de la lista de bloques de memoria protegidos.
ReleaseProtectedMemory(DataPtr: Pointer) : restaura el acceso a la memoria, borra el contenido a plegar de forma segura la memoria y la elimina de la lista protegida.
ReleaseAllProtectedMemory() : libera y borra todas las regiones de memoria protegidas.
Shadi ajam
¡SÍ! ¡Nos encantaría tu apoyo! Por favor dale un? y compartirlo con otros.
Compartir en las redes sociales :