begin working on relf component

This commit is contained in:
mykola2312 2024-08-24 14:32:50 +03:00
parent a39999e134
commit b2015a0d8a
9 changed files with 85 additions and 2 deletions

View file

@ -28,7 +28,7 @@ export MAKE
export PYTHON export PYTHON
# order matters here, build libraries first! # 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 .PHONY: $(TARGETS) debug clean

View file

@ -15,3 +15,7 @@ Hijacks runtime process in order to inject shared objects.
### rtdisasm ### 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. 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.

26
src/relf/Makefile Normal file
View file

@ -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)/*

1
src/relf/relf.c Normal file
View file

@ -0,0 +1 @@
#include "relf/relf.h"

4
src/relf/relf.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef __RELF_H
#define __RELF_H
#endif

31
src/relf_test/Makefile Normal file
View file

@ -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)/*

View file

@ -0,0 +1,9 @@
#include <stdio.h>
volatile int dummy_symbol1;
volatile int dummy_symbol2;
void dummy_function1()
{
printf("hello from dummy_function1\n");
}

View file

@ -0,0 +1,8 @@
#include "relf/relf.h"
#include <stdio.h>
int main()
{
printf("relf_test\n");
return 0;
}

View file

@ -2,7 +2,7 @@ NAME = rtdisasm
CFLAGS = -Wall -I$(INC_DIR) CFLAGS = -Wall -I$(INC_DIR)
ASFLAGS = ASFLAGS =
LDFLAGS = -z noexecstack -lcap LDFLAGS = -z noexecstack
SRC = rtdisasm.c SRC = rtdisasm.c
OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC)))) OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.s,%.o,$(patsubst %.c,%.o,$(SRC))))