Skip to content

Instantly share code, notes, and snippets.

@Deliaz
Created April 8, 2019 05:22

Revisions

  1. Deliaz created this gist Apr 8, 2019.
    19 changes: 19 additions & 0 deletions crxver.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/usr/bin/env node
    const fs = require('fs');

    const filePath = process.argv[2];
    if(!filePath) {
    console.error('No file specified.\nUsage:\n\tnode crxver.js my-extensions.crx\n');
    process.exit(-1);
    }

    const buf = fs.readFileSync(filePath);

    const VERSION_POS_BYTE_OFFSET = 4;
    const VERSION_LENGTH_BYTE = 1;

    const type = buf.subarray(0, 4).toString('ascii');
    const version = buf.readIntBE(VERSION_POS_BYTE_OFFSET, VERSION_LENGTH_BYTE).toString(16);

    console.log('File type:\t', type);
    console.log('Version:\t', version);