From 571e200ecf24cbe9c0cccad3405600d845db951f Mon Sep 17 00:00:00 2001 From: comex Date: Mon, 28 Mar 2011 23:09:38 -0400 Subject: [PATCH] have a makefile --- Makefile | 9 +++++++++ apply_patchfile.c | 1 + check_sanity.c | 34 ++++++++++++++++++++++++++++++++++ make_kernel_patchfile.c | 1 + 4 files changed, 45 insertions(+) create mode 100644 Makefile create mode 100644 check_sanity.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7e6ad3e --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +DATA = $(word 1,$(wildcard ./data ../data)) +include $(DATA)/Makefile.common +OBJS = check_sanity make_kernel_patchfile apply_patchfile +all: .settings $(OBJS) +%: %.c + make -C $(DATA) + $(GCC) $(CFLAGS) -o $@ $< -I$(DATA) $(DATA)/libdata.a +clean: + rm -f $(OBJS) diff --git a/apply_patchfile.c b/apply_patchfile.c index b099673..754e685 100644 --- a/apply_patchfile.c +++ b/apply_patchfile.c @@ -3,6 +3,7 @@ #include int main(int argc, char **argv) { + (void) argc; struct binary binary; b_init(&binary); mode_t mode; diff --git a/check_sanity.c b/check_sanity.c new file mode 100644 index 0000000..df40817 --- /dev/null +++ b/check_sanity.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + if(argc != 2) { + fprintf(stderr, "Usage: check_sanity macho\n"); + exit(1); + } + struct binary binary; + b_init(&binary); + b_load_macho(&binary, argv[1], false); + int result = 0; + CMD_ITERATE(binary.mach_hdr, cmd) { + if(cmd->cmd == LC_SEGMENT) { + struct segment_command *seg = (void *) cmd; + uint32_t start = seg->vmaddr; + uint32_t end = seg->vmaddr + seg->vmsize; + + struct section *sections = (void *) (seg + 1); + for(uint32_t i = 0; i < seg->nsects; i++) { + struct section *sect = §ions[i]; + if(!(start <= sect->addr && sect->addr <= end && \ + start <= (sect->addr + sect->size) && (sect->addr + sect->size) <= end)) { + printf("insane: segment %.16s section %d is out of bounds (vmaddr:%x vmsize:%x addr:%x size:%x)\n", seg->segname, i, seg->vmaddr, seg->vmsize, sect->addr, sect->size); + result = 1; + } + } + } + } + return result; +} diff --git a/make_kernel_patchfile.c b/make_kernel_patchfile.c index 35a960b..3b447bd 100644 --- a/make_kernel_patchfile.c +++ b/make_kernel_patchfile.c @@ -174,6 +174,7 @@ void do_kernel(struct binary *binary, struct binary *sandbox) { int main(int argc, char **argv) { + (void) argc; struct binary kernel, sandbox; b_init(&kernel); b_init(&sandbox);