Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3InitTargetComms", CallingConvention = CallingConvention.Cdecl)]
- private static extern int InitTargetComms();
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessGetMemory", CallingConvention = CallingConvention.Cdecl)]
- private static extern int ProcessGetMemory(int target, int unit, uint processId, ulong threadId, ulong address, int count, byte[] buffer);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessSetMemory", CallingConvention = CallingConvention.Cdecl)]
- private static extern int ProcessSetMemory(int target, int unit, uint processId, ulong threadId, ulong address, int count, byte[] buffer);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3PickTarget", CallingConvention = CallingConvention.Cdecl)]
- private static extern int PickTarget(IntPtr hWndOwner, out int target);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3Connect", CallingConvention = CallingConvention.Cdecl)]
- private static extern int Connect(int target, string application);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessList", CallingConvention = CallingConvention.Cdecl)]
- private static extern int GetProcessListExt(int target, ref uint count, IntPtr processIdArray);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessAttach", CallingConvention = CallingConvention.Cdecl)]
- private static extern int ProcessAttach(int target, int unitId, uint processId);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3ProcessContinue", CallingConvention = CallingConvention.Cdecl)]
- private static extern int ProcessContinue(int target, uint processId);
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3CloseTargetComms", CallingConvention = CallingConvention.Cdecl)]
- private static extern int CloseTargetComms();
- [DllImport("PS3TMAPI.dll", EntryPoint = "SNPS3Exit", CallingConvention = CallingConvention.Cdecl)]
- private static extern int Exit();
- public static bool SUCCEEDED(int res)
- {
- return res >= 0;
- }
- public static bool FAILED(int res)
- {
- return !SUCCEEDED(res);
- }
- private static IntPtr ReadDataFromUnmanagedIncPtr<T>(IntPtr unmanagedBuf, ref T storage)
- {
- storage = (T)Marshal.PtrToStructure(unmanagedBuf, typeof(T));
- return new IntPtr(unmanagedBuf.ToInt64() + (long)Marshal.SizeOf((object)storage));
- }
- private static int GetProcessList(int target, out uint[] processIDs)
- {
- processIDs = (uint[])null;
- IntPtr processIdArray = IntPtr.Zero;
- uint count = 0U;
- int res;
- if (FAILED(res = GetProcessListExt(target, ref count, processIdArray)))
- return res;
- IntPtr num = Marshal.AllocHGlobal(4 * (int)count);
- if (FAILED(res = GetProcessListExt(target, ref count, num)))
- {
- Marshal.FreeHGlobal(num);
- return res;
- }
- else
- {
- IntPtr unmanagedBuf = num;
- processIDs = new uint[count];
- for (uint index = 0U; index < count; ++index)
- unmanagedBuf = ReadDataFromUnmanagedIncPtr<uint>(unmanagedBuf, ref processIDs[index]);
- Marshal.FreeHGlobal(num);
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement