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