Skip to content

Commit ea52c82

Browse files
committed
Fixed more linting errors for rust src
1 parent f17c6ca commit ea52c82

File tree

16 files changed

+113
-80
lines changed

16 files changed

+113
-80
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ target/wheels/
5454
.ssh/ssh-agent
5555
.ssh/ssh-agent.pid
5656
.ssh/ssh-agent.env
57-
.DS_Store
57+
.DS_Store
58+
**/.DS_Store

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ pub mod pe;
66
#[cfg(feature = "python")]
77
pub mod python;
88
pub mod utils;
9-

src/packer/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,4 @@ mod tests {
236236

237237
assert!(packer.config().key.is_some());
238238
}
239-
}
239+
}

src/packer/encryption.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use aes::Aes128;
2-
use cbc::{Encryptor as Aes128CbcEnc, Decryptor as Aes128CbcDec};
3-
use cbc::cipher::{KeyIvInit, block_padding::Pkcs7, BlockEncryptMut, BlockDecryptMut};
2+
use cbc::cipher::{block_padding::Pkcs7, BlockDecryptMut, BlockEncryptMut, KeyIvInit};
3+
use cbc::{Decryptor as Aes128CbcDec, Encryptor as Aes128CbcEnc};
44
use rand::Rng;
55

66
/// Encryption algorithms supported by the packer
@@ -170,7 +170,7 @@ mod tests {
170170

171171
assert!(high_entropy > low_entropy);
172172
assert!(high_entropy > 7.0); // Random data should have ~8 bits of entropy
173-
assert!(low_entropy < 1.0); // Repeated data should have very low entropy
173+
assert!(low_entropy < 1.0); // Repeated data should have very low entropy
174174
}
175175

176176
#[test]
@@ -184,4 +184,4 @@ mod tests {
184184
let none_key = generate_key(EncryptionAlgorithm::None);
185185
assert!(none_key.is_empty());
186186
}
187-
}
187+
}

src/packer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ pub use encryption::EncryptionAlgorithm;
99
pub use stub_generator::StubGenerator;
1010

1111
// Re-export for convenience
12+
pub use crate::pe::builder::PEBuilder;
1213
pub use crate::pe::parser::PEParser;
13-
pub use crate::pe::builder::PEBuilder;

src/packer/stub_generator.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rand::Rng;
21
use super::encryption::EncryptionAlgorithm;
2+
use rand::Rng;
33

44
/// Generates decryption stubs for packed executables
55
pub struct StubGenerator {
@@ -120,14 +120,14 @@ impl StubGenerator {
120120
stub.extend_from_slice(b"XOR_DECRYPTION_ROUTINE");
121121
// In a real implementation, this would contain actual x86/x64 assembly
122122
// for XOR decryption
123-
},
123+
}
124124
EncryptionAlgorithm::Aes => {
125125
stub.extend_from_slice(b"AES_DECRYPTION_ROUTINE");
126126
// AES decryption assembly would go here
127-
},
127+
}
128128
EncryptionAlgorithm::None => {
129129
stub.extend_from_slice(b"NO_DECRYPTION_NEEDED");
130-
},
130+
}
131131
}
132132

133133
stub.extend_from_slice(b"DECRYPT_LOGIC_END");
@@ -149,7 +149,7 @@ impl StubGenerator {
149149

150150
/// Generate a unique stub ID for tracking
151151
pub fn generate_stub_id(&self) -> String {
152-
use sha2::{Sha256, Digest};
152+
use sha2::{Digest, Sha256};
153153

154154
let mut hasher = Sha256::new();
155155
hasher.update(&self.key);
@@ -163,7 +163,11 @@ impl StubGenerator {
163163
pub fn estimate_stub_size(&self) -> usize {
164164
let base_size = 64; // Header, flags, etc.
165165
let anti_debug_size = if self.config.add_anti_debug { 128 } else { 0 };
166-
let metadata_size = if self.config.add_benign_metadata { 256 } else { 0 };
166+
let metadata_size = if self.config.add_benign_metadata {
167+
256
168+
} else {
169+
0
170+
};
167171
let padding_size = 40; // Average padding
168172

169173
base_size + anti_debug_size + metadata_size + padding_size
@@ -233,4 +237,4 @@ mod tests {
233237
// Should contain AES marker
234238
assert!(stub_str.contains("AES"));
235239
}
236-
}
240+
}

src/pe/builder.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ impl<'a> PEBuilder<'a> {
268268
),
269269
size_of_raw_data: stub.len() as u32,
270270
pointer_to_raw_data: current_offset,
271-
characteristics: IMAGE_SCN_CNT_CODE
272-
| IMAGE_SCN_MEM_EXECUTE
273-
| IMAGE_SCN_MEM_READ,
271+
characteristics: IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ,
274272
..Default::default()
275273
};
276274

@@ -330,10 +328,8 @@ impl<'a> PEBuilder<'a> {
330328
fn pad_to_alignment(&self, output: &mut Vec<u8>, alignment: u32) -> Result<(), PackerError> {
331329
let current_size = output.len() as u32;
332330
let aligned_size = Self::align_value(current_size, alignment);
333-
let padding = aligned_size - current_size;
334-
335-
if padding > 0 {
336-
output.extend(vec![0u8; padding as usize]);
331+
if aligned_size > current_size {
332+
output.resize(aligned_size as usize, 0u8);
337333
}
338334

339335
Ok(())
@@ -421,4 +417,4 @@ mod tests {
421417
fn test_file_alignment() {
422418
assert_eq!(PEBuilder::get_file_alignment(), 0x200);
423419
}
424-
}
420+
}

src/pe/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! PE file parsing and building functionality
22
3-
pub mod parser;
43
pub mod builder;
4+
pub mod parser;
55
mod structures;
66

7-
pub use parser::PEParser;
87
pub use builder::PEBuilder;
9-
pub use structures::*;
8+
pub use parser::PEParser;
9+
pub use structures::*;

src/pe/parser.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use goblin::pe::PE;
21
use crate::utils::error::PackerError;
32
use goblin::pe::characteristic::IMAGE_FILE_DLL;
3+
use goblin::pe::PE;
44

55
pub struct PEParser<'a> {
66
pe: PE<'a>,
@@ -20,19 +20,22 @@ impl<'a> PEParser<'a> {
2020
pub fn extract_section_data<'b>(
2121
&self,
2222
section: &goblin::pe::section_table::SectionTable,
23-
buffer: &'b [u8]
23+
buffer: &'b [u8],
2424
) -> &'b [u8] {
2525
let start = section.pointer_to_raw_data as usize;
2626
let size = section.size_of_raw_data as usize;
27-
if start >= buffer.len() { return &buffer[0..0]; }
27+
if start >= buffer.len() {
28+
return &buffer[0..0];
29+
}
2830
let end = start.saturating_add(size).min(buffer.len());
2931
&buffer[start..end]
3032
}
3133

3234
pub fn entry_point(&self) -> u32 {
3335
// goblin exposes optional_header as Option<OptionalHeader>
3436
// address_of_entry_point is in standard_fields
35-
(self.pe
37+
(self
38+
.pe
3639
.header
3740
.optional_header
3841
.as_ref()
@@ -46,15 +49,23 @@ impl<'a> PEParser<'a> {
4649

4750
// Helper: raw DOS header bytes (first 64 bytes)
4851
pub fn get_dos_header(&self) -> Option<&[u8]> {
49-
if self.data.len() >= 64 { Some(&self.data[..64]) } else { None }
52+
if self.data.len() >= 64 {
53+
Some(&self.data[..64])
54+
} else {
55+
None
56+
}
5057
}
5158

5259
// Helper: raw COFF header bytes (20 bytes at e_lfanew + 4)
5360
pub fn get_coff_header(&self) -> Option<&[u8]> {
5461
let pe_off = self.read_u32_le(0x3C)? as usize;
5562
let start = pe_off.checked_add(4)?;
5663
let end = start.checked_add(20)?;
57-
if end <= self.data.len() { Some(&self.data[start..end]) } else { None }
64+
if end <= self.data.len() {
65+
Some(&self.data[start..end])
66+
} else {
67+
None
68+
}
5869
}
5970

6071
// Helper: raw Optional header bytes (size given in COFF header at offset +16, u16)
@@ -66,7 +77,11 @@ impl<'a> PEParser<'a> {
6677
} else { return None };
6778
let opt_start = coff_start.checked_add(20)?;
6879
let opt_end = opt_start.checked_add(size_opt)?;
69-
if opt_end <= self.data.len() { Some(&self.data[opt_start..opt_end]) } else { None }
80+
if opt_end <= self.data.len() {
81+
Some(&self.data[opt_start..opt_end])
82+
} else {
83+
None
84+
}
7085
}
7186

7287
pub fn section_count(&self) -> usize {
@@ -85,4 +100,4 @@ impl<'a> PEParser<'a> {
85100
None
86101
}
87102
}
88-
}
103+
}

src/pe/structures.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use serde::{Serialize, Deserialize};
1+
use serde::{Deserialize, Serialize};
22

33
#[derive(Debug, Clone, Serialize, Deserialize)]
44
pub struct DOSHeader {
@@ -44,4 +44,4 @@ pub struct PEFile {
4444
pub nt_headers: NTHeaders,
4545
pub sections: Vec<SectionHeader>,
4646
pub data: Vec<u8>,
47-
}
47+
}

0 commit comments

Comments
 (0)