mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Obfuscation macros are now defined more easily
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
mod obs_junk_asm;
|
||||
mod obs_xor;
|
||||
mod sym_aes_strings;
|
||||
|
||||
pub use obs_junk_asm::junk_asm;
|
||||
pub use obs_xor::xor;
|
||||
pub use sym_aes_strings::*;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
use base62::{STATIC_IV, encrypt_aes_lines};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{ItemFn, LitStr, parse_macro_input};
|
||||
|
||||
use crate::env::get_encryption_key;
|
||||
|
||||
/// Obfuscate function names by encrypting in AES
|
||||
pub fn aes_fn_name(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
// Parse the input function
|
||||
|
||||
let func = parse_macro_input!(item as ItemFn);
|
||||
|
||||
// Get the original function name
|
||||
let fn_name = func.sig.ident.to_string();
|
||||
|
||||
// Generate the new, obfuscated name
|
||||
let obfuscated_name = encrypt_aes_lines(&fn_name, &get_encryption_key(), STATIC_IV);
|
||||
|
||||
// Create a new string literal for the name
|
||||
let new_name_lit = LitStr::new(&obfuscated_name, func.sig.ident.span());
|
||||
|
||||
// Re-build the function, but add #[no_mangle]
|
||||
// and rename the *exported* symbol via #[export_name]
|
||||
TokenStream::from(quote! {
|
||||
#[unsafe(export_name = #new_name_lit)]
|
||||
#func
|
||||
})
|
||||
}
|
||||
|
||||
/// Obfuscate strings by encrypting in AES
|
||||
pub fn aes_str(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();
|
||||
|
||||
// Generate the exact same obfuscated name
|
||||
let obfuscated_name = encrypt_aes_lines(&original_name, &get_encryption_key(), STATIC_IV);
|
||||
|
||||
// Expand to a static string literal
|
||||
TokenStream::from(quote! {
|
||||
#obfuscated_name
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user