-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add support for C strings #57
Comments
Hi, I've tried to implement it but I'm getting a weird errors:
I'm confused as this should just work the same as the |
Hi, thanks for the time spent on this! I've taken a quick look at the implementation and it looks just fine as-is. Indeed, the example I see you using in the macro's description is: const HELLO_WORLD: &'static CStr = obfcstr!(c"Hello CStr");
assert_eq!(HELLO_WORLD.to_str().unwrap(), "Hello CStr"); (mind the missing and it does not compile, yes. However, note that the following: const X: &'static str = obfstr!("abc");
assert_eq!(X, "abc"); already does not compile either on a very similar error: the macro is called as part of the constant definition, which is probably not what is wanted here. Instead, the following is usually done in order to achieve this case: const X: &'static str = "abc";
assert_eq!(obfstr!(X), "abc"); which should also apply with const Y: &'static CStr = c"xyz";
assert_eq!(obfcstr!(Y).to_str().unwrap(), "xyz"); In tests, |
Oooh, /facepalm. I didn't look close enough at it. PR #58 |
Merged and published |
Cool, thanks! |
With 1.72 adding the
c"..."
literal C string syntax and const support for much ofCStr
's methods, it would be nice if this crate had support for them. As far as I can tell, there is currently no way to have such a literal obfuscated without allocating on the heap. Having a specialized macro, for exampleobfcstr
, should help in this regard. In terms of API, it should probably have everythingobfstr
already has, and only differ in the type of expressions allowed.As an implementation detail, it should probably work well to mimic what
obfstr
already does: passing raw bytes toobfbytes
withstr::to_bytes
and then reconstructing a&str
from its returned value. Here,CStr::to_bytes_with_nul
andCStr::from_bytes_with_nul_unchecked
should fit in just fine.The text was updated successfully, but these errors were encountered: