mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Add refrerence symbolic strings
This commit is contained in:
@@ -2,8 +2,10 @@ const ENV_KEY_NAME: &str = "OBFUSCATION_KEY";
|
||||
const BACKUP_ENV_KEY: &str = "OBFUSCATION_KEY_DO_NOT_USE";
|
||||
|
||||
pub fn get_encryption_key() -> String {
|
||||
std::env::var(ENV_KEY_NAME).unwrap_or({
|
||||
if let Ok(key) = std::env::var(ENV_KEY_NAME) {
|
||||
key
|
||||
} else {
|
||||
println!("Using default encryption key!");
|
||||
BACKUP_ENV_KEY.to_owned()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ pub fn xor(input: TokenStream) -> TokenStream {
|
||||
return TokenStream::from(quote! { String::new() });
|
||||
}
|
||||
|
||||
// --- Obfuscated Branch Logic ---
|
||||
// This code runs at compile-time
|
||||
|
||||
let str_bytes = original_str.as_bytes();
|
||||
let len = str_bytes.len();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ macro_rules! delete {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "obfuscate_none")]
|
||||
#[cfg(all(not(feature = "obfuscate_aes"), not(feature = "obfuscate_ref")))]
|
||||
pub mod proc_impl {
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{LitStr, parse_macro_input};
|
||||
@@ -61,6 +61,6 @@ pub mod proc_impl {
|
||||
unwrap_string!(xor);
|
||||
delete!(junk_asm);
|
||||
|
||||
unwrap_string!(sym);
|
||||
passtrough!(sym, crate::symbolic_ref::sym_ref);
|
||||
unwrap_string!(sym_fn);
|
||||
}
|
||||
|
||||
@@ -1 +1,48 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base62::{Base62, hash};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{LitStr, parse_macro_input};
|
||||
|
||||
use crate::env::get_encryption_key;
|
||||
|
||||
static mut SYM_COUNTER: Vec<String> = Vec::new();
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
pub fn get_symbol_number() -> usize {
|
||||
unsafe { SYM_COUNTER.len() }
|
||||
}
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
pub fn get_symbol(text: String) -> usize {
|
||||
unsafe {
|
||||
if let Some(n) = SYM_COUNTER.iter().position(|r| r == &text) {
|
||||
n
|
||||
} else {
|
||||
SYM_COUNTER.push(text);
|
||||
|
||||
SYM_COUNTER.len() - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sym_ref(input: TokenStream) -> TokenStream {
|
||||
// Parse the input as a string literal
|
||||
let lit_str = parse_macro_input!(input as LitStr);
|
||||
let original_name = lit_str.value();
|
||||
|
||||
let n = get_symbol(original_name);
|
||||
|
||||
let data = base62::encode_usize(n);
|
||||
let key = hash(&get_encryption_key().as_bytes());
|
||||
|
||||
let encoded = format!("_{}_", Base62::encode_full(&data, &key));
|
||||
|
||||
println!("Aliased '{}' as '{encoded}'", lit_str.value());
|
||||
|
||||
// Expand to a static string literal
|
||||
TokenStream::from(quote! {
|
||||
#encoded
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user