mirror of
https://github.com/blueskythlikesclouds/SonicAudioTools.git
synced 2024-11-24 15:10:11 +01:00
55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
namespace SonicAudioLib.IO
|
|
{
|
|
public class Helpers
|
|
{
|
|
public static long Align(long value, long alignment)
|
|
{
|
|
while ((value % alignment) != 0)
|
|
{
|
|
value++;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
// This one masks the source to destination
|
|
public static void MaskCriTable(Stream source, Stream destination, long length)
|
|
{
|
|
uint currentXor = 25951;
|
|
long currentPosition = source.Position;
|
|
|
|
while (source.Position < currentPosition + length)
|
|
{
|
|
byte maskedByte = (byte)(EndianStream.ReadByte(source) ^ currentXor);
|
|
currentXor *= 16661;
|
|
|
|
EndianStream.WriteByte(destination, maskedByte);
|
|
}
|
|
}
|
|
|
|
// This one masks the source to itself
|
|
public static void MaskCriTable(Stream source, long length)
|
|
{
|
|
if (source.CanRead && source.CanWrite)
|
|
{
|
|
uint currentXor = 25951;
|
|
long currentPosition = source.Position;
|
|
|
|
while (source.Position < currentPosition + length)
|
|
{
|
|
byte maskedByte = (byte)(EndianStream.ReadByte(source) ^ currentXor);
|
|
currentXor *= 16661;
|
|
|
|
EndianStream.WriteByteAt(source, maskedByte, source.Position - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|