Example #1
0
    private static void ExportBlock(SCBlock block, BinaryWriter bw, int blockIndex, SCBlockExportOption option)
    {
        if (option.HasFlagFast(SCBlockExportOption.DataOnly) && block.Data.Length == 0)
        {
            return;
        }

        if (option.HasFlagFast(SCBlockExportOption.FakeHeader))
        {
            bw.Write($"BLOCK{blockIndex:0000} {block.Key:X8}");
        }

        if (option.HasFlagFast(SCBlockExportOption.Key))
        {
            bw.Write(block.Key);
        }

        if (option.HasFlagFast(SCBlockExportOption.TypeInfo))
        {
            bw.Write((byte)block.Type);
            bw.Write((byte)block.SubType);
        }

        bw.Write(block.Data);
    }
Example #2
0
    public static byte[] ExportAllBlocks(IReadOnlyList <SCBlock> blocks, SCBlockExportOption option = SCBlockExportOption.None)
    {
        if (option == SCBlockExportOption.None)
        {
            return(SwishCrypto.GetDecryptedRawData(blocks));
        }

        using var stream = new MemoryStream();
        using var bw     = new BinaryWriter(stream);
        for (var i = 0; i < blocks.Count; i++)
        {
            ExportBlock(blocks[i], bw, i, option);
        }
        return(stream.ToArray());
    }
Example #3
0
    public static void ExportAllBlocksAsSingleFile(IReadOnlyList <SCBlock> blocks, string path, SCBlockExportOption option = SCBlockExportOption.All)
    {
        var data = ExportAllBlocks(blocks, option);

        File.WriteAllBytes(path, data);
    }
Example #4
0
 public static bool HasFlagFast(this SCBlockExportOption value, SCBlockExportOption flag)
 {
     return((value & flag) != 0);
 }