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,8 @@
2016-09-02 Natalia Portillo <claunia@claunia.com>
* Program.cs:
* AssemblyInfo.cs:
* Claunia.RsrcFork.CLI.csproj: 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,59 @@
<?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>{38A6F05E-8900-44E4-83A5-7A215175F78B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Claunia.RsrcFork.CLI</RootNamespace>
<AssemblyName>Claunia.RsrcFork.CLI</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>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
<CSharpFormattingPolicy IndentSwitchSection="True" NewLinesForBracesInProperties="True" NewLinesForBracesInAccessors="True" NewLinesForBracesInAnonymousMethods="True" NewLinesForBracesInControlBlocks="True" NewLinesForBracesInAnonymousTypes="True" NewLinesForBracesInObjectCollectionArrayInitializers="True" NewLinesForBracesInLambdaExpressionBody="True" NewLineForElse="True" NewLineForCatch="True" NewLineForFinally="True" NewLineForMembersInObjectInit="True" NewLineForMembersInAnonymousTypes="True" NewLineForClausesInQuery="True" SpacingAfterMethodDeclarationName="False" SpaceAfterMethodCallName="False" SpaceAfterControlFlowStatementKeyword="False" SpaceBeforeOpenSquareBracket="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>

View File

@@ -0,0 +1,152 @@
//
// Program.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;
using System.IO;
using System.Text;
using System.Linq;
namespace Claunia.RsrcFork.CLI
{
class MainClass
{
public static void Main (string [] args)
{
Console.WriteLine("Claunia.RsrcFork.CLI");
Console.WriteLine("© 2016 Natalia Portillo");
Console.WriteLine();
if(args.Length != 2 && args.Length != 4)
{
Usage();
return;
}
if(args.Length == 2)
{
if(args[0] != "-l")
{
Usage();
return;
}
if(!File.Exists(args[1]))
{
Console.WriteLine("Specified file does not exist.");
return;
}
FileStream rsrcStream = new FileStream(args[1], FileMode.Open, FileAccess.Read);
ResourceFork rsrc = new ResourceFork(rsrcStream);
foreach(uint type in rsrc.GetTypes())
{
byte[] typeBytes = BitConverter.GetBytes(type);
typeBytes = typeBytes.Reverse().ToArray();
string typeName = Types.GetName(type);
if(typeName != null)
Console.WriteLine("\"{0}\" (0x{1:X8}) - {2}", Encoding.ASCII.GetString(typeBytes), type, typeName);
else
Console.WriteLine("\"{0}\" (0x{1:X8})", Encoding.ASCII.GetString(typeBytes), type);
Resource rez = rsrc.GetResource(type);
Console.WriteLine("{0,6}{1,8}\t{2}", "ID", "Length", "Name");
Console.WriteLine("{0,6}{1,8}--{2}", "------", "--------", "----------------");
foreach(short id in rez.GetIds())
{
if(rez.GetName(id) != null)
Console.WriteLine("{0,6}{1,8}\t\"{2}\"", id, rez.GetLength(id), rez.GetName(id));
else
Console.WriteLine("{0,6}{1,8}", id, rez.GetLength(id));
}
Console.WriteLine();
}
return;
}
if(args.Length == 4)
{
if(args[0] != "-x")
{
Usage();
return;
}
if(args[1] != "-o")
{
Usage();
return;
}
if(Directory.Exists(args[2]))
{
Console.WriteLine("Output directory exists, not proceeding");
return;
}
if(!File.Exists(args[3]))
{
Console.WriteLine("Specified file does not exist.");
return;
}
FileStream rsrcStream = new FileStream(args[3], FileMode.Open, FileAccess.Read);
FileStream outStream;
ResourceFork rsrc = new ResourceFork(rsrcStream);
foreach(uint type in rsrc.GetTypes())
{
byte[] typeBytes = BitConverter.GetBytes(type);
typeBytes = typeBytes.Reverse().ToArray();
Directory.CreateDirectory(Path.Combine(args[2], Encoding.ASCII.GetString(typeBytes)));
Resource rez = rsrc.GetResource(type);
foreach(short id in rez.GetIds())
{
outStream = new FileStream(Path.Combine(args[2], Encoding.ASCII.GetString(typeBytes), string.Format("{0}", id)), FileMode.Create, FileAccess.ReadWrite);
byte[] rez_b = rez.GetResource(id);
outStream.Write(rez_b, 0, rez_b.Length);
outStream.Close();
}
}
return;
}
}
public static void Usage()
{
Console.WriteLine("Usage:");
Console.WriteLine("\tClaunia.RsrcFork.CLI.exe -l resourcefork.bin - Lists resources in resource fork file");
Console.WriteLine("\t\tor");
Console.WriteLine("\tClaunia.RsrcFork.CLI.EXE -x -o output.dir resourcefork.bin - Extracts all resources to output.dir");
}
}
}

View File

@@ -0,0 +1,52 @@
//
// AssemblyInfo.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.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Claunia.RsrcFork.CLI")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("Claunia.com")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("© Claunia.com")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]