source: oup/releases/0.28a/Unit8_binedit.pas@ 455

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