Skip to content
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

wsh: invalid lua syntax from mangled symbols #24

Open
sp3d opened this issue Jun 2, 2017 · 4 comments
Open

wsh: invalid lua syntax from mangled symbols #24

sp3d opened this issue Jun 2, 2017 · 4 comments

Comments

@sp3d
Copy link

sp3d commented Jun 2, 2017

Running wsh on binaries with non-alphanumeric symbols (e.g. the mangled ones produced by rustc) results in output like

ERROR: Wsh internal lua initialization (Synthax Error): Wsh internal lua buffer:2070: '(' expected near '$'

which refers to this line in the generated lua:

function _ZN4core3num68_$LT$impl$u20$core..convert..TryFrom$LT$i16$GT$$u20$for$u20$u128$GT$8try_from17h890e52784dfa2181E (a, b, c, d, e, f, g, h) j,k = libcall(reflect__ZN4core3num68_$LT$impl$u20$core..convert..TryFrom$LT$i16$GT$$u20$for$u20$u128$GT$8try_from17h890e52784dfa2181E, a, b, c, d, e, f, g, h); return j, k; end

It might be nice to support demangling, though that may complicate parsing (angle brackets, parentheses, and colons would be valid in symbol names); in any event it would be nice for these symbols to not prevent wsh from running.

@endrazine
Copy link
Owner

Hi sp3d,
Very cool finding ! May I ask you to share a minimal sample code to reproduce ? I'm unsure if demangling in rust follows the same rules as in cpp. If so, should be not too hard to fix :)

@sp3d
Copy link
Author

sp3d commented Jun 3, 2017

This happens even with a hello-world compiled with rustc:

fn main() {println!("Hello, world!")}

Rust symbol-mangling rules aren't stable or formally specified, but roughly coincide with C++ mangling. The implementation lives here: https://github.com/rust-lang/rust/blob/master/src/librustc_trans/back/symbol_names.rs

@endrazine
Copy link
Owner

Hi sp3d,
Do you happen to know if I may demangle rust symbols using libiberty ?
Thanks and regards,
j-

@sp3d
Copy link
Author

sp3d commented Jun 18, 2019

Rust has an old "legacy" mangling scheme that mostly follows C++ rules, and a new scheme that works much better for the needs of Rust symbols. Both are supported by the rustc-demangle crate.

That said, it may be easiest for now to simply make wsh escape symbols somehow so that it doesn't rely on being able to demangle them. Binaries created by more arcane toolchains (e.g. malware) are likely to have unprintable and undemangleable symbol names, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants