Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elfdump tool for disassembly of ELF object file .text sections #13

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@

# Executables
*.exe
*.out
/sm64compress
/n64cksum
/mipsdisasm
/sm64extend
/f3d
/f3d2obj
/sm64geo
/n64graphics
/mio0
/n64split
/sm64walk
/elfdump

# Makefile dependencies
*.d
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GRAPHICS_TARGET := n64graphics
MIO0_TARGET := mio0
SPLIT_TARGET := n64split
WALK_TARGET := sm64walk
ELFDUMP_TARGET := elfdump

LIB_SRC_FILES := libmio0.c \
libsm64.c \
Expand All @@ -25,6 +26,10 @@ COMPRESS_SRC_FILES := sm64compress.c
DISASM_SRC_FILES := mipsdisasm.c \
utils.c

ELFDUMP_SRC_FILES := mipsdisasm.c \
utils.c \
elfdump.c

EXTEND_SRC_FILES := sm64extend.c

F3D_SRC_FILES := f3d.c \
Expand Down Expand Up @@ -92,7 +97,7 @@ default: all

all: $(EXTEND_TARGET) $(COMPRESS_TARGET) $(MIO0_TARGET) $(CKSUM_TARGET) \
$(SPLIT_TARGET) $(F3D_TARGET) $(F3D2OBJ_TARGET) $(GRAPHICS_TARGET) \
$(DISASM_TARGET) $(GEO_TARGET) $(WALK_TARGET)
$(DISASM_TARGET) $(GEO_TARGET) $(WALK_TARGET) $(ELFDUMP_TARGET)

$(OBJ_DIR)/%.o: %.c
@[ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR)
Expand Down Expand Up @@ -135,6 +140,9 @@ $(SPLIT_TARGET): $(SPLIT_OBJ_FILES)
$(WALK_TARGET): sm64walk.c $(SM64_LIB)
$(CC) $(CFLAGS) -o $@ $^

$(ELFDUMP_TARGET): $(ELFDUMP_SRC_FILES)
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ -lcapstone

rawmips: rawmips.c utils.c
$(CC) $(CFLAGS) -o $@ $^ -lcapstone

Expand All @@ -151,6 +159,7 @@ clean:
rm -f $(GRAPHICS_TARGET) $(GRAPHICS_TARGET).exe
rm -f $(SPLIT_TARGET) $(SPLIT_TARGET).exe
rm -f $(WALK_TARGET) $(WALK_TARGET).exe
rm -f $(ELFDUMP_TARGET) $(ELFDUMP_TARGET).exe
-@[ -d $(OBJ_DIR) ] && rmdir --ignore-fail-on-non-empty $(OBJ_DIR)

.PHONY: all clean default
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ There are many other smaller tools included to help with SM64 hacking. They are
- n64cksum: standalone N64 checksum generator. can either do in place or output to a new file
- n64graphics: converts graphics data from PNG files into RGBA or IA N64 graphics data
- mipsdisasm: standalone recursive MIPS disassembler
- elfdump: disassembler for MIPS ELF object files
- sm64geo: standalone SM64 geometry layout decoder

## License
Expand Down
61 changes: 61 additions & 0 deletions elf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <stdint.h>

#define EI_DATA 5
#define EI_NIDENT 16
#define SHT_SYMTAB 2
#define SHT_REL 9
#define STN_UNDEF 0

#define ELF32_R_SYM(info) ((info) >> 8)
#define ELF32_R_TYPE(info) ((info) & 0xff)

#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6

typedef uint32_t Elf32_Addr;
typedef uint32_t Elf32_Off;

typedef struct {
uint8_t e_ident[EI_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} Elf32_Ehdr;

typedef struct {
uint32_t sh_name;
uint32_t sh_type;
uint32_t sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
uint32_t sh_size;
uint32_t sh_link;
uint32_t sh_info;
uint32_t sh_addralign;
uint32_t sh_entsize;
} Elf32_Shdr;

typedef struct {
uint32_t st_name;
Elf32_Addr st_value;
uint32_t st_size;
uint8_t st_info;
uint8_t st_other;
uint16_t st_shndx;
} Elf32_Sym;

typedef struct {
Elf32_Addr r_offset;
uint32_t r_info;
} Elf32_Rel;
Loading