Kod:
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_***s = record
timeStamp: array[0..3] of byte;
***1: array[0..15] of byte;
***2: array[0..15] of byte;
***3: array[0..15] of byte;
flag0: byte;
flag1: byte;
flag2: byte;
flag3: byte;
end;
const
bad_***3_1: array[0..2] of byte = ($00, $87, $BF); //headers inside!
bad_***2_1: array[0..2] of byte = ($00, $87, $BB); //headers inside!
rc_***s: 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_***_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.....});
***s_beginning: array[0..1] of byte = (1, 1);
cosmetic***: array[0..15] of byte =
($36, $1B, $3E, $2B, $64, $C0, $8A, $22, $3C, $6B, $12, $B8, $D4, $A9, $29, $F3);
ident_***1: array[0..1] of byte = ($09, $10);
ident_***2: array[0..1] of byte = ($0A, $10);
var
All_TPS_***s: array of TPS_***s;
fs1: TFileStream = nil;
buf1: pbytearray;
whole_size: integer;
lastCallPos, total_***s_no: integer;
isEncrypted: boolean = False;
rc6***Index: integer = 0;
procedure decryptRC6_CBC(idea***: array of byte; InBlock: array of byte;
var outBlock: array of byte);
var
Data: TRC6Data;
begin
fillchar(outBlock, 16, 0);
RC6Init(Data, @idea***, Sizeof(idea***), 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;
RC6***: 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[i], @TimeStampsStart[0], 31) then
break
else
Inc(i);
end;
total_***s_no := buf1[i + 32] - 1;
if total_***s_no < 5 then
begin
Result := False;
lastCallPos := i + 34;
exit;
end;
if buf1[i + 32 + 4] <> 0 then
begin
isEncrypted := True;
rc6***Index := buf1[i + 32 + 4 + 1];
GUI.PushMSG_Info('TPS ***s are encrypted..., Algo No:' + inttostr(buf1[i + 32 + 4]));
end
else
GUI.PushMSG_Info('TPS ***s are not encrypted.');
setlength(All_TPS_***s, total_***s_no);
Inc(i, 31);
i := i + 7;
n := 0;
while i < len do
begin
All_TPS_***s[n].timeStamp[3] := buf1[i];
Inc(n);
if buf1[i] = $FF then
begin
if n > total_***s_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_***s[n].timeStamp[2] := buf1[i];
Inc(n);
if buf1[i] = $FF then
begin
if n > total_***s_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_***s[n].timeStamp[1] := buf1[i];
Inc(n);
if buf1[i] = $FF then
begin
if n > total_***s_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_***s[n].timeStamp[0] := buf1[i];
Inc(n);
if buf1[i] = $FF then
begin
if n > total_***s_no then
break;
end;
Inc(i);
end;
lastCallPos := i;
Result := True;
if isEncrypted then
begin
i := lastCallPos + 160 + 160;
move(rc_***s[rc6***Index * 16], RC6***[0], 16);
lenArr := 0;
while (i + 16) < len do
begin
if CompareMem(@buf1[i], @end_of_***_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_***2_1[0], 3) then
begin
move(encryptedBuf[i + j + 25], inData[5], 11);
addSpecial := 15 + 14;
break;
end;
if CompareMem(@inData[j], @bad_***3_1[0], 3) then
begin
move(encryptedBuf[i + j + 25], inData[2], 14);
addSpecial := 15 + 14;
break;
end;
Inc(j);
end;
decryptRC6_CBC(RC6***, inData, outData);
move(outData[0], buf1[lastCallPos + 160 + 160 + kk], 16);
Inc(i, 16 + addSpecial);
Inc(kk,16);
end;
end;
end;
function make***s(): boolean;
var
res: boolean;
var
i, len, n: integer;
myFile: file;
Current***: 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_***s_no then
break;
while (i + 2) < len do
begin
if CompareMem(@buf1[i], @***s_beginning[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;
All_TPS_***s[n].flag0 := 0; //dummy
All_TPS_***s[n].flag3 := $1C; //dummy
Inc(i, 4);
All_TPS_***s[n].flag1 := buf1[i];
if All_TPS_***s[n].flag1 > 3 then
begin
res := False;
lastCallPos := i;
break; // incomplete *** set ...
end;
Inc(i);
All_TPS_***s[n].flag2 := buf1[i];
if All_TPS_***s[n].flag2 > 3 then
begin
lastCallPos := i;
res := False;
break; // incomplete *** set ...
end;
while i + 2 < len do
begin
if CompareMem(@buf1[i], @ident_***1[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;
move(cosmetic***[0], All_TPS_***s[n].***1[0], 16); //dummy
move(buf1[i + 2], All_TPS_***s[n].***2[0], 16);
if CompareMem(@buf1[i + 2 + 7 - 1], @bad_***2_1[0], 3) then
begin
move(buf1[i + 2], All_TPS_***s[n].***2[0], 2);
move(buf1[i + 33], All_TPS_***s[n].***2[2], 14);
end;
Inc(i, 16);
while i + 2 < len do
begin
if CompareMem(@buf1[i], @ident_***2[0], 2) then
break
else
Inc(i);
end;
if i + 16 >= len then
break;
move(buf1[i + 2], All_TPS_***s[n].***3[0], 16);
if CompareMem(@buf1[i + 2 + 16 + 3], @bad_***3_1[0], 3) then
begin
All_TPS_***s[n].***3[15] := buf1[i + 2 + 16 + 3 + 25];
end;
//write to file
move(All_TPS_***s[n].timeStamp[0], Current***[0], 4);
move(All_TPS_***s[n].***1[0], Current***[4], 16);
move(All_TPS_***s[n].***2[0], Current***[20], 16);
move(All_TPS_***s[n].***3[0], Current***[36], 16);
move(All_TPS_***s[n].flag0, Current***[52], 1);
move(All_TPS_***s[n].flag1, Current***[53], 1);
move(All_TPS_***s[n].flag2, Current***[54], 1);
move(All_TPS_***s[n].flag3, Current***[55], 1);
BlockWrite(myFile, Current***, length(Current***));
Inc(i, 16);
Inc(n);
lastCallPos := i;
end;
CloseFile(myFile);
Result := res;
lastCallPos := i;
end;
procedure extract***s();
var
res: boolean;
cnt: integer;
begin
readWholeFileToMem;
cnt := 0;
while lastCallPos < whole_size do
begin
if makeTimeStamps then
begin
res := make***s();
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();
extract***s();
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.
Yer imleri