-
Notifications
You must be signed in to change notification settings - Fork 92
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
Feature/sc 118580/binary inspect bundle #642
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4d5d7bb
Update README only for binary module
keeramis b93c59b
Refactor binary inspect command such that it can inspect both pure bi…
keeramis 7a53c11
Remove test files
keeramis 8d895d6
Fix text in tests
keeramis a919a94
minor
keeramis c91bae9
Update BVR to 2.2.0
keeramis cbceafa
lint fix
keeramis 4d02f9d
minor
keeramis 3bd0649
Remove decompress
monkbroc 3de4fee
Simplify binary inspect
monkbroc 53febb9
Fix tests
keeramis 684c2de
Fix tests
keeramis e8705d1
Minor
keeramis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# binary.js | ||
|
||
## Overview | ||
|
||
`binary.js` is a command module in the `particle-cli` tool that provides functionality related to inspecting binary files and/or bundles that may contain binary files and assets. | ||
|
||
## Usage | ||
|
||
To use the `binary.js` command module, you can run the following commands: | ||
|
||
- `particle binary inspect <.bin file>`: Inspects a binary file and displays detailed information such as filename, crc, prefixInfo, suffixInfo, and other relevant metadata. | ||
|
||
- `particle binary inspect <.bin file with baked-in dependencies>`: Inspects a binary file and displays detailed information such as filename, crc, prefixInfo, suffixInfo, and other relevant metadata such as TLV of the (asset) files. | ||
|
||
- `particle binary inspect <.zip file>`: Extracts and inspects contents from the zip file | ||
|
||
## Command-Line Options | ||
|
||
- `--verbose` or `-v`: Increases how much logging to display | ||
|
||
- `--quiet` or `-q`: Decreases how much logging to display | ||
|
||
## Examples | ||
|
||
1. Inspecting a binary file such as tinker.bin: | ||
|
||
``` | ||
particle binary inspect p2_app.bin | ||
|
||
> particle-cli@3.10.2 start | ||
> node ./src/index.js binary inspect /path/to/p2_app.bin | ||
|
||
p2_app.bin | ||
CRC is ok (6e2abf80) | ||
Compiled for p2 | ||
This is an application module number 1 at version 6 | ||
It depends on a system module number 1 at version 5302 | ||
``` | ||
|
||
2. Inspecting a zip file whose app firmware has baked-in asset dependencies: | ||
|
||
``` | ||
$ npm start -- binary inspect /path/to/bundle.zip | ||
|
||
> particle-cli@3.10.2 start | ||
> node ./src/index.js binary inspect /path/to/bundle.zip | ||
|
||
app.bin | ||
CRC is ok (7fa30408) | ||
Compiled for argon | ||
This is an application module number 2 at version 6 | ||
It is firmware for product id 12 at version 3 | ||
It depends on a system module number 1 at version 4006 | ||
It depends on assets: | ||
cat.txt (hash b0f0d8ff8cc965a7b70b07e0c6b4c028f132597196ae9c70c620cb9e41344106) | ||
house.txt (hash a78fb0e7df9977ffd3102395254ae92dd332b46a616e75ff4701e75f91dd60d3) | ||
water.txt (hash 3b0c25d6b8af66da115b30018ae94fbe3f04ac056fa60d1150131128baf8c591) | ||
``` | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
const BinaryCommand = require('../cmd/binary'); | ||
const { expect } = require('../../test/setup'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const { PATH_FIXTURES_THIRDPARTY_OTA_DIR, PATH_FIXTURES_BINARIES_DIR } = require('../../test/lib/env'); | ||
describe('Binary Inspect', () => { | ||
let binaryCommand; | ||
|
||
beforeEach(async () => { | ||
binaryCommand = new BinaryCommand(); | ||
}); | ||
|
||
describe('__checkFile', () => { | ||
it('errors if file does not exist', async () => { | ||
let error; | ||
|
||
try { | ||
await binaryCommand._checkFile('does-not-exist.bin'); | ||
} catch (_error) { | ||
error = _error; | ||
} | ||
|
||
expect(error).to.be.an.instanceof(Error); | ||
expect(error.message).to.equal('File does not exist: does-not-exist.bin'); | ||
}); | ||
|
||
it('returns nothing if file exists', async () => { | ||
let res = false; | ||
try { | ||
res = await binaryCommand._checkFile(path.join(PATH_FIXTURES_BINARIES_DIR, 'argon_stroby.bin')); | ||
} catch (err) { | ||
// ignore error | ||
} | ||
|
||
expect(res).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('_extractFiles', () => { | ||
it('errors if file is not .zip or .bin', async () => { | ||
let error; | ||
|
||
try { | ||
await binaryCommand._extractFiles('not-a-zip-or-bin-file'); | ||
} catch (_error) { | ||
error = _error; | ||
} | ||
|
||
expect(error).to.be.an.instanceof(Error); | ||
expect(error.message).to.equal('File must be a .bin or .zip file: not-a-zip-or-bin-file'); | ||
}); | ||
|
||
it('extracts a .zip file', async () => { | ||
const zipPath = path.join(PATH_FIXTURES_THIRDPARTY_OTA_DIR, 'bundle.zip'); | ||
|
||
const binaryInfo = await binaryCommand._extractFiles(zipPath); | ||
|
||
expect(binaryInfo).to.have.property('application').with.property('name', 'app.bin'); | ||
expect(binaryInfo).to.have.property('assets').with.lengthOf(3); | ||
expect(binaryInfo.assets.map(a => a.name)).to.eql(['cat.txt', 'house.txt', 'water.txt']); | ||
}); | ||
|
||
xit('errors out if the .zip file does not contain a .bin', async () => { | ||
// TODO | ||
}); | ||
|
||
it('extracts a .bin file', async () => { | ||
const binPath = path.join(PATH_FIXTURES_BINARIES_DIR, 'argon_stroby.bin'); | ||
|
||
const binaryInfo = await binaryCommand._extractFiles(binPath); | ||
|
||
expect(binaryInfo).to.have.property('application').with.property('name', 'argon_stroby.bin'); | ||
expect(binaryInfo).to.have.property('assets').with.lengthOf(0); | ||
}); | ||
|
||
it('handles if zip file does not have a binary or assets', async () => { | ||
const zipPath = path.join(PATH_FIXTURES_THIRDPARTY_OTA_DIR, 'invalid-bundle.zip'); | ||
|
||
const binaryInfo = await binaryCommand._extractFiles(zipPath); | ||
|
||
expect(binaryInfo).to.have.property('application').with.property('name', 'app.txt'); | ||
expect(binaryInfo).to.have.property('assets').with.lengthOf(0); | ||
|
||
}); | ||
}); | ||
|
||
describe('_parseApplicationBinary', () => { | ||
it('parses a .bin file', async () => { | ||
const name = 'argon_stroby.bin'; | ||
const data = await fs.readFile(path.join(PATH_FIXTURES_BINARIES_DIR, name)); | ||
const applicationBinary = { name, data }; | ||
|
||
const res = await binaryCommand._parseApplicationBinary(applicationBinary); | ||
|
||
expect(path.basename(res.filename)).to.equal('argon_stroby.bin'); | ||
expect(res.crc.ok).to.equal(true); | ||
expect(res).to.have.property('prefixInfo'); | ||
expect(res).to.have.property('suffixInfo'); | ||
}); | ||
|
||
it('errors if the binary is not valid', async () => { | ||
const applicationBinary = { name: 'junk', data: Buffer.from('junk') }; | ||
|
||
let error; | ||
try { | ||
await binaryCommand._parseApplicationBinary(applicationBinary); | ||
} catch (_error) { | ||
error = _error; | ||
} | ||
|
||
expect(error).to.be.an.instanceof(Error); | ||
expect(error.message).to.match(/Could not parse junk/); | ||
}); | ||
}); | ||
|
||
describe('_verifyBundle', () => { | ||
it('verifies bundle with asset info', async () => { | ||
const zipPath = path.join(PATH_FIXTURES_THIRDPARTY_OTA_DIR, 'bundle.zip'); | ||
const res = await binaryCommand._extractFiles(zipPath); | ||
const parsedBinaryInfo = await binaryCommand._parseApplicationBinary(res.application); | ||
|
||
const verify = await binaryCommand._verifyBundle(parsedBinaryInfo, res.assets); | ||
|
||
expect(verify).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
|
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check what happens without the file existance check for binary inspect on a .bin and on a .zip? If the error is reasonable, remove this function. If not, keep it and remove the comment.