一个游戏客户端文件的字节加解密代码,我花1000元请人解的,存在这,以后应该用得到。
代码
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;