Advertisement
ScriptzMoDz

RSYLib.cs

Aug 29th, 2014
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. public class RSYSLib
  9. {
  10. #region Utils
  11. private static void ToBigEndian(Byte[] array, Int32 size, Int32 count)
  12. {
  13. if (BitConverter.IsLittleEndian)
  14. {
  15. for (Int32 i = 0; i < count; i++)
  16. {
  17. Array.Reverse(array, i * size, size);
  18. }
  19. }
  20. }
  21.  
  22. public static void ToBigEndian(Int16[] array)
  23. {
  24. Int32 size = sizeof(Int16) * array.Length;
  25. Byte[] bytes = new Byte[size];
  26. Buffer.BlockCopy(array, 0, bytes, 0, size);
  27. ToBigEndian(bytes, sizeof(Int16), array.Length);
  28. Buffer.BlockCopy(bytes, 0, array, 0, size);
  29. }
  30.  
  31. public static void ToBigEndian(Int32[] array)
  32. {
  33. Int32 size = sizeof(Int32) * array.Length;
  34. Byte[] bytes = new Byte[size];
  35. Buffer.BlockCopy(array, 0, bytes, 0, size);
  36. ToBigEndian(bytes, sizeof(Int32), array.Length);
  37. Buffer.BlockCopy(bytes, 0, array, 0, size);
  38. }
  39.  
  40. public static void ToBigEndian(Int64[] array)
  41. {
  42. Int32 size = sizeof(Int64) * array.Length;
  43. Byte[] bytes = new Byte[size];
  44. Buffer.BlockCopy(array, 0, bytes, 0, size);
  45. ToBigEndian(bytes, sizeof(Int64), array.Length);
  46. Buffer.BlockCopy(bytes, 0, array, 0, size);
  47. }
  48.  
  49. public static void ToBigEndian(UInt16[] array)
  50. {
  51. Int32 size = sizeof(UInt16) * array.Length;
  52. Byte[] bytes = new Byte[size];
  53. Buffer.BlockCopy(array, 0, bytes, 0, size);
  54. ToBigEndian(bytes, sizeof(UInt16), array.Length);
  55. Buffer.BlockCopy(bytes, 0, array, 0, size);
  56. }
  57.  
  58. public static void ToBigEndian(UInt32[] array)
  59. {
  60. Int32 size = sizeof(UInt32) * array.Length;
  61. Byte[] bytes = new Byte[size];
  62. Buffer.BlockCopy(array, 0, bytes, 0, size);
  63. ToBigEndian(bytes, sizeof(UInt32), array.Length);
  64. Buffer.BlockCopy(bytes, 0, array, 0, size);
  65. }
  66.  
  67. public static void ToBigEndian(UInt64[] array)
  68. {
  69. Int32 size = sizeof(UInt64) * array.Length;
  70. Byte[] bytes = new Byte[size];
  71. Buffer.BlockCopy(array, 0, bytes, 0, size);
  72. ToBigEndian(bytes, sizeof(UInt64), array.Length);
  73. Buffer.BlockCopy(bytes, 0, array, 0, size);
  74. }
  75.  
  76. public static void ToBigEndian(Single[] array)
  77. {
  78. Int32 size = sizeof(Single) * array.Length;
  79. Byte[] bytes = new Byte[size];
  80. Buffer.BlockCopy(array, 0, bytes, 0, size);
  81. ToBigEndian(bytes, sizeof(Single), array.Length);
  82. Buffer.BlockCopy(bytes, 0, array, 0, size);
  83. }
  84.  
  85. public static void ToBigEndian(Double[] array)
  86. {
  87. Int32 size = sizeof(Double) * array.Length;
  88. Byte[] bytes = new Byte[size];
  89. Buffer.BlockCopy(array, 0, bytes, 0, size);
  90. ToBigEndian(bytes, sizeof(Double), array.Length);
  91. Buffer.BlockCopy(bytes, 0, array, 0, size);
  92. }
  93.  
  94. public static String ToUTF16(String utf8)
  95. {
  96. String utf16 = utf8;
  97. for (Int32 i = 0; i < utf8.Length; i++)
  98. {
  99. utf16 = utf16.Insert(i * 2, "\0");
  100. }
  101. return utf16;
  102. }
  103.  
  104. public static String ToUTF8(String utf16)
  105. {
  106. Char[] wchar = utf16.ToCharArray();
  107. String utf8 = "";
  108. for (Int32 i = 1; i < utf16.Length; i+=2)
  109. {
  110. utf8 += wchar[i];
  111. }
  112. return utf8;
  113. }
  114. #endregion
  115.  
  116. #region Syscalls
  117. public enum LedColor
  118. {
  119. green = 1,
  120. red = 2
  121. }
  122.  
  123. public enum LedAction
  124. {
  125. off,
  126. on,
  127. blink_fast,
  128. blink_slow
  129. }
  130.  
  131. public enum RingMode
  132. {
  133. single_beep = 0x6,
  134. double_beep = 0x36,
  135. triple_beep = 0x1b6,
  136. continuous_beep = 0xFFF
  137. }
  138.  
  139. public enum Temperature
  140. {
  141. cell,
  142. rsx
  143. }
  144.  
  145. public static void TTYWrite(String text)
  146. {
  147. UInt64 ret = 0;
  148. Int32 size = text.Length + 1;
  149. UInt32[] arr = new UInt32[1];
  150. RSYS.Syscall("i c" + size + " i p4", 403, out ret, __arglist(0, text, size, arr));
  151. }
  152.  
  153. public static void ControlLed(LedColor color, LedAction action)
  154. {
  155. UInt64 ret = 0;
  156. RSYS.Syscall("i i", 386, out ret, __arglist(color, action));
  157. }
  158.  
  159. public static void GetIDPS(out Byte[] idps)
  160. {
  161. idps = new Byte[16];
  162. UInt64 ret;
  163. RSYS.Syscall("p16", 0x366, out ret, __arglist(idps));
  164. }
  165.  
  166. private static UInt64 ToBigEndian(UInt64 value)
  167. {
  168. if(BitConverter.IsLittleEndian)
  169. {
  170. UInt64 ret = ((value & 0xFF00000000000000ul) >> 56)
  171. |((value & 0x00FF000000000000ul) >> 40)
  172. |((value & 0x0000FF0000000000ul) >> 24)
  173. |((value & 0x000000FF00000000ul) >> 8)
  174. |((value & 0x00000000FF000000ul) << 8)
  175. |((value & 0x0000000000FF0000ul) << 24)
  176. |((value & 0x000000000000FF00ul) << 40)
  177. |((value & 0x00000000000000FFul) << 56);
  178. return ret;
  179. }
  180. else
  181. {
  182. return value;
  183. }
  184. }
  185.  
  186. private static UInt32 ToBigEndian(UInt32 value)
  187. {
  188. if (BitConverter.IsLittleEndian)
  189. {
  190. UInt32 ret = ((value & 0xFF000000u) >> 24)
  191. | ((value & 0x00FF0000u) >> 8)
  192. | ((value & 0x0000FF00u) << 8)
  193. | ((value & 0x000000FFu) << 24);
  194. return ret;
  195. }
  196. else
  197. {
  198. return value;
  199. }
  200. }
  201.  
  202. public static void GetPSID(out UInt64 high, out UInt64 low)
  203. {
  204. UInt64 ret;
  205. high = low = 0;
  206. RSYS.Syscall("l l", 0x368, out ret, __arglist(high, low));
  207. high = ToBigEndian(high);
  208. low = ToBigEndian(low);
  209. }
  210.  
  211. public static void GetParamSfo(out Byte[] info)
  212. {
  213. info = new Byte[64];
  214. UInt64 ret;
  215. RSYS.Syscall("p64", 30, out ret, __arglist(info));
  216. }
  217.  
  218. public static String GetGameID()
  219. {
  220. Byte[] titleID = new Byte[64];
  221. UInt64 ret;
  222. RSYS.Syscall("p64", 986, out ret, __arglist(titleID));
  223. String gameID = Encoding.ASCII.GetString(titleID, 1, 9);
  224. return gameID;
  225. }
  226.  
  227. public static UInt64 GetProcessID()
  228. {
  229. UInt64 ret;
  230. RSYS.Syscall(null, 1, out ret, __arglist());
  231. return ret;
  232. }
  233.  
  234. public static UInt64 GetProcessList(out UInt32[] list)
  235. {
  236. list = new UInt32[32];
  237. UInt64 ret;
  238. UInt64 max = 0;
  239. UInt64 count = 0;
  240. RSYS.Syscall("p128 p8 p8", 0x38C, out ret, __arglist(list, ref max, ref count));
  241. return count;
  242. }
  243.  
  244. public static void RingBuzzer(RingMode mode)
  245. {
  246. UInt64 ret;
  247. RSYS.Syscall("i i i", 392, out ret, __arglist(0x1007, 0xA, mode));
  248. }
  249.  
  250. public static void GetSdkVersion(UInt32 processID, out Byte[] version)
  251. {
  252. version = new Byte[4];
  253. UInt64 ret;
  254. RSYS.Syscall("i p4", 25, out ret, __arglist(processID, version));
  255. }
  256.  
  257. public static String GetTemperature(Temperature temperature)
  258. {
  259. UInt64 ret;
  260. UInt32 temp;
  261. RSYS.Syscall("i p4", 383, out ret, __arglist(temperature, out temp));
  262. temp = ToBigEndian(temp);
  263. UInt64 value = ((UInt64)temp * 100) >> 24;
  264. return value.ToString().Insert(2, ".");
  265. }
  266.  
  267. public static UInt64 Sleep(UInt32 seconds)
  268. {
  269. UInt64 ret;
  270. RSYS.Syscall("i", 142, out ret, __arglist(seconds));
  271. return ret;
  272. }
  273.  
  274. public static void USleep(UInt32 useconds)
  275. {
  276. UInt64 ret;
  277. RSYS.Syscall("i", 141, out ret, __arglist(useconds));
  278. }
  279.  
  280. public static UInt64 lv2_peek(UInt64 address)
  281. {
  282. UInt64 ret;
  283. RSYS.Syscall("l", 6, out ret, __arglist(address));
  284. return ret;
  285. }
  286.  
  287. public static void lv2_poke(UInt64 address, UInt64 value)
  288. {
  289. UInt64 ret;
  290. RSYS.Syscall("l l", 7, out ret, __arglist(address, value));
  291. }
  292. #endregion
  293.  
  294. #region FunctionCalls
  295. public static void Notify(String message)
  296. {
  297. Opd_s target;
  298. RSYS.FindExport("vshtask", 0xA02D46E7, out target);
  299. UInt64 int_out;
  300. Double flt_out;
  301. RSYS.Call(ref target, out int_out, out flt_out, "i c" + (message.Length + 1).ToString(), __arglist(0, message));
  302. }
  303.  
  304. public static Int32 fopen(String path, String mode)
  305. {
  306. Opd_s target;
  307. RSYS.FindExport("stdc", 0x69C27C12, out target);
  308. UInt64 int_out;
  309. Double flt_out;
  310. RSYS.Call(ref target, out int_out, out flt_out, "c" + (path.Length + 1).ToString() + " c" + (mode.Length + 1).ToString(), __arglist(path, mode));
  311. return (Int32)int_out;
  312. }
  313.  
  314. public static void fwrite(Byte[] source, Int32 file)
  315. {
  316. Opd_s target;
  317. RSYS.FindExport("stdc", 0xF88F26C4, out target);
  318. UInt64 int_out;
  319. Double flt_out;
  320. RSYS.Call(ref target, out int_out, out flt_out, "c" + source.Length.ToString() + " i i i", __arglist(source, 1, source.Length, file));
  321. }
  322.  
  323. public static void fclose(Int32 file)
  324. {
  325. Opd_s target;
  326. RSYS.FindExport("stdc", 0xE1BD3587, out target);
  327. UInt64 int_out;
  328. Double flt_out;
  329. RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(file));
  330. }
  331.  
  332. public static UInt32 malloc(Int32 size)
  333. {
  334. Opd_s target;
  335. RSYS.FindExport("allocator", 0x759E0635, out target);
  336. UInt64 int_out;
  337. Double flt_out;
  338. RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(size));
  339. return (UInt32)int_out;
  340. }
  341.  
  342. public static void free(UInt32 address)
  343. {
  344. Opd_s target;
  345. RSYS.FindExport("allocator", 0x77A602DD, out target);
  346. UInt64 int_out;
  347. Double flt_out;
  348. RSYS.Call(ref target, out int_out, out flt_out, "i", __arglist(address));
  349. }
  350.  
  351. public static Int32 sys_prx_load_module(String path, Int32 flags, ref UInt64 pOpt)
  352. {
  353. Opd_s function;
  354. RSYS.FindExport("sysPrxForUser", 0x26090058, out function);
  355. UInt64 prx_id;
  356. Double flt_out;
  357. RSYS.Call(ref function, out prx_id, out flt_out, "c" + (path.Length + 1) + " i p8", __arglist(path, flags, ref pOpt));
  358. return (Int32)prx_id;
  359. }
  360.  
  361. public static void sys_prx_start_module(Int32 prx_id, Int32 args, ref Byte[] argp, out Int32 modres, Int32 flags, UInt64 size)
  362. {
  363. Opd_s function;
  364. RSYS.FindExport("sysPrxForUser", 0x9F18429D, out function);
  365. UInt64 int_out;
  366. Double flt_out;
  367. 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));
  368. modres = IPAddress.HostToNetworkOrder(modres);
  369. }
  370.  
  371. public static String sprintf_example()
  372. {
  373. StringBuilder dest = new StringBuilder(80);// equivalent of char dest[80]
  374. Opd_s function;
  375. RSYS.FindExport("stdc", 0x273B9711, out function);
  376. UInt64 ret;
  377. Double flt_ret;
  378. RSYS.Call(ref function, out ret, out flt_ret, "p80 c9 c4", __arglist(dest, "hello %s", "vsh"));
  379. return dest.ToString();
  380. }
  381.  
  382. public static void memcpy(UInt32 address, ref Byte[] destination)
  383. {
  384.  
  385. Opd_s memcpy;
  386. RSYS.FindExport("stdc", 0x831D70A5, out memcpy);
  387. UInt64 int_out;
  388. Double flt_out;
  389. RSYS.Call(ref memcpy, out int_out, out flt_out, "p" + destination.Length + " i i", __arglist(destination, address, destination.Length));
  390. }
  391. #endregion
  392.  
  393. #region TLS
  394. public static Int32 GetThreadID()
  395. {
  396. Int32 value;
  397. RSYS.ReadTLS(-0x702C, out value); // return *(int32_t*)(r13 - 0x702C);
  398. return value;
  399. }
  400. #endregion
  401. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement