Skip to content

Commit

Permalink
update registers' name
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Sep 14, 2015
1 parent 72ea920 commit 5d30184
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 3 additions & 1 deletion ptrace.nimble
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[Package]
name = "ptrace"
version = "0.0.1"
version = "0.0.2"
author = "Huy Doan"
description = "ptrace wrapper for Nim"
license = "MIT"

skipDirs = "tests"

[Deps]
Requires: "nim >= 0.10.0"
31 changes: 17 additions & 14 deletions ptrace/ptrace.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import posix

{.pragma: c,
importc,
header: "sys/ptrace.h"
importc,
header: "sys/ptrace.h"
.}

type
Expand All @@ -11,21 +11,22 @@ type
r14*: culong
r13*: culong
r12*: culong
bp*: culong
bx*: culong
rbp*: culong
rbx*: culong
r11*: culong
r10*: culong
r9*: culong
r8*: culong
ax*: culong
xc*: culong
dx*: culong
si*: culong
di*: culong
orig_ax*: culong
ip*: culong
flags*: culong
sp*: culong
rax*: culong
rcx*: culong
rdx*: culong
rsi*: culong
rdi*: culong
orig_rax*: culong
rip*: culong
cs*: culong
eflags*: culong
rsp*: culong
ss*: culong
fs_base*: culong
gs_base*: culong
Expand Down Expand Up @@ -62,6 +63,8 @@ var
PTRACE_INTERRUPT* {.c.}: cint
PTRACE_LISTEN* {.c.}: cint



const
PTRACE_EVENT_FORK* = 1
PTRACE_EVENT_VFORK* = 2
Expand Down Expand Up @@ -171,7 +174,7 @@ when isMainModule:
discard wait(a)

var regs = getRegs(child)
echo "orig_ax: ", regs.orig_ax
echo "orig_rax: ", regs.orig_rax
if errno != 0:
echo errno, " ", strerror(errno)

Expand Down
7 changes: 6 additions & 1 deletion tests/test1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var child: Pid
var orig_eax, eax: clong
var params: array[3, clong]
var status: cint
var insyscall = 0;
var insyscall = 0


child = fork()

Expand All @@ -27,6 +28,10 @@ else:
params[1] = ptrace(PTRACE_PEEKUSER, child, RCX, nil)
params[2] = ptrace(PTRACE_PEEKUSER, child, RDX, nil)
echo "Write called with ", params[0], ", ", params[1], ", ", params[2]

let regs: Registers = getRegs(child)
echo regs.rbx, " ", regs.rcx, " ", regs.rdx

else:
eax = ptrace(PTRACE_PEEKUSER, child, RAX, nil)
echo "Write returned with ", eax
Expand Down

0 comments on commit 5d30184

Please sign in to comment.