* Replace all instances of 'service' with 'svc' or 'svc call' to get my terminology straight
* Make logging in loader toggleable, add boot logging, and add an option to the menu. Hopefully this will cut down on improper issue reporting.
-fomit-frame-pointer -ffunction-sections -fdata-sections -fshort-wchar \
$(ARCH)
-CFLAGS += $(INCLUDE) -DARM11 -D_3DS
+CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DLOADER=1
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu99
+++ /dev/null
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-__attribute__((unused)) static unsigned int config_version = 1;
-
-#define CONFIG_MAGIC "OVAN"
-
-// Structure of config file
-struct config_file
-{
- char magic[4]; // "OVAN" for shits and giggles again.
-
- uint32_t config_ver; // Config file version.
-
- uint8_t options[256]; // Options in the menu - deliberately large to avoid
- // config version bumps.
-
- uint64_t patch_ids[256]; // What patches are enabled by UUID. 256 is an
- // arbitrary limit - contact me if you hit it.
-} __attribute__((packed));
-
-#define OPTION_LOADER_CPU_L2 11 // Enable L2 cache.
-#define OPTION_LOADER_CPU_800MHZ 12 // Enable 800Mhz mode.
-#define OPTION_LOADER_LANGEMU 13 // Enable 800Mhz mode.
-
-#endif
// 'Tis not ready for the world at large yet.
// I don't want to delete it since I'm working on it though,
// so it's temporarliy #if'd 0.
-#define LOADER 1
-
#include <3ds.h>
#include "patcher.h"
#include "fsldr.h"
#define PATH_MAX 255
#define _MAX_LFN 255
#endif
-#include "config.h"
+#include "../../../source/config.h"
#include "../../../source/patch_format.h"
// Because I want to avoid malloc.
u32 text_grow, data_grow, ro_grow;
u16 progver;
- openLogger();
+ load_config(); // First order of business - we need the config file.
+ openLogger(); // Open logs if enabled in config.
// make sure the cached info corrosponds to the current prog_handle
if (g_cached_prog_handle != prog_handle) {
logu64(progid);
logstr(" validated params\n");
- load_config(); // First order of business - we need the config file.
-
// Check and set the CPU mode. Possible values: 0 - Keep o3ds speed, 1 -
// n3ds speed, -1 force o3ds
// This is A-OK because the CPU speed parameter isn't passed through to any
#define PATH_MAX 255
#define _MAX_LFN 255
#endif
-#include "config.h"
+#include "../../../source/config.h"
#include "../../../source/patch_format.h"
Handle log_file_hdl;
int logger_is_initd = 0;
+extern struct config_file config;
+
void
openLogger()
{
+ if (config.options[OPTION_SAVE_LOGS] == 0) {
+ logger_is_initd = -1; // Setting -1 effectively disables logs.
+ }
Result r;
if (logger_is_initd)
#define PATH_MAX 255
#define _MAX_LFN 255
#endif
-#include "config.h"
+#include "../../../source/config.h"
#include "../../../source/patch_format.h"
int
#define PATH_MAX 255
#define _MAX_LFN 255
#endif
-#include "config.h"
+#include "../../../source/config.h"
int
fileOpen(Handle *file, FS_ArchiveID id, const char *path, int flags)
return FSLDR_OpenFileDirectly(file, id, apath, ppath, flags, 0);
}
-static struct config_file config;
+struct config_file config;
static int failed_load_config = 1;
void
f_mkdir(PATH_PATCHES);
f_mkdir(PATH_FIRMWARES);
f_mkdir(PATH_MODULES);
- f_mkdir(PATH_SERVICES);
+ f_mkdir(PATH_SVC);
f_mkdir(PATH_KEYS);
f_mkdir(PATH_EXEFS);
f_mkdir(PATH_TEMP);
#ifndef __CONFIG_H
#define __CONFIG_H
-_UNUSED static unsigned int config_version = 1;
+#define config_version 1
#define CONFIG_MAGIC "OVAN"
// Use builtin loader module replacer.
#define OPTION_LOADER 2
-// Inject services (including backdoor for 11)
-#define OPTION_SERVICES 3
+// Inject svc calls (including backdoor for 11)
+#define OPTION_SVCS 3
// Use builtin ARM9 thread injector.
#define OPTION_ARM9THREAD 4
// Enable language emulation.
#define OPTION_LOADER_LANGEMU 13
-// Force replacement of services. Normally you don't want this.
+// Force replacement of non-null svcs. Normally you don't want this.
#define OPTION_REPLACE_ALLOCATED_SVC 14
// Ignore patch UUID dependencies. Not recommended.
// change and causes caches to be regenerated.
#define OPTION_RECONFIGURED 255
-// TODO - Every option beyond here is a patch now, so once I get listing
-// implemented, these shall go.
-
-#define OPTION_SIGPATCH 0 // Use builtin signature patch.
-#define OPTION_FIRMPROT 1 // Protect firmware from writes.
-
-#define OPTION_AADOWNGRADE 16 // Anti-anti-downgrade.
-#define OPTION_MEMEXEC 17 // Prevent MPU from disabling execute permissions.
-#define OPTION_UNITINFO 18 // Dev UNITINFO. Note that this is overkill.
-
//#define HEADER_COLOR 12 // Color of header text.
//#define BG_COLOR 13 // Color of background.
//#define TEXT_COLOR 14 // Color of most text.
//#define ARROW_COLOR 15 // Color of Arrow.
+#ifndef LOADER
void load_config();
void save_config();
-
+#endif
/*
[CORBENIK]
version=1
fprintf(BOTTOM_SCREEN, "Updated keyX keyslots\n");
}
- fumount(); // Unmount SD. No longer needed.
- fprintf(BOTTOM_SCREEN, "SD Unmounted.\n");
-
for (firm_section_h *section = firm_loc->section; section < firm_loc->section + 4 && section->address != 0; section++) {
memcpy((void *)section->address, (void *)firm_loc + section->offset, section->size);
}
wait();
+ clear_disp(BOTTOM_SCREEN);
+
+ fumount(); // Unmount SD. No longer needed.
+
// No fprintf will work from here on out.
*a11_entry = (uint32_t)arm11_preboot_halt;
// Patches.
{ 0, "\x1b[32;40mOptions\x1b[0m", "", not_option, 0, 0 },
- { OPTION_LOADER, "System Modules", "Replaces system modules (including loader)", boolean_val, 0, 0 },
+ { OPTION_LOADER, "Loader Replacement", "Replaces loader with one capable of the below and also applying bytecode patches.", boolean_val, 0, 0 },
{ OPTION_LOADER_CPU_L2, " CPU - L2 cache", "Forces the system to use the L2 cache. Ignored if not a N3DS.", boolean_val, 0, 0 },
{ OPTION_LOADER_CPU_800MHZ, " CPU - 800Mhz", "Forces the system to run in 800Mhz mode. Ignored if not a N3DS.", boolean_val, 0, 0 },
{ OPTION_LOADER_LANGEMU, " Language Emulation", "Reads language emulation configuration and imitates the region/language.", boolean_val, 0, 0 },
{ 0, "", "", not_option, 0, 0 },
- { OPTION_SERVICES, "Service Replacement", "Replaces ARM11 services, including svcBackdoor. With 11.0 NATIVE_FIRM, you need this.", boolean_val, 0, 0 },
+ { OPTION_SVCS, "SVC Replacement", "Replaces ARM11 svc calls, including svcBackdoor. With 11.0 NATIVE_FIRM, you probably want this.", boolean_val, 0, 0 },
{ 0, "", "", not_option, 0, 0 },
// Patches.
{ 0, "\x1b[32;40mDeveloper Options\x1b[0m", "", not_option, 0, 0 },
- { OPTION_REPLACE_ALLOCATED_SVC, "Force service replace", "Replace ARM11 services even if they exist. Don't use unless you know what you're doing.",
+ { OPTION_REPLACE_ALLOCATED_SVC, "Force svc replace", "Replace ARM11 svc calls even if they exist. Don't use this unless you know what you're doing.",
boolean_val, 0, 0 },
- { OPTION_TRACE, "Debug Pauses", "After each important step, [WAIT] will be shown and you'll need to press a key. Debug.", boolean_val, 0, 0 },
+ { OPTION_TRACE, "Step Through", "After each important step, [WAIT] will be shown and you'll need to press a key. Debug.", boolean_val, 0, 0 },
{ OPTION_OVERLY_VERBOSE, "Verbose", "Output more debug information than the average user needs.", boolean_val, 0, 0 },
+ { OPTION_SAVE_LOGS, "Logging", "Save logs to the corbenik folder. Slows operation a bit.", boolean_val, 0, 0 },
+
+ { OPTION_RECONFIGURED, "Reconfigured (DO NOT UNCHECK)", "If patches were reconfigured, this will be set. Do not untick this if ticked.", boolean_val, 0,
+ 0 },
// { OPTION_ARM9THREAD, "ARM9 Thread", boolean_val, 0, 0 },
// { IGNORE_PATCH_DEPS, "Ignore dependencies", boolean_val, 0, 0 },
fprintf(stderr, "Svc: table at %x\n", (uint32_t)svcTable);
- char str[] = PATH_SERVICES "/00.bin";
+ char str[] = PATH_SVC "/00.bin";
char *at = str + (strlen(str) - 6);
// FIXME - This is really slow. Some way to optimize it?
for (uint32_t i = 0; i <= 0xf; i++) {
#define PATH_PATCHES PATH_CFW "/patch" // Patch binary folder.
#define PATH_FIRMWARES PATH_CFW "/firmware" // Firmware folder.
#define PATH_MODULES PATH_CFW "/module" // Sysmodule location
-#define PATH_SERVICES PATH_CFW "/svc" // Svc code location.
+#define PATH_SVC PATH_CFW "/svc" // Svc code location.
#define PATH_TEMP PATH_CFW "/cache" // Files that are transient and used to speed operation
#define PATH_LOADER_CACHE PATH_TEMP "/loader" // Cached patch bytecode for loader.
// Replace loader?
if (config.options[OPTION_LOADER]) {
if (patch_modules()) {
- abort("Fatal. Service patch has failed.");
+ abort("Fatal. Loader inject has failed.");
}
// This requires OPTION_SIGPATCH.
wait();
}
// Inject services?
- if (config.options[OPTION_SERVICES]) {
+ if (config.options[OPTION_SVCS]) {
if (patch_services()) {
- abort("Fatal. Service patch has failed.");
+ abort("Fatal. Svc inject has failed.");
}
wait();
}
#include "../fatfs/ff.h"
#include "fs.h"
#include "unused.h"
+#include "../config.h"
+#include "../patch_format.h"
static unsigned int top_cursor_x = 0, top_cursor_y = 0;
static unsigned int bottom_cursor_x = 0, bottom_cursor_y = 0;
-#ifdef BUFFER
-static char text_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
static char text_buffer_bottom[TEXT_BOTTOM_HEIGHT * TEXT_BOTTOM_WIDTH + 1];
+#ifdef BUFFER
+static char text_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
static char color_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
static char color_buffer_bottom[TEXT_BOTTOM_HEIGHT * TEXT_BOTTOM_WIDTH + 1];
#endif
void
clear_disp(uint8_t *screen)
{
+ // There's a reason the logging code is here rather than putc:
+ // writing a batch is faster.
+ if (screen == BOTTOM_SCREEN && config.options[OPTION_SAVE_LOGS]) {
+ FILE *f = fopen(PATH_CFW "/boot.log", "w");
+ fseek(f, 0, SEEK_END);
+ for (int i = 0; i < TEXT_BOTTOM_HEIGHT; i++) {
+ char *text = text_buffer_bottom + (TEXT_BOTTOM_WIDTH * i);
+ if (text[0] == 0)
+ break;
+ fwrite(text, 1, strnlen(text, TEXT_BOTTOM_WIDTH), f);
+ fwrite("\n", 1, 1, f);
+ }
+ fclose(f);
+ memset(text_buffer_bottom, 0, TEXT_BOTTOM_WIDTH * TEXT_BOTTOM_HEIGHT);
+ }
+
if (screen == TOP_SCREEN)
screen = framebuffers->top_left;
else if (screen == BOTTOM_SCREEN)
clear_disp(buf);
cursor_x[0] = 0;
cursor_y[0] = 0;
+
/* uint32_t col = SCREEN_TOP_HEIGHT * SCREEN_DEPTH;
uint32_t one_c = 8 * SCREEN_DEPTH;
for (unsigned int x = 0; x < width * 8; x++) {
}
#else
+ if (buf == BOTTOM_SCREEN)
+ text_buffer_bottom[cursor_y[0] * width + cursor_x[0]] = c;
draw_character(screen, c, cursor_x[0], cursor_y[0], colors[(*color >> 4) & 0xF], colors[*color & 0xF]);
#endif
void set_cursor(void *channel, unsigned int x, unsigned int y);
+void clear_disp(uint8_t *screen);
+
// Like printf. Supports the following format specifiers:
// %s - char*
// %c - char