Advertisement
BaSs_HaXoR

PS3Lib 4.4.6 SOURCE CODE (CCAPI.cs)(10-24-14)

Oct 24th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 32.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Windows.Forms;
  6. using System.Net.NetworkInformation;
  7. using System.Net;
  8. using System.Diagnostics;
  9. using System.Threading;
  10. namespace PS3Lib
  11. {
  12.     public class CCAPI
  13.     {
  14.         public enum BuzzerMode
  15.         {
  16.             Continuous,
  17.             Single,
  18.             Double
  19.         }
  20.         private class CCAPIGlobalPointer
  21.         {
  22.             private IntPtr _intPtr = IntPtr.Zero;
  23.             public CCAPIGlobalPointer(IntPtr intPtr)
  24.             {
  25.                 this._intPtr = intPtr;
  26.             }
  27.             ~CCAPIGlobalPointer()
  28.             {
  29.                 if (this._intPtr != IntPtr.Zero)
  30.                 {
  31.                     Marshal.FreeHGlobal(this._intPtr);
  32.                 }
  33.             }
  34.             public IntPtr GetPtr()
  35.             {
  36.                 return this._intPtr;
  37.             }
  38.         }
  39.         public class ConsoleInfo
  40.         {
  41.             public string Ip;
  42.             public string Name;
  43.         }
  44.         public enum ConsoleType
  45.         {
  46.             CEX = 1,
  47.             DEX,
  48.             TOOL
  49.         }
  50.         public enum LedColor
  51.         {
  52.             Green = 1,
  53.             Red
  54.         }
  55.         public enum LedMode
  56.         {
  57.             Off,
  58.             On,
  59.             Blink
  60.         }
  61.         public enum NotifyIcon
  62.         {
  63.             INFO,
  64.             CAUTION,
  65.             FRIEND,
  66.             SLIDER,
  67.             WRONGWAY,
  68.             DIALOG,
  69.             DIALOGSHADOW,
  70.             TEXT,
  71.             POINTER,
  72.             GRAB,
  73.             HAND,
  74.             PEN,
  75.             FINGER,
  76.             ARROW,
  77.             ARROWRIGHT,
  78.             PROGRESS
  79.         }
  80.         public enum ProcessType
  81.         {
  82.             VSH,
  83.             SYS_AGENT,
  84.             CURRENTGAME
  85.         }
  86.         public enum RebootFlags
  87.         {
  88.             HardReboot = 3,
  89.             ShutDown = 1,
  90.             SoftReboot
  91.         }
  92.         private class System
  93.         {
  94.             public static int connectionID = -1;
  95.             public static uint processID = 0u;
  96.             public static uint[] processIDs;
  97.         }
  98.         public class TargetInfo
  99.         {
  100.             public int CCAPI;
  101.             public int ConsoleType;
  102.             public int Firmware;
  103.             public ulong SysTable;
  104.             public int TempCell;
  105.             public int TempRSX;
  106.         }
  107.         private CCAPI.TargetInfo pInfo = new CCAPI.TargetInfo();
  108.         public Extension Extension
  109.         {
  110.             get
  111.             {
  112.                 return new Extension(SelectAPI.ControlConsole);
  113.             }
  114.         }
  115.         public CCAPI()
  116.         {
  117.  
  118.         }
  119.  
  120.         public string BaSs_HaXoRwazHere()
  121.         {
  122.             string text = "Sup bro. Fancy meeting you here! ;p";
  123.             return MessageBox.Show(string.Concat(new string[]
  124.             {
  125.                 text,
  126.                 Environment.NewLine,
  127.                 "Go check out my youtube channel :D",
  128.                 Environment.NewLine,
  129.                 "www.youtube.com/CODNoobFriendly"
  130.             })).ToString();
  131.         }
  132.  
  133.         #region Get Mac and IP of PS3
  134.         #region OUIFingerprint
  135.         private string PS3OUIs = @"
  136. 00:1D:0D   
  137. 00:1F:A7
  138. 00:24:8D
  139. 00:D9:D1
  140. 28:0D:FC
  141. 70:9E:29
  142. A8:E3:EE
  143. F8:D0:AC
  144. FC:0F:E6
  145. 001D0D 
  146. 001FA7
  147. 00248D
  148. 00D9D1
  149. 280DFC
  150. 709E29
  151. A8E3EE
  152. F8D0AC
  153. FC0FE6
  154.  
  155. 00248D
  156. 271769
  157. 0023f8
  158. 0019c5
  159. FC0FE6
  160. 002248
  161. A8E3EE
  162. 00041F
  163. 001315
  164. 0015C1
  165. 0019C5
  166. 001D0D
  167. 001FA7
  168. 00:24:8D
  169. 27:17:69
  170. 00:23:f8
  171. 00:19:c5
  172. FC:0F:E6
  173. 00:22:48
  174. A8:E3:EE
  175. 00:04:1F
  176. 00:13:15
  177. 00:15:C1
  178. 00:19:C5
  179. 00:1D:0D
  180. 00:1F:A7
  181. ";
  182.         #endregion
  183.        // public string ConsoleIP = null;
  184.        // public string ConsoleMac = null;
  185.        /* private void getpastie()
  186.         {
  187.             WebClient client = new WebClient();
  188.             PS3OUIs = client.DownloadString("http://pastebin.com/raw.php?i=BpcKRq64");
  189.         }*/
  190.  
  191.         #region NetSniff
  192.         [StructLayout(LayoutKind.Sequential)]
  193.         struct MIB_IPNETROW
  194.         {
  195.             [MarshalAs(UnmanagedType.U4)]
  196.             public int dwIndex;
  197.             [MarshalAs(UnmanagedType.U4)]
  198.             public int dwPhysAddrLen;
  199.             [MarshalAs(UnmanagedType.U1)]
  200.             public byte mac0;
  201.             [MarshalAs(UnmanagedType.U1)]
  202.             public byte mac1;
  203.             [MarshalAs(UnmanagedType.U1)]
  204.             public byte mac2;
  205.             [MarshalAs(UnmanagedType.U1)]
  206.             public byte mac3;
  207.             [MarshalAs(UnmanagedType.U1)]
  208.             public byte mac4;
  209.             [MarshalAs(UnmanagedType.U1)]
  210.             public byte mac5;
  211.             [MarshalAs(UnmanagedType.U1)]
  212.             public byte mac6;
  213.             [MarshalAs(UnmanagedType.U1)]
  214.             public byte mac7;
  215.             [MarshalAs(UnmanagedType.U4)]
  216.             public int dwAddr;
  217.             [MarshalAs(UnmanagedType.U4)]
  218.             public int dwType;
  219.         }
  220.  
  221.         /// <summary>
  222.         /// GetIpNetTable external method
  223.         /// </summary>
  224.         /// <param name="pIpNetTable"></param>
  225.         /// <param name="pdwSize"></param>
  226.         /// <param name="bOrder"></param>
  227.         /// <returns></returns>
  228.         [DllImport("IpHlpApi.dll")]
  229.         [return: MarshalAs(UnmanagedType.U4)]
  230.         static extern int GetIpNetTable(IntPtr pIpNetTable,
  231.               [MarshalAs(UnmanagedType.U4)] ref int pdwSize, bool bOrder);
  232.  
  233.         /// <summary>
  234.         /// Error codes GetIpNetTable returns that we recognise
  235.         /// </summary>
  236.         const int ERROR_INSUFFICIENT_BUFFER = 122;
  237.         /// <summary>
  238.         /// Get the IP and MAC addresses of all known devices on the LAN
  239.         /// </summary>
  240.         /// <remarks>
  241.         /// 1) This table is not updated often - it can take some human-scale time
  242.         ///    to notice that a device has dropped off the network, or a new device
  243.         ///    has connected.
  244.         /// 2) This discards non-local devices if they are found - these are multicast
  245.         ///    and can be discarded by IP address range.
  246.         /// </remarks>
  247.         /// <returns></returns>
  248.  
  249.         private static Dictionary<IPAddress, PhysicalAddress> GetAllDevicesOnLAN()
  250.         {
  251.             Dictionary<IPAddress, PhysicalAddress> all = new Dictionary<IPAddress, PhysicalAddress>();
  252.             // Add this PC to the list...
  253.             all.Add(GetIPAddress(), GetMacAddress());
  254.             int spaceForNetTable = 0;
  255.             // Get the space needed
  256.             // We do that by requesting the table, but not giving any space at all.
  257.             // The return value will tell us how much we actually need.
  258.             GetIpNetTable(IntPtr.Zero, ref spaceForNetTable, false);
  259.             // Allocate the space
  260.             // We use a try-finally block to ensure release.
  261.             IntPtr rawTable = IntPtr.Zero;
  262.             try
  263.             {
  264.                 rawTable = Marshal.AllocCoTaskMem(spaceForNetTable);
  265.                 // Get the actual data
  266.                 int errorCode = GetIpNetTable(rawTable, ref spaceForNetTable, false);
  267.                 if (errorCode != 0)
  268.                 {
  269.                     // Failed for some reason - can do no more here.
  270.                     throw new Exception(string.Format(
  271.                       "Unable to retrieve network table. Error code {0}", errorCode));
  272.                 }
  273.                 // Get the rows count
  274.                 int rowsCount = Marshal.ReadInt32(rawTable);
  275.                 IntPtr currentBuffer = new IntPtr(rawTable.ToInt64() + Marshal.SizeOf(typeof(Int32)));
  276.                 // Convert the raw table to individual entries
  277.                 MIB_IPNETROW[] rows = new MIB_IPNETROW[rowsCount];
  278.                 for (int index = 0; index < rowsCount; index++)
  279.                 {
  280.                     rows[index] = (MIB_IPNETROW)Marshal.PtrToStructure(new IntPtr(currentBuffer.ToInt64() +
  281.                                                 (index * Marshal.SizeOf(typeof(MIB_IPNETROW)))
  282.                                                ),
  283.                                                 typeof(MIB_IPNETROW));
  284.                 }
  285.                 // Define the dummy entries list (we can discard these)
  286.                 PhysicalAddress virtualMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
  287.                 PhysicalAddress broadcastMAC = new PhysicalAddress(new byte[] { 255, 255, 255, 255, 255, 255 });
  288.                 foreach (MIB_IPNETROW row in rows)
  289.                 {
  290.                     IPAddress ip = new IPAddress(BitConverter.GetBytes(row.dwAddr));
  291.                     byte[] rawMAC = new byte[] { row.mac0, row.mac1, row.mac2, row.mac3, row.mac4, row.mac5 };
  292.                     PhysicalAddress pa = new PhysicalAddress(rawMAC);
  293.                     if (!pa.Equals(virtualMAC) && !pa.Equals(broadcastMAC) && !IsMulticast(ip))
  294.                     {
  295.                         //Console.WriteLine("IP: {0}\t\tMAC: {1}", ip.ToString(), pa.ToString());
  296.                         if (!all.ContainsKey(ip))
  297.                         {
  298.                             all.Add(ip, pa);
  299.                         }
  300.                     }
  301.                 }
  302.             }
  303.             finally
  304.             {
  305.                 // Release the memory.
  306.                 Marshal.FreeCoTaskMem(rawTable);
  307.             }
  308.             return all;
  309.         }
  310.  
  311.         /// <summary>
  312.         /// Gets the IP address of the current PC
  313.         /// </summary>
  314.         /// <returns></returns>
  315.         private static IPAddress GetIPAddress()
  316.         {
  317.             String strHostName = Dns.GetHostName();
  318.             IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
  319.             IPAddress[] addr = ipEntry.AddressList;
  320.             foreach (IPAddress ip in addr)
  321.             {
  322.                 if (!ip.IsIPv6LinkLocal)
  323.                 {
  324.                     return (ip);
  325.                 }
  326.             }
  327.             return addr.Length > 0 ? addr[0] : null;
  328.         }
  329.  
  330.         /// <summary>
  331.         /// Gets the MAC address of the current PC.
  332.         /// </summary>
  333.         /// <returns></returns>
  334.         private static PhysicalAddress GetMacAddress()
  335.         {
  336.             foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
  337.             {
  338.                 // Only consider Ethernet network interfaces
  339.                 if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
  340.                     nic.OperationalStatus == OperationalStatus.Up)
  341.                 {
  342.                     return nic.GetPhysicalAddress();
  343.                 }
  344.             }
  345.             return null;
  346.         }
  347.  
  348.         /// <summary>
  349.         /// Returns true if the specified IP address is a multicast address
  350.         /// </summary>
  351.         /// <param name="ip"></param>
  352.         /// <returns></returns>
  353.         private static bool IsMulticast(IPAddress ip)
  354.         {
  355.             bool result = true;
  356.             if (!ip.IsIPv6Multicast)
  357.             {
  358.                 byte highIP = ip.GetAddressBytes()[0];
  359.                 if (highIP < 224 || highIP > 239)
  360.                 {
  361.                     result = false;
  362.                 }
  363.             }
  364.             return result;
  365.         }
  366.  
  367.         #endregion
  368.         //
  369.         public string[] searchNetwork()
  370.         {
  371.             PS3API PS3 = new PS3API(SelectAPI.ControlConsole);
  372.             Dictionary<IPAddress, PhysicalAddress> all = GetAllDevicesOnLAN();
  373.             foreach (KeyValuePair<IPAddress, PhysicalAddress> kvp in all)
  374.             {
  375.                 string Consoles = "";//clear console
  376.                 string infos = "IP: " + kvp.Key + Environment.NewLine + "Mac: " + kvp.Value;
  377.                 //http://pastebin.com/yKLTzdW8
  378.                 string fullmacaddress = Convert.ToString(kvp.Value);
  379.                 fullmacaddress = fullmacaddress.Substring(0, 6);
  380.                 MessageBox.Show("" + kvp.Key);
  381.                 if (PS3OUIs.Contains(fullmacaddress))
  382.                 {
  383.                     string[] consoleandmacs = null;
  384.                     string ip = Convert.ToString(kvp.Key);
  385.                     string mac = Convert.ToString(kvp.Value);
  386.                     Consoles = Consoles + ip + Environment.NewLine + mac + " ";
  387.                     consoleandmacs = new[] { Consoles };
  388.                     MessageBox.Show("" + kvp.Key);
  389.                 }
  390.             }
  391.             return new string[0];
  392.         }
  393.  
  394.         private string MACIP;
  395.         public void CCAPIConnect()
  396.         {
  397.             PS3API PS3 = new PS3API(SelectAPI.ControlConsole);
  398.             Dictionary<IPAddress, PhysicalAddress> all = GetAllDevicesOnLAN();
  399.             foreach (KeyValuePair<IPAddress, PhysicalAddress> kvp in all)
  400.             {
  401.                 Thread.Sleep(100);
  402.                 //"IP : {0}\n MAC {1}" +
  403.                 string infos = "IP: " + kvp.Key + Environment.NewLine + "Mac: " + kvp.Value;
  404.                 //  MessageBox.Show(infos);
  405.                 //   consoleandmacs = new [] { infos };
  406.                 //http://pastebin.com/yKLTzdW8
  407.                 MessageBox.Show(infos);
  408.                 string fullmacaddress = Convert.ToString(kvp.Value);
  409.  
  410.                 if (fullmacaddress.Length >= 6)
  411.                 {
  412.                     fullmacaddress = fullmacaddress.Substring(0, 6);
  413.                 }
  414.                 else
  415.                 {
  416.                     try
  417.                     {
  418.                         fullmacaddress = fullmacaddress.Substring(0, 3);
  419.                     }
  420.                     catch
  421.                     {
  422.                         MessageBox.Show("Error getting Macaddresses on the Network!");
  423.                         MessageBox.Show(fullmacaddress);
  424.                     }
  425.                 }
  426.                 if (PS3OUIs.Contains(fullmacaddress))
  427.                 {
  428.                     MACIP = kvp.Key.ToString();
  429.                     if (PS3.ConnectTarget(MACIP))
  430.                     {
  431.                         PS3.CCAPI.RingBuzzer(CCAPI.BuzzerMode.Double);
  432.                         //   PS3.CCAPI.BaSs_HaXoRwazHere();
  433.                         return;
  434.                     }
  435.                     else
  436.                     {
  437.                         MessageBox.Show("Failed to connect to Console!");
  438.                         // PS3.ConnectTarget("192.168.137.201");
  439.                         //PS3.CCAPI.Notify(CCAPI.NotifyIcon.WRONGWAY, "Failed!");
  440.                     }
  441.                 }
  442.                 else
  443.                 {
  444.                     MessageBox.Show("No PS3 Consoles found on your Network!");
  445.                 }
  446.             }
  447.         }
  448.         #endregion
  449.  
  450.         private bool IsValidHexString(IEnumerable<char> hexString)
  451.         {
  452.             return (
  453.                 from currentCharacter in hexString
  454.                 select (currentCharacter >= '0' && currentCharacter <= '9') || (currentCharacter >= 'a' && currentCharacter <= 'f') || (currentCharacter >= 'A' && currentCharacter <= 'F')).All((bool isHexCharacter) => isHexCharacter);
  455.         }
  456.         private byte[] HexStringToByteArray(string hex)
  457.         {
  458.             return (
  459.                 from x in Enumerable.Range(0, hex.Length)
  460.                 where x % 2 == 0
  461.                 select Convert.ToByte(hex.Substring(x, 2), 16)).ToArray<byte>();
  462.         }
  463.         public void SetPSID(string PSID)
  464.         {
  465.             if (this.IsValidHexString(PSID) && PSID.Length == 32)
  466.             {
  467.                 byte[] buffer = this.HexStringToByteArray(PSID);
  468.                 this.SetLv2Memory(9223372036859580196uL, buffer);
  469.             }
  470.             else
  471.             {
  472.                 MessageBox.Show("Check Your PSID. Wrong Length or Hex Chars.");
  473.             }
  474.         }
  475.         public string GetConsoleID()
  476.         {
  477.             byte[] array = new byte[16];
  478.             this.GetLv2Memory(9223372036858981040uL, array);
  479.             return BitConverter.ToString(array).Replace("-", " ");
  480.         }
  481.         [DllImport("CCAPI2.dll", CallingConvention = CallingConvention.Cdecl)]
  482.         private static extern int getLv1Memory(int connectionId, ulong offset, uint size, byte[] buffOut);
  483.         public int GetLv1Memory(uint offset, byte[] buffer)
  484.         {
  485.             return CCAPI.getLv1Memory(CCAPI.System.connectionID, (ulong)offset, (uint)buffer.Length, buffer);
  486.         }
  487.         public int GetLv1Memory(ulong offset, byte[] buffer)
  488.         {
  489.             return CCAPI.getLv1Memory(CCAPI.System.connectionID, offset, (uint)buffer.Length, buffer);
  490.         }
  491.         [DllImport("CCAPI2.dll", CallingConvention = CallingConvention.Cdecl)]
  492.         private static extern int getLv2Memory(int connectionId, ulong offset, uint size, byte[] buffOut);
  493.         public int GetLv2Memory(ulong offset, byte[] buffer)
  494.         {
  495.             return CCAPI.getLv2Memory(CCAPI.System.connectionID, offset, (uint)buffer.Length, buffer);
  496.         }
  497.         [DllImport("CCAPI2.dll", CallingConvention = CallingConvention.Cdecl)]
  498.         private static extern int setLv1Memory(int connectionId, ulong offset, uint size, byte[] buffIn);
  499.         public int SetLv1Memory(uint offset, byte[] buffer)
  500.         {
  501.             return CCAPI.setLv1Memory(CCAPI.System.connectionID, (ulong)offset, (uint)buffer.Length, buffer);
  502.         }
  503.         public int SetLv1Memory(ulong offset, byte[] buffer)
  504.         {
  505.             return CCAPI.setLv1Memory(CCAPI.System.connectionID, offset, (uint)buffer.Length, buffer);
  506.         }
  507.         [DllImport("CCAPI2.dll", CallingConvention = CallingConvention.Cdecl)]
  508.         private static extern int setLv2Memory(int connectionId, ulong offset, uint size, byte[] buffIn);
  509.         public int SetLv2Memory(ulong offset, byte[] buffer)
  510.         {
  511.             return CCAPI.setLv2Memory(CCAPI.System.connectionID, offset, (uint)buffer.Length, buffer);
  512.         }
  513.         public string GetPSID()
  514.         {
  515.             byte[] array = new byte[16];
  516.             this.GetLv2Memory(9223372036859580196uL, array);
  517.             return BitConverter.ToString(array).Replace("-", " ");
  518.         }
  519.         public int AttachProcess()
  520.         {
  521.             CCAPI.System.processID = 0u;
  522.             int num = this.GetProcessList(out CCAPI.System.processIDs);
  523.             int result;
  524.             if (!this.SUCCESS(num) || CCAPI.System.processIDs.Length <= 0)
  525.             {
  526.                 result = -1;
  527.             }
  528.             else
  529.             {
  530.                 for (int i = 0; i < CCAPI.System.processIDs.Length; i++)
  531.                 {
  532.                     string empty = string.Empty;
  533.                     num = this.GetProcessName(CCAPI.System.processIDs[i], out empty);
  534.                     if (!this.SUCCESS(num))
  535.                     {
  536.                         break;
  537.                     }
  538.                     if (!empty.Contains("flash"))
  539.                     {
  540.                         CCAPI.System.processID = CCAPI.System.processIDs[i];
  541.                         break;
  542.                     }
  543.                     num = -1;
  544.                 }
  545.                 if (CCAPI.System.processID == 0u)
  546.                 {
  547.                     CCAPI.System.processID = CCAPI.System.processIDs[CCAPI.System.processIDs.Length - 1];
  548.                 }
  549.                 result = num;
  550.             }
  551.             return result;
  552.         }
  553.         public int AttachProcess(CCAPI.ProcessType procType)
  554.         {
  555.             CCAPI.System.processID = 0u;
  556.             int num = this.GetProcessList(out CCAPI.System.processIDs);
  557.             int result;
  558.             if (num < 0 || CCAPI.System.processIDs.Length <= 0)
  559.             {
  560.                 result = -1;
  561.             }
  562.             else
  563.             {
  564.                 for (int i = 0; i < CCAPI.System.processIDs.Length; i++)
  565.                 {
  566.                     string empty = string.Empty;
  567.                     num = this.GetProcessName(CCAPI.System.processIDs[i], out empty);
  568.                     if (num < 0)
  569.                     {
  570.                         break;
  571.                     }
  572.                     if (procType == CCAPI.ProcessType.VSH && empty.Contains("vsh"))
  573.                     {
  574.                         CCAPI.System.processID = CCAPI.System.processIDs[i];
  575.                         break;
  576.                     }
  577.                     if (procType == CCAPI.ProcessType.SYS_AGENT && empty.Contains("agent"))
  578.                     {
  579.                         CCAPI.System.processID = CCAPI.System.processIDs[i];
  580.                         break;
  581.                     }
  582.                     if (procType == CCAPI.ProcessType.CURRENTGAME && !empty.Contains("flash"))
  583.                     {
  584.                         CCAPI.System.processID = CCAPI.System.processIDs[i];
  585.                         break;
  586.                     }
  587.                 }
  588.                 if (CCAPI.System.processID == 0u)
  589.                 {
  590.                     CCAPI.System.processID = CCAPI.System.processIDs[CCAPI.System.processIDs.Length - 1];
  591.                 }
  592.                 result = num;
  593.             }
  594.             return result;
  595.         }
  596.         public int AttachProcess(uint process)
  597.         {
  598.             uint[] array = new uint[64];
  599.             int num = this.GetProcessList(out array);
  600.             int num2;
  601.             int result;
  602.             if (this.SUCCESS(num))
  603.             {
  604.                 for (int i = 0; i < array.Length; i++)
  605.                 {
  606.                     if (array[i] == process)
  607.                     {
  608.                         num = 0;
  609.                         CCAPI.System.processID = process;
  610.                         num2 = num;
  611.                         result = num2;
  612.                         return result;
  613.                     }
  614.                     num = -1;
  615.                 }
  616.             }
  617.             num2 = num;
  618.             result = num2;
  619.             return result;
  620.         }
  621.         public void ClearTargetInfo()
  622.         {
  623.             this.pInfo = new CCAPI.TargetInfo();
  624.         }
  625.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi16closeTargetCommsEv")]
  626.         private static extern int closeTargetComms();
  627.         private void CompleteInfo(ref CCAPI.TargetInfo Info, int fw, int ccapi, ulong sysTable, int consoleType, int tempCELL, int tempRSX)
  628.         {
  629.             Info.Firmware = fw;
  630.             Info.CCAPI = ccapi;
  631.             Info.SysTable = sysTable;
  632.             Info.ConsoleType = consoleType;
  633.             Info.TempCell = tempCELL;
  634.             Info.TempRSX = tempRSX;
  635.         }
  636.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi14connectConsoleEPKc")]
  637.         private static extern int connectConsole(string targetIP);
  638.         public int ConnectTarget(string targetIP)
  639.         {
  640.             if (this.SUCCESS(CCAPI.System.connectionID))
  641.             {
  642.                 CCAPI.disconnectConsole(CCAPI.System.connectionID);
  643.             }
  644.             CCAPI.initTargetComms();
  645.             CCAPI.System.connectionID = CCAPI.connectConsole(targetIP);
  646.             CCAPI cCAPI = new CCAPI();
  647.             cCAPI.Notify(CCAPI.NotifyIcon.FRIEND, "PS3Lib(4.4) [UNOFFICIAL]: By BaSs_HaXoR");
  648.             return CCAPI.System.connectionID;
  649.         }
  650.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi17disconnectConsoleEi")]
  651.         private static extern int disconnectConsole(int connectionID);
  652.         public int DisconnectTarget()
  653.         {
  654.             return CCAPI.disconnectConsole(CCAPI.System.connectionID);
  655.         }
  656.         public uint GetAttachedProcess()
  657.         {
  658.             return CCAPI.System.processID;
  659.         }
  660.         public byte[] GetBytes(uint offset, uint length)
  661.         {
  662.             byte[] array = new byte[length];
  663.             this.GetMemory(offset, array);
  664.             return array;
  665.         }
  666.         public byte[] GetBytes(ulong offset, uint length)
  667.         {
  668.             byte[] array = new byte[length];
  669.             this.GetMemory(offset, array);
  670.             return array;
  671.         }
  672.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN8Settings14getConsoleInfoEiPcS0_")]
  673.         private static extern int getConsoleInfo(int index, IntPtr ptrN, IntPtr ptrI);
  674.         public List<CCAPI.ConsoleInfo> GetConsoleList()
  675.         {
  676.             List<CCAPI.ConsoleInfo> list = new List<CCAPI.ConsoleInfo>();
  677.             int numberOfConsoles = CCAPI.getNumberOfConsoles();
  678.             IntPtr intPtr = Marshal.AllocHGlobal(256);
  679.             IntPtr intPtr2 = Marshal.AllocHGlobal(256);
  680.             for (int i = 0; i < numberOfConsoles; i++)
  681.             {
  682.                 CCAPI.ConsoleInfo consoleInfo = new CCAPI.ConsoleInfo();
  683.                 CCAPI.getConsoleInfo(i, intPtr, intPtr2);
  684.                 consoleInfo.Name = Marshal.PtrToStringAnsi(intPtr);
  685.                 consoleInfo.Ip = Marshal.PtrToStringAnsi(intPtr2);
  686.                 list.Add(consoleInfo);
  687.             }
  688.             Marshal.FreeHGlobal(intPtr);
  689.             Marshal.FreeHGlobal(intPtr2);
  690.             return list;
  691.         }
  692.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi13getDllVersionEv")]
  693.         private static extern int getDllVersion();
  694.         public int GetDllVersion()
  695.         {
  696.             return CCAPI.getDllVersion();
  697.         }
  698.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi15getFirmwareInfoEiPiS0_PyS0_")]
  699.         private static extern int getFirmwareInfo(int connectionId, ref int firmware, ref int ccapi, ref ulong systable, ref int consoleType);
  700.         public string GetFirmwareType()
  701.         {
  702.             if (this.pInfo.ConsoleType.ToString() == "")
  703.             {
  704.                 this.GetTargetInfo(out this.pInfo);
  705.             }
  706.             string text = string.Empty;
  707.             string result;
  708.             if (this.pInfo.ConsoleType == 1)
  709.             {
  710.                 result = "CEX";
  711.             }
  712.             else
  713.             {
  714.                 if (this.pInfo.ConsoleType == 2)
  715.                 {
  716.                     result = "DEX";
  717.                 }
  718.                 else
  719.                 {
  720.                     if (this.pInfo.ConsoleType == 3)
  721.                     {
  722.                         text = "TOOL";
  723.                     }
  724.                     result = text;
  725.                 }
  726.             }
  727.             return result;
  728.         }
  729.         public string GetFirmwareVersion()
  730.         {
  731.             if (this.pInfo.Firmware == 0)
  732.             {
  733.                 this.GetTargetInfo();
  734.             }
  735.             string text = this.pInfo.Firmware.ToString("X8");
  736.             string str = text.Substring(1, 1) + ".";
  737.             string str2 = text.Substring(3, 1);
  738.             string str3 = text.Substring(4, 1);
  739.             return str + str2 + str3;
  740.         }
  741.         public int GetMemory(uint offset, byte[] buffer)
  742.         {
  743.             return CCAPI.getProcessMemory(CCAPI.System.connectionID, CCAPI.System.processID, (ulong)offset, (uint)buffer.Length, buffer);
  744.         }
  745.         public int GetMemory(ulong offset, byte[] buffer)
  746.         {
  747.             return CCAPI.getProcessMemory(CCAPI.System.connectionID, CCAPI.System.processID, offset, (uint)buffer.Length, buffer);
  748.         }
  749.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN8Settings19getNumberOfConsolesEv")]
  750.         private static extern int getNumberOfConsoles();
  751.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi14getProcessListEiPjS0_")]
  752.         private static extern int getProcessList(int connectionID, ref uint numberProcesses, IntPtr processIdPtr);
  753.         public int GetProcessList(out uint[] processIds)
  754.         {
  755.             uint num = 0u;
  756.             CCAPI.CCAPIGlobalPointer cCAPIGlobalPointer = new CCAPI.CCAPIGlobalPointer(Marshal.AllocHGlobal(256));
  757.             int processList = CCAPI.getProcessList(CCAPI.System.connectionID, ref num, cCAPIGlobalPointer.GetPtr());
  758.             processIds = new uint[num];
  759.             if (this.SUCCESS(processList))
  760.             {
  761.                 IntPtr unBuf = cCAPIGlobalPointer.GetPtr();
  762.                 for (uint num2 = 0u; num2 < num; num2 += 1u)
  763.                 {
  764.                     unBuf = this.ReadDataFromUnBufPtr<uint>(unBuf, ref processIds[(int)((uint)((UIntPtr)num2))]);
  765.                 }
  766.             }
  767.             return processList;
  768.         }
  769.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi16getProcessMemoryEijyjPh")]
  770.         private static extern int getProcessMemory(int connectionID, uint processID, ulong offset, uint size, byte[] buffOut);
  771.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi14getProcessNameEijPc")]
  772.         private static extern int getProcessName(int connectionID, uint processID, IntPtr strPtr);
  773.         public int GetProcessName(uint processId, out string name)
  774.         {
  775.             IntPtr intPtr = Marshal.AllocHGlobal(529);
  776.             int processName = CCAPI.getProcessName(CCAPI.System.connectionID, processId, intPtr);
  777.             name = string.Empty;
  778.             if (this.SUCCESS(processName))
  779.             {
  780.                 name = Marshal.PtrToStringAnsi(intPtr);
  781.             }
  782.             return processName;
  783.         }
  784.         private int GetTargetInfo()
  785.         {
  786.             int[] array = new int[2];
  787.             int fw = 0;
  788.             int ccapi = 0;
  789.             int consoleType = 0;
  790.             ulong sysTable = 0uL;
  791.             int num = CCAPI.getFirmwareInfo(CCAPI.System.connectionID, ref fw, ref ccapi, ref sysTable, ref consoleType);
  792.             int num2;
  793.             int result;
  794.             if (num >= 0)
  795.             {
  796.                 CCAPI.CCAPIGlobalPointer cCAPIGlobalPointer = new CCAPI.CCAPIGlobalPointer(Marshal.AllocHGlobal(8));
  797.                 num = CCAPI.getTemperature(CCAPI.System.connectionID, cCAPIGlobalPointer.GetPtr());
  798.                 if (num < 0)
  799.                 {
  800.                     num2 = num;
  801.                     result = num2;
  802.                     return result;
  803.                 }
  804.                 IntPtr unBuf = cCAPIGlobalPointer.GetPtr();
  805.                 for (uint num3 = 0u; num3 < 2u; num3 += 1u)
  806.                 {
  807.                     unBuf = this.ReadDataFromUnBufPtr<int>(unBuf, ref array[(int)((uint)((UIntPtr)num3))]);
  808.                 }
  809.                 this.CompleteInfo(ref this.pInfo, fw, ccapi, sysTable, consoleType, array[0], array[1]);
  810.             }
  811.             num2 = num;
  812.             result = num2;
  813.             return result;
  814.         }
  815.         public int GetTargetInfo(out CCAPI.TargetInfo Info)
  816.         {
  817.             Info = new CCAPI.TargetInfo();
  818.             int[] array = new int[2];
  819.             int fw = 0;
  820.             int ccapi = 0;
  821.             int consoleType = 0;
  822.             ulong sysTable = 0uL;
  823.             int num = CCAPI.getFirmwareInfo(CCAPI.System.connectionID, ref fw, ref ccapi, ref sysTable, ref consoleType);
  824.             int num2;
  825.             int result;
  826.             if (num >= 0)
  827.             {
  828.                 CCAPI.CCAPIGlobalPointer cCAPIGlobalPointer = new CCAPI.CCAPIGlobalPointer(Marshal.AllocHGlobal(8));
  829.                 num = CCAPI.getTemperature(CCAPI.System.connectionID, cCAPIGlobalPointer.GetPtr());
  830.                 if (num < 0)
  831.                 {
  832.                     num2 = num;
  833.                     result = num2;
  834.                     return result;
  835.                 }
  836.                 IntPtr unBuf = cCAPIGlobalPointer.GetPtr();
  837.                 for (uint num3 = 0u; num3 < 2u; num3 += 1u)
  838.                 {
  839.                     unBuf = this.ReadDataFromUnBufPtr<int>(unBuf, ref array[(int)((uint)((UIntPtr)num3))]);
  840.                 }
  841.                 this.CompleteInfo(ref Info, fw, ccapi, sysTable, consoleType, array[0], array[1]);
  842.                 this.CompleteInfo(ref this.pInfo, fw, ccapi, sysTable, consoleType, array[0], array[1]);
  843.             }
  844.             num2 = num;
  845.             result = num2;
  846.             return result;
  847.         }
  848.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi14getTemperatureEiPj")]
  849.         private static extern int getTemperature(int connectionId, IntPtr tempPtr);
  850.         public string GetTemperatureCELL()
  851.         {
  852.             if (this.pInfo.TempCell == 0)
  853.             {
  854.                 this.GetTargetInfo(out this.pInfo);
  855.             }
  856.             return this.pInfo.TempCell.ToString() + " C";
  857.         }
  858.         public string GetTemperatureRSX()
  859.         {
  860.             if (this.pInfo.TempRSX == 0)
  861.             {
  862.                 this.GetTargetInfo(out this.pInfo);
  863.             }
  864.             return this.pInfo.TempRSX.ToString() + " C";
  865.         }
  866.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi15initTargetCommsEv")]
  867.         private static extern int initTargetComms();
  868.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi6notifyEiiPw")]
  869.         private static extern int notify(int connectionId, int mode, [MarshalAs(UnmanagedType.LPWStr)] string msgWChar);
  870.         public int Notify(CCAPI.NotifyIcon icon, string message)
  871.         {
  872.             return CCAPI.notify(CCAPI.System.connectionID, (int)icon, message);
  873.         }
  874.         public int Notify(int icon, string message)
  875.         {
  876.             return CCAPI.notify(CCAPI.System.connectionID, icon, message);
  877.         }
  878.         private IntPtr ReadDataFromUnBufPtr<T>(IntPtr unBuf, ref T storage)
  879.         {
  880.             storage = (T)((object)Marshal.PtrToStructure(unBuf, typeof(T)));
  881.             return new IntPtr(unBuf.ToInt64() + (long)Marshal.SizeOf(storage));
  882.         }
  883.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi10ringBuzzerEii")]
  884.         private static extern int ringBuzzer(int connectionId, int type);
  885.         public int RingBuzzer(CCAPI.BuzzerMode flag)
  886.         {
  887.             return CCAPI.ringBuzzer(CCAPI.System.connectionID, (int)flag);
  888.         }
  889.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi12setConsoleIDEiPh")]
  890.         private static extern int setConsoleID(int connectionId, byte[] consoleID);
  891.         public int SetConsoleID(string consoleID)
  892.         {
  893.             string hex = string.Empty;
  894.             if (consoleID.Length >= 32)
  895.             {
  896.                 hex = consoleID.Substring(0, 32);
  897.             }
  898.             return CCAPI.setConsoleID(CCAPI.System.connectionID, CCAPI.StringToByteArray(hex));
  899.         }
  900.         public int SetConsoleID(byte[] consoleID)
  901.         {
  902.             return CCAPI.setConsoleID(CCAPI.System.connectionID, consoleID);
  903.         }
  904.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi13setConsoleLedEiii")]
  905.         private static extern int setConsoleLed(int connectionId, int color, int status);
  906.         public int SetConsoleLed(CCAPI.LedColor color, CCAPI.LedMode mode)
  907.         {
  908.             return CCAPI.setConsoleLed(CCAPI.System.connectionID, (int)color, (int)mode);
  909.         }
  910.         public int SetMemory(uint offset, byte[] buffer)
  911.         {
  912.             return CCAPI.setProcessMemory(CCAPI.System.connectionID, CCAPI.System.processID, (ulong)offset, (uint)buffer.Length, buffer);
  913.         }
  914.         public int SetMemory(ulong offset, byte[] buffer)
  915.         {
  916.             return CCAPI.setProcessMemory(CCAPI.System.connectionID, CCAPI.System.processID, offset, (uint)buffer.Length, buffer);
  917.         }
  918.         public int SetMemory(ulong offset, string hexadecimal, EndianType Type = EndianType.LittleEndian)
  919.         {
  920.             byte[] array = CCAPI.StringToByteArray(hexadecimal);
  921.             if (Type == EndianType.LittleEndian)
  922.             {
  923.                 Array.Reverse(array);
  924.             }
  925.             return CCAPI.setProcessMemory(CCAPI.System.connectionID, CCAPI.System.processID, offset, (uint)array.Length, array);
  926.         }
  927.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi16setProcessMemoryEijyjPh")]
  928.         private static extern int setProcessMemory(int connectionID, uint processID, ulong offset, uint size, byte[] buffIn);
  929.         [DllImport("CCAPI.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "_ZN5CcApi8shutdownEii")]
  930.         private static extern int shutdown(int connectionId, int mode);
  931.         public int ShutDown(CCAPI.RebootFlags flag)
  932.         {
  933.             return CCAPI.shutdown(CCAPI.System.connectionID, (int)flag);
  934.         }
  935.         internal static byte[] StringToByteArray(string hex)
  936.         {
  937.             Func<int, byte> func = null;
  938.             Func<int, byte> func2 = null;
  939.             string replace = hex.Replace("0x", "");
  940.             string Stringz = replace.Insert(replace.Length - 1, "0");
  941.             bool flag;
  942.             if (replace.Length % 2 == 0)
  943.             {
  944.                 flag = true;
  945.             }
  946.             else
  947.             {
  948.                 flag = false;
  949.             }
  950.             byte[] array;
  951.             byte[] result;
  952.             byte[] array2;
  953.             try
  954.             {
  955.                 if (flag)
  956.                 {
  957.                     if (func == null)
  958.                     {
  959.                         func = ((int x) => Convert.ToByte(replace.Substring(x, 2), 16));
  960.                     }
  961.                     array = (
  962.                         from x in Enumerable.Range(0, replace.Length)
  963.                         where x % 2 == 0
  964.                         select x).Select(func).ToArray<byte>();
  965.                     result = array;
  966.                     return result;
  967.                 }
  968.                 if (func2 == null)
  969.                 {
  970.                     func2 = ((int x) => Convert.ToByte(Stringz.Substring(x, 2), 16));
  971.                 }
  972.                 array2 = (
  973.                     from x in Enumerable.Range(0, replace.Length)
  974.                     where x % 2 == 0
  975.                     select x).Select(func2).ToArray<byte>();
  976.             }
  977.             catch
  978.             {
  979.                 throw new ArgumentException("Value not possible.", "Byte Array");
  980.             }
  981.             array = array2;
  982.             result = array;
  983.             return result;
  984.         }
  985.         public bool SUCCESS(int Void)
  986.         {
  987.             return Void >= 0;
  988.         }
  989.     }
  990. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement