mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Obfuscation macros are now defined more easily
This commit is contained in:
@@ -3,7 +3,7 @@ use quote::quote;
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
use syn::{Expr, Lit, Token, parse_macro_input};
|
||||
|
||||
pub fn format_obs(input: TokenStream) -> TokenStream {
|
||||
pub fn sym_format(input: TokenStream) -> TokenStream {
|
||||
let PrintlnArgs { format_str, args } = parse_macro_input!(input as PrintlnArgs);
|
||||
|
||||
let segments = parse_format_string(&format_str);
|
||||
@@ -21,7 +21,7 @@ pub fn format_obs(input: TokenStream) -> TokenStream {
|
||||
match segment {
|
||||
FormatSegment::Static(text) => {
|
||||
parts.push(quote! {
|
||||
obfuscate::symbol!(#text).to_string()
|
||||
obfuscate::sym!(#text).to_string()
|
||||
});
|
||||
}
|
||||
FormatSegment::Dynamic(spec, idx) => {
|
||||
|
||||
+20
-23
@@ -1,43 +1,40 @@
|
||||
#![feature(proc_macro_quote)]
|
||||
#![feature(proc_macro_span)]
|
||||
#![allow(dead_code, unused_macros, unused_imports)]
|
||||
|
||||
mod env;
|
||||
mod format_helper;
|
||||
mod proc_impl_switcher;
|
||||
|
||||
mod obfuscate;
|
||||
|
||||
// Types of symbolic reference
|
||||
mod symbolic_aes;
|
||||
mod symbolic_ref;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
mod env;
|
||||
mod format_helper;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
mod no_obfuscate;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
mod obfuscate;
|
||||
|
||||
#[cfg(not(feature = "obfuscate"))]
|
||||
use no_obfuscate as obs;
|
||||
#[cfg(feature = "obfuscate")]
|
||||
use obfuscate as obs;
|
||||
|
||||
// String obfuscation
|
||||
use proc_impl_switcher::proc_impl;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn obs(input: TokenStream) -> TokenStream {
|
||||
obs::xor(input)
|
||||
proc_impl::xor(input)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn obfuscated_symbol(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
obs::aes_fn_name(_attr, item)
|
||||
pub fn sym_fn(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
proc_impl::sym_fn(item)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn symbol(input: TokenStream) -> TokenStream {
|
||||
obs::aes_str(input)
|
||||
pub fn sym(input: TokenStream) -> TokenStream {
|
||||
proc_impl::sym(input)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn junk_asm(input: TokenStream) -> TokenStream {
|
||||
obs::junk_asm(input)
|
||||
proc_impl::junk_asm(input)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
@@ -57,6 +54,6 @@ pub fn file_symbol(_input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn format_obs(input: TokenStream) -> TokenStream {
|
||||
format_helper::format_obs(input)
|
||||
pub fn sym_format(input: TokenStream) -> TokenStream {
|
||||
format_helper::sym_format(input)
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{ItemFn, LitStr, parse_macro_input};
|
||||
|
||||
pub fn xor(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as LitStr);
|
||||
|
||||
(quote::quote! {
|
||||
String::from(#input)
|
||||
})
|
||||
.into()
|
||||
}
|
||||
pub fn aes_fn_name(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let func = parse_macro_input!(item as ItemFn);
|
||||
TokenStream::from(quote! {
|
||||
#[unsafe(no_mangle)]
|
||||
#func
|
||||
})
|
||||
}
|
||||
|
||||
pub fn aes_str(input: TokenStream) -> TokenStream {
|
||||
input
|
||||
}
|
||||
|
||||
pub fn junk_asm(_input: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
@@ -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::*;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/// Call some other function
|
||||
macro_rules! passtrough {
|
||||
($name:tt, $ref:expr) => {
|
||||
pub fn $name(input: TokenStream) -> TokenStream {
|
||||
$ref(input)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Just return the underlying string
|
||||
macro_rules! unwrap_string {
|
||||
($func:tt) => {
|
||||
pub fn $func(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as LitStr);
|
||||
|
||||
(quote::quote! {
|
||||
#input
|
||||
})
|
||||
.into()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Delete the content
|
||||
macro_rules! delete {
|
||||
($func:tt) => {
|
||||
pub fn $func(_: TokenStream) -> TokenStream {
|
||||
(quote::quote! {}).into()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "obfuscate_none")]
|
||||
pub mod proc_impl {
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{LitStr, parse_macro_input};
|
||||
|
||||
unwrap_string!(xor);
|
||||
delete!(junk_asm);
|
||||
|
||||
unwrap_string!(sym);
|
||||
unwrap_string!(sym_fn);
|
||||
}
|
||||
|
||||
#[cfg(feature = "obfuscate_aes")]
|
||||
pub mod proc_impl {
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
passtrough!(xor, crate::obfuscate::xor);
|
||||
passtrough!(junk_asm, crate::obfuscate::junk_asm);
|
||||
|
||||
passtrough!(sym, crate::symbolic_aes::aes_str);
|
||||
passtrough!(sym_fn, crate::symbolic_aes::aes_fn_name);
|
||||
}
|
||||
|
||||
#[cfg(feature = "obfuscate_ref")]
|
||||
pub mod proc_impl {
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{LitStr, parse_macro_input};
|
||||
|
||||
unwrap_string!(xor);
|
||||
delete!(junk_asm);
|
||||
|
||||
unwrap_string!(sym);
|
||||
unwrap_string!(sym_fn);
|
||||
}
|
||||
@@ -6,9 +6,8 @@ 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 {
|
||||
pub fn aes_fn_name(item: TokenStream) -> TokenStream {
|
||||
// Parse the input function
|
||||
|
||||
let func = parse_macro_input!(item as ItemFn);
|
||||
|
||||
// Get the original function name
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user