Add sysbot injector UI

This commit is contained in:
Kurt
2020-03-31 19:23:00 -07:00
parent b3e8b1b1fb
commit ae4d1f3263
6 changed files with 466 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\NHSE.Core\NHSE.Core.csproj" />
<ProjectReference Include="..\NHSE.Injection\NHSE.Injection.csproj" />
<ProjectReference Include="..\NHSE.Sprites\NHSE.Sprites.csproj" />
</ItemGroup>

View File

@@ -34,5 +34,41 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["LastFilePath"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("192.168.0.1")]
public string SysBotIP {
get {
return ((string)(this["SysBotIP"]));
}
set {
this["SysBotIP"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("6000")]
public int SysBotPort {
get {
return ((int)(this["SysBotPort"]));
}
set {
this["SysBotPort"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("2889584832")]
public uint SysBotPouchOffset {
get {
return ((uint)(this["SysBotPouchOffset"]));
}
set {
this["SysBotPouchOffset"] = value;
}
}
}
}

View File

@@ -5,5 +5,14 @@
<Setting Name="LastFilePath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SysBotIP" Type="System.String" Scope="User">
<Value Profile="(Default)">192.168.0.1</Value>
</Setting>
<Setting Name="SysBotPort" Type="System.Int32" Scope="User">
<Value Profile="(Default)">6000</Value>
</Setting>
<Setting Name="SysBotPouchOffset" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">2889584832</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -0,0 +1,181 @@
namespace NHSE.WinForms
{
partial class SysBotUI
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.B_Connect = new System.Windows.Forms.Button();
this.L_Port = new System.Windows.Forms.Label();
this.TB_Port = new System.Windows.Forms.TextBox();
this.L_IP = new System.Windows.Forms.Label();
this.TB_IP = new System.Windows.Forms.TextBox();
this.GB_Inject = new System.Windows.Forms.GroupBox();
this.RamOffset = new System.Windows.Forms.TextBox();
this.L_Offset = new System.Windows.Forms.Label();
this.B_ReadCurrent = new System.Windows.Forms.Button();
this.B_WriteCurrent = new System.Windows.Forms.Button();
this.GB_Inject.SuspendLayout();
this.SuspendLayout();
//
// B_Connect
//
this.B_Connect.Location = new System.Drawing.Point(102, 37);
this.B_Connect.Name = "B_Connect";
this.B_Connect.Size = new System.Drawing.Size(63, 23);
this.B_Connect.TabIndex = 12;
this.B_Connect.Text = "Connect";
this.B_Connect.UseVisualStyleBackColor = true;
this.B_Connect.Click += new System.EventHandler(this.B_Connect_Click);
//
// L_Port
//
this.L_Port.Location = new System.Drawing.Point(13, 38);
this.L_Port.Name = "L_Port";
this.L_Port.Size = new System.Drawing.Size(40, 20);
this.L_Port.TabIndex = 11;
this.L_Port.Text = "Port:";
this.L_Port.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// TB_Port
//
this.TB_Port.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.TB_Port.Location = new System.Drawing.Point(54, 38);
this.TB_Port.Name = "TB_Port";
this.TB_Port.Size = new System.Drawing.Size(42, 20);
this.TB_Port.TabIndex = 10;
this.TB_Port.Text = "6000";
//
// L_IP
//
this.L_IP.Location = new System.Drawing.Point(13, 12);
this.L_IP.Name = "L_IP";
this.L_IP.Size = new System.Drawing.Size(40, 20);
this.L_IP.TabIndex = 9;
this.L_IP.Text = "IP:";
this.L_IP.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// TB_IP
//
this.TB_IP.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.TB_IP.Location = new System.Drawing.Point(54, 12);
this.TB_IP.Name = "TB_IP";
this.TB_IP.Size = new System.Drawing.Size(111, 20);
this.TB_IP.TabIndex = 8;
this.TB_IP.Text = "111.111.111.111";
//
// GB_Inject
//
this.GB_Inject.Controls.Add(this.RamOffset);
this.GB_Inject.Controls.Add(this.L_Offset);
this.GB_Inject.Controls.Add(this.B_ReadCurrent);
this.GB_Inject.Controls.Add(this.B_WriteCurrent);
this.GB_Inject.Enabled = false;
this.GB_Inject.Location = new System.Drawing.Point(16, 66);
this.GB_Inject.Name = "GB_Inject";
this.GB_Inject.Size = new System.Drawing.Size(149, 74);
this.GB_Inject.TabIndex = 13;
this.GB_Inject.TabStop = false;
this.GB_Inject.Text = "Injector";
//
// RamOffset
//
this.RamOffset.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.RamOffset.Location = new System.Drawing.Point(72, 19);
this.RamOffset.MaxLength = 8;
this.RamOffset.Name = "RamOffset";
this.RamOffset.Size = new System.Drawing.Size(63, 20);
this.RamOffset.TabIndex = 20;
this.RamOffset.Text = "AC3B90C0";
//
// L_Offset
//
this.L_Offset.Location = new System.Drawing.Point(3, 18);
this.L_Offset.Name = "L_Offset";
this.L_Offset.Size = new System.Drawing.Size(63, 20);
this.L_Offset.TabIndex = 19;
this.L_Offset.Text = "Offset:";
this.L_Offset.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// B_ReadCurrent
//
this.B_ReadCurrent.Location = new System.Drawing.Point(18, 41);
this.B_ReadCurrent.Name = "B_ReadCurrent";
this.B_ReadCurrent.Size = new System.Drawing.Size(56, 23);
this.B_ReadCurrent.TabIndex = 0;
this.B_ReadCurrent.Text = "Read";
this.B_ReadCurrent.UseVisualStyleBackColor = true;
this.B_ReadCurrent.Click += new System.EventHandler(this.B_ReadCurrent_Click);
//
// B_WriteCurrent
//
this.B_WriteCurrent.Location = new System.Drawing.Point(80, 41);
this.B_WriteCurrent.Name = "B_WriteCurrent";
this.B_WriteCurrent.Size = new System.Drawing.Size(56, 23);
this.B_WriteCurrent.TabIndex = 1;
this.B_WriteCurrent.Text = "Write";
this.B_WriteCurrent.UseVisualStyleBackColor = true;
this.B_WriteCurrent.Click += new System.EventHandler(this.B_WriteCurrent_Click);
//
// SysBotUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(184, 151);
this.Controls.Add(this.GB_Inject);
this.Controls.Add(this.B_Connect);
this.Controls.Add(this.L_Port);
this.Controls.Add(this.TB_Port);
this.Controls.Add(this.L_IP);
this.Controls.Add(this.TB_IP);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SysBotUI";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SysBotUI";
this.GB_Inject.ResumeLayout(false);
this.GB_Inject.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button B_Connect;
private System.Windows.Forms.Label L_Port;
private System.Windows.Forms.TextBox TB_Port;
private System.Windows.Forms.Label L_IP;
private System.Windows.Forms.TextBox TB_IP;
private System.Windows.Forms.GroupBox GB_Inject;
private System.Windows.Forms.Button B_ReadCurrent;
private System.Windows.Forms.Button B_WriteCurrent;
private System.Windows.Forms.TextBox RamOffset;
private System.Windows.Forms.Label L_Offset;
}
}

View File

@@ -0,0 +1,119 @@
using System;
using System.Windows.Forms;
using NHSE.Injection;
using NHSE.WinForms.Properties;
namespace NHSE.WinForms
{
public partial class SysBotUI : Form
{
private readonly Func<byte[]> ByteFetch;
private readonly Action<byte[]> ByteSet;
private readonly InjectionType Type;
private readonly SysBot Bot = new SysBot();
private readonly Settings Settings = Settings.Default;
public SysBotUI(Action<byte[]> read, Func<byte[]> write, InjectionType type)
{
InitializeComponent();
ByteFetch = write;
ByteSet = read;
Type = type;
RamOffset.Text = GetOffset(type).ToString("X8");
TB_IP.Text = Settings.SysBotIP;
TB_Port.Text = Settings.SysBotPort.ToString();
}
private uint GetOffset(InjectionType type)
{
var settings = Settings;
return type switch
{
_ => settings.SysBotPouchOffset,
};
}
private void SetOffset(InjectionType type, uint value)
{
var settings = Settings;
settings.SysBotPouchOffset = type switch
{
_ => value,
};
settings.Save();
}
private void B_Connect_Click(object sender, EventArgs e)
{
var ip = TB_IP.Text;
var port = TB_Port.Text;
if (!int.TryParse(port, out var p))
p = 6000;
try
{
Bot.Connect(ip, p);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
WinFormsUtil.Error(ex.Message);
return;
}
var settings = Settings;
settings.SysBotIP = ip;
settings.SysBotPort = p;
settings.Save();
GB_Inject.Enabled = true;
}
private void B_WriteCurrent_Click(object sender, EventArgs e)
{
if (!uint.TryParse(RamOffset.Text, out var offset))
{
WinFormsUtil.Error("Incorrect hex offset.");
return;
}
try
{
var data = ByteFetch();
Bot.WriteBytes(data, offset);
SetOffset(Type, offset);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
WinFormsUtil.Error(ex.Message);
}
}
private void B_ReadCurrent_Click(object sender, EventArgs e)
{
if (!uint.TryParse(RamOffset.Text, out var offset))
{
WinFormsUtil.Error("Incorrect hex offset.");
return;
}
try
{
var data = ByteFetch();
var result = Bot.ReadBytes(offset, data.Length);
ByteSet(result);
SetOffset(Type, offset);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
WinFormsUtil.Error(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>