-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserv_param.pas
95 lines (86 loc) · 2.08 KB
/
serv_param.pas
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
unit serv_param;
interface
function IsThereParams: boolean;
implementation
uses Windows, SysUtils, Classes, Service;
function RawDiskToFile (const sourceDisk, targetFile: string): boolean;
const
_bufSize = 10 * 1024;
var
_handleSource, _handleTarget: integer;
_countRead: longword;
_buffer: array[0.._bufSize] of byte;
begin
_handleSource := CreateFile(PChar(Format('\\.\%s', [sourceDisk])),
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, 0);
Result := (_handleSource = INVALID_HANDLE_VALUE);
if not Result then
begin
_handleTarget := FileCreate(targetFile);
if _handleTarget <> -1 then
begin
_countRead := _bufSize;
while _countRead = _bufSize do
begin
ReadFile(_handleSource, _buffer, _bufSize, _countRead, nil);
FileWrite(_handleTarget, _buffer, _countRead);
end;
end
else
Result := False;
end;
if _handleSource <> INVALID_HANDLE_VALUE then
CloseHandle(_handleSource);
if _handleTarget <> -1 then
FileClose(_handleTarget);
end;
procedure CreateFileSize (const fname: string; fsize: longword);
var
fHandle: integer;
_written, I: integer;
Buf: array[0..1024 + 1] of char;
begin
fHandle := FileCreate(fname);
FillChar(Buf, 1024, 0);
I := 0;
_written := 1024;
while (I < fsize) and (_written = 1024) do
begin
_written := FileWrite(fHandle, Buf, 1024);
if I mod 10 = 0 then
Write('.');
Inc(I);
end;
FileClose(fHandle);
end;
function IsThereParams: boolean;
var
_s, _s1, _s2: string;
begin
Result := True;
_s := ParamStr(1);
if _s[1] <> '-' then
Result := False
else
begin
_s := Copy(ParamStr(1), 2, 1);
case _s[1] of
'p':
begin
_s1 := ParamStr(2);
_s2 := ParamStr(3);
assert((Length(_s1) > 0) and ((Length(_s2) > 0)));
RawDiskToFile(_s1, _s2);
end;
'd':
begin
_s1 := ParamStr(2);
_s2 := ParamStr(3);
assert((Length(_s1) > 0) and ((Length(_s2) > 0)));
CreateFileSize(_s1, StrToInt(_s2));
end;
end;
end;
end;
end.