![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
procedure
EncryptMemory(Data: Pointer; Size: Cardinal);
procedure EncryptData( var A, B: DWORD);
var
_Constant, i: DWORD;
begin
_Constant : = 0 ;
for i : = 0 to 31 do
begin
_Constant : = _Constant - $61C88647;
A : = A + (((B shr 5 ) + $2B4805C2) xor ((B shl 4 ) + $98DFF541) xor (B + _Constant));
B : = B + (((A shr 5 ) + $D8144BA5) xor ((A shl 4 ) + $01AF979B) xor (A + _Constant));
end ;
end ;
var
i: Integer;
_Data1, _Data2: Dword;
begin
for I : = 0 to (Size div 8 ) - 1 do
begin
_Data1 : = Pdword(dword(Data) + (i * 8 ))^;
_Data2 : = Pdword(dword(Data) + (i * 8 ) + 4 )^;
EncryptData(_Data1, _Data2);
Pdword(dword(Data) + (i * 8 ))^ : = _Data1;
Pdword(dword(Data) + (i * 8 ) + 4 )^ : = _Data2;
end ;
end ;
procedure DecryptMemory(Data: Pointer; Size: Cardinal);
procedure DecryptData( var A, B: DWORD);
var
_Constant, i: DWORD;
begin
_Constant : = $C6EF3720;
for i : = 0 to 31 do
begin
B : = B - (((A shr 5 ) + $D8144BA5) xor ((A shl 4 ) + $01AF979B) xor (A + _Constant));
A : = A - (((B shr 5 ) + $2B4805C2) xor ((B shl 4 ) + $98DFF541) xor (B + _Constant));
_Constant : = _Constant + $61C88647;
end ;
end ;
var
i: Integer;
_Data1, _Data2: Dword;
begin
for I : = 0 to (Size div 8 ) - 1 do
begin
_Data1 : = Pdword(dword(Data) + (i * 8 ))^;
_Data2 : = Pdword(dword(Data) + (i * 8 ) + 4 )^;
DecryptData(_Data1, _Data2);
Pdword(dword(Data) + (i * 8 ))^ : = _Data1;
Pdword(dword(Data) + (i * 8 ) + 4 )^ : = _Data2;
end ;
end ;
// 使用
procedure TfrmMain.btn1Click(Sender: TObject);
var
memStream: TMemoryStream;
begin
memStream : = TMemoryStream.Create;
memStream.LoadFromFile( ' .\732 ' );
DecryptMemory(memStream.Memory, memStream.Size);
memStream.SaveToFile( ' .\732_u ' );
FreeAndNil(memStream);
end ;
procedure EncryptData( var A, B: DWORD);
var
_Constant, i: DWORD;
begin
_Constant : = 0 ;
for i : = 0 to 31 do
begin
_Constant : = _Constant - $61C88647;
A : = A + (((B shr 5 ) + $2B4805C2) xor ((B shl 4 ) + $98DFF541) xor (B + _Constant));
B : = B + (((A shr 5 ) + $D8144BA5) xor ((A shl 4 ) + $01AF979B) xor (A + _Constant));
end ;
end ;
var
i: Integer;
_Data1, _Data2: Dword;
begin
for I : = 0 to (Size div 8 ) - 1 do
begin
_Data1 : = Pdword(dword(Data) + (i * 8 ))^;
_Data2 : = Pdword(dword(Data) + (i * 8 ) + 4 )^;
EncryptData(_Data1, _Data2);
Pdword(dword(Data) + (i * 8 ))^ : = _Data1;
Pdword(dword(Data) + (i * 8 ) + 4 )^ : = _Data2;
end ;
end ;
procedure DecryptMemory(Data: Pointer; Size: Cardinal);
procedure DecryptData( var A, B: DWORD);
var
_Constant, i: DWORD;
begin
_Constant : = $C6EF3720;
for i : = 0 to 31 do
begin
B : = B - (((A shr 5 ) + $D8144BA5) xor ((A shl 4 ) + $01AF979B) xor (A + _Constant));
A : = A - (((B shr 5 ) + $2B4805C2) xor ((B shl 4 ) + $98DFF541) xor (B + _Constant));
_Constant : = _Constant + $61C88647;
end ;
end ;
var
i: Integer;
_Data1, _Data2: Dword;
begin
for I : = 0 to (Size div 8 ) - 1 do
begin
_Data1 : = Pdword(dword(Data) + (i * 8 ))^;
_Data2 : = Pdword(dword(Data) + (i * 8 ) + 4 )^;
DecryptData(_Data1, _Data2);
Pdword(dword(Data) + (i * 8 ))^ : = _Data1;
Pdword(dword(Data) + (i * 8 ) + 4 )^ : = _Data2;
end ;
end ;
// 使用
procedure TfrmMain.btn1Click(Sender: TObject);
var
memStream: TMemoryStream;
begin
memStream : = TMemoryStream.Create;
memStream.LoadFromFile( ' .\732 ' );
DecryptMemory(memStream.Memory, memStream.Size);
memStream.SaveToFile( ' .\732_u ' );
FreeAndNil(memStream);
end ;