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