Skip to content

Commit e7f6c4c

Browse files
committed
Refactor build system and reorganize test structure
- Add ida-cmake agent configuration for automated builds - Add comprehensive CLAUDE.md documentation - Update CMakeLists.txt and prep-cmake.bat for improved build process - Reorganize test_scripts/trigger-native to test_addons for clarity - Add CMakeLists.txt files for addon templates (loader, plugin, triton) - Improve project documentation and structure
1 parent 9df769d commit e7f6c4c

33 files changed

Lines changed: 389 additions & 48 deletions

.claude/agents/ida-cmake.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: ida-cmake
3+
description: Use this agent to compile/build IDA Pro extensions including plugins, idalib applications, processor modules, or file loaders (all known as IDA addons) using the IDA C++ SDK. Used this agent to create a new addon template or for troubleshooting build issues, configuring the IDASDK environment, or integrating ida-cmake into existing projects.
4+
model: sonnet
5+
color: orange
6+
---
7+
8+
IDA Pro addons usually refer to: plugins, processor modules, file loaders, or idalib standalone applications.
9+
You are an expert in building these addons using the ida-cmake CMake scripts located in `$IDASDK/ida-cmake`.
10+
11+
- Refer to `$IDASDK/ida-cmake/README.md` for documentation on how to use `ida-cmake`.
12+
- Refer to `$IDASDK/ida-cmake/templates/plugin/` for example CMakeLists.txt file and plugin
13+
- Refer to `$IDASDK/ida-cmake/templates/loader` for example CMakeLists.txt file and loader
14+
- Refer to `$IDASDK/ida-cmake/templates/procmod` for example CMakeLists.txt file and processor module
15+
- Refer to `$IDASDK/ida-cmake/templates/idalib` for example CMakeLists.txt file and idalib application
16+
- Refer to `$IDASDK/include` for SDK headers. All headers have docstrings, use them to explain SDK usage and lookup APIs.
17+
- Refer to `$IDASDK/plugins`, `$IDASDK/loaders`, `$IDASDK/module` for SDK example and how APIs are used in practice.
18+
19+
You must open and read those files above to answer the user correctly to answer all things IDA compiling and building related questions.
20+
21+
## CMake Usage
22+
23+
The ida-cmake provides clean interface libraries:
24+
- `idasdk::plugin` - For IDA plugins
25+
- `idasdk::loader` - For file loaders
26+
- `idasdk::procmod` - For processor modules
27+
- `idasdk::idalib` - For standalone idalib applications
28+
29+
## Example Usage
30+
31+
For quick reference, here's a skeleton CMakeLists.txt begining:
32+
33+
```cmake
34+
cmake_minimum_required(VERSION 3.27)
35+
project(myplugin)
36+
set(CMAKE_CXX_STANDARD 17)
37+
38+
# Include IDA SDK bootstrap
39+
include($ENV{IDASDK}/ida-cmake/bootstrap.cmake)
40+
find_package(idasdk REQUIRED)
41+
```
42+
43+
Now, for a plugin, use the `ida_add_plugin` function:
44+
45+
```cmake
46+
ida_add_plugin(myplugin
47+
SOURCES
48+
main.cpp
49+
DEBUG_ARGS
50+
"-t -z10000"
51+
)```
52+
53+
...and for a file loader, use the `ida_add_loader` function:
54+
55+
```cmake
56+
ida_add_loader(myloader
57+
SOURCES
58+
loader.cpp
59+
DEBUG_ARGS
60+
"-c -A" # Common loader debug args
61+
)```
62+
63+
...and for a standalone idalib application, use the following CMakeLists.txt:
64+
65+
```cmake
66+
ida_add_idalib_exe(myidalib
67+
SOURCES
68+
main.cpp
69+
DEBUG_ARGS
70+
"${IDASDK}/ida-cmake/samples/wizmo32.exe.i64"
71+
)```
72+
73+
To build an addon, just use something like from the addon source folder:
74+
75+
```bash
76+
cmake -B build
77+
cmake --build build --config RelWithDebInfo
78+
```

CLAUDE.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
# QScripts - IDA Pro Productivity Plugin
6+
7+
QScripts is an IDA Pro plugin that enables automatic script execution upon file changes, supporting hot-reload development workflows with Python, IDC, and compiled plugins.
8+
9+
## Build Commands
10+
11+
### Prerequisites
12+
- **IDASDK**: Environment variable must be set to IDA SDK path
13+
- **IDAX**: Must be installed at `$IDASDK/include/idax/`
14+
- **ida-cmake**: Must be installed at `$IDASDK/ida-cmake/`
15+
16+
### Build with ida-cmake agent
17+
Always use the ida-cmake agent for building:
18+
```
19+
Task with subagent_type="ida-cmake"
20+
```
21+
22+
### Manual build (Windows)
23+
```bash
24+
# Configure CMake
25+
prep-cmake.bat
26+
27+
# Build
28+
prep-cmake.bat build
29+
30+
# Clean build
31+
prep-cmake.bat clean
32+
```
33+
34+
## Architecture
35+
36+
### Core Components
37+
38+
**Main Plugin (`qscripts.cpp`)**
39+
- Implements `qscripts_chooser_t`: Non-modal chooser UI for script management
40+
- File monitoring system with configurable intervals (default 500ms)
41+
- Dependency tracking and automatic reloading
42+
- Integration with IDA's recent scripts system (shares same list)
43+
44+
**Script Management (`script.hpp`)**
45+
- `fileinfo_t`: File metadata and modification tracking
46+
- `script_info_t`: Script state management (active/inactive/dependency)
47+
- `active_script_info_t`: Extends script_info with dependency handling
48+
- Dependency resolution with recursive parsing and cycle detection
49+
50+
### Key Features Implementation
51+
52+
**Dependency System**
53+
- Dependencies defined in `.deps.qscripts` files
54+
- Supports `/reload` directive for Python module reloading
55+
- `/triggerfile` directive for custom trigger conditions
56+
- `/notebook` mode for cell-based execution
57+
- Variable expansion: `$basename$`, `$env:VAR$`, `$pkgbase$`, `$ext$`
58+
59+
**File Monitoring**
60+
- Uses qtimer-based polling (not OS-specific watchers yet)
61+
- Monitors active script and all dependencies
62+
- Trigger file support for compiled plugin development
63+
64+
## IDA SDK and API Resources
65+
66+
When answering SDK/API questions, search and read from:
67+
- **SDK Headers**: `$IDASDK/include` - All headers have docstrings
68+
- **SDK Examples**: `$IDASDK/plugins`, `$IDASDK/loaders`, `$IDASDK/module`
69+
70+
## Testing
71+
72+
Test scripts are located in `test_scripts/`:
73+
- `dependency-test/` - Simple dependency examples
74+
- `pkg-dependency/` - Package dependency examples
75+
- `notebooks/` - Notebook mode examples
76+
- `trigger-native/` - Compiled plugin hot-reload examples
77+
78+
## Plugin States
79+
80+
Scripts can be in three states:
81+
1. **Normal**: Shown in regular font
82+
2. **Active** (bold): Currently monitored for changes
83+
3. **Inactive** (italics): Previously active but monitoring disabled
84+
85+
## Important Implementation Notes
86+
87+
- Plugin uses IDAX framework for enhanced UI capabilities
88+
- Shares script list with IDA's built-in "Recent Scripts" (Alt-F9)
89+
- Maximum 512 scripts in list (IDA_MAX_RECENT_SCRIPTS)
90+
- Special unload function: `__quick_unload_script` called before reload
91+
- Supports undo via IDA's undo system when enabled in options

CMakeLists.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
2-
3-
project(qscripts)
4-
5-
include($ENV{IDASDK}/ida-cmake/common.cmake)
6-
7-
set(CMAKE_CXX_STANDARD 17)
8-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9-
10-
list(APPEND DISABLED_SOURCES utils_impl.cpp) # included file
11-
set(PLUGIN_NAME qscripts)
12-
set(PLUGIN_SOURCES qscripts.cpp ida.h script.hpp ${DISABLED_SOURCES})
13-
14-
set_source_files_properties(${DISABLED_SOURCES} PROPERTIES LANGUAGE "")
15-
16-
generate()
1+
cmake_minimum_required(VERSION 3.27)
2+
project(qscripts)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
# Include IDA SDK bootstrap
8+
include($ENV{IDASDK}/ida-cmake/bootstrap.cmake)
9+
find_package(idasdk REQUIRED)
10+
11+
# Convert paths to native format
12+
set(SAMPLE_IDB "${IDA_CMAKE_DIR}/samples/wizmo32.exe.i64")
13+
file(TO_NATIVE_PATH "${SAMPLE_IDB}" SAMPLE_IDB)
14+
15+
# Disabled sources
16+
list(APPEND DISABLED_SOURCES utils_impl.cpp)
17+
set_source_files_properties(${DISABLED_SOURCES} PROPERTIES LANGUAGE "")
18+
19+
# Add plugin
20+
ida_add_plugin(qscripts
21+
SOURCES
22+
qscripts.cpp
23+
ida.h
24+
script.hpp
25+
${DISABLED_SOURCES}
26+
DEBUG_ARGS
27+
"${SAMPLE_IDB}"
28+
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Now, simply use your favorite IDE (or terminal) and build (or rebuild) the `hell
151151

152152
The moment the compilation succeeds, the new binary will be detected (since it is the trigger file) then your active script will use IDA's `load_and_run_plugin()` to run the plugin again.
153153

154-
Please check the [trigger-native](test_scripts/trigger-native/) example.
154+
Please check the native addons examples in [test_addons](test_addons/).
155155

156156
# Building
157157

prep-cmake.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if not exist %IDASDK%\include\idax\xkernwin.hpp (
1515
goto :eof
1616
)
1717

18-
if not exist %IDASDK%\ida-cmake\common.cmake (
18+
if not exist %IDASDK%\ida-cmake\idasdkConfig.cmake (
1919
echo ida-cmake not properly installed in the IDA SDK folder.
2020
echo See: https://github.com/allthingsida/ida-cmake
2121
goto :eof
File renamed without changes.
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.27)
2+
project(qscripts_native)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
# Include IDA SDK bootstrap
8+
include($ENV{IDASDK}/ida-cmake/bootstrap.cmake)
9+
find_package(idasdk REQUIRED)
10+
11+
# Add loader
12+
ida_add_loader(qscripts_native
13+
SOURCES
14+
driver.cpp
15+
main.cpp
16+
idasdk.h
17+
DEBUG_ARGS
18+
"-t"
19+
)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)