Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde_json = { version = "1.0" }
erased-serde = "0.4"
pyo3 = { version = "0.20", features = ["extension-module"], optional=true}
log = { version = "0.4", optional = true }
wasm-bindgen = "0.2.92"

[dev-dependencies]
criterion = "0.5"
Expand Down
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>Scalpel using WASM</title>
</head>
<body>

<h1>Scalpel using WASM</h1>
<h2>Byte Stream to be dissected</h2>
<p id="byteStream"></p>

<button id="dissectButton">Dissect Packet</button>
<div id="output"></div>

<script type="module">
import init, { dissect_packet } from "./pkg/scalpel.js";

const byteStream = "003096e6fc3900309605283888470001ddff45c0002800030000ff06a4e80a0102010a2200012af90017983210058dd58ea55010102099cd00000000";

async function initialize() {
await init();
showByteStream();
document.getElementById('dissectButton').addEventListener('click', handleDissectClick);
}

function handleDissectClick() {
const result = dissect_packet(byteStream);
document.getElementById('output').innerText = result;
}

function showByteStream() {
document.getElementById('byteStream').innerText = byteStream;
}

window.onload = initialize;
</script>

</body>
</html>
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ pub use types::{ENCAP_TYPE_ETH, ENCAP_TYPE_LINUX_SLL, ENCAP_TYPE_LINUX_SLL2};
#[cfg(feature = "python-bindings")]
use pyo3::prelude::*;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn dissect_packet(packet: String) -> String {
let _ = layers::register_defaults();

let packet = hex::decode(packet);

let packet = packet.unwrap();

let p = Packet::from_bytes(&packet, ENCAP_TYPE_ETH);

let p = p.unwrap();

serde_json::to_string_pretty(&p).unwrap()
}

/// Python bindings for packet dissection and sculpting in Rust (scalpel)
#[cfg(feature = "python-bindings")]
#[pymodule]
Expand Down