From ad98e4ecd3d6ddc999e93f59549a03ef05fffead Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 6 Oct 2016 01:04:12 -0400 Subject: Generate some test code in jrp --- .bin/jrp.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.bin/jrp.c b/.bin/jrp.c index 83894342..cd5dbb82 100755 --- a/.bin/jrp.c +++ b/.bin/jrp.c @@ -2,6 +2,13 @@ exec cc -Wall -Wextra $@ -o $(dirname $0)/jrp $0 #endif +#include +#include +#include +#include +#include +#include + enum op { OP_PROL = 0x90fc8948e5894855, // push ebp; mov rbp, rsp; mov rsp, rdi OP_EPIL = 0xc35dec8948e08948, // mov rax, rsp; mov rsp, rbp; pop rbp; ret @@ -24,6 +31,35 @@ enum op { OP_SHR = 0x906666242cd34859, // pop rcx; shr qword [rsp], cl }; +typedef int64_t *(*fptr)(int64_t *); + int main() { + int error; + int page = getpagesize(); + + int64_t *stack = mmap(0, page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); + if (stack == MAP_FAILED) err(EX_OSERR, "mmap"); + int64_t *stack_ptr = stack + page / sizeof(int64_t); + + enum op *ops = mmap(0, page, PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); + if (ops == MAP_FAILED) err(EX_OSERR, "mmap"); + + enum op *p = ops; + *p++ = OP_PROL; + *p++ = OP_PUSH | (1 << 8); + *p++ = OP_PUSH | (2 << 8); + *p++ = OP_ADD; + *p++ = OP_DUP; + *p++ = OP_MUL; + *p++ = OP_EPIL; + + error = mprotect(ops, page, PROT_READ | PROT_EXEC); + if (error) err(EX_OSERR, "mprotect"); + + fptr fn = (fptr) ops; + stack_ptr = fn(stack_ptr); + + printf("%lld\n", *stack_ptr); + return 0; } -- cgit 1.4.1 ='qt'>
Commit message (Collapse)Author
2019-01-15Add sans8x16.psfJune McEnroe
The symbols are still really bad...
2019-01-14Add guides to psfedJune McEnroe
2019-01-14Check for NULL copy or undo buffers in psfedJune McEnroe
2019-01-14Add cash.7 READMEJune McEnroe
2019-01-14Document old=new argument of fc -sJune McEnroe
2019-01-14Allow replacing empty string with fc old=newJune McEnroe
2019-01-13Enable warnings in libeditJune McEnroe
2019-01-13Show full path in RPS1June McEnroe
2019-01-13Shorten $HOME to ~ in prompt expansionJune McEnroe
2019-01-13Document PSlitJune McEnroe
2019-01-13Document PS0June McEnroe
2019-01-13Set PS0 in cashJune McEnroe
2019-01-13Add PS0June McEnroe
2019-01-13Change default ENV from cashrc to env.shJune McEnroe
2019-01-13Use colours in cash promptsJune McEnroe
2019-01-12Set PSlit like NetBSD shJune McEnroe
2019-01-12Install gnupg2 from pkgsrc and symlink gpgJune McEnroe
2019-01-12Reference cash builtin man pages in cash.1 SEE ALSOJune McEnroe
2019-01-12Restore cash builtin man page datesJune McEnroe
2019-01-12Use local libeditJune McEnroe
2019-01-12Replace libedit MakefileJune McEnroe
2019-01-11Import /usr/src/lib/libedit from NetBSD 8.0June McEnroe
2019-01-11Add PSlit for prompt escapesJune McEnroe
2019-01-11Don't make depend automaticallyJune McEnroe