| 1 |
|
unit BinEdit; |
| 2 |
+ |
|
| 3 |
|
interface |
| 4 |
+ |
|
| 5 |
|
uses |
| 6 |
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
< |
Dialogs, Template, StdCtrls, ExtCtrls, VirtualTrees, Grids, Wrapgrid, |
| 8 |
< |
MPHexEditor, VTHeaderPopup, Menus, StrUtils, Clipbrd, |
| 9 |
< |
Data, TypeDefs, ConnectionManager, Buttons; |
| 7 |
> |
Dialogs, VirtualTrees, Grids, Wrapgrid, MPHexEditor, |
| 8 |
> |
StdCtrls, Menus, ExtCtrls, Buttons, |
| 9 |
> |
Data, TypeDefs, ConnectionManager, |
| 10 |
> |
_TemplateFileList, VTHeaderPopup, ComCtrls; |
| 11 |
|
|
| 12 |
|
type |
| 13 |
< |
TForm_BinEdit = class(TForm_ToolTemplate) |
| 13 |
> |
TForm_BinEdit = class(TForm_TemplateFileList) |
| 14 |
> |
panel_imexport: TPanel; |
| 15 |
> |
btn_export: TButton; |
| 16 |
> |
btn_import: TButton; |
| 17 |
|
hex: TMPHexEditor; |
| 18 |
|
Splitter2: TSplitter; |
| 19 |
|
value_viewer: TWrapGrid; |
| 14 |
– |
VST: TVirtualStringTree; |
| 20 |
|
Splitter3: TSplitter; |
| 21 |
+ |
VST: TVirtualStringTree; |
| 22 |
+ |
VTHPopup: TVTHeaderPopupMenu; |
| 23 |
|
value_viewer_context: TPopupMenu; |
| 24 |
|
value_viewer_context_copy: TMenuItem; |
| 25 |
|
value_viewer_context_copyasdec: TMenuItem; |
| 27 |
|
value_viewer_context_copyasbitset: TMenuItem; |
| 28 |
|
value_viewer_context_copyasstring: TMenuItem; |
| 29 |
|
value_viewer_context_copyashex: TMenuItem; |
| 23 |
– |
VTHPopup: TVTHeaderPopupMenu; |
| 24 |
– |
procedure FormCreate(Sender: TObject); |
| 30 |
|
procedure NewFile(fileinfo: TFileInfo); |
| 31 |
|
|
| 27 |
– |
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 28 |
– |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
| 29 |
– |
|
| 30 |
– |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 31 |
– |
procedure hexSelectionChanged(Sender: TObject); |
| 32 |
– |
procedure hexChange(Sender: TObject); |
| 33 |
– |
|
| 34 |
– |
procedure LoadDat(_fileid: Integer); |
| 32 |
|
function Save: Boolean; |
| 33 |
< |
function GetValue(datatype: Word; offset: LongWord): String; |
| 34 |
< |
procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); |
| 33 |
> |
function GetValue(datatype: Word; offset: Integer): String; |
| 34 |
> |
procedure SetNewValue(datatype: Word; offset: Integer; Value: String); |
| 35 |
|
|
| 36 |
|
procedure WriteStructureInfos; |
| 37 |
|
procedure ClearStructViewer; |
| 41 |
– |
procedure VSTDblClick(Sender: TObject); |
| 42 |
– |
procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 43 |
– |
Column: TColumnIndex); |
| 44 |
– |
procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree; |
| 45 |
– |
const Column: TColumnIndex; Visible: Boolean); |
| 46 |
– |
procedure VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex; |
| 47 |
– |
OldPosition: Integer); |
| 48 |
– |
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 49 |
– |
Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); |
| 38 |
|
|
| 39 |
|
procedure ClearValues; |
| 40 |
|
procedure WriteValues; |
| 41 |
+ |
|
| 42 |
+ |
procedure FormCreate(Sender: TObject); |
| 43 |
+ |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
| 44 |
+ |
procedure hexChange(Sender: TObject); |
| 45 |
+ |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 46 |
+ |
procedure hexSelectionChanged(Sender: TObject); |
| 47 |
|
procedure value_viewerDblClick(Sender: TObject); |
| 48 |
< |
procedure value_viewer_context_copyClick(Sender: TObject); |
| 48 |
> |
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 49 |
> |
procedure value_viewer_contextPopup(Sender: TObject); |
| 50 |
|
procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton; |
| 51 |
|
Shift: TShiftState; X, Y: Integer); |
| 52 |
< |
procedure value_viewer_contextPopup(Sender: TObject); |
| 52 |
> |
procedure value_viewer_context_copyClick(Sender: TObject); |
| 53 |
> |
procedure VSTDblClick(Sender: TObject); |
| 54 |
> |
procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 55 |
> |
Column: TColumnIndex); |
| 56 |
> |
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 57 |
> |
Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); |
| 58 |
> |
procedure VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex; |
| 59 |
> |
OldPosition: Integer); |
| 60 |
> |
procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree; |
| 61 |
> |
const Column: TColumnIndex; Visible: Boolean); |
| 62 |
|
private |
| 63 |
|
fileid: Integer; |
| 64 |
|
ConID: Integer; |
| 65 |
+ |
rawlist: TRawDataList; |
| 66 |
|
public |
| 67 |
|
end; |
| 68 |
|
|
| 64 |
– |
var |
| 65 |
– |
Form_BinEdit: TForm_BinEdit; |
| 66 |
– |
|
| 69 |
|
implementation |
| 68 |
– |
|
| 69 |
– |
uses ValueEdit, Main, Functions, DatStructureLoader{, RawEdit}; |
| 70 |
|
{$R *.dfm} |
| 71 |
+ |
uses ValueEdit, Main, Functions, DatStructureLoader, RawEdit, RawList, |
| 72 |
+ |
StrUtils, Clipbrd, _TemplateFile; |
| 73 |
+ |
|
| 74 |
|
|
| 75 |
|
type |
| 76 |
|
PNodeData = ^TNodeData; |
| 117 |
|
// |
| 118 |
|
end; |
| 119 |
|
|
| 117 |
– |
procedure TForm_BinEdit.NewFile(fileinfo: TFileInfo); |
| 118 |
– |
begin |
| 119 |
– |
LoadDat(fileinfo.ID); |
| 120 |
– |
end; |
| 121 |
– |
|
| 120 |
|
|
| 121 |
< |
|
| 124 |
< |
|
| 125 |
< |
function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; |
| 126 |
< |
ARecord: TNodeData): PVirtualNode; |
| 127 |
< |
var |
| 128 |
< |
Data: PNodeData; |
| 129 |
< |
begin |
| 130 |
< |
Result := AVST.AddChild(ANode); |
| 131 |
< |
Data := AVST.GetNodeData(Result); |
| 132 |
< |
AVST.ValidateNode(Result, False); |
| 133 |
< |
Data^ := ARecord; |
| 134 |
< |
end; |
| 135 |
< |
|
| 136 |
< |
|
| 137 |
< |
|
| 138 |
< |
|
| 139 |
< |
procedure TForm_BinEdit.LoadDat(_fileid: Integer); |
| 121 |
> |
procedure TForm_BinEdit.NewFile(fileinfo: TFileInfo); |
| 122 |
|
var |
| 123 |
|
mem: TMemoryStream; |
| 142 |
– |
Data: TByteData; |
| 124 |
|
begin |
| 125 |
|
if ConID <> -1 then |
| 126 |
|
begin |
| 133 |
|
end; |
| 134 |
|
end; |
| 135 |
|
end; |
| 136 |
< |
if _fileid >= 0 then |
| 136 |
> |
if fileinfo.ID >= 0 then |
| 137 |
|
begin |
| 138 |
< |
fileid := _fileid; |
| 138 |
> |
fileid := fileinfo.ID; |
| 139 |
|
ConID := ConnectionID; |
| 140 |
< |
if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]) <> fileid then |
| 141 |
< |
Self.SelectFileID(ConnectionID, fileid); |
| 140 |
> |
// if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]) <> fileid then |
| 141 |
> |
// Self.SelectFileID(ConnectionID, fileid); |
| 142 |
|
Self.ClearStructViewer; |
| 143 |
|
mem := nil; |
| 144 |
|
ConManager.Connection[ConID].LoadDatFile(fileid, TStream(mem)); |
| 145 |
+ |
rawlist := ConManager.Connection[ConID].GetRawList(fileid); |
| 146 |
|
hex.LoadFromStream(mem); |
| 147 |
|
mem.Free; |
| 148 |
|
ClearValues; |
| 150 |
|
end |
| 151 |
|
else |
| 152 |
|
begin |
| 153 |
< |
fileid := _fileid; |
| 153 |
> |
fileid := -1; |
| 154 |
|
ConID := -1; |
| 155 |
|
Self.ClearStructViewer; |
| 156 |
|
ClearValues; |
| 157 |
|
hex.DataSize := 0; |
| 158 |
+ |
SetLength(rawlist, 0); |
| 159 |
|
end; |
| 160 |
|
end; |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
< |
function IntToBin(Value: Byte): String; |
| 165 |
> |
function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; |
| 166 |
> |
ARecord: TNodeData): PVirtualNode; |
| 167 |
|
var |
| 168 |
< |
i: Byte; |
| 168 |
> |
Data: PNodeData; |
| 169 |
|
begin |
| 170 |
< |
Result := ''; |
| 171 |
< |
for i := 7 downto 0 do |
| 172 |
< |
Result := Result + IntToStr((Value shr i) and $01); |
| 170 |
> |
Result := AVST.AddChild(ANode); |
| 171 |
> |
Data := AVST.GetNodeData(Result); |
| 172 |
> |
AVST.ValidateNode(Result, False); |
| 173 |
> |
Data^ := ARecord; |
| 174 |
|
end; |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
< |
function TForm_BinEdit.GetValue(datatype: Word; offset: LongWord): String; |
| 179 |
> |
|
| 180 |
> |
function TForm_BinEdit.GetValue(datatype: Word; offset: Integer): String; |
| 181 |
|
var |
| 182 |
|
Data: TByteData; |
| 183 |
< |
i: Word; |
| 183 |
> |
i: Integer; |
| 184 |
|
floatformat: TFormatSettings; |
| 185 |
|
begin |
| 186 |
|
floatformat.DecimalSeparator := '.'; |
| 216 |
|
10: |
| 217 |
|
Result := IntToBin(hex.Data[offset]); |
| 218 |
|
11: |
| 219 |
< |
Result := '0x' + IntToHex(ConManager.Connection[ConID].GetRawInfo(fileid, offset).RawAddr, 8); |
| 219 |
> |
begin |
| 220 |
> |
if Length(rawlist) > 0 then |
| 221 |
> |
begin |
| 222 |
> |
for i := 0 to High(rawlist) do |
| 223 |
> |
if rawlist[i].SrcOffset = offset then |
| 224 |
> |
begin |
| 225 |
> |
if rawlist[i].RawAddr > 0 then |
| 226 |
> |
Result := '0x' + IntToHex(rawlist[i].RawAddr, 8) |
| 227 |
> |
else |
| 228 |
> |
Result := 'unused'; |
| 229 |
> |
Break; |
| 230 |
> |
end; |
| 231 |
> |
if i > High(rawlist) then |
| 232 |
> |
Result := 'unused'; |
| 233 |
> |
end; |
| 234 |
> |
end; |
| 235 |
|
12: |
| 236 |
< |
Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 + |
| 237 |
< |
hex.Data[offset + 3] * 256 * 256, 5, '0'); |
| 236 |
> |
if hex.Data[offset] = 1 then |
| 237 |
> |
Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 + |
| 238 |
> |
hex.Data[offset + 3] * 256 * 256, 5, '0') |
| 239 |
> |
else |
| 240 |
> |
Result := 'no link'; |
| 241 |
|
13: |
| 242 |
|
Result := IntToStr(hex.Data[offset]); |
| 243 |
|
14: |
| 290 |
|
|
| 291 |
|
procedure TForm_BinEdit.WriteStructureInfos; |
| 292 |
|
var |
| 293 |
< |
i, j: LongWord; |
| 293 |
> |
i, j: Integer; |
| 294 |
|
pdata: PNodeData; |
| 295 |
|
Data: TNodeData; |
| 296 |
|
node: PVirtualNode; |
| 324 |
|
begin |
| 325 |
|
if Pos('#', SubName) > 0 then |
| 326 |
|
begin |
| 327 |
< |
Data.Offset := HexToLong(MidStr(SubName, Pos('#', SubName) + 1, 8)); |
| 328 |
< |
Data.Value := |
| 327 |
> |
Data.Offset := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8)); |
| 328 |
> |
Data.Value := '$' + |
| 329 |
|
MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8); |
| 330 |
|
Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1); |
| 331 |
|
Data.Description := SubDesc; |
| 392 |
|
i, j: Integer; |
| 393 |
|
Data: TByteData; |
| 394 |
|
str: String; |
| 395 |
< |
Value: LongWord; |
| 395 |
> |
Value: Integer; |
| 396 |
|
floatformat: TFormatSettings; |
| 397 |
|
begin |
| 398 |
|
floatformat.DecimalSeparator := '.'; |
| 475 |
|
str := ''; |
| 476 |
|
if hex.SelCount = 0 then |
| 477 |
|
begin |
| 478 |
< |
while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do |
| 478 |
> |
while (hex.SelStart + j) < hex.DataSize do |
| 479 |
|
begin |
| 480 |
+ |
if hex.Data[hex.SelStart + j] = 0 then |
| 481 |
+ |
Break; |
| 482 |
|
if hex.Data[hex.selstart + j] >= 32 then |
| 483 |
|
str := str + Char(hex.Data[hex.SelStart + j]) |
| 484 |
|
else |
| 507 |
|
function TForm_BinEdit.Save: Boolean; |
| 508 |
|
var |
| 509 |
|
mem: TMemoryStream; |
| 510 |
< |
i: LongWord; |
| 510 |
> |
i: Integer; |
| 511 |
|
begin |
| 512 |
|
case MessageBox(Self.Handle, PChar('Save changes to file ' + |
| 513 |
|
ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'), |
| 689 |
|
procedure TForm_BinEdit.value_viewer_context_copyClick(Sender: TObject); |
| 690 |
|
var |
| 691 |
|
Name: String; |
| 692 |
< |
Value: LongWord; |
| 692 |
> |
Value: Integer; |
| 693 |
|
begin |
| 694 |
|
Name := TMenuItem(Sender).Name; |
| 695 |
|
if Pos('asstring', Name) > 0 then |
| 752 |
|
var |
| 753 |
|
node: PVirtualNode; |
| 754 |
|
nodedata: PNodeData; |
| 755 |
< |
form: TForm_ToolTemplate; |
| 755 |
> |
rawinfo: TRawDataInfo; |
| 756 |
> |
form: TForm_TemplateFileList; |
| 757 |
|
begin |
| 758 |
|
if VST.FocusedColumn = 3 then |
| 759 |
|
begin |
| 768 |
|
end |
| 769 |
|
else |
| 770 |
|
begin |
| 771 |
< |
if nodedata.DataType = 11 then |
| 771 |
> |
if (nodedata.DataType = 11) and (nodedata.Value <> 'unused') then |
| 772 |
|
begin |
| 773 |
< |
if ConManager.Connection[ConID].GetRawInfo(fileid, nodedata.offset).RawSize > 0 then |
| 774 |
< |
Form_Main.open_child('rawedit', ConID, fileid); |
| 773 |
> |
rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, nodedata.offset); |
| 774 |
> |
if rawinfo.RawSize > 0 then |
| 775 |
> |
begin |
| 776 |
> |
form := nil; |
| 777 |
> |
form := TForm_TemplateFileList(Form_Main.open_child('rawedit', ConID, fileid)); |
| 778 |
> |
if Assigned(form) then |
| 779 |
> |
TForm_RawEdit(form).LoadRaw(rawinfo); |
| 780 |
> |
end; |
| 781 |
|
end; |
| 782 |
< |
if nodedata.DataType = 12 then |
| 782 |
> |
if (nodedata.DataType = 12) and (nodedata.Value <> 'no link') then |
| 783 |
|
begin |
| 784 |
|
if (StrToInt(nodedata.Value) < ConManager.Connection[ConID].GetFileCount) and |
| 785 |
|
(StrToInt(nodedata.Value) > 0) and |
| 793 |
|
end; |
| 794 |
|
if (nodedata.DataType >= 100) and (nodedata.DataType <= 300) then |
| 795 |
|
begin |
| 796 |
< |
form := Form_Main.open_child('binedit', ConID, -1); |
| 796 |
> |
form := TForm_TemplateFileList(Form_Main.open_child('binedit', ConID)); |
| 797 |
|
if Assigned(form) then |
| 798 |
|
form.SetFileFilters(nodedata.Value, '', False); |
| 799 |
|
end; |
| 819 |
|
else |
| 820 |
|
begin |
| 821 |
|
hex.SelStart := Data.Offset; |
| 822 |
< |
hex.SelEnd := Data.Offset + HexToLong(Data.Value) - 1; |
| 822 |
> |
hex.SelEnd := Data.Offset + StrToInt(Data.Value) - 1; |
| 823 |
|
end; |
| 824 |
|
end; |
| 825 |
|
|
| 850 |
|
if Data.DataType > 0 then |
| 851 |
|
CellText := Data.Value //GetValue(data.DataType, data.Offset) |
| 852 |
|
else if Length(Data.Value) > 0 then |
| 853 |
< |
CellText := IntToStr(HexToLong(Data.Value)) + ' Bytes'; |
| 853 |
> |
CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes'; |
| 854 |
|
4: |
| 855 |
|
CellText := Data.Description; |
| 856 |
|
end; |
| 881 |
|
|
| 882 |
|
|
| 883 |
|
|
| 884 |
< |
procedure TForm_BinEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String); |
| 884 |
> |
procedure TForm_BinEdit.SetNewValue(datatype: Word; offset: Integer; Value: String); |
| 885 |
|
var |
| 886 |
|
Data: TByteData; |
| 887 |
|
value_int: LongWord; |
| 948 |
|
|
| 949 |
|
procedure TForm_BinEdit.value_viewerDblClick(Sender: TObject); |
| 950 |
|
var |
| 951 |
< |
offset: LongWord; |
| 951 |
> |
offset: Integer; |
| 952 |
|
datatype: Word; |
| 953 |
|
objectname: String; |
| 954 |
|
Value: String; |
| 983 |
|
|
| 984 |
|
|
| 985 |
|
|
| 973 |
– |
|
| 986 |
|
procedure TForm_BinEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 987 |
|
begin |
| 988 |
|
if (Shift = [ssCtrl]) and (Key = 83) then |