Skip to content

Commit 7191f3a

Browse files
committed
fix crash
1 parent 6fea326 commit 7191f3a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

SPHDecode/Implementations/Cryptography.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static byte[] Decrypt(byte[] clearText)
2828
return null;
2929
}
3030

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

44-
if (util.IsValidXML(Encoding.UTF8.GetString(data)).Equals(false))
44+
if (util.IsValidXML((data)).Equals(false))
4545
{
4646
MessageBox.Show("Not a valid config file...", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
4747
return null;

SPHDecode/Implementations/util.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
using System;
2+
using System.Text;
23
using System.Xml;
34

45
namespace SPHDecode.Implementations
56
{
67
class util
78
{
8-
public static bool IsValidXML(string value)
9+
public static bool IsValidXML(byte[] data)
910
{
10-
if (string.IsNullOrWhiteSpace(value))
11+
if (Object.Equals(data, null))
12+
{
1113
return false;
12-
13-
if (value.EndsWith("\0"))
14-
value = value.Substring(0, value.Length - 1);
14+
}
1515

1616
try
1717
{
18+
string value = Encoding.UTF8.GetString(data);
19+
20+
if (string.IsNullOrWhiteSpace(value))
21+
return false;
22+
23+
if (value.EndsWith("\0"))
24+
value = value.Substring(0, value.Length - 1);
25+
1826
XmlDocument xmlDoc = new XmlDocument();
1927

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

3139
public static byte[] removeNullByte (byte[] data)
3240
{
33-
if (data[data.Length - 1].Equals(0))
41+
42+
if (Object.Equals(data, null).Equals(false) && data[data.Length - 1].Equals(0))
3443
{
3544
byte[] tmp = new byte[data.Length - 1];
3645
Array.Copy(data, tmp, data.Length - 1);
@@ -43,7 +52,7 @@ public static byte[] removeNullByte (byte[] data)
4352

4453
public static byte[] addNullByte (byte[] data)
4554
{
46-
if (data[data.Length - 1].Equals(0).Equals(false))
55+
if (Object.Equals(data, null).Equals(false) && data[data.Length - 1].Equals(0).Equals(false))
4756
{
4857
byte[] tmp = data;
4958
Array.Resize(ref tmp, tmp.Length + 1);

0 commit comments

Comments
 (0)