Examples

This page is currently a stub. We're working on additional examples tailored for beginners, so expect more samples soon.

The IDA SDK, which you can get from our Download Center in My Hex-Rays Portal, provides sample code in addition to necessary libraries and headers. These exemplary plugins, processor modules, or file loaders are designed to help you create your own plugins, modules, and more.

Where can I find all the examples?

The IDA SDK is shipped with plenty of samples (including, for example, sample processor modules or loaders) and exemplary plugins that you can find in the IDA SDK folder. To kickstart your journey with the IDA SDK, we encourage you to check out the included samples, compile them, and run them.

Sample plugins

The plugins folder contains sample plugins written in C++. Usually, the subfolders contains at minimum the cpp file(s) and a makefile.

Below, we present only a selection of samples to familiarize yourself with the possibilities of the C++ SDK. All of these samples and their corresponding makefiles can be found in your plugins folder inside the SDK directory.

hello

Simple hello word plugin ideal to get started with IDA SDK.

#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <kernwin.hpp>

//--------------------------------------------------------------------------
struct plugin_ctx_t : public plugmod_t
{
  virtual bool idaapi run(size_t) override;
};

//--------------------------------------------------------------------------
bool idaapi plugin_ctx_t::run(size_t)
{
  msg("Hello, world! (cpp)\n");
  return true;
}

//--------------------------------------------------------------------------
static plugmod_t *idaapi init()
{
  return new plugin_ctx_t;
}

//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
  IDP_INTERFACE_VERSION,
  PLUGIN_UNL            // Unload the plugin immediately after calling 'run'
  | PLUGIN_MULTI,       // The plugin can work with multiple idbs in parallel
  init,                 // initialize
  nullptr,
  nullptr,
  nullptr,              // long comment about the plugin
  nullptr,              // multiline help about the plugin
  "Hello, world",       // the preferred short name of the plugin
  nullptr,              // the preferred hotkey to run the plugin
};

vcsample

Sample plugin, ideal to get familiar with plugins structure.

calle

Sample plugin that allows the user to change the address of the called function.

choose

Sample plugin module that demonstrates the use of the choose() function.

custdata

This sample plugin demonstates how to install a custom data type and a custom data format.

custview

This sample plugin demonstates how to create and manipulate a simple custom viewer, that allows you to create a view which displays colored lines.

cvt64_sample

Plugin with CVT64 examples.

dwarf

The source code of the dwarf plugin

ex_debidc

This sample Debugger IDC Helper executes IDC script when the process is launched and allows to hook IDC scripts to various debugger events.

ex_events1

Sample plugin illustrating analysis improvement; it checks branch targets for newly created instructions.

extlang

Sample plugin that illustrates how to register a thid party language interpreter.

formsample

This plugin demonstrates how to use complex forms.

funclist

This sample plugin demonstrates how to get the the entry point prototypes.

getlines

This sample plugin demonstrates how to get the disassembly lines for one address.

highlighter

This plugin will display a colored box at the executed instructions.

ht_output

This sample plugin demonstrates receiving output window notification callbacks and usage of new output window functions.

ht_view

This sample plugin demonstrates usage of the view callbacks and adding custom menu items to popup menus.

mtsample

Sample multi-threaded plugin module.

This sample plugin demonstrates how to customize navigation band colors.

openform

This plugin demonstrates how to use non modal forms.

procext

Sample plugin that extends the IBM PC processor module to disassemble some NEC V20 instructions.

ui_requests

This plugin demonstrates the UI requests and the process_ui_action()

More plugin samples

We encourage you to browse the plugins folder inside the SDK directory to check out all of examples, including more complex and advances ones, like FindCrypt program, that finds constants used in crypto algorithms, or qproject, that demonstrates how to fully use the Qt environment in IDA.

Modules samples

The modules folder contains sample processor modules, that are used to add support for new instruction sets or architectures to IDA. Inside the README file you will find instructions on how to compile and run the modules.

If you are going to write a new processor module, it's recommended to follow the below steps:

  1. copy the sample module files to a new directory

  2. edit ins.cpp and ins.hpp files

  3. write the analyser ana.cpp

  4. then outputter

  5. and emulator (you can start with an almost empty emulator)

  6. describe the processor & assembler, write the notify() function

Loaders samples

The ldr folder includes source code for new file format loaders:

  • aif ARM Image File

  • amiga Amige Hunk File

  • aof ARM Object File

  • aout a.out

  • dos MS DOS File

  • dump Memory Dump File

  • geos GEOS File

  • hex Intel/Motorola HEX File

  • hpsom HP SOM

  • intelomf Intel Object File

  • javaldr Java Class Loader

  • mas Macro Assembler

  • nlm Netware Loader Module

  • os9 FLEX/9

  • pef Portable Executable Format (MAC)

  • pilot Palm Pilot

  • qnx Qnx

  • rt11 RT/11

  • w32run Watcom RUN32

ready to be compiled, similarly as processor module samples.

Decompiler SDK sample plugins

The exemplary decompiler plugins are shipped with the C++ SDK and can be found in the plugins folder (vds1-vds20) alongside other plugins.

Below are descriptions of sample decompiler plugins.

Sample 1

This plugin decompiles the current function and prints the result in the message window. It is useful to learn how to initialize a decompiler plugin. Please note that all decompiler sample plugins have the "hexrays_" prefix in their names. This is done to make sure that the decompiler plugins are loaded after the hexrays plugin. Otherwise they would see that the decompiler is missing and immediately terminate.

We recommend you to keep the same naming scheme: please use the "hexrays_" prefix for your decompiler plugins.

N.B.: if you're writing a plugin for non-x86 version of the decompiler, you should use another prefix. For example, the x64 decompiler is named "hexx64", ARM is "hexarm" and so on. To be certain, check IDA's "plugins" directory. To debug plugin loading issues, you can use -z20 switch when running IDA.

Sample 2

This plugin shows how to hook to decompiler events and react to them. It also shows how to visit all ctree elements and modify them.

This plugin waits for the decompilation result to be ready and replaces zeroes in pointer contexts with NULLs. One might say that this is just cosmetic change, but it makes the output more readable.

Since the plugin hooks to events, it is fully automatic. The user can disable it by selecting it from the Edit, Plugins menu.

Sample 3

This plugin shows

This is a quite complex plugin but it is thoroughly commented.

Sample 4

This plugin dumps all user-defined information to the message window. Read the source code to learn how to access various user-defined data from your plugins:

Sample 5

This plugin generates a graph from the current pseudocode and displays it with wingraph32.

The source code can be used to learn ctree details.

Sample 6

This plugin modifies the decompilation output: removes some space characters.

The source code can be used to learn the output text.

Sample 7

This plugin demonstrates how to use the cblock_t::iterator class. It enumerates all instructions of a block statement.

Sample 8

This plugin demonstrates how to use the udc_filter_t (User-Defined Call generator) class, which allows replacing cryptic function calls, with a simpler/more-readable counterpart.

Sample 9

This plugin demonstrates how to generate microcode for a given function and print it into the output window. It displays fully optimized microcode but it is also possible to retrieve microcode from earlier stages of decompilation. Generating the microcode text should be used only for debugging purposes. Printing microcode in production code may lead to crashes or wrong info.

Sample 10

This plugin installs a custom microcode optimization rule: call !DbgRaiseAssertionFailure fast:.0 => call !DbgRaiseAssertionFailure <fast:"char *" "assertion text">.0

See also sample19 for another example.

Sample 11

This plugin installs a custom inter-block optimization rule:

L1: goto L2

In other words we fix a goto target if it points to a chain of gotos. This improves the decompiler output is some cases.

Sample 12

This plugin displays list of direct references to a register from the current instruction.

Sample 13

This plugin generates microcode for selection and dumps it to the output window.

Sample 14

This plugin shows xrefs to the called function as the decompiler output. All calls are displayed with the call arguments.

Sample 15

This plugin shows list of possible values of a register using the value range analysis.

Sample 16

This plugin installs a custom instruction optimization rule:

We need this rule because the decompiler cannot propagate the second byte of VAR into the xor instruction.

The XOR opcode can be replaced by any other, we do not rely on it. Also operand sizes can vary.

Sample 17

This plugin shows how to use "Select offsets" widget (select_udt_by_offset() API). This plugin repeats the Alt-Y functionality.

Sample 18

This plugin shows how to specify a register value at a desired location. Such a functionality may be useful when the code to decompile is obfuscated and uses opaque predicates.

Sample 19

This plugin shows how to install a custom microcode optimization rule. Custom rules are useful to handle obfuscated code. See also sample10 for another example.

Sample 20

This plugin shows how to modify the decompiler output on the fly by adding dynamic comments.

Last updated

Was this helpful?