• Stars
    star
    158
  • Rank 236,226 (Top 5 %)
  • Language
    C
  • Created about 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Runtime C++ Editing

DynamicPatcher

Runtime C++ Editing library.
compile .cpps, load and link .objs (or .libs, .dlls), and update functions at runtime.

##demo movie
DynamicPatcher demo

##detailed description (japanese) http://www.slideshare.net/i-saint/runtime-cediting
(japanese) http://i-saint.hatenablog.com/entry/2013/06/06/212515

##example

#include <windows.h> // Sleep()
#include <cstdio>
#include "DynamicPatcher.h"

// dpPatch をつけておくとロード時に同名の関数を自動的に更新する。
// (dpPatch は単なる dllexport。.obj に情報が残るいい指定方法が他に見当たらなかったので仕方なく…。
//  この自動ロードは dpInitialize() のオプションで切ることも可能)
dpPatch void MaybeOverridden()
{
    // ここを書き換えるとリアルタイムに挙動が変わる
    puts("MaybeOverridden()\n");
}

// CRT の関数を差し替える例。今回の犠牲者は puts()
int puts_hook(const char *s)
{
    typedef int (*puts_t)(const char *s);
    puts_t orig_puts = (puts_t)dpGetUnpatched(&puts); // hook 前の関数を取得
    orig_puts("puts_hook()");
    return orig_puts(s);
}

// dpOnLoad() の中身はロード時に自動的に実行される。アンロード時に実行される dpOnUnload() も記述可能
dpOnLoad(
    // dpPatch による自動差し替えを使わない場合、on load 時とかに手動で差し替える必要がある。
    // 元関数と新しい関数の名前が違うケースでは手動指定するしかない。
    dpPatchAddressToAddress(&puts, &puts_hook); // puts() を puts_hook() に差し替える
)

int main()
{
    dpInitialize();
    dpAddSourcePath("."); // このディレクトリのファイルに変更があったらビルドコマンドを呼ぶ
    dpAddModulePath("example.obj"); // ビルドが終わったらこのファイルをロードする
    // cl.exe でコンパイル。msbuild や任意のコマンドも指定可能。
    // 実運用の際は msbuild を使うか、自動ビルドは使用せすユーザー制御になると思われる。
    // (dpStartAutoBuild() を呼ばなかった場合、dpUpdate() はロード済み or module path にあるモジュールに更新があればそれをリロードする)
    dpAddCLBuildCommand("example.cpp /c /Zi");
    dpStartAutoBuild(); // 自動ビルド開始

    for(;;) {
        MaybeOverridden();
        ::Sleep(2000);
        dpUpdate();
    }

    dpFinalize();
}

// cl /Zi example.cpp && ./example

##license CC BY

##thanks DynamicPatcher contains a disassembler (tDisasm) by Matt Conover.
Runtime-Compiled C++
Mhook
PE/COFF file format
lib file format

Riot Games used this library!

More Repositories

1

Unity5Effects

C#
1,645
star
2

BatchRenderer

C#
209
star
3

MassParticle

C#
189
star
4

RaymarchingOnUnity5

C#
103
star
5

DeferredShading

C#
78
star
6

SmallFBX

An open-source implementation of Autodesk's FBX
C++
50
star
7

UnityCppScript

C++
49
star
8

scribble

scribble
C++
41
star
9

RemoteTalk

VOICEROID & CeVIO CS for Unity
C++
40
star
10

Alcantarea

C
40
star
11

PatchLibrary

C++
39
star
12

exception

http://i-saint.skr.jp/exception/
C++
32
star
13

WebAlembicViewer

Simple alembic viewer that works on browser.
C++
30
star
14

BlueImpulse

C#
30
star
15

OpenSubdivForUnity

C#
29
star
16

MemoryLeakBuster

C++
23
star
17

OpenToonzPluginForUnity

OpenToonz plugin as Unity post effects
C++
21
star
18

SIMDExample

C#
17
star
19

D3D12Raymarcher

C++
15
star
20

atomic

流体シム STG。カワノさんによるサウンドデータはこちら http://pocomo.skr.jp/atomic_sound/
C++
11
star
21

exception_conflict

http://i-saint.skr.jp/exception_conflict/
C++
10
star
22

USDForMetasequoia

C++
9
star
23

CEDEC2022_expand_video

JavaScript
8
star
24

OpticalCircuitUnityPort

C
8
star
25

D3DHookInterface

C++
8
star
26

WebDebugMenu

debug menu implemented by HTTP Server & HTML.
C
7
star
27

ScreenCaptureTest

C
7
star
28

Marionette

C++
6
star
29

BinaryGenerator

C++
4
star
30

GDCVaultExpandVideo

JavaScript
4
star
31

halfVisualizer

C++
3
star
32

CEDEC2016_4kintro

C++
3
star
33

WebInterface

C++
3
star
34

LazyD3D11DeviceContext

C++
3
star
35

glSpriteFont

sprite font の OpenGL 実装
C
3
star
36

ispc_SPH

C++
3
star
37

AlembicForMetasequoia

C++
2
star
38

SerializeCoroutineTest

C++
2
star
39

UnrealPlugins

JavaScript
2
star
40

RaymarchingInUnity

C
2
star
41

legeclodb

Vue
1
star
42

flat_container

C++
1
star
43

WebController

WebController
C++
1
star