source: oup/releases/0.24a/Unit8_binedit.pas@ 765

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