Board index » delphi » Checking which DLLs an .EXE links to?

Checking which DLLs an .EXE links to?

I would like to use Delphi 2 to check which DLLs an .EXE links to,
without running the .EXE.  I know this can be done.  If anyone can
show me how, please email me a copy of your reply as well as posting
it to the new group.

Thanks.

Simon Oxley
Wellington, New Zealand

 

Re:Checking which DLLs an .EXE links to?


In article <326f3c20.100...@snews.zippo.com>, sim...@super.zippo.com!
says...

Quote

>I would like to use Delphi 2 to check which DLLs an .EXE links to,
>without running the .EXE.  I know this can be done.  If anyone can
>show me how, please email me a copy of your reply as well as posting
>it to the new group.

>Thanks.

>Simon Oxley
>Wellington, New Zealand

What's wrong with TDUMP ?

Re:Checking which DLLs an .EXE links to?


Quote
sim...@super.zippo.com (Simon Oxley) wrote:
>I would like to use Delphi 2 to check which DLLs an .EXE links to,
>without running the .EXE.  I know this can be done.  If anyone can
>show me how, please email me a copy of your reply as well as posting
>it to the new group.

Statically linked DLLs are listed in the EXE file header. Remember
that apps can also dynamically link to DLLs (with LoadLibrary, for
example). To get those, you need to monitor calls to these API
functions (see Petzold's book for details).

Quote
>Thanks.
>Simon Oxley
>Wellington, New Zealand

Regards,

Jani J?rvinen
Helsinki Finland
ja...@xgw.fi

Re:Checking which DLLs an .EXE links to?


Jani J?rvinen <ja...@dystopia.fi> wrote in article
<54vshv$...@news.clinet.fi>...

Quote
> sim...@super.zippo.com (Simon Oxley) wrote:

> >I would like to use Delphi 2 to check which DLLs an .EXE links to,
> >without running the .EXE.  I know this can be done.  If anyone can
> >show me how, please email me a copy of your reply as well as posting
> >it to the new group.

> Statically linked DLLs are listed in the EXE file header. Remember
> that apps can also dynamically link to DLLs (with LoadLibrary, for
> example). To get those, you need to monitor calls to these API
> functions (see Petzold's book for details).

Jani's right - you may want to search your drive for a "dumpbin.exe" - run
dumpbin /exports FOO.EXE and you'll see the DLLs your app links directly
to.  

Dumpbin ships with some of the Microsoft toolkits and SDKs - there's likely
something similar in Delphi or BC++ (perhaps in the linker).

Re:Checking which DLLs an .EXE links to?


Quote
"Pat Loughery" <p...@mom.isc-br.com> wrote:
>> >I would like to use Delphi 2 to check which DLLs an .EXE links to,
>> >without running the .EXE.  I know this can be done.  If anyone can
>> >show me how, please email me a copy of your reply as well as posting
>> >it to the new group.

>> Statically linked DLLs are listed in the EXE file header. Remember
>> that apps can also dynamically link to DLLs (with LoadLibrary, for
>> example). To get those, you need to monitor calls to these API
>> functions (see Petzold's book for details).
>Jani's right - you may want to search your drive for a "dumpbin.exe" - run
>dumpbin /exports FOO.EXE and you'll see the DLLs your app links directly
>to.  
>Dumpbin ships with some of the Microsoft toolkits and SDKs - there's likely
>something similar in Delphi or BC++ (perhaps in the linker).

If you don't want to buy a MS compiler use TDUMP ... you can use
the following code as a quick hack to interogate a DLL or EXE...It
just runs TDUMP against a file, redirects it, then reads it back into
a listbox.  Like I said, it's a hack, took all of 5 minutes, but it is
kinda handy...

unit Dump;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    ListBox1: TListBox;
    Panel1: TPanel;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
end;

function WinExecAndWait(Path: String; Visibility: word): word;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.BitBtn1Click(Sender: TObject);
const ModRef = 'Module Reference Table';
var
  Where, S : String;
  C : Word;
  F : TextFile;
begin
  C := 0;
  If OpenDialog1.Execute Then begin;
    Where := 'D:\DELPHI\BIN\TDUMP ' + OpenDialog1.FileName + ' > ' +
'$$TDUMP$$';
    If WinExecAndWait(Where, SW_HIDE) >= 32 Then begin
      AssignFile(F, '$$TDUMP$$');
      Reset(F);
      ListBox1.Clear;
      While Not Eof(F) do begin
        ReadLn(F, S);
        If (Pos(ModRef, S)>0) Then Inc(C);
        If C = 2 Then begin
          While Not Eof(F) Do begin
            ReadLn(F, S);
            If (Pos('Module',S)=0) Or (Pos('Description',S)>0) Then
Break;
            If (Pos(':',S)>0) Then
S:=Copy(S,Pos(':',S)+2,Length(S)-Pos(':',S));
            If (ListBox1.Items.IndexOf(S)=-1) Then
ListBox1.Items.Add(S);
          end;
        end;
      end;
      CloseFile(F);
      Erase(F);
    end;
  end;
end;

{ Thanks to whoever's this was originally }
function WinExecAndWait(Path: String; Visibility: word): word;
var
  InstanceID : THandle;
  TPath : array[0..255] of char;
begin
  StrPCopy(TPath, Path);
  InstanceID := WinExec(TPath, Visibility);
  if InstanceID < 32 then
     WinExecAndWait := InstanceID
  else begin
    repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    WinExecAndWait := 32;
  end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  Application.Terminate;
end;
end.

JE McTaggart
t...@iguana.ruralnet.net

Other Threads