1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// use proc_macro::TokenStream;
// use quote::quote;
// use syn::{parse_macro_input, Data, DeriveInput, Fields, Ident, Type};
// #[proc_macro_derive(Obfuscate)]
// pub fn derive_obfuscate(input: TokenStream) -> TokenStream {
// let input = parse_macro_input!(input as DeriveInput);
// let name = &input.ident;
// let vis = &input.vis;
// let obf_name = Ident::new(&format!("Obfuscated{}", name), name.span());
// let data = match &input.data {
// Data::Struct(s) => s,
// _ => panic!("Obfuscate can only be derived for structs"),
// };
// let fields = match &data.fields {
// Fields::Named(fields) => &fields.named,
// _ => panic!("Only named fields are supported"),
// };
// let obf_fields = fields.iter().map(|f| {
// let name = &f.ident;
// quote! {
// #name: (Vec<u8>, [u8; 12])
// }
// });
// let clear_args = fields.iter().map(|f| {
// let name = &f.ident;
// let ty = match &f.ty {
// Type::Path(p) if p.path.is_ident("String") => quote! { &str },
// Type::Path(p) if p.path.is_ident("u32") => quote! { u32 },
// _ => quote! { &str },
// };
// quote! { #name: #ty }
// });
// let clear_encrypt = fields.iter().map(|f| {
// let name = &f.ident;
// match &f.ty {
// Type::Path(p) if p.path.is_ident("String") => quote! {
// #name: rust_code_obfuscator::crypto::encrypt_string(#name, AES_KEY)
// },
// Type::Path(p) if p.path.is_ident("u32") => quote! {
// #name: rust_code_obfuscator::crypto::encrypt_u32(#name, AES_KEY)
// },
// _ => quote! {
// #name: rust_code_obfuscator::crypto::encrypt_string(#name, AES_KEY)
// },
// }
// });
// let decrypt_fields = fields.iter().map(|f| {
// let name = &f.ident;
// match &f.ty {
// Type::Path(p) if p.path.is_ident("String") => quote! {
// #name: rust_code_obfuscator::crypto::decrypt_string(&self.#name.0, &self.#name.1, AES_KEY)
// },
// Type::Path(p) if p.path.is_ident("u32") => quote! {
// #name: rust_code_obfuscator::crypto::decrypt_u32(&self.#name.0, &self.#name.1, AES_KEY)
// },
// _ => quote! {
// #name: rust_code_obfuscator::crypto::decrypt_string(&self.#name.0, &self.#name.1, AES_KEY)
// },
// }
// });
// let expanded = quote! {
// use rust_code_obfuscator::crypto::{AES_KEY};
// #[derive(Clone)]
// #vis struct #obf_name {
// #(#obf_fields),*
// }
// impl #obf_name {
// pub fn new_clear(#(#clear_args),*) -> Self {
// Self {
// #(#clear_encrypt),*
// }
// }
// pub fn get_clear(&self) -> #name {
// #name {
// #(#decrypt_fields),*
// }
// }
// }
// };
// TokenStream::from(expanded)
// }