Skip to content

Commit 037b79e

Browse files
committed
fix regressions and crashes
1 parent b4f140d commit 037b79e

File tree

6 files changed

+104
-93
lines changed

6 files changed

+104
-93
lines changed

NSPVerify/NSPVerify.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@
5454
<None Include="App.config" />
5555
<None Include="packages.config" />
5656
</ItemGroup>
57-
<ItemGroup>
58-
<ProjectReference Include="..\..\libhac\libhac\libhac.csproj">
59-
<Project>{e156d7b4-dced-47b5-a0cc-40811b2fef0d}</Project>
60-
<Name>libhac</Name>
61-
</ProjectReference>
62-
</ItemGroup>
6357
<ItemGroup>
6458
<Content Include="FodyWeavers.xml" />
6559
<Content Include="history.txt">
6660
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6761
</Content>
6862
</ItemGroup>
63+
<ItemGroup>
64+
<ProjectReference Include="..\..\libhac\src\LibHac\LibHac.csproj">
65+
<Project>{f7786ff9-5b77-41f2-bd67-114bd2952f2d}</Project>
66+
<Name>LibHac</Name>
67+
</ProjectReference>
68+
</ItemGroup>
6969
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7070
<Import Project="..\packages\Fody.3.1.4\build\Fody.targets" Condition="Exists('..\packages\Fody.3.1.4\build\Fody.targets')" />
7171
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

NSPVerify/Program.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Security.Cryptography;
66
using LibHac;
7+
using LibHac.IO;
78

89
namespace NSPVerify
910
{
@@ -85,7 +86,7 @@ static void Main(string[] args)
8586
using (var nspfile = fs.OpenFile(file, FileMode.Open, FileAccess.Read))
8687
{
8788

88-
var nspdata = new Pfs(nspfile);
89+
var nspdata = new Pfs(new StreamStorage(nspfile, true));
8990
var cnmtfile = nspdata.Files.FirstOrDefault(x => x.Name.ToLowerInvariant().EndsWith(".cnmt.nca"));
9091
if (cnmtfile == null)
9192
{
@@ -96,7 +97,7 @@ static void Main(string[] args)
9697

9798
var cnmtdata = nspdata.OpenFile(cnmtfile);
9899
Cnmt cnmt;
99-
using (var sr = new BinaryReader(cnmtdata))
100+
using (var sr = new BinaryReader(cnmtdata.AsStream()))
100101
{
101102
var cnmthash = SHA256.Create().ComputeHash(sr.ReadBytes((int) cnmtdata.Length));
102103
if (!cnmtfile.Name.ToLowerInvariant().Contains(cnmthash.Take(16).ToArray().ToHexString()))
@@ -108,19 +109,19 @@ static void Main(string[] args)
108109
continue;
109110
}
110111

111-
cnmtdata.Position = 0;
112+
sr.BaseStream.Position = 0;
112113
var cnmtnca = new Nca(keyset, cnmtdata, false);
113-
var section = cnmtnca.OpenSection(0, false);
114+
var section = cnmtnca.OpenSection(0, false, IntegrityCheckLevel.ErrorOnInvalid, false);
114115
var sectionpfs = new Pfs(section);
115-
cnmt = new Cnmt(sectionpfs.OpenFile(sectionpfs.Files[0]));
116+
cnmt = new Cnmt(sectionpfs.OpenFile(sectionpfs.Files[0]).AsStream());
116117
}
117118

118119
foreach (var entry in cnmt.ContentEntries)
119120
{
120121
var entryfile = nspdata.Files.FirstOrDefault(x => x.Name.ToLowerInvariant().EndsWith(entry.NcaId.ToHexString() + ".nca"));
121122
if (entryfile == null)
122123
{
123-
if (entry.Type != CnmtContentType.UpdatePatch)
124+
if (entry.Type != CnmtContentType.DeltaFragment)
124125
{
125126
//Put failure here
126127
Console.WriteLine($"\rChecking {filename}: one of the entries required by the cnmt.nca is missing.");
@@ -135,13 +136,13 @@ static void Main(string[] args)
135136
{
136137
var hash = SHA256.Create();
137138

138-
using (var sr = new BinaryReader(entrynca))
139+
using (var sr = new BinaryReader(entrynca.AsStream()))
139140
{
140-
while (entrynca.Length != entrynca.Position)
141+
while (entrynca.Length != sr.BaseStream.Position)
141142
{
142143
var entryncadata = sr.ReadBytes(0x100000);
143144
hash.TransformBlock(entryncadata, 0, entryncadata.Length, entryncadata, 0);
144-
Console.Write($"\rChecking {filename}: {((entrynca.Position * 100.0) / entrynca.Length):0.0}%");
145+
Console.Write($"\rChecking {filename}: {((sr.BaseStream.Position * 100.0) / entrynca.Length):0.0}%");
145146
}
146147

147148
hash.TransformFinalBlock(new byte[0], 0, 0);

SwitchSDTool.sln

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ VisualStudioVersion = 15.0.27703.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwitchSDTool", "SwitchSDTool\SwitchSDTool.csproj", "{672895BC-DB06-423B-8E22-F59059486D2D}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libhac", "..\libhac\libhac\libhac.csproj", "{E156D7B4-DCED-47B5-A0CC-40811B2FEF0D}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSPVerify", "NSPVerify\NSPVerify.csproj", "{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libhac.Nand", "..\libhac\libhac.Nand\libhac.Nand.csproj", "{A647DD91-AC76-4703-BA93-6CC89139AA1D}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibHac", "..\libhac\src\LibHac\LibHac.csproj", "{F7786FF9-5B77-41F2-BD67-114BD2952F2D}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSPVerify", "NSPVerify\NSPVerify.csproj", "{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibHac.Nand", "..\libhac\src\LibHac.Nand\LibHac.Nand.csproj", "{04D51950-1389-43FF-8580-FBD2AD57F187}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,18 +21,18 @@ Global
2121
{672895BC-DB06-423B-8E22-F59059486D2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
2222
{672895BC-DB06-423B-8E22-F59059486D2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{672895BC-DB06-423B-8E22-F59059486D2D}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{E156D7B4-DCED-47B5-A0CC-40811B2FEF0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{E156D7B4-DCED-47B5-A0CC-40811B2FEF0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{E156D7B4-DCED-47B5-A0CC-40811B2FEF0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{E156D7B4-DCED-47B5-A0CC-40811B2FEF0D}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{A647DD91-AC76-4703-BA93-6CC89139AA1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{A647DD91-AC76-4703-BA93-6CC89139AA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{A647DD91-AC76-4703-BA93-6CC89139AA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{A647DD91-AC76-4703-BA93-6CC89139AA1D}.Release|Any CPU.Build.0 = Release|Any CPU
3224
{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3325
{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
3426
{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
3527
{97CDB25B-7325-4D06-ABC4-752ACB0B99DF}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{F7786FF9-5B77-41F2-BD67-114BD2952F2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{F7786FF9-5B77-41F2-BD67-114BD2952F2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{F7786FF9-5B77-41F2-BD67-114BD2952F2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{F7786FF9-5B77-41F2-BD67-114BD2952F2D}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{04D51950-1389-43FF-8580-FBD2AD57F187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{04D51950-1389-43FF-8580-FBD2AD57F187}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{04D51950-1389-43FF-8580-FBD2AD57F187}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{04D51950-1389-43FF-8580-FBD2AD57F187}.Release|Any CPU.Build.0 = Release|Any CPU
3636
EndGlobalSection
3737
GlobalSection(SolutionProperties) = preSolution
3838
HideSolutionNode = FALSE

SwitchSDTool/ControlNACP.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Windows.Forms;
77
using LibHac;
8+
using LibHac.IO;
89
using SwitchSDTool.Properties;
910

1011
namespace SwitchSDTool
@@ -41,7 +42,7 @@ public ControlNACP(Romfs romfs, string baseTitleID)
4142
Icons = new Bitmap[15];
4243
Languages = new List<Languages>();
4344
BaseTitleID = baseTitleID;
44-
using (var control = new BinaryReader(romfs.OpenFile("/control.nacp")))
45+
using (var control = new BinaryReader(romfs.OpenFile("/control.nacp").AsStream()))
4546
{
4647
var versionBytes = new byte[16];
4748
control.BaseStream.Seek(0x3060, SeekOrigin.Begin);
@@ -66,7 +67,7 @@ public ControlNACP(Romfs romfs, string baseTitleID)
6667
lname = $"/icon_{lname}.dat";
6768
if (!romfs.FileExists(lname)) continue;
6869
Bitmap icon;
69-
using (var bm = new Bitmap(romfs.OpenFile(lname)))
70+
using (var bm = new Bitmap(romfs.OpenFile(lname).AsStream()))
7071
{
7172
icon = new Bitmap(bm);
7273
}

0 commit comments

Comments
 (0)