orph3usLyre / muddy-waters

A static string obfuscation library for rust projects
Apache License 2.0
73 stars 3 forks source link

could not find `windows` in `os` #19

Closed lovelyjuice closed 4 months ago

lovelyjuice commented 5 months ago

My code on Windows:

use muddy::{m, muddy_init};
muddy_init!();

fn main() {
    println!("{}", m!("My highly obfuscated text"));
    println!("{}", "My non obfuscated static str - ripgrep me");
}

Run cargo build --target x86_64-unknown-linux-musl

error[E0433]: failed to resolve: could not find `windows` in `os`                                                                                              
   --> src\main.rs:2:1
    |
2   | muddy_init!();
    | ^^^^^^^^^^^^^ could not find `windows` in `os`
    |
note: found an item that was configured out
   --> C:\Users\myname\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library/std/src/os/mod.rs:53:9
    |
53  | pub mod windows {}
    |         ^^^^^^^
note: found an item that was configured out
   --> C:\Users\myname\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library/std/src/os/mod.rs:100:9
    |
100 | pub mod windows;
    |         ^^^^^^^
    = note: this error originates in the macro `muddy_init` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0433`.                                                                                            
error: could not compile `test_muddy` (bin "test_muddy") due to 1 previous error    

Expand macros:

pub mod muddy_internal {
    use muddy::{GenericArray, KeyInit, Lazy, ChaCha20Poly1305, Key, Aead, U32, Nonce};
    pub use muddy::{LazyStr, FromHex};
    use std::os::windows::ffi::OsStrExt;

    static KHJU9SXTVNMVXTDQY: &'static [u8; 32] = b"s|i\xbc\xa88\x9et\x18[}\xb1\xbdn\xdfP\xce\xe0\rH\xf47\x9am,{\xa6\xe4\xe2=\x9c\x15";
    static JUNK: &'static [u8; 32] = b"\xff\x89 \x9d!\xb2\x0ef\xb0\x87t)\xf6\x8e\x01\xc8\xee^\xca2:Z\x1a\x1a\x92\xc0\xc7\xc4(\x03I ";
    static PMBKW4TKD2HJK04P8: Lazy<ChaCha20Poly1305> = Lazy::new(|| {
        let mut key = KHJU9SXTVNMVXTDQY.clone();
        key.iter_mut().zip(JUNK.iter()).for_each(|(b, k)| *b ^= k);
        ChaCha20Poly1305::new(Key::from_slice(&key))
    });

    pub fn decrypt(encrypted: &[u8], nonce: &[u8]) -> String {
        let nonce = Nonce::from_slice(nonce);
        let plaintext = PMBKW4TKD2HJK04P8.decrypt(nonce, encrypted).unwrap();
        String::from_utf8(plaintext).unwrap()
    }
}
lovelyjuice commented 5 months ago

Cargo.toml

[package]
name = "test_muddy"
version = "0.1.0"
edition = "2021"

[dependencies]
muddy = "0.2.1"
orph3usLyre commented 4 months ago

Just to make sure I correctly understand the issue - you're trying to build for the linux target x86_64-unknown-linux-musl from a windows box when this compiler error throws?

In that case, this error would make sense since we check the current platform to know which std traits need to be imported. I think this logic can be changed to work with cross-platform use cases - I'll have a look at it over the next week. Thanks! :)

lovelyjuice commented 4 months ago

Yes, that is what I mean. I tried other crates like obfstr and goldberg, they support building linux version on Windows.

orph3usLyre commented 4 months ago

Yes, that is what I mean. I tried other crates like obfstr and goldberg, they support building linux version on Windows.

Can you checkout the branch of this PR and let me know if this solves the issue? #20

lovelyjuice commented 4 months ago

Same error. image

orph3usLyre commented 4 months ago

Hey @lovelyjuice, I believe it should work now :) Let me know if this solves your issue, and if so I'll merge and make a new minor release

lovelyjuice commented 4 months ago

Thank you, it's now working properly!