Skip to content

TechMecca/Ida-Code-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

🧠 IDA Code Generator (Function Wrapper & Detour Plugin)

A plugin for IDA Pro 9.1 that automatically generates ready-to-use C/C++ code for interacting with analyzed functions. It supports both direct function calling wrappers and detouring/hooking stubs with multiple hooking frameworks: Windows Detours, MinHook, and ByteWeaver.

Making it easier to integrate reverse-engineered code into real projects.


🚀 Features

  • 🔌 Native IDA Pro 9.1 plugin integration
  • 🧩 Generates C/C++ callable wrappers for identified functions
  • 🪝 Generates hook/detour templates with multiple framework support:
    • Windows Detours - Microsoft's detour framework
    • MinHook - Minimal x86/x64 API Hooking Library
    • ByteWeaver - Macro-based memory hooking framework
  • ⚙️ Auto-save settings that persist across IDA restarts
  • 📄 Converts IDA-analyzed functions into reusable project code
  • 🧠 Works directly from disassembled function context
  • 💡 Speeds up binary integration and runtime patching workflows
  • 🔍 Intelligent parameter naming (a1, a2, a3, etc. for unnamed parameters)
  • ✨ Support for __thiscall, __cdecl, __stdcall, __fastcall calling conventions

🎯 What This Plugin Does

When analyzing a binary in IDA, this plugin can:

1. Generate Function Call Wrappers

It produces clean code that allows you to call reverse-engineered functions directly from your own project:

DWORD __cdecl MyFunction(int a1, const char* a2)
{
    return ((decltype(&MyFunction))(0x401000))(a1, a2);
}

2. Generate Hook/Detour Stubs

It can generate hook templates for multiple frameworks:

Windows Detours:

typedef DWORD (__cdecl* OriginalMyFunctionFn_t)(int a1, const char* a2);
OriginalMyFunctionFn_t OriginalMyFunction = NULL;

DWORD __cdecl MyFunctionHk(int a1, const char* a2)
{
    // custom logic here
    return OriginalMyFunction(a1, a2);
}

DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&OriginalMyFunction, (PVOID)MyFunctionHk);
DetourTransactionCommit();

MinHook:

typedef DWORD (__cdecl* OriginalMyFunctionFn_t)(int a1, const char* a2);
OriginalMyFunctionFn_t OriginalMyFunction = nullptr;

DWORD __cdecl MyFunctionHk(int a1, const char* a2)
{
    // custom logic here
    return OriginalMyFunction(a1, a2);
}

MH_Initialize();
MH_CreateHook((LPVOID)0x401000, (LPVOID)MyFunctionHk, (LPVOID*)&OriginalMyFunction);
MH_EnableHook((LPVOID)0x401000);

ByteWeaver:

DECLARE_HOOK_SIMPLE(MyFunction, DWORD, __cdecl, int a1, const char* a2);

DWORD __cdecl MyFunctionHook(int a1, const char* a2)
{
    // custom logic here
    return MyFunctionOriginal(a1, a2);
}

INSTALL_HOOK_ADDRESS(MyFunction, 0x401000);

📦 Requirements

  • IDA Pro 9.1
  • IDAPython enabled
  • C/C++ compiler (for integrating generated output)
  • Optional: Hooking library based on your choice:
    • Windows Detours - Microsoft Detours library
    • MinHook - Minimal API Hooking Library
    • ByteWeaver - Custom memory hooking framework by @0xKate

📁 Installation

  1. Open your IDA installation directory:
<IDA_INSTALLATION>/plugins/
  1. Copy:
ida_Code_generator.py
  1. Restart IDA Pro

  2. The plugin will appear under:

Edit → Plugins → Code Generator

▶️ Usage

  1. Load a binary in IDA Pro

  2. Wait for auto-analysis to complete

  3. Position cursor in a function

  4. Choose your hook framework:

  • Windows Detours - For Microsoft Detours library
  • MinHook - For Minimal API Hooking
  • ByteWeaver - For macro-based hooking
  1. Configure settings as needed (auto-saves!)
  2. Click "Generate Detours Hook" or "Generate Calling Function"
  3. Copy generated code into your project

⚙️ Settings

The plugin includes comprehensive settings that auto-save and persist across IDA restarts:

Output Options

  • Hook Framework - Select between Windows Detours, MinHook, or ByteWeaver
  • Include Comments in Generated Code - Add/remove TODO comments
  • Include Typedef Declarations - Include function pointer typedefs
  • Include Original Signature Comment - Show original IDA signature

Hook Options

  • Include Framework Setup Code - Include initialization/hook attachment code
  • Auto-Copy Generated Code to Clipboard - Automatically copy to clipboard on generation

🧠 How It Works

The plugin leverages IDAPython APIs to:

  • Identify selected or discovered functions
  • Extract function signatures (where possible)
  • Detect calling conventions and parameters
  • Read addresses and type information
  • Generate structured C/C++ code templates
  • Support multiple hooking frameworks
  • Auto-persist settings to IDA database

It bridges the gap between:

🔍 Reverse engineering (IDA analysis) and 🧱 Real-world code integration


📂 File Structure

ida_code_gen_with_settings.py    # Main IDA Pro 9.1 plugin with multi-framework support
README.md                        # This file

💡 Use Cases

  • Reverse engineering software for research or auditing
  • Game hacking / modding workflows (where permitted)
  • Malware analysis and behavioral redirection
  • Binary API reconstruction
  • Rapid prototyping of function interfaces
  • Runtime hooking and detouring
  • Integration of reverse-engineered code into custom tools

🔧 Framework Comparison

Feature Windows Detours MinHook ByteWeaver
Setup Complexity Medium Low Low
Macro-Based No No Yes
Microsoft Yes No No
Typedef Support Yes Yes Yes
x86/x64 Yes Yes Yes
Type Safety High High High

⚠️ Disclaimer

This tool is intended strictly for educational, research, and authorized security testing purposes only.

Do not use this plugin on software you do not own or have explicit permission to analyze.

The author is not responsible for misuse.


🤝 Contributing

Pull requests are welcome.

Ideas for improvement:

  • Better type inference from IDA signatures
  • Improved calling convention detection
  • Additional hooking framework support
  • Export formats (JSON, etc.)
  • Batch code generation

📜 License

The MIT License (MIT)

Copyright (c) 2025 Tech Mecca

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


🔗 Notes

This plugin is designed for IDA Pro 9.1, but may be adaptable to other versions with minor API adjustments.

Version History

  • v2.1.0 - Added auto-save settings, MinHook support, ByteWeaver support
  • v2.0.0 - Initial release with Windows Detours support

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages