Skip to content

Commit e4921d1

Browse files
committed
Detect rust by looking at the symbols table.
Some binaries don't include the name directly in strtab, so we need to look at the global functions in the symbols tableand allocate their name to find if they are rust binaries. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 538f93a commit e4921d1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default = ["console_error_panic_hook"]
1616

1717
[dependencies]
1818
wasm-bindgen = "0.2.63"
19-
goblin = { version = "0.2", default-features = false, features = ["elf32", "elf64", "endian_fd"] }
19+
goblin = { version = "0.2", default-features = false, features = ["alloc", "elf32", "elf64", "endian_fd"] }
2020

2121
# The `console_error_panic_hook` crate provides better debugging of panics by
2222
# logging them with `console.error`. This is great for development, but requires

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use goblin::elf::Elf;
1+
use goblin::{elf::sym, elf::Elf};
22

33
mod utils;
44

@@ -49,5 +49,15 @@ pub fn detect(data: &[u8]) -> Result<Option<Runtime>, JsValue> {
4949
}
5050
}
5151

52+
for s in elf.syms.iter() {
53+
if s.is_function() && s.st_bind() == sym::STB_GLOBAL {
54+
if let Some(Ok(sym_name)) = elf.strtab.get(s.st_name) {
55+
if sym_name == RUST_PERSONALITY {
56+
return Ok(Some(Runtime::Rust));
57+
}
58+
}
59+
}
60+
}
61+
5262
Ok(None)
5363
}

0 commit comments

Comments
 (0)