Skip to content
This repository was archived by the owner on Jun 30, 2020. It is now read-only.

Commit aa2b0ea

Browse files
committed
Implement support for BinGz index replacement
1 parent 6672b8b commit aa2b0ea

1 file changed

Lines changed: 68 additions & 4 deletions

File tree

source/main.cpp

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Result roLoadModuleHook(nn::ro::Module* module, const void * nro, void * buffer,
3131
return rc;
3232
}
3333

34+
struct BinGz {
35+
u64 entry_count;
36+
u64 unk;
37+
u32 entry_id;
38+
// ...
39+
};
40+
3441
Result (*ogRoUnloadModule)(nn::ro::Module*);
3542

3643
Result roUnloadModuleHook(nn::ro::Module* module){
@@ -51,14 +58,14 @@ void exceptionHandler(nn::os::UserExceptionInfo* info){
5158
skyline::TcpLogger::SendRawFormat("LR: %" PRIx64 " \n", info->LR.x);
5259
skyline::TcpLogger::SendRawFormat("SP: %" PRIx64 "\n", info->SP.x);
5360
skyline::TcpLogger::SendRawFormat("PC: %" PRIx64 "\n", info->PC.x);
54-
55-
//*((u64*)0) = 0x69;
5661
}
5762

5863
void* (*fe_malloc)(u64, u64);
5964
u64* (*og_load_entryid)(u64*,u32,u64*,u32,u64,u64*,u64*,u64*);
6065
u64 (*uncompress_entryid)(u64*, u32);
6166
void (*ktgl_io_fs_getfilepath)(char*, uint);
67+
u32 (*original_filesize_by_idx)(BinGz*, uint);
68+
void* (*original_bingz_get_entry_offset)(BinGz* bin, u32 index);
6269

6370
u64* load_from_forge(u64* archive_ptr, u32 entryid, u64* file_ptr, u32 seek, u64 size, u64* unk3, u64* unk4, u64* unk5) {
6471
char path[256];
@@ -93,7 +100,7 @@ u64* load_from_forge(u64* archive_ptr, u32 entryid, u64* file_ptr, u32 seek, u64
93100
ktgl_io_fs_getfilepath(filename, entryid);
94101
if(filename[0] == '\0')
95102
return 0;
96-
103+
97104
skyline::TcpLogger::SendRawFormat("Filename: %s\n", filename);
98105
return 0;
99106
}
@@ -125,8 +132,55 @@ u64 archive_fake_uncomp_size(u64* archive_ptr, u32 entryid)
125132
}
126133
}
127134

135+
uint bingz_get_filesize_by_index(BinGz* bin, u32 index)
136+
{
137+
char path[256];
138+
nn::util::SNPrintf(path, 256, "sdmc:/Aldebaran/forge/%d/%d", bin->entry_id, index);
139+
nn::fs::FileHandle file;
140+
Result result;
141+
result = nn::fs::OpenFile(&file, path, 1);
142+
if (result == 0) {
143+
skyline::TcpLogger::SendRaw("BinGz index filesize read intercepted\n");
144+
s64 filesize;
145+
nn::fs::GetFileSize(&filesize, file);
146+
nn::fs::CloseFile(file);
147+
skyline::TcpLogger::SendRawFormat("Entry id: %d\nIndex: %d\nNew filesize: %d\n", bin->entry_id, index, filesize);
148+
return (u32)filesize;
149+
} else {
150+
if(bin->entry_id == 3121)
151+
skyline::TcpLogger::SendRaw("BinGz index filesize read intercepted\n");
152+
153+
return original_filesize_by_idx(bin, index);
154+
}
155+
}
156+
157+
void* bingz_get_entry_offset(BinGz* bin, u32 index)
158+
{
159+
char path[256];
160+
nn::util::SNPrintf(path, 256, "sdmc:/Aldebaran/forge/%d/%d", bin->entry_id, index);
161+
nn::fs::FileHandle file;
162+
Result result;
163+
result = nn::fs::OpenFile(&file, path, 1);
164+
if (result == 0) {
165+
skyline::TcpLogger::SendRawFormat("Hijacked index found in BinGz\n", index, bin->entry_id);
166+
167+
s64 filesize;
168+
nn::fs::GetFileSize(&filesize, file);
169+
170+
void* contents;
171+
contents = fe_malloc(filesize, 0x10);
172+
173+
nn::fs::ReadFile(file, 0, contents, filesize);
174+
nn::fs::CloseFile(file);
175+
176+
return contents;
177+
} else {
178+
return original_bingz_get_entry_offset(bin, index);
179+
}
180+
}
181+
128182
char* hook_get_version_string() {
129-
return "Aldebaran 0.1.2";
183+
return "Aldebaran 0.1.3";
130184
}
131185

132186
void stub() {}
@@ -175,6 +229,16 @@ void runtimePatchMain() {
175229
reinterpret_cast<void*>(text + 0x3e63e0),
176230
reinterpret_cast<void*>(hook_get_version_string),
177231
NULL);
232+
233+
A64HookFunction(
234+
reinterpret_cast<void*>(text + 0x4a4ca0),
235+
reinterpret_cast<void*>(bingz_get_filesize_by_index),
236+
(void**)&original_filesize_by_idx);
237+
238+
A64HookFunction(
239+
reinterpret_cast<void*>(text + 0x4a4cc0),
240+
reinterpret_cast<void*>(bingz_get_entry_offset),
241+
(void**)&original_bingz_get_entry_offset);
178242

179243
fe_malloc = (void* (*) (u64, u64)) text + 0x5bab80;
180244
ktgl_io_fs_getfilepath = (void (*)(char*, uint))text + 0x4a47d0;

0 commit comments

Comments
 (0)