carrot

package module
v0.0.0-...-448aa33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2018 License: MIT Imports: 7 Imported by: 0

README

GO carrot patch

This is a detours like library for Golang!

Ref

Design

  call target                                                  call original
      v                                                              |
      |                                                              |
      |       target                              replacement        |       original
      +-> +-----------+                     +-> +-------------+      +---> +----------+
          |    JMP1   | jump to replacement |   |     new     |            |    JMP   |
      +-> +-----------+---------------------+   |    target   |            +----+-----+
      |   |    code   |       (jmp2r)           |     func    |                 |
      |   |    ...    |                         |             |                 |
      |   +-----------+                         +-------------+          jump to bridge
      |   |    JMP2   |                                                         |
      |   +-----------+---------+                                               |
    (jmp2t)                     |                                             (jmp2b)
      |                  jump to incr stack                                     |
      |                       (jmp2i)                                           |
      |          bridge         |                                               |
      |   +----------------+ <--------------+-----------------------------------+
      |   | code from JMP1 |    |           ^
      |   +----------------+    |           |
      |   |    JMP         |    |           |
      +---+----------------+    |  continue exec after stack incrd
          +----------------+ <--+         (jmp2b)
          | call incr stk  |                |
          +----------------+                |
          |       JMP      |                |
          +----------------+----------------+

Using carrot

package main

import (
	"fmt"

	"github.com/CodeTrek/carrot"
)

var t3 = func() string { return "target" }
var r3 = func() string { return "replacement" }
var o3 = func() string { return "original" }

func main() {
	carrot.Patch(t3, r3, o3)
	fmt.Printf("after patch\ntarget=%s, replacement=%s, original=%s\n", t3(), r3(), o3())
    
    carrot.Unpatch(t3)
}

Warning!!

This library is not fully tested.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Break

func Break()

Break int3

func Disas

func Disas(target interface{})

Disas function

func GetBridge

func GetBridge(target interface{}) []byte

GetBridge of target

func IsPatched

func IsPatched(f interface{}) bool

IsPatched to test wether f is patched or used as bridge

func Patch

func Patch(target, replacement, original interface{}) bool

Patch is to patch function

target: func to replace
replacement: new func
original: to recv original target func pointer

func Unpatch

func Unpatch(target interface{})

Unpatch target

func UnpatchAll

func UnpatchAll()

UnpatchAll func

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL