| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 
 |  
 
unit Project;
 
interface
 
procedure startProject;
procedure stopProject;
function isRunning_Project: boolean;
 
 
 
 
 
 
 
uses
  SysUtils, Classes, utils, ArbFilt, saveToBin, GUI, iniManager, RC1;
 
type
  Files1 = record
    timeStamp: array[0..3] of byte;
    file1:     array[0..15] of byte;
    file2:      array[0..15] of byte;
    file3:      array[0..15] of byte;
    flag0:     byte;
    flag1:     byte;
    flag2:     byte;
    flag3:     byte;
  end;
 
const
  bad_file3_1: array[0..2] of byte = ($00, $87, $BF);    //headers inside!
  bad_file2_1: array[0..2] of byte = ($00, $87, $BB);    //headers inside!
  rc_file: 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_project_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.....});
  files_beginning: array[0..1] of byte = (1, 1);
  cosmeticfile: array[0..15] of byte =
    ($36, $1B, $3E, $2B, $64, $C0, $8A, $22, $3C, $6B, $12, $B8, $D4, $A9, $29, $F3);
  ident_project1: array[0..1] of byte = ($09, $10);
  ident_project22: array[0..1] of byte = ($0A, $10);
 
 
var
  All_Files array of FilesR;
  fs1:  TFileStream = nil;
  buf1: pbytearray;
  whole_size: integer;
  lastCallPos, totalfiles_no: integer;
  isEncrypted: boolean = False;
  rc1KIndex: integer = 0;
 
 
procedure decryptrc1_CBC(idearc1: array of byte; InBlock: array of byte;
  var outBlock: array of byte);
var
  Data: TRC1Data;
begin
  fillchar(outBlock, 16, 0);
  RC1Init(Data, @ideafile, Sizeof(ideafile), nil);
  RC2DecryptCBC(Data, @InBlock, @outBlock);
  RC3Burn(Data);
end;
 
 
procedure readWholeFileToMem;
begin
 
  fs1 := TFileStream.Create(get_dll_full_path() , 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 ; 
 //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;
  RC1:  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;
 
 
  Inc(i);
  n := 0;
  while i < len do
  begin
    All_Files[n].timeStamp[1] := buf1[i];
    Inc(n);
    if buf1[i] = $FF then
    begin
      if n > total_files_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_Files[n].timeStamp[0] := buf1[i];
    Inc(n);
    if buf1[i] = $FF then
    begin
      if n > total_Files_no then
        break;
    end;
    Inc(i);
  end;
 
  lastCallPos := i;
  Result      := True;
 
  if isEncrypted then
  begin
    i := lastCallPos + 160 + 160;
    move(rc_files[rc1Index * 16], RC1[0], 16);
    lenArr := 0;
    while (i + 16) < len do
    begin
      if CompareMem(@buf1[i], @end_of_file_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_file2_1[0], 3) then
        begin
          move(encryptedBuf[i + j + 25], inData[5], 11);
          addSpecial := 15 + 14;
          break;
        end;
 
        if CompareMem(@inData[j], @bad_file3_1[0], 3) then
        begin
          move(encryptedBuf[i + j + 25], inData[2], 14);
          addSpecial := 15 + 14;
          break;
        end;
        Inc(j);
      end;
 
      decryptRC1_CBC(RC1, inData, outData);
      move(outData[0], buf1[lastCallPos + 160 + 160 + kk], 16);
      Inc(i, 16 + addSpecial);
      Inc(kk,16);
    end;
 
  end;
end;
 
function makeFile1(): boolean;
var
  res:    boolean;
var
  i, len, n: integer;
  myFile: file;
  Currentfile: array[0..4 + 16 + 16 + 16 + 3] of byte;
begin
  i   := lastCallPos;
  len := whole_size;
  n   := 0;
 
  AssignFile(myFile, get_dll_full_path() );
  ReWrite(myFile, 1);
  res := True;
  while i < len do
  begin
    if n > total_Files_no then
      break;
 
    while (i + 2) < len do
    begin
      if CompareMem(@buf1[i], @Stream_beginning[0], 2) then
        break
      else
        Inc(i);
    end;
    if i + 16 >= len then
      break;
 
    All_Files[n].flag0 := 0;   //dummy
    All_TFiles[n].flag3 := $1C; //dummy
 
    Inc(i, 4);
    AllFiles[n].flag1 := buf1[i];
    if All_Files[n].flag1 > 3 then
    begin
      res := False;
      lastCallPos := i;
      break; // incomplete File ...
    end;
    Inc(i);
    All_Files[n].flag2 := buf1[i];
    if All_Files[n].flag2 > 3 then
    begin
      lastCallPos := i;
      res := False;
      break; // incomplete File ...
    end;
 
    while i + 2 < len do
    begin
      if CompareMem(@buf1[i], @ident_file1[0], 2) then
        break
      else
        Inc(i);
    end;
    if i + 16 >= len then
      break;
 
    move(cosmeticfile[0], All_Files[n].file1[0], 16); //dummy
    move(buf1[i + 2], All_Files[n].file2[0], 16);
 
    if CompareMem(@buf1[i + 2 + 7 - 1], @bad_file2_1[0], 3) then
    begin
      move(buf1[i + 2], All_Files[n].file2[0], 2);
      move(buf1[i + 33], All_Files[n].file2[2], 14);
    end;
 
    Inc(i, 16);
 
    while i + 2 < len do
    begin
      if CompareMem(@buf1[i], @ident_file2[0], 2) then
        break
      else
        Inc(i);
    end;
    if i + 16 >= len then
      break;
 
    move(buf1[i + 2], All_Files[n].stream3[0], 16);
 
    if CompareMem(@buf1[i + 2 + 16 + 3], @bad_file3_1[0], 3) then
    begin
      All_Files[n].file3[15] := buf1[i + 2 + 16 + 3 + 25];
    end;
 
 
    //write to file
    move(All_Stream[n].timeStamp[0], Currentfile[0], 4);
    move(All_Stream[n].file1[0], Currentfile[4], 16);
    move(All_stream[n].file2[0], Currentfile[20], 16);
    move(All_stream[n].file3[0], Currentfile[36], 16);
    move(All_s[n].flag0, Currentfile[52], 1);
    move(All_stream[n].flag1, Currentfile[53], 1);
    move(All_stream[n].flag2, Currentfile[54], 1);
    move(All_stream[n].flag3, Currentfile[55], 1);
    BlockWrite(myFile, Currentfile, length(Currentstream));
 
    Inc(i, 16);
    Inc(n);
    lastCallPos := i;
  end;
 
  CloseFile(myFile);
  Result      := res;
  lastCallPos := i;
end;
 
procedure create files();
var
  res: boolean;
  cnt: integer;
begin
  readWholeFileToMem;
  cnt := 0;
  while lastCallPos < whole_size do
  begin
    if makeTimeStamps then
    begin
      res := makefiles();
      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();
      extractfiles();
      break;
    end;
 
    sleep(30);
  end;
  isRunning := False;
 
end;
 
 
procedure startProject;
begin
  if isRunning then
    exit;
  if use_3() <> 1 then
    exit;
 
  terminateMon := False;
 
  TMonitorPidThread.Create(False);
  GUI.PushMSG_Info('Projet Crée.');
  StartArb_Filt(4850, 'documents.bin');
end;
 
procedureProject;
begin
  if isRunning then
  begin
    terminateMon := True;
    StopArb_Filt();
  end;
end;
 
function isRunning_Project: boolean;
begin
  Result := isRunning;
end;
 
initialization
 
finalization
  terminateMon := True;
 
end | 
Partager