Skip to content

Commit

Permalink
feat: allow nss uploads for nintendo
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyg603 committed Jul 12, 2024
1 parent 1b51a4f commit 89c43c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/elf.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import { ElfFile } from '@bugsplat/elfy';
import { extname } from 'node:path';

export async function tryGetElfUUID(path: string) {
let success: boolean, section: Buffer | undefined;

// TODO BG use a using statement here when we move away from pkg and can use node 20+
let elfFile = await ElfFile.create(path);
try {
({ success, section } = await elfFile.tryReadSection('.note.gnu.build-id'));
} finally {
elfFile.dispose();
}
using elfFile = await ElfFile.create(path);
({ success, section } = await elfFile.tryReadSection('.note.gnu.build-id'));

if (success) {
return getUUID(section!, 16);
return getUUID(section!, path, 16);
}

elfFile = await ElfFile.create(path);
try {
({ success, section } = await elfFile.tryReadSection('.sce_special'));
} finally {
elfFile.dispose();
}
({ success, section } = await elfFile.tryReadSection('.sce_special'));

if (success) {
return getUUID(section!);
return getUUID(section!, path);
}

return '';
}

function getUUID(section: Buffer, offset = 0) {
return section.subarray(offset, offset + 20).toString('hex');
function getUUID(section: Buffer, path: string, offset = 0) {
let uuid = section.subarray(offset, offset + 20).toString('hex');

// Nintendo GUIDs seem to be 32 or 40 hex chars 0 padded to 64 hex chars
// Until we know more, pad it ourselves with this hacky workaround
if (extname(path)?.toLowerCase() === '.nss') {
uuid = uuid.padEnd(64, '0');
}

return uuid;
}
2 changes: 1 addition & 1 deletion src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ async function createSymbolFileInfos(symbolFilePath: string): Promise<SymbolFile
} as SymbolFileInfo];
}

const elfExtensions = ['.elf', '.self', '.prx', '.sprx'];
const elfExtensions = ['.elf', '.self', '.prx', '.sprx', '.nss'];

0 comments on commit 89c43c9

Please sign in to comment.