Skip to content
Snippets Groups Projects
Commit 3ade181f authored by whh8b's avatar whh8b
Browse files

Initial checkin of dynamic hook callbacks.

parent fe2be2f0
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ canaries/debug_canary_callbacks.c -text
/configure_for_rss -text
example/Makefile.in -text
example/callback.c -text
hookdynamic/Makefile.in -text
hookdynamic/hook_dynamic_callbacks.c -text
inferfn/Makefile.in -text
inferfn/infer.c -text
inferfn/infer.h -text
......
CC=@CC@
CFLAGS=@CFLAGS@
LIB=@LIB@
AR=@AR@
AS=@AS@
ASFLAGS=@ASFLAGS@
OBJS=hook_dynamic_callbacks.o
.SUFFIXES: .o .s .c
.c.o:
$(CC) $(CFLAGS) $(INCLUDE) -D__$(ARCH) -c $<
.s.o:
$(AS) $(ASFLAGS) $<
all: $(OBJS)
$(AR) -r $(LIB) $(OBJS)
clean:
rm *.o
/*
* Copyright (c) 2014 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
#ifdef DEBUG
#include "malloc.h"
#include "itox.h"
#include "strlen.h"
#include "null.h"
#define DEBUG_ADD
#else
typedef unsigned uintptr_t;
#define NULL 0L
#endif
#ifdef DEBUG
#define print_str_debug print_str
#define print_int_debug print_int
#else
#define print_str_debug(a)
#define print_int_debug(a)
#define assert(a)
#endif
#ifdef DEBUG
#define write_fd 2
void print_str(char *s)
{
write(write_fd,s,strlen(s));
}
void print_int(int x)
{
char buf[100];
itox(x,buf);
write(write_fd,buf,strlen(buf));
}
#endif
unsigned long long read_random64(void) {
unsigned long long random_value = -1;
int fd = -1;
fd = open("/dev/urandom", 0x00);
if (fd != -1) {
read(fd, (void*)&random_value, sizeof(unsigned long long));
close(fd);
}
return random_value;
}
unsigned long read_random32(void) {
unsigned long random_value = -1;
int fd = -1;
fd = open("/dev/urandom", 0x00);
if (fd != -1) {
read(fd, (void*)&random_value, sizeof(unsigned long));
close(fd);
}
return random_value;
}
void set_canary64(unsigned long long new_canary) {
asm volatile ("mov %0, %%fs:0x28\n"
:
: "r" (new_canary)
:);
}
void set_canary32(unsigned long new_canary) {
asm volatile ("mov %0, %%fs:0x28\n"
:
: "r" (new_canary)
:);
}
/*
*/
#define FORK 57
void zipr_hook_dynamic_callback(unsigned int id, unsigned int rax)
{
#ifdef DEBUG
print_str_debug("In zipr_hook_dynamic_callback, id=");
print_int_debug(id);
print_str_debug(", rax=");
print_int_debug(rax);
print_str_debug("\n");
#endif
if (id == FORK && rax!=0) {
/*
* Child!
*/
set_canary32(read_random32());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment