Implemented &data= hash and length check.

This commit is contained in:
Greg Edwards 2014-05-19 04:06:31 -04:00
parent d00c1a3ac2
commit bf956a9260
4 changed files with 16 additions and 15 deletions

View File

@ -12,13 +12,10 @@ namespace PkmnFoundations.GTS
{
public partial class BattleVideo : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
litMessage.Text = "";
}
protected void Page_Load(object sender, EventArgs e)
{
litMessage.Text = "";
using (MySqlConnection db = CreateConnection())
{
db.Open();

View File

@ -58,7 +58,12 @@ namespace PkmnFoundations.GTS
rand = DecryptRNG(rand);
data3[pos] = (byte)(data2[pos + 4] ^ (byte)(rand >> 16));
}
// todo: validate checksum
int checkedsum = 0;
foreach (byte b in data3)
checkedsum += b;
if (checkedsum != checksum) throw new FormatException("Data checksum is incorrect.");
return data3;
}

View File

@ -54,7 +54,13 @@ namespace PkmnFoundations.GTS
// the ashx to check for pids to match.
// todo: prune first 12 bytes, pass pid to this function to validate
Array.Copy(data2, 4, data3, 0, data2.Length - 4);
// todo: validate checksum and length
if (length + 8 != data3.Length) throw new FormatException("Data length is incorrect.");
int checkedsum = 0;
foreach (byte b in data3)
checkedsum += b;
if (checkedsum != checksum) throw new FormatException("Data checksum is incorrect.");
return data3;
}

View File

@ -10,14 +10,9 @@ namespace PkmnFoundations.GTS.debug
{
public partial class Decode : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
litMessage.Text = "";
}
protected void Page_Load(object sender, EventArgs e)
{
litMessage.Text = "";
}
protected void btnDecode_Click(object sender, EventArgs e)
@ -29,8 +24,6 @@ namespace PkmnFoundations.GTS.debug
{
data = GtsSession4.DecryptData(txtData.Text);
litGeneration.Text = "4";
// todo: genIV is always valid so genV never gets detected
// need to validate checksum and error there
}
catch (FormatException)
{