diff --git a/Netimobiledevice/Plist/IntegerNode.cs b/Netimobiledevice/Plist/IntegerNode.cs index 01bb2d2..9f95901 100755 --- a/Netimobiledevice/Plist/IntegerNode.cs +++ b/Netimobiledevice/Plist/IntegerNode.cs @@ -3,6 +3,8 @@ using System; using System.Globalization; using System.IO; +using System.Linq; +using System.Numerics; namespace Netimobiledevice.Plist { @@ -148,7 +150,18 @@ internal override void ReadBinary(Stream stream, int nodeLength) break; } default: { - throw new PlistFormatException("UInt > 64Bit"); + byte[] valueBuf = buf.Skip(buf.Length - nodeLength).Take(nodeLength).ToArray(); + if (valueBuf.Length > 15) { + throw new PlistFormatException("UInt > 64Bit"); + } + else { + uint nearestPowOf2 = BitOperations.RoundUpToPowerOf2((uint) valueBuf.Length); + int nthRoot = (int) Math.Log(nearestPowOf2, 2); + using (Stream valueBufStream = new MemoryStream(valueBuf)) { + ReadBinary(valueBufStream, nthRoot); + } + } + break; } } } diff --git a/NetimobiledeviceTest/Plist/IntegerNodeTests.cs b/NetimobiledeviceTest/Plist/IntegerNodeTests.cs index 270615f..61163e0 100755 --- a/NetimobiledeviceTest/Plist/IntegerNodeTests.cs +++ b/NetimobiledeviceTest/Plist/IntegerNodeTests.cs @@ -36,4 +36,32 @@ public void ParseHandlesNegativeValue() int actualValue = (int) node.Value; Assert.AreEqual(-536854523, actualValue); } + + [TestMethod] + public void ReadBinaryHandlesNodeLengthNotAsAPower() + { + IntegerNode node = new IntegerNode(); + byte[] longNodeLength = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xB, 0xB8 }; + + using (MemoryStream stream = new MemoryStream(longNodeLength)) { + node.ReadBinary(stream, 4); + } + + int nodeValue = (int) node.Value; + Assert.AreEqual(3000, nodeValue); + } + + [TestMethod] + public void ReadBinaryHandlesNodeLengthAsAPower() + { + IntegerNode node = new IntegerNode(); + byte[] longNodeLength = new byte[] { 0, 0, 0x7, 0xD0 }; + + using (MemoryStream stream = new MemoryStream(longNodeLength)) { + node.ReadBinary(stream, 2); + } + + int nodeValue = (int) node.Value; + Assert.AreEqual(2000, nodeValue); + } }