⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileviewer.pas

📁 Jedi Code Library JCL JVCL 组件包 JCL+JVCL超过300个组件的非可视/可视大型组件包。
💻 PAS
📖 第 1 页 / 共 2 页
字号:

procedure TFileViewerChild.SetFileName(const Value: TFileName);
begin
  FAnyRootError := False;
  FFileName := Value;
  FBasePath := ExtractFilePath(FFileName);
  Caption := ModuleName;
  InitTree;
end;

class procedure TFileViewerChild.UpdateSortData(Column: TListColumn);
var
  ListView: TListView;
  I: Integer;
begin
  ListView := TListView(TListColumns(Column.Collection).Owner);
  ListView.Columns.BeginUpdate;
  with ListView.Columns do
    for I := 0 to Count - 1 do
      Items[I].ImageIndex := -1;
  if ListView.Tag and $FF = Column.Index then
    ListView.Tag := ListView.Tag xor $100
  else
    ListView.Tag := Column.Index;
  if ListView.Tag and $100 = 0 then
    Column.ImageIndex := imgSortAsceding
  else
    Column.ImageIndex := imgSortDesceding;
  ListView.Columns.EndUpdate;
end;

function TFileViewerChild.IsListViewActiveAndFocused( ListView: TListView): Boolean;
begin
  Result := (ActiveControl = ListView) and (ListView.ItemFocused <> nil);
end;

function TFileViewerChild.GetWin32Function: String;
begin
  Result := '';
  if IsListViewActiveAndFocused(ImportListView) then
    Result := ImportListView.ItemFocused.Caption
  else
  if IsListViewActiveAndFocused(ExportListView) then
    Result := ExportListView.ItemFocused.Caption
  else
    Result := '';
  if Pos('@', Result) > 0 then
    Result := ''
  else
    Result := StrRemoveChars(Result, ['[', ']']);
end;

procedure TFileViewerChild.ExportListViewData(Sender: TObject;
  Item: TListItem);
begin
  with Item, FExportViewImage.ExportList[Item.Index] do
  begin
    Caption := Name;
    SubItems.Add(Format('%d', [Ordinal]));
    SubItems.Add(Format('%d', [Hint]));
    SubItems.Add(AddressOrForwardStr);
    if IsForwarded then ImageIndex := imgFwdExport else ImageIndex := imgExport;
  end;
end;

procedure TFileViewerChild.ImportListViewData(Sender: TObject; Item: TListItem);
var
  ViewItem: TJclPeImportFuncItem;
begin
  if FCurrentImportDirIndex = -1 then
    ViewItem := FParentImportViewImage.ImportList.AllItems[Item.Index]
  else
    ViewItem := FParentImportViewImage.ImportList[FCurrentImportDirIndex][Item.Index];
  with Item, ViewItem do
  begin
    if IndirectImportName then
      Caption := Format('[%s]', [Name])
    else
      Caption := Name;
    if Ordinal <> 0 then
    begin
      SubItems.Add(Format('%d', [Ordinal]));
      SubItems.Add('');
    end else
    begin
      SubItems.Add('');
      SubItems.Add(Format('%d', [Hint]));
    end;  
    if FCurrentImportDirIndex = -1 then SubItems.Add(ImportLib.Name);
    case ResolveCheck of
      icUnresolved: ImageIndex := imgUnresolvedImport;
      icResolved, icNotChecked: ImageIndex := imgImport;
    end;
  end;
end;

procedure TFileViewerChild.ExportListViewColumnClick(Sender: TObject; Column: TListColumn);
begin
  UpdateSortData(Column);
  ExportListViewSort;
end;

procedure TFileViewerChild.ImportListViewColumnClick(Sender: TObject; Column: TListColumn);
begin
  UpdateSortData(Column);
  ImportListViewSort;
end;

procedure TFileViewerChild.UpdateExportView(Node: TTreeNode);
begin
  with ExportListView.Items do
  begin
    BeginUpdate;
    if PPeModuleNodeData(Node.Data)^.State in ErrorModules then
      FExportViewImage.FileName := ''
    else
      FExportViewImage.FileName := ModuleToFilename(Node.Text);
    Count := FExportViewImage.ExportList.Count;
    ExportListViewSort;
    EndUpdate;
  end;
end;

procedure TFileViewerChild.UpdateParentImportView(Node: TTreeNode);
var
  ParentFileName: TFileName;
  NodeState: TPeModuleState;

  procedure ShowModuleColumn(B: Boolean);
begin
  with ImportListView do
    if (B xor (Columns.Count <> 3)) then
    begin
      Columns.BeginUpdate;
      if B then Columns.Add.Caption := 'Module' else
      begin
        Columns[3].Free;
        if Tag and $FF = 3 then
        begin
          Tag := $100;
          UpdateSortData(Columns[0]);
          ImportListViewSort;
        end;
      end;
      Columns.EndUpdate;
    end;
end;

begin
  with ImportListView.Items do
  begin
    BeginUpdate;
    if Node.Parent = nil then
      ParentFileName := Node.Text
    else
      ParentFileName := Node.Parent.Text;
    ParentFileName := ModuleToFilename(ParentFileName);
    NodeState := PPeModuleNodeData(Node.Data)^.State;
{$IFDEF UsePeImagesCache}
    FParentImportViewImage := FPeImagesCache[ParentFileName];
    FParentImportViewImage.ImportList.SortList(ilIndex);
{$ELSE}
    FParentImportViewImage.FileName := ParentFileName;
{$ENDIF}
    if (NodeState in MissingExportModules + ErrorModules) or FAnyRootError then
      FParentImportViewImage.ImportList.CheckImports;
    FParentImportViewImage.TryGetNamesForOrdinalImports;
    if NodeState in ForwardedModules then
    begin
      ShowModuleColumn(False);
      FCurrentImportDirIndex := -1;
      FParentImportViewImage.ImportList.FilterModuleName := Node.Text;
      Count := FParentImportViewImage.ImportList.AllItemCount;
    end else
    if Node.Parent = nil then
    begin
      ShowModuleColumn(True);
      FCurrentImportDirIndex := -1;
      FParentImportViewImage.ImportList.FilterModuleName := '';
      Count := FParentImportViewImage.ImportList.AllItemCount;
    end else
    begin
      ShowModuleColumn(False);
      FCurrentImportDirIndex := PPeModuleNodeData(Node.Data)^.ImportDirectoryIndex;
      Count := FParentImportViewImage.ImportList[FCurrentImportDirIndex].Count;
    end;
    ImportListViewSort;
    EndUpdate;
  end;
end;

procedure TFileViewerChild.DependencyTreeViewChange(Sender: TObject; Node: TTreeNode);
begin
  UpdateExportView(Node);
  UpdateParentImportView(Node);
end;

procedure TFileViewerChild.DependencyTreeViewDeletion(Sender: TObject; Node: TTreeNode);
begin
  Dispose(Node.Data); // PPeModuleNodeData
end;

procedure TFileViewerChild.ImportListViewSort;
const
  MapIndexToSortType: array[0..3] of TJclPeImportSort = (isName, isOrdinal, isHint, isLibImport);
begin
  with ImportListView do
  begin
    if FCurrentImportDirIndex = -1 then
      FParentImportViewImage.ImportList.SortAllItemsList(MapIndexToSortType[Tag and $FF], Tag and $100 <> 0)
    else
      FParentImportViewImage.ImportList[FCurrentImportDirIndex].SortList(MapIndexToSortType[Tag and $FF], Tag and $100 <> 0);
    Invalidate;
  end;
end;

procedure TFileViewerChild.ExportListViewSort;
const
  MapIndexToSortType: array[0..3] of TJclPeExportSort =
    (esName, esOrdinal, esHint, esAddrOrFwd);
begin
  with ExportListView do
  begin
    FExportViewImage.ExportList.SortList(MapIndexToSortType[Tag and $FF], Tag and $100 <> 0);
    Invalidate;
  end;
end;

procedure TFileViewerChild.UpdateModulesView;
var
  I: Integer;
  ExeImage: TJclPeImage;
  VI: TJclFileVersionInfo;
begin
  with ModulesListView.Items do
  begin
    BeginUpdate;
    try
      Clear;
      for I := 0 to FModulesList.Count - 1 do
        with Add, FModulesList do
        begin
          ExeImage := FPeImagesCache.Images[ModuleToFilename(Strings[I])];
          Caption := ExtractFileName(ExeImage.FileName);
          Data := Objects[I];
          if ExeImage.Status = stOk then
          begin
            VI := ExeImage.VersionInfo;
            with ExeImage.FileProperties, SubItems do
            begin
              Add(FormatDateTime('ddddd tt', LastWriteTime));
              Add(Format('%.0n', [IntToExtended(Size)]));
            end;
            with ExeImage, SubItems do
            begin
              Add(HeaderValues[JclPeHeader_Subsystem]);
              Add(HeaderValues[JclPeHeader_ImageBase]);
              if Assigned(VI) then Add(VI.FileVersion) else Add('');
              if Assigned(VI) then Add(VI.ProductVersion) else Add('');
              Add(HeaderValues[JclPeHeader_ImageVersion]);
              Add(HeaderValues[JclPeHeader_LinkerVersion]);
              Add(HeaderValues[JclPeHeader_OperatingSystemVersion]);
              Add(HeaderValues[JclPeHeader_SubsystemVersion]);
              if Assigned(VI) then Add(VI.FileDescription) else Add('');
            end;
          end;
          ImageIndex := ModuleImages[TPeModuleState(Objects[I])].ImageIndex; 
        end;
    finally
      EndUpdate;
    end;
  end;
end;

procedure TFileViewerChild.ModulesListViewInfoTip(Sender: TObject; Item: TListItem; var InfoTip: String);
begin
  with Item.SubItems do
    if Count > 10 then
      InfoTip := Strings[5] + #13#10 + Strings[10]
    else
      InfoTip := '';
end;

function TFileViewerChild.ModuleToFileName(const ModuleName: string): TFileName;
begin
  Result := TJclPeImage.ExpandBySearchPath(ModuleName, FBasePath);
end;

function TFileViewerChild.GetSelectedFileName: TFileName;
var
  S: string;
begin
  S := '';
  if ActiveControl = DependencyTreeView then
  begin
    with DependencyTreeView do
      if Selected <> nil then 
        if Selected.Level = 0 then S := FFileName else
          S := Selected.Text;
  end else
  if Activecontrol = ModulesListView then
    with ModulesListView do
      if Selected <> nil then
        S := Selected.Caption;
  Result := ModuleToFileName(S);
end;

procedure TFileViewerChild.ExportListViewDblClick(Sender: TObject);
begin
  MainForm.Win32Help1.Execute;
end;

procedure TFileViewerChild.ModulesListViewDblClick(Sender: TObject);
begin
  MainForm.DumpPe1.Execute;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -