From b2015a0d8ae68d39126a431c61bd70d84e941efd Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:32:50 +0300 Subject: [PATCH] begin working on relf component --- Makefile | 2 +- README.md | 4 ++++ src/relf/Makefile | 26 ++++++++++++++++++++++++++ src/relf/relf.c | 1 + src/relf/relf.h | 4 ++++ src/relf_test/Makefile | 31 +++++++++++++++++++++++++++++++ src/relf_test/relf_dummy.c | 9 +++++++++ src/relf_test/relf_test.c | 8 ++++++++ src/rtdisasm/Makefile | 2 +- 9 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/relf/Makefile create mode 100644 src/relf/relf.c create mode 100644 src/relf/relf.h create mode 100644 src/relf_test/Makefile create mode 100644 src/relf_test/relf_dummy.c create mode 100644 src/relf_test/relf_test.c 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))))