diff --git a/Makefile b/Makefile index b050888..2168203 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ export MAKE export PYTHON # order matters here, build libraries first! -TARGETS = rtdisasm rtdisasm_test dummy_target blackjack +TARGETS = rtdisasm rtdisasm_test relf relf_test dummy_target blackjack .PHONY: $(TARGETS) debug clean diff --git a/README.md b/README.md index c1463bb..05cb0bf 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,7 @@ Hijacks runtime process in order to inject shared objects. ### rtdisasm KISS robust runtime "disassembler". Used to analyze instructions encoded sizes and find desired instructions for trampolines. No need to bloat it with full-blown disassembler logic like other projects do - one big lookup table is enough for such purposes. + +### relf + +Instrument to parse and analyze ELF shared objects. Primary goal is to find symbols and their offsets, so blackjack could link them in runtime. diff --git a/src/relf/Makefile b/src/relf/Makefile new file mode 100644 index 0000000..a0ecdf2 --- /dev/null +++ b/src/relf/Makefile @@ -0,0 +1,26 @@ +NAME = relf + +CFLAGS = -Wall -I$(INC_DIR) +ASFLAGS = +LDFLAGS = -z noexecstack + +SRC = relf.c +OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC)))) +DEPS = relf.h + +$(OBJ_DIR)/%.o: %.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c -o $@ $< + +.PHONY: all clean debug + +all: $(OBJ) $(DEPS) + $(AR) -crs $(BIN_DIR)/lib$(NAME).a $(OBJ) + +debug: CFLAGS += -DDEBUG -g +debug: LDFLAGS += -g +debug: ASFLAGS += -g +debug: all + +clean: + rm -f $(OBJ_DIR)/* \ No newline at end of file diff --git a/src/relf/relf.c b/src/relf/relf.c new file mode 100644 index 0000000..ff3427f --- /dev/null +++ b/src/relf/relf.c @@ -0,0 +1 @@ +#include "relf/relf.h" diff --git a/src/relf/relf.h b/src/relf/relf.h new file mode 100644 index 0000000..c5643ba --- /dev/null +++ b/src/relf/relf.h @@ -0,0 +1,4 @@ +#ifndef __RELF_H +#define __RELF_H + +#endif \ No newline at end of file diff --git a/src/relf_test/Makefile b/src/relf_test/Makefile new file mode 100644 index 0000000..439cd52 --- /dev/null +++ b/src/relf_test/Makefile @@ -0,0 +1,31 @@ +NAME = relf_test + +CFLAGS = -Wall -I$(INC_DIR) +ASFLAGS = +LDFLAGS = -z noexecstack + +SRC = relf_test.c relf_dummy.c +OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC)))) +DEPS = + +$(OBJ_DIR)/%.o: %.c + @mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c -o $@ $< + +$(OBJ_DIR)/%.o: %.s + @mkdir -p $(OBJ_DIR) + $(AS) $(ASFLAGS) -o $@ $< + +.PHONY: all clean debug + +all: $(OBJ) $(DEPS) + $(CC) $(LDFLAGS) -shared -o $(BIN_DIR)/relf_dummy.so obj/relf_dummy.o + $(CC) $(LDFLAGS) -o $(BIN_DIR)/relf_test obj/relf_test.o $(LIB_DIR)/librelf.a + +debug: CFLAGS += -DDEBUG -g +debug: LDFLAGS += -g +debug: ASFLAGS += -g +debug: all + +clean: + rm -f $(OBJ_DIR)/* \ No newline at end of file diff --git a/src/relf_test/relf_dummy.c b/src/relf_test/relf_dummy.c new file mode 100644 index 0000000..9af724f --- /dev/null +++ b/src/relf_test/relf_dummy.c @@ -0,0 +1,9 @@ +#include + +volatile int dummy_symbol1; +volatile int dummy_symbol2; + +void dummy_function1() +{ + printf("hello from dummy_function1\n"); +} diff --git a/src/relf_test/relf_test.c b/src/relf_test/relf_test.c new file mode 100644 index 0000000..16af8bb --- /dev/null +++ b/src/relf_test/relf_test.c @@ -0,0 +1,8 @@ +#include "relf/relf.h" +#include + +int main() +{ + printf("relf_test\n"); + return 0; +} diff --git a/src/rtdisasm/Makefile b/src/rtdisasm/Makefile index 510c5b8..95c6f48 100644 --- a/src/rtdisasm/Makefile +++ b/src/rtdisasm/Makefile @@ -2,7 +2,7 @@ NAME = rtdisasm CFLAGS = -Wall -I$(INC_DIR) ASFLAGS = -LDFLAGS = -z noexecstack -lcap +LDFLAGS = -z noexecstack SRC = rtdisasm.c OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC))))