diff --git a/Windows/Libraries/OrbisLib/Common/API/API.cs b/Windows/Libraries/OrbisLib/Common/API/API.cs new file mode 100644 index 0000000..4c9fa33 --- /dev/null +++ b/Windows/Libraries/OrbisLib/Common/API/API.cs @@ -0,0 +1,167 @@ +using System.Net.Sockets; + +namespace OrbisSuite.Common +{ + public static class API + { + /// + /// Connects to the API. + /// + /// Address we would like to connnect to. + /// The socket we have connected on. + /// Returns true if we successfully connected. + public static bool Connect(string IPAddr, int Port, out Socket Sock) + { + Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + + try + { + return Sock.EasyConnect(IPAddr, Port, 2000); + } + catch + { + + } + + return false; + } + + /// + /// Short API Call used when you only need to send the initial packet and no additional data. + /// + /// Address to send to. + /// The initial Packet Data. + /// Returns the result of the action. + public static APIResults Call(string IPAddr, int Port, APIPacket Packet) + { + try + { + if (Connect(IPAddr, Port, out Socket Sock)) + { + // Send Inital Packet. + Sock.Send(Helpers.StructtoBytes(Packet)); + + // Get API Response. + var Result = (APIResults)Sock.RecvInt32(); + + // Clean up. + Sock.Close(); + + return Result; + } + else + return APIResults.API_ERROR_COULDNT_CONNECT; + } + catch + { + + } + + return APIResults.API_ERROR_GENERAL; + } + + /// + /// Long API Call used for when we need to send more than just the initial packet. + /// + /// Address to send to. + /// The initial Packet Data. + /// The soucket out used for sending more data. + /// Returns the result of the action. + public static APIResults CallLong(string IPAddr, int Port, APIPacket Packet, out Socket Sock) + { + Sock = null; + + try + { + if (Connect(IPAddr, Port, out Sock)) + { + // Send Inital Packet. + Sock.Send(Helpers.StructtoBytes(Packet)); + + // Get API Response. + return (APIResults)Sock.RecvInt32(); + } + else + return APIResults.API_ERROR_COULDNT_CONNECT; + } + catch + { + + } + + return APIResults.API_ERROR_GENERAL; + } + + /// + /// Sends additional data if required. + /// + /// The packet type. + /// The socket instance were using. + /// Any Packet structure. + /// Returns the result of the action. + public static APIResults SendNextPacket(Socket Sock, T Packet) + { + try + { + // Send Next Packet. + Sock.Send(Helpers.StructtoBytes(Packet)); + + // Get API Response. + return (APIResults)Sock.RecvInt32(); + } + catch + { + + } + + return APIResults.API_ERROR_GENERAL; + } + + /// + /// + /// + /// + /// + /// + public static APIResults SendInt32(Socket Sock, int Value) + { + try + { + // Send Next Packet. + Sock.Send(BitConverter.GetBytes(Value)); + + // Get API Response. + return (APIResults)Sock.RecvInt32(); + } + catch + { + + } + + return APIResults.API_ERROR_GENERAL; + } + + /// + /// Completes the call and gets our final result. + /// + /// The socket used to communicate witht the API. + /// Returns the result of the action. + public static APIResults CompleteCall(Socket Sock) + { + try + { + var Results = (APIResults)Sock.RecvInt32(); + + Sock.Close(); + + return Results; + } + catch + { + + } + + return APIResults.API_ERROR_GENERAL; + } + } +} diff --git a/Windows/Libraries/OrbisLib/Common/API/APIPackets.cs b/Windows/Libraries/OrbisLib/Common/API/APIPackets.cs new file mode 100644 index 0000000..da2a887 --- /dev/null +++ b/Windows/Libraries/OrbisLib/Common/API/APIPackets.cs @@ -0,0 +1,248 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace OrbisSuite.Common +{ + public enum APICommands : int + { + APITest = 1, + + /* ####### Proc functions ####### */ + PROC_START, + API_PROC_GET_LIST, + API_PROC_ATTACH, + API_PROC_DETACH, + API_PROC_GET_CURRENT, + API_PROC_READ, + API_PROC_WRITE, + API_PROC_KILL, + API_PROC_LOAD_ELF, + API_PROC_CALL, + + /* Remote Library functions */ + API_PROC_LOAD_SPRX, + API_PROC_UNLOAD_SPRX, + API_PROC_UNLOAD_SPRX_NAME, + API_PROC_RELOAD_SPRX_NAME, + API_PROC_RELOAD_SPRX_HANDLE, + API_PROC_DUMP_MODULE, + API_PROC_MODULE_LIST, + PROC_END, + /* ############################## */ + + /* ##### Debugger functions ##### */ + DBG_START, + API_DBG_START, /* Debugger attach to target */ + API_DBG_STOP, /* Debugger detach from target */ + API_DBG_BREAK, + API_DBG_RESUME, + API_DBG_SIGNAL, + API_DBG_STEP, + API_DBG_STEP_OVER, + API_DBG_STEP_OUT, + API_DBG_GET_CALLSTACK, + API_DBG_GET_REG, + API_DBG_SET_REG, + API_DBG_GET_FREG, + API_DBG_SET_FREG, + API_DBG_GET_DBGREG, + API_DBG_SET_DBGREG, + + /* Thread Management */ + API_DBG_THREAD_LIST, + API_DBG_THREAD_STOP, + API_DBG_THREAD_RESUME, + + /* Breakpoint functions */ + API_DBG_BREAKPOINT_GETFREE, + API_DBG_BREAKPOINT_SET, + API_DBG_BREAKPOINT_UPDATE, + API_DBG_BREAKPOINT_REMOVE, + API_DBG_BREAKPOINT_GETINFO, + API_DBG_BREAKPOINT_LIST, + + /* Watchpoint functions */ + API_DBG_WATCHPOINT_SET, + API_DBG_WATCHPOINT_UPDATE, + API_DBG_WATCHPOINT_REMOVE, + API_DBG_WATCHPOINT_GETINFO, + API_DBG_WATCHPOINT_LIST, + DBG_END, + /* ############################## */ + + /* ###### Kernel functions ###### */ + KERN_START, + API_KERN_BASE, + API_KERN_READ, + API_KERN_WRITE, + KERN_END, + /* ############################## */ + + /* ###### Target functions ###### */ + TARGET_START, + API_TARGET_INFO, + API_TARGET_RESTMODE, + API_TARGET_SHUTDOWN, + API_TARGET_REBOOT, + API_TARGET_NOTIFY, + API_TARGET_BUZZER, + API_TARGET_SET_LED, + API_TARGET_DUMP_PROC, + //API_TARGET_LOAD_VSH_MODULE + TARGET_END, + /* ############################## */ + } + + public enum APIResults : int + { + API_OK = 1, + + API_ERROR_COULDNT_CONNECT, + API_ERROR_NOT_CONNECTED, + API_ERROR_NOT_ATTACHED, + API_ERROR_LOST_PROC, + API_ERROR_GENERAL, + API_ERROR_INVALID_ADDRESS, + + //Debugger + API_ERROR_PROC_RUNNING, + API_ERROR_DEBUG_TO_ATTACHED, + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi, Size = 40), Serializable] + public struct APIPacket + { + public int PacketVersion; + public APICommands Command; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string ProcName; + } + + [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Ansi)] + public struct ProcPacket + { + public int ProcessID; + public int Attached; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string ProcName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string TitleID; + public UInt64 TextSegmentBase; + public UInt64 TextSegmentLen; + public UInt64 DataSegmentBase; + public UInt64 DataSegmentLen; + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] + public struct ModuleListPacket + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)] + public string Name; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string Path; + public int Handle; + public UInt64 TextSegmentBase; + public UInt64 TextSegmentLen; + public UInt64 DataSegmentBase; + public UInt64 DataSegmentLen; + } + + public enum ConsoleTypes + { + UNK, + DIAG, //0x80 + DEVKIT, //0x81 + TESTKIT, //0x82 + RETAIL, //0x83 -> 0x8F + KRATOS, //0xA0 IMPOSSIBLE?? + }; + + public enum ConsoleLEDColours + { + white, + white_Blinking, + Blue_Blinking, + }; + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi, Size = 260), Serializable] + public struct TargetInfoPacket + { + public int SDKVersion; + public int SoftwareVersion; + public int FactorySoftwareVersion; + public int CPUTemp; + public int SOCTemp; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string CurrentTitleID; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] + public string ConsoleName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] + public string MotherboardSerial; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string Serial; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] + public string Model; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public byte[] MACAddressLAN; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] + public byte[] MACAddressWIFI; + public int UART; + public int IDUMode; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] IDPS; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] PSID; + public int ConsoleType; + public int Attached; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string CurrentProc; + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] + public struct ProcRWPacket + { + public UInt64 Address; + public UInt64 Length; + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] + public struct ProcSPRXPacket + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string Name; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string Path; + public int ModuleHandle; + public int Flags; + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] + public struct ProcBreakpointPacket + { + public int Index; + public UInt64 Address; + public int Enable; + } + + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)] + public struct TargetNotifyPacket + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + public string IconURI; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + public string Message; + } + + public enum BuzzerType + { + RingOnce = 1, + RingThree, + LongRing, + ThreeLongRing, + ThreeLongDoubleBeeps, + } +} diff --git a/Windows/Libraries/OrbisLib/Common/DataBase/SavedTargets.cs b/Windows/Libraries/OrbisLib/Common/DataBase/SavedTargets.cs index 5d2a1e3..4bf5a68 100644 --- a/Windows/Libraries/OrbisLib/Common/DataBase/SavedTargets.cs +++ b/Windows/Libraries/OrbisLib/Common/DataBase/SavedTargets.cs @@ -1,4 +1,6 @@ using System.Data.SQLite; +using System.Net.Sockets; +using System.Runtime.InteropServices; namespace OrbisSuite.Common.DataBase { @@ -444,22 +446,20 @@ namespace OrbisSuite.Common.DataBase Target.SDKVersion = $"{((Packet.SDKVersion >> 24) & 0xFF).ToString("X1")}.{((Packet.SDKVersion >> 12) & 0xFFF).ToString("X3")}.{(Packet.SDKVersion & 0xFFF).ToString("X3")}"; Target.SoftwareVersion = $"{((Packet.SoftwareVersion >> 24) & 0xFF).ToString("X1")}.{((Packet.SoftwareVersion >> 16) & 0xFF).ToString("X2")}"; Target.FactorySoftwareVersion = $"{((Packet.FactorySoftwareVersion >> 24) & 0xFF).ToString("X1")}.{((Packet.FactorySoftwareVersion >> 12) & 0xFFF).ToString("X3")}.{(Packet.FactorySoftwareVersion & 0xFFF).ToString("X3")}"; - Target.CPUTemp = Packet.CPUTemp; - Target.SOCTemp = Packet.SOCTemp; - // CurrentTitleID + Target.CurrentTitleID = Packet.CurrentTitleID; // TODO: Implement this on console Target.ConsoleName = Packet.ConsoleName; Target.MotherboardSerial = Packet.MotherboardSerial; Target.Serial = Packet.Serial; Target.Model = Packet.Model; Target.MACAddressLAN = BitConverter.ToString(Packet.MACAddressLAN).Replace("-", ":"); - // MACAddressWIFI + Target.MACAddressWIFI = "-"; // TODO: Find this on the console. BitConverter.ToString(Packet.MACAddressWIFI).Replace("-", ":"); Target.UART = Packet.UART > 0; Target.IDUMode = Packet.IDUMode > 0; Target.IDPS = BitConverter.ToString(Packet.IDPS).Replace("-", string.Empty); Target.PSID = BitConverter.ToString(Packet.PSID).Replace("-", string.Empty); Target.ConsoleType = ConsoleTypeNames[Packet.ConsoleType]; Target.Attached = Packet.Attached > 0; - Target.CurrentProc = Packet.CurrentProc; + Target.CurrentProcessId = 0;// TODO: Update this to process Id Packet.CurrentProc; // Write to Database. using (var connection = new SQLiteConnection($"Data Source={Config.DataBasePath}")) @@ -471,8 +471,6 @@ namespace OrbisSuite.Common.DataBase SDKVersion=@SDKVersion, SoftwareVersion=@SoftwareVersion, FactorySoftwareVersion=@FactorySoftwareVersion, - CPUTemp=@CPUTemp, - SOCTemp=@SOCTemp, CurrentTitleID=@CurrentTitleID, ConsoleName=@ConsoleName, MotherboardSerial=@MotherboardSerial, @@ -486,15 +484,16 @@ namespace OrbisSuite.Common.DataBase PSID=@PSID, ConsoleType=@ConsoleType, Attached=@Attached, - CurrentProc=@CurrentProc + CurrentProcessId=@CurrentProcessId, + HDDUsedSpace=@HDDUsedSpace, + HDDFreeSpace=@HDDFreeSpace, + HDDTotalSpace=@HDDTotalSpace WHERE TargetName=@Target"; command.Parameters.AddWithValue("@Target", TargetName); command.Parameters.AddWithValue("@SDKVersion", Target.SDKVersion); command.Parameters.AddWithValue("@SoftwareVersion", Target.SoftwareVersion); command.Parameters.AddWithValue("@FactorySoftwareVersion", Target.FactorySoftwareVersion); - command.Parameters.AddWithValue("@CPUTemp", Target.CPUTemp); - command.Parameters.AddWithValue("@SOCTemp", Target.SOCTemp); command.Parameters.AddWithValue("@CurrentTitleID", Target.CurrentTitleID); command.Parameters.AddWithValue("@ConsoleName", Target.ConsoleName); command.Parameters.AddWithValue("@MotherboardSerial", Target.MotherboardSerial); @@ -508,7 +507,11 @@ namespace OrbisSuite.Common.DataBase command.Parameters.AddWithValue("@PSID", Target.PSID); command.Parameters.AddWithValue("@ConsoleType", Target.ConsoleType); command.Parameters.AddWithValue("@Attached", Target.Attached); - command.Parameters.AddWithValue("@CurrentProc", Target.CurrentProc); + command.Parameters.AddWithValue("@CurrentProcessId", Target.CurrentProcessId); + command.Parameters.AddWithValue("@HDDUsedSpace", Target.HDDUsedSpace); + command.Parameters.AddWithValue("@HDDFreeSpace", Target.HDDFreeSpace); + command.Parameters.AddWithValue("@HDDTotalSpace", Target.HDDTotalSpace); + // TODO: Possibly have CPU stats here SOC/CPU Temp, RAM, VRAM, ThreadCount, CPUAverageUsage & CPUUsage[8]. return (command.ExecuteNonQuery() > 0); } diff --git a/Windows/Libraries/OrbisLib/Common/DataBase/Settings.cs b/Windows/Libraries/OrbisLib/Common/DataBase/Settings.cs index fc9cd47..35c7953 100644 --- a/Windows/Libraries/OrbisLib/Common/DataBase/Settings.cs +++ b/Windows/Libraries/OrbisLib/Common/DataBase/Settings.cs @@ -8,5 +8,208 @@ namespace OrbisSuite.Common.DataBase { internal class Settings { + #region General + + /// + /// The API port that OrbisLib communicates on. + /// + public int APIPort + { + get + { + return Database.GetSetting("APIPort"); + } + + set + { + Database.SetSetting("APIPort", value); + } + } + + /// + /// The port that will be used to access the targets file system using ftp + /// + public int FTPPort + { + get + { + return Database.GetSetting("FTPPort"); + } + + set + { + Database.SetSetting("FTPPort", value); + } + } + + /// + /// The port of a klog server that will be used to print console output similar to UART. + /// + public int KlogPort + { + get + { + return Database.GetSetting("KlogPort"); + } + + set + { + Database.SetSetting("KlogPort", value); + } + } + + /// + /// The serial COM port we will listen to for UART output. + /// + public string COMPort + { + get + { + return Database.GetSetting("COMPort"); + } + + set + { + Database.SetSetting("COMPort", value); + } + } + + /// + /// Starts the Orbis Suite taskbar app when windows boots. + /// + public bool StartOnBoot + { + get + { + return Database.GetSetting("StartOnBoot"); + } + + set + { + Database.SetSetting("StartOnBoot", value); + + //Get windows registry key to set app on start up. + Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + + //add or remove the value. + if (value) + key.SetValue("OrbisTaskbarApp", AppDomain.CurrentDomain.BaseDirectory + "OrbisTaskbarApp.exe"); + else + key.DeleteValue("OrbisTaskbarApp", false); + + //Close the key after use. + key?.Close(); + } + } + + #endregion + + #region Themes + + /// + /// Choose which theme will be used across Orbis Suite. + /// + public int Theme + { + get + { + return Database.GetSetting("Theme"); + } + + set + { + Database.SetSetting("Theme", value); + } + } + + /// + /// Enables the accent colours to cycle through all colours of the rainbow. + /// + public bool RainbowColours + { + get + { + return Database.GetSetting("RainbowColours"); + } + + set + { + Database.SetSetting("RainbowColours", value); + } + } + + #endregion + + #region TargetInfo + + /// + /// When viewd from the target details choose to censor the Target identifier. + /// + public bool CensorIDPS + { + get + { + return Database.GetSetting("CensorIDPS"); + } + + set + { + Database.SetSetting("CensorIDPS", value); + } + } + + /// + /// When viewd from the target details choose to censor the Target identifier. + /// + public bool CensorPSID + { + get + { + return Database.GetSetting("CensorPSID"); + } + + set + { + Database.SetSetting("CensorPSID", value); + } + } + + #endregion + + #region ConsoleOutput + + /// + /// SHow timestamps on the console output. + /// + public bool ShowTimestamps + { + get + { + return Database.GetSetting("ShowTimestamps"); + } + + set + { + Database.SetSetting("ShowTimestamps", value); + } + } + + /// + /// Word wrap the console output window. + /// + public bool WordWrap + { + get + { + return Database.GetSetting("WordWrap"); + } + + set + { + Database.SetSetting("WordWrap", value); + } + } + + #endregion } } diff --git a/Windows/Libraries/OrbisLib/Common/Helpers/Helpers.cs b/Windows/Libraries/OrbisLib/Common/Helpers/Helper.cs similarity index 99% rename from Windows/Libraries/OrbisLib/Common/Helpers/Helpers.cs rename to Windows/Libraries/OrbisLib/Common/Helpers/Helper.cs index 6f61ed1..150185c 100644 --- a/Windows/Libraries/OrbisLib/Common/Helpers/Helpers.cs +++ b/Windows/Libraries/OrbisLib/Common/Helpers/Helper.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; using System.Runtime.Serialization.Formatters.Binary; using System.Text; -namespace OrbisSuite.Common.Helpers +namespace OrbisSuite.Common { public static class Helpers { diff --git a/Windows/Libraries/OrbisLib/Common/Helpers/Listener.cs b/Windows/Libraries/OrbisLib/Common/Helpers/Listener.cs index 732d6a9..2f554a9 100644 --- a/Windows/Libraries/OrbisLib/Common/Helpers/Listener.cs +++ b/Windows/Libraries/OrbisLib/Common/Helpers/Listener.cs @@ -2,7 +2,7 @@ using System.Net.Sockets; -namespace OrbisSuite.Common.Helpers +namespace OrbisSuite.Common { public class Listener { diff --git a/Windows/Libraries/OrbisLib/OrbisLib.csproj b/Windows/Libraries/OrbisLib/OrbisLib.csproj index c6fa1ce..ef1375f 100644 --- a/Windows/Libraries/OrbisLib/OrbisLib.csproj +++ b/Windows/Libraries/OrbisLib/OrbisLib.csproj @@ -9,7 +9,6 @@ -