Last active
November 16, 2021 00:24
-
-
Save maca134/655276226c985252cc92df826f410f68 to your computer and use it in GitHub Desktop.
Get Chrome Extension ID in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFileSync } from 'fs'; | |
import { parse } from 'protobufjs'; | |
if (!process.argv[2]) throw new Error('no arg'); | |
const file = readFileSync(process.argv[2]); | |
if (!file) throw new Error('no file'); | |
const root = parse(` | |
package chromeextensionid; | |
syntax = "proto3"; | |
message CrxFileHeader { | |
repeated AsymmetricKeyProof sha256_with_rsa = 2; | |
repeated AsymmetricKeyProof sha256_with_ecdsa = 3; | |
optional SignedData signed_header_data = 10000; | |
} | |
message AsymmetricKeyProof { | |
optional bytes public_key = 1; | |
optional bytes signature = 2; | |
} | |
message SignedData { | |
optional bytes crx_id = 1; | |
} | |
`).root; | |
const CrxFileHeader = root.lookupType('chromeextensionid.CrxFileHeader'); | |
const headerObj = CrxFileHeader.decode(file.slice(12, 12 + file.readInt32LE(8))) as any; | |
const crxId = headerObj.signedHeaderData.crxId as Buffer; | |
const chars = '0123456789abcdefghijklmnop'.split(''); | |
const id = crxId.toString('hex') | |
.split('') | |
.map(c => chars[chars.findIndex(d => c === d) + 10]) | |
.join(''); | |
console.log(id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment