-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #796 from ReFirmLabs/gpg_decompress
Fixed signed GPG decompression bug
- Loading branch information
Showing
4 changed files
with
62 additions
and
5 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,57 @@ | ||
use crate::extractors::common::{ExtractionResult, Extractor, ExtractorType}; | ||
use crate::extractors::inflate; | ||
|
||
/// Defines the internal extractor function for decompressing signed GPG data | ||
/// | ||
/// ``` | ||
/// use std::io::ErrorKind; | ||
/// use std::process::Command; | ||
/// use binwalk::extractors::common::ExtractorType; | ||
/// use binwalk::extractors::gpg::gpg_extractor; | ||
/// | ||
/// match gpg_extractor().utility { | ||
/// ExtractorType::None => panic!("Invalid extractor type of None"), | ||
/// ExtractorType::Internal(func) => println!("Internal extractor OK: {:?}", func), | ||
/// ExtractorType::External(cmd) => { | ||
/// if let Err(e) = Command::new(&cmd).output() { | ||
/// if e.kind() == ErrorKind::NotFound { | ||
/// panic!("External extractor '{}' not found", cmd); | ||
/// } else { | ||
/// panic!("Failed to execute external extractor '{}': {}", cmd, e); | ||
/// } | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
pub fn gpg_extractor() -> Extractor { | ||
Extractor { | ||
utility: ExtractorType::Internal(gpg_decompress), | ||
..Default::default() | ||
} | ||
} | ||
|
||
/// Internal extractor for decompressing signed GPG data | ||
pub fn gpg_decompress( | ||
file_data: &[u8], | ||
offset: usize, | ||
output_directory: Option<&String>, | ||
) -> ExtractionResult { | ||
// Size of the GPG header | ||
const HEADER_SIZE: usize = 2; | ||
|
||
let mut exresult = ExtractionResult { | ||
..Default::default() | ||
}; | ||
|
||
// Do the decompression, ignoring the GPG header | ||
let inflate_result = | ||
inflate::inflate_decompressor(file_data, offset + HEADER_SIZE, output_directory); | ||
|
||
// Check that the data decompressed OK | ||
if inflate_result.success { | ||
exresult.success = true; | ||
exresult.size = Some(HEADER_SIZE + inflate_result.size); | ||
} | ||
|
||
exresult | ||
} |
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