update and add nm
This commit is contained in:
parent
ec9980e0f9
commit
4f0405def6
4
Makefile
4
Makefile
@ -2,7 +2,7 @@ DATA = $(word 1,$(wildcard ./data ../data))
|
|||||||
CFLAGS += -I$(DATA)
|
CFLAGS += -I$(DATA)
|
||||||
include $(DATA)/Makefile.common
|
include $(DATA)/Makefile.common
|
||||||
|
|
||||||
BINS := $(OUTDIR)/check_sanity $(OUTDIR)/make_kernel_patchfile $(OUTDIR)/apply_patchfile $(OUTDIR)/dump_range sandboxc.c
|
BINS := $(OUTDIR)/check_sanity $(OUTDIR)/make_kernel_patchfile $(OUTDIR)/apply_patchfile $(OUTDIR)/dump_range $(OUTDIR)/nm sandboxc.c
|
||||||
|
|
||||||
all: .data $(OUTDIR) $(BINS)
|
all: .data $(OUTDIR) $(BINS)
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ $(OUTDIR)/make_kernel_patchfile: $(OUTDIR)/make_kernel_patchfile.o $(OUTDIR)/san
|
|||||||
$(GCC) -o $@ $^
|
$(GCC) -o $@ $^
|
||||||
$(OUTDIR)/dump_range: $(OUTDIR)/dump_range.o $(DATA)/$(OUTDIR)/libdata.a
|
$(OUTDIR)/dump_range: $(OUTDIR)/dump_range.o $(DATA)/$(OUTDIR)/libdata.a
|
||||||
$(GCC) -o $@ $^
|
$(GCC) -o $@ $^
|
||||||
$(OUTDIR)/fakesym: $(OUTDIR)/fakesym.o $(DATA)/$(OUTDIR)/libdata.a
|
$(OUTDIR)/nm: $(OUTDIR)/nm.o $(DATA)/$(OUTDIR)/libdata.a
|
||||||
$(GCC) -o $@ $^
|
$(GCC) -o $@ $^
|
||||||
|
|
||||||
clean: .clean
|
clean: .clean
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include <data/common.h>
|
#include <data/mach-o/binary.h>
|
||||||
#include <data/binary.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -8,7 +7,7 @@ int main(int argc, char **argv) {
|
|||||||
b_init(&binary);
|
b_init(&binary);
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
prange_t kernel = load_file(argv[1], true, &mode);
|
prange_t kernel = load_file(argv[1], true, &mode);
|
||||||
b_prange_load_macho(&binary, kernel, argv[1]);
|
b_prange_load_macho(&binary, kernel, 0, argv[1]);
|
||||||
|
|
||||||
int patchfd = open(argv[2], O_RDONLY);
|
int patchfd = open(argv[2], O_RDONLY);
|
||||||
if(patchfd == -1) {
|
if(patchfd == -1) {
|
||||||
@ -55,7 +54,7 @@ int main(int argc, char **argv) {
|
|||||||
printf("%s (0x%x)\n", name, addr);
|
printf("%s (0x%x)\n", name, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((char *) kernel.start + range_to_off_range((range_t) {&binary, addr, size}).start, stuff, size);
|
memcpy((char *) kernel.start + range_to_off_range((range_t) {&binary, addr, size}, MUST_FIND).start, stuff, size);
|
||||||
|
|
||||||
skip:
|
skip:
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <data/common.h>
|
#include <data/mach-o/binary.h>
|
||||||
#include <data/binary.h>
|
#include <data/mach-o/headers/loader.h>
|
||||||
#include <data/loader.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -11,9 +10,9 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
struct binary binary;
|
struct binary binary;
|
||||||
b_init(&binary);
|
b_init(&binary);
|
||||||
b_load_macho(&binary, argv[1], false);
|
b_prange_load_macho(&binary, load_file(argv[1], false, NULL), 0, argv[1]);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
CMD_ITERATE(binary.mach_hdr, cmd) {
|
CMD_ITERATE(binary.mach->hdr, cmd) {
|
||||||
if(cmd->cmd == LC_SEGMENT) {
|
if(cmd->cmd == LC_SEGMENT) {
|
||||||
struct segment_command *seg = (void *) cmd;
|
struct segment_command *seg = (void *) cmd;
|
||||||
uint32_t start = seg->vmaddr;
|
uint32_t start = seg->vmaddr;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include <data/common.h>
|
#include <data/mach-o/binary.h>
|
||||||
#include <data/binary.h>
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if(argc != 4) {
|
if(argc != 4) {
|
||||||
@ -8,8 +7,8 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
struct binary binary;
|
struct binary binary;
|
||||||
b_init(&binary);
|
b_init(&binary);
|
||||||
b_load_macho(&binary, argv[1], false);
|
b_load_macho(&binary, argv[1]);
|
||||||
prange_t pr = rangeconv((range_t) {&binary, parse_hex_uint32(argv[2]), parse_hex_uint32(argv[3])});
|
prange_t pr = rangeconv((range_t) {&binary, parse_hex_uint32(argv[2]), parse_hex_uint32(argv[3])}, MUST_FIND);
|
||||||
write(1, pr.start, pr.size);
|
write(1, pr.start, pr.size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <data/common.h>
|
#include <data/common.h>
|
||||||
#include <data/find.h>
|
#include <data/find.h>
|
||||||
#include <data/binary.h>
|
#include <data/mach-o/binary.h>
|
||||||
#include <data/link.h>
|
#include <data/mach-o/link.h>
|
||||||
#include "lambda.h"
|
#include "lambda.h"
|
||||||
|
|
||||||
extern unsigned char sandbox_o[];
|
extern unsigned char sandbox_o[];
|
||||||
@ -118,7 +118,7 @@ void do_kernel(struct binary *binary, struct binary *sandbox) {
|
|||||||
die("? %s", name);
|
die("? %s", name);
|
||||||
})
|
})
|
||||||
b_relocate(sandbox, (void *) l.arg, (void *) l.func, 0);
|
b_relocate(sandbox, (void *) l.arg, (void *) l.func, 0);
|
||||||
prange_t sandbox_pr = rangeconv(b_nth_segment(sandbox, 0));
|
prange_t sandbox_pr = rangeconv_off(sandbox->segments[0].file_range, MUST_FIND);
|
||||||
patch_with_range("sb_evaluate hook",
|
patch_with_range("sb_evaluate hook",
|
||||||
scratch,
|
scratch,
|
||||||
sandbox_pr);
|
sandbox_pr);
|
||||||
@ -139,8 +139,8 @@ int main(int argc, char **argv) {
|
|||||||
struct binary kernel, sandbox;
|
struct binary kernel, sandbox;
|
||||||
b_init(&kernel);
|
b_init(&kernel);
|
||||||
b_init(&sandbox);
|
b_init(&sandbox);
|
||||||
b_load_macho(&kernel, argv[1], false);
|
b_load_macho(&kernel, argv[1]);
|
||||||
b_prange_load_macho(&sandbox, (prange_t) {&sandbox_o, sandbox_o_len}, "sandbox.o");
|
b_prange_load_macho(&sandbox, (prange_t) {&sandbox_o, sandbox_o_len}, 0, "sandbox.o");
|
||||||
|
|
||||||
patchfd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
patchfd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
if(patchfd == -1) {
|
if(patchfd == -1) {
|
||||||
|
39
nm.c
Normal file
39
nm.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <data/mach-o/binary.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static void usage() {
|
||||||
|
fprintf(stderr, "Usage: nm [-exp] binary [symbol]\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int flags = 0;
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while((c = getopt(argc, argv, "ixp")) != -1) switch(c) {
|
||||||
|
case 'i': flags |= IMPORTED_SYM; break;
|
||||||
|
case 'x': flags |= TO_EXECUTE; break;
|
||||||
|
case 'p': flags |= PRIVATE_SYM; break;
|
||||||
|
default: usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!argv[optind] || (argv[optind + 1] && argv[optind + 2])) usage();
|
||||||
|
|
||||||
|
struct binary binary;
|
||||||
|
b_init(&binary);
|
||||||
|
b_load_macho(&binary, argv[optind]);
|
||||||
|
|
||||||
|
if(argv[optind + 1]) {
|
||||||
|
printf("%8x\n", b_sym(&binary, argv[optind + 1], flags));
|
||||||
|
} else {
|
||||||
|
struct data_sym *syms;
|
||||||
|
uint32_t nsyms;
|
||||||
|
b_copy_syms(&binary, &syms, &nsyms, flags);
|
||||||
|
while(nsyms--) {
|
||||||
|
printf("%8x %s\n", syms->address, syms->name);
|
||||||
|
syms++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user