Coder Social home page Coder Social logo

nimp's Introduction

NimP

NimP is a small proof-of-concept used to generate "dummy" Nim code, instantiating all of the existing procs. It was designed in order to force Nim to compile library functions into C code. This way, compiled functions from Nim's libraries could be imported into IDA, and rules could be generated to match stripped Nim binaries.

Details

This tool was written at a time when no FLIRT rules for Nim existed. Stripped binaries were consequently harder to analyse in IDA, as they include hundreds of library functions. The Nim compiler does not allow to export all the functions inside a library in any easy way. Thus, I figured a simple solution was to write "dummy" code, with all the procedures called with nonsense (yet correctly typed) arguments. This would produce a non-working program, but force the compiler to include all the procedures we want.

Once we have the exported procedures, it is possible to use tools such as FireEye's idb2pat to generate FLIRT rules. However, different options at compilation time (besides different compilers and different OS) will result in different FLIRT rules. Be sure to generate the ones you need!

Howto

  1. Install Nim from their website or build it from the GitHub repository.
  2. Install the compiler you want. It should be the same one that was used to compile the binaries for which you want to make FLIRT rules.
  3. Use NimP to generate code for a given set of libraries.
  4. Open the dummy binary built by NimP in IDA, and use idb2pat to export signatures for functions into PAT format (alt-F7 then select idb2pat.py).
  5. Use IDA FLAIR's sigmake to build the SIG file, containing the FLIRT rules.
  6. Add the SIG file into IDA's FLIRT rules directory (C:\Program Files:\IDA Pro X.Y:\sig:\pc:\).
  7. You are good to go. :-)

Examples

# This will export all the functions from the "math" library
# /path/to/Nim should be the root folder from Nim installation,
# so that /path/to/Nim/bin/nim and /path/to/Nim/lib/pure/math.nim
# are valid paths.
python3 nimp.py /path/to/Nim/ pure/math

# This will export all the functions from the "math" library, and
# then from the "httpclient" library. Note the order may be relevant,
# as type declarations are taken into account, when analysing a library,
# and kept in memory for the next analysis.
python3 nimp.py /path/to/Nim/ pure/math pure/httpclient

Optimisations

When you compile Nim code, you can choose among various optimisations. They will reflect on the resulting assembly code produced. Read the Nim Compile User Guide to have further information. Among the possible optimisations :

  • --opt:none|speed|size
  • -d:useMalloc

Artefacts

In the artefacts directory, you will find:

  • a code produced by running NimP on all "pure/" libraries, and then manually corrected
  • a sigfile for Nim compiled in 32 bits mode with recommended MinGW 6.3.0 on Windows (opt: none & size & speed, malloc: with & without)

Useful links

License

NimP is licensed under the AGPL 3 (or newer) terms.

nimp's People

Contributors

zaphodef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nimp's Issues

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.