Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- public class RSYSLib
- {
- #region Utils
- private static void ToBigEndian(Byte[] array, Int32 size, Int32 count)
- {
- if (BitConverter.IsLittleEndian)
- {
- for (Int32 i = 0; i < count; i++)
- {
- Array.Reverse(array, i * size, size);
- }
- }
- }
- public static void ToBigEndian(Int16[] array)
- {
- Int32 size = sizeof(Int16) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(Int16), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(Int32[] array)
- {
- Int32 size = sizeof(Int32) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(Int32), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(Int64[] array)
- {
- Int32 size = sizeof(Int64) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(Int64), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(UInt16[] array)
- {
- Int32 size = sizeof(UInt16) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(UInt16), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(UInt32[] array)
- {
- Int32 size = sizeof(UInt32) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(UInt32), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(UInt64[] array)
- {
- Int32 size = sizeof(UInt64) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(UInt64), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(Single[] array)
- {
- Int32 size = sizeof(Single) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(Single), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static void ToBigEndian(Double[] array)
- {
- Int32 size = sizeof(Double) * array.Length;
- Byte[] bytes = new Byte[size];
- Buffer.BlockCopy(array, 0, bytes, 0, size);
- ToBigEndian(bytes, sizeof(Double), array.Length);
- Buffer.BlockCopy(bytes, 0, array, 0, size);
- }
- public static String ToUTF16(String utf8)
- {
- String utf16 = utf8;
- for (Int32 i = 0; i < utf8.Length; i++)
- {
- utf16 = utf16.Insert(i * 2, "\0");
- }
- return utf16;
- }
- public static String ToUTF8(String utf16)
- {
- Char[] wchar = utf16.ToCharArray();
- String utf8 = "";
- for (Int32 i = 1; i < utf16.Length; i+=2)
- {
- utf8 += wchar[i];
- }
- return utf8;
- }
- #endregion
- #region Syscalls
- public enum LedColor
- {
- green = 1,
- red = 2
- }
- public enum LedAction
- {
- off,
- on,
- blink_fast,
- blink_slow
- }
- public enum RingMode
- {
- single_beep = 0x6,
- double_beep = 0x36,
- triple_beep = 0x1b6,
- continuous_beep = 0xFFF
- }
- public enum Temperature
- {
- cell,
- rsx
- }
- public static void TTYWrite(String text)
- {
- UInt64 ret = 0;
- Int32 size = text.Length + 1;
- UInt32[] arr = new UInt32[1];
- RSYS.Syscall("i c" + size + " i p4", 403, out ret, __arglist(0, text, size, arr));
- }
- public static void ControlLed(LedColor color, LedAction action)
- {
- UInt64 ret = 0;
- RSYS.Syscall("i i", 386, out ret, __arglist(color, action));
- }
- public static void GetIDPS(out Byte[] idps)
- {
- idps = new Byte[16];
- UInt64 ret;
- RSYS.Syscall("p16", 0x366, out ret, __arglist(idps));
- }
- private static UInt64 ToBigEndian(UInt64 value)
- {
- if(BitConverter.IsLittleEndian)
- {
- UInt64 ret = ((value & 0xFF00000000000000ul) >> 56)
- |((value & 0x00FF000000000000ul) >> 40)
- |((value & 0x0000FF0000000000ul) >> 24)
- |((value & 0x000000FF00000000ul) >> 8)
- |((value & 0x00000000FF000000ul) << 8)
- |((value & 0x0000000000FF0000ul) << 24)
- |((value & 0x000000000000FF00ul) << 40)
- |((value & 0x00000000000000FFul) << 56);
- return ret;
- }
- else
- {
- return value;
- }
- }
- private static UInt32 ToBigEndian(UInt32 value)
- {
- if (BitConverter.IsLittleEndian)
- {
- UInt32 ret = ((value & 0xFF000000u) >> 24)
- | ((value & 0x00FF0000u) >> 8)
- | ((value & 0x0000FF00u) << 8)
- | ((value & 0x000000FFu) << 24);
- return ret;
- }
- else
- {
- return value;
- }
- }
- public static void GetPSID(out UInt64 high, out UInt64 low)
- {
- UInt64 ret;
- high = low = 0;
- RSYS.Syscall("l l", 0x368, out ret, __arglist(high, low));
- high = ToBigEndian(high);
- low = ToBigEndian(low);
- }
- public static void GetParamSfo(out Byte[] info)
- {
- info = new Byte[64];
- UInt64 ret;
- RSYS.Syscall("p64", 30, out ret, __arglist(info));
- }
- public static String GetGameID()
- {
- Byte[] titleID = new Byte[64];
- UInt64 ret;
- RSYS.Syscall("p64", 986, out ret, __arglist(titleID));
- String gameID = Encoding.ASCII.GetString(titleID, 1, 9);
- return gameID;
- }
- public static UInt64 GetProcessID()
- {
- UInt64 ret;
- RSYS.Syscall(null, 1, out ret, __arglist());
- return ret;
- }
- public static UInt64 GetProcessList(out UInt32[] list)
- {
- list = new UInt32[32];
- UInt64 ret;
- UInt64 max = 0;
- UInt64 count = 0;
- RSYS.Syscall("p128 p8 p8", 0x38C, out ret, __arglist(list, ref max, ref count));
- return count;
- }
- public static void RingBuzzer(RingMode mode)
- {
- UInt64 ret;
- RSYS.Syscall("i i i", 392, out ret, __arglist(0x1007, 0xA, mode));
- }
- public static void GetSdkVersion(UInt32 processID, out Byte[] version)
- {
- version = new Byte[4];
- UInt64 ret;
- RSYS.Syscall("i p4", 25, out ret, __arglist(processID, version));
- }
- public static String GetTemperature(Temperature temperature)
- {
- UInt64 ret;
- UInt32 temp;
- RSYS.Syscall("i p4", 383, out ret, __arglist(temperature, out temp));
- temp = ToBigEndian(temp);
- UInt64 value = ((UInt64)temp * 100) >> 24;
- return value.ToString().Insert(2, ".");
- }
- public static UInt64 Sleep(UInt32 seconds)
- {
- UInt64 ret;
- RSYS.Syscall("i", 142, out ret, __arglist(seconds));
- return ret;
- }
- public static void USleep(UInt32 useconds)
- {
- UInt64 ret;
- RSYS.Syscall("i", 141, out ret, __arglist(useconds));
- }
- public static UInt64 lv2_peek(UInt64 address)
- {
- UInt64 ret;
- RSYS.Syscall("l", 6, out ret, __arglist(address));
- return ret;
- }
- public static void lv2_poke(UInt64 address, UInt64 value)
- {
- UInt64 ret;
- RSYS.Syscall("l l", 7, out ret, __arglist(address, value));
- }
- #endregion
- #region FunctionCalls
- public static void Notify(String message)
- {
- Opd_s target;
- RSYS.FindExport("vshtask", 0xA02D46E7, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "i c" + (message.Length + 1).ToString(), __arglist(0, message));
- }
- public static Int32 fopen(String path, String mode)
- {
- Opd_s target;
- RSYS.FindExport("stdc", 0x69C27C12, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "c" + (path.Length + 1).ToString() + " c" + (mode.Length + 1).ToString(), __arglist(path, mode));
- return (Int32)int_out;
- }
- public static void fwrite(Byte[] source, Int32 file)
- {
- Opd_s target;
- RSYS.FindExport("stdc", 0xF88F26C4, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "c" + source.Length.ToString() + " i i i", __arglist(source, 1, source.Length, file));
- }
- public static void fclose(Int32 file)
- {
- Opd_s target;
- RSYS.FindExport("stdc", 0xE1BD3587, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(file));
- }
- public static UInt32 malloc(Int32 size)
- {
- Opd_s target;
- RSYS.FindExport("allocator", 0x759E0635, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(size));
- return (UInt32)int_out;
- }
- public static void free(UInt32 address)
- {
- Opd_s target;
- RSYS.FindExport("allocator", 0x77A602DD, out target);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(address));
- }
- public static Int32 sys_prx_load_module(String path, Int32 flags, ref UInt64 pOpt)
- {
- Opd_s function;
- RSYS.FindExport("sysPrxForUser", 0x26090058, out function);
- UInt64 prx_id;
- Double flt_out;
- RSYS.Call(ref function, out prx_id, out flt_out, "c" + (path.Length + 1) + " i p8", __arglist(path, flags, ref pOpt));
- return (Int32)prx_id;
- }
- public static void sys_prx_start_module(Int32 prx_id, Int32 args, ref Byte[] argp, out Int32 modres, Int32 flags, UInt64 size)
- {
- Opd_s function;
- RSYS.FindExport("sysPrxForUser", 0x9F18429D, out function);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref function, out int_out, out flt_out, "i i p" + argp.Length + " p4 i l", __arglist(prx_id, args, argp, out modres, flags, size));
- modres = IPAddress.HostToNetworkOrder(modres);
- }
- public static String sprintf_example()
- {
- StringBuilder dest = new StringBuilder(80);// equivalent of char dest[80]
- Opd_s function;
- RSYS.FindExport("stdc", 0x273B9711, out function);
- UInt64 ret;
- Double flt_ret;
- RSYS.Call(ref function, out ret, out flt_ret, "p80 c9 c4", __arglist(dest, "hello %s", "vsh"));
- return dest.ToString();
- }
- public static void memcpy(UInt32 address, ref Byte[] destination)
- {
- Opd_s memcpy;
- RSYS.FindExport("stdc", 0x831D70A5, out memcpy);
- UInt64 int_out;
- Double flt_out;
- RSYS.Call(ref memcpy, out int_out, out flt_out, "p" + destination.Length + " i i", __arglist(destination, address, destination.Length));
- }
- #endregion
- #region TLS
- public static Int32 GetThreadID()
- {
- Int32 value;
- RSYS.ReadTLS(-0x702C, out value); // return *(int32_t*)(r13 - 0x702C);
- return value;
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement