Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
8be3a041
There was an error fetching the commit references. Please try again later.
Commit
8be3a041
authored
1 year ago
by
Liam
Browse files
Options
Downloads
Patches
Plain Diff
file_sys/card_image: support dumps with prepended key area
parent
ddedaa88
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/file_sys/card_image.cpp
+41
-7
41 additions, 7 deletions
src/core/file_sys/card_image.cpp
src/core/file_sys/card_image.h
+1
-0
1 addition, 0 deletions
src/core/file_sys/card_image.h
with
42 additions
and
7 deletions
src/core/file_sys/card_image.cpp
+
41
−
7
View file @
8be3a041
...
...
@@ -31,13 +31,9 @@ XCI::XCI(VirtualFile file_, u64 program_id, size_t program_index)
:
file
(
std
::
move
(
file_
)),
program_nca_status
{
Loader
::
ResultStatus
::
ErrorXCIMissingProgramNCA
},
partitions
(
partition_names
.
size
()),
partitions_raw
(
partition_names
.
size
()),
keys
{
Core
::
Crypto
::
KeyManager
::
Instance
()}
{
if
(
file
->
ReadObject
(
&
header
)
!=
sizeof
(
GamecardHeader
))
{
status
=
Loader
::
ResultStatus
::
ErrorBadXCIHeader
;
return
;
}
if
(
header
.
magic
!=
Common
::
MakeMagic
(
'H'
,
'E'
,
'A'
,
'D'
))
{
status
=
Loader
::
ResultStatus
::
ErrorBadXCIHeader
;
const
auto
header_status
=
TryReadHeader
();
if
(
header_status
!=
Loader
::
ResultStatus
::
Success
)
{
status
=
header_status
;
return
;
}
...
...
@@ -316,6 +312,44 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
return
Loader
::
ResultStatus
::
Success
;
}
Loader
::
ResultStatus
XCI
::
TryReadHeader
()
{
constexpr
size_t
CardInitialDataRegionSize
=
0x1000
;
// Define the function we'll use to determine if we read a valid header.
const
auto
ReadCardHeader
=
[
&
]()
{
// Ensure we can read the entire header. If we can't, we can't read the card image.
if
(
file
->
ReadObject
(
&
header
)
!=
sizeof
(
GamecardHeader
))
{
return
Loader
::
ResultStatus
::
ErrorBadXCIHeader
;
}
// Ensure the header magic matches. If it doesn't, this isn't a card image header.
if
(
header
.
magic
!=
Common
::
MakeMagic
(
'H'
,
'E'
,
'A'
,
'D'
))
{
return
Loader
::
ResultStatus
::
ErrorBadXCIHeader
;
}
// We read a card image header.
return
Loader
::
ResultStatus
::
Success
;
};
// Try to read the header directly.
if
(
ReadCardHeader
()
==
Loader
::
ResultStatus
::
Success
)
{
return
Loader
::
ResultStatus
::
Success
;
}
// Get the size of the file.
const
size_t
card_image_size
=
file
->
GetSize
();
// If we are large enough to have a key area, offset past the key area and retry.
if
(
card_image_size
>=
CardInitialDataRegionSize
)
{
file
=
std
::
make_shared
<
OffsetVfsFile
>
(
file
,
card_image_size
-
CardInitialDataRegionSize
,
CardInitialDataRegionSize
);
return
ReadCardHeader
();
}
// We had no header and aren't large enough to have a key area, so this can't be parsed.
return
Loader
::
ResultStatus
::
ErrorBadXCIHeader
;
}
u8
XCI
::
GetFormatVersion
()
{
return
GetLogoPartition
()
==
nullptr
?
0x1
:
0x2
;
}
...
...
This diff is collapsed.
Click to expand it.
src/core/file_sys/card_image.h
+
1
−
0
View file @
8be3a041
...
...
@@ -128,6 +128,7 @@ public:
private:
Loader
::
ResultStatus
AddNCAFromPartition
(
XCIPartition
part
);
Loader
::
ResultStatus
TryReadHeader
();
VirtualFile
file
;
GamecardHeader
header
{};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment