mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Make base62 project independent, more concise macro definitions.
This commit is contained in:
@@ -3,12 +3,9 @@
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
mod env;
|
||||
mod format_helper;
|
||||
use format_helper::*;
|
||||
|
||||
mod crypt;
|
||||
|
||||
#[allow(dead_code, unused_imports)]
|
||||
mod no_obfuscate;
|
||||
@@ -43,8 +40,6 @@ pub fn junk_asm(input: TokenStream) -> TokenStream {
|
||||
obs::junk_asm(input)
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[proc_macro]
|
||||
pub fn file_symbol(_input: TokenStream) -> TokenStream {
|
||||
// Get the call site span to extract file information
|
||||
@@ -58,70 +53,10 @@ pub fn file_symbol(_input: TokenStream) -> TokenStream {
|
||||
let output = quote! {
|
||||
obfuscate::symbol!(#concatted)
|
||||
};
|
||||
// let output = quote! {
|
||||
// #concatted
|
||||
// };
|
||||
output.into()
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn format_obs(input: TokenStream) -> TokenStream {
|
||||
let PrintlnArgs { format_str, args } = parse_macro_input!(input as PrintlnArgs);
|
||||
|
||||
let segments = parse_format_string(&format_str);
|
||||
|
||||
if segments.is_empty() {
|
||||
return quote! {
|
||||
print!("\n")
|
||||
}
|
||||
.into();
|
||||
}
|
||||
|
||||
let mut parts = Vec::new();
|
||||
|
||||
for segment in segments {
|
||||
match segment {
|
||||
FormatSegment::Static(text) => {
|
||||
parts.push(quote! {
|
||||
obfuscate::symbol!(#text).to_string()
|
||||
});
|
||||
}
|
||||
FormatSegment::Dynamic(spec, idx) => {
|
||||
if idx >= args.len() {
|
||||
return syn::Error::new(
|
||||
proc_macro2::Span::call_site(),
|
||||
format!("argument {} is missing", idx),
|
||||
)
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
let arg = &args[idx];
|
||||
let fmt_spec = if spec.is_empty() {
|
||||
quote! { "{}" }
|
||||
} else {
|
||||
let full_spec = format!("{{{}}}", spec);
|
||||
quote! { #full_spec }
|
||||
};
|
||||
|
||||
// quote! {
|
||||
// println!(#fmt_spec, #arg);
|
||||
// }
|
||||
parts.push(quote! {
|
||||
format!(#fmt_spec, #arg)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(quote! {
|
||||
{
|
||||
let mut string = String::new();
|
||||
#(
|
||||
string.push_str(&#parts);
|
||||
)*
|
||||
string
|
||||
}
|
||||
})
|
||||
.into()
|
||||
format_helper::format_obs(input)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user