Added code for handling resource forks when they are in the

data fork without headers (not Macbinary, neither AppleDouble,
	are supported).
This commit is contained in:
2016-09-02 02:58:13 +01:00
commit cd99f65ebf
23 changed files with 1683 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
2016-09-02 Natalia Portillo <claunia@claunia.com>
* Test.cs:
* packages.config:
* UDIF.rsrc:
* DiskCopy6.rsrc:
* DiskCopy42.rsrc:
* Claunia.RsrcFork.Test.csproj:
* SelfMountingImage.rsrc: Added code for handling resource
forks when they are in the data fork without headers (not
Macbinary, neither AppleDouble, are supported).

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D204981A-84C2-454D-AE41-7B16E9265339}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Claunia.RsrcFork.Test</RootNamespace>
<AssemblyName>Claunia.RsrcFork.Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Test.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Samples\SelfMountingImage.rsrc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Samples\DiskCopy6.rsrc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Samples\DiskCopy42.rsrc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Samples\UDIF.rsrc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Samples\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Claunia.RsrcFork\Claunia.RsrcFork.csproj">
<Project>{CA231ED3-0C78-496C-AAFE-D085F6E9BEC6}</Project>
<Name>Claunia.RsrcFork</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\LICENSE">
<Link>LICENSE</Link>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy FileWidth="120" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
<CSharpFormattingPolicy SpacingAfterMethodDeclarationName="False" SpaceAfterMethodCallName="False" SpaceAfterControlFlowStatementKeyword="False" SpaceBeforeOpenSquareBracket="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -0,0 +1,193 @@
//
// Test.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2016 © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.IO;
using NUnit.Framework;
namespace Claunia.RsrcFork.Test
{
[TestFixture]
public class Test
{
readonly byte[] DC42_Vers = { 0x06, 0x40, 0x80, 0x00, 0x00, 0x00, 0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79, 0x1C, 0x34, 0x2E, 0x32, 0x2C,
0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6B, 0x73, 0x75, 0x6D, 0x3D, 0x24, 0x41, 0x35, 0x31, 0x34, 0x37, 0x46, 0x37, 0x45 };
readonly byte[] DC42_Str = { 0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79 };
[Test]
public void TestDC42()
{
FileStream dc42Stream = new FileStream("Samples/DiskCopy42.rsrc", FileMode.Open, FileAccess.Read);
ResourceFork rsrc = new ResourceFork(dc42Stream);
uint[] types = rsrc.GetTypes();
Assert.AreEqual(0x53545220, types[0]);
Assert.AreEqual(0x76657273, types[1]);
Resource str_ = rsrc.GetResource(0x53545220);
Assert.IsNotNull(str_);
short[] str_Ids = str_.GetIds();
Assert.AreEqual(-16396, str_Ids[0]);
Assert.AreEqual(10, str_.GetLength(-16396));
byte[] str1 = str_.GetResource(-16396);
Assert.AreEqual(DC42_Str, str1);
string strStr = str_.GetName(-16396);
Assert.IsNull(strStr);
Resource vers = rsrc.GetResource(0x76657273);
Assert.IsNotNull(vers);
short[] versIds = vers.GetIds();
Assert.AreEqual(1, versIds[0]);
Assert.AreEqual(45, vers.GetLength(1));
byte[] vers1 = vers.GetResource(1);
Assert.AreEqual(DC42_Vers, vers1);
string versStr = vers.GetName(1);
Assert.IsNull(versStr);
}
[Test]
public void TestDC6()
{
FileStream dc6Stream = new FileStream("Samples/DiskCopy6.rsrc", FileMode.Open, FileAccess.Read);
ResourceFork rsrc = new ResourceFork(dc6Stream);
uint[] types = rsrc.GetTypes();
Assert.AreEqual(0x53545220, types[0]);
Assert.AreEqual(0x6263656D, types[1]);
Assert.AreEqual(0x62636D23, types[2]);
Assert.AreEqual(0x76657273, types[3]);
Resource str_ = rsrc.GetResource(0x53545220);
Assert.IsNotNull(str_);
short[] str_Ids = str_.GetIds();
Assert.AreEqual(-16396, str_Ids[0]);
Assert.AreEqual(10, str_.GetLength(-16396));
byte[] str1 = str_.GetResource(-16396);
Assert.AreEqual(DC42_Str, str1);
string strStr = str_.GetName(-16396);
Assert.IsNull(strStr);
Resource vers = rsrc.GetResource(0x76657273);
Assert.IsNotNull(vers);
short[] versIds = vers.GetIds();
Assert.AreEqual(1, versIds[0]);
Assert.AreEqual(66, vers.GetLength(1));
string versStr = vers.GetName(1);
Assert.IsNull(versStr);
Resource bcem = rsrc.GetResource(0x6263656D);
Assert.IsNotNull(bcem);
short[] bcemIds = bcem.GetIds();
Assert.AreEqual(128, bcemIds[0]);
Assert.AreEqual(224, bcem.GetLength(128));
string bcemStr = bcem.GetName(128);
Assert.IsNull(bcemStr);
Resource bceS = rsrc.GetResource(0x6263656D);
Assert.IsNotNull(bceS);
short[] bceSIds = bceS.GetIds();
Assert.AreEqual(128, bceSIds[0]);
Assert.AreEqual(224, bcem.GetLength(128));
string bceSStr = bceS.GetName(128);
Assert.IsNull(bceSStr);
}
[Test]
public void TestSMI()
{
FileStream smiStream = new FileStream("Samples/SelfMountingImage.rsrc", FileMode.Open, FileAccess.Read);
ResourceFork rsrc = new ResourceFork(smiStream);
uint[] types = rsrc.GetTypes();
Assert.AreEqual(29, types.Length);
Assert.AreEqual(0x424E444C, types[0]);
Assert.AreEqual(0x434F4445, types[1]);
Assert.AreEqual(0x44415441, types[2]);
Assert.AreEqual(0x4449544C, types[3]);
Assert.AreEqual(0x444C4F47, types[4]);
Assert.AreEqual(0x44525652, types[5]);
Assert.AreEqual(0x46524546, types[6]);
Assert.AreEqual(0x49434E23, types[7]);
Assert.AreEqual(0x4D505352, types[8]);
Assert.AreEqual(0x4D574242, types[9]);
Assert.AreEqual(0x50415420, types[10]);
Resource code = rsrc.GetResource(0x434F4445);
Assert.IsNotNull(code);
short[] codeIds = code.GetIds();
Assert.AreEqual(0, codeIds[0]);
Assert.AreEqual(1, codeIds[1]);
Assert.AreEqual(35130, code.GetLength(1));
string codeStr = code.GetName(1);
Assert.AreEqual("First Segment", codeStr); //"First Segment"
Resource bndl = rsrc.GetResource(0x424E444C);
Assert.IsNotNull(bndl);
short[] bndlIds = bndl.GetIds();
Assert.AreEqual(128, bndlIds[0]);
Assert.AreEqual(28, bndl.GetLength(128));
string bndlStr = bndl.GetName(128);
Assert.IsNull(bndlStr);
}
[Test]
public void TestUDIF()
{
FileStream udifStream = new FileStream("Samples/UDIF.rsrc", FileMode.Open, FileAccess.Read);
ResourceFork rsrc = new ResourceFork(udifStream);
uint[] types = rsrc.GetTypes();
Assert.AreEqual(2, types.Length);
Assert.AreEqual(0x626C6B78, types[0]);
Assert.AreEqual(0x706C7374, types[1]);
Resource blkx = rsrc.GetResource(0x626C6B78);
Assert.IsNotNull(blkx);
short[] blkxIds = blkx.GetIds();
Assert.AreEqual(0, blkxIds[0]);
Assert.AreEqual(524, blkx.GetLength(0));
string blkxStr = blkx.GetName(0);
Assert.AreEqual("Whole Device (Apple_XXX : 0)", blkxStr); //"First Segment"
Resource plst = rsrc.GetResource(0x706C7374);
Assert.IsNotNull(plst);
short[] plstIds = plst.GetIds();
Assert.AreEqual(0, plstIds[0]);
Assert.AreEqual(1544, plst.GetLength(0));
string plstStr = plst.GetName(0);
Assert.IsNull(plstStr);
}
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>