mirror of
https://github.com/claunia/Claunia.RsrcFork.git
synced 2025-12-16 19:24:46 +00:00
Code refactor.
This commit is contained in:
@@ -23,16 +23,17 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork.CLI
|
namespace Claunia.RsrcFork.CLI
|
||||||
{
|
{
|
||||||
class MainClass
|
class MainClass
|
||||||
{
|
{
|
||||||
public static void Main (string [] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Claunia.RsrcFork.CLI");
|
Console.WriteLine("Claunia.RsrcFork.CLI");
|
||||||
Console.WriteLine("© 2016 Natalia Portillo");
|
Console.WriteLine("© 2016 Natalia Portillo");
|
||||||
@@ -68,20 +69,17 @@ namespace Claunia.RsrcFork.CLI
|
|||||||
typeBytes = typeBytes.Reverse().ToArray();
|
typeBytes = typeBytes.Reverse().ToArray();
|
||||||
string typeName = Types.GetName(type);
|
string typeName = Types.GetName(type);
|
||||||
if(typeName != null)
|
if(typeName != null)
|
||||||
Console.WriteLine("\"{0}\" (0x{1:X8}) - {2}", Encoding.ASCII.GetString(typeBytes), type, typeName);
|
Console.WriteLine("\"{0}\" (0x{1:X8}) - {2}", Encoding.ASCII.GetString(typeBytes), type,
|
||||||
else
|
typeName);
|
||||||
Console.WriteLine("\"{0}\" (0x{1:X8})", Encoding.ASCII.GetString(typeBytes), type);
|
else Console.WriteLine("\"{0}\" (0x{1:X8})", Encoding.ASCII.GetString(typeBytes), type);
|
||||||
|
|
||||||
Resource rez = rsrc.GetResource(type);
|
Resource rez = rsrc.GetResource(type);
|
||||||
Console.WriteLine("{0,6}{1,8}\t{2}", "ID", "Length", "Name");
|
Console.WriteLine("{0,6}{1,8}\t{2}", "ID", "Length", "Name");
|
||||||
Console.WriteLine("{0,6}{1,8}--{2}", "------", "--------", "----------------");
|
Console.WriteLine("{0,6}{1,8}--{2}", "------", "--------", "----------------");
|
||||||
foreach(short id in rez.GetIds())
|
foreach(short id in rez.GetIds())
|
||||||
{
|
|
||||||
if(rez.GetName(id) != null)
|
if(rez.GetName(id) != null)
|
||||||
Console.WriteLine("{0,6}{1,8}\t\"{2}\"", id, rez.GetLength(id), rez.GetName(id));
|
Console.WriteLine("{0,6}{1,8}\t\"{2}\"", id, rez.GetLength(id), rez.GetName(id));
|
||||||
else
|
else Console.WriteLine("{0,6}{1,8}", id, rez.GetLength(id));
|
||||||
Console.WriteLine("{0,6}{1,8}", id, rez.GetLength(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
@@ -130,14 +128,15 @@ namespace Claunia.RsrcFork.CLI
|
|||||||
Resource rez = rsrc.GetResource(type);
|
Resource rez = rsrc.GetResource(type);
|
||||||
foreach(short id in rez.GetIds())
|
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);
|
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);
|
byte[] rez_b = rez.GetResource(id);
|
||||||
outStream.Write(rez_b, 0, rez_b.Length);
|
outStream.Write(rez_b, 0, rez_b.Length);
|
||||||
outStream.Close();
|
outStream.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,4 +148,4 @@ namespace Claunia.RsrcFork.CLI
|
|||||||
Console.WriteLine("\tClaunia.RsrcFork.CLI.EXE -x -o output.dir resourcefork.bin - Extracts all resources to output.dir");
|
Console.WriteLine("\tClaunia.RsrcFork.CLI.EXE -x -o output.dir resourcefork.bin - Extracts all resources to output.dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,30 +23,29 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
// Information about this assembly is defined by the following attributes.
|
// Information about this assembly is defined by the following attributes.
|
||||||
// Change them to the values specific to your project.
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
[assembly: AssemblyTitle ("Claunia.RsrcFork.CLI")]
|
[assembly: AssemblyTitle("Claunia.RsrcFork.CLI")]
|
||||||
[assembly: AssemblyDescription ("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration ("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany ("Claunia.com")]
|
[assembly: AssemblyCompany("Claunia.com")]
|
||||||
[assembly: AssemblyProduct ("")]
|
[assembly: AssemblyProduct("")]
|
||||||
[assembly: AssemblyCopyright ("© Claunia.com")]
|
[assembly: AssemblyCopyright("© Claunia.com")]
|
||||||
[assembly: AssemblyTrademark ("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture ("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
[assembly: AssemblyVersion ("1.0.*")]
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
// The following attributes are used to specify the signing key for the assembly,
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
// if desired. See the Mono documentation for more information about signing.
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
//[assembly: AssemblyDelaySign(false)]
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
//[assembly: AssemblyKeyFile("")]
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
@@ -33,15 +33,19 @@ namespace Claunia.RsrcFork.Test
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class Test
|
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,
|
readonly byte[] DC42_Vers =
|
||||||
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 };
|
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]
|
[Test]
|
||||||
public void TestDC42()
|
public void TestDC42()
|
||||||
{
|
{
|
||||||
FileStream dc42Stream = new FileStream("Samples/DiskCopy42.rsrc", FileMode.Open, FileAccess.Read);
|
FileStream dc42Stream = new FileStream("Samples/DiskCopy42.rsrc", FileMode.Open, FileAccess.Read);
|
||||||
ResourceFork rsrc = new ResourceFork(dc42Stream);
|
ResourceFork rsrc = new ResourceFork(dc42Stream);
|
||||||
|
|
||||||
uint[] types = rsrc.GetTypes();
|
uint[] types = rsrc.GetTypes();
|
||||||
Assert.AreEqual(0x53545220, types[0]);
|
Assert.AreEqual(0x53545220, types[0]);
|
||||||
@@ -52,7 +56,7 @@ namespace Claunia.RsrcFork.Test
|
|||||||
|
|
||||||
short[] str_Ids = str_.GetIds();
|
short[] str_Ids = str_.GetIds();
|
||||||
Assert.AreEqual(-16396, str_Ids[0]);
|
Assert.AreEqual(-16396, str_Ids[0]);
|
||||||
Assert.AreEqual(10, str_.GetLength(-16396));
|
Assert.AreEqual(10, str_.GetLength(-16396));
|
||||||
|
|
||||||
byte[] str1 = str_.GetResource(-16396);
|
byte[] str1 = str_.GetResource(-16396);
|
||||||
Assert.AreEqual(DC42_Str, str1);
|
Assert.AreEqual(DC42_Str, str1);
|
||||||
@@ -63,7 +67,7 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Resource vers = rsrc.GetResource(0x76657273);
|
Resource vers = rsrc.GetResource(0x76657273);
|
||||||
Assert.IsNotNull(vers);
|
Assert.IsNotNull(vers);
|
||||||
short[] versIds = vers.GetIds();
|
short[] versIds = vers.GetIds();
|
||||||
Assert.AreEqual(1, versIds[0]);
|
Assert.AreEqual(1, versIds[0]);
|
||||||
Assert.AreEqual(45, vers.GetLength(1));
|
Assert.AreEqual(45, vers.GetLength(1));
|
||||||
|
|
||||||
byte[] vers1 = vers.GetResource(1);
|
byte[] vers1 = vers.GetResource(1);
|
||||||
@@ -73,20 +77,20 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Assert.IsNull(versStr);
|
Assert.IsNull(versStr);
|
||||||
|
|
||||||
Version versDec = new Version(vers1);
|
Version versDec = new Version(vers1);
|
||||||
Assert.AreEqual(6, versDec.MajorVersion);
|
Assert.AreEqual(6, versDec.MajorVersion);
|
||||||
Assert.AreEqual(40, versDec.MinorVersion);
|
Assert.AreEqual(40, versDec.MinorVersion);
|
||||||
Assert.AreEqual(Version.DevelopmentStage.Final, versDec.DevStage);
|
Assert.AreEqual(Version.DevelopmentStage.Final, versDec.DevStage);
|
||||||
Assert.AreEqual(0, versDec.PreReleaseVersion);
|
Assert.AreEqual(0, versDec.PreReleaseVersion);
|
||||||
Assert.AreEqual(0, versDec.RegionCode);
|
Assert.AreEqual(0, versDec.RegionCode);
|
||||||
Assert.AreEqual("Disk Copy", versDec.VersionString);
|
Assert.AreEqual("Disk Copy", versDec.VersionString);
|
||||||
Assert.AreEqual("4.2, data checksum=$A5147F7E", versDec.VersionMessage);
|
Assert.AreEqual("4.2, data checksum=$A5147F7E", versDec.VersionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDC6()
|
public void TestDC6()
|
||||||
{
|
{
|
||||||
FileStream dc6Stream = new FileStream("Samples/DiskCopy6.rsrc", FileMode.Open, FileAccess.Read);
|
FileStream dc6Stream = new FileStream("Samples/DiskCopy6.rsrc", FileMode.Open, FileAccess.Read);
|
||||||
ResourceFork rsrc = new ResourceFork(dc6Stream);
|
ResourceFork rsrc = new ResourceFork(dc6Stream);
|
||||||
|
|
||||||
uint[] types = rsrc.GetTypes();
|
uint[] types = rsrc.GetTypes();
|
||||||
Assert.AreEqual(0x53545220, types[0]);
|
Assert.AreEqual(0x53545220, types[0]);
|
||||||
@@ -99,7 +103,7 @@ namespace Claunia.RsrcFork.Test
|
|||||||
|
|
||||||
short[] str_Ids = str_.GetIds();
|
short[] str_Ids = str_.GetIds();
|
||||||
Assert.AreEqual(-16396, str_Ids[0]);
|
Assert.AreEqual(-16396, str_Ids[0]);
|
||||||
Assert.AreEqual(10, str_.GetLength(-16396));
|
Assert.AreEqual(10, str_.GetLength(-16396));
|
||||||
|
|
||||||
byte[] str1 = str_.GetResource(-16396);
|
byte[] str1 = str_.GetResource(-16396);
|
||||||
Assert.AreEqual(DC42_Str, str1);
|
Assert.AreEqual(DC42_Str, str1);
|
||||||
@@ -110,7 +114,7 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Resource vers = rsrc.GetResource(0x76657273);
|
Resource vers = rsrc.GetResource(0x76657273);
|
||||||
Assert.IsNotNull(vers);
|
Assert.IsNotNull(vers);
|
||||||
short[] versIds = vers.GetIds();
|
short[] versIds = vers.GetIds();
|
||||||
Assert.AreEqual(1, versIds[0]);
|
Assert.AreEqual(1, versIds[0]);
|
||||||
Assert.AreEqual(66, vers.GetLength(1));
|
Assert.AreEqual(66, vers.GetLength(1));
|
||||||
|
|
||||||
string versStr = vers.GetName(1);
|
string versStr = vers.GetName(1);
|
||||||
@@ -132,25 +136,25 @@ namespace Claunia.RsrcFork.Test
|
|||||||
string bceSStr = bceS.GetName(128);
|
string bceSStr = bceS.GetName(128);
|
||||||
Assert.IsNull(bceSStr);
|
Assert.IsNull(bceSStr);
|
||||||
|
|
||||||
byte[] vers1 = vers.GetResource(1);
|
byte[] vers1 = vers.GetResource(1);
|
||||||
Version versDec = new Version(vers1);
|
Version versDec = new Version(vers1);
|
||||||
Assert.AreEqual(6, versDec.MajorVersion);
|
Assert.AreEqual(6, versDec.MajorVersion);
|
||||||
Assert.AreEqual(40, versDec.MinorVersion);
|
Assert.AreEqual(40, versDec.MinorVersion);
|
||||||
Assert.AreEqual(Version.DevelopmentStage.Final, versDec.DevStage);
|
Assert.AreEqual(Version.DevelopmentStage.Final, versDec.DevStage);
|
||||||
Assert.AreEqual(0, versDec.PreReleaseVersion);
|
Assert.AreEqual(0, versDec.PreReleaseVersion);
|
||||||
Assert.AreEqual(0, versDec.RegionCode);
|
Assert.AreEqual(0, versDec.RegionCode);
|
||||||
Assert.AreEqual("6.4 Disk Copy", versDec.VersionString);
|
Assert.AreEqual("6.4 Disk Copy", versDec.VersionString);
|
||||||
Assert.AreEqual("Mac? OS HFS 1680K disk image\rCRC28: $07213FB7", versDec.VersionMessage);
|
Assert.AreEqual("Mac? OS HFS 1680K disk image\rCRC28: $07213FB7", versDec.VersionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSMI()
|
public void TestSMI()
|
||||||
{
|
{
|
||||||
FileStream smiStream = new FileStream("Samples/SelfMountingImage.rsrc", FileMode.Open, FileAccess.Read);
|
FileStream smiStream = new FileStream("Samples/SelfMountingImage.rsrc", FileMode.Open, FileAccess.Read);
|
||||||
ResourceFork rsrc = new ResourceFork(smiStream);
|
ResourceFork rsrc = new ResourceFork(smiStream);
|
||||||
|
|
||||||
uint[] types = rsrc.GetTypes();
|
uint[] types = rsrc.GetTypes();
|
||||||
Assert.AreEqual(29, types.Length);
|
Assert.AreEqual(29, types.Length);
|
||||||
Assert.AreEqual(0x424E444C, types[0]);
|
Assert.AreEqual(0x424E444C, types[0]);
|
||||||
Assert.AreEqual(0x434F4445, types[1]);
|
Assert.AreEqual(0x434F4445, types[1]);
|
||||||
Assert.AreEqual(0x44415441, types[2]);
|
Assert.AreEqual(0x44415441, types[2]);
|
||||||
@@ -166,8 +170,8 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Resource code = rsrc.GetResource(0x434F4445);
|
Resource code = rsrc.GetResource(0x434F4445);
|
||||||
Assert.IsNotNull(code);
|
Assert.IsNotNull(code);
|
||||||
short[] codeIds = code.GetIds();
|
short[] codeIds = code.GetIds();
|
||||||
Assert.AreEqual(0, codeIds[0]);
|
Assert.AreEqual(0, codeIds[0]);
|
||||||
Assert.AreEqual(1, codeIds[1]);
|
Assert.AreEqual(1, codeIds[1]);
|
||||||
Assert.AreEqual(35130, code.GetLength(1));
|
Assert.AreEqual(35130, code.GetLength(1));
|
||||||
string codeStr = code.GetName(1);
|
string codeStr = code.GetName(1);
|
||||||
Assert.AreEqual("First Segment", codeStr); //"First Segment"
|
Assert.AreEqual("First Segment", codeStr); //"First Segment"
|
||||||
@@ -176,38 +180,38 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Assert.IsNotNull(bndl);
|
Assert.IsNotNull(bndl);
|
||||||
short[] bndlIds = bndl.GetIds();
|
short[] bndlIds = bndl.GetIds();
|
||||||
Assert.AreEqual(128, bndlIds[0]);
|
Assert.AreEqual(128, bndlIds[0]);
|
||||||
Assert.AreEqual(28, bndl.GetLength(128));
|
Assert.AreEqual(28, bndl.GetLength(128));
|
||||||
string bndlStr = bndl.GetName(128);
|
string bndlStr = bndl.GetName(128);
|
||||||
Assert.IsNull(bndlStr);
|
Assert.IsNull(bndlStr);
|
||||||
|
|
||||||
Resource vers = rsrc.GetResource(0x76657273);
|
Resource vers = rsrc.GetResource(0x76657273);
|
||||||
Assert.IsNotNull(vers);
|
Assert.IsNotNull(vers);
|
||||||
byte[] vers1 = vers.GetResource(1);
|
byte[] vers1 = vers.GetResource(1);
|
||||||
Version versDec = new Version(vers1);
|
Version versDec = new Version(vers1);
|
||||||
Assert.AreEqual(1, versDec.MajorVersion);
|
Assert.AreEqual(1, versDec.MajorVersion);
|
||||||
Assert.AreEqual(10, versDec.MinorVersion);
|
Assert.AreEqual(10, versDec.MinorVersion);
|
||||||
Assert.AreEqual(Version.DevelopmentStage.Beta, versDec.DevStage);
|
Assert.AreEqual(Version.DevelopmentStage.Beta, versDec.DevStage);
|
||||||
Assert.AreEqual(6, versDec.PreReleaseVersion);
|
Assert.AreEqual(6, versDec.PreReleaseVersion);
|
||||||
Assert.AreEqual(0, versDec.RegionCode);
|
Assert.AreEqual(0, versDec.RegionCode);
|
||||||
Assert.AreEqual("1.1b6", versDec.VersionString);
|
Assert.AreEqual("1.1b6", versDec.VersionString);
|
||||||
Assert.AreEqual("1.1b6, Copyright 1997-2001 Apple Computer, Inc.", versDec.VersionMessage);
|
Assert.AreEqual("1.1b6, Copyright 1997-2001 Apple Computer, Inc.", versDec.VersionMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUDIF()
|
public void TestUDIF()
|
||||||
{
|
{
|
||||||
FileStream udifStream = new FileStream("Samples/UDIF.rsrc", FileMode.Open, FileAccess.Read);
|
FileStream udifStream = new FileStream("Samples/UDIF.rsrc", FileMode.Open, FileAccess.Read);
|
||||||
ResourceFork rsrc = new ResourceFork(udifStream);
|
ResourceFork rsrc = new ResourceFork(udifStream);
|
||||||
|
|
||||||
uint[] types = rsrc.GetTypes();
|
uint[] types = rsrc.GetTypes();
|
||||||
Assert.AreEqual(2, types.Length);
|
Assert.AreEqual(2, types.Length);
|
||||||
Assert.AreEqual(0x626C6B78, types[0]);
|
Assert.AreEqual(0x626C6B78, types[0]);
|
||||||
Assert.AreEqual(0x706C7374, types[1]);
|
Assert.AreEqual(0x706C7374, types[1]);
|
||||||
|
|
||||||
Resource blkx = rsrc.GetResource(0x626C6B78);
|
Resource blkx = rsrc.GetResource(0x626C6B78);
|
||||||
Assert.IsNotNull(blkx);
|
Assert.IsNotNull(blkx);
|
||||||
short[] blkxIds = blkx.GetIds();
|
short[] blkxIds = blkx.GetIds();
|
||||||
Assert.AreEqual(0, blkxIds[0]);
|
Assert.AreEqual(0, blkxIds[0]);
|
||||||
Assert.AreEqual(524, blkx.GetLength(0));
|
Assert.AreEqual(524, blkx.GetLength(0));
|
||||||
string blkxStr = blkx.GetName(0);
|
string blkxStr = blkx.GetName(0);
|
||||||
Assert.AreEqual("Whole Device (Apple_XXX : 0)", blkxStr); //"First Segment"
|
Assert.AreEqual("Whole Device (Apple_XXX : 0)", blkxStr); //"First Segment"
|
||||||
@@ -215,7 +219,7 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Resource plst = rsrc.GetResource(0x706C7374);
|
Resource plst = rsrc.GetResource(0x706C7374);
|
||||||
Assert.IsNotNull(plst);
|
Assert.IsNotNull(plst);
|
||||||
short[] plstIds = plst.GetIds();
|
short[] plstIds = plst.GetIds();
|
||||||
Assert.AreEqual(0, plstIds[0]);
|
Assert.AreEqual(0, plstIds[0]);
|
||||||
Assert.AreEqual(1544, plst.GetLength(0));
|
Assert.AreEqual(1544, plst.GetLength(0));
|
||||||
string plstStr = plst.GetName(0);
|
string plstStr = plst.GetName(0);
|
||||||
Assert.IsNull(plstStr);
|
Assert.IsNull(plstStr);
|
||||||
@@ -224,5 +228,4 @@ namespace Claunia.RsrcFork.Test
|
|||||||
Assert.IsNull(vers);
|
Assert.IsNull(vers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,51 +23,48 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// 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
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains convertes between .NET and Pascal strings. Only ASCII supported right now.
|
/// Contains convertes between .NET and Pascal strings. Only ASCII supported right now.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class PascalString
|
public static class PascalString
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts an ASCII Pascal string to a .NET string.
|
/// Converts an ASCII Pascal string to a .NET string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The .NET string.</returns>
|
/// <returns>The .NET string.</returns>
|
||||||
/// <param name="PStr">The ASCII Pascal string.</param>
|
/// <param name="PStr">The ASCII Pascal string.</param>
|
||||||
public static string GetString(byte[] PStr)
|
public static string GetString(byte[] PStr)
|
||||||
{
|
{
|
||||||
if(PStr == null || PStr[0] >= PStr.Length)
|
if(PStr == null || PStr[0] >= PStr.Length) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
return Encoding.ASCII.GetString(PStr, 1, PStr[0]);
|
return Encoding.ASCII.GetString(PStr, 1, PStr[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a .NET string to an ASCII Pascal string.
|
/// Converts a .NET string to an ASCII Pascal string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The ASCII Pascal string.</returns>
|
/// <returns>The ASCII Pascal string.</returns>
|
||||||
/// <param name="str">The .NET string.</param>
|
/// <param name="str">The .NET string.</param>
|
||||||
public static byte[] GetBytes(string str)
|
public static byte[] GetBytes(string str)
|
||||||
{
|
{
|
||||||
if(str == null)
|
if(str == null) return new byte[1];
|
||||||
return new byte[1];
|
|
||||||
|
|
||||||
byte[] str_b = Encoding.ASCII.GetBytes(str);
|
byte[] str_b = Encoding.ASCII.GetBytes(str);
|
||||||
byte[] PStr;
|
byte[] PStr;
|
||||||
|
|
||||||
if(str_b.Length >= 256)
|
if(str_b.Length >= 256) PStr = new byte[256];
|
||||||
PStr = new byte[256];
|
else PStr = new byte[str_b.Length + 1];
|
||||||
else
|
|
||||||
PStr = new byte[str_b.Length + 1];
|
|
||||||
|
|
||||||
Array.Copy(str_b, 0, PStr, 1, PStr.Length - 1);
|
Array.Copy(str_b, 0, PStr, 1, PStr.Length - 1);
|
||||||
PStr[0] = (byte)(PStr.Length - 1);
|
PStr[0] = (byte)(PStr.Length - 1);
|
||||||
|
|
||||||
return PStr;
|
return PStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,24 +33,18 @@ using System.Text;
|
|||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class represents a resource type.
|
/// This class represents a resource type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Resource
|
public class Resource
|
||||||
{
|
{
|
||||||
readonly Dictionary<short, string> resourceNames;
|
readonly List<short> ids;
|
||||||
|
readonly Dictionary<short, byte[]> resourceCache;
|
||||||
|
readonly Dictionary<short, string> resourceNames;
|
||||||
readonly Dictionary<short, ResourceData> resources;
|
readonly Dictionary<short, ResourceData> resources;
|
||||||
readonly Dictionary<short, byte[]> resourceCache;
|
readonly Stream rsrcStream;
|
||||||
readonly Stream rsrcStream;
|
|
||||||
readonly List<short> ids;
|
|
||||||
|
|
||||||
struct ResourceData
|
|
||||||
{
|
|
||||||
public long offset;
|
|
||||||
public long length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializates the specified resource type.
|
/// Initializates the specified resource type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">Stream where the resources of this reside.</param>
|
/// <param name="stream">Stream where the resources of this reside.</param>
|
||||||
/// <param name="resources">How many resource of this type are.</param>
|
/// <param name="resources">How many resource of this type are.</param>
|
||||||
@@ -58,13 +52,15 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="resourceNameOffset">Offset from start of stream to resource name list.</param>
|
/// <param name="resourceNameOffset">Offset from start of stream to resource name list.</param>
|
||||||
/// <param name="resourceDataOffset">Offset from start of stream to resource data.</param>
|
/// <param name="resourceDataOffset">Offset from start of stream to resource data.</param>
|
||||||
/// <param name="OSType">Resource type.</param>
|
/// <param name="OSType">Resource type.</param>
|
||||||
internal Resource(Stream stream, ushort resources, long referenceListOff, long resourceNameOffset, long resourceDataOffset, uint OSType)
|
internal Resource(Stream stream, ushort resources, long referenceListOff, long resourceNameOffset,
|
||||||
|
long resourceDataOffset, uint OSType)
|
||||||
{
|
{
|
||||||
rsrcStream = stream;
|
rsrcStream = stream;
|
||||||
Dictionary<short, ResourceTypeReferenceListItem> referenceLists = new Dictionary<short, ResourceTypeReferenceListItem>();
|
Dictionary<short, ResourceTypeReferenceListItem> referenceLists =
|
||||||
resourceNames = new Dictionary<short, string>();
|
new Dictionary<short, ResourceTypeReferenceListItem>();
|
||||||
|
resourceNames = new Dictionary<short, string>();
|
||||||
this.resources = new Dictionary<short, ResourceData>();
|
this.resources = new Dictionary<short, ResourceData>();
|
||||||
ids = new List<short>();
|
ids = new List<short>();
|
||||||
byte[] tmp;
|
byte[] tmp;
|
||||||
|
|
||||||
rsrcStream.Seek(referenceListOff + 2, SeekOrigin.Begin);
|
rsrcStream.Seek(referenceListOff + 2, SeekOrigin.Begin);
|
||||||
@@ -76,11 +72,11 @@ namespace Claunia.RsrcFork
|
|||||||
item.id = BitConverter.ToInt16(tmp.Reverse().ToArray(), 0);
|
item.id = BitConverter.ToInt16(tmp.Reverse().ToArray(), 0);
|
||||||
rsrcStream.Read(tmp, 0, 2);
|
rsrcStream.Read(tmp, 0, 2);
|
||||||
item.nameOff = BitConverter.ToInt16(tmp.Reverse().ToArray(), 0);
|
item.nameOff = BitConverter.ToInt16(tmp.Reverse().ToArray(), 0);
|
||||||
tmp = new byte[4];
|
tmp = new byte[4];
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
item.attributes = tmp[0];
|
item.attributes = tmp[0];
|
||||||
tmp[0] = 0;
|
tmp[0] = 0;
|
||||||
item.dataOff = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
item.dataOff = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
item.handle = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
item.handle = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
@@ -90,15 +86,14 @@ namespace Claunia.RsrcFork
|
|||||||
|
|
||||||
foreach(ResourceTypeReferenceListItem item in referenceLists.Values)
|
foreach(ResourceTypeReferenceListItem item in referenceLists.Values)
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
ResourceData data = new ResourceData();
|
ResourceData data = new ResourceData();
|
||||||
|
|
||||||
if(item.nameOff == -1)
|
if(item.nameOff == -1) name = null;
|
||||||
name = null;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rsrcStream.Seek(resourceNameOffset + item.nameOff, SeekOrigin.Begin);
|
rsrcStream.Seek(resourceNameOffset + item.nameOff, SeekOrigin.Begin);
|
||||||
byte nameLen = (byte)rsrcStream.ReadByte();
|
byte nameLen = (byte)rsrcStream.ReadByte();
|
||||||
byte[] nameBytes = new byte[nameLen];
|
byte[] nameBytes = new byte[nameLen];
|
||||||
rsrcStream.Read(nameBytes, 0, nameLen);
|
rsrcStream.Read(nameBytes, 0, nameLen);
|
||||||
// TODO: Use MacRoman
|
// TODO: Use MacRoman
|
||||||
@@ -119,7 +114,7 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the specified resource id, or null if there is no name.
|
/// Gets the name of the specified resource id, or null if there is no name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The name.</returns>
|
/// <returns>The name.</returns>
|
||||||
/// <param name="id">Identifier.</param>
|
/// <param name="id">Identifier.</param>
|
||||||
@@ -130,7 +125,7 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the resource contents.
|
/// Gets the resource contents.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The resource.</returns>
|
/// <returns>The resource.</returns>
|
||||||
/// <param name="id">Identifier.</param>
|
/// <param name="id">Identifier.</param>
|
||||||
@@ -138,13 +133,11 @@ namespace Claunia.RsrcFork
|
|||||||
{
|
{
|
||||||
byte[] resource;
|
byte[] resource;
|
||||||
|
|
||||||
if(resourceCache.TryGetValue(id, out resource))
|
if(resourceCache.TryGetValue(id, out resource)) return resource;
|
||||||
return resource;
|
|
||||||
|
|
||||||
ResourceData data;
|
ResourceData data;
|
||||||
|
|
||||||
if(!resources.TryGetValue(id, out data))
|
if(!resources.TryGetValue(id, out data)) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
resource = new byte[data.length];
|
resource = new byte[data.length];
|
||||||
rsrcStream.Seek(data.offset, SeekOrigin.Begin);
|
rsrcStream.Seek(data.offset, SeekOrigin.Begin);
|
||||||
@@ -156,7 +149,7 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the length of the resource specified by ID.
|
/// Gets the length of the resource specified by ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The length.</returns>
|
/// <returns>The length.</returns>
|
||||||
/// <param name="id">Resource identifier.</param>
|
/// <param name="id">Resource identifier.</param>
|
||||||
@@ -167,23 +160,22 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the IDs of all the resources contained by this instance.
|
/// Gets the IDs of all the resources contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The identifiers.</returns>
|
/// <returns>The identifiers.</returns>
|
||||||
public short[] GetIds()
|
public short[] GetIds() => ids.ToArray();
|
||||||
{
|
|
||||||
return ids.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the resource specified by ID is contained by this instance.
|
/// Checks if the resource specified by ID is contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c>, if the resource is contained in this instance, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c>, if the resource is contained in this instance, <c>false</c> otherwise.</returns>
|
||||||
/// <param name="id">Resource identifier.</param>
|
/// <param name="id">Resource identifier.</param>
|
||||||
public bool ContainsId(short id)
|
public bool ContainsId(short id) => ids.Contains(id);
|
||||||
|
|
||||||
|
struct ResourceData
|
||||||
{
|
{
|
||||||
return ids.Contains(id);
|
public long offset;
|
||||||
|
public long length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,19 +31,19 @@ using System.Linq;
|
|||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class represents a resource fork.
|
/// This class represents a resource fork.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResourceFork
|
public class ResourceFork
|
||||||
{
|
{
|
||||||
Stream rsrcStream;
|
ResourceHeader header;
|
||||||
ResourceHeader header;
|
ResourceMap map;
|
||||||
ResourceMap map;
|
List<uint> osTypes;
|
||||||
|
Dictionary<uint, Resource> resourceCache;
|
||||||
Dictionary<uint, ResourceTypeListItem> resourceTypeList;
|
Dictionary<uint, ResourceTypeListItem> resourceTypeList;
|
||||||
Dictionary<uint, Resource> resourceCache;
|
readonly Stream rsrcStream;
|
||||||
List<uint> osTypes;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializates a resource fork using a byte array as backend.
|
/// Initializates a resource fork using a byte array as backend.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="buffer">Buffer.</param>
|
/// <param name="buffer">Buffer.</param>
|
||||||
public ResourceFork(byte[] buffer)
|
public ResourceFork(byte[] buffer)
|
||||||
@@ -53,7 +53,7 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializates a resource fork using a stream as backed.
|
/// Initializates a resource fork using a stream as backed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">Stream.</param>
|
/// <param name="stream">Stream.</param>
|
||||||
public ResourceFork(Stream stream)
|
public ResourceFork(Stream stream)
|
||||||
@@ -63,16 +63,15 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cleans up this instances and closes the underlying stream.
|
/// Cleans up this instances and closes the underlying stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
~ResourceFork()
|
~ResourceFork()
|
||||||
{
|
{
|
||||||
if(rsrcStream != null)
|
if(rsrcStream != null) rsrcStream.Dispose();
|
||||||
rsrcStream.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes this instance.
|
/// Initializes this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
@@ -88,14 +87,14 @@ namespace Claunia.RsrcFork
|
|||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
header.resourceMapLen = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
header.resourceMapLen = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
if(header.resourceDataOff <= 0 || header.resourceMapOff <= 0 || header.resourceDataLen <= 0 || header.resourceMapLen <= 0)
|
if(header.resourceDataOff <= 0 || header.resourceMapOff <= 0 || header.resourceDataLen <= 0 ||
|
||||||
throw new InvalidCastException("Not a resource fork");
|
header.resourceMapLen <= 0) throw new InvalidCastException("Not a resource fork");
|
||||||
|
|
||||||
if(header.resourceDataOff + header.resourceDataLen > rsrcStream.Length ||
|
if(header.resourceDataOff + header.resourceDataLen > rsrcStream.Length ||
|
||||||
header.resourceMapOff + header.resourceMapLen > rsrcStream.Length)
|
header.resourceMapOff + header.resourceMapLen > rsrcStream.Length)
|
||||||
throw new InvalidCastException("Not a resource fork");
|
throw new InvalidCastException("Not a resource fork");
|
||||||
|
|
||||||
map = new ResourceMap();
|
map = new ResourceMap();
|
||||||
map.header = new ResourceHeader();
|
map.header = new ResourceHeader();
|
||||||
rsrcStream.Seek(header.resourceMapOff, SeekOrigin.Begin);
|
rsrcStream.Seek(header.resourceMapOff, SeekOrigin.Begin);
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
@@ -109,13 +108,13 @@ namespace Claunia.RsrcFork
|
|||||||
|
|
||||||
if(map.header.resourceDataOff != header.resourceDataOff ||
|
if(map.header.resourceDataOff != header.resourceDataOff ||
|
||||||
map.header.resourceDataLen != header.resourceDataLen ||
|
map.header.resourceDataLen != header.resourceDataLen ||
|
||||||
map.header.resourceMapOff != header.resourceMapOff ||
|
map.header.resourceMapOff != header.resourceMapOff ||
|
||||||
map.header.resourceMapLen != header.resourceMapLen)
|
map.header.resourceMapLen != header.resourceMapLen)
|
||||||
throw new InvalidCastException("Header copy is not same as header.");
|
throw new InvalidCastException("Header copy is not same as header.");
|
||||||
|
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
map.handleToNextMap = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
map.handleToNextMap = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
||||||
tmp = new byte[2];
|
tmp = new byte[2];
|
||||||
rsrcStream.Read(tmp, 0, 2);
|
rsrcStream.Read(tmp, 0, 2);
|
||||||
map.fileRefNo = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
map.fileRefNo = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
||||||
rsrcStream.Read(tmp, 0, 2);
|
rsrcStream.Read(tmp, 0, 2);
|
||||||
@@ -132,14 +131,15 @@ namespace Claunia.RsrcFork
|
|||||||
map.numberOfTypes = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
map.numberOfTypes = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
resourceTypeList = new Dictionary<uint, ResourceTypeListItem>();
|
resourceTypeList = new Dictionary<uint, ResourceTypeListItem>();
|
||||||
osTypes = new List<uint>();
|
osTypes = new List<uint>();
|
||||||
|
|
||||||
for(int i = 0; i <= map.numberOfTypes; i++) {
|
for(int i = 0; i <= map.numberOfTypes; i++)
|
||||||
|
{
|
||||||
ResourceTypeListItem typeList = new ResourceTypeListItem();
|
ResourceTypeListItem typeList = new ResourceTypeListItem();
|
||||||
tmp = new byte[4];
|
tmp = new byte[4];
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
typeList.type = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
typeList.type = BitConverter.ToUInt32(tmp.Reverse().ToArray(), 0);
|
||||||
tmp = new byte[2];
|
tmp = new byte[2];
|
||||||
rsrcStream.Read(tmp, 0, 2);
|
rsrcStream.Read(tmp, 0, 2);
|
||||||
typeList.resources = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
typeList.resources = BitConverter.ToUInt16(tmp.Reverse().ToArray(), 0);
|
||||||
rsrcStream.Read(tmp, 0, 2);
|
rsrcStream.Read(tmp, 0, 2);
|
||||||
@@ -153,7 +153,7 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the resources with indicated type
|
/// Gets the resources with indicated type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The resource.</returns>
|
/// <returns>The resource.</returns>
|
||||||
/// <param name="OSType">OSType.</param>
|
/// <param name="OSType">OSType.</param>
|
||||||
@@ -161,14 +161,15 @@ namespace Claunia.RsrcFork
|
|||||||
{
|
{
|
||||||
Resource rsrc;
|
Resource rsrc;
|
||||||
|
|
||||||
if(resourceCache.TryGetValue(OSType, out rsrc))
|
if(resourceCache.TryGetValue(OSType, out rsrc)) return rsrc;
|
||||||
return rsrc;
|
|
||||||
|
|
||||||
ResourceTypeListItem typeList;
|
ResourceTypeListItem typeList;
|
||||||
if(!resourceTypeList.TryGetValue(OSType, out typeList))
|
if(!resourceTypeList.TryGetValue(OSType, out typeList)) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
rsrc = new Resource(rsrcStream, (ushort)(typeList.resources + 1), header.resourceMapOff + map.typeListOff + typeList.referenceOff - 2, header.resourceMapOff + map.nameListOff, header.resourceDataOff, OSType);
|
rsrc = new Resource(rsrcStream, (ushort)(typeList.resources + 1),
|
||||||
|
header.resourceMapOff + map.typeListOff + typeList.referenceOff - 2,
|
||||||
|
header.resourceMapOff + map.nameListOff,
|
||||||
|
header.resourceDataOff, OSType);
|
||||||
|
|
||||||
resourceCache.Add(OSType, rsrc);
|
resourceCache.Add(OSType, rsrc);
|
||||||
|
|
||||||
@@ -176,22 +177,15 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all OSTypes stored in this resource fork
|
/// Gets all OSTypes stored in this resource fork
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The types.</returns>
|
/// <returns>The types.</returns>
|
||||||
public uint[] GetTypes()
|
public uint[] GetTypes() => osTypes.ToArray();
|
||||||
{
|
|
||||||
return osTypes.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the specified OSType is present in this resource fork.
|
/// Returns true if the specified OSType is present in this resource fork.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="OSType">OSType.</param>
|
/// <param name="OSType">OSType.</param>
|
||||||
public bool ContainsKey(uint OSType)
|
public bool ContainsKey(uint OSType) => resourceTypeList.ContainsKey(OSType);
|
||||||
{
|
|
||||||
return resourceTypeList.ContainsKey(OSType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,68 +31,35 @@ using Claunia.RsrcFork;
|
|||||||
namespace Resources
|
namespace Resources
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class handles the "VERS" resource fork
|
/// This class handles the "VERS" resource fork
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Version
|
public class Version
|
||||||
{
|
{
|
||||||
static uint ostype = 0x76657273;
|
|
||||||
|
|
||||||
#region On-disk structure
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Major version.
|
/// Known development stages
|
||||||
/// </summary>
|
|
||||||
public byte MajorVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Minor version.
|
|
||||||
/// </summary>
|
|
||||||
public byte MinorVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Development stage.
|
|
||||||
/// </summary>
|
|
||||||
public DevelopmentStage DevStage;
|
|
||||||
/// <summary>
|
|
||||||
/// Pre-release version.
|
|
||||||
/// </summary>
|
|
||||||
public byte PreReleaseVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Region code.
|
|
||||||
/// </summary>
|
|
||||||
public ushort RegionCode;
|
|
||||||
/// <summary>
|
|
||||||
/// Version string.
|
|
||||||
/// </summary>
|
|
||||||
public string VersionString;
|
|
||||||
/// <summary>
|
|
||||||
/// Version message.
|
|
||||||
/// </summary>
|
|
||||||
public string VersionMessage;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Known development stages
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum DevelopmentStage : byte
|
public enum DevelopmentStage : byte
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pre-alpha.
|
/// Pre-alpha.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
PreAlpha = 0x20,
|
PreAlpha = 0x20,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Alpha.
|
/// Alpha.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Alpha = 0x40,
|
Alpha = 0x40,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Beta.
|
/// Beta.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Beta = 0x60,
|
Beta = 0x60,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Final release.
|
/// Final release.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Final = 0x80
|
Final = 0x80
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:Resources.Version"/> class.
|
/// Initializes a new instance of the <see cref="T:Resources.Version" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource">Byte array containing the "VERS" resource.</param>
|
/// <param name="resource">Byte array containing the "VERS" resource.</param>
|
||||||
public Version(byte[] resource)
|
public Version(byte[] resource)
|
||||||
@@ -101,30 +68,36 @@ namespace Resources
|
|||||||
|
|
||||||
tmpShort = new byte[2];
|
tmpShort = new byte[2];
|
||||||
|
|
||||||
MajorVersion = BCDToNumber(resource[0]);
|
MajorVersion = BCDToNumber(resource[0]);
|
||||||
MinorVersion = BCDToNumber(resource[1]);
|
MinorVersion = BCDToNumber(resource[1]);
|
||||||
DevStage = (DevelopmentStage)resource[2];
|
DevStage = (DevelopmentStage)resource[2];
|
||||||
PreReleaseVersion = BCDToNumber(resource[3]);
|
PreReleaseVersion = BCDToNumber(resource[3]);
|
||||||
Array.Copy(resource, 4, tmpShort, 0, 2);
|
Array.Copy(resource, 4, tmpShort, 0, 2);
|
||||||
RegionCode = BitConverter.ToUInt16(tmpShort.Reverse().ToArray(), 0);
|
RegionCode = BitConverter.ToUInt16(tmpShort.Reverse().ToArray(), 0);
|
||||||
tmpStr = new byte[resource[6] + 1];
|
tmpStr = new byte[resource[6] + 1];
|
||||||
Array.Copy(resource, 6, tmpStr, 0, tmpStr.Length);
|
Array.Copy(resource, 6, tmpStr, 0, tmpStr.Length);
|
||||||
VersionString = PascalString.GetString(tmpStr);
|
VersionString = PascalString.GetString(tmpStr);
|
||||||
tmpMsg = new byte[resource[6 + tmpStr.Length] + 1];
|
tmpMsg = new byte[resource[6 + tmpStr.Length] + 1];
|
||||||
Array.Copy(resource, 6 + tmpStr.Length, tmpMsg, 0, tmpMsg.Length);
|
Array.Copy(resource, 6 + tmpStr.Length, tmpMsg, 0, tmpMsg.Length);
|
||||||
VersionMessage = PascalString.GetString(tmpMsg);
|
VersionMessage = PascalString.GetString(tmpMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a byte array with the "VERS" resource contained by this instance.
|
/// Gets the OSTYPE of this resource.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The OSTYPE.</value>
|
||||||
|
public static uint OSType { get; } = 0x76657273;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a byte array with the "VERS" resource contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The "VERS" resource.</returns>
|
/// <returns>The "VERS" resource.</returns>
|
||||||
public byte[] GetBytes()
|
public byte[] GetBytes()
|
||||||
{
|
{
|
||||||
byte[] tmpShort, tmpStr, tmpMsg;
|
byte[] tmpShort, tmpStr, tmpMsg;
|
||||||
tmpShort = BitConverter.GetBytes(RegionCode).Reverse().ToArray();
|
tmpShort = BitConverter.GetBytes(RegionCode).Reverse().ToArray();
|
||||||
tmpStr = PascalString.GetBytes(VersionString);
|
tmpStr = PascalString.GetBytes(VersionString);
|
||||||
tmpMsg = PascalString.GetBytes(VersionMessage);
|
tmpMsg = PascalString.GetBytes(VersionMessage);
|
||||||
|
|
||||||
byte[] vers = new byte[6 + tmpStr.Length + tmpMsg.Length];
|
byte[] vers = new byte[6 + tmpStr.Length + tmpMsg.Length];
|
||||||
|
|
||||||
@@ -132,35 +105,51 @@ namespace Resources
|
|||||||
vers[1] = NumberToBCD(MinorVersion);
|
vers[1] = NumberToBCD(MinorVersion);
|
||||||
vers[2] = (byte)DevStage;
|
vers[2] = (byte)DevStage;
|
||||||
vers[3] = NumberToBCD(PreReleaseVersion);
|
vers[3] = NumberToBCD(PreReleaseVersion);
|
||||||
Array.Copy(tmpShort, 0, vers, 4, 2);
|
Array.Copy(tmpShort, 0, vers, 4, 2);
|
||||||
Array.Copy(tmpStr, 0, vers, 6, tmpStr.Length);
|
Array.Copy(tmpStr, 0, vers, 6, tmpStr.Length);
|
||||||
Array.Copy(tmpMsg, 0, vers, 6 + tmpStr.Length, tmpMsg.Length);
|
Array.Copy(tmpMsg, 0, vers, 6 + tmpStr.Length, tmpMsg.Length);
|
||||||
|
|
||||||
return vers;
|
return vers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
byte BCDToNumber(byte bcd) => Convert.ToByte(string.Format("{0:X2}", bcd), 10);
|
||||||
/// Gets the OSTYPE of this resource.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The OSTYPE.</value>
|
|
||||||
public static uint OSType {
|
|
||||||
get {
|
|
||||||
return ostype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte BCDToNumber(byte bcd)
|
|
||||||
{
|
|
||||||
return Convert.ToByte(string.Format("{0:X2}", bcd), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte NumberToBCD(byte number)
|
byte NumberToBCD(byte number)
|
||||||
{
|
{
|
||||||
if(number >= 100)
|
if(number >= 100) number = 99;
|
||||||
number = 99;
|
|
||||||
|
|
||||||
return Convert.ToByte(string.Format("{0:D2}", number), 16);
|
return Convert.ToByte(string.Format("{0:D2}", number), 16);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#region On-disk structure
|
||||||
|
/// <summary>
|
||||||
|
/// Major version.
|
||||||
|
/// </summary>
|
||||||
|
public byte MajorVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Minor version.
|
||||||
|
/// </summary>
|
||||||
|
public byte MinorVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Development stage.
|
||||||
|
/// </summary>
|
||||||
|
public DevelopmentStage DevStage;
|
||||||
|
/// <summary>
|
||||||
|
/// Pre-release version.
|
||||||
|
/// </summary>
|
||||||
|
public byte PreReleaseVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Region code.
|
||||||
|
/// </summary>
|
||||||
|
public ushort RegionCode;
|
||||||
|
/// <summary>
|
||||||
|
/// Version string.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionString;
|
||||||
|
/// <summary>
|
||||||
|
/// Version message.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionMessage;
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,19 +29,19 @@ namespace Claunia.RsrcFork
|
|||||||
struct ResourceHeader
|
struct ResourceHeader
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from start of resource fork to resource data
|
/// Offset from start of resource fork to resource data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int resourceDataOff;
|
public int resourceDataOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from start of resource fork to resource map
|
/// Offset from start of resource fork to resource map
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int resourceMapOff;
|
public int resourceMapOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Length of resource data
|
/// Length of resource data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int resourceDataLen;
|
public int resourceDataLen;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Length of resource map
|
/// Length of resource map
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int resourceMapLen;
|
public int resourceMapLen;
|
||||||
}
|
}
|
||||||
@@ -49,31 +49,31 @@ namespace Claunia.RsrcFork
|
|||||||
struct ResourceMap
|
struct ResourceMap
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy of the resource fork header
|
/// Copy of the resource fork header
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ResourceHeader header;
|
public ResourceHeader header;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reserved for handle to next resource map
|
/// Reserved for handle to next resource map
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint handleToNextMap;
|
public uint handleToNextMap;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reserved for file reference number
|
/// Reserved for file reference number
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort fileRefNo;
|
public ushort fileRefNo;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resource fork attributes
|
/// Resource fork attributes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort attributes;
|
public ushort attributes;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from start of resource map to resource type list
|
/// Offset from start of resource map to resource type list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short typeListOff;
|
public short typeListOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from start of resource map to resource name list
|
/// Offset from start of resource map to resource name list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short nameListOff;
|
public short nameListOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of types in the map minus 1
|
/// Number of types in the map minus 1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort numberOfTypes;
|
public ushort numberOfTypes;
|
||||||
}
|
}
|
||||||
@@ -81,15 +81,15 @@ namespace Claunia.RsrcFork
|
|||||||
struct ResourceTypeListItem
|
struct ResourceTypeListItem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resource type
|
/// Resource type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint type;
|
public uint type;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of resources of this type minus 1
|
/// Number of resources of this type minus 1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort resources;
|
public ushort resources;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from beginning of resource type list to reference list
|
/// Offset from beginning of resource type list to reference list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short referenceOff;
|
public short referenceOff;
|
||||||
}
|
}
|
||||||
@@ -97,25 +97,24 @@ namespace Claunia.RsrcFork
|
|||||||
struct ResourceTypeReferenceListItem
|
struct ResourceTypeReferenceListItem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resource ID
|
/// Resource ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short id;
|
public short id;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from beginning of resource name list to resource name. -1 if it does not have a name
|
/// Offset from beginning of resource name list to resource name. -1 if it does not have a name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short nameOff;
|
public short nameOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resource attributes
|
/// Resource attributes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte attributes;
|
public byte attributes;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset from beginning of resource data to resource. First byte is <see cref="attributes"/>.
|
/// Offset from beginning of resource data to resource. First byte is <see cref="attributes" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int dataOff;
|
public int dataOff;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reserved for handle to resource
|
/// Reserved for handle to resource
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint handle;
|
public uint handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,24 +25,25 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class contains static methods for OSTYPE handling.
|
/// This class contains static methods for OSTYPE handling.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Types
|
public static class Types
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a descriptive name of a resource from its OSTYPE.
|
/// Gets a descriptive name of a resource from its OSTYPE.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The name corresponding to the specified OSTYPE.</returns>
|
/// <returns>The name corresponding to the specified OSTYPE.</returns>
|
||||||
/// <param name="OSType">The OSTYPE.</param>
|
/// <param name="OSType">The OSTYPE.</param>
|
||||||
public static string GetName(uint OSType)
|
public static string GetName(uint OSType)
|
||||||
{
|
{
|
||||||
switch(OSType) {
|
switch(OSType)
|
||||||
|
{
|
||||||
case 0x2E58534C: // ".XSL"
|
case 0x2E58534C: // ".XSL"
|
||||||
return "XML style sheet";
|
return "XML style sheet";
|
||||||
case 0x33444D46: // "3DMF"
|
case 0x33444D46: // "3DMF"
|
||||||
@@ -683,26 +684,23 @@ namespace Claunia.RsrcFork
|
|||||||
return "MC680x0 Code";
|
return "MC680x0 Code";
|
||||||
case 0x5F505043: // "_PPC"
|
case 0x5F505043: // "_PPC"
|
||||||
return "PowerPC Code";
|
return "PowerPC Code";
|
||||||
default:
|
default: return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a descriptive name of a resource from its OSTYPE.
|
/// Gets a descriptive name of a resource from its OSTYPE.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The name corresponding to the specified OSTYPE.</returns>
|
/// <returns>The name corresponding to the specified OSTYPE.</returns>
|
||||||
/// <param name="OSType">The OSTYPE.</param>
|
/// <param name="OSType">The OSTYPE.</param>
|
||||||
public static string GetName(string OSType)
|
public static string GetName(string OSType)
|
||||||
{
|
{
|
||||||
if(OSType.Length != 4)
|
if(OSType.Length != 4) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] typB = Encoding.ASCII.GetBytes(OSType);
|
byte[] typB = Encoding.ASCII.GetBytes(OSType);
|
||||||
uint type = BitConverter.ToUInt32(typB.Reverse().ToArray(), 0);
|
uint type = BitConverter.ToUInt32(typB.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
return GetName(type);
|
return GetName(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user