procedure DecryptLevel2(lpSource: Pointer);
var
Offset: Byte;
ContentSize: Word;
PBuffer: PByte;
Condition, Condition2: Byte;
begin
Offset := GetHdrSize(lpSource) +2; // Counter = 2
ContentSize := GetContentSize(lpSource);
PBuffer := PByte(lpSource) + Offset;
if not (ContentSize >= 4) then
Exit // No Decryption for this size
else
if not (ContentSize >= 8) then
begin
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ xor $85; //09CB6897
Condition := SAR(PByte(PBuffer +3)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +3)^, 2) and 1;
if (Condition = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
if (Condition2 = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
Condition := SAR(PByte(PBuffer +7)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +7)^, 5) and 1;
if (Condition = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $DF //09BFCCF4
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $20; //09CB6356
if (Condition2 = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $EF //09BFCD36
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $10;
end
else
if not (ContentSize >= 16) then
begin
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ xor $85; //09CB6897
Condition := SAR(PByte(PBuffer +3)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +3)^, 2) and 1;
if (Condition = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
if (Condition2 = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
Condition := SAR(PByte(PBuffer +7)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +7)^, 5) and 1;
if (Condition = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $DF //09BFCCF4
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $20; //09CB6356
if (Condition2 = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $EF //09BFCD36
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $10;
end
else
if not (ContentSize >= 32) then
begin
PByte(PBuffer +$1F)^ := PByte(PBuffer +$1F)^ xor $7D;
Condition := PByte(PBuffer +$10)^;
PByte(PBuffer +$10)^ := PByte(PBuffer +$18)^;
PByte(PBuffer +$18)^ := Condition;
Condition2 := (PByte(PBuffer +$1A)^ shr 5);
PByte(PBuffer)^ := PByte(PBuffer +$1A)^ or Condition2;
PByte(PBuffer +$1A)^ := (PByte(PBuffer)^ shl 3);
Condition := PByte(PBuffer +3)^;
PByte(PBuffer +3)^ := PByte(PBuffer +$18)^;
PByte(PBuffer +$18)^ := Condition;
Condition := (PByte(PBuffer +4)^ shl 2);
PByte(PBuffer +4)^ := PByte(PBuffer +4)^ shr 6;
PByte(PBuffer +4)^ := (PByte(PBuffer +4)^ or Condition);
Condition := (PByte(PBuffer +2)^ shr 5) and 1;
Condition2 := (PByte(PBuffer +2)^ shr 2) and 1;
if (Condition2 = 0) then
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ and $DF //09CB75DE
else
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ or $20; //09CB75D0
if (Condition = 0) then
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ and $FB //09BFD34A
else
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ or 4; //09CB75B7
Condition := (PByte(PBuffer +6)^ shr 7) and 1; //8bit
Condition2 := (PByte(PBuffer +6)^ shr 6) and 1; //7bit
if (Condition = 0) then
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ and $BF //09CB74CB
else
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ or $40; //09CB74BD
if (Condition2 = 0) then
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ and $7F //09CB755F
else
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ or $80; //$FFFFFF7F
PByte(PBuffer +$11)^ := PByte(PBuffer +$11)^ xor $AC;
Condition := (PByte(PBuffer +$15)^ shr 2) and 1;
Condition2 := (PByte(PBuffer +$15)^ shr 2) and 1;
if (Condition = 0) then
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ and $FB //9CB740B
else
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ or 4;
if (Condition2 = 0) then
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ and $DF
else
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ or 4;
PByte(PBuffer +1)^ := PByte(PBuffer +1)^ xor $1A; //09CB7290
end
else
begin
Condition := PByte(PBuffer +$C)^ shl 6;
Condition2 := PByte(PBuffer +$C)^ shr 2;
PByte(PBuffer +$C)^ := (Condition or Condition2);
Condition := PByte(PBuffer +$A)^ shr 1 and 1;
Condition2 := PByte(PBuffer +$A)^ shr 1 and 1;
if (Condition = 0) then
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ and $FD //09BFD1E6
else
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ or $20;
if (Condition2 = 0) then
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ and $FD //09BFD251
else
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ or 2; //09BFD242
PByte(PBuffer +8)^ := PByte(PBuffer +8)^ xor $DF;
PByte(PBuffer)^ := PByte(PBuffer)^ xor $A;
Condition := PByte(PBuffer +$B)^;
PByte(PBuffer +$B)^ := PByte(PBuffer +2)^;
PByte(PBuffer +$B)^ := Condition;
end;
end;
procedure EncryptLevel2(lpSource: Pointer); //1.14.17
var
Offset: Byte;
ContentSize: Word;
PBuffer: PByte;
Condition, Condition2: Byte;
begin
Offset := GetHdrSize(lpSource) +2; // Counter = 2
ContentSize := GetContentSize(lpSource);
PBuffer := PByte(lpSource) + Offset;
if not (ContentSize >= 4) then
Exit // No Encryption for this size
else
if not (ContentSize >= 8) then
begin
PByte(PBuffer +2)^ := ((PByte(PBuffer +2)^ shr 2) or (PByte(PBuffer +2)^ shl 6)) xor $91;
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ xor $F6; //09CB62E6
end
else
if not (ContentSize >= 16) then //006681FB
begin
Condition := SAR(PByte(PBuffer +7)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +7)^, 5) and 1;
if (Condition = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $DF //09BFCCF4
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $20; //09CB6356
if (Condition2 = 0) then
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ and $EF //09BFCD36
else
PByte(PBuffer +7)^ := PByte(PBuffer +7)^ or $10;
Condition := SAR(PByte(PBuffer +3)^, 4) and 1;
Condition2 := SAR(PByte(PBuffer +3)^, 2) and 1;
if (Condition = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
if (Condition2 = 0) then
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ and $EF //09BFCD94
else
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ or $10; //09CB6573
PByte(PBuffer +3)^ := PByte(PBuffer +3)^ xor $85; //09CB6897
end
else
if not (ContentSize >= 32) then // Login packet
begin
PBuffer := PByte(lpSource) + Offset;
PByte(PBuffer +1)^ := PByte(PBuffer +1)^ xor $1A; //09CB7290
Condition := SAR(PByte(PBuffer +$15)^, 2) and 1;
Condition2 := SAR(PByte(PBuffer +$15)^, 2) and 1;
if (Condition = 0) then
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ and $FB //9CB740B
else
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ or 4;
if (Condition2 = 0) then
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ and $DF
else
PByte(PBuffer +$15)^ := PByte(PBuffer +$15)^ or 4;
Condition := SAR(PByte(PBuffer +6)^, 7) and 1;
Condition2 := SAR(PByte(PBuffer +6)^, 6) and 1;
if (Condition = 0) then
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ and $BF //09CB74CB
else
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ or $40; //09CB74BD
if (Condition2 = 0) then
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ and $7F //09CB755F
else
PByte(PBuffer +6)^ := PByte(PBuffer +6)^ or $80; //$FFFFFF7F
PByte(PBuffer +$11)^ := PByte(PBuffer +$11)^ xor $AC;
Condition := SAR(PByte(PBuffer +2)^, 5) and 1;
Condition2 := SAR(PByte(PBuffer +2)^, 2) and 1;
if (Condition = 0) then
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ and $FB //09BFD34A
else
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ or 4; //09CB75B7
if (Condition2 = 0) then
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ and $DF //09CB75DE
else
PByte(PBuffer +2)^ := PByte(PBuffer +2)^ or $20; //09CB75D0
Condition := SAR(PByte(PBuffer +4)^, 2);
PByte(PBuffer +4)^ := PByte(PBuffer +4)^ shl 6;
PByte(PBuffer +4)^ := (PByte(PBuffer +4)^ or Condition);
Condition := PByte(PBuffer +$18)^;
PByte(PBuffer +$18)^ := PByte(PBuffer +3)^;
PByte(PBuffer +3)^ := Condition;
Condition := SAR(PByte(PBuffer +$1A)^, 3); //09CB7680
Condition2 := (PByte(PBuffer +$1A)^ shl 5);
PByte(PBuffer)^ := (Condition or Condition2);
PByte(PBuffer +$1A)^ := Condition;
Condition := PByte(PBuffer +$10)^;
PByte(PBuffer +$10)^ := PByte(PBuffer +$18)^;
PByte(PBuffer +$18)^ := Condition;
PByte(PBuffer +$1F)^ := PByte(PBuffer +$1F)^ xor $7D;
end
else
begin
Condition := PByte(PBuffer +2)^;
PByte(PBuffer +2)^ := PByte(PBuffer +$B)^;
PByte(PBuffer +$B)^ := Condition;
PByte(PBuffer +8)^ := PByte(PBuffer +8)^ xor $DF;
PByte(PBuffer)^ := PByte(PBuffer)^ xor $A;
Condition := SAR(PByte(PBuffer +$A)^, 1) and 1;
Condition2 := SAR(PByte(PBuffer +$A)^, 5) and 1;
if (Condition = 0) then
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ and $FD //09BFD1E6
else
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ or $20;
if (Condition2 = 0) then
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ and $FD //09BFD251
else
PByte(PBuffer +$A)^ := PByte(PBuffer +$A)^ or 2; //09BFD242
Condition := SAR(PByte(PBuffer +$C)^, 6);
Condition2 := PByte(PBuffer +$C)^ shl 2;
PByte(PBuffer +$C)^ := (Condition or Condition2);
end;
end;