privacy-scan: AppImage squashfs found at the end of the ELF runtime (the runtime contains the magic too); a generic home (/root) is not a term. tools test: 30s timeout (detectTools runs every version command)
This commit is contained in:
parent
03b938efa3
commit
e3711ec52f
3 changed files with 26 additions and 4 deletions
|
|
@ -40,6 +40,18 @@ const sh = (cmd: string[]): string => {
|
|||
return r.status === 0 ? r.stdout.trim() : '';
|
||||
};
|
||||
|
||||
/** Where an AppImage's squashfs starts: the end of its ELF runtime (section headers come last), else the first
|
||||
* "hsqs" magic. The runtime itself may contain the magic as a constant, so the ELF end is tried first. */
|
||||
export function squashfsOffset(data: Uint8Array): number {
|
||||
const b = Buffer.from(data.buffer, data.byteOffset, data.length);
|
||||
const isSq = (o: number) => o > 0 && o + 4 <= b.length && b.toString('latin1', o, o + 4) === 'hsqs';
|
||||
if (b.length > 0x40 && b.toString('latin1', 0, 4) === '\x7fELF' && b[4] === 2 && b[5] === 1) {
|
||||
const end = Number(b.readBigUInt64LE(0x28)) + b.readUInt16LE(0x3a) * b.readUInt16LE(0x3c);
|
||||
if (isSq(end)) return end;
|
||||
}
|
||||
return b.indexOf('hsqs', 0x400, 'latin1');
|
||||
}
|
||||
|
||||
export function parseTerms(text: string): string[] {
|
||||
return text.split(/\r?\n/).map(l => l.trim()).filter(l => l && !l.startsWith('#'));
|
||||
}
|
||||
|
|
@ -59,7 +71,8 @@ export function collectTerms(file: string | null, auto = true): Term[] {
|
|||
try { user = userInfo().username; } catch { /* no passwd entry */ }
|
||||
add(user, true);
|
||||
add(basename(homedir()), true);
|
||||
if (homedir().length > 4) add(homedir(), true);
|
||||
// a generic home (/root in a CI container) is no name, and "/root" is part of ordinary strings (root_certs.cpp)
|
||||
if (homedir().length > 4 && !GENERIC.has(basename(homedir()).toLowerCase())) add(homedir(), true);
|
||||
const host = hostname().replace(/\.local$/i, '');
|
||||
add(host, true);
|
||||
if (process.platform === 'darwin') {
|
||||
|
|
@ -174,7 +187,7 @@ function unpack(path: string, kind: Kind): { dir: string; cleanup: () => void }
|
|||
if (kind === 'appimage') {
|
||||
const unsq = which('unsquashfs');
|
||||
const data = readFileSync(path);
|
||||
const off = data.indexOf(Buffer.from('hsqs'), 0x400);
|
||||
const off = squashfsOffset(data);
|
||||
if (unsq && off > 0) { run([unsq, '-q', '-n', '-d', join(dir, 'root'), '-o', String(off), path]); return { dir: join(dir, 'root'), cleanup }; }
|
||||
const z = which('7zz', '7z');
|
||||
if (z) { run([z, 'x', '-y', `-o${dir}`, path]); return { dir, cleanup }; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue