mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Added support for different character encodings.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.ImagePlugins;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
@@ -64,14 +65,17 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
Name = "Apple Macintosh File System";
|
||||
PluginUUID = new Guid("36405F8D-0D26-4066-6538-5DBF5D065C3A");
|
||||
CurrentEncoding = Encoding.GetEncoding("macintosh");
|
||||
}
|
||||
|
||||
public AppleMFS(ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
||||
public AppleMFS(ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, Encoding encoding)
|
||||
{
|
||||
Name = "Apple Macintosh File System";
|
||||
PluginUUID = new Guid("36405F8D-0D26-4066-6538-5DBF5D065C3A");
|
||||
device = imagePlugin;
|
||||
this.partitionStart = partitionStart;
|
||||
if(encoding == null)
|
||||
CurrentEncoding = Encoding.GetEncoding("macintosh");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,14 +93,14 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
entry.flMdDat = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 46);
|
||||
entry.flNam = new byte[directoryBlocks[offset + 50] + 1];
|
||||
Array.Copy(directoryBlocks, offset + 50, entry.flNam, 0, entry.flNam.Length);
|
||||
lowerFilename = GetStringFromPascal(entry.flNam).ToLowerInvariant().Replace('/', ':');
|
||||
lowerFilename = StringHandlers.PascalToString(entry.flNam, CurrentEncoding).ToLowerInvariant().Replace('/', ':');
|
||||
|
||||
if(entry.flFlags.HasFlag(MFS_FileFlags.Used) && !idToFilename.ContainsKey(entry.flFlNum) &&
|
||||
!idToEntry.ContainsKey(entry.flFlNum) && !filenameToId.ContainsKey(lowerFilename) &&
|
||||
entry.flFlNum > 0)
|
||||
{
|
||||
idToEntry.Add(entry.flFlNum, entry);
|
||||
idToFilename.Add(entry.flFlNum, GetStringFromPascal(entry.flNam).Replace('/', ':'));
|
||||
idToFilename.Add(entry.flFlNum, StringHandlers.PascalToString(entry.flNam, CurrentEncoding).Replace('/', ':'));
|
||||
filenameToId.Add(lowerFilename, entry.flFlNum);
|
||||
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlags = {0}", entry.flFlags);
|
||||
@@ -114,7 +114,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRPyLen = {0}", entry.flRPyLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flCrDat = {0}", DateHandlers.MacToDateTime(entry.flCrDat));
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flMdDat = {0}", DateHandlers.MacToDateTime(entry.flMdDat));
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}", GetStringFromPascal(entry.flNam));
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}", StringHandlers.PascalToString(entry.flNam, CurrentEncoding));
|
||||
}
|
||||
|
||||
offset += (50 + entry.flNam.Length);
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Encoding.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : Apple Macintosh File System plugin.
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Apple MacRoman to Unicode converters.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2017 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
// Information from Inside Macintosh Volume II
|
||||
partial class AppleMFS : Filesystem
|
||||
{
|
||||
/// <summary>
|
||||
/// The MacRoman to Unicode character map.
|
||||
/// </summary>
|
||||
static readonly char[] MacRomanTable = {
|
||||
// 0x00
|
||||
'\u0000','\u0001','\u0002','\u0003','\u0004','\u0005','\u0006','\u0007',
|
||||
// 0x08
|
||||
'\u0008','\u0009','\u000A','\u000B','\u000C','\u000D','\u000E','\u000F',
|
||||
// 0x10
|
||||
'\u0010','\u0011','\u0012','\u0013','\u0014','\u0015','\u0016','\u0017',
|
||||
// 0x18
|
||||
'\u0018','\u0019','\u001A','\u001B','\u001C','\u001D','\u001E','\u001F',
|
||||
// 0x20
|
||||
'\u0020','\u0021','\u0022','\u0023','\u0024','\u0025','\u0026','\u0027',
|
||||
// 0x28
|
||||
'\u0028','\u0029','\u002A','\u002B','\u002C','\u002D','\u002E','\u002F',
|
||||
// 0x30
|
||||
'\u0030','\u0031','\u0032','\u0033','\u0034','\u0035','\u0036','\u0037',
|
||||
// 0x38
|
||||
'\u0038','\u0039','\u003A','\u003B','\u003C','\u003D','\u003E','\u003F',
|
||||
// 0x40
|
||||
'\u0040','\u0041','\u0042','\u0043','\u0044','\u0045','\u0046','\u0047',
|
||||
// 0x48
|
||||
'\u0048','\u0049','\u004A','\u004B','\u004C','\u004D','\u004E','\u004F',
|
||||
// 0x50
|
||||
'\u0050','\u0051','\u0052','\u0053','\u0054','\u0055','\u0056','\u0057',
|
||||
// 0x58
|
||||
'\u0058','\u0059','\u005A','\u005B','\u005C','\u005D','\u005E','\u005F',
|
||||
// 0x60
|
||||
'\u0060','\u0061','\u0062','\u0063','\u0064','\u0065','\u0066','\u0067',
|
||||
// 0x68
|
||||
'\u0068','\u0069','\u006A','\u006B','\u006C','\u006D','\u006E','\u006F',
|
||||
// 0x70
|
||||
'\u0070','\u0071','\u0072','\u0073','\u0074','\u0075','\u0076','\u0077',
|
||||
// 0x78
|
||||
'\u0078','\u0079','\u007A','\u007B','\u007C','\u007D','\u007E','\u007F',
|
||||
// 0x80
|
||||
'\u00C4','\u00C5','\u00C7','\u00C9','\u00D1','\u00D6','\u00DC','\u00E1',
|
||||
// 0x88
|
||||
'\u00E0','\u00E2','\u00E4','\u00E3','\u00E5','\u00E7','\u00E9','\u00E8',
|
||||
// 0x90
|
||||
'\u00EA','\u00EB','\u00ED','\u00EC','\u00EE','\u00EF','\u00F1','\u00F3',
|
||||
// 0x98
|
||||
'\u00F2','\u00F4','\u00F6','\u00F5','\u00FA','\u00F9','\u00FB','\u00FC',
|
||||
// 0xA0
|
||||
'\u2020','\u00B0','\u00A2','\u00A3','\u00A7','\u2022','\u00B6','\u00DF',
|
||||
// 0xA8
|
||||
'\u00AE','\u00A9','\u2122','\u00B4','\u00A8','\u2260','\u00C6','\u00D8',
|
||||
// 0xB0
|
||||
'\u221E','\u00B1','\u2264','\u2265','\u00A5','\u00B5','\u2202','\u2211',
|
||||
// 0xB8
|
||||
'\u220F','\u03C0','\u222B','\u00AA','\u00BA','\u03A9','\u00E6','\u00F8',
|
||||
// 0xC0
|
||||
'\u00BF','\u00A1','\u00AC','\u221A','\u0192','\u2248','\u2206','\u00AB',
|
||||
// 0xC8
|
||||
'\u00BB','\u2026','\u00A0','\u00C0','\u00C3','\u00D5','\u0152','\u0153',
|
||||
// 0xD0
|
||||
'\u2013','\u2014','\u201C','\u201D','\u2018','\u2019','\u00F7','\u25CA',
|
||||
// 0xD8
|
||||
'\u00FF','\u0178','\u2044','\u00A4','\u2039','\u203A','\uFB01','\uFB02',
|
||||
// 0xE0
|
||||
'\u2021','\u00B7','\u201A','\u201E','\u2030','\u00C2','\u00CA','\u00C1',
|
||||
// 0xE8
|
||||
'\u00CB','\u00C8','\u00CD','\u00CE','\u00CF','\u00CC','\u00D3','\u00D4',
|
||||
// 0xF0
|
||||
'\uF8FF','\u00D2','\u00DA','\u00DB','\u00D9','\u0131','\u02C6','\u02DC',
|
||||
// 0xF8
|
||||
'\u00AF','\u02D8','\u02D9','\u02DA','\u00B8','\u02DD','\u02DB','\u02C7'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Converts a MacRoman character to an Unicode character
|
||||
/// </summary>
|
||||
/// <returns>Unicode character.</returns>
|
||||
/// <param name="character">MacRoman character.</param>
|
||||
static char GetChar(byte character)
|
||||
{
|
||||
return MacRomanTable[character];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a MacRoman string, null-terminated or null-paded, to a C# string
|
||||
/// </summary>
|
||||
/// <returns>The C# string.</returns>
|
||||
/// <param name="str">MacRoman string.</param>
|
||||
static string GetString(byte[] str)
|
||||
{
|
||||
string uni = "";
|
||||
|
||||
foreach(byte b in str)
|
||||
{
|
||||
if(b == 0x00)
|
||||
break;
|
||||
|
||||
uni += MacRomanTable[b];
|
||||
}
|
||||
|
||||
return uni;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a MacRoman string, in Pascal length-prefixed format, to a C# string
|
||||
/// </summary>
|
||||
/// <returns>The C# string.</returns>
|
||||
/// <param name="PascalString">The MacRoman string in Pascal format.</param>
|
||||
static string GetStringFromPascal(byte[] PascalString)
|
||||
{
|
||||
if(PascalString == null)
|
||||
return null;
|
||||
|
||||
string uni = "";
|
||||
|
||||
byte length = PascalString[0];
|
||||
|
||||
if(length > PascalString.Length - 1)
|
||||
length = (byte)(PascalString.Length - 1);
|
||||
|
||||
for(int i = 1; i < length + 1; i++)
|
||||
{
|
||||
uni += MacRomanTable[PascalString[i]];
|
||||
}
|
||||
|
||||
return uni;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
MDB.drVNSiz = mdb_sector[0x024];
|
||||
variable_size = new byte[MDB.drVNSiz+1];
|
||||
Array.Copy(mdb_sector, 0x024, variable_size, 0, MDB.drVNSiz+1);
|
||||
MDB.drVN = GetStringFromPascal(variable_size);
|
||||
MDB.drVN = StringHandlers.PascalToString(variable_size, CurrentEncoding);
|
||||
|
||||
BB.signature = BigEndianBitConverter.ToUInt16(bb_sector, 0x000);
|
||||
|
||||
@@ -103,19 +103,19 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
BB.sec_sv_pages = BigEndianBitConverter.ToInt16(bb_sector, 0x008);
|
||||
|
||||
Array.Copy(mdb_sector, 0x00A, pString, 0, 16);
|
||||
BB.system_name = GetStringFromPascal(pString);
|
||||
BB.system_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x01A, pString, 0, 16);
|
||||
BB.finder_name = GetStringFromPascal(pString);
|
||||
BB.finder_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x02A, pString, 0, 16);
|
||||
BB.debug_name = GetStringFromPascal(pString);
|
||||
BB.debug_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x03A, pString, 0, 16);
|
||||
BB.disasm_name = GetStringFromPascal(pString);
|
||||
BB.disasm_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x04A, pString, 0, 16);
|
||||
BB.stupscr_name = GetStringFromPascal(pString);
|
||||
BB.stupscr_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x05A, pString, 0, 16);
|
||||
BB.bootup_name = GetStringFromPascal(pString);
|
||||
BB.bootup_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
Array.Copy(mdb_sector, 0x06A, pString, 0, 16);
|
||||
BB.clipbrd_name = GetStringFromPascal(pString);
|
||||
BB.clipbrd_name = StringHandlers.PascalToString(pString, CurrentEncoding);
|
||||
|
||||
BB.max_files = BigEndianBitConverter.ToUInt16(bb_sector, 0x07A);
|
||||
BB.queue_size = BigEndianBitConverter.ToUInt16(bb_sector, 0x07C);
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
volMDB.drVNSiz = mdbBlocks[0x024];
|
||||
variable_size = new byte[volMDB.drVNSiz + 1];
|
||||
Array.Copy(mdbBlocks, 0x024, variable_size, 0, volMDB.drVNSiz + 1);
|
||||
volMDB.drVN = GetStringFromPascal(variable_size);
|
||||
volMDB.drVN = StringHandlers.PascalToString(variable_size, CurrentEncoding);
|
||||
|
||||
directoryBlocks = device.ReadSectors(volMDB.drDirSt + partitionStart, volMDB.drBlLen);
|
||||
int bytesInBlockMap = ((volMDB.drNmAlBlks * 12) / 8) + ((volMDB.drNmAlBlks * 12) % 8);
|
||||
|
||||
Reference in New Issue
Block a user