Use new little endian marshaller on decoders.

This commit is contained in:
2019-02-28 00:04:13 +00:00
parent 0fe8e3c11f
commit 691b51aa1b
5 changed files with 13 additions and 20 deletions

View File

@@ -2133,6 +2133,7 @@
<e p="VTOC.cs" t="Include" /> <e p="VTOC.cs" t="Include" />
</e> </e>
<e p="Program.cs" t="Include" /> <e p="Program.cs" t="Include" />
<e p="TestResult.xml" t="Include" />
<e p="bin" t="ExcludeRecursive" /> <e p="bin" t="ExcludeRecursive" />
<e p="obj" t="ExcludeRecursive"> <e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include"> <e p="Debug" t="Include">

View File

@@ -37,6 +37,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Decoders.SCSI; using DiscImageChef.Decoders.SCSI;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Decoders.ATA namespace DiscImageChef.Decoders.ATA
{ {
@@ -1863,10 +1864,7 @@ namespace DiscImageChef.Decoders.ATA
return null; return null;
} }
IntPtr ptr = Marshal.AllocHGlobal(512); IdentifyDevice ATAID = Marshal.ByteArrayToStructureLittleEndian<IdentifyDevice>(IdentifyDeviceResponse);
Marshal.Copy(IdentifyDeviceResponse, 0, ptr, 512);
IdentifyDevice ATAID = (IdentifyDevice)Marshal.PtrToStructure(ptr, typeof(IdentifyDevice));
Marshal.FreeHGlobal(ptr);
ATAID.WWN = DescrambleWWN(ATAID.WWN); ATAID.WWN = DescrambleWWN(ATAID.WWN);
ATAID.WWNExtension = DescrambleWWN(ATAID.WWNExtension); ATAID.WWNExtension = DescrambleWWN(ATAID.WWNExtension);
@@ -1891,10 +1889,10 @@ namespace DiscImageChef.Decoders.ATA
ataId.WWNExtension = DescrambleWWN(ataId.WWNExtension); ataId.WWNExtension = DescrambleWWN(ataId.WWNExtension);
byte[] buf = new byte[512]; byte[] buf = new byte[512];
IntPtr ptr = Marshal.AllocHGlobal(512); IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
Marshal.StructureToPtr(ataId, ptr, false); System.Runtime.InteropServices.Marshal.StructureToPtr(ataId, ptr, false);
Marshal.Copy(ptr, buf, 0, 512); System.Runtime.InteropServices.Marshal.Copy(ptr, buf, 0, 512);
Marshal.FreeHGlobal(ptr); System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr);
byte[] str = ScrambleATAString(ataId.SerialNumber, 20); byte[] str = ScrambleATAString(ataId.SerialNumber, 20);
Array.Copy(str, 0, buf, 10 * 2, 20); Array.Copy(str, 0, buf, 10 * 2, 20);

View File

@@ -36,6 +36,7 @@ using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using DiscImageChef.Console; using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Decoders.Sega namespace DiscImageChef.Decoders.Sega
{ {
@@ -134,10 +135,7 @@ namespace DiscImageChef.Decoders.Sega
if(ipbin_sector.Length < 512) return null; if(ipbin_sector.Length < 512) return null;
IntPtr ptr = Marshal.AllocHGlobal(512); IPBin ipbin = Marshal.ByteArrayToStructureLittleEndian<IPBin>(ipbin_sector);
Marshal.Copy(ipbin_sector, 0, ptr, 512);
IPBin ipbin = (IPBin)Marshal.PtrToStructure(ptr, typeof(IPBin));
Marshal.FreeHGlobal(ptr);
DicConsole.DebugWriteLine("SegaCD IP.BIN Decoder", "segacd_ipbin.volume_name = \"{0}\"", DicConsole.DebugWriteLine("SegaCD IP.BIN Decoder", "segacd_ipbin.volume_name = \"{0}\"",
Encoding.ASCII.GetString(ipbin.volume_name)); Encoding.ASCII.GetString(ipbin.volume_name));

View File

@@ -36,6 +36,7 @@ using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using DiscImageChef.Console; using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Decoders.Sega namespace DiscImageChef.Decoders.Sega
{ {
@@ -109,10 +110,7 @@ namespace DiscImageChef.Decoders.Sega
if(ipbin_sector.Length < 512) return null; if(ipbin_sector.Length < 512) return null;
IntPtr ptr = Marshal.AllocHGlobal(512); IPBin ipbin = Marshal.ByteArrayToStructureLittleEndian<IPBin>(ipbin_sector);
Marshal.Copy(ipbin_sector, 0, ptr, 512);
IPBin ipbin = (IPBin)Marshal.PtrToStructure(ptr, typeof(IPBin));
Marshal.FreeHGlobal(ptr);
DicConsole.DebugWriteLine("Dreamcast IP.BIN Decoder", "dreamcast_ipbin.maker_id = \"{0}\"", DicConsole.DebugWriteLine("Dreamcast IP.BIN Decoder", "dreamcast_ipbin.maker_id = \"{0}\"",
Encoding.ASCII.GetString(ipbin.maker_id)); Encoding.ASCII.GetString(ipbin.maker_id));

View File

@@ -36,6 +36,7 @@ using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using DiscImageChef.Console; using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Decoders.Sega namespace DiscImageChef.Decoders.Sega
{ {
@@ -91,10 +92,7 @@ namespace DiscImageChef.Decoders.Sega
if(ipbin_sector.Length < 512) return null; if(ipbin_sector.Length < 512) return null;
IntPtr ptr = Marshal.AllocHGlobal(512); IPBin ipbin = Marshal.ByteArrayToStructureLittleEndian<IPBin>(ipbin_sector);
Marshal.Copy(ipbin_sector, 0, ptr, 512);
IPBin ipbin = (IPBin)Marshal.PtrToStructure(ptr, typeof(IPBin));
Marshal.FreeHGlobal(ptr);
DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.maker_id = \"{0}\"", DicConsole.DebugWriteLine("Saturn IP.BIN Decoder", "saturn_ipbin.maker_id = \"{0}\"",
Encoding.ASCII.GetString(ipbin.maker_id)); Encoding.ASCII.GetString(ipbin.maker_id));