diff --git a/Makefile b/Makefile index 5a1dc07..be76504 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ CFLAGS := -g -std=c11 -Os \ -fomit-frame-pointer -fdata-sections -ffunction-sections \ $(ARCH) -nostartfiles -CFLAGS += $(INCLUDE) -D_GNU_SOURCE -DCAN_HAZ_IRQ -fno-builtin-printf -Wno-nonnull -Werror=implicit +CFLAGS += $(INCLUDE) -D_GNU_SOURCE -fno-builtin-printf -Wno-nonnull -Werror=implicit CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions diff --git a/Makefile.mlckey b/Makefile.mlckey new file mode 100644 index 0000000..9a87d9a --- /dev/null +++ b/Makefile.mlckey @@ -0,0 +1,135 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +export TOPDIR ?= $(CURDIR) +export MAKEFILE_ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +include $(MAKEFILE_ROOT_DIR)/elf_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# SPECS is the directory containing the important build and link files +#--------------------------------------------------------------------------------- +export TARGET := wafel_sd_usb_mlckey +export BUILD ?= debug + +R_SOURCES := +SOURCES := source source/ios source/services source/wupserver source/latte + +R_INCLUDES := +INCLUDES := source + +DATA := + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv5te -mcpu=arm926ej-s -mthumb-interwork -mbig-endian -mfloat-abi=soft -fPIE -fno-jump-tables -export-dynamic -s -isystem $(STROOPWAFEL_ROOT)/wafel_core/include + +CFLAGS := -g -std=c11 -Os \ + -fomit-frame-pointer -fdata-sections -ffunction-sections \ + $(ARCH) -nostartfiles + +CFLAGS += $(INCLUDE) -D_GNU_SOURCE -fno-builtin-printf -Wno-nonnull -Werror=implicit -DUSE_MLC_KEY + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -g --specs=$(MAKEFILE_ROOT_DIR)/ccd00.specs $(ARCH) -Wl,--gc-sections,-Map,$(TARGET).map \ + -L$(DEVKITARM)/lib/gcc/arm-none-eabi/$(GCC_VERSION)/be -L$(DEVKITARM)/arm-none-eabi/lib/be \ + -z max-page-size=4096 -nostartfiles + +LIBS := -lnosys + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export ROOTDIR := $(CURDIR) +export OUTPUT := $(CURDIR)/$(TARGET) + +SOURCES := $(SOURCES) $(foreach dir,$(R_SOURCES), $(dir) $(filter %/, $(wildcard $(dir)/*/))) +INCLUDES := $(INCLUDES) $(foreach dir,$(R_INCLUDES), $(dir) $(filter %/, $(wildcard $(dir)/*/))) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.S=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + @mv $(OUTPUT).elf $(OUTPUT).ipx + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT)-strip.elf $(OUTPUT).ipx + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +#$(OUTPUT)-strip.elf: $(OUTPUT).elf +# $(STRIP) $< -o $@ + +$(OUTPUT).elf: $(OFILES) + + +-include $(DEPENDS) + + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/source/main.c b/source/main.c index 484dfd5..053b9b8 100644 --- a/source/main.c +++ b/source/main.c @@ -18,6 +18,10 @@ const char* MODULE_NAME = "SDUSB"; #define SECTOR_SIZE 512 #define LOCAL_HEAP_ID 0xCAFE #define DEVTYPE_USB 17 +// hope that 0x11 stays constant for mlc +#define MLC_CRYPTO_HANDLE 0x11 +// tells crypto to not do crypto (depends on stroopwafel patch) +#define NO_CRYPTO_HANDLE 0xDEADBEEF #define SERVER_HANDLE_LEN 0xb5 #define SERVER_HANDLE_SZ (SERVER_HANDLE_LEN * sizeof(int)) @@ -179,11 +183,13 @@ void hook_register_sd(trampoline_state *state){ void crypto_hook(trampoline_state* state){ - // hope that 0x11 stays constant for mlc - if(active && state->r[5] == sdusb_size && state->r[0] != 0x11){ + if(active && state->r[5] == sdusb_size && state->r[0] != MLC_CRYPTO_HANDLE){ //debug_printf("SDUSB: cryptohook detected USB partition true lr: %p\n", state->lr); - // tells crypto to not do crypto (depends on stroopwafel patch) - state->r[0] = 0xDEADBEEF; +#ifdef USE_MLC_KEY + tate->r[0] = MLC_CRYPTO_HANDLE; +#else + state->r[0] = NO_CRYPTO_HANDLE; +#endif } //debug_printf("crypto_hook: r0: %p, r1: %p, r2: %p, r3: %p, r4: %p, r5: %p, r6: %p, r7: %p, r8: %p, r9: %p, r10: %p, r11: %p, r12: %p, lr: %p\n", // state->r[0],state->r[1],state->r[2],state->r[3],state->r[4],state->r[5],state->r[6],state->r[7],state->r[8],state->r[9],state->r[10],state->r[11], state->r[12], state->lr);