Code Monkey home page Code Monkey logo

pe-util's Introduction

List shared object dependencies of a portable executable (PE).

It uses the pe-parse library to read the PE structure.

2016, Georg Sauthoff [email protected]

Examples

Create a portable executable (PE) via cross-compiling and displays it shared object dependencies:

$ mkdir build
$ cd build
$ mingw64-cmake ..
$ mingw64-make main
$ peldd main.exe --no-wlist
ADVAPI32.dll
libboost_filesystem-mt.dll
libboost_system-mt.dll
libgcc_s_seh-1.dll
KERNEL32.dll
msvcrt.dll
libstdc++-6.dll
USER32.dll

Display the dependencies of a PE library:

$ peldd /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll --no-wlist
libgcc_s_seh-1.dll
KERNEL32.dll
msvcrt.dll
libwinpthread-1.dll
USER32.dll

Display the dependencies of a PE binary without any well-known system libraries:

$ peldd main.exe
libgcc_s_seh-1.dll
libstdc++-6.dll

Compute the transitive closure of a binary, using the default search path:

$ peldd main.exe --all
main.exe
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll

Error because on non whitelisted dll:

$ peldd ut.exe --all
Error: Could not resolve: WS2_32.dll

The same binary after extending the whitelist:

$ peldd ut.exe -a  -w WS2_32.dll 
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/iconv.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libboost_filesystem-mt.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libboost_regex-mt.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libboost_system-mt.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libxml2-2.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll
ut.exe

There is also --ignore-errors for ignoring resolve errors.

Deploy a cross compiled binary:

$ peldd ut.exe -a | xargs cp -t /mnt/win/builds/

Build Instructions

To build peldd itself:

git clone https://github.com/gsauthof/pe-util.git
cd pe-util
git submodule update --init
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make VERBOSE=1

Or if ninja is available and enable debug mode (replace last 2 steps):

CXXFLAGS='-fsanitize=address -fsanitize=undefined -Og' cmake .. -DCMAKE_BUILD_TYPE=Debug -G Ninja
ninja -v

License

Both the library and the program are licensed under the MIT license.

pe-util's People

Contributors

chriskitching avatar gsauthof avatar msarehn avatar stweil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pe-util's Issues

Build on Windows / Windows binary release

I'm in the unfortunate situation of having to build things on Windows. And I cannot get peldd compiled on it. cmake says it can't find boost:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
CMake Warning at C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1204 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1326 (_Boost_COMPONENT_DEPENDENCIES)
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1935 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:5 (find_package)


CMake Warning at C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1204 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1326 (_Boost_COMPONENT_DEPENDENCIES)
  C:/msys64/mingw64/share/cmake-3.19/Modules/FindBoost.cmake:1935 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:5 (find_package)


-- Could NOT find Boost (missing: system filesystem) (found suitable version "1.75.0", minimum required is "1.54")

I do have boost installed, but it's not the boost package, but mingw-w64-x86_64-boost instead.

Add --ignore-errors option

@ChrisKitching suggested this in pull request #2 :

Might I suggest you add an --ignore-errors option? I'm trying to
use this tool in a build script to automatically select needed

dlls for installation (when cross compiling). It is extremely
annoying to have to keep adding things to the whitelist.

Newest clang yields warnings building this project

Some minor wrinkles you might like to look into

build/pe-util/pe-parse/parser-library/parse.cpp:266:54: warning: unused parameter 'fileBegin' [-Wunused-parameter]
bool getResources(bounded_buffer *b, bounded_buffer *fileBegin, list<section> secs, list<resource> &rsrcs) {
                                                     ^
pe-util/pe-parse/parser-library/buffer.cpp:192:21: warning: missing field 'st_ino' initializer [-Wmissing-field-initializers]
  struct stat s = {0};
                    ^

pe-util/pe-parse/parser-library/parse.cpp:1225:17: warning: variable 'lookupVA' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
      } else if(curEnt.AddressRVA != 0 ) {
                ^~~~~~~~~~~~~~~~~~~~~~
pe-util/pe-parse/parser-library/parse.cpp:1240:41: note: uninitialized use occurs here
[ 58%] Building C object CMakeFiles/matio.dir/src/matvar_cell.c.o
      if(getSecForVA(p->internal->secs, lookupVA, lookupSec) == false) {
                                        ^~~~~~~~
[ 66%] Building C object CMakeFiles/matio.dir/src/mat73.c.o
pe-util/pe-parse/parser-library/parse.cpp:1225:14: note: remove the 'if' if its condition is always true
      } else if(curEnt.AddressRVA != 0 ) {
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~[ 75%] Building C object CMakeFiles/matio.dir/src/matvar_struct.c.o

pe-util/pe-parse/parser-library/parse.cpp:1212:18: note: initialize the variable 'lookupVA' to silence this warning
      VA lookupVA;
                 ^
                  = 0

Can this be built with latest pe-parse?

Hi,

This looks like a really useful utility that I'd like to add to MXE but I'm having some build issues both using the latest pe-parse or going back to the pinned commit.

Before I spend too much time investigating, I thought I'd ask if this is known to work with later pe-parse?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.