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