-
Notifications
You must be signed in to change notification settings - Fork 0
/
uMain.pas
316 lines (297 loc) · 11.3 KB
/
uMain.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
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
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type TFieldLevel = (flSingle, flBegin, flEnd);
type TAFPDS = class(TObject)
private
fPosition: Integer;
fLength: Integer;
fFieldValue: Integer;
fLevel: Integer;
private
function GetFieldName: String;
function GetFieldLevel: TFieldLevel;
public
property Position: Integer read fPosition write fPosition;
property Length: Integer read fLength write fLength;
property FieldValue: Integer read fFieldValue write fFieldValue;
property Level: Integer read fLevel;
property FieldName: String read GetFieldName;
property FieldLevel: TFieldLevel read GetFieldLevel;
end;
type
TfrmMain = class(TForm)
Button1: TButton;
OD: TOpenDialog;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
function ParseFile(aFileName: String): Boolean;
function IdName(const aId: Integer): String;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
uses ebcdic, uAFPTriplets;
{$R *.dfm}
procedure TfrmMain.Button1Click(Sender: TObject);
begin
if (not OD.Execute) then
Exit;
Memo1.Clear;
ParseFile(OD.FileName);
end;
function TAFPDS.GetFieldLevel: TFieldLevel;
begin
case fFieldValue of
afpBAG: Result := 'Begin Active Environment Group';
afpBBC: Result := 'Begin Bar Code Object';
afpBCA: Result := 'Begin Color Attribute Table';
afpBDA: Result := 'Bar Code Data';
afpBDD: Result := 'Bar Code Data Descriptor';
afpBDG: Result := 'Begin Document Environment Group';
afpBDI: Result := 'Begin Document Index';
afpBDT: Result := 'Begin Document';
afpBFG: Result := 'Begin Form Environment Group (Obsolete)';
afpBFM: Result := 'Begin Form Map';
afpBGR: Result := 'Begin Graphics Object';
afpBII: Result := 'Begin IM Image (C)';
afpBIM: Result := 'Begin Image Object';
afpBMM: Result := 'Begin Medium Map';
afpBMO: Result := 'Begin Overlay';
afpBNG: Result := 'Begin Named Page Group';
afpBOC: Result := 'Begin Object Container';
afpBOG: Result := 'Begin Object Environment Group';
afpBPG: Result := 'Begin Page';
afpBPS: Result := 'Begin Page Segment';
afpBPT: Result := 'Begin Presentation Text Object';
afpBR : Result := 'Begin Resource (R)';
afpBRG: Result := 'Begin Resource Group';
afpBSG: Result := 'Begin Resource Environment Group';
afpCAT: Result := 'Color Attribute Table';
afpCDD: Result := 'Container Data Descriptor';
afpCTC: Result := 'Composed Text Control (O)';
afpEAG: Result := 'End Active Environment Group';
afpEBC: Result := 'End Bar Code Object';
afpECA: Result := 'End Color Attribute Table';
afpEDG: Result := 'End Document Environment Group';
afpEDI: Result := 'End Document Index';
afpEDT: Result := 'End Document';
afpEFG: Result := 'End Form Environment Group (Obsolete)';
afpEFM: Result := 'End Form Map';
afpEGR: Result := 'End Graphics Object';
afpEII: Result := 'End IM Image (C)';
afpEIM: Result := 'End Image Object';
afpEMM: Result := 'End Medium Map';
afpEMO: Result := 'End Overlay';
afpENG: Result := 'End Named Page Group';
afpEOC: Result := 'End Object Container';
afpEOG: Result := 'End Object Environment Group';
afpEPG: Result := 'End Page';
afpEPS: Result := 'End Page Segment';
afpEPT: Result := 'End Presentation Text Object';
afpER : Result := 'End Resource (R)';
afpERG: Result := 'End Resource Group';
afpESG: Result := 'End Resource Environment Group';
afpFGD: Result := 'Form Environment Group Descriptor (Obsolete)';
afpGAD: Result := 'Graphics Data';
afpGDD: Result := 'Graphics Data Descriptor';
afpICP: Result := 'IM Image Cell Position (C)';
afpIDD: Result := 'Image Data Descriptor';
afpIEL: Result := 'Index Element';
afpIID: Result := 'IM Image Input Descriptor (C)';
afpIMM: Result := 'Invoke Medium Map';
afpIOB: Result := 'Include Object';
afpIOC: Result := 'IM Image Output Control (C)';
afpIPD: Result := 'Image Picture Data';
afpIPG: Result := 'Include Page';
afpIPO: Result := 'Include Page Overlay';
afpIPS: Result := 'Include Page Segment';
afpIRD: Result := 'IM Image Raster Data (C)';
afpLLE: Result := 'Link Logical Element';
afpMBC: Result := 'Map Bar Code Object';
afpMCA: Result := 'Map Color Attribute Table';
afpMCC: Result := 'Medium Copy Count';
afpMCD: Result := 'Map Container Data';
afpMCF: Result := 'Map Coded Font';
afpMCF1: Result := 'Map Coded Font Format-1 (C)';
afpMDD: Result := 'Medium Descriptor';
afpMDR: Result := 'Map Data Resource';
afpMFC: Result := 'Medium Finishing Control';
afpMGO: Result := 'Map Graphics Object';
afpMIO: Result := 'Map Image Object';
afpMMC: Result := 'Medium Modification Control';
afpMMO: Result := 'Map Medium Overlay';
afpMMT: Result := 'Map Media Type';
afpMPG: Result := 'Map Page';
afpMPO: Result := 'Map Page Overlay';
afpMPS: Result := 'Map Page Segment';
afpMSU: Result := 'Map Suppression';
afpNOP: Result := 'No Operation //EEEED3';
afpOBD: Result := 'Object Area Descriptor';
afpOBP: Result := 'Object Area Position';
afpOCD: Result := 'Object Container Data';
afpPFC: Result := 'Presentation Fidelity Control';
afpPGD: Result := 'Page Descriptor';
afpPGP: Result := 'Page Position';
afpPGP1: Result := 'Page Position Format-1 (C)';
afpPMC: Result := 'Page Modification Control';
afpPTD: Result := 'Presentation Text Data Descriptor';
afpPTD1: Result := 'Presentation Text Descriptor Format-1 (C)';
afpPTX: Result := 'Presentation Text Data';
afpTLE: Result := 'Tag Logical Element'
else
Result := PChar(IntToHex(aId, 4));
end;
end;
function TAFPDS.GetFieldName: String;
begin
case fFieldValue of
afpBAG: Result := 'Begin Active Environment Group';
afpBBC: Result := 'Begin Bar Code Object';
afpBCA: Result := 'Begin Color Attribute Table';
afpBDA: Result := 'Bar Code Data';
afpBDD: Result := 'Bar Code Data Descriptor';
afpBDG: Result := 'Begin Document Environment Group';
afpBDI: Result := 'Begin Document Index';
afpBDT: Result := 'Begin Document';
afpBFG: Result := 'Begin Form Environment Group (Obsolete)';
afpBFM: Result := 'Begin Form Map';
afpBGR: Result := 'Begin Graphics Object';
afpBII: Result := 'Begin IM Image (C)';
afpBIM: Result := 'Begin Image Object';
afpBMM: Result := 'Begin Medium Map';
afpBMO: Result := 'Begin Overlay';
afpBNG: Result := 'Begin Named Page Group';
afpBOC: Result := 'Begin Object Container';
afpBOG: Result := 'Begin Object Environment Group';
afpBPG: Result := 'Begin Page';
afpBPS: Result := 'Begin Page Segment';
afpBPT: Result := 'Begin Presentation Text Object';
afpBR : Result := 'Begin Resource (R)';
afpBRG: Result := 'Begin Resource Group';
afpBSG: Result := 'Begin Resource Environment Group';
afpCAT: Result := 'Color Attribute Table';
afpCDD: Result := 'Container Data Descriptor';
afpCTC: Result := 'Composed Text Control (O)';
afpEAG: Result := 'End Active Environment Group';
afpEBC: Result := 'End Bar Code Object';
afpECA: Result := 'End Color Attribute Table';
afpEDG: Result := 'End Document Environment Group';
afpEDI: Result := 'End Document Index';
afpEDT: Result := 'End Document';
afpEFG: Result := 'End Form Environment Group (Obsolete)';
afpEFM: Result := 'End Form Map';
afpEGR: Result := 'End Graphics Object';
afpEII: Result := 'End IM Image (C)';
afpEIM: Result := 'End Image Object';
afpEMM: Result := 'End Medium Map';
afpEMO: Result := 'End Overlay';
afpENG: Result := 'End Named Page Group';
afpEOC: Result := 'End Object Container';
afpEOG: Result := 'End Object Environment Group';
afpEPG: Result := 'End Page';
afpEPS: Result := 'End Page Segment';
afpEPT: Result := 'End Presentation Text Object';
afpER : Result := 'End Resource (R)';
afpERG: Result := 'End Resource Group';
afpESG: Result := 'End Resource Environment Group';
afpFGD: Result := 'Form Environment Group Descriptor (Obsolete)';
afpGAD: Result := 'Graphics Data';
afpGDD: Result := 'Graphics Data Descriptor';
afpICP: Result := 'IM Image Cell Position (C)';
afpIDD: Result := 'Image Data Descriptor';
afpIEL: Result := 'Index Element';
afpIID: Result := 'IM Image Input Descriptor (C)';
afpIMM: Result := 'Invoke Medium Map';
afpIOB: Result := 'Include Object';
afpIOC: Result := 'IM Image Output Control (C)';
afpIPD: Result := 'Image Picture Data';
afpIPG: Result := 'Include Page';
afpIPO: Result := 'Include Page Overlay';
afpIPS: Result := 'Include Page Segment';
afpIRD: Result := 'IM Image Raster Data (C)';
afpLLE: Result := 'Link Logical Element';
afpMBC: Result := 'Map Bar Code Object';
afpMCA: Result := 'Map Color Attribute Table';
afpMCC: Result := 'Medium Copy Count';
afpMCD: Result := 'Map Container Data';
afpMCF: Result := 'Map Coded Font';
afpMCF1: Result := 'Map Coded Font Format-1 (C)';
afpMDD: Result := 'Medium Descriptor';
afpMDR: Result := 'Map Data Resource';
afpMFC: Result := 'Medium Finishing Control';
afpMGO: Result := 'Map Graphics Object';
afpMIO: Result := 'Map Image Object';
afpMMC: Result := 'Medium Modification Control';
afpMMO: Result := 'Map Medium Overlay';
afpMMT: Result := 'Map Media Type';
afpMPG: Result := 'Map Page';
afpMPO: Result := 'Map Page Overlay';
afpMPS: Result := 'Map Page Segment';
afpMSU: Result := 'Map Suppression';
afpNOP: Result := 'No Operation //EEEED3';
afpOBD: Result := 'Object Area Descriptor';
afpOBP: Result := 'Object Area Position';
afpOCD: Result := 'Object Container Data';
afpPFC: Result := 'Presentation Fidelity Control';
afpPGD: Result := 'Page Descriptor';
afpPGP: Result := 'Page Position';
afpPGP1: Result := 'Page Position Format-1 (C)';
afpPMC: Result := 'Page Modification Control';
afpPTD: Result := 'Presentation Text Data Descriptor';
afpPTD1: Result := 'Presentation Text Descriptor Format-1 (C)';
afpPTX: Result := 'Presentation Text Data';
afpTLE: Result := 'Tag Logical Element'
else
Result := PChar(IntToHex(aId, 4));
end;
end;
function TfrmMain.ParseFile(aFileName: String): Boolean;
const
cBeginBlock: byte = $5A;
var
sMem: TStream;
buf: Byte;
LenTag: SmallInt;
IdTag: Integer;
SaveEAX: Integer;
begin
sMem := TFileStream.Create(aFileName, fmOpenRead or fmShareExclusive);
try
sMem.Position := 0;
while sMem.Position < sMem.Size do
begin
sMem.Read(buf, 1);
if (buf <> cBeginBlock) then
continue;
LenTag := 0;
sMem.Read(LenTag, 2);
asm// ìåíÿåì áàéòû ìåñòàìè, SwapBytes
ror LenTag, 8;
end;
IdTag := 0;
sMem.Read(IdTag, 3);
asm
mov SaveEAX, eax;
mov eax, IdTag;
BSWAP eax;
mov IdTag, eax;
ror IdTag, 8
mov eax, SaveEAX;
end;
//Memo1.Lines.Add(PChar(IntToStr(IdTag)));
Memo1.Lines.Add(IdName(IdTag));
//OutputDebugString(PChar(IntToHex(IdTag, 4)));
sMem.Position := sMem.Position + (LenTag - (2 + 3));
end;
finally
FreeAndNil(sMem);
end;
ShowMessage('ok');
end;
end.