-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/cli commands and options (#15)
* refactor(cli)!: Remove nothing injection. Add inject and decode subcommads Signed-off-by: Maksim Dimitrov <[email protected]> * chore(tests): Remove stack_limiter tests Signed-off-by: Maksim Dimitrov <[email protected]> * refactor(cli): Fix naming when no destination file is passed Signed-off-by: Maksim Dimitrov <[email protected]> * ci: Add github workflow for crago test, fmt, clippy Signed-off-by: Maksim Dimitrov <[email protected]> * chore(cargo): Update clap version Signed-off-by: Maksim Dimitrov <[email protected]> * Make the julia script to execute tests for a specific host only Signed-off-by: Maksim Dimitrov <[email protected]> * refactor(cli): Rename Decode to Convert. Add convert options Signed-off-by: Maksim Dimitrov <[email protected]> * Update the workflow Signed-off-by: Maksim Dimitrov <[email protected]> * ci: Trigger zombienet workflow on changes to tests or main.taml Signed-off-by: Maksim Dimitrov <[email protected]> * chore(cli): Update help messages Signed-off-by: Maksim Dimitrov <[email protected]> * ci: Remove base_ref check Signed-off-by: Maksim Dimitrov <[email protected]> * chore(readme): Update readme Signed-off-by: Maksim Dimitrov <[email protected]> * chore(readme): Update folder name Signed-off-by: Maksim Dimitrov <[email protected]> --------- Signed-off-by: Maksim Dimitrov <[email protected]>
- Loading branch information
1 parent
4ff10a7
commit 4bf9152
Showing
10 changed files
with
379 additions
and
161 deletions.
There are no files selected for viewing
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,61 @@ | ||
name: Rust | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
|
||
fmt: | ||
name: Rustfmt | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- run: rustup component add rustfmt | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --all -- --check | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- run: rustup component add clippy | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: -- -D warnings |
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 |
---|---|---|
@@ -1,66 +1,120 @@ | ||
# wasm-injector | ||
# wasm_injector | ||
|
||
`wasm-injector` is a Rust-based command line utility to manipulate WebAssembly (wasm) modules. It allows you to inject code, compress, and hexify a given wasm module. This utility is especially useful when you need to modify wasm files for testing, optimization, or debugging. | ||
`wasm_injector` is a Rust-based command line utility to manipulate WebAssembly (wasm) modules. It allows you to inject code, compress, and hexify a given wasm module. This utility is especially useful when you need to modify wasm files for testing, optimization, or debugging. | ||
|
||
## Prerequisites | ||
## Prerequisites | ||
|
||
To use this utility, you need to have Rust installed on your system. If you don't have Rust installed, you can follow the official instructions [here](https://www.rust-lang.org/tools/install). | ||
To use this utility, you need to have Rust installed on your system. If you don't have Rust installed, you can follow the official instructions [here](https://www.rust-lang.org/tools/install). | ||
|
||
## Installation | ||
## Installation | ||
|
||
Clone the repository and build the project with `cargo`, Rust's package manager: | ||
Clone the repository and build the project with `cargo`, Rust's package manager: | ||
|
||
```sh | ||
git clone https://github.com/your_github_username/wasm-injector.git | ||
cd wasm-injector | ||
cargo build --release | ||
``` | ||
```sh | ||
git clone https://github.com/LimeChain/parachain-conformance-dev.git | ||
cd parachain-conformance-dev | ||
cargo build --release | ||
``` | ||
|
||
This will create an executable in the `target/release` directory. | ||
This will create an executable in the `target/release` directory. | ||
|
||
## Usage | ||
- This project is developed to inject instructions in WASM modules or polkadot conformance testing. You can download a sample WASM file from [here](https://github.com/paritytech/cumulus/releases/tag/parachains-v9430). | ||
- The script will automatically unhexify and decompress WASM modules passed in as input | ||
- The general format to run the `wasm-injector` is as follows: | ||
## Usage | ||
- This project is developed to inject instructions in WASM modules or polkadot conformance testing. You can download a sample WASM file from [here](https://github.com/paritytech/cumulus/releases/tag/parachains-v9430). | ||
- The script will automatically unhexify and decompress WASM modules passed in as input | ||
- The general format to run the `wasm_injector` is as follows: | ||
|
||
```sh | ||
./wasm-injector [INJECTION] [SOURCE] [DESTINATION] [--compressed] [--hexified] | ||
``` | ||
```sh | ||
Usage: wasm_injector <COMMAND> | ||
|
||
- `[INJECTION]` (required): The type of injection to apply to the wasm module. Possible values ```possible values: [nothing, infinite-loop, jibberish-return-value, stack-overflow, noops, heap-overflow]``` | ||
Commands: | ||
inject Inject invalid instructions into a wasm module | ||
convert Convert from `hexified` and/or `compressed` to `raw` wasm module and vice versa | ||
help Print this message or the help of the given subcommand(s) | ||
|
||
- `[SOURCE]` (required): A path to the wasm source file. If the wasm module is compressed or hexified, indicate this in the path name as "(hexified)" and/or "(compressed)". | ||
Options: | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` | ||
|
||
- `[DESTINATION]` (optional): A path where you want the output wasm file to be saved. If this argument is not provided, the modified wasm file will be saved alongside the source file with a predefined file name. | ||
### Inject: | ||
```sh | ||
Usage: wasm_injector inject [OPTIONS] <injection> <SOURCE> [DESTINATION] | ||
|
||
- `--compressed` (optional): If this flag is provided, the output file will be compressed. | ||
Arguments: | ||
<injection> [possible values: infinite-loop, bad-return-value, stack-overflow, noops, heap-overflow] | ||
<SOURCE> Wasm source file path. Can be compressed and/or hexified. | ||
[DESTINATION] Destination file path (optional). If not specified, the output file will be a prefixed source file name. | ||
|
||
- `--hexified` (optional): If this flag is provided, the output file will be hexified (converted to a hexadecimal representation). | ||
Options: | ||
--compressed Compresses the wasm. Can be used with `--hexified` | ||
--hexified Hexifies the wasm. Can be used with `--compressed` | ||
-h, --help Print help | ||
``` | ||
|
||
### Convert: | ||
```sh | ||
Usage: wasm_injector convert [OPTIONS] <SOURCE> [DESTINATION] | ||
|
||
Arguments: | ||
<SOURCE> Wasm source file path. Can be compressed and/or hexified. | ||
[DESTINATION] Destination file path (optional). If not specified, the output file will be a prefixed source file name. | ||
|
||
Options: | ||
--raw Saves the file as raw wasm (default). Can not be used with `--compressed` or `--hexified`. | ||
--compressed Compresses the wasm (zstd compression). Can be used with `--hexified`. | ||
--hexified Hexifies the wasm. Can be used with `--compressed` | ||
-h, --help Print help | ||
``` | ||
|
||
## Examples | ||
|
||
To inject code into a wasm file, compress and hexify it, you can run: | ||
### Inject: | ||
To inject code into a wasm file, compress and hexify it, you can run: | ||
|
||
```sh | ||
./wasm_injector inject noops my_wasm_file.wasm --compressed --hexified | ||
``` | ||
|
||
To specify a custom destination path, you can run: | ||
|
||
```sh | ||
./wasm_injector inject noops my_wasm_file.wasm my_destination_directory/injected_new_file.wasm | ||
``` | ||
|
||
### Convert: | ||
|
||
#### From Compressed and/or Hexified Wasm to Raw (default): | ||
```sh | ||
./wasm_injector convert --raw compressed_and_hexified_wasm_file.wasm.hex raw_wasm_file.wasm | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
./wasm_injector convert compressed_and_hexified_wasm_file.wasm.hex raw_wasm_file.wasm | ||
``` | ||
|
||
#### From Raw Wasm to Compressed and/or Hexified: | ||
|
||
```sh | ||
./wasm_injector convert --hexified raw_wasm_file.wasm heified_wasm_file.wasm.hex | ||
``` | ||
|
||
```sh | ||
./wasm_injector convert --compressed --hexified raw_wasm_file.wasm compressed_and_hexified_wasm_file.wasm.hex | ||
``` | ||
|
||
```sh | ||
./wasm-injector noops my_wasm_file.wasm --compressed --hexified | ||
``` | ||
To run the WASM you need Linux environment with [Zombienet](https://github.com/paritytech/zombienet) | ||
For each test you need to specify the path to the WASM module in the corresponding `.toml` file before running the test | ||
|
||
To specify a custom destination path, you can run: | ||
```sh | ||
zombienet -p native test ./tests/0001-parachains-pvf-compilation-time-bad.zndsl | ||
``` | ||
|
||
```sh | ||
./wasm-injector noops my_wasm_file.wasm my_destination_directory/my_new_file.wasm | ||
``` | ||
To run the WASM you need Linux environment with [Zombienet](https://github.com/paritytech/zombienet) | ||
For each test you need to specify the path to the WASM module in the corresponding `.toml` file before running the test | ||
|
||
```sh | ||
zombienet -p native test ./tests/0001-parachains-pvf-compilation-time-bad.zndsl | ||
``` | ||
|
||
## Contributing | ||
## Contributing | ||
|
||
Please feel free to contribute to the project. For major changes, please open an issue first to discuss what you would like to change. | ||
Please feel free to contribute to the project. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
## License | ||
## License | ||
|
||
This project is licensed under [TODO]. See the LICENSE file for details. | ||
This project is licensed under [TODO]. See the LICENSE file for details. |
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
Oops, something went wrong.