gcc/MinGW – Utilities – ldd and objdump

Background

Let us cover a couple of utilities that are bundled with gcc/minGW toolset.

Lineage

  1. NetCat – Visual Studio – Source Code Compilation
    Link
  2. Netcat on MS Windows – Sample Usage
    Link
  3. MinGW – Error – “undefined reference to `__imp_WSAStartup’”
    LinkLink

Need

When troubleshooting an application one sometimes wants to gain familiarity with the dependant modules.

Dependent Modules

There are quite a few ways that an application interops with other modules.

Inclusive :-

  1. Static Linking
  2. Dynamic Linking
  3. Interprocess Communication
    • Shared Memory
    • DDE
    • OLE
  4. Web Services

Utilities

In the gcc world, there are a couple of utilities packaged in :-

  1. ldd
  2. objdump

Utility – ldd

Unfortunately, ldd is not included with the MS Windows distro
( minGW).

Utility – objdump

Let us see how much help objdump will be.

Referenced Modules

Outline

  1. Invoke objdump.exe
    • Pass along -p
      • -p means to print private headers

Syntax


objdump.exe -p

Sample

Sample – Referenced Modules – Outline
  1. Invoke objdump.exe
    • Pass along -p
    • Parse output
      • Find pattern matching
        • dll
Sample – Referenced Modules – Code

setlocal

set _compilerFolder=C:\mingw\x86_64\8.1.0\posix\seh\mingw64\bin
set _compilerBinary=objdump.exe

set _binary=%_compilerFolder%\%_compilerBinary%

set PATH=%PATH%;%_compilerFolder%

set _app=nc.exe

set "_fileFormat=file format"
set "_moduleMarker=dll"

%_binary% -p %_app% | findstr /R "%_fileFormat% \.%_moduleMarker%$"

endlocal

Output

nc.exe:     file format pei-x86-64
        DLL Name: KERNEL32.dll
        DLL Name: msvcrt.dll
        DLL Name: WS2_32.dll

Explanation
File Format
  1. pei-x86-64
Dll
  1. KERNEL32.dll
  2. msvcrt.dll
  3. WS2_32.dll

References

  1. die-net
  2.  SourceForge.net
    • MinGW-w64 – for 32 and 64 bit Windows
      • [Mingw-w64-public] ldd functionality?
        • Daniel Goldman
          Link
  3.  StackOverflow
    • How to use OR operator in findstr command from a windows 7 command prompt?
      Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s