Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ lto = true
debug = true
opt-level = 0

[dependencies.libnx-rs]
git = "https://github.com/ischeinkman/libnx-rs"
branch = "master"
#[dependencies.libnx-rs]
#git = "https://github.com/ischeinkman/libnx-rs"
#branch = "master"

[dependencies.libc]
version = "0.2.48"
#[dependencies.libc]
#version = "0.2.48"

[dependencies.rand]
version = "0.5"
#[dependencies.rand]
#version = "0.5"

#[dependencies.piston]
#version = "0.37"
Expand Down
Binary file added lib/libsaltysd.a
Binary file not shown.
Binary file added lib/saltysd.o
Binary file not shown.
Binary file added plugin.elf
Binary file not shown.
50 changes: 40 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
#![allow(dead_code)]
#![feature(linkage)]
#![feature(lang_items, linkage, start, no_core)]
#![no_core]

extern crate libnx_rs;
extern crate libc;
//extern crate libnx_rs;
//extern crate libc;

use std::result::Result;
/*use std::result::Result;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::Write;
use std::io;
use std::os::unix::io::AsRawFd;

*/
mod saltynx;

pub fn main() {
if let Some(ver_ptr) = saltynx::find_code(b"Ver. %d.%d.%d") {
#[lang="sized"]
trait Sized {}

#[lang="copy"]
trait Copy {}

#[lang="freeze"]
trait Freeze {}

//#[panic_handler] fn panic(_: &core::panic::PanicInfo) -> ! {loop{}}
#[lang = "eh_personality"] extern fn eh_personality() {}

#[start]
pub fn main(a: isize, b: *const *const u8) -> isize {
/*if let Some(ver_ptr) = saltynx::find_code(b"Ver. %d.%d.%d") {
match saltynx::memcpy(ver_ptr, b"noice v%d%d%d") {
Ok(_) => {}
Err(_) => {}
Err(_) => { loop {} }
}
} else {
loop {}
}*/
unsafe {
const ver_string: &'static [u8; 13] = b"Ver. %d.%d.%d";
const new_ver: &'static [u8; 13] = b"noice v%d%d%d";
let ver_ptr = saltynx::S_findCode(
ver_string as *const u8,
13
);
saltynx::S_Memcpy(
ver_ptr as _,
new_ver as *const u8 as _,
13
);
}
0
}

/*
pub fn redirect_stdout (filename : &str) -> Result<File, io::Error> {
let mut outfile = OpenOptions::new()
.write(true)
Expand Down Expand Up @@ -59,4 +89,4 @@ pub fn redirect_stderr (filename : &str) -> Result<File, io::Error> {
Ok(outfile)
}
}

*/
12 changes: 7 additions & 5 deletions src/saltynx/core.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use libc::{c_void, size_t};
use super::IntoVoid;
use std::num::NonZeroU64;
//use libc::{c_void, size_t};
pub type size_t = u64;
//use super::IntoVoid;
//use core::num::NonZeroU64;

#[link(name="saltysd")]
extern "C" {
fn S_getCodeStart() -> u64;
fn S_getCodeSize() -> u64;
fn S_findCode(code: *const u8, size: size_t) -> u64;
pub fn S_findCode(code: *const u8, size: size_t) -> u64;
}

/*
pub fn get_code_start() -> *const c_void {
unsafe {
S_getCodeStart() as *const c_void
Expand All @@ -31,4 +33,4 @@ pub fn find_code_raw<T: IntoVoid>(code: T, size: size_t) -> Option<NonZeroU64> {
unsafe {
NonZeroU64::new(S_findCode(code.into() as *const u8, size))
}
}
}*/
10 changes: 6 additions & 4 deletions src/saltynx/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use libc::{c_void, c_char};
use super::{IntoVoid, IntoCString};
//use libc::{c_void, c_char};
pub struct c_void;
pub type c_char = u8;
//use super::{IntoVoid, IntoCString};

#[link(name="saltysd")]
extern "C" {
Expand All @@ -12,7 +14,7 @@ extern "C" {
fn S_ReplaceModuleImport(base: *const c_void, name: *const c_char, new_replace: *const c_void);
fn S_ReplaceImport(name: *const c_char, new_replace: *const c_void);
}

/*
pub fn get_symbol_addr<T, S>(base: T, name: S) -> u64
where S: IntoCString,
T: IntoVoid {
Expand Down Expand Up @@ -77,4 +79,4 @@ fn replace_import<S, V>(name: S, new_replace: V)
new_replace.into()
)
}
}
}*/
17 changes: 10 additions & 7 deletions src/saltynx/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use libc::{c_void, size_t};
use super::*;
use libnx_rs::libnx::Handle;
//use libc::{c_void, size_t};
pub struct c_void;
pub type size_t = u64;
pub type SwitchResult = u32;
//use super::*;
//use libnx_rs::libnx::Handle;

extern "C" {
fn S_Init();
fn S_Deinit() -> SwitchResult;
fn S_Term() -> SwitchResult;
fn S_Restore() -> SwitchResult;
fn S_Memcpy(to: *const c_void, from: *const c_void, size: size_t) -> SwitchResult;
fn S_GetSDCard(retrieve: *mut Handle) -> SwitchResult;
pub fn S_Memcpy(to: *const c_void, from: *const c_void, size: size_t) -> SwitchResult;
// fn S_GetSDCard(retrieve: *mut Handle) -> SwitchResult;
}

/*
pub fn init() {
unsafe { S_Init() }
}
Expand Down Expand Up @@ -69,4 +72,4 @@ pub fn get_sd_card() -> Result<Handle, SwitchError> {
handle
)
}
}
}*/
11 changes: 6 additions & 5 deletions src/saltynx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::{CStr, CString};
use libc::{c_void, c_char};
use std::num::NonZeroU64;
//use core::ffi::{CStr, CString};
//use libc::{c_void, c_char};
//use core::num::NonZeroU64;

pub mod core;
pub mod ipc;
Expand All @@ -10,8 +10,9 @@ pub use self::core::*;
pub use self::ipc::*;
pub use self::dynamic::*;

pub type SwitchResult = libnx_rs::libnx::Result;
//pub type SwitchResult = libnx_rs::libnx::Result;

/*
#[derive(Debug, Clone)]
pub struct SwitchError {
pub result: SwitchResult
Expand Down Expand Up @@ -83,4 +84,4 @@ impl IntoCString for CStr {
fn into_cstring(&self) -> CString {
CString::new(self.to_bytes()).unwrap()
}
}
}*/