Skip to content
Merged
Show file tree
Hide file tree
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
66 changes: 39 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,54 @@ If you're building firmware on the Particle Platform, you might be curious to se
});
```

You can also get the raw output of binary-version-reader by using it as a command line tool without installing it.
You can also inspect a firmware binary from the command line without installing the package:

```
npx binary-version-reader your_binary.bin
```

The output is valid JSON, suitable for piping into other tools:

```
npx binary-version-reader your_binary.bin | jq '.prefixInfo.moduleVersion'
```
Comment thread
monkbroc marked this conversation as resolved.

## Example output

```json
{
"filename": "/.../040_user-part.bin",
"fileBuffer": "<Buffer ...>",
"crc": {
"ok": 1,
"storedCrc": "b138f375",
"actualCrc": "b138f375"
},
"prefixInfo": {
"moduleStartAddy": "80a0000",
"moduleEndAddy": "80a128c",
"moduleVersion": 2,
"platformID": 6,
"moduleFunction": 5,
"moduleIndex": 1,
"depModuleFunction": 4,
"depModuleIndex": 2,
"depModuleVersion": 1
},
"suffixInfo": {
"productId": -1,
"productVersion": -1,
"fwUniqueId": "f9f552aa98d7e3eab750862a01743024a4d05514021598a4341b3d83b37eda36",
"reserved": 0,
"suffixSize": 36,
"crcBlock": "b138f375"
}
"filename": "your_binary.bin",
"crc": {
"ok": true,
"storedCrc": "b138f375",
"actualCrc": "b138f375"
},
"prefixInfo": {
"moduleStartAddy": "80a0000",
"moduleEndAddy": "80a128c",
"reserved": 0,
"moduleFlags": 0,
"moduleVersion": 2,
"platformID": 6,
"moduleFunction": 5,
"moduleIndex": 1,
"depModuleFunction": 4,
"depModuleIndex": 2,
"depModuleVersion": 1,
"dep2ModuleFunction": 0,
"dep2ModuleIndex": 0,
"dep2ModuleVersion": 0,
"prefixSize": 24,
"prefixOffset": 0
},
"suffixInfo": {
"productId": -1,
"productVersion": -1,
"fwUniqueId": "f9f552aa98d7e3eab750862a01743024a4d05514021598a4341b3d83b37eda36",
"reserved": 0,
"suffixSize": 36,
"crcBlock": "b138f375"
}
}
```

Expand Down
18 changes: 16 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ if (args.length <= 2) {
var filename = process.argv[2];


p.parseFile(filename, function() {
console.dir(arguments, { depth: null });
p.parseFile(filename, function(result, error) {
if (error) {
console.error(error.message || error);
process.exit(1);
}
delete result.fileBuffer;
const replacer = (key, value) => {
if (value && value.type === 'Buffer' && Array.isArray(value.data)) {
return Buffer.from(value.data).toString('hex');
}
return value;
};
console.log(JSON.stringify(result, replacer, 2));
}).catch(function(err) {
console.error(err.message || err);
process.exit(1);
Comment thread
monkbroc marked this conversation as resolved.
});
23 changes: 23 additions & 0 deletions specs/lib/cli.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var path = require('path');
var { spawnSync } = require('child_process');
Comment thread
monkbroc marked this conversation as resolved.

var CLI = path.resolve(__dirname, '../../cli.js');
var BINARIES = path.resolve(__dirname, '../binaries');

describe('CLI', function () {
it('outputs valid JSON for a valid binary', function () {
var result = spawnSync(process.execPath, [CLI, path.join(BINARIES, 'p2-tinker@5.3.1.bin')]);
var stdout = result.stdout.toString();
var parsed = JSON.parse(stdout);
parsed.should.have.property('prefixInfo');
parsed.should.have.property('suffixInfo');
parsed.should.have.property('crc');
parsed.should.not.have.property('fileBuffer');
});
Comment thread
monkbroc marked this conversation as resolved.

it('exits with code 1 and prints to stderr when file does not exist', function () {
var result = spawnSync(process.execPath, [CLI, 'nonexistent.bin']);
result.status.should.equal(1);
result.stderr.toString().should.match(/doesn't exist/);
});
});
Loading