Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Stricted committed Jan 27, 2016
1 parent 6fea326 commit 7191f3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions SPHDecode/Implementations/Cryptography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static byte[] Decrypt(byte[] clearText)
return null;
}

if (util.IsValidXML(Encoding.UTF8.GetString(response)).Equals(false))
if (util.IsValidXML(response).Equals(false))
{
MessageBox.Show("Not a valid config file...", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
Expand All @@ -41,7 +41,7 @@ public static byte[] Encrypt(byte[] data)
{
byte[] response = null;

if (util.IsValidXML(Encoding.UTF8.GetString(data)).Equals(false))
if (util.IsValidXML((data)).Equals(false))
{
MessageBox.Show("Not a valid config file...", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
Expand Down
23 changes: 16 additions & 7 deletions SPHDecode/Implementations/util.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
using System;
using System.Text;
using System.Xml;

namespace SPHDecode.Implementations
{
class util
{
public static bool IsValidXML(string value)
public static bool IsValidXML(byte[] data)
{
if (string.IsNullOrWhiteSpace(value))
if (Object.Equals(data, null))
{
return false;

if (value.EndsWith("\0"))
value = value.Substring(0, value.Length - 1);
}

try
{
string value = Encoding.UTF8.GetString(data);

if (string.IsNullOrWhiteSpace(value))
return false;

if (value.EndsWith("\0"))
value = value.Substring(0, value.Length - 1);

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(value);
Expand All @@ -30,7 +38,8 @@ public static bool IsValidXML(string value)

public static byte[] removeNullByte (byte[] data)
{
if (data[data.Length - 1].Equals(0))

if (Object.Equals(data, null).Equals(false) && data[data.Length - 1].Equals(0))
{
byte[] tmp = new byte[data.Length - 1];
Array.Copy(data, tmp, data.Length - 1);
Expand All @@ -43,7 +52,7 @@ public static byte[] removeNullByte (byte[] data)

public static byte[] addNullByte (byte[] data)
{
if (data[data.Length - 1].Equals(0).Equals(false))
if (Object.Equals(data, null).Equals(false) && data[data.Length - 1].Equals(0).Equals(false))
{
byte[] tmp = data;
Array.Resize(ref tmp, tmp.Length + 1);
Expand Down

0 comments on commit 7191f3a

Please sign in to comment.