Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradually check if format is ASAR/Pickle. #1

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,24 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0x04, 0x00, 0x00, 0x00]) && buffer.length >= 16) { // Rough & quick check Pickle/ASAR
const jsonSize = buffer.readUInt32LE(12);
if (jsonSize > 12 && jsonSize < 240 && buffer.length >= jsonSize + 16) {
try {
const header = buffer.slice(16, jsonSize + 16).toString();
const json = JSON.parse(header);
// Check if Pickle is ASAR
if (json.files) { // Final check, assuring Pickle/ASAR format
return {
ext: 'asar',
mime: 'application/x-asar'
};
}
} catch (_) {
}
}
}

if (
check([0x30, 0x30, 0x30, 0x30, 0x30, 0x30], {offset: 148, mask: [0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8]}) && // Valid tar checksum
tarHeaderChecksumMatches(buffer)
Expand Down Expand Up @@ -1355,21 +1373,6 @@ async function _fromTokenizer(tokenizer) {
}
}
}

// Check for Asar
if (checkString('{"files":{', {offset: 16})) {
try {
// Check header
const jsonSize = buffer.readUInt32LE(12);
const header = buffer.slice(16, jsonSize + 16).toString();
JSON.parse(header);

return {
ext: 'asar',
mime: 'application/x-asar'
};
} catch (_) {}
}
}

const stream = readableStream => new Promise((resolve, reject) => {
Expand All @@ -1382,7 +1385,8 @@ const stream = readableStream => new Promise((resolve, reject) => {
const pass = new stream.PassThrough();
let outputStream;
if (stream.pipeline) {
outputStream = stream.pipeline(readableStream, pass, () => {});
outputStream = stream.pipeline(readableStream, pass, () => {
});
} else {
outputStream = readableStream.pipe(pass);
}
Expand Down