Advertisement
BaSs_HaXoR

PS3TMAPI

Oct 18th, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | None | 0 0
  1.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3InitTargetComms", CallingConvention = CallingConvention.Cdecl)]
  2.         private static extern int InitTargetComms();
  3.  
  4.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessGetMemory", CallingConvention = CallingConvention.Cdecl)]
  5.         private static extern int ProcessGetMemory(int target, int unit, uint processId, ulong threadId, ulong address, int count, byte[] buffer);
  6.  
  7.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessSetMemory", CallingConvention = CallingConvention.Cdecl)]
  8.         private static extern int ProcessSetMemory(int target, int unit, uint processId, ulong threadId, ulong address, int count, byte[] buffer);
  9.  
  10.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3PickTarget", CallingConvention = CallingConvention.Cdecl)]
  11.         private static extern int PickTarget(IntPtr hWndOwner, out int target);
  12.  
  13.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3Connect", CallingConvention = CallingConvention.Cdecl)]
  14.         private static extern int Connect(int target, string application);
  15.  
  16.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessList", CallingConvention = CallingConvention.Cdecl)]
  17.         private static extern int GetProcessListExt(int target, ref uint count, IntPtr processIdArray);
  18.  
  19.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessAttach", CallingConvention = CallingConvention.Cdecl)]
  20.         private static extern int ProcessAttach(int target, int unitId, uint processId);
  21.  
  22.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessContinue", CallingConvention = CallingConvention.Cdecl)]
  23.         private static extern int ProcessContinue(int target, uint processId);
  24.  
  25.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3CloseTargetComms", CallingConvention = CallingConvention.Cdecl)]
  26.         private static extern int CloseTargetComms();
  27.  
  28.         [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3Exit", CallingConvention = CallingConvention.Cdecl)]
  29.         private static extern int Exit();
  30.  
  31.         public static bool SUCCEEDED(int res)
  32.         {
  33.             return res >= 0;
  34.         }
  35.  
  36.         public static bool FAILED(int res)
  37.         {
  38.             return !SUCCEEDED(res);
  39.         }
  40.  
  41.         private static IntPtr ReadDataFromUnmanagedIncPtr<T>(IntPtr unmanagedBuf, ref T storage)
  42.         {
  43.             storage = (T)Marshal.PtrToStructure(unmanagedBuf, typeof(T));
  44.             return new IntPtr(unmanagedBuf.ToInt64() + (long)Marshal.SizeOf((object)storage));
  45.         }
  46.  
  47.         private static int GetProcessList(int target, out uint[] processIDs)
  48.         {
  49.             processIDs = (uint[])null;
  50.             IntPtr processIdArray = IntPtr.Zero;
  51.             uint count = 0U;
  52.             int res;
  53.  
  54.             if (FAILED(res = GetProcessListExt(target, ref count, processIdArray)))
  55.                 return res;
  56.  
  57.             IntPtr num = Marshal.AllocHGlobal(4 * (int)count);
  58.             if (FAILED(res = GetProcessListExt(target, ref count, num)))
  59.             {
  60.                 Marshal.FreeHGlobal(num);
  61.                 return res;
  62.             }
  63.             else
  64.             {
  65.                 IntPtr unmanagedBuf = num;
  66.                 processIDs = new uint[count];
  67.                 for (uint index = 0U; index < count; ++index)
  68.                     unmanagedBuf = ReadDataFromUnmanagedIncPtr<uint>(unmanagedBuf, ref processIDs[index]);
  69.                 Marshal.FreeHGlobal(num);
  70.                 return res;
  71.             }
  72.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement