Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
masagrator authored Mar 14, 2022
1 parent cd747ee commit b23b17c
Show file tree
Hide file tree
Showing 672 changed files with 5,361,226 additions and 5 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install numpy
- name: Compile jsons
run: |
python scena_assembler.py
python talk_assembler.py
python text_assembler.py
python ui_assembler.py
compile:
runs-on: ubuntu-latest
container: devkitpro/devkita64
steps:
- uses: actions/checkout@v2
- name: make
run: |
cd Plugin
make -j$(nproc)
cd ../
22 changes: 22 additions & 0 deletions Plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2020 The Skyline Project
Copyright (c) 2021 MasaGratoR

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions Plugin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: all clean skyline

NAME := $(shell basename $(CURDIR))
NAME_LOWER := $(shell echo $(NAME) | tr A-Z a-z)

BUILD_DIR := build

MAKE_NSO := nso.mk

all: skyline

skyline:
$(MAKE) all -f $(MAKE_NSO) MAKE_NSO=$(MAKE_NSO) BUILD=$(BUILD_DIR) TARGET=$(NAME)
mkdir -p 0100AD0014AB4000/exefs
cp subsdk9 0100AD0014AB4000/exefs/subsdk9
cp main.npdm 0100AD0014AB4000/exefs/main.npdm

clean:
$(MAKE) clean -f $(MAKE_NSO)
14 changes: 14 additions & 0 deletions Plugin/exported.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
global:
__custom_init;
__custom_fini;
skyline_tcp_send_raw;
getRegionAddress;
A64HookFunction;
A64InlineHook;
sky_memcpy;
get_program_id;
get_plugin_addresses;

local: *;
};
67 changes: 67 additions & 0 deletions Plugin/include/ModuleObject.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once

#include <assert.h>
#include <elf.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

namespace rtld {
struct ModuleObject {
private:
// ResolveSymbols internals
inline void ResolveSymbolRelAbsolute(Elf64_Rel* entry);
inline void ResolveSymbolRelaAbsolute(Elf64_Rela* entry);
inline void ResolveSymbolRelJumpSlot(Elf64_Rel* entry, bool do_lazy_got_init);
inline void ResolveSymbolRelaJumpSlot(Elf64_Rela* entry, bool do_lazy_got_init);

public:
struct ModuleObject* next;
struct ModuleObject* prev;
union {
Elf64_Rel* rel;
Elf64_Rela* rela;
void* raw;
} rela_or_rel_plt;
union {
Elf64_Rel* rel;
Elf64_Rela* rela;
} rela_or_rel;
uint64_t module_base;
Elf64_Dyn* dynamic;
bool is_rela;
uint64_t rela_or_rel_plt_size;
void (*dt_init)(void);
void (*dt_fini)(void);
uint32_t* hash_bucket;
uint32_t* hash_chain;
char* dynstr;
Elf64_Sym* dynsym;
uint64_t dynstr_size;
void** got;
uint64_t rela_dyn_size;
uint64_t rel_dyn_size;
uint64_t rel_count;
uint64_t rela_count;
uint64_t hash_nchain_value;
uint64_t hash_nbucket_value;
uint64_t got_stub_ptr;
#ifdef __RTLD_6XX__
uint64_t soname_idx;
uint64_t nro_size;
bool cannot_revert_symbols;
#endif

void Initialize(uint64_t aslr_base, Elf64_Dyn* dynamic);
void Relocate();
Elf64_Sym* GetSymbolByName(const char* name);
void ResolveSymbols(bool do_lazy_got_init);
bool TryResolveSymbol(Elf64_Addr* target_symbol_address, Elf64_Sym* symbol);
};

#ifdef __RTLD_6XX__
static_assert(sizeof(ModuleObject) == 0xD0, "ModuleObject size isn't valid");
#else
static_assert(sizeof(ModuleObject) == 0xB8, "ModuleObject size isn't valid");
#endif
} // namespace rtld
23 changes: 23 additions & 0 deletions Plugin/include/alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file alloc.h
* @brief Allocation functions.
*/

#pragma once

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

void* malloc(size_t size);
void free(void* src);
void* calloc(u64 num, u64 size);
void* realloc(void* ptr, u64 size);
void* aligned_alloc(u64 alignment, u64 size);
u64 malloc_usable_size(void* ptr);

#ifdef __cplusplus
}
#endif
37 changes: 37 additions & 0 deletions Plugin/include/curl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file curl.h
* @brief CURL implementation.
*/

#pragma once

#include "types.h"

typedef u32 CURLCode; // basic code for getting results from functions

#ifdef __cplusplus
extern "C" {
#endif

typedef void CURL;
enum CURLINFO {};
enum CURLoption {};

// GLOBAL
CURLcode curl_global_init(s64 flags);

// EASY
CURL* curl_easy_init();
CURLcode curl_easy_setopt(CURL* curl, CURLoption, ...);
CURLcode curl_easy_perform(CURL* curl);
void curl_easy_cleanup(CURL* curl);
CURLcode curl_easy_getinfo(CURL* curl, CURLINFO info, ...);
CURL* curl_easy_duphandle(CURL* curl);
void curl_easy_reset(CURL* curl);
CURLcode curl_easy_pause(CURL* curl, s32 mask);
CURLcode curl_easy_recv(CURL* curl, void* buffer, u64 bufferLength, u64*);
CURLcode curl_easy_send(CURL* curl, void const* buffer, u64 bufferLength, u64*);

#ifdef __cplusplus
}
#endif
21 changes: 21 additions & 0 deletions Plugin/include/cxa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file cxa.h
* @brief One-Time Constru(X)tion API.
*/

#pragma once

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

extern s32 __cxa_guard_acquire(u32* guard);
extern void __cxa_guard_release(u32* guard);
extern void __cxa_pure_virtual();
void __cxa_atexit();

#ifdef __cplusplus
}
#endif
12 changes: 12 additions & 0 deletions Plugin/include/endianess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file endianess.h
* @brief Functions for reversing data in between the two endianesses.
*/

#pragma once

#include "types.h"

u16 swap16(u16 x) { return (x << 8) | (x >> 8); }

u32 swap32(u32 x) { return (x << 24) | ((x << 8) & 0xFF0000) | ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00); }
23 changes: 23 additions & 0 deletions Plugin/include/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @file macros.h
* @brief Various macros defined from IDA Pro.
*/

#pragma once

#include "types.h"

// https://github.com/joxeankoret/tahh/blob/master/comodo/defs.h

#define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_##l
#define __CASSERT_N1__(l) __CASSERT_N0__(l)
#define CASSERT(cnd) typedef char __CASSERT_N1__(__LINE__)[(cnd) ? 1 : -1]

#define LODWORD(x) (*((u32*)&(x)))

template <class T>
bool is_mul_ok(T count, T elsize) {
CASSERT((T)(-1) > 0);
if (elsize == 0 || count == 0) return true;
return count <= ((T)(-1)) / elsize;
}
36 changes: 36 additions & 0 deletions Plugin/include/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <map>
#include <string>

#include "ModuleObject.hpp"
#include "alloc.h"
#include "mem.h"
#include "nn/crypto.h"
#include "nn/diag.h"
#include "nn/err.h"
#include "nn/fs.h"
#include "nn/nn.h"
#include "nn/oe.h"
#include "nn/os.hpp"
#include "nn/prepo.h"
#include "nn/ro.h"
#include "nvn/pfnc.h"
#include "operator.h"
#include "skyline/inlinehook/And64InlineHook.hpp"
#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "skyline/nx/kernel/virtmem.h"
#include "skyline/nx/runtime/env.h"

#ifdef __cplusplus
};
#endif

extern nn::os::EventType romMountedEvent;

extern "C" void skyline_init();
22 changes: 22 additions & 0 deletions Plugin/include/mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file mem.h
* @brief Memory functions.
*/

#pragma once

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

void* memset(void* src, int val, u64 num);
void* memcpy(void* dest, void const* src, u64 count);
void* memmove(void* dest, const void* src, u64 count);
void* memalign(size_t alignment, size_t size);
void* memmem(void* needle, size_t needleLen, void* haystack, size_t haystackLen);

#ifdef __cplusplus
}
#endif
45 changes: 45 additions & 0 deletions Plugin/include/nn/account.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @file account.h
* @brief Account service implementation.
*/

#pragma once

#include "os.hpp"
#include "types.h"

namespace nn {
namespace account {
typedef char Nickname[0x21];
struct Uid {
u64 _x0[2];
};
typedef u64 NetworkServiceAccountId;

class AsyncContext;
struct UserHandle;

void Initialize();
Result ListAllUsers(s32*, nn::account::Uid*, s32 numUsers);
Result OpenUser(nn::account::UserHandle*, nn::account::Uid const&);
Result IsNetworkServiceAccountAvailable(bool* out, nn::account::UserHandle const&);
void CloseUser(nn::account::UserHandle const&);

Result EnsureNetworkServiceAccountAvailable(nn::account::UserHandle const& userHandle);
Result EnsureNetworkServiceAccountIdTokenCacheAsync(nn::account::AsyncContext*, nn::account::UserHandle const&);
Result LoadNetworkServiceAccountIdTokenCache(u64*, char*, u64, nn::account::UserHandle const&);

Result GetLastOpenedUser(nn::account::Uid*);
Result GetNickname(nn::account::Nickname* nickname, nn::account::Uid const& userID);

class AsyncContext {
public:
AsyncContext();

Result HasDone(bool*);
Result GetResult();
Result Cancel();
Result GetSystemEvent(nn::os::SystemEvent*);
};
}; // namespace account
}; // namespace nn
Loading

0 comments on commit b23b17c

Please sign in to comment.