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