Skip to content

Commit

Permalink
some minor changes, sync w/ upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Mar 12, 2019
1 parent b5608a2 commit 0536a4f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/private/subhook
56 changes: 33 additions & 23 deletions src/subhook.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ospaths

{.compile: "private/subhook/subhook.c".}

{.passC: "-DSUBHOOK_STATIC".}
{.pragma: subhook,
cdecl,
importc,
Expand All @@ -11,31 +11,41 @@ import ospaths


type
subhook_t* {.final, pure.} = object

subhook_flags* {.pure.} = enum
NONE
SUBHOOK_64BIT_OFFSET = 1

proc subhook_new(src, dst: pointer, flags: subhook_flags): ptr subhook_t {.subhook.}
proc subhook_free(hook: ptr subhook_t) {.subhook.}
proc subhook_get_src(hook: ptr subhook_t): pointer {.subhook.}
proc subhook_get_dst(hook: ptr subhook_t): pointer {.subhook.}
proc subhook_get_trampoline(hook: ptr subhook_t): pointer {.subhook.}
proc subhook_install(hook: ptr subhook_t): cint {.subhook.}
proc subhook_is_installed(hook: ptr subhook_t): cint {.subhook.}
proc subhook_remove(hook: ptr subhook_t): cint {.subhook.}
subhook_struct* {.bycopy.} = object
installed*: int
src*: pointer
dst*: pointer
flags*: subhook_flags
code*: pointer
trampoline*: pointer
jmp_size*: csize
trampoline_size*: csize
trampoline_len*: csize

subhook_t* = ptr subhook_struct

proc subhook_new(src, dst: pointer, flags: subhook_flags): subhook_t {.subhook.}
proc subhook_free(hook: subhook_t) {.subhook.}
proc subhook_get_src(hook: subhook_t): pointer {.subhook.}
proc subhook_get_dst(hook: subhook_t): pointer {.subhook.}
proc subhook_get_trampoline(hook: subhook_t): pointer {.subhook.}
proc subhook_install(hook: subhook_t): cint {.subhook.}
proc subhook_is_installed(hook: subhook_t): cint {.subhook.}
proc subhook_remove(hook: subhook_t): cint {.subhook.}


type
Hook* = object
impl: ptr subhook_t
Hook* = ptr subhook_struct

proc initHook*(src, dest: pointer, flags: subhook_flags = NONE): Hook {.inline.} =
result.impl = subhook_new(src, dest, flags)
result = subhook_new(src, dest, flags)

proc initHook*(src, dest: int, flags = NONE): Hook {.inline.} =
initHook(cast[pointer](src), cast[pointer](dest), flags)
proc initHook*(src, dest: int, flags = NONE): Hook {.inline.} =
result = subhook_new(cast[pointer](src), cast[pointer](dest), flags)

proc initHook*(src: pointer, dest: int, flags = NONE): Hook {.inline.} =
initHook(src, cast[pointer](dest), flags)
Expand All @@ -44,25 +54,25 @@ proc initHook*(src: int, dest: pointer, flags = NONE): Hook {.inline.} =
initHook(cast[pointer](src), dest, flags)

proc free*(hook: Hook) {.inline.} =
subhook_free(hook.impl)
subhook_free(hook)

proc getSource*(hook: Hook): pointer {.inline.} =
subhook_get_src(hook.impl)
subhook_get_src(hook)

proc getDest*(hook: Hook): pointer {.inline.} =
subhook_get_dst(hook.impl)
subhook_get_dst(hook)

proc getTrampoline*(hook: Hook): pointer {.inline.} =
subhook_get_trampoline(hook.impl)
subhook_get_trampoline(hook)

proc install*(hook: Hook): int {.inline, discardable.} =
subhook_install(hook.impl)
subhook_install(hook)

proc isInstalled*(hook: Hook): int {.inline.} =
subhook_is_installed(hook.impl)
subhook_is_installed(hook)

proc remove*(hook: Hook): int {.inline, discardable.} =
subhook_remove(hook.impl)
subhook_remove(hook)


when isMainModule:
Expand Down
5 changes: 0 additions & 5 deletions src/subhook.nims

This file was deleted.

4 changes: 2 additions & 2 deletions subhook.nimble
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Package

version = "0.5.2"
version = "0.5.3"
author = "Huy Doan"
description = "subhook wrapper"
license = "BSD2"
srcDir = "src"

# Dependencies

requires "nim >= 0.18.1"
requires "nim >= 0.19.4"

0 comments on commit 0536a4f

Please sign in to comment.