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