Permalink
Browse files

Bug fix for proper byte offsets.

  • Loading branch information...
animetrics committed Oct 28, 2011
1 parent fb91b0d commit 4daf8c8724236b8ddc0d6612dd90f4bf090c4c21
View
Binary file not shown.
@@ -46,7 +46,9 @@
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
- <Compile Include="Plist.cs" />
+ <Compile Include="..\Src\Plist.cs">
+ <Link>Plist.cs</Link>
+ </Compile>
<Compile Include="PlistTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -12,7 +12,7 @@ public class plistTests
string targetBinPath = "targetBin.plist";
string sourceXmlPath = "testXml.plist";
string sourceBinPath = "testBin.plist";
- string sourceImage = "testImage.jpg";
+ string sourceImage = "testImage.jpg";
private Dictionary<string, object> CreateDictionary()
{
@@ -8,9 +8,9 @@
[assembly: AssemblyTitle("PlistCS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("Animetrics")]
[assembly: AssemblyProduct("PlistCS")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyCopyright("Copyright © Animetrics 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Binary file not shown.
Binary file not shown.
@@ -3,3 +3,8 @@ C:\Users\mark\Programming\c#\PlistCS\PlistCS\bin\Debug\PlistCS.dll
C:\Users\mark\Programming\c#\PlistCS\PlistCS\bin\Debug\PlistCS.pdb
C:\Users\mark\Programming\c#\PlistCS\PlistCS\obj\Debug\PlistCS.dll
C:\Users\mark\Programming\c#\PlistCS\PlistCS\obj\Debug\PlistCS.pdb
+C:\Users\mark\BinaryPlists\PlistCS\PlistCS\bin\Debug\PlistCS.dll
+C:\Users\mark\BinaryPlists\PlistCS\PlistCS\bin\Debug\PlistCS.pdb
+C:\Users\mark\BinaryPlists\PlistCS\PlistCS\obj\Debug\ResolveAssemblyReference.cache
+C:\Users\mark\BinaryPlists\PlistCS\PlistCS\obj\Debug\PlistCS.dll
+C:\Users\mark\BinaryPlists\PlistCS\PlistCS\obj\Debug\PlistCS.pdb
Binary file not shown.
Binary file not shown.
View
@@ -56,6 +56,7 @@ public static object readPlist(string path)
else
{
XmlDocument xml = new XmlDocument();
+ xml.XmlResolver = null;
xml.LoadXml(System.Text.Encoding.UTF8.GetString(reader.ReadBytes((int)reader.BaseStream.Length)));
return readXml(xml);
}
@@ -125,11 +126,10 @@ public static string writeXml(object value)
using (XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings))
{
- xmlWriter.WriteStartDocument();
+ xmlWriter.WriteStartDocument();
xmlWriter.WriteComment("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
xmlWriter.WriteStartElement("plist");
xmlWriter.WriteAttributeString("version", "1.0");
- //writeDictionaryValues(dictionary, xmlWriter);
compose(value, xmlWriter);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
@@ -540,8 +540,7 @@ private static byte[] composeBinary(object obj)
public static byte[] writeBinaryDate(DateTime obj)
{
List<byte> buffer = RegulateNullBytes(BitConverter.GetBytes(PlistDateConverter.ConvertToAppleTimeStamp(obj)), 8).ToList();
- if (BitConverter.IsLittleEndian)
- buffer.Reverse();
+ buffer.Reverse();
buffer.Insert(0, 0x33);
objectTable.InsertRange(0, buffer);
return buffer.ToArray();
@@ -562,8 +561,7 @@ private static byte[] writeBinaryInteger(int value, bool write)
buffer.Add(0);
int header = 0x10 | (int)(Math.Log(buffer.Count) / Math.Log(2));
- if (BitConverter.IsLittleEndian)
- buffer.Reverse();
+ buffer.Reverse();
buffer.Insert(0, Convert.ToByte(header));
@@ -580,8 +578,7 @@ private static byte[] writeBinaryDouble(double value)
buffer.Add(0);
int header = 0x20 | (int)(Math.Log(buffer.Count) / Math.Log(2));
- if (BitConverter.IsLittleEndian)
- buffer.Reverse();
+ buffer.Reverse();
buffer.Insert(0, Convert.ToByte(header));
@@ -699,10 +696,10 @@ private static object parseBinaryDictionary(int objRef)
int refCount = 0;
byte dictByte = objectTable[offsetTable[objRef]];
-
- refCount = getCount(offsetTable[objRef], dictByte);
-
+
int refStartPosition;
+ refCount = getCount(offsetTable[objRef], out refStartPosition);
+
if (refCount < 15)
refStartPosition = offsetTable[objRef] + 1;
@@ -732,9 +729,9 @@ private static object parseBinaryArray(int objRef)
byte arrayByte = objectTable[offsetTable[objRef]];
- refCount = getCount(offsetTable[objRef], arrayByte);
-
int refStartPosition;
+ refCount = getCount(offsetTable[objRef], out refStartPosition);
+
if (refCount < 15)
refStartPosition = offsetTable[objRef] + 1;
@@ -757,15 +754,19 @@ private static object parseBinaryArray(int objRef)
return buffer;
}
- private static int getCount(int bytePosition, byte headerByte)
+ private static int getCount(int bytePosition, out int newBytePosition)
{
+ byte headerByte = objectTable[bytePosition];
byte headerByteTrail = Convert.ToByte(headerByte & 0xf);
+ int count;
if (headerByteTrail < 15)
- return headerByteTrail;
- else
{
- return (int)parseBinaryInt(bytePosition + 1);
+ count = headerByteTrail;
+ newBytePosition = bytePosition + 1;
}
+ else
+ count = (int)parseBinaryInt(bytePosition + 1, out newBytePosition);
+ return count;
}
private static object parseBinary(int objRef)
@@ -816,21 +817,26 @@ private static object parseBinary(int objRef)
public static object parseBinaryDate(int headerPosition)
{
byte[] buffer = objectTable.GetRange(headerPosition + 1, 8).ToArray();
- if (BitConverter.IsLittleEndian)
- Array.Reverse(buffer);
+ Array.Reverse(buffer);
double appleTime = BitConverter.ToDouble(buffer, 0);
DateTime result = PlistDateConverter.ConvertFromAppleTimeStamp(appleTime);
return result;
}
-
+
private static object parseBinaryInt(int headerPosition)
+ {
+ int output;
+ return parseBinaryInt(headerPosition, out output);
+ }
+
+ private static object parseBinaryInt(int headerPosition, out int newHeaderPosition)
{
byte header = objectTable[headerPosition];
int byteCount = (int)Math.Pow(2, header & 0xf);
byte[] buffer = objectTable.GetRange(headerPosition + 1, byteCount).ToArray();
- if (BitConverter.IsLittleEndian)
- Array.Reverse(buffer);
-
+ Array.Reverse(buffer);
+ //Add one to account for the header byte
+ newHeaderPosition = headerPosition + byteCount + 1;
return BitConverter.ToInt32(RegulateNullBytes(buffer, 4), 0);
}
@@ -846,13 +852,8 @@ private static object parseBinaryReal(int headerPosition)
private static object parseBinaryString(int headerPosition)
{
- byte headerByte = objectTable[headerPosition];
- int charCount = getCount(headerPosition, headerByte);
int charStartPosition;
- if (charCount < 15)
- charStartPosition = headerPosition + 1;
- else
- charStartPosition = headerPosition + 2 + RegulateNullBytes(BitConverter.GetBytes(charCount), 1).Length;
+ int charCount = getCount(headerPosition, out charStartPosition);
string buffer = "";
foreach (byte byt in objectTable.GetRange(charStartPosition, charCount))
{
@@ -863,13 +864,8 @@ private static object parseBinaryString(int headerPosition)
private static object parseBinaryByteArray(int headerPosition)
{
- byte headerByte = objectTable[headerPosition];
- int byteCount = getCount(headerPosition, headerByte);
int byteStartPosition;
- if (byteCount < 15)
- byteStartPosition = headerPosition + 1;
- else
- byteStartPosition = headerPosition + 2 + RegulateNullBytes(BitConverter.GetBytes(byteCount), 1).Length;
+ int byteCount = getCount(headerPosition, out byteStartPosition);
return objectTable.GetRange(byteStartPosition, byteCount).ToArray();
}
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestRun id="cce2db90-ce46-4fce-a36b-4c55b72b4b82" name="Mark@ANIMETRICSPC07 2011-10-28 16:42:33" runUser="ANIMETRICS\Mark" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestSettings name="Local" id="a7d51227-d16f-41c2-bc4f-cf9684c810c7">
+ <Description>These are default test settings for a local test run.</Description>
+ <Deployment runDeploymentRoot="Mark_ANIMETRICSPC07 2011-10-28 16_42_33">
+ <DeploymentItem filename="TestDocuments\" />
+ </Deployment>
+ <Execution>
+ <TestTypeSpecific>
+ <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
+ <AssemblyResolution>
+ <TestDirectory useLoadContext="true" />
+ </AssemblyResolution>
+ </UnitTestRunConfig>
+ </TestTypeSpecific>
+ <AgentRule name="Execution Agents">
+ </AgentRule>
+ </Execution>
+ </TestSettings>
+ <Times creation="2011-10-28T16:42:33.4911193-04:00" queuing="2011-10-28T16:42:41.3189020-04:00" start="2011-10-28T16:42:41.7029404-04:00" finish="2011-10-28T16:42:45.2452946-04:00" />
+ <ResultSummary outcome="Completed">
+ <Counters total="5" executed="5" passed="5" error="0" failed="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
+ </ResultSummary>
+ <TestDefinitions>
+ <UnitTest name="WriteXml" storage="c:\users\mark\binaryplists\plistcs\plistcs\bin\debug\plistcs.dll" id="20ba49e5-bd2e-d998-0e25-abc54b03ea3e">
+ <Execution id="c67f3233-b5f0-4bdc-8e81-c118635dd789" />
+ <TestMethod codeBase="C:/Users/mark/BinaryPlists/PlistCS/PlistCS/bin/Debug/PlistCS.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Testing.plistTests, PlistCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="WriteXml" />
+ </UnitTest>
+ <UnitTest name="ReadBinary" storage="c:\users\mark\binaryplists\plistcs\plistcs\bin\debug\plistcs.dll" id="e13d0195-e8af-a1d7-2a65-2f322e342ad4">
+ <Execution id="9c10aa59-11e9-453c-b886-35445c2cb3bd" />
+ <TestMethod codeBase="C:/Users/mark/BinaryPlists/PlistCS/PlistCS/bin/Debug/PlistCS.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Testing.plistTests, PlistCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="ReadBinary" />
+ </UnitTest>
+ <UnitTest name="WriteBinary" storage="c:\users\mark\binaryplists\plistcs\plistcs\bin\debug\plistcs.dll" id="1890a3d6-991e-d0b7-e84d-ad14e7ec06ca">
+ <Execution id="06843368-4aad-4cb1-8e93-84afbe719cbe" />
+ <TestMethod codeBase="C:/Users/mark/BinaryPlists/PlistCS/PlistCS/bin/Debug/PlistCS.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Testing.plistTests, PlistCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="WriteBinary" />
+ </UnitTest>
+ <UnitTest name="ReadWriteBinaryByteArray" storage="c:\users\mark\binaryplists\plistcs\plistcs\bin\debug\plistcs.dll" id="704d2384-63e4-24bd-d143-8a78eb88f9eb">
+ <Execution id="60086f43-23c0-4b6a-b7cb-65778aaa9983" />
+ <TestMethod codeBase="C:/Users/mark/BinaryPlists/PlistCS/PlistCS/bin/Debug/PlistCS.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Testing.plistTests, PlistCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="ReadWriteBinaryByteArray" />
+ </UnitTest>
+ <UnitTest name="ReadXml" storage="c:\users\mark\binaryplists\plistcs\plistcs\bin\debug\plistcs.dll" id="5652a79b-d1dd-cd2e-3818-c81c73fad10a">
+ <Execution id="61043557-65ad-4bdc-8f2f-0e7f645eb108" />
+ <TestMethod codeBase="C:/Users/mark/BinaryPlists/PlistCS/PlistCS/bin/Debug/PlistCS.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Testing.plistTests, PlistCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="ReadXml" />
+ </UnitTest>
+ </TestDefinitions>
+ <TestLists>
+ <TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ <TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
+ </TestLists>
+ <TestEntries>
+ <TestEntry testId="e13d0195-e8af-a1d7-2a65-2f322e342ad4" executionId="9c10aa59-11e9-453c-b886-35445c2cb3bd" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ <TestEntry testId="5652a79b-d1dd-cd2e-3818-c81c73fad10a" executionId="61043557-65ad-4bdc-8f2f-0e7f645eb108" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ <TestEntry testId="1890a3d6-991e-d0b7-e84d-ad14e7ec06ca" executionId="06843368-4aad-4cb1-8e93-84afbe719cbe" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ <TestEntry testId="20ba49e5-bd2e-d998-0e25-abc54b03ea3e" executionId="c67f3233-b5f0-4bdc-8e81-c118635dd789" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ <TestEntry testId="704d2384-63e4-24bd-d143-8a78eb88f9eb" executionId="60086f43-23c0-4b6a-b7cb-65778aaa9983" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
+ </TestEntries>
+ <Results>
+ <UnitTestResult executionId="9c10aa59-11e9-453c-b886-35445c2cb3bd" testId="e13d0195-e8af-a1d7-2a65-2f322e342ad4" testName="ReadBinary" computerName="ANIMETRICSPC07" duration="00:00:00.1654320" startTime="2011-10-28T16:42:41.8849586-04:00" endTime="2011-10-28T16:42:44.1811882-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="9c10aa59-11e9-453c-b886-35445c2cb3bd">
+ </UnitTestResult>
+ <UnitTestResult executionId="61043557-65ad-4bdc-8f2f-0e7f645eb108" testId="5652a79b-d1dd-cd2e-3818-c81c73fad10a" testName="ReadXml" computerName="ANIMETRICSPC07" duration="00:00:00.0782332" startTime="2011-10-28T16:42:44.2331934-04:00" endTime="2011-10-28T16:42:44.3312032-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="61043557-65ad-4bdc-8f2f-0e7f645eb108">
+ </UnitTestResult>
+ <UnitTestResult executionId="06843368-4aad-4cb1-8e93-84afbe719cbe" testId="1890a3d6-991e-d0b7-e84d-ad14e7ec06ca" testName="WriteBinary" computerName="ANIMETRICSPC07" duration="00:00:00.2270885" startTime="2011-10-28T16:42:44.4542155-04:00" endTime="2011-10-28T16:42:44.7162417-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="06843368-4aad-4cb1-8e93-84afbe719cbe">
+ </UnitTestResult>
+ <UnitTestResult executionId="c67f3233-b5f0-4bdc-8e81-c118635dd789" testId="20ba49e5-bd2e-d998-0e25-abc54b03ea3e" testName="WriteXml" computerName="ANIMETRICSPC07" duration="00:00:00.1038320" startTime="2011-10-28T16:42:44.7492450-04:00" endTime="2011-10-28T16:42:44.8682569-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="c67f3233-b5f0-4bdc-8e81-c118635dd789">
+ </UnitTestResult>
+ <UnitTestResult executionId="60086f43-23c0-4b6a-b7cb-65778aaa9983" testId="704d2384-63e4-24bd-d143-8a78eb88f9eb" testName="ReadWriteBinaryByteArray" computerName="ANIMETRICSPC07" duration="00:00:00.0112939" startTime="2011-10-28T16:42:44.8942595-04:00" endTime="2011-10-28T16:42:44.9232624-04:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="60086f43-23c0-4b6a-b7cb-65778aaa9983">
+ </UnitTestResult>
+ </Results>
+</TestRun>
Oops, something went wrong.

0 comments on commit 4daf8c8

Please sign in to comment.