diff --git a/Extensions.CFB.cs b/Extensions.CFB.cs new file mode 100644 index 00000000..316bd5bd --- /dev/null +++ b/Extensions.CFB.cs @@ -0,0 +1,36 @@ +using System; +using SabreTools.Models.CFB; + +namespace SabreTools.Serialization +{ + public static partial class Extensions + { + /// + /// Sector size in bytes + /// + /// Binary model to derive from + /// Sector size on success, -1 on error + public static long SectorSize(this Binary binary) + { + // If we have an invalid header + if (binary.Header?.SectorShift == null) + return -1; + + return (long)Math.Pow(2, binary.Header.SectorShift); + } + + /// + /// Mini sector size in bytes + /// + /// Binary model to derive from + /// Sector size on success, -1 on error + public static long MiniSectorSize(this Binary binary) + { + // If we have an invalid header + if (binary.Header?.SectorShift == null) + return -1; + + return (long)Math.Pow(2, binary.Header.MiniSectorShift); + } + } +} \ No newline at end of file diff --git a/Extensions.InstallShieldCabinet.cs b/Extensions.InstallShieldCabinet.cs new file mode 100644 index 00000000..587ac30d --- /dev/null +++ b/Extensions.InstallShieldCabinet.cs @@ -0,0 +1,33 @@ +using SabreTools.Models.InstallShieldCabinet; + +namespace SabreTools.Serialization +{ + public static partial class Extensions + { + /// + /// The major version of the cabinet + /// + /// Cabinet model to derive from + /// Major version on success, -1 on error + public static int MajorVersion(this Cabinet cabinet) + { + // If we have an invalid header + if (cabinet.CommonHeader?.Version == null) + return -1; + + uint majorVersion = cabinet.CommonHeader.Version; + if (majorVersion >> 24 == 1) + { + majorVersion = (majorVersion >> 12) & 0x0F; + } + else if (majorVersion >> 24 == 2 || majorVersion >> 24 == 4) + { + majorVersion = majorVersion & 0xFFFF; + if (majorVersion != 0) + majorVersion /= 100; + } + + return (int)majorVersion; + } + } +} \ No newline at end of file