1 |
UNIT Unit13_rawedit; |
2 |
INTERFACE |
3 |
USES |
4 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
5 |
Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd, |
6 |
Unit3_data, Unit2_functions, Unit9_data_structures, Unit4_exporters, Menus, Math; |
7 |
|
8 |
TYPE |
9 |
TForm13 = Class(TForm) |
10 |
Splitter1: TSplitter; |
11 |
panel_data: TPanel; |
12 |
hex: TMPHexEditor; |
13 |
Splitter2: TSplitter; |
14 |
structs: TWrapGrid; |
15 |
value_viewer: TWrapGrid; |
16 |
Splitter3: TSplitter; |
17 |
value_viewer_context: TPopupMenu; |
18 |
value_viewer_context_copy: TMenuItem; |
19 |
value_viewer_context_copyashex: TMenuItem; |
20 |
value_viewer_context_copyasdec: TMenuItem; |
21 |
value_viewer_context_copyasfloat: TMenuItem; |
22 |
value_viewer_context_copyasbitset: TMenuItem; |
23 |
value_viewer_context_copyasstring: TMenuItem; |
24 |
panel_files: TPanel; |
25 |
opend: TOpenDialog; |
26 |
saved: TSaveDialog; |
27 |
panel_imexport: TPanel; |
28 |
btn_export: TButton; |
29 |
btn_import: TButton; |
30 |
group_file: TGroupBox; |
31 |
list: TListBox; |
32 |
panel_extension: TPanel; |
33 |
lbl_filter: TLabel; |
34 |
combo_extension: TComboBox; |
35 |
check_zerobyte: TCheckBox; |
36 |
edit_filtername: TEdit; |
37 |
check_filtername: TCheckBox; |
38 |
GroupBox1: TGroupBox; |
39 |
list_offset: TListBox; |
40 |
Splitter4: TSplitter; |
41 |
PROCEDURE list_offsetClick(Sender: TObject); |
42 |
PROCEDURE LoadRaw(raw_info:TRawInfo); |
43 |
PROCEDURE LoadFileNames; |
44 |
PROCEDURE check_filternameClick(Sender: TObject); |
45 |
PROCEDURE check_zerobyteClick(Sender: TObject); |
46 |
PROCEDURE combo_extensionClick(Sender: TObject); |
47 |
PROCEDURE panel_extensionResize(Sender: TObject); |
48 |
PROCEDURE listClick(Sender: TObject); |
49 |
PROCEDURE Recreatelist; |
50 |
|
51 |
PROCEDURE FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
52 |
PROCEDURE value_viewerDblClick(Sender: TObject); |
53 |
PROCEDURE structsDblClick(Sender: TObject); |
54 |
PROCEDURE value_viewer_context_copyClick(Sender: TObject); |
55 |
PROCEDURE value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
56 |
PROCEDURE value_viewer_contextPopup(Sender: TObject); |
57 |
PROCEDURE FormActivate(Sender: TObject); |
58 |
PROCEDURE btn_importClick(Sender: TObject); |
59 |
PROCEDURE btn_exportClick(Sender: TObject); |
60 |
PROCEDURE panel_imexportResize(Sender: TObject); |
61 |
FUNCTION Save:Boolean; |
62 |
PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction); |
63 |
FUNCTION GetValue(datatype:Word; offset:LongWord):String; |
64 |
PROCEDURE WriteStructureInfos(structinfoid:Integer); |
65 |
PROCEDURE hexSelectionChanged(Sender: TObject); |
66 |
PROCEDURE hexChange(Sender: TObject); |
67 |
PROCEDURE panel_dataResize(Sender: TObject); |
68 |
PROCEDURE structsClick(Sender: TObject); |
69 |
PROCEDURE FormResize(Sender: TObject); |
70 |
PROCEDURE ClearStructViewer; |
71 |
PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
72 |
PROCEDURE FormCreate(Sender: TObject); |
73 |
PROCEDURE ClearValues; |
74 |
PROCEDURE WriteValues; |
75 |
PROCEDURE SetNewValue(datatype:Word; offset:LongWord; value:String); |
76 |
PRIVATE |
77 |
PUBLIC |
78 |
END; |
79 |
|
80 |
VAR |
81 |
Form13: TForm13; |
82 |
|
83 |
IMPLEMENTATION |
84 |
{$R *.dfm} |
85 |
USES Unit1_main, Unit12_ValueEdit; |
86 |
VAR |
87 |
fileid:LongWord; |
88 |
dat_offset:LongWord; |
89 |
fileid_opened,dat_offset_opened:LongWord; |
90 |
|
91 |
|
92 |
PROCEDURE TForm13.LoadRaw(raw_info:TRawInfo); |
93 |
VAR |
94 |
i:LongWord; |
95 |
data:Tdata; |
96 |
mem:TMemoryStream; |
97 |
BEGIN |
98 |
IF hex.Modified THEN BEGIN |
99 |
IF NOT Save THEN BEGIN |
100 |
Exit; |
101 |
END; |
102 |
END; |
103 |
Self.ClearStructViewer; |
104 |
SetLength(data,raw_info.raw_size); |
105 |
LoadRawFilebyIDOffset(raw_info.src_id,raw_info.src_offset,@data[0]); |
106 |
IF Length(data)>0 THEN BEGIN |
107 |
hex.DataSize:=0; |
108 |
hex.DataSize:=raw_info.raw_size; |
109 |
FOR i:=0 TO High(data) DO |
110 |
hex.Data[i]:=data[i]; |
111 |
//WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension)); |
112 |
structs.Height:=structs.RowCount*20; |
113 |
IF structs.Height>120 THEN structs.Height:=120; |
114 |
hexSelectionChanged(Self); |
115 |
fileid_opened:=raw_info.src_id; |
116 |
dat_offset_opened:=raw_info.src_offset; |
117 |
hex.Modified:=False; |
118 |
END ELSE BEGIN |
119 |
ClearValues; |
120 |
hex.DataSize:=0; |
121 |
END; |
122 |
END; |
123 |
|
124 |
PROCEDURE TForm13.Recreatelist; |
125 |
VAR |
126 |
i:LongWord; |
127 |
exts:TStringList; |
128 |
BEGIN |
129 |
combo_extension.Items.Clear; |
130 |
combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)}+')'); |
131 |
exts:=GetExtensionsList; |
132 |
FOR i:=0 TO High(exts) DO |
133 |
combo_extension.Items.Add(exts[i]); |
134 |
combo_extension.ItemIndex:=0; |
135 |
combo_extensionClick(Self); |
136 |
END; |
137 |
|
138 |
PROCEDURE TForm13.LoadFileNames; |
139 |
VAR |
140 |
Extension:String[4]; |
141 |
no_zero_bytes:Boolean; |
142 |
pattern:String; |
143 |
files:TStringList; |
144 |
i:LongWord; |
145 |
BEGIN |
146 |
Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4); |
147 |
no_zero_bytes:=NOT check_zerobyte.Checked; |
148 |
pattern:=''; |
149 |
IF check_filtername.Checked THEN pattern:=edit_filtername.Text; |
150 |
IF Extension='_All' THEN Extension:=''; |
151 |
|
152 |
files:=GetFilesList(extension,pattern,no_zero_bytes); |
153 |
list.Items.Clear; |
154 |
IF Length(files)>0 THEN |
155 |
FOR i:=0 TO High(files) DO |
156 |
list.Items.Add(files[i]); |
157 |
list_offset.Items.Clear; |
158 |
END; |
159 |
|
160 |
PROCEDURE TForm13.panel_extensionResize(Sender: TObject); |
161 |
BEGIN |
162 |
combo_extension.Width:=panel_extension.Width-5; |
163 |
edit_filtername.Width:=panel_extension.Width-5; |
164 |
END; |
165 |
|
166 |
PROCEDURE TForm13.combo_extensionClick(Sender: TObject); |
167 |
BEGIN |
168 |
LoadFileNames; |
169 |
END; |
170 |
|
171 |
PROCEDURE TForm13.check_zerobyteClick(Sender: TObject); |
172 |
VAR |
173 |
i:Byte; |
174 |
BEGIN |
175 |
LoadFileNames; |
176 |
END; |
177 |
|
178 |
PROCEDURE TForm13.check_filternameClick(Sender: TObject); |
179 |
BEGIN |
180 |
edit_filtername.Enabled:=NOT check_filtername.Checked; |
181 |
LoadFileNames; |
182 |
END; |
183 |
|
184 |
PROCEDURE TForm13.listClick(Sender: TObject); |
185 |
VAR |
186 |
mem:TMemoryStream; |
187 |
data:Tdata; |
188 |
i:LongWord; |
189 |
offsets:TRawList; |
190 |
BEGIN |
191 |
Self.ClearStructViewer; |
192 |
IF hex.Modified THEN BEGIN |
193 |
IF NOT Save THEN BEGIN |
194 |
Exit; |
195 |
END; |
196 |
END; |
197 |
ClearValues; |
198 |
hex.DataSize:=0; |
199 |
fileid:=StrToInt(MidStr(list.Items.Strings[list.ItemIndex],1,5)); |
200 |
list_offset.Enabled:=True; |
201 |
IF GetFileInfo(fileid).size>0 THEN BEGIN |
202 |
offsets:=GetRawList(fileid); |
203 |
list_offset.Items.Clear; |
204 |
IF Length(offsets)>0 THEN BEGIN |
205 |
FOR i:=0 TO High(offsets) DO BEGIN |
206 |
list_offset.Items.Add('0x'+IntToHex(offsets[i].src_offset,6)+', '+IntToStr(offsets[i].raw_size)+' bytes'); |
207 |
END; |
208 |
END ELSE BEGIN |
209 |
list_offset.Enabled:=False; |
210 |
END; |
211 |
END ELSE BEGIN |
212 |
list_offset.Enabled:=False; |
213 |
END; |
214 |
END; |
215 |
|
216 |
PROCEDURE TForm13.list_offsetClick(Sender: TObject); |
217 |
VAR |
218 |
i:LongWord; |
219 |
raw_info:TRawInfo; |
220 |
BEGIN |
221 |
Self.ClearStructViewer; |
222 |
ClearValues; |
223 |
dat_offset:=StrToInt('$'+MidStr(list_offset.Items.Strings[list_offset.ItemIndex],3,6)); |
224 |
LoadRaw(GetRawInfo(fileid,dat_offset)); |
225 |
END; |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
FUNCTION IntToBin(value:Byte):String; |
231 |
VAR i:Byte; |
232 |
BEGIN |
233 |
Result:=''; |
234 |
FOR i:=7 DOWNTO 0 DO BEGIN |
235 |
Result:=Result+IntToStr((value SHR i) AND $01); |
236 |
END; |
237 |
END; |
238 |
|
239 |
FUNCTION TForm13.GetValue(datatype:Word; offset:LongWord):String; |
240 |
VAR |
241 |
data:Tdata; |
242 |
i:Word; |
243 |
BEGIN |
244 |
CASE datatype OF |
245 |
1: Result:=IntToStr(hex.data[offset]); |
246 |
2: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256); |
247 |
3: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256); |
248 |
4: Result:=IntToStr(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256); |
249 |
5: Result:='0x'+IntToHex(hex.data[offset],2); |
250 |
6: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256,4); |
251 |
7: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256,6); |
252 |
8: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8); |
253 |
9: BEGIN |
254 |
SetLength(data,4); |
255 |
data[0]:=hex.data[offset]; |
256 |
data[1]:=hex.data[offset+1]; |
257 |
data[2]:=hex.data[offset+2]; |
258 |
data[3]:=hex.data[offset+3]; |
259 |
Result:=FloatToStr(Decode_Float(data)); |
260 |
END; |
261 |
10: Result:=IntToBin(hex.data[offset]); |
262 |
11: Result:='0x'+IntToHex(hex.data[offset]+hex.data[offset+1]*256+hex.data[offset+2]*256*256+hex.data[offset+3]*256*256*256,8); |
263 |
10000..65535: BEGIN |
264 |
Result:=''; |
265 |
FOR i:=1 TO datatype-10000 DO BEGIN |
266 |
IF hex.Data[offset+i-1]>=32 THEN |
267 |
Result:=Result+Chr(hex.Data[offset+i-1]) |
268 |
ELSE |
269 |
Result:=Result+'.'; |
270 |
END; |
271 |
END; |
272 |
END; |
273 |
END; |
274 |
|
275 |
PROCEDURE TForm13.WriteStructureInfos(structinfoid:Integer); |
276 |
VAR |
277 |
i:Byte; |
278 |
BEGIN |
279 |
IF structinfoid>=0 THEN BEGIN |
280 |
structs.Enabled:=True; |
281 |
WITH structure_infos[structinfoid] DO BEGIN |
282 |
Self.structs.RowCount:=Length(entries)+1; |
283 |
FOR i:=1 TO Length(entries) DO BEGIN |
284 |
Self.structs.Cells[0,i]:=entries[i-1].name; |
285 |
Self.structs.Cells[1,i]:='0x'+IntToHex(entries[i-1].offset,6); |
286 |
Self.structs.Cells[2,i]:=GetDataType(entries[i-1].datatype); |
287 |
IF entries[i-1].datatype>10000 THEN |
288 |
Self.structs.Cells[3,i]:='*String*#HINT:'+GetValue(entries[i-1].datatype,entries[i-1].offset)+'#' |
289 |
ELSE |
290 |
Self.structs.Cells[3,i]:=GetValue(entries[i-1].datatype,entries[i-1].offset); |
291 |
Self.structs.Cells[4,i]:=entries[i-1].description; |
292 |
END; |
293 |
END; |
294 |
END; |
295 |
END; |
296 |
|
297 |
PROCEDURE TForm13.ClearValues; |
298 |
VAR |
299 |
i:Byte; |
300 |
BEGIN |
301 |
FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN |
302 |
value_viewer.Cells[1,i]:=''; |
303 |
END; |
304 |
END; |
305 |
|
306 |
PROCEDURE TForm13.WriteValues; |
307 |
VAR |
308 |
i,j:Byte; |
309 |
data:Tdata; |
310 |
str:String; |
311 |
value:LongWord; |
312 |
BEGIN |
313 |
FOR i:=1 TO value_viewer.RowCount-1 DO BEGIN |
314 |
IF value_viewer.Cells[0,i]='1 byte, unsigned' THEN BEGIN |
315 |
IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN BEGIN |
316 |
value:=hex.Data[hex.SelStart]; |
317 |
value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 2 ); |
318 |
END ELSE |
319 |
value_viewer.Cells[1,i]:=''; |
320 |
END; |
321 |
IF value_viewer.Cells[0,i]='2 bytes, unsigned' THEN BEGIN |
322 |
IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN BEGIN |
323 |
value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256; |
324 |
value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 4 ); |
325 |
END ELSE |
326 |
value_viewer.Cells[1,i]:=''; |
327 |
END; |
328 |
IF value_viewer.Cells[0,i]='4 bytes, unsigned' THEN BEGIN |
329 |
IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN |
330 |
value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256; |
331 |
value_viewer.Cells[1,i]:=IntToStr( value )+' / 0x'+IntToHex( value , 8 ); |
332 |
END ELSE |
333 |
value_viewer.Cells[1,i]:=''; |
334 |
END; |
335 |
IF value_viewer.Cells[0,i]='Bitset' THEN BEGIN |
336 |
IF (hex.SelCount<=8) THEN BEGIN |
337 |
IF hex.SelCount=0 THEN BEGIN |
338 |
SetLength(data,1); |
339 |
data[0]:=hex.Data[hex.SelStart]; |
340 |
END ELSE BEGIN |
341 |
SetLength(data,hex.SelCount); |
342 |
FOR j:=0 TO hex.SelCount-1 DO |
343 |
data[j]:=hex.Data[hex.SelStart+j]; |
344 |
END; |
345 |
value_viewer.Cells[1,i]:=DataToBin(data); |
346 |
END ELSE |
347 |
value_viewer.Cells[1,i]:=''; |
348 |
END; |
349 |
IF value_viewer.Cells[0,i]='Float' THEN BEGIN |
350 |
IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN BEGIN |
351 |
SetLength(data,4); |
352 |
FOR j:=0 TO 3 DO |
353 |
data[j]:=hex.Data[hex.SelStart+j]; |
354 |
value_viewer.Cells[1,i]:=FloatToStr(Decode_Float(data)); |
355 |
END ELSE |
356 |
value_viewer.Cells[1,i]:=''; |
357 |
END; |
358 |
IF value_viewer.Cells[0,i]='Selected length' THEN BEGIN |
359 |
value_viewer.Cells[1,i]:=IntToStr(hex.SelCount)+' bytes'; |
360 |
END; |
361 |
IF value_viewer.Cells[0,i]='String' THEN BEGIN |
362 |
j:=0; |
363 |
str:=''; |
364 |
IF hex.SelCount=0 THEN BEGIN |
365 |
{ WHILE (hex.Data[hex.SelStart+j]>0) AND ((hex.SelStart+j)<hex.DataSize) DO BEGIN |
366 |
IF hex.Data[hex.selstart+j]>=32 THEN |
367 |
str:=str+Char(hex.Data[hex.SelStart+j]) |
368 |
ELSE |
369 |
str:=str+'.'; |
370 |
Inc(j); |
371 |
END; |
372 |
} END ELSE BEGIN |
373 |
FOR j:=1 TO hex.SelCount DO |
374 |
str:=str+Char(hex.Data[hex.SelStart+j-1]); |
375 |
END; |
376 |
value_viewer.Cells[1,i]:=str; |
377 |
END; |
378 |
END; |
379 |
END; |
380 |
|
381 |
PROCEDURE TForm13.FormCreate(Sender: TObject); |
382 |
BEGIN |
383 |
Self.Caption:=''; |
384 |
fileid:=0; |
385 |
structs.Height:=40; |
386 |
structs.ColCount:=5; |
387 |
structs.RowCount:=2; |
388 |
structs.FixedRows:=1; |
389 |
structs.Cells[0,0]:='Name'; |
390 |
structs.Cells[1,0]:='Offset'; |
391 |
structs.Cells[2,0]:='Type'; |
392 |
structs.Cells[3,0]:='Value'; |
393 |
structs.Cells[4,0]:='Description'; |
394 |
structs.ColWidths[0]:=75; |
395 |
structs.ColWidths[1]:=60; |
396 |
structs.ColWidths[2]:=75; |
397 |
structs.ColWidths[3]:=75; |
398 |
value_viewer.ColCount:=2; |
399 |
value_viewer.RowCount:=8; |
400 |
value_viewer.FixedRows:=1; |
401 |
value_viewer.Cells[0,0]:='Type'; |
402 |
value_viewer.Cells[1,0]:='Value'; |
403 |
value_viewer.Cells[0,1]:='1 byte, unsigned'; |
404 |
value_viewer.Cells[0,2]:='2 bytes, unsigned'; |
405 |
value_viewer.Cells[0,3]:='4 bytes, unsigned'; |
406 |
value_viewer.Cells[0,4]:='Bitset'; |
407 |
value_viewer.Cells[0,5]:='Float'; |
408 |
value_viewer.Cells[0,6]:='String'; |
409 |
value_viewer.Cells[0,7]:='Selected length'; |
410 |
value_viewer.ColWidths[0]:=100; |
411 |
hex.Height:=panel_data.Height-215; |
412 |
Self.panel_dataResize(Self); |
413 |
END; |
414 |
|
415 |
FUNCTION TForm13.Save:Boolean; |
416 |
VAR |
417 |
mem:TMemoryStream; |
418 |
data:Tdata; |
419 |
i:LongWord; |
420 |
BEGIN |
421 |
CASE MessageBox(Self.Handle,PChar('Save changes to .raw-part of file '+GetFileInfo(fileid).FileName+'?'),PChar('Data changed...'),MB_YESNOCANCEL) OF |
422 |
IDYES: BEGIN |
423 |
mem:=TMemoryStream.Create; |
424 |
hex.SaveToStream(mem); |
425 |
mem.Seek(0,soFromBeginning); |
426 |
SetLength(data,mem.Size); |
427 |
mem.Read(data[0],mem.Size); |
428 |
mem.Free; |
429 |
UpdateRawFile(GetRawInfo(fileid_opened,dat_offset_opened),@data[0]); |
430 |
hex.Modified:=False; |
431 |
FOR i:=0 TO hex.Datasize-1 DO hex.ByteChanged[i]:=False; |
432 |
Result:=True; |
433 |
END; |
434 |
IDNO: Result:=True; |
435 |
IDCANCEL: BEGIN |
436 |
Result:=False; |
437 |
END; |
438 |
END; |
439 |
END; |
440 |
|
441 |
PROCEDURE TForm13.FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
442 |
BEGIN |
443 |
IF hex.Modified THEN BEGIN |
444 |
IF NOT Save THEN CanClose:=False; |
445 |
END; |
446 |
END; |
447 |
|
448 |
PROCEDURE TForm13.ClearStructViewer; |
449 |
VAR |
450 |
x:Word; |
451 |
BEGIN |
452 |
structs.RowCount:=2; |
453 |
FOR x:=0 TO structs.ColCount-1 DO structs.Cells[x,1]:=''; |
454 |
structs.Enabled:=False; |
455 |
structs.Height:=40; |
456 |
END; |
457 |
|
458 |
PROCEDURE TForm13.FormResize(Sender: TObject); |
459 |
BEGIN |
460 |
IF Self.Width>=650 THEN BEGIN |
461 |
END ELSE Self.Width:=650; |
462 |
IF Self.Height>=450 THEN BEGIN |
463 |
END ELSE Self.Height:=450; |
464 |
END; |
465 |
|
466 |
PROCEDURE TForm13.structsClick(Sender: TObject); |
467 |
VAR |
468 |
offset:LongWord; |
469 |
length:Byte; |
470 |
BEGIN |
471 |
IF structs.Row>0 THEN BEGIN |
472 |
offset:=structure_infos[GetStructureInfoId(GetFileInfo(fileid).extension)].entries[structs.Row-1].offset; |
473 |
length:=GetTypeDataLength(structure_infos[GetStructureInfoId(GetFileInfo(fileid).extension)].entries[structs.Row-1].datatype); |
474 |
hex.SelStart:=offset; |
475 |
hex.SelEnd:=offset+length-1; |
476 |
END; |
477 |
END; |
478 |
|
479 |
PROCEDURE TForm13.panel_dataResize(Sender: TObject); |
480 |
BEGIN |
481 |
structs.ColWidths[4]:=structs.Width-structs.ColWidths[0]-structs.ColWidths[1]-structs.ColWidths[2]-structs.ColWidths[3]-28; |
482 |
value_viewer.ColWidths[1]:=value_viewer.Width-value_viewer.ColWidths[0]-28; |
483 |
END; |
484 |
|
485 |
PROCEDURE TForm13.hexChange(Sender: TObject); |
486 |
BEGIN |
487 |
ClearValues; |
488 |
IF hex.DataSize>0 THEN BEGIN |
489 |
WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension)); |
490 |
WriteValues; |
491 |
END; |
492 |
END; |
493 |
|
494 |
PROCEDURE TForm13.hexSelectionChanged(Sender: TObject); |
495 |
VAR |
496 |
selstart:Integer; |
497 |
i,j:Word; |
498 |
BEGIN |
499 |
{ FOR i:=1 TO structs.RowCount-1 DO BEGIN |
500 |
FOR j:=0 TO structs.ColCount-1 DO BEGIN |
501 |
structs.CellColors[j,i]:=clWhite; |
502 |
structs.CellFontColors[j,i]:=clBlack; |
503 |
END; |
504 |
END; |
505 |
} IF hex.DataSize>0 THEN BEGIN |
506 |
{ selstart:=hex.SelStart; |
507 |
IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN |
508 |
WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN |
509 |
FOR i:=0 TO High(entries) DO BEGIN |
510 |
IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN |
511 |
FOR j:=0 TO structs.ColCount-1 DO BEGIN |
512 |
structs.CellColors[j,i+1]:=clBlue; |
513 |
structs.CellFontColors[j,i+1]:=clWhite; |
514 |
END; |
515 |
structs.Row:=i+1; |
516 |
END; |
517 |
END; |
518 |
END; |
519 |
END; |
520 |
} WriteValues; |
521 |
END; |
522 |
END; |
523 |
|
524 |
PROCEDURE TForm13.FormClose(Sender: TObject; var Action: TCloseAction); |
525 |
BEGIN |
526 |
Action:=caFree; |
527 |
Form1.close_window(Self.Name); |
528 |
END; |
529 |
|
530 |
PROCEDURE TForm13.panel_imexportResize(Sender: TObject); |
531 |
BEGIN |
532 |
btn_import.Width:=panel_imexport.Width-8; |
533 |
btn_export.Width:=panel_imexport.Width-8; |
534 |
END; |
535 |
|
536 |
PROCEDURE TForm13.btn_exportClick(Sender: TObject); |
537 |
VAR |
538 |
fs:TFileStream; |
539 |
BEGIN |
540 |
saved.Filter:='Files of matching extension (*.'+GetFileInfo(fileid).Extension+')|*.'+dat_files[fileid].Extension+'|All files|*.*'; |
541 |
saved.DefaultExt:=GetFileInfo(fileid).Extension; |
542 |
IF saved.Execute THEN BEGIN |
543 |
fs:=TFileStream.Create(saved.FileName,fmCreate); |
544 |
hex.SaveToStream(fs); |
545 |
fs.Free; |
546 |
END; |
547 |
END; |
548 |
|
549 |
PROCEDURE TForm13.btn_importClick(Sender: TObject); |
550 |
VAR |
551 |
data:Tdata; |
552 |
fs:TFileStream; |
553 |
BEGIN |
554 |
opend.Filter:='Files of matching extension (*.'+GetFileInfo(fileid).Extension+')|*.'+dat_files[fileid].Extension+'|All files|*.*'; |
555 |
IF opend.Execute THEN BEGIN |
556 |
fs:=TFileStream.Create(opend.FileName,fmOpenRead); |
557 |
IF fs.Size<>hex.DataSize THEN BEGIN |
558 |
ShowMessage('Can''t import '+ExtractFilename(opend.FileName)+ |
559 |
', file has to have same size as file in .dat.'+CrLf+ |
560 |
'Size of file in .dat: '+FormatFileSize(hex.datasize)+CrLf+ |
561 |
'Size of chosen file: '+FormatFileSize(fs.Size)); |
562 |
END ELSE BEGIN |
563 |
hex.LoadFromStream(fs); |
564 |
hex.Modified:=True; |
565 |
END; |
566 |
fs.Free; |
567 |
END; |
568 |
END; |
569 |
|
570 |
PROCEDURE TForm13.FormActivate(Sender: TObject); |
571 |
BEGIN |
572 |
Form1.SetActiveWindow(Self.Name); |
573 |
END; |
574 |
|
575 |
PROCEDURE TForm13.value_viewer_contextPopup(Sender: TObject); |
576 |
VAR |
577 |
i:Byte; |
578 |
BEGIN |
579 |
FOR i:=0 TO value_viewer_context.Items.Count-1 DO |
580 |
value_viewer_context.Items.Items[i].Visible:=False; |
581 |
WITH value_viewer DO BEGIN |
582 |
IF (Col=1) AND (Row>0) AND (Length(Cells[Col,Row])>0) THEN BEGIN |
583 |
IF Pos(' byte',Cells[0,Row])=2 THEN BEGIN |
584 |
value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True; |
585 |
value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible:=True; |
586 |
value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible:=True; |
587 |
END; |
588 |
IF Pos('Float',Cells[0,Row])=1 THEN |
589 |
value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible:=True; |
590 |
IF Pos('Bitset',Cells[0,Row])=1 THEN |
591 |
value_viewer_context.Items.Find('Copy to clipboard (as &bitset)').Visible:=True; |
592 |
IF Pos('String',Cells[0,Row])=1 THEN |
593 |
value_viewer_context.Items.Find('Copy to clipboard (as &string)').Visible:=True; |
594 |
IF Pos('Selected length',Cells[0,Row])=1 THEN |
595 |
value_viewer_context.Items.Find('Copy to &clipboard').Visible:=True; |
596 |
END; |
597 |
END; |
598 |
END; |
599 |
|
600 |
PROCEDURE TForm13.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
601 |
VAR |
602 |
ACol,ARow:Integer; |
603 |
BEGIN |
604 |
IF Button=mbRight THEN BEGIN |
605 |
value_viewer.MouseToCell(x,y,ACol,ARow); |
606 |
IF ARow>0 THEN BEGIN |
607 |
value_viewer.Col:=ACol; |
608 |
value_viewer.Row:=ARow; |
609 |
END; |
610 |
END; |
611 |
END; |
612 |
|
613 |
PROCEDURE TForm13.value_viewer_context_copyClick(Sender: TObject); |
614 |
VAR |
615 |
i:Byte; |
616 |
name:String; |
617 |
value:LongWord; |
618 |
BEGIN |
619 |
name:=TMenuItem(Sender).Name; |
620 |
IF Pos('asstring',name)>0 THEN BEGIN |
621 |
Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; |
622 |
END ELSE |
623 |
IF Pos('asfloat',name)>0 THEN BEGIN |
624 |
Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; |
625 |
END ELSE |
626 |
IF Pos('asbitset',name)>0 THEN BEGIN |
627 |
Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; |
628 |
END ELSE |
629 |
IF (Pos('ashex',name)>0) OR (Pos('asdec',name)>0) THEN BEGIN |
630 |
IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN BEGIN |
631 |
IF ((hex.SelCount=1) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+1)>hex.DataSize) THEN |
632 |
value:=hex.Data[hex.SelStart]; |
633 |
END; |
634 |
IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN BEGIN |
635 |
IF ((hex.SelCount=2) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+2)>hex.DataSize) THEN |
636 |
value:=hex.Data[hex.SelStart] + hex.Data[hex.SelStart+1]*256; |
637 |
END; |
638 |
IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN BEGIN |
639 |
IF ((hex.SelCount=4) OR (hex.SelCount=0)) AND NOT ((hex.SelStart+4)>hex.DataSize) THEN |
640 |
value:=hex.Data[hex.SelStart]+hex.Data[hex.SelStart+1]*256+hex.Data[hex.SelStart+2]*256*256+hex.Data[hex.SelStart+3]*256*256*256; |
641 |
END; |
642 |
IF Pos('asdec',name)>0 THEN BEGIN |
643 |
Clipboard.AsText:=IntToStr(value); |
644 |
END ELSE BEGIN |
645 |
IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN |
646 |
Clipboard.AsText:='0x'+IntToHex(value,2); |
647 |
IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN |
648 |
Clipboard.AsText:='0x'+IntToHex(value,4); |
649 |
IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN |
650 |
Clipboard.AsText:='0x'+IntToHex(value,8); |
651 |
END; |
652 |
END ELSE BEGIN |
653 |
Clipboard.AsText:=value_viewer.Cells[value_viewer.Col,value_viewer.Row]; |
654 |
END; |
655 |
END; |
656 |
|
657 |
PROCEDURE TForm13.structsDblClick(Sender: TObject); |
658 |
VAR |
659 |
offset:LongWord; |
660 |
datatype:Word; |
661 |
objectname:String; |
662 |
value:String; |
663 |
BEGIN |
664 |
IF (structs.Row>0) AND (structs.Cells[structs.Col,0]='Value') THEN BEGIN |
665 |
offset:=structure_infos[GetStructureInfoId(GetFileInfo(fileid).extension)].entries[structs.Row-1].offset; |
666 |
datatype:=structure_infos[GetStructureInfoId(GetFileInfo(fileid).extension)].entries[structs.Row-1].datatype; |
667 |
IF datatype<>11 THEN BEGIN |
668 |
objectname:=structure_infos[GetStructureInfoId(GetFileInfo(fileid).extension)].entries[structs.Row-1].name; |
669 |
value:=GetValue(datatype,offset); |
670 |
Form12.MakeVarInput(objectname,offset,datatype,value,Self); |
671 |
END ELSE BEGIN |
672 |
{LOAD RAW-EDITOR} |
673 |
END; |
674 |
END; |
675 |
END; |
676 |
|
677 |
PROCEDURE TForm13.SetNewValue(datatype:Word; offset:LongWord; value:String); |
678 |
VAR |
679 |
data:Tdata; |
680 |
value_int:LongWord; |
681 |
value_float:Single; |
682 |
i:Word; |
683 |
BEGIN |
684 |
CASE datatype OF |
685 |
1..4: BEGIN |
686 |
value_int:=StrToInt(value); |
687 |
SetLength(data,datatype); |
688 |
FOR i:=0 TO datatype-1 DO BEGIN |
689 |
data[i]:=value_int MOD 256; |
690 |
value_int:=value_int DIV 256; |
691 |
END; |
692 |
END; |
693 |
5..8: BEGIN |
694 |
value_int:=StrToInt('$'+value); |
695 |
SetLength(data,datatype-4); |
696 |
FOR i:=0 TO datatype-5 DO BEGIN |
697 |
data[i]:=value_int MOD 256; |
698 |
value_int:=value_int DIV 256; |
699 |
END; |
700 |
END; |
701 |
9: BEGIN |
702 |
value_float:=StrToFloat(value); |
703 |
data:=Encode_Float(value_float); |
704 |
END; |
705 |
10: BEGIN |
706 |
value_int:=BinToInt(value); |
707 |
SetLength(data,1); |
708 |
data[0]:=value_int; |
709 |
END; |
710 |
10000..65535: BEGIN |
711 |
SetLength(data,datatype-10000); |
712 |
FOR i:=1 TO datatype-10000 DO BEGIN |
713 |
IF i<=Length(value) THEN |
714 |
data[i-1]:=Ord(value[i]) |
715 |
ELSE |
716 |
data[i-1]:=0; |
717 |
END; |
718 |
END; |
719 |
END; |
720 |
FOR i:=0 TO High(data) DO BEGIN |
721 |
IF hex.Data[offset+i]<>data[i] THEN hex.ByteChanged[offset+i]:=True; |
722 |
hex.Data[offset+i]:=data[i]; |
723 |
END; |
724 |
hex.Modified:=True; |
725 |
hexChange(Self); |
726 |
hex.Repaint; |
727 |
END; |
728 |
|
729 |
PROCEDURE TForm13.value_viewerDblClick(Sender: TObject); |
730 |
VAR |
731 |
offset:LongWord; |
732 |
datatype:Word; |
733 |
objectname:String; |
734 |
value:String; |
735 |
BEGIN |
736 |
IF (value_viewer.Col=1) AND (Length(value_viewer.Cells[1,value_viewer.Row])>0) THEN BEGIN |
737 |
offset:=hex.SelStart; |
738 |
IF value_viewer.Cells[0,value_viewer.Row]='1 byte, unsigned' THEN |
739 |
datatype:=1; |
740 |
IF value_viewer.Cells[0,value_viewer.Row]='2 bytes, unsigned' THEN |
741 |
datatype:=2; |
742 |
IF value_viewer.Cells[0,value_viewer.Row]='4 bytes, unsigned' THEN |
743 |
datatype:=4; |
744 |
IF value_viewer.Cells[0,value_viewer.Row]='Bitset' THEN |
745 |
datatype:=10; |
746 |
IF value_viewer.Cells[0,value_viewer.Row]='Float' THEN |
747 |
datatype:=9; |
748 |
IF value_viewer.Cells[0,value_viewer.Row]='Selected length' THEN |
749 |
Exit; |
750 |
IF value_viewer.Cells[0,value_viewer.Row]='String' THEN BEGIN |
751 |
IF hex.SelCount>0 THEN |
752 |
datatype:=10000+hex.SelCount |
753 |
ELSE |
754 |
datatype:=10000+Length(value_viewer.Cells[1,value_viewer.Row]); |
755 |
END; |
756 |
objectname:=''; |
757 |
value:=GetValue(datatype,offset); |
758 |
Form12.MakeVarInput(objectname,offset,datatype,value,Self); |
759 |
END; |
760 |
END; |
761 |
|
762 |
PROCEDURE TForm13.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
763 |
BEGIN |
764 |
IF (Shift=[ssCtrl]) AND (Key=83) THEN |
765 |
IF hex.Modified THEN |
766 |
IF NOT Save THEN |
767 |
Exit; |
768 |
END; |
769 |
|
770 |
END. |