/
ddd.dpr
1819 lines (1660 loc) · 61.6 KB
/
ddd.dpr
1
2
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program ddd;
{$APPTYPE CONSOLE}
uses
Windows, StrUtils, SysUtils, Classes, WindowsVersion;
//------------------------------------------------------------------------------
type
ByteArray = array[0..65535] of Byte;
ByteArray2 = array[0..262143] of Byte;
TDiskGeometry = packed record
Cylinders: Int64;
MediaType: Integer;
TracksPerCylinder: DWORD;
SectorsPerTrack: DWORD;
BytesPerSector: Integer; // wichtig für die Reservierung des Buffer-Speichers
end;
TRawDrive = record
DiskGeometry: TDiskGeometry;
Handle: THandle;
end;
TIDERegs = packed record
bFeaturesReg: BYTE; // Used for specifying SMART ""commands"".
bSectorCountReg: BYTE; // IDE sector count register
bSectorNumberReg: BYTE; // IDE sector number register
bCylLowReg: BYTE; // IDE low order cylinder value
bCylHighReg: BYTE; // IDE high order cylinder value
bDriveHeadReg: BYTE; // IDE drive/head register
bCommandReg: BYTE; // Actual IDE command.
bReserved: BYTE; // reserved for future use. Must be zero.
end;
TSendCmdInParams = packed record
cBufferSize: DWORD; // Buffer size in bytes
irDriveRegs: TIDERegs; // Structure with drive register values.
bDriveNumber: BYTE; // Physical drive number to send command to (0,1,2,3).
bReserved: array[0..2] of Byte;
dwReserved: array[0..3] of DWORD;
bBuffer: array[0..0] of Byte; // Input buffer.
end;
TIdSector = packed record
wGenConfig: Word;
wNumCyls: Word;
wReserved: Word;
wNumHeads: Word;
wBytesPerTrack: Word;
wBytesPerSector: Word;
wSectorsPerTrack: Word;
wVendorUnique: array[0..2] of Word;
sSerialNumber: array[0..19] of CHAR;
wBufferType: Word;
wBufferSize: Word;
wECCSize: Word;
sFirmwareRev: array[0..7] of Char;
sModelNumber: array[0..39] of Char;
wMoreVendorUnique: Word;
wDoubleWordIO: Word;
wCapabilities: Word;
wReserved1: Word;
wPIOTiming: Word;
wDMATiming: Word;
wBS: Word;
wNumCurrentCyls: Word;
wNumCurrentHeads: Word;
wNumCurrentSectorsPerTrack: Word;
ulCurrentSectorCapacity: DWORD;
wMultSectorStuff: Word;
ulTotalAddressableSectors: DWORD;
wSingleWordDMA: Word;
wMultiWordDMA: Word;
bReserved: array[0..127] of BYTE;
end;
PIdSector = ^TIdSector;
TDriverStatus = packed record
bDriverError: Byte; // Error code from driver, or 0 if no error.
bIDEStatus: Byte; // Contents of IDE Error register. Only valid when bDriverError is SMART_IDE_ERROR.
bReserved: array[0..1] of Byte;
dwReserved: array[0..1] of DWORD;
end;
TSendCmdOutParams = packed record
cBufferSize: DWORD; // Size of bBuffer in bytes
DriverStatus: TDriverStatus; // Driver status structure.
bBuffer: array[0..0] of BYTE; // Buffer of arbitrary length in which to store the data read from the drive.
end;
//------------------------------------------------------------------------------
const
//Versionsinfo
VERSIONINFO: String =#201+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#187+#13+#10+
#186+' DigiCorder Disk Dump V1.6 '+#186+#13+#10+
#200+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#205+#188;
//Copyright
COPYRIGHT: String ='© 2006-2012 by Lostech';
//Homepage Adresse
HOMEPAGE: String ='www.lostech.de.vu';
//Beschreibung
DESCRIPTION: String ='Disk dumping tool for TechniSat©'+#13+#10+'* DigiCorder S1'+#13+#10+'* DigiCorder T1'+#13+#10+'* DigiCorder S2'+#13+#10+'* DigiCorder K2'+#13+#10+'* DigiCorder HD S2'+#13+#10+'* DigiCorder HD K2'+#13+#10+'and compatible devices with TSD filesystem.'+#13+#10;
//Warnung
WARNING: String ='Use at own risk! Removing HDD from Receiver/TV results in losing warranty!';
//Betriebssystem Konstanten
cOsUnknown =-1;
cOsWin95 =0;
cOsWin98 =1;
cOsWin98SE =2;
cOsWinME =3;
cOsWinNT =4;
cOsWin2000 =5;
cOsXP =6;
//Disk Raw Zugriff Konstanten
IOCTL_DISK_GET_DRIVE_GEOMETRY= $00070000;
IDENTIFY_BUFFER_SIZE= 512;
//Konstanten für Farben in der Konsole definieren
YellowOnBlue =FOREGROUND_GREEN OR FOREGROUND_RED OR FOREGROUND_INTENSITY OR BACKGROUND_BLUE;
WhiteOnBlue =FOREGROUND_BLUE OR FOREGROUND_GREEN OR FOREGROUND_RED OR FOREGROUND_INTENSITY OR BACKGROUND_BLUE;
BlueOnWhite =BACKGROUND_BLUE OR BACKGROUND_GREEN OR BACKGROUND_RED OR BACKGROUND_INTENSITY OR FOREGROUND_BLUE;
RedOnWhite =FOREGROUND_RED OR FOREGROUND_INTENSITY OR BACKGROUND_RED OR BACKGROUND_GREEN OR BACKGROUND_BLUE OR BACKGROUND_INTENSITY;
WhiteOnRed =BACKGROUND_RED OR BACKGROUND_INTENSITY OR FOREGROUND_RED OR FOREGROUND_GREEN OR FOREGROUND_BLUE OR FOREGROUND_INTENSITY;
ConsoleStandard =FOREGROUND_BLUE OR FOREGROUND_GREEN OR FOREGROUND_RED;
//------------------------------------------------------------------------------
var
//Laufwerke (PhysicalDrive)
PVR_Drive: String;
PVR_Drive2: String;
PVR_Size: Int64;
PVR_Size2: Int64;
//Image Datei
PVR_Image: String;
//Argumente/Optionen in Main
POS1: Integer;
CounterMain: Integer;
ParameterstringMain: String;
CmdLineError: Boolean;
ColorMain: Word;
//zusätzliche Variablen
Buffer: String;
//globaler Event
GlobalEvent: String;
//globale Abbruch Variable
Globalbreak: Boolean;
//Handle to console window
ConHandle: THandle;
//To store/set screen position
Coord: TCoord;
//To store max window size
MaxX, MaxY: Word;
CCI: TConsoleCursorInfo;
//To store results of some functions
NOAW: Cardinal;
//ignoriere Fehler beim auslesen
IgnoreErrors: Boolean;
//------------------------------------------------------------------------------
procedure ChangeByteOrder(var Data; Size: Integer);
//Byte Reihenfolge tauschen
var
ptr: PChar;
i: Integer;
c: Char;
begin
ptr := @Data;
for i := 0 to (Size shr 1) - 1 do
begin
c := ptr^;
ptr^ := (ptr + 1)^;
(ptr + 1)^ := c;
Inc(ptr, 2);
end;
end;
function GetConInputHandle : THandle;
//Get handle to console input
begin
Result := GetStdHandle(STD_INPUT_HANDLE)
end;
function GetConOutputHandle : THandle;
//Get handle to console output
begin
Result := GetStdHandle(STD_OUTPUT_HANDLE)
end;
function ReadKey: Char;
//Tastendruck abfragen
var
NumRead: Cardinal;
InputRec: TInputRecord;
begin
while ((not ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), InputRec, 1, NumRead)) or (InputRec.EventType <> KEY_EVENT)) do ;
Result := InputRec.Event.KeyEvent.AsciiChar;
end;
function WhereX: integer;
//X Position in der Konsole abfragen
var
cbi: TConsoleScreenBufferInfo;
begin
getConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), cbi);
result := tcoord(cbi.dwCursorPosition).x + 1
end;
function WhereY: integer;
//Y Position in der Konsole abfragen
var
cbi: TConsoleScreenBufferInfo;
begin
getConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), cbi);
result := tcoord(cbi.dwCursorPosition).y + 1
end;
procedure GotoXY(X, Y : Word);
//zur X/Y Position in der Konsole springen
begin
Coord.X := X; Coord.Y := Y;
SetConsoleCursorPosition(ConHandle, Coord);
end;
procedure CLS;
//Clear Screen - Bildschirm mit Leerzeichen überschreiben
begin
Coord.X := 0; Coord.Y := 0;
FillConsoleOutputCharacter(ConHandle, ' ', MaxX*MaxY, Coord, NOAW);
GotoXY(0, 0);
end;
procedure ShowCursor(Show : Bool);
//Cursor ein-/ausblenden
begin
CCI.bVisible := Show;
SetConsoleCursorInfo(ConHandle, CCI);
end;
procedure Init;
//Globale Konsolen Variablen initialisieren
begin
//Get console output handle
ConHandle := GetConOutputHandle;
//Get max window size
Coord := GetLargestConsoleWindowSize(ConHandle);
MaxX := Coord.X;
MaxY := Coord.Y;
end;
procedure StatusLine(S : String);
//Statuszeile schreiben
begin
Coord.X := 0;
Coord.Y := 0;
WriteConsoleOutputCharacter(ConHandle, PChar(S), Length(S)+1, Coord, NOAW);
FillConsoleOutputAttribute (ConHandle, WhiteOnRed, Length(S), Coord, NOAW);
end;
procedure ClearStatusLine;
//Statuszeile löschen
var
S : String;
begin
Coord.X := 0;
Coord.Y := 0;
S:=StringOfChar(' ',79);
WriteConsoleOutputCharacter(ConHandle, PChar(S), Length(S)+1, Coord, NOAW);
FillConsoleOutputAttribute (ConHandle, WhiteOnBlue, Length(S), Coord, NOAW);
end;
procedure NewLine(S: String; Color: Integer);
//Neue Zeile schreiben
begin
Coord.X := WhereX-1;
Coord.Y := WhereY;
S:=S+StringOfChar(' ',80-Length(S));
WriteConsoleOutputCharacter(ConHandle, PChar(S), Length(S)+1, Coord, NOAW);
FillConsoleOutputAttribute (ConHandle, Color, Length(S), Coord, NOAW);
GotoXY(WhereX-1,WhereY+1);
end;
function ConProc(CtrlType : DWord) : Bool; stdcall; far;
//Console Event Handler z.B. für STRG+C abfragen
var
S : String;
begin
//Event Typ auswerten
case CtrlType of
CTRL_C_EVENT : S := 'CTRL_C_EVENT';
CTRL_BREAK_EVENT : S := 'CTRL_BREAK_EVENT';
CTRL_CLOSE_EVENT : S := 'CTRL_CLOSE_EVENT';
CTRL_LOGOFF_EVENT : S := 'CTRL_LOGOFF_EVENT';
CTRL_SHUTDOWN_EVENT : S := 'CTRL_SHUTDOWN_EVENT';
else
S := 'UNKNOWN_EVENT';
end;
//Abbruch
StatusLine('[ Warning: '+S+' received ]');
GlobalBreak:=true;
GlobalEvent:=S;
Result := True;
end;
procedure RestoreConsole;
//Farbe der Konsole wieder herstellen
begin
//Abbruchmeldung
if GlobalBreak=true then
begin
sleep(100);
ClearStatusLine;
NewLine('Program abort due to a '+GlobalEvent,BlueOnWhite);
end;
//Farbe der Console wieder auf Standard zurücksetzen
ColorMain:=ConsoleStandard;
FillConsoleOutputAttribute(ConHandle, ColorMain, MaxX*MaxY, Coord, NOAW);
SetConsoleTextAttribute(ConHandle,ColorMain);
ShowCursor(true);
//Abbruchbedingung melden
if GlobalBreak=true then
ExitCode:=10;
end;
function DriveSize(Drive: String): Int64;
//Laufwerksgröße in Bytes auslesen
var
hDevice: Cardinal;
RawDrive: TRawDrive;
BytesReturned: Cardinal;
begin
DriveSize:=0;
FillChar(RawDrive, SizeOf(TRawDrive), 0);
hDevice:=CreateFile(pchar('\\.\'+Drive), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
begin
Exit;
end;
if DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, nil, 0, @RawDrive.DiskGeometry, SizeOf(TDiskGeometry), BytesReturned, nil)=true then
begin
DriveSize:=RawDrive.DiskGeometry.Cylinders*RawDrive.DiskGeometry.TracksPerCylinder*RawDrive.DiskGeometry.SectorsPerTrack*RawDrive.DiskGeometry.BytesPerSector;
end;
CloseHandle(hDevice);
end;
function GetDosDevice(PhysicalDrive: String): String;
//DOSDeviceName bzw. Symlinks auslesen
var
Buffer: string;
begin
SetLength(Buffer,256);
Buffer:=StringOfChar(#0,Length(Buffer));
try
QueryDosDevice(PChar(PhysicalDrive), @Buffer[1], 256);
except
Buffer:='';
end;
Buffer:=StringReplace(Buffer,#0,'',[rfReplaceAll, rfIgnoreCase]);
Result:=Trim(Buffer);
end;
procedure DriveInfo(Drive: String);
//Laufwerksinfo anzeigen
var
Buffer: String;
hDevice: Cardinal;
RawDrive: TRawDrive;
BytesReturned: Cardinal;
cbBytesReturned: DWORD;
SCIP: TSendCmdInParams;
aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
begin
//Grundeinstellungen
hDevice:=CreateFile(pchar('\\.\'+Drive), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
begin
writeln('');
if Pos('PhysicalDrive',Drive)>0 then
writeln('Error:'+#9+'Could not access "'+Drive+'" for reading!')
else
writeln('Error:'+#9+'Could not access Drive "'+AnsiReplaceStr(Drive,'\\.\','')+'" for reading!');
writeln('');
ExitCode:=5;
RestoreConsole;
Exit;
end;
if DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, nil, 0, @RawDrive.DiskGeometry, SizeOf(TDiskGeometry), BytesReturned, nil)=true then
begin
writeln('');
if Pos('PhysicalDrive',Drive)>0 then
writeln('"'+Drive+'" detailed infos!')
else
writeln('Drive "'+AnsiReplaceStr(Drive,'\\.\','')+'" detailed infos!');
writeln('');
writeln(' Info | Value');
writeln('-------------------+-------------------');
FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
cbBytesReturned := 0;
// Set up data structures for IDENTIFY command.
with SCIP do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
// bDriveNumber := 0;
with irDriveRegs do
begin
bSectorCountReg := 1;
bSectorNumberReg := 1;
// if Win32Platform=VER_PLATFORM_WIN32_NT then bDriveHeadReg := $A0
// else bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4);
bDriveHeadReg := $A0;
bCommandReg := $EC;
end;
end;
if DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1, @aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then
begin
Buffer:='';
with PIdSector(@IdOutCmd.bBuffer)^ do
begin
ChangeByteOrder(sModelNumber, SizeOf(sModelNumber));
(PChar(@sModelNumber) + SizeOf(sModelNumber))^ := #0;
Buffer:=PChar(@sModelNumber);
end;
writeln(' HDD Model | '+Buffer);
Buffer:='';
with PIdSector(@IdOutCmd.bBuffer)^ do
begin
ChangeByteOrder(sFirmwareRev, SizeOf(sFirmwareRev));
(PChar(@sFirmwareRev) + SizeOf(sFirmwareRev))^ := #0;
Buffer:=PChar(@sFirmwareRev);
end;
writeln(' HDD Firmware | '+Buffer);
Buffer:='';
with PIdSector(@IdOutCmd.bBuffer)^ do
begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
(PChar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;
Buffer:=PChar(@sSerialNumber);
end;
writeln(' HDD Serial | '+Buffer);
end;
writeln(' Cylinders | '+IntToStr(RawDrive.DiskGeometry.Cylinders));
writeln(' TracksPerCylinder | '+IntToStr(RawDrive.DiskGeometry.TracksPerCylinder));
writeln(' SectorsPerTrack | '+IntToStr(RawDrive.DiskGeometry.SectorsPerTrack));
writeln(' BytesPerSector | '+IntToStr(RawDrive.DiskGeometry.BytesPerSector));
writeln(' HDD physical size | '+format('%.2f GB',[RawDrive.DiskGeometry.Cylinders*RawDrive.DiskGeometry.TracksPerCylinder*RawDrive.DiskGeometry.SectorsPerTrack*RawDrive.DiskGeometry.BytesPerSector/1024/1024/1000]));
Buffer:='';
Buffer:=GetDosDevice(Drive);
if Buffer<>'' then
writeln(' MS-DOS Devicename | '+Buffer);
writeln('');
end;
CloseHandle(hDevice);
end;
function AddPath(FileName: String): String;
//Pfadangabe ergänzen wenn nur Dateiname und kein Pfad angegeben wurde
begin
if ExtractFilePath(FileName)='' then
AddPath:=ExtractFilePath(Paramstr(0))+FileName
else
AddPath:=FileName;
end;
{
function GetOperatingSystem: Integer;
//Betriebssystem auswerten
var
osVerInfo: TOSVersionInfo;
majorVer, minorVer: Integer;
begin
//Betriebsystemversion auslesen
osVerInfo.dwOSVersionInfoSize:=SizeOf(TOSVersionInfo);
if GetVersionEx(osVerInfo) then
begin
//Betriebssystemversion auswerten
majorVer:=osVerInfo.dwMajorVersion;
minorVer:=osVerInfo.dwMinorVersion;
case osVerInfo.dwPlatformId of
//Windows NT/2000/XP
VER_PLATFORM_WIN32_NT:
begin
if majorVer <= 4 then
Result:=cOsWinNT
else if (majorVer = 5) and (minorVer = 0) then
Result:=cOsWin2000
else if (majorVer = 5) and (minorVer = 1) then
Result:=cOsXP
else
Result:=cOsUnknown;
end;
//Windows 9x/ME
VER_PLATFORM_WIN32_WINDOWS:
begin
if (majorVer = 4) and (minorVer = 0) then
Result:=cOsWin95
else if (majorVer = 4) and (minorVer = 10) then
begin
if osVerInfo.szCSDVersion[1] = 'A' then
Result:=cOsWin98SE
else
Result:=cOsWin98;
end
else if (majorVer = 4) and (minorVer = 90) then
Result:=cOsWinME
else
Result:=cOsUnknown;
end;
else
Result:=cOsUnknown;
end;
end
else
Result:=cOsUnknown;
end;
}
procedure Version;
//Programm Versionsinfo anzeigen
begin
writeln('');
writeln(VERSIONINFO);
writeln('');
writeln(DESCRIPTION);
writeln(WARNING);
writeln('');
writeln(COPYRIGHT+' '+HOMEPAGE);
writeln('');
end;
procedure Help;
//Hilfe anzeigen
begin
writeln('Available options:');
writeln('-di[a..z] set drive letter for read input (overrides automatic)');
writeln('-dl[a..z] show drive letter info');
writeln('-do[a..z] set drive letter for write output (without c: see remarks)');
writeln('-erased[a..z] erase selected drive by letter (without c: see remarks)');
writeln('-erasepd[1..19] erase selected PhysicalDrive');
writeln('-errorignore do not stop on read errors');
writeln('-exitcodes show list of possible exit codes');
writeln('-help show this help page');
writeln('-i [filename] set binary input filename');
writeln('-list show list of Magic Headers by PhysicalDrive');
writeln('-list2 show list of Magic Headers by drive letter');
writeln('-listdetails show detailed list of PhysicalDrives (only if available)');
writeln('-listdetails2 show detailed list of drives by letter (only if available)');
writeln('-noboot ignore bootsector during erasing or writing');
writeln('-o [filename] set binary output filename');
writeln('-pd[0..19] show PhysicalDrive info');
writeln('-pdi[0..19] set PhysicalDrive for read input (overrides automatic)');
writeln('-pdo[1..19] set PhysicalDrive for write output');
writeln('');
writeln('');
writeln('Additional remarks:');
writeln('1.) PhysicalDrive0 and drive c: are blocked for erasing and writing operations');
writeln(' due to security reasons because this is normaly the main Windows HDD');
writeln('2.) Option "-noboot" can only be applied for erasing and writing operations');
writeln('3.) a program break can be done by pressing [CTRL+C]');
writeln('4.) Option "-errorignore" may cause that the program does not stop on its own');
writeln(' to stop it manually press [CTRL+C]');
writeln('5.) Option "-list" shows all PhyiscalDrives which can be accessed.');
writeln(' Option "-listdetails" shows instead only PhysicalDrives with available');
writeln(' detail infos');
writeln('6.) Option "-list2" shows all Drives by letters which can be accessed.');
writeln(' Option "-listdetails2" shows instead only Drives by letters with available');
writeln(' detail infos');
writeln('7.) "TechniSat FS 1" signalizes a DigiCorder S1/T1 (and compatible) HDD');
writeln(' "TechniSat FS 2" signalizes a DigiCorder (HD)S2/K2 (and compatible) HDD');
writeln('');
writeln('');
writeln('Usage examples (change PhysicalDrive/Drive letter or file path to your needs):');
writeln('1.) Dumping a DigiCorder HDD into a file:');
writeln(' ddd.exe C:/Dumpfile.bin');
writeln(' ddd.exe -pdi1 -o "C:/Dumpfile.bin"');
writeln('');
writeln('2.) Erasing a HDD:');
writeln(' ddd.exe -erasepd2');
writeln(' ddd.exe -erasepd2 -noboot');
writeln('');
writeln('3.) Writing a dump image to a HDD:');
writeln(' ddd.exe -pdo1 -i "C:/Dumpfile.bin"');
writeln(' ddd.exe -pdo1 -i "C:/Dumpfile.bin" -noboot');
writeln('');
writeln('4.) Copy a HDD to another HDD:');
writeln(' ddd.exe -pdi1 -pdo2');
writeln(' ddd.exe -pdi1 -pdo2 -noboot');
writeln('');
end;
procedure ExitCodes;
//Exit Codes anzeigen
begin
writeln('');
writeln('Code | Meaning');
writeln('-----+------------------------------------');
writeln(' 0 | no error');
writeln(' 1 | unsupported OS (Windows 9x and NT)');
writeln(' 2 | no commandline options declared');
writeln(' 3 | PVR HDD not found');
writeln(' 4 | no dump image filename declared');
writeln(' 5 | no PhysicalDrive read access');
writeln(' 6 | no PhysicalDrive write access');
writeln(' 7 | no dump image read access');
writeln(' 8 | no dump image write access');
writeln(' 9 | illegal commandline combination');
writeln(' 10 | program aborted');
writeln('');
end;
function ReadBlock(Drive: string; Block: LongInt; ChangeEndian: Boolean): ByteArray;
//Block von Festplatte lesen
var
hDevice: Cardinal;
RipArray: ByteArray;
NewArray: ByteArray;
BytesRead: Cardinal;
Counter: Integer;
Sector: LARGE_INTEGER;
begin
//einzelnen Block auslesen
hDevice:=CreateFile(pchar('\\.\'+Drive), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
begin
Exit;
end;
if (Block>0) then
Sector.QuadPart:=Block*65536
else
Sector.QuadPart:=0;
SetFilePointer(hDevice,Sector.LowPart,@Sector.HighPart, FILE_BEGIN);
ReadFile(hDevice, RipArray, SizeOf(RipArray), BytesRead, nil);
CloseHandle (hDevice);
//Endian Reihenfolge ändern
if ChangeEndian=true then
begin
Counter:=0;
while Counter<SizeOf(RipArray)+1 do
begin
NewArray[Counter]:= RipArray[Counter+1];
NewArray[Counter+1]:=RipArray[Counter];
Counter:=Counter+2;
end;
ReadBlock:=NewArray;
end
else
ReadBlock:=RipArray;
end;
function FindDrive: String;
//DigiCorder Festplatte finden
var
ReadBlockArray: ByteArray;
DriveNumber: Integer;
begin
//20 mögliche physikalische Laufwerke auf Magic prüfen und das 1. gefundene Laufwerk melden
FindDrive:='';
for DriveNumber:=0 to 19 do
begin
ReadBlockArray[0]:=0;
ReadBlockArray[1]:=0;
ReadBlockArray[2]:=0;
ReadBlockArray[3]:=0;
ReadBlockArray:=ReadBlock('PhysicalDrive'+IntToStr(DriveNumber),0, false);
//8C A2 76 B9 -> DigiCorder S1/T1
if (ReadBlockArray[0]=140) and (ReadBlockArray[1]=162) and (ReadBlockArray[2]=118) and (ReadBlockArray[3]=185) then
begin
FindDrive:='PhysicalDrive'+IntToStr(DriveNumber);
break;
end;
//B3 6E DB 8A -> DigiCorder S2/K2/HD S2
if (ReadBlockArray[0]=179) and (ReadBlockArray[1]=110) and (ReadBlockArray[2]=219) and (ReadBlockArray[3]=138) then
begin
FindDrive:='PhysicalDrive'+IntToStr(DriveNumber);
break;
end;
end;
//26 mögliche Laufwerksbuchstaben auf Magic prüfen und das 1. gefundene Laufwerk melden
for DriveNumber:=0 to 25 do
begin
ReadBlockArray[0]:=0;
ReadBlockArray[1]:=0;
ReadBlockArray[2]:=0;
ReadBlockArray[3]:=0;
ReadBlockArray:=ReadBlock('\\.\'+Chr(97+DriveNumber)+':',0, false);
//8C A2 76 B9 -> DigiCorder S1/T1
if (ReadBlockArray[0]=140) and (ReadBlockArray[1]=162) and (ReadBlockArray[2]=118) and (ReadBlockArray[3]=185) then
begin
FindDrive:='\\.\'+Chr(97+DriveNumber)+':';
break;
end;
//B3 6E DB 8A -> DigiCorder S2/K2/HD S2
if (ReadBlockArray[0]=179) and (ReadBlockArray[1]=110) and (ReadBlockArray[2]=219) and (ReadBlockArray[3]=138) then
begin
FindDrive:='\\.\'+Chr(97+DriveNumber)+':';
break;
end;
end;
end;
procedure ListDrives;
//Festplatten auflisten
var
ReadBlockArray: ByteArray;
DriveNumber: Integer;
DosDevice: String;
begin
//20 mögliche physikalische Laufwerke auf Magic prüfen
writeln('');
writeln(' Drive | MagicHeader | HDD Type | MS-DOS Devicename');
writeln('----------------+-------------+-------------------+----------------------------');
for DriveNumber:=0 to 19 do
begin
ReadBlockArray[0]:=255;
ReadBlockArray[1]:=254;
ReadBlockArray[2]:=253;
ReadBlockArray[3]:=252;
ReadBlockArray:=ReadBlock('PhysicalDrive'+IntToStr(DriveNumber),0,false);
//nur bei echtem Ergebnis eine Ausgabe anzeigen
if (ReadBlockArray[0]<>255) and (ReadBlockArray[1]<>254) and (ReadBlockArray[2]<>253) and (ReadBlockArray[3]<>252) then
begin
DosDevice:=GetDosDevice('PhysicalDrive'+IntToStr(DriveNumber));
//8C A2 76 B9 -> DigiCorder S1/T1
if (ReadBlockArray[0]=140) and (ReadBlockArray[1]=162) and (ReadBlockArray[2]=118) and (ReadBlockArray[3]=185) then
writeln('PhysicalDrive'+IntToStr(DriveNumber)+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | TechniSat FS 1 | '+DosDevice)
//B3 6E DB 8A -> DigiCorder S2/K2/HD S2/HD K2
else if (ReadBlockArray[0]=179) and (ReadBlockArray[1]=110) and (ReadBlockArray[2]=219) and (ReadBlockArray[3]=138) then
writeln('PhysicalDrive'+IntToStr(DriveNumber)+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | TechniSat FS 2 | '+DosDevice)
else
writeln('PhysicalDrive'+IntToStr(DriveNumber)+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | unknown HDD | '+DosDevice)
end;
end;
writeln('');
end;
procedure ListDrivesByDriveLetter;
//Festplatten auflisten
var
ReadBlockArray: ByteArray;
DriveNumber: Integer;
DosDevice: String;
begin
//26 mögliche Laufwerke auf Magic prüfen
writeln('');
writeln(' Drive | MagicHeader | HDD Type | MS-DOS Devicename');
writeln('----------------+-------------+-------------------+-----------------------------');
for DriveNumber:=0 to 25 do
begin
ReadBlockArray[0]:=255;
ReadBlockArray[1]:=254;
ReadBlockArray[2]:=253;
ReadBlockArray[3]:=252;
ReadBlockArray:=ReadBlock(Chr(97+DriveNumber)+':',0,false);
//nur bei echtem Ergebnis eine Ausgabe anzeigen
if (ReadBlockArray[0]<>255) and (ReadBlockArray[1]<>254) and (ReadBlockArray[2]<>253) and (ReadBlockArray[3]<>252) then
begin
DosDevice:=GetDosDevice('PhysicalDrive'+IntToStr(DriveNumber));
//8C A2 76 B9 -> DigiCorder S1/T1
if (ReadBlockArray[0]=140) and (ReadBlockArray[1]=162) and (ReadBlockArray[2]=118) and (ReadBlockArray[3]=185) then
writeln('Drive '+Chr(97+DriveNumber)+':'+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | TechniSat FS 1 | '+DosDevice)
//B3 6E DB 8A -> DigiCorder S2/K2/HD S2/HD K2 Digit HD8-S/K
else if (ReadBlockArray[0]=179) and (ReadBlockArray[1]=110) and (ReadBlockArray[2]=219) and (ReadBlockArray[3]=138) then
writeln('Drive '+Chr(97+DriveNumber)+':'+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | TechniSat FS 2 | '+DosDevice)
else
writeln('Drive '+Chr(97+DriveNumber)+':'+#9+'| 0x'+IntToHex(ReadBlockArray[0],2)+IntToHex(ReadBlockArray[1],2)+IntToHex(ReadBlockArray[2],2)+IntToHex(ReadBlockArray[3],2)+' | unknown HDD | '+DosDevice)
end;
end;
writeln('');
end;
procedure ListDrivesExtended;
//Festplatten auflisten (Details)
var
hDevice: Cardinal;
DriveNumber: Integer;
begin
//20 mögliche physikalische Laufwerke auf Detailinfos prüfen
writeln('');
for DriveNumber:=0 to 19 do
begin
hDevice:=CreateFile(pchar('\\.\'+'PhysicalDrive'+IntToStr(DriveNumber)), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
begin
//writeln('');
//writeln('Error:'+#9+'Could not access "'+'PhysicalDrive'+IntToStr(DriveNumber)+'" for reading!');
//writeln('');
end
else
begin
DriveInfo('PhysicalDrive'+IntToStr(DriveNumber));
CloseHandle(hDevice);
end;
end;
writeln('');
end;
procedure ListDrivesExtendedByDriveLetter;
//Festplatten auflisten (Details)
var
hDevice: Cardinal;
DriveNumber: Integer;
begin
//26 mögliche Laufwerke auf Detailinfos prüfen
writeln('');
for DriveNumber:=0 to 25 do
begin
hDevice:=CreateFile(pchar('\\.\'+Chr(97+DriveNumber)+':'), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then
begin
//writeln('');
//writeln('Error:'+#9+'Could not access "'+'PhysicalDrive'+IntToStr(DriveNumber)+'" for reading!');
//writeln('');
end
else
begin
DriveInfo(Chr(97+DriveNumber)+':');
CloseHandle(hDevice);
end;
end;
writeln('');
end;
procedure DumpImage(Drive: String; ImageFile: String);
//Dump Image eines Laufwerks anlegen
var
Percent, PercentOld: Single;
hDevice, hDevice2: Cardinal;
BytesRead, BytesWritten: Cardinal;
RipArray: ByteArray2;
Position: LARGE_INTEGER;
ImageSize: LARGE_INTEGER;
begin
//Fehler beim auslesen ignorieren
if IgnoreErrors=true then
begin
writeln('');
writeln('Warning:'+#9+'Read errors will be ignored');
writeln('Warning:'+#9+'If programm does not stop when source HD end is reached then exit by pressing [CTRL+C]');
writeln('');
end;
//Festplattengröße auslesen
PVR_Size:=DriveSize(PVR_Drive);
writeln('Info:'+#9+'Input HDD physical size'+#9+#9+format('%.2f GB',[PVR_Size/1024/1024/1000]));
//Grundeinstellungen
writeln('');
write('Info:'+#9+'Progress [ ] 0.0%');
PercentOld:=0;
Position.QuadPart:=0;
//Laufwerk öffnen
hDevice:=CreateFile(pchar('\\.\'+Drive), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice=INVALID_HANDLE_VALUE then
begin
writeln('');
if Pos('PhysicalDrive',Drive)>0 then
writeln('Error:'+#9+'Could not access "'+Drive+'" for reading!')
else
writeln('Error:'+#9+'Could not access Drive "'+AnsiReplaceStr(Drive,'\\.\','')+'" for reading!');
writeln('');
ExitCode:=5;
RestoreConsole;
Exit;
end;
//Dump Image öffnen
if FileExists(ImageFile) then
DeleteFile(ImageFile);
hDevice2:=CreateFile(pchar(ImageFile), GENERIC_WRITE, FILE_SHARE_WRITE, nil, OPEN_ALWAYS, 0, 0);
if hDevice2=INVALID_HANDLE_VALUE then
begin
writeln('');
writeln('Error:'+#9+'Could not access "'+ImageFile+'" for writing!');
writeln('');
CloseHandle(hDevice);
ExitCode:=8;
RestoreConsole;
Exit;
end;
//while (Position.QuadPart div 512)<SuperBlock.SectCount-1 do
while (Position.QuadPart<PVR_Size-1) and (GlobalBreak=false) do
begin
//Daten aus Laufwerk auslesen
SetFilePointer(hDevice,Position.LowPart,@Position.HighPart, FILE_BEGIN);
ReadFile(hDevice, RipArray, SizeOf(RipArray), BytesRead, nil);
if BytesRead=0 then
begin
writeln('');
writeln('Info:'+#9+'End of HDD reached or read error');
if IgnoreErrors=false then
break;
end;
//Fortschrittsanzeige
Percent:=(Position.QuadPart/PVR_Size)*100;
if FormatFloat('000.0', Percent)<>FormatFloat('000.0', PercentOld) then
begin
PercentOld:=Percent;
buffer:='['+StringOfChar(#254,trunc((Percent+0.1)*0.2))+StringOfChar(' ',20-trunc((Percent+0.1)*0.2))+'] '+StringOfChar(' ',3-Length(FormatFloat('000.0', Percent)))+FormatFloat('000.0', Percent)+'%';
buffer:=StringOfChar(#8, Length(buffer))+buffer;
buffer:=StringReplace(buffer, ',', '.',[rfReplaceAll, rfIgnoreCase]);
buffer:=StringReplace(buffer, '] 00', '] ',[rfReplaceAll, rfIgnoreCase]);
buffer:=StringReplace(buffer, '] 0', '] ',[rfReplaceAll, rfIgnoreCase]);
write(buffer);
end;
//Daten in Dump Image schreiben
SetFilePointer(hDevice2,Position.LowPart,@Position.HighPart, FILE_BEGIN);
WriteFile(hDevice2, RipArray, SizeOf(RipArray), BytesWritten, nil);
if BytesWritten=0 then
begin
writeln('');
writeln('Info:'+#9+'Target HDD full or write error');
break;
end;
Position.QuadPart:=Position.QuadPart+(SizeOf(RipArray));
end;
//Dump Image Größe ermitteln
ImageSize.LowPart:=GetFileSize(hDevice2,@ImageSize.HighPart);
writeln('');
writeln('Info:'+#9+format('%.2f GB',[ImageSize.QuadPart/1024/1024/1000])+' written');
//aufräumen
CloseHandle(hDevice);
CloseHandle(hDevice2);
end;
procedure WriteImage(PhysicalDrive: String; ImageFile: String; IgnoreBootSector: Boolean);
//Dump Image eines Laufwerks anlegen
var
Percent, PercentOld: Single;
hDevice, hDevice2: Cardinal;
BytesRead, BytesWritten: Cardinal;
WriteArray: ByteArray2;
Position: LARGE_INTEGER;
ImageSize: LARGE_INTEGER;
begin
//Grundeinstellungen
PercentOld:=0;
if IgnoreBootSector=true then
begin
writeln('');
writeln('Info:'+#9+'Ignore bootsector to be written');
Position.QuadPart:=512;
end
else
begin
writeln('');