-
Notifications
You must be signed in to change notification settings - Fork 1
/
bingen.pas
125 lines (91 loc) · 2.89 KB
/
bingen.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
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
unit bingen;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, StrUtils;
type
//TByteArray = Array of Byte;
TBinGen = class(TObject)
private
FFile : File of Byte;
FBytes : TBytes;
FBytePos : Cardinal;
public
procedure WriteByte(AInput : Byte);
procedure WriteBytePos(AInput : Byte; APos : Cardinal);
procedure WriteHexStrBEtoLE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
procedure WriteHexStrLEtoBE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
procedure WriteHexStr(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
procedure WriteDecStrLE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
procedure WriteDecStrBE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
procedure WriteChar(AInput : Char);
procedure WriteString(AInput : AnsiString);
procedure SaveFile(filename : AnsiString);
constructor Create();
destructor Destroy(); override;
property BytePos : Cardinal read FBytePos;
end;
implementation
procedure TBinGen.WriteByte(AInput : Byte);
var i : Cardinal;
begin
i := Length(self.FBytes);
SetLength(self.FBytes, i + 1);
self.FBytes[i] := AInput;
self.FBytePos := i;
end;
procedure TBinGen.WriteBytePos(AInput : Byte; APos : Cardinal);
begin
self.FBytes[APos] := AInput;
end;
procedure TBinGen.WriteHexStrBEtoLE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
var li : LongInt;
bytes : Array[0..3] of Byte;
begin
li := Hex2Dec(AInput);
Move(li, bytes[0], 4);
self.WriteByte(bytes[0]);
self.WriteByte(bytes[1]);
self.WriteByte(bytes[2]);
self.WriteByte(bytes[3]);
end;
procedure TBinGen.WriteHexStrLEtoBE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
begin
end;
procedure TBinGen.WriteHexStr(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
begin
end;
procedure TBinGen.WriteDecStrLE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
begin
end;
procedure TBinGen.WriteDecStrBE(AInput : AnsiString; AFixedSize : Boolean = True; ASizeBytes : Byte = 4);
begin
end;
procedure TBinGen.WriteChar(AInput : Char);
begin
end;
procedure TBinGen.WriteString(AInput : AnsiString);
begin
end;
procedure TBinGen.SaveFile(filename : AnsiString);
var i : Integer;
begin
AssignFile(self.FFile, filename);
Rewrite(self.FFile);
Truncate(self.FFile);
for i := 0 to Length(self.FBytes) - 1 do
begin
Write(self.FFile, self.FBytes[i]);
end;
CloseFile(self.FFile);
end;
constructor TBinGen.Create();
begin
SetLength(self.FBytes, 0);
self.FBytePos := 0;
end;
destructor TBinGen.Destroy();
begin
SetLength(self.FBytes, 0);
end;
end.