Skip to content

0xeb/hiew-sdk-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hiew-sdk-cpp

Modern C++ SDK for developing Hiew External Modules (HEM).

Wraps the raw C SDK (v0.54) with idiomatic C++ abstractions.

Requirements

  • Windows only (Hiew is a Windows application)
  • 32-bit only (Hiew is 32-bit)
  • CMake 3.16+
  • MSVC (Visual Studio 2019+)

Quick Start

As a Git Submodule

git submodule add https://github.com/0xeb/hiew-sdk-cpp.git extern/hiew-sdk-cpp

CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(my_plugin LANGUAGES C CXX)

add_subdirectory(extern/hiew-sdk-cpp)

add_hem_module(my_plugin SOURCES src/my_plugin.cpp)

my_plugin.cpp:

#include <hiew/hiew.hpp>

int plugin_main() {
    auto d = hiew::data();
    if (!d) return hiew::error;

    hiew::message("Hello", "Plugin loaded!");
    return hiew::ok;
}

HIEW_PLUGIN(
    plugin_main,
    "MyPlugin",
    "My Hiew Plugin",
    1, 0,
    hiew::Flag::AllModes | hiew::Flag::AllFiles,
    "", "", "")

Build:

mkdir build && cd build
cmake -A Win32 ..
cmake --build . --config Release

Copy my_plugin.hem to Hiew's hem/ folder.

Extending the Target

add_hem_module() creates a standard CMake target:

add_hem_module(my_plugin SOURCES src/my_plugin.cpp)

target_sources(my_plugin PRIVATE src/utils.cpp)
target_include_directories(my_plugin PRIVATE include/)
target_compile_definitions(my_plugin PRIVATE DEBUG_MODE=1)
target_link_libraries(my_plugin PRIVATE my_lib)

How Plugins Work

A HEM plugin is a DLL (renamed to .hem) that exports a single function: Hem_Load. When Hiew loads the plugin, it calls this function and passes a HIEWINFO_TAG structure containing a HiewGate function pointer for calling Hiew APIs. The plugin returns a HEMINFO_TAG structure with its metadata and callback function pointers (EntryPoint, Unload, Hem2HemGate).

When the user activates the plugin, Hiew calls the EntryPoint callback. The plugin then uses HiewGate to interact with Hiew (show menus, read files, etc.).

The HIEW_PLUGIN macro handles all this boilerplate - it creates the Hem_Load export, stores the HiewGate pointer, and wires up your entry function as the EntryPoint callback.

API Overview

Core

auto d = hiew::data();              // Get file info (name, length, cursor)
hiew::message("Title", "Text");     // Show message box
auto s = hiew::get_string("Prompt", 64, "default");  // Input dialog

Return Actions

hiew::return_offset(0x1000);        // Jump to offset on exit
hiew::return_mode(hiew::ReturnMode::Hex);  // Switch view mode

File Operations

auto [err, buf] = hiew::file_read(offset, 256);
hiew::file_write(offset, data);     // Requires file_open_for_write()

Names/Symbols

hiew::names::add_global(offset, "my_func");
hiew::names::add_local(local_offset, "label");
auto result = hiew::names::find("my_func");

Search & Markers

auto found = hiew::find(hiew::FindFlag::None, start, pattern);
hiew::mark_block(start, end);
hiew::color_marker(offset, length, 0x20);  // Green

UI

auto menu = hiew::ui::Menu::create("Title")
    .items({"Option 1", "Option 2"})
    .width(30);
auto [line, key] = menu.show();

auto window = hiew::ui::Window::create("Info")
    .lines({"Line 1", "Line 2"})
    .show();

Building Examples

cmake -A Win32 -DHIEW_SDK_BUILD_EXAMPLES=ON ..
cmake --build . --config Release

License

MIT License. See LICENSE file.

About

C++ SDK for the Hiew Hex Editor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published