Skip to content

Commit

Permalink
use sha256 as function encrypt key
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Aug 24, 2024
1 parent 1e3d057 commit e75f165
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
78 changes: 78 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ anyhow = "1.0.86"
clap = { version = "4.5.3", features = ["derive"] }
memmap2 = "0.9.4"
rust-crypto = "0.2.36"
sha2 = "0.10.8"
thiserror = "1.0.63"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ $ objdump -d bin/res_enc
1218: 89 7d fc mov %edi,-0x4(%rbp)
121b: 48 89 75 f0 mov %rsi,-0x10(%rbp)
121f: bf 01 00 00 00 mov $0x1,%edi
1224: e8 20 ff ff ff call 1149 <�0,>
1224: e8 20 ff ff ff call 1149 <ӵ�>
1229: bf 01 00 00 00 mov $0x1,%edi
122e: e8 6a ff ff ff call 119d <fib>
1233: bf 05 00 00 00 mov $0x5,%edi
1238: e8 0c ff ff ff call 1149 <�0,>
1238: e8 0c ff ff ff call 1149 <ӵ�>
123d: bf 05 00 00 00 mov $0x5,%edi
1242: e8 56 ff ff ff call 119d <fib>
1247: bf 0a 00 00 00 mov $0xa,%edi
124c: e8 f8 fe ff ff call 1149 <�0,>
124c: e8 f8 fe ff ff call 1149 <ӵ�>
1251: bf 0a 00 00 00 mov $0xa,%edi
1256: e8 42 ff ff ff call 119d <fib>
125b: b8 00 00 00 00 mov $0x0,%eax
Expand Down
14 changes: 4 additions & 10 deletions src/obfus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,10 @@ impl Obfuscator {
}

pub fn encrypt_function_name(&mut self, function: &str, key: &str) -> crate::error::Result<()> {
let mut key_bytes = [0; 32];
if key.len() > 32 {
return Err(crate::error::Error::InvalidOption(
"key length must be less than 32",
));
}
for (i, byte) in key.bytes().enumerate() {
key_bytes[i] = byte;
}
let encryptor = crypto::aessafe::AesSafe256Encryptor::new(&key_bytes);
use sha2::digest::Digest as _;

let hash = sha2::Sha256::digest(key.as_bytes());
let encryptor = crypto::aessafe::AesSafe256Encryptor::new(&hash);

let tmp_file = std::fs::OpenOptions::new()
.read(true)
Expand Down

0 comments on commit e75f165

Please sign in to comment.