Compare commits

1 Commits
main ... test

Author SHA1 Message Date
d59c4788d9 Test 2024-04-19 15:51:54 +02:00

View File

@@ -3,34 +3,29 @@
#if defined(__linux__) #if defined(__linux__)
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/random.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <linux/futex.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/random.h>
#include <sys/syscall.h>
#include <unistd.h>
uint8_t *__jasmin_syscall_randombytes__(uint8_t *_x, uint64_t xlen) {
uint8_t* __jasmin_syscall_randombytes__(uint8_t* _x, uint64_t xlen)
{
int i; int i;
uint8_t* x = _x; uint8_t *x = _x;
printf("%lx:\n", x); printf("%lx:\n", x);
for (i = 0; i < xlen; i++) for (i = 0; i < xlen; i++) {
{
printf("%02X", _x[i]); printf("%02X", _x[i]);
} }
printf("\n"); printf("\n");
return _x; return _x;
} }
@@ -54,15 +49,16 @@ uint8_t* __jasmin_syscall_randombytes__(uint8_t* _x, uint64_t xlen)
// } // }
// } // }
uint64_t __jasmin_syscall_open__(uint8_t* x, uint64_t xlen) uint64_t __jasmin_syscall_open__(uint8_t *x, uint64_t xlen) {
{ uint8_t *mem =
uint8_t* mem = (uint8_t*)mmap(NULL, 1024, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0); (uint8_t *)mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0);
if (mem == NULL) { if (mem == NULL) {
puts("mem error"); puts("mem error");
exit(1); exit(1);
} }
uintptr_t addr = (uintptr_t)(mem - 4096); uintptr_t addr = (uintptr_t)(mem - 4096);
void* futex_mem = mmap((void*)addr, 1024, PROT_READ|PROT_WRITE, MAP_SHARED, 4, 0); void *futex_mem =
mmap((void *)addr, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, 4, 0);
if ((uintptr_t)futex_mem != addr) { if ((uintptr_t)futex_mem != addr) {
puts("mem error 2"); puts("mem error 2");
exit(1); exit(1);
@@ -88,9 +84,9 @@ uint64_t __jasmin_syscall_open__(uint8_t* x, uint64_t xlen)
// return _x; // return _x;
// } // }
uint8_t* __jasmin_syscall_read__(uint8_t* _x, uint64_t xlen, uint64_t fd) uint8_t *__jasmin_syscall_read__(uint8_t *_x, uint64_t xlen, uint64_t fd) {
{ printf("Waiting...\n");
uint32_t* addr = (uint32_t*)(uintptr_t)fd; uint32_t *addr = (uint32_t *)(uintptr_t)fd;
long ret = syscall(SYS_futex, addr, FUTEX_WAIT, 0x1, NULL, NULL, 0); long ret = syscall(SYS_futex, addr, FUTEX_WAIT, 0x1, NULL, NULL, 0);
if (ret == -1) { if (ret == -1) {
printf("Agent futex error: %d\n", errno); printf("Agent futex error: %d\n", errno);
@@ -100,9 +96,8 @@ uint8_t* __jasmin_syscall_read__(uint8_t* _x, uint64_t xlen, uint64_t fd)
return _x; return _x;
} }
uint8_t* __jasmin_syscall_write__(uint8_t* _x, uint64_t xlen, uint64_t fd) uint8_t *__jasmin_syscall_write__(uint8_t *_x, uint64_t xlen, uint64_t fd) {
{ uint32_t *addr = (uint32_t *)(uintptr_t)fd;
uint32_t* addr = (uint32_t*)(uintptr_t)fd;
*addr = 1; *addr = 1;
syscall(SYS_futex, addr, FUTEX_WAKE, 1, NULL, NULL, 0); syscall(SYS_futex, addr, FUTEX_WAKE, 1, NULL, NULL, 0);
@@ -133,11 +128,12 @@ uint8_t* __jasmin_syscall_write__(uint8_t* _x, uint64_t xlen, uint64_t fd)
#include <stdlib.h> #include <stdlib.h>
#if !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) #if !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
__MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
#error "macOS version not supported (>= 10.12)" #error "macOS version not supported (>= 10.12)"
#endif #endif
uint8_t* __jasmin_syscall_randombytes__(uint8_t* x, uint64_t xlen){ uint8_t *__jasmin_syscall_randombytes__(uint8_t *x, uint64_t xlen) {
arc4random_buf(x, xlen); arc4random_buf(x, xlen);
return x; return x;
} }