Skip to content

Commit 43c6eef

Browse files
ippm: add example native plugin cross compiled with zig cc
1 parent 3c9f7e2 commit 43c6eef

File tree

9 files changed

+135
-0
lines changed

9 files changed

+135
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "plugins/plugin-manager/examples/native-ida-plugin/src/deps/zig-cross"]
2+
path = plugins/plugin-manager/examples/native-ida-plugin/src/deps/zig-cross
3+
url = git@github.com:mrexodia/zig-cross.git
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build-*/
2+
dist/
3+
build/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# native-ida-plugin
2+
3+
## Build
4+
5+
Have the following installed:
6+
- cmake
7+
- zig
8+
- just
9+
- python, with package `build`
10+
11+
```
12+
$ export IDASDK=~/.idapro/sdk/idasdk91/
13+
$ just build
14+
```
15+
16+
Then find the output file in `dist/native_ida_plugin-0.1.0-py3-none-any.whl`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mysample.so
2+
mysample.dll
3+
mysample_x86_64.dylib
4+
mysample_aarch64.dylib
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
_build target:
2+
cmake -B "build-{{target}}" -DCMAKE_TOOLCHAIN_FILE="deps/zig-cross/{{target}}.cmake" -S src/ -Wno-dev
3+
rm -f $IDASDK/bin/plugins/mysample.*
4+
cmake --build "build-{{target}}" --target all
5+
mv -f $IDASDK/bin/plugins/mysample.* "build-{{target}}/"
6+
7+
build-linux-x86_64: (_build "x86_64-linux-gnu")
8+
build-macos-x86_64: (_build "x86_64-macos-none")
9+
build-macos-aarch64: (_build "aarch64-macos-none")
10+
build-windows-x86_64: (_build "x86_64-windows-gnu")
11+
12+
build-wheel:
13+
cp build-x86_64-linux-gnu/mysample.so bin/native_ida_plugin/mysample.so
14+
cp build-x86_64-macos-none/mysample.dylib bin/native_ida_plugin/mysample_x86_64.dylib
15+
cp build-aarch64-macos-none/mysample.dylib bin/native_ida_plugin/mysample_aarch64.dylib
16+
cp build-x86_64-windows-gnu/mysample.dll bin/native_ida_plugin/mysample.dll
17+
python -m build --wheel
18+
19+
build: build-linux-x86_64 build-macos-x86_64 build-macos-aarch64 build-windows-x86_64 build-wheel
20+
21+
clean-wheel:
22+
rm -rf bin/native_ida_plugin/* build/ dist/
23+
24+
_clean target:
25+
-cmake --build "build-{{target}}" --target clean
26+
rm -rf "build-{{target}}"
27+
28+
clean-linux-x86_64: (_clean "x86_64-linux-gnu")
29+
clean-macos-x86_64: (_clean "x86_64-macos-none")
30+
clean-macos-aarch64: (_clean "aarch64-macos-none")
31+
clean-windows-x86_64: (_clean "x86_64-windows-gnu")
32+
33+
clean: clean-linux-x86_64 clean-macos-x86_64 clean-macos-aarch64 clean-windows-x86_64 clean-wheel
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[project]
2+
name = "williballenthin-native-ida-plugin"
3+
authors = [
4+
{name = "Willi Ballenthin", email = "wballenthin@google.com"},
5+
]
6+
description = "Example IDA Plugin (native)"
7+
version = "0.1.0"
8+
readme = "README.md"
9+
license = "Apache-2.0"
10+
requires-python = ">=3.9"
11+
dependencies = []
12+
13+
[project.entry-points.'idapro.plugins']
14+
aarch64-apple-darwin = "native_ida_plugin:mysample_aarch64"
15+
x86_64-apple-darwin = "native_ida_plugin:mysample_x86_64"
16+
x86_64-unknown-linux = "native_ida_plugin:mysample"
17+
x86_64-pc-windows = "native_ida_plugin:mysample"
18+
19+
[build-system]
20+
requires = ["setuptools>=61.0"]
21+
build-backend = "setuptools.build_meta"
22+
23+
[tool.setuptools]
24+
package-dir = {"" = "bin"} # Python package data is found in "bin/" directory.
25+
# "src/" is the default, but we'll use "bin/" for all this binary data.
26+
27+
[tool.setuptools.package-data]
28+
"native_ida_plugin" = [
29+
# filenames relative to: bin/native_ida_plugin/
30+
"mysample.dll",
31+
"mysample.so",
32+
"mysample_aarch64.dylib",
33+
"mysample_x86_64.dylib",
34+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
2+
3+
project(mysample)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
include($ENV{IDASDK}/ida-cmake/idasdk.cmake)
8+
9+
set(PLUGIN_NAME mysample)
10+
set(PLUGIN_SOURCES mysample.cpp)
11+
12+
generate()
13+
disable_ida_warnings(mysample)
Submodule zig-cross added at 673a914
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <ida.hpp>
2+
#include <idp.hpp>
3+
#include <loader.hpp>
4+
#include <kernwin.hpp>
5+
6+
//--------------------------------------------------------------------------
7+
struct plugin_ctx_t : public plugmod_t
8+
{
9+
bool idaapi run(size_t) override
10+
{
11+
msg("Hello from native!\n");
12+
return true;
13+
}
14+
};
15+
16+
//--------------------------------------------------------------------------
17+
plugin_t PLUGIN =
18+
{
19+
IDP_INTERFACE_VERSION,
20+
PLUGIN_UNL | PLUGIN_MULTI,
21+
[]()->plugmod_t* {return new plugin_ctx_t; }, // initialize
22+
nullptr,
23+
nullptr,
24+
"This is an example native plugin (comment)", // long comment about the plugin
25+
"This is an example native plugin", // multiline help about the plugin
26+
"Example native plugin", // the preferred short name of the plugin
27+
nullptr, // the preferred hotkey to run the plugin
28+
};

0 commit comments

Comments
 (0)