ystero-dev / scalpel

Packet Dissection and sculpting in Rust
Other
3 stars 6 forks source link

Adding WASM support #64

Open csking101 opened 5 months ago

csking101 commented 5 months ago

Referencing #61

We had discussed about whether our crate can support WASM. This PR creates a demonstration of the same.

Instructions to run

  1. Firstly, you need to have wasm-pack installed. It can be found here. Simply run cargo install wasm-pack. This is used to create the WASM files based on our target (which in this case is the web). It also has the potential to create WASM files for different targets as well such as NodeJS.
  2. Next, you must create the WASM file. This can be done by running wasm-pack build --target web. It will create WASM binaries in ./pkg/.
  3. Finally, we must have index.html served by a simple Python server to avoid CORS issues. This can be done by running python -m http.server in the same directory as index.html.
  4. Go to the URL given by the Python server as you should see a simple HTML page like this: image
  5. Click the Dissect Packet button to see this: image

My Analysis

More areas to look into

Further Resources

gabhijit commented 5 months ago

@csking101 : This is a great start. Thanks a lot!!

I am wondering whether it's a good idea to actually capture this into a GH discussion. Let's keep the PR open, so that it allows us to iterate, but essential discussions should be captured in discussions (because PRs once closed or merged, those discussions get kind of lost.)

I quickly looked at the cargo test --target wasm32-unknown-unknown issue. This is because of the errno dependency, which is due to pcap dev-dependency (required for examples). So we may have to wrap that into two separate feature (say wasm and pcap). And then do a cargo test per feature. I will take a shot at this. Is that cool?

csking101 commented 5 months ago

Sure sir, that sounds great!

Also, I think we can continue in the discussions about what functions will be WASM supported, as you said, they have can different features for the same. It'll be better to segregate the two at this stage I believe.

gabhijit commented 5 months ago

Parts of this PR are merged with merge of #66 . Thank you for your contribution.

We can keep this PR open or move some relevant links, information to the Discussions page.