Skip to content

Commit

Permalink
Merge branch 'origin/addStringPercentage' into addStringPercentage
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasscharenbroch committed Jan 15, 2024
2 parents 9f0d697 + 8598e4c commit a53b2a4
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 113 deletions.
33 changes: 27 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]
members = [
"auto_obfuscate",
"labyrinth",
"cryptify",
"labyrinth_macros",
]
default-members = ["auto_obfuscate"]
resolver = "2"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Pranav Dronavalli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
237 changes: 236 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,236 @@
# rust-obfuscator
# Rust-Obfuscator

`rust-obfuscator` is a set of tools designed to automatically obfuscate Rust source code by inserting procedural macros or by (optionally) providing the obfuscation in the source code directly. For more fine-grained obfuscation a procedural macro library [cryptify](https://crates.io/crates/cryptify) is also provided.

## Currently Supported
1. string literal encryption
2. control-flow obfuscation
3. control-flow obfuscation (source code)
4. variable renaming (source code)

## Features

- **String Encryption**: Automatically encrypts string literals assigned to local variables at compile time.
- Can also be used for formatted strings, but currently requires manual placement
```rs
println!("{}", cryptify::encrypt_string!("hello!"));
```
- **Control Flow Obfuscation**: Introduces compile-dummy dummy loops and random variables.
- **Customizable Obfuscation**: Offers flexibility to enable or disable specific obfuscation features based on your requirements.
- **Variable Renaming**: Obfuscation of the source code directly, if you'd like to ship the code or just want to make your code look worse.

## Installation

Add `cryptify` to your `Cargo.toml` as a dependency:

```toml
[dependencies]
cryptify = "3.1.0"
```

To install `rust-obfuscator`, clone the repository and build the tool using Cargo from the root:
```
cargo build --release --bin rust-obfuscator
```
The binary can then be found under /target/release, you can copy it to the root of the project like such
```
cp ./target/release/rust-obfuscator .
```

# Usage
Set the **CRYPTIFY_KEY** environment variable for custom encryption otherwise it defaults to defined fixed key
- Add to source code you'd like to modify
```rs
use cryptify;
```
The binary can be used on either a file or a directory. If provided with a directory it will only modify rust source files within that directory not any subdirectories
```sh
./rust-obfuscator path/to/your_project <Options>
```
- All Obfuscated code will be under the **obfuscated_code** directory that is created from the directory the tool was run.
- **Recommended to use a Rust Formatter with the obfuscated code as syn naturally modifies the structure and it will be written to the file as one line**

## Option Flags
- --no_string: Disables string obfuscation.
- --no_flow: Disables control flow obfuscation.
- --disable_macro: Uses direct source manipulation for flow obfuscation instead of procedural macros.
- --var: Enables variable renaming source code obfuscation.

### Example usage with flag
```sh
rust-obfuscator path/to/your_project --no_flow
```
(disables flow obfuscation)

# Input
-running the tool with no config
```rs
use cryptify;
mod word_counter;
use std::env;
use std::fs;
use word_counter::count_words;
fn main() {
let b = "Hello World";
println!("{}", b);
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <filename>", args[0]);
return;
}
let filename = &args[1];
let content = fs::read_to_string(filename).expect("Could not read file");
let word_counts = count_words(&content);
for (word, count) in word_counts.iter() {
println!("{}: {}", word, count);
}
}

fn dummy() {
let a = 1;
let b = 2;
let c = a + b;
println!("{}", c);
}

fn calc_sum(a: i32, b: i32) -> i32 {
cryptify::flow_stmt!();
let c = a + b;
c
}

fn helloooo(){
println!("hi");
}

```
# Output
```rs
fn main() {
cryptify::flow_stmt!();
let b = cryptify::encrypt_string!("Hello World");
println!("{}", b);
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <filename>", args[0]);
return;
}
let filename = &args[1];
let content = fs::read_to_string(filename).expect("Could not read file");
let word_counts = count_words(&content);
for (word, count) in word_counts.iter() {
println!("{}: {}", word, count);
}
}
fn dummy() {
cryptify::flow_stmt!();
let a = 1;
let b = 2;
let c = a + b;
println!("{}", c);
}
fn calc_sum(a: i32, b: i32) -> i32 {
cryptify::flow_stmt!();
let c = a + b;
c
}
fn helloooo() {
println!("hi");
}
```
## Expanded Output
```rs
fn main() {
{
let _is_dummy_145 = true;
let _dummy_upper_bound = 100;
let _random_dummy_var = 1;
let mut _dummy_counter = 6i32;
let _dummy_increment = 2i32;
loop {
if _dummy_counter > _dummy_upper_bound {
break;
}
unsafe {
std::ptr::write_volatile(
&mut _dummy_counter,
_dummy_counter + _dummy_increment,
);
}
}
};
let b = cryptify::decrypt_string("0\u{b}\r\u{1f}\tFd\u{18}\u{11}\t\0");
{
::std::io::_print(format_args!("{0}\n", b));
};
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
{
::std::io::_eprint(format_args!("Usage: {0} <filename>\n", args[0]));
};
return;
}
let filename = &args[1];
let content = fs::read_to_string(filename).expect("Could not read file");
let word_counts = count_words(&content);
for (word, count) in word_counts.iter() {
{
::std::io::_print(format_args!("{0}: {1}\n", word, count));
};
}
}
fn dummy() {
{
let _is_dummy_145 = true;
let mut _dummy_counter = 4i32;
let _dummy_upper_bound = 100;
let _dummy_increment = 3i32;
loop {
if _dummy_counter > _dummy_upper_bound {
break;
}
unsafe {
std::ptr::write_volatile(
&mut _dummy_counter,
_dummy_counter + _dummy_increment,
);
}
}
};
let a = 1;
let b = 2;
let c = a + b;
{
::std::io::_print(format_args!("{0}\n", c));
};
}
fn calc_sum(a: i32, b: i32) -> i32 {
{
let _is_dummy_145 = true;
let mut _dummy_counter = 8i32;
let _dummy_increment = 3i32;
let _extra_dummy_var = 4i32;
let _dummy_upper_bound = 100;
loop {
if _dummy_counter > _dummy_upper_bound {
break;
}
unsafe {
std::ptr::write_volatile(
&mut _dummy_counter,
_dummy_counter + _dummy_increment,
);
}
}
};
let c = a + b;
c
}
fn helloooo() {
{
::std::io::_print(format_args!("hi\n"));
};
}
```
# License
rust-obfuscator is licensed under the MIT License - see the [LICENSE](https://github.com/dronavallipranav/rust-obfuscator/blob/main/LICENSE) file for details.
8 changes: 5 additions & 3 deletions auto_obfuscate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[package]
name = "rust-obfuscator"
version = "0.1.0"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "rust-obfuscator"
path = "src/main.rs"

[dependencies]
syn = { version = "2.0", features = ["full", "visit-mut", "visit"] }
Expand All @@ -12,4 +14,4 @@ proc-macro2 = "1.0"
rand = "0.8.0"
regex = "1.5.4"
clap = "3.0"
labyrinth = { path = "../labyrinth" }
cryptify = "3.1.0"
1 change: 0 additions & 1 deletion auto_obfuscate/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion auto_obfuscate/src/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl VisitMut for FlowObfuscator {
//if use macro enabled, use macro to expand to dummy loop
if self.use_macro {
let macro_call = syn::parse_quote! {
labyrinth::flow_stmt!();
cryptify::flow_stmt!();
};
block.stmts.insert(0, macro_call);
} else {
Expand Down
4 changes: 2 additions & 2 deletions auto_obfuscate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::fs;
fn main() {
//default config
let mut config = Config::default();
let matches = App::new("Rust Obfuscator")
let matches = App::new("Rust Automatic Obfuscator")
.version("1.0")
.author("Your Name")
.author("Pranav Dronavalli")
.about("Obfuscates Rust source code")
.arg(
Arg::with_name("path")
Expand Down
Loading

0 comments on commit a53b2a4

Please sign in to comment.