Coder Social home page Coder Social logo

chen-charles / pedetour Goto Github PK

View Code? Open in Web Editor NEW
61.0 7.0 15.0 46.63 MB

modify binary Portable Executable to hook its export functions

License: GNU General Public License v3.0

C++ 25.05% C 73.13% Assembly 1.83%
capstone keystone dll hook windows

pedetour's Introduction

PEDetour

modify binary Portable Executable to hook its export functions

Dependencies

This project uses Capstone disassembly framework and Keystone assembly framework.
Their licenses and compiled binaries are included in the capstone-win32 and keystone-win32 folders.
Further information are available at Capstone and Keystone.
LLVM's license is also included as a part of Capstone and Keystone.

Compile

This project uses relative library paths so you don't have to adjust paths.
SDK version is set to 10.0.14393.0 with Toolset Visual Studio 2017 (v141).
You do not need any modifications if you are using the exact same SDK version and Toolset.
Otherwise, you might need to recompile capstone and keystone for your specific toolset.

Platform

There are two platforms available in the VisualStudio solution: x86 and x64(x86_64)
x86: The binary compiled will only support 32-bit PE files, it will throw an exception for 64-bit files.
x64(x86_64): The binary compiled will only support 64-bit PE files, it will throw an exception for 32-bit files.

Usage

PEDetour currently supports two usages: viewExports and injectFunction

viewExports (Print all export functions listed in the Export Directory)

PEDetour PEFileName
PEFileName          the PE file you want to look at
PEDetour C:\Windows\System32\kernel32.dll   // this is a 64-bit file if you don't know :)

injectFunction (Inject a piece of code to replace the original export function)

PEDetour inputFileName outputFileName functionToInject InjectFileName ...
inputFileName       the PE file you want to inject to (this file itself will not be modified)
outputFileName      where the modified PE will be written to
functionToInject    the function you want to inject (its name as it appears in *viewExports*)
InjectFileName      the assembly file to replace the original function in intel assembly format  
...                 OPTIONAL additional imports you want to add into the output PE  

Additional imports must be in the format of "filename.whatever::functionName" (import file name must be in lower cases, functionName is case sensitive).
If this field is not specified, the following functions will be imported by default,

  • kernel32.dll::GetProcessHeap
  • kernel32.dll::HeapAlloc
  • kernel32.dll::LoadLibraryA
  • kernel32.dll::GetProcAddress
  • kernel32.dll::Beep
  • user32.dll::MessageBoxA
  • inputFileName::functionToInject
PEDetour TestDLL.bak TestDLL.dll ?fnTestDLL@@YAHXZ inject.x86.asm   // you can find this in Release binaries

Demo

For notes on injection assembly files, see inject.x86.asm and inject.x86_64.asm
You can find demos in Release binaries.

License

Version 3 of the GNU General Public Licence (GPLv3)

Known Limitations

As of v1.0:

  • IMAGE_DIRECTORY_ENTRY_SECURITY, IMAGE_DIRECTORY_ENTRY_DEBUG, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG and IMAGE_DIRECTORY_ENTRY_EXCEPTION are dropped from the data directories
  • IMAGE_DIRECTORY_ENTRY_GLOBALPTR, IMAGE_DIRECTORY_ENTRY_TLS, IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, and IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR are not fixed
  • there is an issue with capstone(3.0.4) and keystone(0.9.1) for x86_64 REX prefix handling, see line 200 in PE.h (code generated by Visual Studio), and is currently bypassed through hard coding (ikr)
  • for x86_64, you must use full 64-bit addressing for library function calls (as described in inject.x86_64.asm)
  • .xdata sections are not available for injected function, you must use either the stack space, or kernel32::GetProcessHeap with kernel32::HeapAlloc

pedetour's People

Contributors

chen-charles 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pedetour's Issues

cool project!

this looks like a cool project, but will you have a longer, with more details, README?

keep it up, cheers.

redirect original function in place

instead of importing the original file for the original function (additional dependency), provide links within the modified. (also include links to other functions within the file)

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.