source: oup/releases/0.27a/Unit8_binedit.pas@ 129

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