1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-31 14:37:24 +00:00

Move libc to skyline_libc, Add nn bindings

This commit is contained in:
jam1garner 2020-04-09 02:15:39 -04:00
parent 0f6c365733
commit ba437edf35
12 changed files with 12336 additions and 17 deletions

13
Cargo.lock generated
View file

@ -6,6 +6,13 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "nn"
version = "0.1.0"
dependencies = [
"skyline_libc",
]
[[package]]
name = "no_std_test"
version = "0.1.0"
@ -35,9 +42,15 @@ dependencies = [
name = "skyline"
version = "0.0.1"
dependencies = [
"nn",
"skyline_libc",
"skyline_macro",
]
[[package]]
name = "skyline_libc"
version = "0.1.0"
[[package]]
name = "skyline_macro"
version = "0.1.0"

13
skyline/Cargo.lock generated
View file

@ -5,6 +5,13 @@ name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nn"
version = "0.1.0"
dependencies = [
"skyline_libc 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.10"
@ -25,9 +32,15 @@ dependencies = [
name = "skyline"
version = "0.0.1"
dependencies = [
"nn 0.1.0",
"skyline_libc 0.1.0",
"skyline_macro 0.1.0",
]
[[package]]
name = "skyline_libc"
version = "0.1.0"
[[package]]
name = "skyline_macro"
version = "0.1.0"

View file

@ -8,3 +8,5 @@ edition = "2018"
[dependencies]
skyline_macro = { path = "./skyline_macro" }
nn = { path = "./nn" }
skyline_libc = { path = "./skyline_libc" }

12
skyline/nn/Cargo.lock generated Normal file
View file

@ -0,0 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "nn"
version = "0.1.0"
dependencies = [
"skyline_libc",
]
[[package]]
name = "skyline_libc"
version = "0.1.0"

10
skyline/nn/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "nn"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
skyline_libc = { path = "../skyline_libc" }

12221
skyline/nn/src/lib.rs Normal file

File diff suppressed because it is too large Load diff

5
skyline/skyline_libc/Cargo.lock generated Normal file
View file

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "skyline_libc"
version = "0.1.0"

View file

@ -0,0 +1,9 @@
[package]
name = "skyline_libc"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -1,3 +1,5 @@
#![no_std]
//! Public exports of libc functions
#![allow(non_camel_case_types)]
@ -7,6 +9,7 @@ pub type c_char = u8;
pub type time_t = i32;
pub type wchar_t = u16;
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_schar = i8;
pub type c_uchar = u8;
@ -54,6 +57,16 @@ pub struct tm {
pub tm_isdst: c_int,
}
#[allow(non_snake_case, non_upper_case_globals, dead_code)]
pub mod FileOpenMode {
pub const Write: *const u8 = "w\0".as_bytes().as_ptr();
pub const Read: *const u8 = "r\0".as_bytes().as_ptr();
pub const Append: *const u8 = "a\0".as_bytes().as_ptr();
pub const ReadUpdate: *const u8 = "r+\0".as_bytes().as_ptr();
pub const WriteUpdate: *const u8 = "w+\0".as_bytes().as_ptr();
pub const AppendUpdate: *const u8 = "a+\0".as_bytes().as_ptr();
}
#[derive(Debug, Clone, Copy)]
pub enum FILE {}
@ -116,6 +129,7 @@ extern "C" {
nobj: size_t,
stream: *mut FILE,
) -> size_t;
pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
pub fn ftell(stream: *mut FILE) -> c_long;
pub fn rewind(stream: *mut FILE);
@ -286,3 +300,14 @@ extern "C" {
pub fn fdopendir(fd: c_int) -> *mut DIR;
}
pub fn fwrite_slice<T: Sized>(slice: &[T], stream: *mut FILE) -> size_t {
unsafe {
fwrite(
slice.as_ptr() as _,
core::mem::size_of::<T>(),
slice.len(),
stream
)
}
}

View file

@ -55,12 +55,12 @@ pub fn hook(_: TokenStream, input: TokenStream) -> TokenStream {
let mod_fn = mod_fn.sig.ident;
let info = quote::format_ident!(
let _info = quote::format_ident!(
"{}_skyline_internal_hook_info",
mod_fn
);
let hook = quote::format_ident!(
let _hook = quote::format_ident!(
"{}_skyline_internal_hook",
mod_fn
);

View file

@ -1,10 +1,9 @@
#![no_std]
#![allow(incomplete_features)]
#![feature(alloc_error_handler, lang_items, start, global_asm, const_generics, impl_trait_in_bindings, proc_macro_hygiene)]
#![feature(alloc_error_handler, lang_items, start, global_asm, const_generics, impl_trait_in_bindings, proc_macro_hygiene, alloc_prelude)]
pub extern crate alloc;
pub mod libc;
pub mod hooks;
pub mod build;
pub mod extern_alloc;
@ -12,6 +11,8 @@ pub use extern_alloc::Allocator;
pub use skyline_macro::{main, hook};
pub use hooks::iter_hooks;
pub use skyline_libc as libc;
extern "C" {
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
}
@ -22,6 +23,10 @@ pub fn log(message: &str) {
}
}
pub fn c_str(string: &str) -> *const u8 {
string.as_bytes().as_ptr()
}
#[macro_export] macro_rules! setup {
() => {
#[global_allocator]
@ -46,4 +51,5 @@ pub fn log(message: &str) {
pub mod prelude {
pub use crate::Allocator;
pub use crate::println;
pub use crate::alloc::prelude::v1::*;
}

View file

@ -1,17 +1,10 @@
#![no_std]
#![feature(proc_macro_hygiene)]
use skyline::hook;
#[hook(sym = "nn::fs::MountSaveData")]
fn test1(path: *const u8, user_id: u64) {
println!("user id: {}", user_id);
}
#[hook(inline, offset = 0x71000030)]
fn test2(x: u32) -> u64 {
(x as u64) + 1
}
use skyline::{
libc::{fopen, FileOpenMode, fwrite_slice, fclose},
c_str
};
#[skyline::main]
pub fn main() {
@ -21,7 +14,17 @@ pub fn main() {
println!("{}", i);
}
for hook in skyline::iter_hooks() {
println!("hook: {}", hook.info.fn_name);
println!("Writing to file!");
write_to_file("sd:/test.txt\0", "test test test test");
println!("Done writing to file!");
}
fn write_to_file(file: &str, contents: &str) {
unsafe {
let file = fopen(c_str(file), FileOpenMode::Write);
fwrite_slice(contents.as_bytes(), file);
fclose(file);
}
}