Note: Simplifed version of this question: Is it possible to evaluate inner macro before outer macro in proc macro?
I use the bitflags
crate.
One problem of this crate, is that it unconditionally put the flag name inside executable.
For example,
use bitflags::bitflags;
bitflags! {
pub struct Flags: u32 {
const A = 0b00000001;
const B = 0b00000010;
const C = 0b00000100;
}
}
macro expands to
impl ::bitflags::Flags for Flags {
const FLAGS: &'static [::bitflags::Flag<Flags>] = &[
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("A", Flags::A)
},
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("B", Flags::B)
},
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("C", Flags::C)
},
];
}
with the name of bit flags inside executable. ("A", "B", "C")
I do not want these string inside the executable,
which make it easy for reverse engineering.
I know I can make a locally hosted bitflags
,
or just make a feature request to bitflags
But I prefer to have a better universally proc macro that does string obfuscate
that transform all string literal to some not meanful string literal
For example,
#[Obfuscate]
bitflags! {
pub struct Flags: u32 {
const A = 0b00000001;
const B = 0b00000010;
const C = 0b00000100;
}
}
which transforms to
impl ::bitflags::Flags for Flags {
const FLAGS: &'static [::bitflags::Flag<Flags>] = &[
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("foo", Flags::A)
},
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("bar", Flags::B)
},
{
#[allow(deprecated, non_upper_case_globals)]
::bitflags::Flag::new("zzz", Flags::C)
},
];
}
Any idea how to implement this Obfuscate
proc macro,
or is it really possible?
or any existing crate on crates.io?
- The macro should work for any code, not just limited to
bitflags
- The exact pattern how the string to transformed to obfuscate form, is not relavent in this qeustion