Advertisement
Guest User

Untitled

a guest
Dec 25th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.16 KB | None | 0 0
  1. class PS3AP
  2. {
  3.  
  4. #region Functions
  5. private static PS3API DEX = new PS3API();
  6.  
  7. public static void Connect()
  8. {
  9. DEX.ConnectTarget();
  10. DEX.AttachProcess();
  11. }
  12. public static void Reconnect()
  13. {
  14. DEX.ConnectTarget();
  15. }
  16. public static byte[] GetMemory(UInt32 offset, int length)
  17. {
  18. byte[] array = new byte[length];
  19. DEX.GetMemory(offset, array);
  20. return array;
  21. }
  22. public static void ChangeAPI(SelectAPI API)
  23. {
  24. DEX.ChangeAPI(API);
  25. }
  26. public static SelectAPI GetCurrentAPI()
  27. {
  28. return DEX.GetCurrentAPI();
  29. }
  30. public static byte[] GetMemoryL(UInt32 address, int length)
  31. {
  32. byte[] buffer = new byte[length];
  33. DEX.GetMemory(address, buffer);
  34. return buffer;
  35. }
  36. public static void GetMemor(UInt32 Address, byte[] Bytes)
  37. {
  38. DEX.SetMemory(Address, Bytes);
  39. }
  40. public static void GetMemoryR(UInt32 Address, ref byte[] Bytes)
  41. {
  42. DEX.GetMemory(Address, Bytes);
  43. }
  44.  
  45. public class Extension
  46. {
  47. private static SelectAPI CurrentAPI;
  48. private static byte[] GetBytes(UInt32 offset, int length, SelectAPI API)
  49. {
  50. byte[] bytes = new byte[length];
  51. if (API == SelectAPI.ControlConsole)
  52. {
  53. CurrentAPI = GetCurrentAPI();
  54. return DEX.GetBytes(offset, length);
  55. }
  56. if (API == SelectAPI.TargetManager)
  57. {
  58. CurrentAPI = GetCurrentAPI();
  59. bytes = DEX.GetBytes(offset, length);
  60. }
  61. return bytes;
  62. }
  63.  
  64. private static void GetMem(UInt32 offset, byte[] buffer, SelectAPI API)
  65. {
  66. if (API == SelectAPI.ControlConsole)
  67. {
  68. GetMemoryR(offset, ref buffer);
  69. }
  70. else if (API == SelectAPI.TargetManager)
  71. {
  72. GetMemoryR(offset, ref buffer);
  73. }
  74. }
  75.  
  76. public static bool ReadBool(UInt32 offset)
  77. {
  78. byte[] buffer = new byte[1];
  79. GetMem(offset, buffer, CurrentAPI);
  80. return (buffer[0] != 0);
  81. }
  82.  
  83. public static byte ReadByte(UInt32 offset)
  84. {
  85. return GetBytes(offset, 1, CurrentAPI)[0];
  86. }
  87.  
  88. public static byte[] ReadBytes(UInt32 offset, int length)
  89. {
  90. return GetBytes(offset, length, CurrentAPI);
  91. }
  92.  
  93. public static float ReadFloat(UInt32 offset)
  94. {
  95. byte[] array = GetBytes(offset, 4, CurrentAPI);
  96. Array.Reverse(array, 0, 4);
  97. return BitConverter.ToSingle(array, 0);
  98. }
  99.  
  100. public static short ReadInt16(UInt32 offset)
  101. {
  102. byte[] array = GetBytes(offset, 2, CurrentAPI);
  103. Array.Reverse(array, 0, 2);
  104. return BitConverter.ToInt16(array, 0);
  105. }
  106.  
  107. public static int ReadInt32(UInt32 offset)
  108. {
  109. byte[] array = GetBytes(offset, 4, CurrentAPI);
  110. Array.Reverse(array, 0, 4);
  111. return BitConverter.ToInt32(array, 0);
  112. }
  113.  
  114. public static void WriteSingle(UInt32 address, float input)
  115. {
  116. byte[] array = new byte[4];
  117. BitConverter.GetBytes(input).CopyTo(array, 0);
  118. Array.Reverse(array, 0, 4);
  119. PS3AP.GetMemor(address, array);
  120. }
  121.  
  122. public static void WriteSingle(UInt32 address, float[] input)
  123. {
  124. int length = input.Length;
  125. byte[] array = new byte[length * 4];
  126. for (int i = 0; i < length; i++)
  127. {
  128. ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int)(i * 4));
  129. }
  130. PS3AP.GetMemor(address, array);
  131. }
  132.  
  133. public static long ReadInt64(UInt32 offset)
  134. {
  135. byte[] array = GetBytes(offset, 8, CurrentAPI);
  136. Array.Reverse(array, 0, 8);
  137. return BitConverter.ToInt64(array, 0);
  138. }
  139.  
  140. public static sbyte ReadSByte(UInt32 offset)
  141. {
  142. byte[] buffer = new byte[1];
  143. GetMem(offset, buffer, CurrentAPI);
  144. return (sbyte)buffer[0];
  145. }
  146.  
  147. public static string ReadString(UInt32 offset)
  148. {
  149. int length = 40;
  150. int num2 = 0;
  151. string source = "";
  152. do
  153. {
  154. byte[] bytes = ReadBytes(offset + ((UInt32)num2), length);
  155. source = source + Encoding.UTF8.GetString(bytes);
  156. num2 += length;
  157. }
  158. while (!source.Contains<char>('\0'));
  159. int index = source.IndexOf('\0');
  160. string str2 = source.Substring(0, index);
  161. source = string.Empty;
  162. return str2;
  163. }
  164.  
  165. public static byte[] ReverseArray(float float_0)
  166. {
  167. byte[] bytes = BitConverter.GetBytes(float_0);
  168. Array.Reverse(bytes);
  169. return bytes;
  170. }
  171.  
  172. public static byte[] uintBytes(UInt32 input)
  173. {
  174. byte[] data = BitConverter.GetBytes(input);
  175. Array.Reverse(data);
  176. return data;
  177. }
  178. public static byte[] ReverseBytes(byte[] inArray)
  179. {
  180. Array.Reverse(inArray);
  181. return inArray;
  182. }
  183. public static byte[] ToHexFloat(float Axis)
  184. {
  185. byte[] bytes = BitConverter.GetBytes(Axis);
  186. Array.Reverse(bytes);
  187. return bytes;
  188. }
  189.  
  190. public static ushort ReadUInt16(UInt32 offset)
  191. {
  192. byte[] array = GetBytes(offset, 2, CurrentAPI);
  193. Array.Reverse(array, 0, 2);
  194. return BitConverter.ToUInt16(array, 0);
  195. }
  196.  
  197. public static UInt32 ReadUInt32(UInt32 offset)
  198. {
  199. byte[] array = GetBytes(offset, 4, CurrentAPI);
  200. Array.Reverse(array, 0, 4);
  201. return BitConverter.ToUInt32(array, 0);
  202. }
  203.  
  204. public static ulong ReadUInt64(UInt32 offset)
  205. {
  206. byte[] array = GetBytes(offset, 8, CurrentAPI);
  207. Array.Reverse(array, 0, 8);
  208. return BitConverter.ToUInt64(array, 0);
  209. }
  210.  
  211. private static void SetMem(UInt32 Address, byte[] buffer, SelectAPI API)
  212. {
  213. DEX.SetMemory(Address, buffer);
  214. }
  215.  
  216. public static void WriteBool(UInt32 offset, bool input)
  217. {
  218. byte[] buffer = new byte[] { input ? ((byte)1) : ((byte)0) };
  219. SetMem(offset, buffer, CurrentAPI);
  220. }
  221.  
  222. public static void WriteByte(UInt32 offset, byte input)
  223. {
  224. byte[] buffer = new byte[] { input };
  225. SetMem(offset, buffer, CurrentAPI);
  226. }
  227.  
  228. public static void WriteBytes(UInt32 offset, byte[] input)
  229. {
  230. byte[] buffer = input;
  231. SetMem(offset, buffer, CurrentAPI);
  232. }
  233.  
  234. public static void WriteFloat(UInt32 offset, float input)
  235. {
  236. byte[] array = new byte[4];
  237. BitConverter.GetBytes(input).CopyTo(array, 0);
  238. Array.Reverse(array, 0, 4);
  239. SetMem(offset, array, CurrentAPI);
  240. }
  241.  
  242. public static void WriteInt16(UInt32 offset, short input)
  243. {
  244. byte[] array = new byte[2];
  245. BitConverter.GetBytes(input).CopyTo(array, 0);
  246. Array.Reverse(array, 0, 2);
  247. SetMem(offset, array, CurrentAPI);
  248. }
  249.  
  250. public static void WriteInt32(UInt32 offset, int input)
  251. {
  252. byte[] array = new byte[4];
  253. BitConverter.GetBytes(input).CopyTo(array, 0);
  254. Array.Reverse(array, 0, 4);
  255. SetMem(offset, array, CurrentAPI);
  256. }
  257.  
  258. public static void WriteInt64(UInt32 offset, long input)
  259. {
  260. byte[] array = new byte[8];
  261. BitConverter.GetBytes(input).CopyTo(array, 0);
  262. Array.Reverse(array, 0, 8);
  263. SetMem(offset, array, CurrentAPI);
  264. }
  265.  
  266. public static void WriteSByte(UInt32 offset, sbyte input)
  267. {
  268. byte[] buffer = new byte[] { (byte)input };
  269. SetMem(offset, buffer, CurrentAPI);
  270. }
  271.  
  272. public static void WriteString(UInt32 offset, string input)
  273. {
  274. byte[] bytes = Encoding.UTF8.GetBytes(input);
  275. Array.Resize<byte>(ref bytes, bytes.Length + 1);
  276. SetMem(offset, bytes, CurrentAPI);
  277. }
  278.  
  279. public static void WriteUInt16(UInt32 offset, ushort input)
  280. {
  281. byte[] array = new byte[2];
  282. BitConverter.GetBytes(input).CopyTo(array, 0);
  283. Array.Reverse(array, 0, 2);
  284. SetMem(offset, array, CurrentAPI);
  285. }
  286.  
  287. public static void WriteUInt32(UInt32 offset, UInt32 input)
  288. {
  289. byte[] array = new byte[4];
  290. BitConverter.GetBytes(input).CopyTo(array, 0);
  291. Array.Reverse(array, 0, 4);
  292. SetMem(offset, array, CurrentAPI);
  293. }
  294.  
  295. public static void WriteUInt64(UInt32 offset, ulong input)
  296. {
  297. byte[] array = new byte[8];
  298. BitConverter.GetBytes(input).CopyTo(array, 0);
  299. Array.Reverse(array, 0, 8);
  300. SetMem(offset, array, CurrentAPI);
  301. }
  302. }
  303. public class Func
  304. {
  305. public static byte GetByte(uint offset)
  306. {
  307. return PS3AP.GetMemory(offset, 1)[0];
  308. }
  309.  
  310.  
  311. public static ushort GetUInt16(uint offset, bool Reverse = false)
  312. {
  313. if (Reverse)
  314. {
  315. return BitConverter.ToUInt16(PS3AP.GetMemory(offset, 2), 0);
  316. }
  317. return BitConverter.ToUInt16(PS3AP.GetMemory(offset, 2).Reverse<byte>().ToArray<byte>(), 0);
  318. }
  319.  
  320. public static uint GetUInt32(uint offset, bool Reverse = false)
  321. {
  322. if (Reverse)
  323. {
  324. return BitConverter.ToUInt32(PS3AP.GetMemory(offset, 4), 0);
  325. }
  326. return BitConverter.ToUInt32(PS3AP.GetMemory(offset, 4).Reverse<byte>().ToArray<byte>(), 0);
  327. }
  328.  
  329. public static ulong GetUInt64(uint offset, bool Reverse = false)
  330. {
  331. if (Reverse)
  332. {
  333. return BitConverter.ToUInt64(PS3AP.GetMemory(offset, 8), 0);
  334. }
  335. return BitConverter.ToUInt64(PS3AP.GetMemory(offset, 8).Reverse<byte>().ToArray<byte>(), 0);
  336. }
  337.  
  338. public static void SetByte(uint offset, byte Value)
  339. {
  340. PS3AP.GetMemor(offset, new byte[] { Value });
  341. }
  342.  
  343. public static void SetString(uint offset, string text)
  344. {
  345. byte[] bytes = Encoding.ASCII.GetBytes(text);
  346. Array.Resize<byte>(ref bytes, bytes.Length + 1);
  347. PS3AP.GetMemor(offset, bytes);
  348. }
  349.  
  350. public static void SetUInt16(uint offset, ushort Value, bool Reverse = false)
  351. {
  352. if (Reverse)
  353. {
  354. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
  355. }
  356. else
  357. {
  358. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
  359. }
  360. }
  361.  
  362. public static void SetUInt32(uint offset, uint Value, bool Reverse = false)
  363. {
  364. if (Reverse)
  365. {
  366. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
  367. }
  368. else
  369. {
  370. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
  371. }
  372. }
  373.  
  374. public static void SetUInt64(uint offset, ulong Value, bool Reverse = false)
  375. {
  376. if (Reverse)
  377. {
  378. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
  379. }
  380. else
  381. {
  382. PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
  383. }
  384. }
  385.  
  386. class Conversions
  387. {
  388. public static byte[] ReverseBytes(byte[] input)
  389. {
  390. Array.Reverse(input);
  391. return input;
  392. }
  393. public static byte[] RandomizeRGBA()
  394. {
  395. byte[] RGBA = new byte[4];
  396. Random randomize = new Random();
  397. RGBA[0] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
  398. RGBA[1] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
  399. RGBA[2] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
  400. RGBA[3] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
  401. return RGBA;
  402. }
  403.  
  404. #endregion
  405. }
  406. }
  407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement