Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* PS3Lib 4.4 SOURCE CODE C# */
- //CCAPI.cs
- //<----------------SOURCE-----------------------------------------------------------------------------
- namespace PS3Lib
- {
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Security.Cryptography;
- using System.Windows.Forms;
- using System.Threading;
- public class CCAPI
- {
- //private readonly string CCAPIHASH = "C2FE9E1C387CF29AAC781482C28ECF86"; Won't be needing this :P
- private connectConsoleDelegate connectConsole;
- private disconnectConsoleDelegate disconnectConsole;
- private getConnectionStatusDelegate getConnectionStatus;
- private getConsoleInfoDelegate getConsoleInfo;
- private getDllVersionDelegate getDllVersion;
- private getFirmwareInfoDelegate getFirmwareInfo;
- private getNumberOfConsolesDelegate getNumberOfConsoles;
- private getProcessListDelegate getProcessList;
- private getProcessMemoryDelegate getProcessMemory;
- private getProcessNameDelegate getProcessName;
- private getTemperatureDelegate getTemperature;
- private IntPtr libModule = (IntPtr)Convert.ToInt32("1751121920"); //Pointer to Function;//
- private notifyDelegate notify;
- private TargetInfo pInfo = new TargetInfo();
- private ringBuzzerDelegate ringBuzzer;
- private setBootConsoleIdsDelegate setBootConsoleIds;
- private setConsoleIdsDelegate setConsoleIds;
- private setConsoleLedDelegate setConsoleLed;
- private setProcessMemoryDelegate setProcessMemory;
- private shutdownDelegate shutdown;
- public string getCurrentDir()
- {
- string Dir;
- Dir = Directory.GetCurrentDirectory();
- return Dir;
- }
- public CCAPI()
- {
- string dapath = getCurrentDir() + @"\CCAPI.dll"; //This will get CCAPI 2.60 from your current Directory.
- if (File.Exists(getCurrentDir() + @"\CCAPI.dll"))
- {
- // IntPtr newP = (IntPtr)Convert.ToInt32("1751121920"); //This is the MD5 Hash that is used in the main functions of every call, such as loadlib.
- // credits: jandromeda @-http://www.experts-exchange.com/Programming/Languages/.NET/Q_23237956.html
- LoadLibrary(dapath); //This will load CCAPI from your currently directory
- this.connectConsole = (connectConsoleDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIConnectConsole"), typeof(connectConsoleDelegate));
- this.disconnectConsole = (disconnectConsoleDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIDisconnectConsole"), typeof(disconnectConsoleDelegate));
- this.getConnectionStatus = (getConnectionStatusDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetConnectionStatus"), typeof(getConnectionStatusDelegate));
- this.getConsoleInfo = (getConsoleInfoDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetConsoleInfo"), typeof(getConsoleInfoDelegate));
- this.getDllVersion = (getDllVersionDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetDllVersion"), typeof(getDllVersionDelegate));
- this.getFirmwareInfo = (getFirmwareInfoDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetFirmwareInfo"), typeof(getFirmwareInfoDelegate));
- this.getNumberOfConsoles = (getNumberOfConsolesDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetNumberOfConsoles"), typeof(getNumberOfConsolesDelegate));
- this.getProcessList = (getProcessListDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetProcessList"), typeof(getProcessListDelegate));
- this.getProcessMemory = (getProcessMemoryDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetMemory"), typeof(getProcessMemoryDelegate));
- this.getProcessName = (getProcessNameDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetProcessName"), typeof(getProcessNameDelegate));
- this.getTemperature = (getTemperatureDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIGetTemperature"), typeof(getTemperatureDelegate));
- this.notify = (notifyDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIVshNotify"), typeof(notifyDelegate));
- this.ringBuzzer = (ringBuzzerDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIRingBuzzer"), typeof(ringBuzzerDelegate));
- this.setBootConsoleIds = (setBootConsoleIdsDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPISetBootConsoleIds"), typeof(setBootConsoleIdsDelegate));
- this.setConsoleIds = (setConsoleIdsDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPISetConsoleIds"), typeof(setConsoleIdsDelegate));
- this.setConsoleLed = (setConsoleLedDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPISetConsoleLed"), typeof(setConsoleLedDelegate));
- this.setProcessMemory = (setProcessMemoryDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPISetMemory"), typeof(setProcessMemoryDelegate));
- this.shutdown = (shutdownDelegate) Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.libModule, "CCAPIShutdown"), typeof(shutdownDelegate)); }
- else
- {
- MessageBox.Show("Failed to load CCAPI.dll version 2.60. Not In current Directory!", "CCAPI.dll doesn't exist!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
- }
- public int AttachProcess()
- {
- int @void = -1;
- System.processID = 0;
- @void = this.GetProcessList(out System.processIDs);
- if (!this.SUCCESS(@void) || (System.processIDs.Length <= 0))
- {
- return -1;
- }
- for (int i = 0; i < System.processIDs.Length; i++)
- {
- string name = string.Empty;
- @void = this.GetProcessName(System.processIDs[i], out name);
- if (!this.SUCCESS(@void))
- {
- break;
- }
- if (!name.Contains("flash"))
- {
- System.processID = System.processIDs[i];
- break;
- }
- @void = -1;
- }
- if (System.processID == 0)
- {
- System.processID = System.processIDs[System.processIDs.Length - 1];
- }
- return @void;
- }
- public int AttachProcess(ProcessType procType)
- {
- int processList = -1;
- System.processID = 0;
- processList = this.GetProcessList(out System.processIDs);
- if ((processList < 0) || (System.processIDs.Length <= 0))
- {
- return -1;
- }
- for (int i = 0; i < System.processIDs.Length; i++)
- {
- string name = string.Empty;
- processList = this.GetProcessName(System.processIDs[i], out name);
- if (processList < 0)
- {
- break;
- }
- if ((procType == ProcessType.VSH) && name.Contains("vsh"))
- {
- System.processID = System.processIDs[i];
- break;
- }
- if ((procType == ProcessType.SYS_AGENT) && name.Contains("agent"))
- {
- System.processID = System.processIDs[i];
- break;
- }
- if ((procType == ProcessType.CURRENTGAME) && !name.Contains("flash"))
- {
- System.processID = System.processIDs[i];
- break;
- }
- }
- if (System.processID == 0)
- {
- System.processID = System.processIDs[System.processIDs.Length - 1];
- }
- return processList;
- }
- public int AttachProcess(uint process)
- {
- int @void = -1;
- uint[] processIds = new uint[0x40];
- @void = this.GetProcessList(out processIds);
- if (this.SUCCESS(@void))
- {
- for (int i = 0; i < processIds.Length; i++)
- {
- if (processIds[i] == process)
- {
- @void = 0;
- System.processID = process;
- break;
- }
- @void = -1;
- }
- }
- processIds = null;
- return @void;
- }
- public void ClearTargetInfo()
- {
- this.pInfo = new TargetInfo();
- }
- private void CompleteInfo(ref TargetInfo Info, int fw, int ccapi, ulong sysTable, int consoleType, int tempCELL, int tempRSX)
- {
- Info.Firmware = fw;
- Info.CCAPI = ccapi;
- Info.SysTable = sysTable;
- Info.ConsoleType = consoleType;
- Info.TempCell = tempCELL;
- Info.TempRSX = tempRSX;
- }
- public bool ConnectTarget()
- {
- return new PS3API.ConsoleList(new PS3API(SelectAPI.ControlConsole)).Show();
- }
- public int ConnectTarget(string targetIP)
- {
- return this.connectConsole(targetIP);
- }
- public int DisconnectTarget()
- {
- return this.disconnectConsole();
- }
- public uint GetAttachedProcess()
- {
- return System.processID;
- }
- public byte[] GetBytes(uint offset, uint length)
- {
- byte[] buffer = new byte[length];
- this.GetMemory(offset, buffer);
- return buffer;
- }
- public byte[] GetBytes(ulong offset, uint length)
- {
- byte[] buffer = new byte[length];
- this.GetMemory(offset, buffer);
- return buffer;
- }
- public int GetConnectionStatus()
- {
- int status = 0;
- this.getConnectionStatus(ref status);
- return status;
- }
- public List<ConsoleInfo> GetConsoleList()
- {
- List<ConsoleInfo> list = new List<ConsoleInfo>();
- int num = this.getNumberOfConsoles();
- IntPtr ptrN = Marshal.AllocHGlobal(0x100);
- IntPtr ptrI = Marshal.AllocHGlobal(0x100);
- for (int i = 0; i < num; i++)
- {
- ConsoleInfo item = new ConsoleInfo();
- this.getConsoleInfo(i, ptrN, ptrI);
- item.Name = Marshal.PtrToStringAnsi(ptrN);
- item.Ip = Marshal.PtrToStringAnsi(ptrI);
- list.Add(item);
- }
- Marshal.FreeHGlobal(ptrN);
- Marshal.FreeHGlobal(ptrI);
- return list;
- }
- public int GetDllVersion()
- {
- return this.getDllVersion();
- }
- public string GetFirmwareType()
- {
- if (this.pInfo.ConsoleType.ToString() == "")
- {
- this.GetTargetInfo(out this.pInfo);
- }
- string str = string.Empty;
- if (this.pInfo.ConsoleType == 1)
- {
- return "CEX";
- }
- if (this.pInfo.ConsoleType == 2)
- {
- return "DEX";
- }
- if (this.pInfo.ConsoleType == 3)
- {
- str = "TOOL";
- }
- return str;
- }
- public string GetFirmwareVersion()
- {
- if (this.pInfo.Firmware == 0)
- {
- this.GetTargetInfo();
- }
- string str = this.pInfo.Firmware.ToString("X8");
- string str2 = str.Substring(1, 1) + ".";
- string str3 = str.Substring(3, 1);
- string str4 = str.Substring(4, 1);
- return (str2 + str3 + str4);
- }
- public int GetMemory(uint offset, byte[] buffer)
- {
- return this.getProcessMemory(System.processID, (ulong) offset, (uint) buffer.Length, buffer);
- }
- public int GetMemory(ulong offset, byte[] buffer)
- {
- return this.getProcessMemory(System.processID, offset, (uint) buffer.Length, buffer);
- }
- [DllImport("kernel32.dll")]
- private static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
- public int GetProcessList(out uint[] processIds)
- {
- uint numberProcesses = 0x40;
- int @void = -1;
- IntPtr processIdPtr = Marshal.AllocHGlobal(0x100);
- @void = this.getProcessList(ref numberProcesses, processIdPtr);
- processIds = new uint[numberProcesses];
- if (this.SUCCESS(@void))
- {
- IntPtr unBuf = processIdPtr;
- for (uint i = 0; i < numberProcesses; i++)
- {
- unBuf = this.ReadDataFromUnBufPtr<uint>(unBuf, ref processIds[i]);
- }
- }
- Marshal.FreeHGlobal(processIdPtr);
- return @void;
- }
- public int GetProcessName(uint processId, out string name)
- {
- IntPtr strPtr = Marshal.AllocHGlobal(0x211);
- int @void = -1;
- @void = this.getProcessName(processId, strPtr);
- name = string.Empty;
- if (this.SUCCESS(@void))
- {
- name = Marshal.PtrToStringAnsi(strPtr);
- }
- Marshal.FreeHGlobal(strPtr);
- return @void;
- }
- private int GetTargetInfo()
- {
- int num = -1;
- int[] numArray = new int[2];
- int firmware = 0;
- int ccapi = 0;
- int consoleType = 0;
- ulong sysTable = 0L;
- num = this.getFirmwareInfo(ref firmware, ref ccapi, ref consoleType);
- if (num >= 0)
- {
- num = this.getTemperature(ref numArray[0], ref numArray[1]);
- if (num >= 0)
- {
- this.CompleteInfo(ref this.pInfo, firmware, ccapi, sysTable, consoleType, numArray[0], numArray[1]);
- }
- }
- return num;
- }
- public int GetTargetInfo(out TargetInfo Info)
- {
- Info = new TargetInfo();
- int num = -1;
- int[] numArray = new int[2];
- int firmware = 0;
- int ccapi = 0;
- int consoleType = 0;
- ulong sysTable = 0L;
- num = this.getFirmwareInfo(ref firmware, ref ccapi, ref consoleType);
- if (num >= 0)
- {
- num = this.getTemperature(ref numArray[0], ref numArray[1]);
- if (num >= 0)
- {
- this.CompleteInfo(ref Info, firmware, ccapi, sysTable, consoleType, numArray[0], numArray[1]);
- this.CompleteInfo(ref this.pInfo, firmware, ccapi, sysTable, consoleType, numArray[0], numArray[1]);
- }
- }
- return num;
- }
- public string GetTemperatureCELL()
- {
- if (this.pInfo.TempCell == 0)
- {
- this.GetTargetInfo(out this.pInfo);
- }
- return (this.pInfo.TempCell.ToString() + " C");
- }
- public string GetTemperatureRSX()
- {
- if (this.pInfo.TempRSX == 0)
- {
- this.GetTargetInfo(out this.pInfo);
- }
- return (this.pInfo.TempRSX.ToString() + " C");
- }
- [DllImport("kernel32.dll")]
- private static extern IntPtr LoadLibrary(string dllName);
- public int Notify(NotifyIcon icon, string message)
- {
- return this.notify((int) icon, message);
- }
- public int Notify(int icon, string message)
- {
- return this.notify(icon, message);
- }
- private IntPtr ReadDataFromUnBufPtr<T>(IntPtr unBuf, ref T storage)
- {
- storage = (T) Marshal.PtrToStructure(unBuf, typeof(T));
- return new IntPtr(unBuf.ToInt64() + Marshal.SizeOf((T) storage));
- }
- public int ResetBootConsoleID(IdType Type = 0)
- {
- return this.setBootConsoleIds((int) Type, 0, null);
- }
- public int RingBuzzer(BuzzerMode flag)
- {
- return this.ringBuzzer((int) flag);
- }
- public int SetBootConsoleID(string consoleID, IdType Type = 0)
- {
- if (consoleID.Length >= 0x20)
- {
- consoleID.Substring(0, 0x20);
- }
- return this.SetBootConsoleID(StringToByteArray(consoleID), Type);
- }
- public int SetBootConsoleID(byte[] consoleID, IdType Type = 0)
- {
- return this.setBootConsoleIds((int) Type, 1, consoleID);
- }
- public int SetConsoleID(string consoleID)
- {
- if (string.IsNullOrEmpty(consoleID))
- {
- MessageBox.Show("Cannot send an empty value", "Empty or null console id", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return -1;
- }
- string hex = string.Empty;
- if (consoleID.Length >= 0x20)
- {
- hex = consoleID.Substring(0, 0x20);
- }
- return this.SetConsoleID(StringToByteArray(hex));
- }
- public int SetConsoleID(byte[] consoleID)
- {
- if (consoleID.Length <= 0)
- {
- MessageBox.Show("Cannot send an empty value", "Empty or null console id", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return -1;
- }
- return this.setConsoleIds(0, consoleID);
- }
- public int SetConsoleLed(LedColor color, LedMode mode)
- {
- return this.setConsoleLed((int) color, (int) mode);
- }
- public int SetMemory(uint offset, byte[] buffer)
- {
- return this.setProcessMemory(System.processID, (ulong) offset, (uint) buffer.Length, buffer);
- }
- public int SetMemory(ulong offset, byte[] buffer)
- {
- return this.setProcessMemory(System.processID, offset, (uint) buffer.Length, buffer);
- }
- public int SetMemory(ulong offset, string hexadecimal, EndianType Type = EndianType.LittleEndian)
- {
- byte[] array = StringToByteArray(hexadecimal);
- if (Type == EndianType.LittleEndian)
- {
- Array.Reverse(array);
- }
- return this.setProcessMemory(System.processID, offset, (uint) array.Length, array);
- }
- public int SetPSID(string PSID)
- {
- if (string.IsNullOrEmpty(PSID))
- {
- MessageBox.Show("Cannot send an empty value", "Empty or null psid", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return -1;
- }
- string hex = string.Empty;
- if (PSID.Length >= 0x20)
- {
- hex = PSID.Substring(0, 0x20);
- }
- return this.SetPSID(StringToByteArray(hex));
- }
- public int SetPSID(byte[] consoleID)
- {
- if (consoleID.Length <= 0)
- {
- MessageBox.Show("Cannot send an empty value", "Empty or null psid", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return -1;
- }
- return this.setConsoleIds(1, consoleID);
- }
- public int ShutDown(RebootFlags flag)
- {
- return this.shutdown((int) flag);
- }
- internal static byte[] StringToByteArray(string hex)
- {
- try
- {
- bool flag;
- Func<int, byte> selector = null;
- Func<int, byte> func2 = null;
- string replace = hex.Replace("0x", "");
- string Stringz = replace.Insert(replace.Length - 1, "0");
- if ((replace.Length % 2) == 0)
- {
- flag = true;
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- if (selector == null)
- {
- selector = x => Convert.ToByte(replace.Substring(x, 2), 0x10);
- }
- return (from x in Enumerable.Range(0, replace.Length)
- where (x % 2) == 0
- select x).Select<int, byte>(selector).ToArray<byte>();
- }
- if (func2 == null)
- {
- func2 = x => Convert.ToByte(Stringz.Substring(x, 2), 0x10);
- }
- return (from x in Enumerable.Range(0, replace.Length)
- where (x % 2) == 0
- select x).Select<int, byte>(func2).ToArray<byte>();
- }
- catch
- {
- MessageBox.Show("Incorrect value (empty)", "StringToByteArray Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return new byte[1];
- }
- }
- public bool SUCCESS(int Void)
- {
- return (Void == 0);
- }
- public PS3Lib.Extension Extension
- {
- get
- {
- return new PS3Lib.Extension(SelectAPI.ControlConsole);
- }
- }
- public enum BuzzerMode
- {
- Continuous,
- Single,
- Double
- }
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int connectConsoleDelegate(string targetIP);
- public class ConsoleInfo
- {
- public string Ip;
- public string Name;
- }
- public enum ConsoleType
- {
- CEX = 1,
- DEX = 2,
- TOOL = 3
- }
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int disconnectConsoleDelegate();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getConnectionStatusDelegate(ref int status);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getConsoleInfoDelegate(int index, IntPtr ptrN, IntPtr ptrI);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getDllVersionDelegate();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getFirmwareInfoDelegate(ref int firmware, ref int ccapi, ref int consoleType);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getNumberOfConsolesDelegate();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getProcessListDelegate(ref uint numberProcesses, IntPtr processIdPtr);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getProcessMemoryDelegate(uint processID, ulong offset, uint size, byte[] buffOut);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getProcessNameDelegate(uint processID, IntPtr strPtr);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int getTemperatureDelegate(ref int cell, ref int rsx);
- public enum IdType
- {
- IDPS,
- PSID
- }
- public enum LedColor
- {
- Green = 1,
- Red = 2
- }
- public enum LedMode
- {
- Off,
- On,
- Blink
- }
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int notifyDelegate(int mode, string msgWChar);
- public enum NotifyIcon
- {
- INFO,
- CAUTION,
- FRIEND,
- SLIDER,
- WRONGWAY,
- DIALOG,
- DIALOGSHADOW,
- TEXT,
- POINTER,
- GRAB,
- HAND,
- PEN,
- FINGER,
- ARROW,
- ARROWRIGHT,
- PROGRESS,
- TROPHY1,
- TROPHY2,
- TROPHY3,
- TROPHY4
- }
- public enum ProcessType
- {
- VSH,
- SYS_AGENT,
- CURRENTGAME
- }
- public enum RebootFlags
- {
- HardReboot = 3,
- ShutDown = 1,
- SoftReboot = 2
- }
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int ringBuzzerDelegate(int type);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int setBootConsoleIdsDelegate(int idType, int on, byte[] ID);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int setConsoleIdsDelegate(int idType, byte[] consoleID);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int setConsoleLedDelegate(int color, int status);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int setProcessMemoryDelegate(uint processID, ulong offset, uint size, byte[] buffIn);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- private delegate int shutdownDelegate(int mode);
- private class System
- {
- public static int connectionID = -1;
- public static uint processID = 0;
- public static uint[] processIDs;
- }
- public class TargetInfo
- {
- public int CCAPI;
- public int ConsoleType;
- public int Firmware;
- public ulong SysTable;
- public int TempCell;
- public int TempRSX;
- }
- }
- }
- //------------------------------------------------------------------------------SOURCE--------------->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement