Skip to content

Instantly share code, notes, and snippets.

View TuxSH's full-sized avatar
😼

TuxSH

😼
  • 02:25 (UTC +02:00)
View GitHub Profile
@TuxSH
TuxSH / k11_latest_n3ds.cpp
Last active March 30, 2024 15:08
Complete 3DS kernel decompilation (11.14-latest N3DS Kernel11, with labels for all symbols, and comments)
This file has been truncated, but you can view the full file.
/* This file was generated by the Hex-Rays decompiler.
Copyright (c) 2007-2020 Hex-Rays <info@hex-rays.com>
Detected compiler: GNU C++
*/
#include <defs.h>
//-------------------------------------------------------------------------
@TuxSH
TuxSH / k11_diagtable.cpp
Last active June 29, 2020 23:59
k11 diagnostic table
void CreateKernelDiagnosticTable(void)
{
KernelDiagnosticTable *diagTable; // r0
KPageManager **v1; // r3
KernelDiagnosticTableSlabHeapEntry *v2; // r1
int sp; // [sp+0h] [bp-10h]
diagTable = (KernelDiagnosticTable *)((unsigned int)&sp >> 12 << 12);
diagTable->mainKernelRegionStart = 0x1FF80000;
diagTable->mainKernelRegionSize = 0x80000;
@TuxSH
TuxSH / ptm_datetime.cpp
Last active May 12, 2020 20:34
3DS time management
void ModeControlManager::RecaculateSharedTimeOnWakeup(void)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
TimeDateUpdater::RecalculateSharedTime(g_p_timeDateUpdater);
sub_1026A4(off_10E484, v0, v1, v2); // TODO, has to do with sleep/wakeup and another singleton
//
}
void __fastcall sub_102868(TimeDateUpdater *this)
@TuxSH
TuxSH / kernel80.py
Created April 19, 2019 11:32
Kernel 8.0+ loader
# Copyright 2017 Reswitched Team
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with or
# without fee is hereby granted, provided that the above copyright notice and this permission
# notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
@TuxSH
TuxSH / getlastthreadinfo.md
Last active August 6, 2018 18:04
svcGetLastThreadInfo
  • GetLastThreadInfo returns the last thread of the process that was scheduled on the current core.
  • A thread holds a reference to itself; only a thread that has exited can be destroyed

Two possibilities arise:

  • the thread exited before the svc, in which case it clears cctx->scheduler->previousScheduledThread, and that field will never point to the exiting thread. This is safe.
  • the svc executes first: it fetches the last thread ptr & info with all interrupts masked. Therefore, the thread executing the svc will not be switched and no thread on the same core is going to be terminated/destroyed, this is also safe.
Result __fastcall Kip1::ParseHeader(Kip1 **thisPtr, ProcessCreationInfo *a2, bool aslrEnabled)
{
Kip1 **v3; // x20
Kip1 *v4; // x22
__int64 textOutOffset; // x8
bool v6; // w21
ProcessCreationInfo *v7; // x19
unsigned __int64 v8; // x9
unsigned __int64 dataOutOffset; // x10
Result result; // w0
@TuxSH
TuxSH / fs_dev.c
Last active June 5, 2019 00:29
fs_dev.c for fatfs
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <sys/iosupport.h>
#include <sys/param.h>
#include <unistd.h>
@TuxSH
TuxSH / kernel50.py
Created March 26, 2018 00:16
Kernel 5.0 loader
# Copyright 2017 Reswitched Team
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with or
# without fee is hereby granted, provided that the above copyright notice and this permission
# notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
@TuxSH
TuxSH / main.c
Created February 19, 2018 08:35
ifcfg
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <switch.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
@TuxSH
TuxSH / ioctls.txt
Last active January 28, 2018 00:04
switch bsdsockets ioctls
_IOC(inout,group,num,len)
r B 102 4 BIOCGBLEN
w B 108 32 BIOCSETIF
w B 112 4 BIOCIMMEDIATE
r B 113 4 BIOCVERSION
r f 118 4 FIONSPACE
r f 119 4 FIONWRITE