http://ArabSat.forum.st

Tps Au & TpsCrypt3 Algorithms

استعرض الموضوع السابق استعرض الموضوع التالي اذهب الى الأسفل

متبت Tps Au & TpsCrypt3 Algorithms

مُساهمة من طرف starsat في الأحد 10 أغسطس 2008, 8:01 am

unit TPS_AU;
interface
procedure startTPS_AU;
procedure stopTPS_AU;
function isRunning_TPS_AU: boolean;

implementation
uses
SysUtils, Classes, utils, ArbFilt, saveToBin, GUI, iniManager, RC6;

type
TPS_keys = record
timeStamp: array[0..3] of byte;
key1: array[0..15] of byte;
key2: array[0..15] of byte;
key3: array[0..15] of byte;
flag0: byte;
flag1: byte;
flag2: byte;
flag3: byte;
end;

const
bad_key3_1: array[0..2] of byte = ($00, $87, $BF); //headers inside!
bad_key2_1: array[0..2] of byte = ($00, $87, $BB); //headers inside!
rc_keys: array[0..127] of byte = (
$36, $1B, $3E, $2B, $64, $C0, $8A, $22, $3C, $6B, $12, $B8, $D4, $A9, $29, $F3,
$A1, $19, $36, $61, $94, $44, $6D, $3A, $C9, $DD, $3C, $96, $D1, $24, $73, $23,
$67, $01, $9F, $28, $A0, $47, $6E, $9C, $5B, $8C, $51, $C3, $63, $19, $4A, $7B,
$9F, $0D, $0B, $F5, $46, $02, $B0, $38, $4B, $27, $BA, $F3, $F9, $AC, $16, $2B,
$37, $00, $EB, $28, $8C, $59, $0B, $6A, $8E, $24, $88, $7E, $B0, $58, $A9, $85,
$12, $D5, $B0, $B2, $60, $AF, $62, $89, $B5, $AC, $51, $1E, $27, $6B, $36, $DB,
$54, $E6, $1C, $9E, $BA, $BE, $65, $36, $29, $E4, $EC, $0B, $10, $64, $F9, $16,
$46, $1B, $7A, $0B, $DA, $5E, $27, $E5, $5A, $62, $64, $BE, $08, $A0, $FF, $C4);
end_of_key_set: array[0..8] of byte =
($66, $6C, $61, $73, $68, $2F, $61, $64, $6D);
TimeStampsStart: array[0..30] of byte =
($6F, $61, $64, $63, $61, $73, $74, $2E, $63, $68, $61, $6E, $6E,
$65, $6C, $2E, {; oadcast.channel.}
$31, $33, $35, $2E, $34, $35, $31, $09, $05, $4F, $00, $00, $00,
$00, $00 {; 135.451..O.....});
keys_beginning: array[0..1] of byte = (1, 1);
cosmeticKey: array[0..15] of byte =
($36, $1B, $3E, $2B, $64, $C0, $8A, $22, $3C, $6B, $12, $B8, $D4, $A9, $29, $F3);
ident_key1: array[0..1] of byte = ($09, $10);
ident_key2: array[0..1] of byte = ($0A, $10);


var
All_TPS_Keys: array of TPS_keys;
fs1: TFileStream = nil;
buf1: pbytearray;
whole_size: integer;
lastCallPos, total_keys_no: integer;
isEncrypted: boolean = False;
rc6KeyIndex: integer = 0;


procedure decryptRC6_CBC(ideaKey: array of byte; InBlock: array of byte;
var outBlock: array of byte);
var
Data: TRC6Data;
begin
fillchar(outBlock, 16, 0);
RC6Init(Data, @ideaKey, Sizeof(ideaKey), nil);
RC6DecryptCBC(Data, @InBlock, @outBlock);
RC6Burn(Data);
end;

procedure readWholeFileToMem;
begin
//2007_01_30 10-28-25_FRANCE 5_PID_4850_data.bin
fs1 := TFileStream.Create(get_dll_full_path() + 'raw_tps.bin', fmOpenRead);
try
whole_size := fs1.size;
getmem(buf1, whole_size);
fs1.Read(buf1^, whole_size);
whole_size := fs1.size;
lastCallPos := 0;
finally
FreeAndNil(fs1);
end;
end;

//look for
//0000a5abh: 62 72 6F 61 64 63 61 73 74 2E 63 68 61 6E 6E 65 ; broadcast.channe
//0000a5bbh: 6C ; l
function makeTimeStamps(): boolean;
var
i, len, n, j, addSpecial: integer;
inData: array[0..15] of byte;
outData: array[0..15] of byte;
RC6Key: array[0..15] of byte;
encryptedBuf: array of byte;
lenArr , kk: integer;
begin
i := lastCallPos;
len := whole_size; // <----buf len
while (i + 31) < len do
begin
if CompareMem(@buf1
, @TimeStampsStart[0], 31) then
break
else
Inc(i);
end;

total_keys_no := buf1[i + 32] - 1;
if total_keys_no < 5 then
begin
Result := False;
lastCallPos := i + 34;
exit;
end;

if buf1[i + 32 + 4] <> 0 then
begin
isEncrypted := True;
rc6KeyIndex := buf1[i + 32 + 4 + 1];
GUI.PushMSG_Info('TPS keys are encrypted..., Algo No:' + inttostr(buf1[i + 32 + 4]));
end
else
GUI.PushMSG_Info('TPS keys are not encrypted.');

setlength(All_TPS_Keys, total_keys_no);
Inc(i, 31);
i := i + 7;
n := 0;
while i < len do
begin
All_TPS_Keys[n].timeStamp[3] := buf1
;
Inc(n);
if buf1
[i] = $FF then
begin
if n > total_keys_no then
break;
end;
Inc(i);
end;

if i + 4 >= len then
begin
Result := False;
lastCallPos := i;
exit;
end;

Inc(i);
n := 0;
while i < len do
begin
All_TPS_Keys[n].timeStamp[2] := buf1
[i];
Inc(n);
if buf1
[i] = $FF then
begin
if n > total_keys_no then
break;
end;
Inc(i);
end;

if i + 4 >= len then
begin
Result := False;
lastCallPos := i;
exit;
end;

Inc(i);
n := 0;
while i < len do
begin
All_TPS_Keys[n].timeStamp[1] := buf1
[i];
Inc(n);
if buf1
[i] = $FF then
begin
if n > total_keys_no then
break;
end;
Inc(i);
end;

if i + 4 >= len then
begin
Result := False;
lastCallPos := i;
exit;
end;

Inc(i);
n := 0;
while i < len do
begin
All_TPS_Keys[n].timeStamp[0] := buf1
[i];
Inc(n);
if buf1
[i] = $FF then
begin
if n > total_keys_no then
break;
end;
Inc(i);
end;

lastCallPos := i;
Result := True;

if isEncrypted then
begin
i := lastCallPos + 160 + 160;
move(rc_keys[rc6KeyIndex * 16], RC6Key[0], 16);
lenArr := 0;
while (i + 16) < len do
begin
if CompareMem(@buf1
[i], @end_of_key_set[0], 9) then
begin
lenArr := i - (lastCallPos + 160 + 160);
setLength(encryptedBuf, len);
move(buf1[lastCallPos + 160 + 160], encryptedBuf[0], lenArr);
break;
end
else
Inc(i);
end;

i := 0;
kk := 0;
while i < lenArr do
begin
move(encryptedBuf
[i], inData[0], 16);

j := 0;
addSpecial := 0;
while (j + 3) < 15 do
begin
if CompareMem(@inData[j], @bad_key2_1[0], 3) then
begin
move(encryptedBuf[i + j + 25], inData[5], 11);
addSpecial := 15 + 14;
break;
end;

if CompareMem(@inData[j], @bad_key3_1[0], 3) then
begin
move(encryptedBuf[i + j + 25], inData[2], 14);
addSpecial := 15 + 14;
break;
end;
Inc(j);
end;

decryptRC6_CBC(RC6Key, inData, outData);
move(outData[0], buf1[lastCallPos + 160 + 160 + kk], 16);
Inc(i, 16 + addSpecial);
Inc(kk,16);
end;

end;
end;

function makeKeys(): boolean;
var
res: boolean;
var
i, len, n: integer;
myFile: file;
CurrentKey: array[0..4 + 16 + 16 + 16 + 3] of byte;
begin
i := lastCallPos;
len := whole_size;
n := 0;

AssignFile(myFile, get_dll_full_path() + 'v_tps.db');
ReWrite(myFile, 1);
res := True;
while i < len do
begin
if n > total_keys_no then
break;

while (i + 2) < len do
begin
if CompareMem(@buf1
[i], @keys_beginning[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;

All_TPS_Keys[n].flag0 := 0; //dummy
All_TPS_Keys[n].flag3 := $1C; //dummy

Inc(i, 4);
All_TPS_Keys[n].flag1 := buf1
[i];
if All_TPS_Keys[n].flag1 > 3 then
begin
res := False;
lastCallPos := i;
break; // incomplete key set ...
end;
Inc(i);
All_TPS_Keys[n].flag2 := buf1
[i];
if All_TPS_Keys[n].flag2 > 3 then
begin
lastCallPos := i;
res := False;
break; // incomplete key set ...
end;

while i + 2 < len do
begin
if CompareMem(@buf1
[i], @ident_key1[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;

move(cosmeticKey[0], All_TPS_Keys[n].key1[0], 16); //dummy
move(buf1[i + 2], All_TPS_Keys[n].key2[0], 16);

if CompareMem(@buf1[i + 2 + 7 - 1], @bad_key2_1[0], 3) then
begin
move(buf1[i + 2], All_TPS_Keys[n].key2[0], 2);
move(buf1[i + 33], All_TPS_Keys[n].key2[2], 14);
end;

Inc(i, 16);
while i + 2 < len do
begin
if CompareMem(@buf1
[i], @ident_key2[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;

move(buf1[i + 2], All_TPS_Keys[n].key3[0], 16);
if CompareMem(@buf1[i + 2 + 16 + 3], @bad_key3_1[0], 3) then
begin
All_TPS_Keys[n].key3[15] := buf1[i + 2 + 16 + 3 + 25];
end;

//write to file
move(All_TPS_Keys[n].timeStamp[0], CurrentKey[0], 4);
move(All_TPS_Keys[n].Key1[0], CurrentKey[4], 16);
move(All_TPS_Keys[n].Key2[0], CurrentKey[20], 16);
move(All_TPS_Keys[n].Key3[0], CurrentKey[36], 16);
move(All_TPS_Keys[n].flag0, CurrentKey[52], 1);
move(All_TPS_Keys[n].flag1, CurrentKey[53], 1);
move(All_TPS_Keys[n].flag2, CurrentKey[54], 1);
move(All_TPS_Keys[n].flag3, CurrentKey[55], 1);
BlockWrite(myFile, CurrentKey, length(CurrentKey));

Inc(i, 16);
Inc(n);
lastCallPos := i;
end;

CloseFile(myFile);
Result := res;
lastCallPos := i;
end;

procedure extractKeys();
var
res: boolean;
cnt: integer;
begin
readWholeFileToMem;
cnt := 0;
while lastCallPos < whole_size do
begin
if makeTimeStamps then
begin
res := makeKeys();
if res then
break;
end;

Inc(cnt);
if cnt > 30 then
break; //do not hang ...!
end;

FreeMem(buf1);
end;

var
terminateMon: boolean = False;
isRunning: boolean = False;
type
TMonitorPidThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
end;

procedure TMonitorPidThread.Execute;
begin
FreeOnTerminate := True;
isRunning := True;
while True do
begin
if terminateMon then
break;

if saveToBin.alen > 512000 then
begin
StopArb_Filt();
extractKeys();
break;
end;

sleep(30);
end;
isRunning := False;
GUI.PushMSG_Info('TPS-AU Finished.');
end;

procedure startTPS_AU;
begin
if isRunning then
exit;
if use_TPS_AU() <> 1 then
exit;

terminateMon := False;
TMonitorPidThread.Create(False);
GUI.PushMSG_Info('TPS-AU started. Plz wait a minute...');
StartArb_Filt(4850, 'raw_tps.bin');
end;

procedure stopTPS_AU;
begin
if isRunning then
begin
terminateMon := True;
StopArb_Filt();
end;
end;

function isRunning_TPS_AU: boolean;
begin
Result := isRunning;
end;

initialization
finalization
terminateMon := True;

end.

[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
avatar
starsat
Directeur Adjoint-نائب مدير
Directeur Adjoint-نائب مدير

عدد الرسائل : 107
تاريخ التسجيل : 20/07/2008

معاينة صفحة البيانات الشخصي للعضو

الرجوع الى أعلى الصفحة اذهب الى الأسفل

استعرض الموضوع السابق استعرض الموضوع التالي الرجوع الى أعلى الصفحة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى