From 6fea3261ac4620b38039e5f4ffc2d3c8da1696cb Mon Sep 17 00:00:00 2001 From: Stricted Date: Wed, 27 Jan 2016 02:45:39 +0100 Subject: [PATCH] append/remove last(null) byte --- SPHDecode/Implementations/util.cs | 29 ++++++++++++++++++++++++++++- SPHDecode/Model/MainWindowModel.cs | 4 ++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/SPHDecode/Implementations/util.cs b/SPHDecode/Implementations/util.cs index 02e7520..4ba6399 100644 --- a/SPHDecode/Implementations/util.cs +++ b/SPHDecode/Implementations/util.cs @@ -1,4 +1,5 @@ -using System.Xml; +using System; +using System.Xml; namespace SPHDecode.Implementations { @@ -26,5 +27,31 @@ public static bool IsValidXML(string value) return false; } } + + public static byte[] removeNullByte (byte[] data) + { + if (data[data.Length - 1].Equals(0)) + { + byte[] tmp = new byte[data.Length - 1]; + Array.Copy(data, tmp, data.Length - 1); + + return tmp; + } + + return data; + } + + public static byte[] addNullByte (byte[] data) + { + if (data[data.Length - 1].Equals(0).Equals(false)) + { + byte[] tmp = data; + Array.Resize(ref tmp, tmp.Length + 1); + + return tmp; + } + + return data; + } } } diff --git a/SPHDecode/Model/MainWindowModel.cs b/SPHDecode/Model/MainWindowModel.cs index 855024f..b7bfa8e 100644 --- a/SPHDecode/Model/MainWindowModel.cs +++ b/SPHDecode/Model/MainWindowModel.cs @@ -72,7 +72,7 @@ private void OndstFileDialogExecute() private void OnencryptExecute() { byte[] orig = File.ReadAllBytes(srcFile); - byte[] encode = Cryptography.Encrypt(orig); + byte[] encode = Cryptography.Encrypt(util.addNullByte(orig)); if (Object.Equals(encode, null).Equals(false)) { @@ -84,7 +84,7 @@ private void OnencryptExecute() private void OndecryptExecute() { byte[] orig = File.ReadAllBytes(srcFile); - byte[] decode = Cryptography.Decrypt(orig); + byte[] decode = util.removeNullByte(Cryptography.Decrypt(orig)); if (Object.Equals(decode, null).Equals(false)) {