REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count HEAD)
-AM_CFLAGS= -std=gnu11 -Os -g -fomit-frame-pointer -ffast-math \
+AM_CFLAGS= -std=gnu11 -Os -g -ffast-math \
-Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \
-Wmissing-include-dirs -Wredundant-decls \
-Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wswitch-default \
- -Wundef -Wno-unused $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \
+ -Wundef -Wno-unused -Werror -Wno-error=cast-align -Wno-error=strict-overflow -Wno-error=pedantic \
+ $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \
-fno-builtin -std=gnu11 -DREVISION=\"$(REVISION)\" \
-DFW_NAME=\"corbenik\" $(PATHARGS)
-AM_LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -Wl,-z,defs -lgcc \
- -L$(top_srcdir)/external/libctr9/src
+AM_LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -nodefaultlibs -Wl,-z,defs -lgcc \
+ -lc -L$(top_srcdir)/external/libctr9/src
OCFLAGS=--set-section-flags .bss=alloc,load,contents
#define PDC1_FRAMEBUFFER_SETUP_FBB_ADDR_1 PDC1_FRAMEBUFFER_SETUP_REG(0x94)
#define PDC1_FRAMEBUFFER_SETUP_FBB_ADDR_2 PDC1_FRAMEBUFFER_SETUP_REG(0x98)
-#define MAKE_FRAMEBUFFER_PIXFMT(col, plx, screen) ((col & 0b111) | ((plx & 1) << 5) | ((screen & 1) << 6) | 0b10000000001100000000)
+#define MAKE_FRAMEBUFFER_PIXFMT(col, plx, screen) ((col & 0x7) | ((plx & 1) << 5) | ((screen & 1) << 6) | 0x80300)
#define RGBA8 0
#define BGR8 1
#include <firm/decryptor.h>
#include <firm/firm.h>
+#include <menu.h>
+#include <menu-backend.h>
#include <arm11.h>
#include <interrupt.h>
#include <option.h>
#ifndef __MENU_BACKEND_H__
#define __MENU_BACKEND_H__
+/* Menu entry type. Determines how the menu is displayed and which (if any) options
+ * can be changed.
+ */
+enum type
+{
+ boolean_val = 0, ///< Toggleable boolean
+ ranged_val = 1, ///< N1 - N2, left and right to pick.
+ mask_val = 2, ///< Bitmask allowed values.
+ not_option = 3, ///< Skip over this.
+ call_fun = 4, ///< Call a function. Treat (a) as (void)(*)(void).
+ boolean_val_n3ds = 5, ///< Toggle, but only show on n3DS
+ break_menu = 6 ///< Exit the menu (same as B)
+};
+
+typedef void (*func_call_t)(uint32_t data);
+
+struct range_str
+{
+ int a, b;
+};
+
+struct options_s
+{
+ int64_t index; ///< Option index. Used for displaying values.
+ char name[64]; ///< Name of patch to display in menus.
+ char desc[256]; ///< Description of option, shown when pressing select
+ enum type allowed; ///< Misnomer, FIXME. Type of menu entry. See enum type.
+ uint32_t a, b; ///< Should be union, FIXME. Data values used for menu entry.
+ uint8_t indent; ///< Indentation/ownership level of menu.
+} __attribute__((packed));
+
/* Set the accent foreground color for a screen.
*
* \param screen Which screen it should be set for
--- /dev/null
+#ifndef __MENU_H
+#define __MENU_H
+
+void reset();
+void poweroff();
+
+#endif
extern struct config_file *config;
#endif
-/* Menu entry type. Determines how the menu is displayed and which (if any) options
- * can be changed.
- */
-enum type
-{
- boolean_val = 0, ///< Toggleable boolean
- ranged_val = 1, ///< N1 - N2, left and right to pick.
- mask_val = 2, ///< Bitmask allowed values.
- not_option = 3, ///< Skip over this.
- call_fun = 4, ///< Call a function. Treat (a) as (void)(*)(void).
- boolean_val_n3ds = 5, ///< Toggle, but only show on n3DS
- break_menu = 6 ///< Exit the menu (same as B)
-};
-
-typedef void (*func_call_t)(uint32_t data);
-
-struct range_str
-{
- int a, b;
-};
-
-struct options_s
-{
- int64_t index; ///< Option index. Used for displaying values.
- char name[64]; ///< Name of patch to display in menus.
- char desc[256]; ///< Description of option, shown when pressing select
- enum type allowed; ///< Misnomer, FIXME. Type of menu entry. See enum type.
- uint32_t a, b; ///< Should be union, FIXME. Data values used for menu entry.
- uint8_t indent; ///< Indentation/ownership level of menu.
-} __attribute__((packed));
-
#define OPTION_LOADER 2 ///< Use builtin loader module replacer.
#define OPTION_SVCS 3 ///< Inject svcBackdoor (FIXME, misnomer)
* \param y2 Y2 coordinate
* \param color Color to fill with
*/
-void rect(void* channel, int x, int y, int x2, int y2, uint8_t color);
+void rect(void* channel, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2, uint8_t color);
/* Fill a line behind characters with a color.
*
* \param y Which line to fill
* \param color Color to fill with
*/
-void fill_line(void* channel, int y, uint8_t color);
+void fill_line(void* channel, unsigned int y, uint8_t color);
/* Clears background image bitmaps.
*/
* \param color_fg RGB color to draw character as (as uint32_t)
* \param color_bg RGB color to draw behind character (as uint32_t)
*/
-void draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg);
+void draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, unsigned int ch_y, const uint32_t color_fg, const uint32_t color_bg);
/* Sets the font.
*
* \param buf Handle to output to.
* \param c Character (as int) to output
*/
-void putc(void *buf, const int c);
+void putc(void *buf, int c);
/* Outputs a string to a handle
*
* \param buf Handle to output to.
* \param string String to output
*/
-void puts(void *buf, const char *string);
+void puts(void *buf, char *string);
/* Flushes a handle
*
* \param Format string.
* \param ... Format arguments
*/
-void fprintf(void *channel, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+void fprintf(void *channel, char *format, ...) __attribute__ ((format (printf, 2, 3)));
/* See fprintf. Takes a va_list instead of variable arguments.
*/
-void vfprintf(void *channel, const char *format, va_list ap);
+void vfprintf(void *channel, char *format, va_list ap);
#define BLACK 0
#define BLUE 1
#include <stdint.h>
#include <stddef.h>
-size_t strlen(const char *string);
+size_t strlen(char *string);
void memcpy(void *dest, const void *src, size_t size);
void memmove(void *dest, const void *src, size_t size);
void memset(void *dest, const int filler, size_t size);
#include <common.h>
uint32_t current_chain_index = 0;
-
struct options_s *chains = NULL;
-int show_menu(struct options_s *options, uint8_t *toggles);
-
// TODO - The near same function is called in different places. It would
// be better to have a recursive listing that calls a function for
// each entry (it would cut code density)
memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers));
((void(*)(void*, uint32_t))0x24F00000)(chain_data, size + 256 + 8); // Size of payload + argv.
+
+ while(1);
}
void chain_file_hdl(char* fpath) {
ctr[i] = partitionID[7 - i]; // Convert to big endian & normal input
ctr[8] = type;
} else if (version == 1) {
- int x = 0;
+ unsigned int x = 0;
if (type == NCCHTYPE_EXHEADER)
x = MEDIA_UNITS;
else if (type == NCCHTYPE_EXEFS)
{
static int got_cetk = 0;
uint8_t iv[AES_BLOCK_SIZE] = { 0 };
- uint32_t sigtype = __builtin_bswap32(*(uint32_t *)cetk);
+ uint32_t sigtype = __builtin_bswap32(*(const uint32_t *)cetk);
if (sigtype != SIG_TYPE_RSA2048_SHA256)
return 1;
- ticket_h *ticket = (ticket_h *)(cetk + sizeof(sigtype) + 0x13C);
+ const ticket_h *ticket = (const ticket_h *)((const uint8_t*)cetk + sizeof(sigtype) + 0x13C);
if (ticket->ticketCommonKeyYIndex != 1)
return 1;
uint8_t exefs_key[16] = { 0 };
uint8_t exefs_iv[16] = { 0 };
- fprintf(stderr, " Decrypting FIRM container (size is %u blocks)\n", *size / AES_BLOCK_SIZE);
+ fprintf(stderr, " Decrypting FIRM container (size is %lu blocks)\n", *size / AES_BLOCK_SIZE);
setup_aeskey(0x16, key);
use_aeskey(0x16);
exefs_h *exefs = (exefs_h *)((uint8_t *)ncch + ncch->exeFSOffset * MEDIA_UNITS);
uint32_t exefs_size = ncch->exeFSSize * MEDIA_UNITS;
- fprintf(stderr, " Decrypting ExeFs for FIRM (size is %u blocks)\n", exefs_size / AES_BLOCK_SIZE);
+ fprintf(stderr, " Decrypting ExeFs for FIRM (size is %lu blocks)\n", exefs_size / AES_BLOCK_SIZE);
setup_aeskeyY(0x2C, exefs_key);
use_aeskey(0x2C);
int size = atoi(header->size);
use_aeskey(slot);
- ctr_decrypt(arm9bin, arm9bin, size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, header->ctr);
+ ctr_decrypt(arm9bin, arm9bin, (size_t)size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, header->ctr);
if (firm_title == NATIVE_FIRM_TITLEID)
return *(uint32_t *)arm9bin != ARM9BIN_MAGIC;
*a11_entry = (uint32_t)firm_loc->a11Entry;
((void (*)())firm_loc->a9Entry)();
+
+ while(1);
}
int
set_cursor(TOP_SCREEN, 0, (unsigned int)(i - window_top + 2) );
int indent = options[i].indent;
- for(int i=0; i < indent; i++)
+ for(int j=0; j < indent; j++)
fprintf(TOP_SCREEN, " ");
if (options[i].allowed == boolean_val || (is_n3ds && options[i].allowed == boolean_val_n3ds)) {
strncpy(patches[current_menu_index_patches].desc, fpath, 255);
else
strncpy(patches[current_menu_index_patches].desc, p.desc, 255);
- patches[current_menu_index_patches].index = p.uuid;
+ patches[current_menu_index_patches].index = (int64_t)p.uuid;
patches[current_menu_index_patches].allowed = boolean_val;
patches[current_menu_index_patches].a = 0;
patches[current_menu_index_patches].b = 0;
const uint8_t pattern[] = { 0x21, 0x20, 0x18, 0x20 };
const uint8_t *off = memfind(pos, size, pattern, 4);
- uint32_t ret = *(uint32_t *)(off + 9) + *(uint32_t *)(off + 0xD);
+ uint32_t ret = *(const uint32_t *)(off + 9) + *(const uint32_t *)(off + 0xD);
fprintf(stderr, "emunand: SDMMC code @ %lx\n", ret);
uint32_t need_units = (module->contentSize - sysmodule->contentSize);
memmove((uint8_t *)sysmodule + module->contentSize * 0x200, (uint8_t *)sysmodule + sysmodule->contentSize * 0x200,
- ((uint8_t *)firm_loc + firm_size) - ((uint8_t *)sysmodule + (module->contentSize * 0x200)));
+ ((uint32_t)firm_loc + firm_size) - ((uint32_t)sysmodule + (module->contentSize * 0x200)));
sysmodule_section->size += 0x200 * need_units;
for (int i = section_index + 1; i < 4; i++) {
else if (module->contentSize < sysmodule->contentSize) {
// NOTE - This doesn't change the sysmodule section size; it isn't needed to do so.
fprintf(stderr, "Module: Shrink %lu units\n", sysmodule->contentSize - module->contentSize);
- int remaining_size =
+ uint32_t remaining_size =
sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_loc + sysmodule_section->offset));
// Sysmodule section size - (End location of this sysmodule -
// Sysmodule section) =>
fprintf(stderr, "reboot: firmlaunch @ %lx\n", (uint32_t)off);
// Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1
- uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - process9Offset + process9MemAddr);
+ uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - (uint32_t)process9Offset + process9MemAddr);
fprintf(stderr, "reboot: fopen @ %lx\n", fOpenOffset);
#include <stdarg.h>
#include <common.h>
-void poweroff();
-
-void abort(const char* x, ...) {
+void abort(char* x, ...) {
va_list ap;
va_start(ap, x);
0xffffff // White
}; // VGA color table.
-void rect(void* channel, int x, int y, int x2, int y2, uint8_t color) {
+void rect(void* channel, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2, uint8_t color) {
uint8_t* screen = NULL;
- int height = 0;
+ unsigned int height = 0;
if (channel == stdout) {
screen = framebuffers->top_left;
height = TOP_HEIGHT;
return; // Invalid on non-screen displays.
}
- for(int y_a = y; y_a < y2; y_a++) {
- for(int x_a = x; x_a < x2; x_a++) {
- int xDisplacement = (x_a * SCREEN_DEPTH * height);
- int yDisplacement = ((height - y_a - 1) * SCREEN_DEPTH);
- int pos = xDisplacement + yDisplacement;
+ for(unsigned int y_a = y; y_a < y2; y_a++) {
+ for(unsigned int x_a = x; x_a < x2; x_a++) {
+ unsigned int xDisplacement = (x_a * SCREEN_DEPTH * height);
+ unsigned int yDisplacement = ((height - y_a - 1) * SCREEN_DEPTH);
+ unsigned int pos = xDisplacement + yDisplacement;
screen[pos + 1] = colors[color & 0xF];
screen[pos + 2] = colors[color & 0xF] >> 8;
}
}
-void fill_line(void* channel, int y, uint8_t color) {
- int x2 = 0;
+void fill_line(void* channel, unsigned int y, uint8_t color) {
+ unsigned int x2 = 0;
if (channel == stdout)
x2 = TOP_WIDTH;
else if (channel == stderr)
}
void
-draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg)
+draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, unsigned int ch_y, const uint32_t color_fg, const uint32_t color_bg)
{
if (!isprint(character))
return; // Don't output non-printables.
- _UNUSED int width = 0;
- int height = 0;
+ _UNUSED unsigned int width = 0;
+ unsigned int height = 0;
uint8_t* buffer_bg;
if (screen == framebuffers->top_left || screen == framebuffers->top_right) {
width = TOP_WIDTH;
return; // Invalid buffer.
}
- int x = (font_w + font_kern) * ch_x;
- int y = font_h * ch_y;
+ unsigned int x = (font_w + font_kern) * ch_x;
+ unsigned int y = font_h * ch_y;
if (x >= width || y >= height)
return; // OOB
unsigned int c_font_w = (font_w / 8) + (font_w % 8 ? 1 : 0);
for (unsigned int yy = 0; yy < font_h; yy++) {
- int xDisplacement = (x * SCREEN_DEPTH * height);
- int yDisplacement = ((height - (y + yy) - 1) * SCREEN_DEPTH);
+ unsigned int xDisplacement = (x * SCREEN_DEPTH * height);
+ unsigned int yDisplacement = ((height - (y + yy) - 1) * SCREEN_DEPTH);
unsigned int pos = xDisplacement + yDisplacement;
- int xDisplacementBg = (x * 3 * height);
- int yDisplacementBg = ((height - (y + yy) - 1) * 3);
+ unsigned int xDisplacementBg = (x * 3 * height);
+ unsigned int yDisplacementBg = ((height - (y + yy) - 1) * 3);
unsigned int pos_b = xDisplacementBg + yDisplacementBg;
unsigned char char_dat = font_data[(character - ' ') * (c_font_w * font_h) + yy];
case 4: // Background color
*color &= 0xf0; // Remove bg color.
*color |= ((*val % 40) & 0xf);
+ break;
+ default: // ???
break;
}
*state = ANSI_END;
}
}
return 1;
+ default:
+ *state = TEXT;
+ return 1;
}
+
+ return 0; // Should not be reached.
}
void
-putc(void *buf, const int c)
+putc(void *buf, int c)
{
if(ansi_statemach(buf, c) == 1) // Inside ANSI escape?
return;
cursor_x[0] = 0; // Reset to beginning of line.
break;
default:
- draw_character(screen, c, cursor_x[0], cursor_y[0], colors[(color[0] >> 4) & 0xF], colors[color[0] & 0xF]);
+ draw_character(screen, (unsigned int)c, cursor_x[0], cursor_y[0], colors[(color[0] >> 4) & 0xF], colors[color[0] & 0xF]);
cursor_x[0]++;
}
void
-puts(void *buf, const char *string)
+puts(void *buf, char *string)
{
if ((buf == stdout || buf == stderr) && kill_output)
return;
- char *ref = (char *)string;
+ char *ref = string;
while (ref[0] != 0) {
putc(buf, ref[0]);
put_int64(void *channel, int64_t n, int length)
{
char conv[32], out[32];
+ size_t i = 0, sign = 0;
+
memset(conv, 0, 32);
memset(out, 0, 32);
- int i = 0, sign = 0;
if (n < 0) {
n = -n;
sign = 1;
if (length > 0)
out[length] = '\0';
- int len = strlen(conv);
- for (int i = 0; i < len; i++)
+ size_t len = strlen(conv);
+ for (i = 0; i < len; i++)
out[i] = conv[(len - 1) - i];
puts(channel, out);
put_uint64(void *channel, uint64_t n, int length)
{
char conv[32], out[32];
+ size_t i = 0;
+
memset(conv, 0, 32);
memset(out, 0, 32);
- int i = 0;
do {
conv[i++] = (n % 10) + '0';
} while ((n /= 10) != 0);
if (length > 0)
out[length] = '\0';
- int len = strlen(conv);
- for (int i = 0; i < len; i++)
+ size_t len = strlen(conv);
+ for (i = 0; i < len; i++)
out[i] = conv[(len - 1) - i];
puts(channel, out);
int disable_format = 0;
void
-vfprintf(void *channel, const char *format, va_list ap)
+vfprintf(void *channel, char *format, va_list ap)
{
if ((channel == stdout || channel == stderr) && kill_output)
return;
break;
}
break;
- case 's':
- // For now, this warning stays.
- disable_format = 1; // Disable format strings.
- fprintf(channel, va_arg(ap, char *));
- disable_format = 0; // Reenable.
- break;
case 'c':
putc(channel, va_arg(ap, int));
break;
+ case 's':
case 'p':
puts(channel, va_arg(ap, char *));
break;
}
void
-fprintf(void *channel, const char *format, ...)
+fprintf(void *channel, char *format, ...)
{
// The output suppression is in all the functions to minimize overhead.
// Function calls and format conversions take time and we don't just want
}
void
-printf(void *channel, const char *format, ...)
+printf(char *format, ...)
{
va_list ap;
va_start(ap, format);
// This function is based on PathDeleteWorker from GodMode9.
// It was easier to just import it.
int
-recurse_call_back(char *fpath, void (*call_fun)(char*))
+recurse_call_back(char *fpath, void (*call_fun_param)(char*))
{
FILINFO fno;
DIR pdir;
if (f2.fattrib & AM_DIR) {
// return value won't matter
- recurse_call_back(fpath, call_fun);
+ recurse_call_back(fpath, call_fun_param);
} else {
- call_fun(fpath);
+ call_fun_param(fpath);
}
}
--fname;
fname[0] = 0;
- call_fun(fpath);
+ call_fun_param(fpath);
return 0;
}
-void recurse_call(char *name, void (*call_fun)(char*)) {
+void recurse_call(char *name, void (*call_fun_param)(char*)) {
char fpath[256];
strncpy(fpath, name, 256);
- recurse_call_back(fpath, call_fun);
+ recurse_call_back(fpath, call_fun_param);
}
int
{
char fpath[256];
strncpy(fpath, name, 256);
- recurse_call(fpath, f_unlink);
+ recurse_call(fpath, (void (*)(char*))f_unlink);
return 0;
}
#include <stddef.h>
size_t
-strlen(const char *string)
+strlen(char *string)
{
- char *string_end = (char *)string;
+ char *string_end = string;
while (string_end[0])
string_end++;
- return string_end - string;
+ return (size_t)(string_end - string);
}
size_t
memmove(void *dest, const void *src, size_t size)
{
// memcpy does the job of moving backwards just fine
- if (dest < src || (uint8_t*)src + size <= (uint8_t*)dest) {
+ if (dest < src || (const uint8_t*)src + size <= (uint8_t*)dest) {
memcpy(dest, src, size);
return;
}