Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Aug 23, 2024
1 parent 9faf86a commit e1861ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $ cattleya -i input -e
start obfuscating input...
obfuscation done!
$ readeld -h input
$ readelf -h input
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Expand Down Expand Up @@ -151,7 +151,7 @@ Hex dump of section '.comment':
Encrypts the name of a specific function with AES 256bit using the given key:

```
$ cargo run -- -i bin/test_64bit --encrypt --encrypt-f fac --encrypt-key foo -o bin/res_enc
$ cattleya -i bin/test_64bit --encrypt --encrypt-f fac --encrypt-key foo -o bin/res_enc
start obfuscating bin/test_64bit...
obfuscation done!
$ ./bin/res_enc
Expand Down
12 changes: 5 additions & 7 deletions src/obfus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Obfuscator {
}

fn is_stripped(&self) -> bool {
self.get_section(".symtab").unwrap().0 == 0
self.get_section(".symtab").is_err()
}

fn v2p(&self, virtual_addr: usize, section: &str) -> usize {
Expand Down Expand Up @@ -341,15 +341,14 @@ impl Obfuscator {
.truncate(true)
.open("/tmp/cattleya_encrypted_function_name")
.map_err(crate::error::Error::CreateFile)?;
let mut writer = aesstream::AesWriter::new(tmp_file, encryptor).unwrap();
writer
aesstream::AesWriter::new(tmp_file, encryptor)
.map_err(crate::error::Error::OpenFile)?
.write_all(function.as_bytes())
.map_err(crate::error::Error::Io)?;

let mut encrypted_function_name = Vec::new();
let mut tmp_file = std::fs::File::open("/tmp/cattleya_encrypted_function_name")
.map_err(crate::error::Error::OpenFile)?;
tmp_file
std::fs::File::open("/tmp/cattleya_encrypted_function_name")
.map_err(crate::error::Error::OpenFile)?
.read_to_end(&mut encrypted_function_name)
.map_err(crate::error::Error::Io)?;

Expand All @@ -359,7 +358,6 @@ impl Obfuscator {
self.output[section_addr + idx..section_addr + idx + function.len()]
.copy_from_slice(&encrypted_function_name);
} else {
let mut encrypted_function_name = encrypted_function_name;
encrypted_function_name.resize(function.len(), 0);
self.output[section_addr + idx..section_addr + idx + function.len()]
.copy_from_slice(&encrypted_function_name);
Expand Down

0 comments on commit e1861ea

Please sign in to comment.