From 4f8376ec3e0a145c19ff9474791b734afbea89be Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Mon, 30 Jun 2014 10:36:20 -0400 Subject: [PATCH] Added page to insert box upload captures into the database. --- gts/admin/AddBoxes.aspx | 15 ++++++ gts/admin/AddBoxes.aspx.cs | 71 +++++++++++++++++++++++++++++ gts/admin/AddBoxes.aspx.designer.cs | 51 +++++++++++++++++++++ gts/admin/AddDressup.aspx.cs | 18 +------- gts/gts.csproj | 8 ++++ gts/src/Common.cs | 21 +++++++++ 6 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 gts/admin/AddBoxes.aspx create mode 100644 gts/admin/AddBoxes.aspx.cs create mode 100644 gts/admin/AddBoxes.aspx.designer.cs diff --git a/gts/admin/AddBoxes.aspx b/gts/admin/AddBoxes.aspx new file mode 100644 index 00000000..0098b069 --- /dev/null +++ b/gts/admin/AddBoxes.aspx @@ -0,0 +1,15 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="AddBoxes.aspx.cs" Inherits="PkmnFoundations.GTS.admin.AddBoxes" %> + + + + + +
+
+

Upload a wiresharked box search response here to add it to the database:

+ + +
+ + +
diff --git a/gts/admin/AddBoxes.aspx.cs b/gts/admin/AddBoxes.aspx.cs new file mode 100644 index 00000000..94e20780 --- /dev/null +++ b/gts/admin/AddBoxes.aspx.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using PkmnFoundations.Structures; +using PkmnFoundations.Data; + +namespace PkmnFoundations.GTS.admin +{ + public partial class AddBoxes : System.Web.UI.Page + { + protected void Page_Init(object sender, EventArgs e) + { + litMessage.Text = ""; + } + + protected void Page_Load(object sender, EventArgs e) + { + + } + + protected void btnSend_Click(object sender, EventArgs e) + { + byte[] data = fuBox.FileBytes; + if (data.Length < 0xf8) + { + Fail(); return; + } + + Common.CryptMessage(data); + if (data[0x04] != 0x21 || + data[0x05] != 0x52 || + data[0x06] != 0x00 || + data[0x07] != 0x00) + { + Fail(); return; + } + + int results = BitConverter.ToInt32(data, 0x08); + if (data.Length != 12 + 556 * results) + { + Fail(); return; + } + + int added = 0; + + for (int x = 0; x < results; x++) + { + int pid = BitConverter.ToInt32(data, 12 + 556 * x); + BoxLabels4 label = (BoxLabels4)BitConverter.ToInt32(data, 16 + 556 * x); + long serial = BitConverter.ToInt64(data, 20 + 556 * x); + if (serial == 0) continue; + + byte[] result = new byte[540]; + Array.Copy(data, 28 + 556 * x, result, 0, 540); + + BoxRecord4 record = new BoxRecord4(pid, label, serial, result); + if (DataAbstract.Instance.BoxUpload4(record) != 0) added++; + } + + litMessage.Text = "Added " + added.ToString() + " boxes to the database."; + } + + private void Fail() + { + litMessage.Text = "There was an error with the data."; + } + } +} \ No newline at end of file diff --git a/gts/admin/AddBoxes.aspx.designer.cs b/gts/admin/AddBoxes.aspx.designer.cs new file mode 100644 index 00000000..fa6d9461 --- /dev/null +++ b/gts/admin/AddBoxes.aspx.designer.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PkmnFoundations.GTS.admin { + + + public partial class AddBoxes { + + /// + /// theForm control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlForm theForm; + + /// + /// fuBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.FileUpload fuBox; + + /// + /// btnSend control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button btnSend; + + /// + /// litMessage control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal litMessage; + } +} diff --git a/gts/admin/AddDressup.aspx.cs b/gts/admin/AddDressup.aspx.cs index bdc652f6..b9bc96f2 100644 --- a/gts/admin/AddDressup.aspx.cs +++ b/gts/admin/AddDressup.aspx.cs @@ -22,8 +22,6 @@ namespace PkmnFoundations.GTS.test } - private static byte[] m_pad = new byte[256]; - protected void btnSend_Click(object sender, EventArgs e) { byte[] data = fuBox.FileBytes; @@ -32,11 +30,7 @@ namespace PkmnFoundations.GTS.test Fail(); return; } - FileStream s = File.Open(Server.MapPath("~/pad.bin"), FileMode.Open); - s.Read(m_pad, 0, m_pad.Length); - s.Close(); - - CryptMessage(data); + Common.CryptMessage(data); if (data[0x04] != 0x21 || data[0x05] != 0x4e || data[0x06] != 0x00 || @@ -69,16 +63,6 @@ namespace PkmnFoundations.GTS.test litMessage.Text = "Added " + added.ToString() + " dressup photos to the database."; } - private void CryptMessage(byte[] message) - { - if (message.Length < 5) return; - byte padOffset = (byte)(message[0] + message[4]); - - // encrypt and decrypt are the same operation... - for (int x = 5; x < message.Length; x++) - message[x] ^= m_pad[(x + padOffset) & 0xff]; - } - private void Fail() { litMessage.Text = "There was an error with the data."; diff --git a/gts/gts.csproj b/gts/gts.csproj index 67b0a926..42f89d88 100644 --- a/gts/gts.csproj +++ b/gts/gts.csproj @@ -55,6 +55,7 @@ + @@ -81,6 +82,13 @@ + + AddBoxes.aspx + ASPXCodeBehind + + + AddBoxes.aspx + AllPokemon.aspx ASPXCodeBehind diff --git a/gts/src/Common.cs b/gts/src/Common.cs index fc16be21..ab9002e3 100644 --- a/gts/src/Common.cs +++ b/gts/src/Common.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; +using System.IO; namespace PkmnFoundations.GTS { @@ -76,5 +77,25 @@ namespace PkmnFoundations.GTS { return HttpUtility.HtmlEncode(s); } + + private static byte[] m_pad = null; + + public static void CryptMessage(byte[] message) + { + if (m_pad == null) + { + m_pad = new byte[256]; + FileStream s = File.Open(HttpContext.Current.Server.MapPath("~/pad.bin"), FileMode.Open); + s.Read(m_pad, 0, m_pad.Length); + s.Close(); + } + + if (message.Length < 5) return; + byte padOffset = (byte)(message[0] + message[4]); + + // encrypt and decrypt are the same operation... + for (int x = 5; x < message.Length; x++) + message[x] ^= m_pad[(x + padOffset) & 0xff]; + } } } \ No newline at end of file