generated from PoCInnovation/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hopefully boolean obfuscation is here making deadcode entrypoints a l…
…ittle more hidden
- Loading branch information
1 parent
863622e
commit e3af8ef
Showing
6 changed files
with
102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use rand::thread_rng; | ||
use rand::Rng; | ||
use tree_sitter::{Tree, TreeCursor}; | ||
use super::Shiftable; | ||
use super::Obfuscator; | ||
|
||
fn get_bools(tree: &Tree) -> Vec<std::ops::Range<usize>> { | ||
fn go(cursor: &mut TreeCursor, bools: &mut Vec<std::ops::Range<usize>>) { | ||
let node = cursor.node(); | ||
if node.kind() == "true" || node.kind() == "false" { | ||
bools.push(node.start_byte()..node.end_byte()); | ||
} | ||
if cursor.goto_first_child() { | ||
go(cursor, bools); | ||
cursor.goto_parent(); | ||
} | ||
while cursor.goto_next_sibling() { | ||
go(cursor, bools); | ||
} | ||
} | ||
let mut bools = Vec::new(); | ||
|
||
go(&mut tree.walk(), &mut bools); | ||
|
||
bools | ||
} | ||
|
||
fn random_args() -> String { | ||
let mut rng = thread_rng(); | ||
let args = rng.gen_range(1..10); | ||
(0..args).map(|_| { | ||
let arg : i32 = rng.gen(); | ||
if rng.gen_bool(0.5) { | ||
arg.to_string() | ||
} else { | ||
format!("\"{}\"", arg) | ||
} | ||
}).collect::<Vec<String>>().join(", ") | ||
} | ||
|
||
fn obfuctated_boolean(val: &str) -> String { | ||
let val = match val { | ||
"True" => format!("thruthy({})", random_args()), | ||
"False" => format!("falsy({})", random_args()), | ||
_ => {dbg!(val); panic!()},//unreachable!(), | ||
}; | ||
return format!("({} {})","not not ".repeat(thread_rng().gen_range(0..2)), val); | ||
} | ||
|
||
impl Obfuscator { | ||
pub fn obfuscate_booleans(&mut self) { | ||
let bools = get_bools(&self.tree); | ||
let mut shift = 0; | ||
|
||
bools.into_iter().for_each(|boolean| { | ||
let boolean = boolean.shift(shift); | ||
let val = &self.code[boolean.clone()]; | ||
shift -= val.len() as i32; | ||
let encoded = obfuctated_boolean(val); | ||
|
||
self.code.replace_range(boolean, &encoded); | ||
shift += encoded.len() as i32; | ||
}); | ||
self.reparse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters