mirror of
https://github.com/StudentBlake/XCI-Explorer
synced 2024-11-10 06:34:15 +00:00
Minor cleanup, update keys, add portable publish profile
This commit is contained in:
parent
a328030ff6
commit
2370bc6cf4
23 changed files with 2721 additions and 2901 deletions
|
@ -15,4 +15,10 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Be.Windows.Forms.HexBox.Net5" Version="1.8.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="tools\hactool.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,154 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace XCI_Explorer.Helpers
|
||||
{
|
||||
public class BetterBinaryReader : IDisposable
|
||||
{
|
||||
public string FileName;
|
||||
public bool Initiated;
|
||||
public Stream Stream;
|
||||
private BinaryReader br;
|
||||
|
||||
public BetterBinaryReader()
|
||||
{
|
||||
Initiated = false;
|
||||
}
|
||||
|
||||
public BetterBinaryReader(string file)
|
||||
{
|
||||
Initiated = false;
|
||||
Load(file);
|
||||
}
|
||||
|
||||
public BetterBinaryReader(Stream s)
|
||||
{
|
||||
Initiated = false;
|
||||
FileName = "";
|
||||
Stream = s;
|
||||
br = new BinaryReader(Stream);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Initiated = false;
|
||||
br.Close();
|
||||
br = null;
|
||||
Stream.Close();
|
||||
Stream = null;
|
||||
}
|
||||
|
||||
public void Load(string file)
|
||||
{
|
||||
FileName = file;
|
||||
Stream = new FileStream(file, FileMode.Open);
|
||||
br = new BinaryReader(Stream);
|
||||
Initiated = true;
|
||||
}
|
||||
|
||||
public void Seek(long o)
|
||||
{
|
||||
if (o > -1)
|
||||
{
|
||||
Stream.Seek(o, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
public void Skip(long o)
|
||||
{
|
||||
Stream.Seek(o, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
public long Position()
|
||||
{
|
||||
return Stream.Position;
|
||||
}
|
||||
|
||||
public int Read()
|
||||
{
|
||||
return br.ReadBytes(1)[0];
|
||||
}
|
||||
|
||||
public int Read(byte[] buffer, int index, int count)
|
||||
{
|
||||
return br.Read(buffer, index, count);
|
||||
}
|
||||
|
||||
public int Read(char[] buffer, int index, int count)
|
||||
{
|
||||
return br.Read(buffer, index, count);
|
||||
}
|
||||
|
||||
public byte[] ReadBytes(int l)
|
||||
{
|
||||
if (l >= 0 && l <= 2147483647)
|
||||
{
|
||||
return br.ReadBytes(l);
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public Stream ReadBytesButLonger(long l)
|
||||
{
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
for (long num = 0L; num < l; num++)
|
||||
{
|
||||
}
|
||||
Console.WriteLine(memoryStream.Length);
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
public string ReadCharsAsString(int l)
|
||||
{
|
||||
return new string(br.ReadChars(l));
|
||||
}
|
||||
|
||||
public short ReadShort()
|
||||
{
|
||||
return br.ReadInt16();
|
||||
}
|
||||
|
||||
public short ReadInt16()
|
||||
{
|
||||
return br.ReadInt16();
|
||||
}
|
||||
|
||||
public int ReadInt()
|
||||
{
|
||||
return br.ReadInt32();
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
return br.ReadInt32();
|
||||
}
|
||||
|
||||
public long ReadLong()
|
||||
{
|
||||
return br.ReadInt64();
|
||||
}
|
||||
|
||||
public long ReadInt64()
|
||||
{
|
||||
return br.ReadInt64();
|
||||
}
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
return br.ReadString();
|
||||
}
|
||||
|
||||
private long GreatestDivisor(long n)
|
||||
{
|
||||
long result = 0L;
|
||||
for (long num = 1L; num < n / 64; num++)
|
||||
{
|
||||
if (n % num == 0L && num != n)
|
||||
{
|
||||
result = num;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using System.Windows.Forms;
|
||||
|
||||
namespace XCI_Explorer.Helpers
|
||||
{
|
||||
namespace XCI_Explorer.Helpers;
|
||||
|
||||
public class BetterTreeNode : TreeNode
|
||||
{
|
||||
public long Offset;
|
||||
|
@ -12,7 +12,6 @@ namespace XCI_Explorer.Helpers
|
|||
|
||||
public BetterTreeNode(string t)
|
||||
{
|
||||
base.Text = t;
|
||||
}
|
||||
Text = t;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
internal static class CNMT
|
||||
{
|
||||
public class CNMT_Header
|
||||
|
@ -77,4 +77,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static CNMT_Header[] CNMT_Headers = new CNMT_Header[1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace XCI_Explorer;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
public class CenterWinDialog : IDisposable
|
||||
{
|
||||
private int mTries = 0;
|
||||
|
@ -23,19 +23,28 @@ namespace XCI_Explorer
|
|||
private void findDialog()
|
||||
{
|
||||
// Enumerate windows to find the message box
|
||||
if (mTries < 0) return;
|
||||
EnumThreadWndProc callback = new EnumThreadWndProc(checkWindow);
|
||||
if (mTries < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EnumThreadWndProc callback = new(checkWindow);
|
||||
if (EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero))
|
||||
{
|
||||
if (++mTries < 10) mOwner.BeginInvoke(new MethodInvoker(findDialog));
|
||||
if (++mTries < 10)
|
||||
{
|
||||
mOwner.BeginInvoke(new MethodInvoker(findDialog));
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool checkWindow(IntPtr hWnd, IntPtr lp)
|
||||
{
|
||||
// Checks if <hWnd> is a dialog
|
||||
StringBuilder sb = new StringBuilder(260);
|
||||
StringBuilder sb = new(260);
|
||||
GetClassName(hWnd, sb, sb.Capacity);
|
||||
if (sb.ToString() != "#32770") return true;
|
||||
if (sb.ToString() != "#32770")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// Got it
|
||||
Rectangle frmRect = new Rectangle(mOwner.Location, mOwner.Size);
|
||||
RECT dlgRect;
|
||||
|
@ -66,4 +75,3 @@ namespace XCI_Explorer
|
|||
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int w, int h, bool repaint);
|
||||
private struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
|
||||
}
|
||||
}
|
|
@ -2,14 +2,14 @@
|
|||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
public partial class CertForm : Form
|
||||
{
|
||||
public CertForm(MainForm mainForm)
|
||||
{
|
||||
InitializeComponent();
|
||||
FileStream fileStream = new FileStream(mainForm.TB_File.Text, FileMode.Open, FileAccess.Read);
|
||||
FileStream fileStream = new(mainForm.TB_File.Text, FileMode.Open, FileAccess.Read);
|
||||
byte[] array = new byte[512];
|
||||
fileStream.Position = 28672L;
|
||||
fileStream.Read(array, 0, 512);
|
||||
|
@ -17,4 +17,3 @@ namespace XCI_Explorer
|
|||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
internal static class HFS0
|
||||
{
|
||||
public class HFS0_Header
|
||||
|
@ -49,4 +49,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static HFS0_Header[] HFS0_Headers = new HFS0_Header[1];
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
public static class NACP
|
||||
{
|
||||
public class NACP_String
|
||||
|
@ -39,4 +39,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static NACP_Data[] NACP_Datas = new NACP_Data[1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
internal static class NCA
|
||||
{
|
||||
public class NCA_Header
|
||||
|
@ -32,4 +32,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static NCA_Header[] NCA_Headers = new NCA_Header[1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
internal static class PFS0
|
||||
{
|
||||
public class PFS0_Header
|
||||
|
@ -45,4 +45,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static PFS0_Header[] PFS0_Headers = new PFS0_Header[1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (Object sender, ResolveEventArgs args) =>
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) =>
|
||||
{
|
||||
System.Reflection.AssemblyName embeddedAssembly = new System.Reflection.AssemblyName(args.Name);
|
||||
String resourceName = "XCI_Explorer" + "." + embeddedAssembly.Name + ".dll";
|
||||
string resourceName = "XCI_Explorer" + "." + embeddedAssembly.Name + ".dll";
|
||||
|
||||
using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
|
||||
{
|
||||
Byte[] assemblyData = new Byte[stream.Length];
|
||||
using Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
|
||||
byte[] assemblyData = new byte[stream.Length];
|
||||
stream.Read(assemblyData, 0, assemblyData.Length);
|
||||
return System.Reflection.Assembly.Load(assemblyData);
|
||||
}
|
||||
};
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System.Windows.Forms;
|
||||
using XCI_Explorer.Helpers;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
public class TreeViewFileSystem
|
||||
{
|
||||
public TreeView treeView;
|
||||
|
@ -13,28 +13,28 @@ namespace XCI_Explorer
|
|||
|
||||
public BetterTreeNode AddDir(string name, BetterTreeNode parent = null)
|
||||
{
|
||||
BetterTreeNode betterTreeNode = new BetterTreeNode(name);
|
||||
betterTreeNode.Offset = -1L;
|
||||
betterTreeNode.Size = -1L;
|
||||
BetterTreeNode betterTreeNode = new(name)
|
||||
{
|
||||
Offset = -1L,
|
||||
Size = -1L
|
||||
};
|
||||
parent.Nodes.Add(betterTreeNode);
|
||||
return betterTreeNode;
|
||||
}
|
||||
|
||||
public BetterTreeNode AddFile(string name, BetterTreeNode parent, long offset, long size)
|
||||
{
|
||||
return AddFile(name, parent, offset, size, 0, "", "");
|
||||
}
|
||||
public BetterTreeNode AddFile(string name, BetterTreeNode parent, long offset, long size) => AddFile(name, parent, offset, size, 0, "", "");
|
||||
|
||||
public BetterTreeNode AddFile(string name, BetterTreeNode parent, long offset, long size, long HashedRegionSize, string ExpectedHash, string ActualHash)
|
||||
{
|
||||
BetterTreeNode betterTreeNode = new BetterTreeNode(name);
|
||||
betterTreeNode.Offset = offset;
|
||||
betterTreeNode.Size = size;
|
||||
betterTreeNode.ExpectedHash = ExpectedHash;
|
||||
betterTreeNode.ActualHash = ActualHash;
|
||||
betterTreeNode.HashedRegionSize = HashedRegionSize;
|
||||
BetterTreeNode betterTreeNode = new(name)
|
||||
{
|
||||
Offset = offset,
|
||||
Size = size,
|
||||
ExpectedHash = ExpectedHash,
|
||||
ActualHash = ActualHash,
|
||||
HashedRegionSize = HashedRegionSize
|
||||
};
|
||||
parent.Nodes.Add(betterTreeNode);
|
||||
return betterTreeNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,130 +1,73 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
internal static class Util
|
||||
{
|
||||
public static string GetCapacity(int id)
|
||||
{
|
||||
switch (id)
|
||||
return id switch
|
||||
{
|
||||
case 250:
|
||||
return "1GB";
|
||||
case 248:
|
||||
return "2GB";
|
||||
case 240:
|
||||
return "4GB";
|
||||
case 224:
|
||||
return "8GB";
|
||||
case 225:
|
||||
return "16GB";
|
||||
case 226:
|
||||
return "32GB";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
250 => "1GB",
|
||||
248 => "2GB",
|
||||
240 => "4GB",
|
||||
224 => "8GB",
|
||||
225 => "16GB",
|
||||
226 => "32GB",
|
||||
_ => "?",
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetMkey(byte id)
|
||||
{
|
||||
switch (id)
|
||||
return id switch
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return "MasterKey0 (1.0.0-2.3.0)";
|
||||
case 2:
|
||||
return "MasterKey1 (3.0.0)";
|
||||
case 3:
|
||||
return "MasterKey2 (3.0.1-3.0.2)";
|
||||
case 4:
|
||||
return "MasterKey3 (4.0.0-4.1.0)";
|
||||
case 5:
|
||||
return "MasterKey4 (5.0.0-5.1.0)";
|
||||
case 6:
|
||||
return "MasterKey5 (6.0.0-6.1.0)";
|
||||
case 7:
|
||||
return "MasterKey6 (6.2.0)";
|
||||
case 8:
|
||||
return "MasterKey7 (7.0.0-8.0.1)";
|
||||
case 9:
|
||||
return "MasterKey8 (8.1.0-8.1.1)";
|
||||
case 10:
|
||||
return "MasterKey9 (9.0.0-9.0.1)";
|
||||
case 11:
|
||||
return "MasterKey10 (9.1.0-12.0.3)";
|
||||
case 12:
|
||||
return "MasterKey11 (12.1.0)";
|
||||
case 13:
|
||||
return "MasterKey12 (13.0.0-?)";
|
||||
case 14:
|
||||
return "MasterKey13";
|
||||
case 15:
|
||||
return "MasterKey14";
|
||||
case 16:
|
||||
return "MasterKey15";
|
||||
case 17:
|
||||
return "MasterKey16";
|
||||
case 18:
|
||||
return "MasterKey17";
|
||||
case 19:
|
||||
return "MasterKey18";
|
||||
case 20:
|
||||
return "MasterKey19";
|
||||
case 21:
|
||||
return "MasterKey20";
|
||||
case 22:
|
||||
return "MasterKey21";
|
||||
case 23:
|
||||
return "MasterKey22";
|
||||
case 24:
|
||||
return "MasterKey23";
|
||||
case 25:
|
||||
return "MasterKey24";
|
||||
case 26:
|
||||
return "MasterKey25";
|
||||
case 27:
|
||||
return "MasterKey26";
|
||||
case 28:
|
||||
return "MasterKey27";
|
||||
case 29:
|
||||
return "MasterKey28";
|
||||
case 30:
|
||||
return "MasterKey29";
|
||||
case 31:
|
||||
return "MasterKey30";
|
||||
case 32:
|
||||
return "MasterKey31";
|
||||
case 33:
|
||||
return "MasterKey32";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
0 or 1 => "MasterKey0 (1.0.0-2.3.0)",
|
||||
2 => "MasterKey1 (3.0.0)",
|
||||
3 => "MasterKey2 (3.0.1-3.0.2)",
|
||||
4 => "MasterKey3 (4.0.0-4.1.0)",
|
||||
5 => "MasterKey4 (5.0.0-5.1.0)",
|
||||
6 => "MasterKey5 (6.0.0-6.1.0)",
|
||||
7 => "MasterKey6 (6.2.0)",
|
||||
8 => "MasterKey7 (7.0.0-8.0.1)",
|
||||
9 => "MasterKey8 (8.1.0-8.1.1)",
|
||||
10 => "MasterKey9 (9.0.0-9.0.1)",
|
||||
11 => "MasterKey10 (9.1.0-12.0.3)",
|
||||
12 => "MasterKey11 (12.1.0)",
|
||||
13 => "MasterKey12 (13.0.0-?)",
|
||||
14 => "MasterKey13",
|
||||
15 => "MasterKey14",
|
||||
16 => "MasterKey15",
|
||||
17 => "MasterKey16",
|
||||
18 => "MasterKey17",
|
||||
19 => "MasterKey18",
|
||||
20 => "MasterKey19",
|
||||
21 => "MasterKey20",
|
||||
22 => "MasterKey21",
|
||||
23 => "MasterKey22",
|
||||
24 => "MasterKey23",
|
||||
25 => "MasterKey24",
|
||||
26 => "MasterKey25",
|
||||
27 => "MasterKey26",
|
||||
28 => "MasterKey27",
|
||||
29 => "MasterKey28",
|
||||
30 => "MasterKey29",
|
||||
31 => "MasterKey30",
|
||||
32 => "MasterKey31",
|
||||
33 => "MasterKey32",
|
||||
_ => "?",
|
||||
};
|
||||
}
|
||||
|
||||
public static bool checkFile(string filepath)
|
||||
{
|
||||
return File.Exists(filepath);
|
||||
}
|
||||
|
||||
public static byte[] StringToByteArray(string hex)
|
||||
{
|
||||
return (from x in Enumerable.Range(0, hex.Length)
|
||||
public static byte[] StringToByteArray(string hex) => (from x in Enumerable.Range(0, hex.Length)
|
||||
where x % 2 == 0
|
||||
select Convert.ToByte(hex.Substring(x, 2), 16)).ToArray();
|
||||
}
|
||||
|
||||
public static string Base64Encode(string plainText)
|
||||
{
|
||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
|
||||
return System.Convert.ToBase64String(plainTextBytes);
|
||||
}
|
||||
=> Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText));
|
||||
|
||||
public static string Base64Decode(string base64EncodedData)
|
||||
{
|
||||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
|
||||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
|
||||
}
|
||||
}
|
||||
=> Encoding.UTF8.GetString(Convert.FromBase64String(base64EncodedData));
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace XCI_Explorer
|
||||
{
|
||||
namespace XCI_Explorer;
|
||||
|
||||
public static class XCI
|
||||
{
|
||||
public class XCI_Header
|
||||
|
@ -28,4 +28,3 @@ namespace XCI_Explorer
|
|||
|
||||
public static XCI_Header[] XCI_Headers = new XCI_Header[1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class RandomAccessSectorStream : Stream
|
||||
{
|
||||
private readonly byte[] _buffer;
|
||||
|
@ -17,18 +17,21 @@ namespace XTSSharp
|
|||
public override bool CanWrite => _s.CanWrite;
|
||||
public override long Length => _s.Length + _bufferPos;
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_bufferLoaded)
|
||||
{
|
||||
return _s.Position + _bufferPos;
|
||||
}
|
||||
return _s.Position - _bufferSize + _bufferPos;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("value");
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
}
|
||||
long num = value % _bufferSize;
|
||||
long position = value - num;
|
||||
|
@ -84,19 +87,12 @@ namespace XTSSharp
|
|||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
long num;
|
||||
switch (origin)
|
||||
long num = origin switch
|
||||
{
|
||||
case SeekOrigin.Begin:
|
||||
num = offset;
|
||||
break;
|
||||
case SeekOrigin.End:
|
||||
num = Length - offset;
|
||||
break;
|
||||
default:
|
||||
num = Position + offset;
|
||||
break;
|
||||
}
|
||||
SeekOrigin.Begin => offset,
|
||||
SeekOrigin.End => Length - offset,
|
||||
_ => Position + offset,
|
||||
};
|
||||
Position = num;
|
||||
return num;
|
||||
}
|
||||
|
@ -192,4 +188,3 @@ namespace XTSSharp
|
|||
Array.Clear(_buffer, 0, _bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class SectorStream : Stream
|
||||
{
|
||||
private readonly Stream _baseStream;
|
||||
private readonly long _offset;
|
||||
private ulong _currentSector;
|
||||
|
||||
public int SectorSize {
|
||||
public int SectorSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
@ -19,11 +20,14 @@ namespace XTSSharp
|
|||
public override bool CanWrite => _baseStream.CanWrite;
|
||||
public override long Length => _baseStream.Length - _offset;
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return _baseStream.Position - _offset;
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
ValidateSizeMultiple(value);
|
||||
_baseStream.Position = value + _offset;
|
||||
_currentSector = (ulong)(value / SectorSize);
|
||||
|
@ -78,19 +82,12 @@ namespace XTSSharp
|
|||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
long num;
|
||||
switch (origin)
|
||||
long num = origin switch
|
||||
{
|
||||
case SeekOrigin.Begin:
|
||||
num = offset;
|
||||
break;
|
||||
case SeekOrigin.End:
|
||||
num = Length - offset;
|
||||
break;
|
||||
default:
|
||||
num = Position + offset;
|
||||
break;
|
||||
}
|
||||
SeekOrigin.Begin => offset,
|
||||
SeekOrigin.End => Length - offset,
|
||||
_ => Position + offset,
|
||||
};
|
||||
Position = num;
|
||||
return num;
|
||||
}
|
||||
|
@ -116,4 +113,3 @@ namespace XTSSharp
|
|||
_currentSector++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class Xts
|
||||
{
|
||||
private readonly SymmetricAlgorithm _key1;
|
||||
|
@ -12,15 +12,15 @@ namespace XTSSharp
|
|||
{
|
||||
if (create == null)
|
||||
{
|
||||
throw new ArgumentNullException("create");
|
||||
throw new ArgumentNullException(nameof(create));
|
||||
}
|
||||
if (key1 == null)
|
||||
{
|
||||
throw new ArgumentNullException("key1");
|
||||
throw new ArgumentNullException(nameof(key1));
|
||||
}
|
||||
if (key2 == null)
|
||||
{
|
||||
throw new ArgumentNullException("key2");
|
||||
throw new ArgumentNullException(nameof(key2));
|
||||
}
|
||||
_key1 = create();
|
||||
_key2 = create();
|
||||
|
@ -54,7 +54,7 @@ namespace XTSSharp
|
|||
{
|
||||
if (key == null)
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
if (key.Length * 8 != expectedSize)
|
||||
{
|
||||
|
@ -63,4 +63,3 @@ namespace XTSSharp
|
|||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class XtsAes128 : Xts
|
||||
{
|
||||
private const int KEY_LENGTH = 128;
|
||||
private const int KEY_BYTE_LENGTH = 16;
|
||||
|
||||
protected XtsAes128(Func<SymmetricAlgorithm> create, byte[] key1, byte[] key2)
|
||||
: base(create, Xts.VerifyKey(128, key1), Xts.VerifyKey(128, key2))
|
||||
: base(create, VerifyKey(128, key1), VerifyKey(128, key2))
|
||||
{
|
||||
}
|
||||
|
||||
public static Xts Create(byte[] key1, byte[] key2)
|
||||
{
|
||||
Xts.VerifyKey(128, key1);
|
||||
Xts.VerifyKey(128, key2);
|
||||
VerifyKey(128, key1);
|
||||
VerifyKey(128, key2);
|
||||
return new XtsAes128(Aes.Create, key1, key2);
|
||||
}
|
||||
|
||||
public static Xts Create(byte[] key)
|
||||
{
|
||||
Xts.VerifyKey(256, key);
|
||||
VerifyKey(256, key);
|
||||
byte[] array = new byte[16];
|
||||
byte[] array2 = new byte[16];
|
||||
Buffer.BlockCopy(key, 0, array, 0, 16);
|
||||
|
@ -30,4 +30,3 @@ namespace XTSSharp
|
|||
return new XtsAes128(Aes.Create, array, array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class XtsAes256 : Xts
|
||||
{
|
||||
private const int KEY_LENGTH = 256;
|
||||
private const int KEY_BYTE_LENGTH = 32;
|
||||
|
||||
protected XtsAes256(Func<SymmetricAlgorithm> create, byte[] key1, byte[] key2)
|
||||
: base(create, Xts.VerifyKey(256, key1), Xts.VerifyKey(256, key2))
|
||||
: base(create, VerifyKey(256, key1), VerifyKey(256, key2))
|
||||
{
|
||||
}
|
||||
|
||||
public static Xts Create(byte[] key1, byte[] key2)
|
||||
{
|
||||
Xts.VerifyKey(256, key1);
|
||||
Xts.VerifyKey(256, key2);
|
||||
VerifyKey(256, key1);
|
||||
VerifyKey(256, key2);
|
||||
return new XtsAes256(Aes.Create, key1, key2);
|
||||
}
|
||||
|
||||
public static Xts Create(byte[] key)
|
||||
{
|
||||
Xts.VerifyKey(512, key);
|
||||
VerifyKey(512, key);
|
||||
byte[] array = new byte[32];
|
||||
byte[] array2 = new byte[32];
|
||||
Buffer.BlockCopy(key, 0, array, 0, 32);
|
||||
|
@ -30,4 +30,3 @@ namespace XTSSharp
|
|||
return new XtsAes256(Aes.Create, array, array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class XtsCryptoTransform : IDisposable
|
||||
{
|
||||
private readonly byte[] _cc = new byte[16];
|
||||
|
@ -17,11 +17,11 @@ namespace XTSSharp
|
|||
{
|
||||
if (key1 == null)
|
||||
{
|
||||
throw new ArgumentNullException("key1");
|
||||
throw new ArgumentNullException(nameof(key1));
|
||||
}
|
||||
if (key2 == null)
|
||||
{
|
||||
throw new ArgumentNullException("key2");
|
||||
throw new ArgumentNullException(nameof(key2));
|
||||
}
|
||||
_key1 = key1;
|
||||
_key2 = key2;
|
||||
|
@ -139,4 +139,3 @@ namespace XTSSharp
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.IO;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class XtsSectorStream : SectorStream
|
||||
{
|
||||
public const int DEFAULT_SECTOR_SIZE = 512;
|
||||
|
@ -71,4 +71,3 @@ namespace XTSSharp
|
|||
return _decryptor.TransformBlock(_tempBuffer, 0, num, buffer, offset, currentSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.IO;
|
||||
|
||||
namespace XTSSharp
|
||||
{
|
||||
namespace XTSSharp;
|
||||
|
||||
public class XtsStream : RandomAccessSectorStream
|
||||
{
|
||||
public XtsStream(Stream baseStream, Xts xts)
|
||||
|
@ -19,4 +19,3 @@ namespace XTSSharp
|
|||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue