Skip to content

Commit

Permalink
Merge pull request #8 from citruz/release0.2.0
Browse files Browse the repository at this point in the history
Release0.2.0
  • Loading branch information
citruz authored Aug 26, 2020
2 parents f661f2e + 60d053e commit 73d6d98
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 87 deletions.
67 changes: 50 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Build and Test
name: CI
on: [push, pull_request]

jobs:
test:
name: Test & Build
name: Run Tests and Build
continue-on-error: true
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [stable, beta, nightly, macos, win32, win64]
build: [stable, beta, nightly, macos, win64]
include:
- build: stable
os: ubuntu-latest
Expand All @@ -22,19 +21,23 @@ jobs:
- build: macos
os: macos-latest
rust: stable
- build: win32
os: windows-2016
rust: stable-i686-msvc
- build: win64
os: windows-latest
rust: stable-x86_64-msvc
# win32 build seems to be broken atm
# - build: win32
# os: windows-2016
# rust: stable-i686-msvc
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@main
with:
submodules: true
- name: Install Rust (rustup)
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
shell: bash
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Use strawberry perl
if: startsWith(matrix.os, 'windows')
run: echo ::set-env name=OPENSSL_SRC_PERL::C:/Strawberry/perl/bin/perl
Expand All @@ -44,33 +47,63 @@ jobs:
Get-Command perl
perl -v
if: startsWith(matrix.os, 'windows')
- name: Run Cargo Test
run: cargo test

- name: Test without default features
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
- name: Test with default features
uses: actions-rs/cargo@v1
with:
command: test

- name: Build release binary
run: cargo build --release
if: startsWith(matrix.rust, 'stable')
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Delete intermediate files
if: startsWith(matrix.rust, 'stable')
run: rm -rf ./target/release/{build,deps,incremental}
shell: bash
- name: Upload artifacts
if: startsWith(matrix.rust, 'stable')
uses: actions/upload-artifact@v1
with:
name: dmgwiz_release_${{ matrix.build }}
path: ./target/release/


rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check


clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add clippy
- run: cargo clippy
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: clippy
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Thanks to everyone who contributed to this project (in chronological order):

- Jan Teske (https://github.com/ra-kete)
2 changes: 1 addition & 1 deletion Cargo.lock

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

37 changes: 23 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dmgwiz"
description = "Extract filesystem data from DMG files"
version = "0.1.0"
version = "0.2.0"
authors = ["Felix Seele <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -11,27 +11,36 @@ keywords = ["DMG", "Apple"]
categories = ["command-line-utilities", "encoding", "filesystem", "parsing"]

[dependencies]
itertools = "0.9.0"
clap = "2.33.1"
bincode = "1.3.1"
serde = { version = "1.0", features = ["derive"] }
ring = "0.16.15"
openssl = { version = "0.10", features = ["vendored"] }
plist = "1.0.0"
itertools = "0.9"
clap = "2"
bincode = "1"
serde = { version = "1", features = ["derive"] }
ring = { version = "0.16", optional = true }
plist = "1"
num-traits = "0.2"
num-derive = "0.3"
flate2 = "1.0.16"
bzip2 = "0.4.1"
adc = "0.1.0"
lzfse = "0.1.0"
flate2 = "1"
bzip2 = "0.4"
adc = "0.1"
lzfse = "0.1"

[dependencies.openssl]
version = "0.10"
features = ["vendored"]
optional = true

[dev-dependencies]
file_diff = "1.0.0"
file_diff = "1"

[lib]
name = "dmgwiz"
path = "src/lib.rs"

[[bin]]
name = "dmgwiz"
path = "src/main.rs"
path = "src/main.rs"
required-features = ["crypto"]

[features]
default = ["crypto"]
crypto = ["openssl", "ring"]
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ DmgWiz lets you extract raw filesystem data from compressed and encrypted DMG fi
DmgWiz is both a CLI tool and a Rust crate so it can be integrated into other projects.


[API Documentation](https://docs.rs/dmgwiz)
----------

CLI Usage
-----
---------

dmgwiz [OPTIONS] <INPUT> [SUBCOMMAND]

Expand All @@ -38,6 +35,28 @@ CLI Usage
dmgwiz <INPUT> extract [-n <partition number>] -o <output>


Crate Usage
-----------

DmgWiz can also be used as a crate in other Rust projects. Please see the [API Documentation](https://docs.rs/dmgwiz) and `main.rs` for examples how to use it.

Support for encrypted DMGs can be disabled to reduce the compilation time and amount of C code. To do this, add the `default-features = false` option in your `Cargo.toml`:
```TOML
[dependencies]
dmgwiz = {version = "0.2", default-features = false}
```

Changelog
---------

0.2.0
- Added support for comment chunks
- Added `CFName` as fallback in case the `Name` attribute is not set
- Separated crypto support in a feature (enabled by default)

0.1.0
- Initial release

References
----------
- [dmg2img](http://vu1tur.eu.org/tools/)
Expand Down
39 changes: 39 additions & 0 deletions src/crypto/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use serde::{Deserialize, Serialize};

/// Header used for encrypted DMGs
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct EncryptedDmgHeader {
signature: [char; 8],
pub version: u32,
pub enc_iv_size: u32,
unk1: u32,
unk2: u32,
pub data_enc_key_bits: u32,
unk4: u32,
pub hmac_key_bits: u32,
pub uuid: [u8; 16],
pub blocksize: u32,
pub datasize: u64,
pub dataoffset: u64,
unk6: [u8; 24],
pub kdf_algorithm: u32,
pub kdf_prng_algorithm: u32,
pub kdf_iteration_count: u32,
pub kdf_salt_len: u32,
pub kdf_salt: [u8; 32],
pub blob_enc_iv_size: u32,
pub blob_enc_iv: [u8; 32],
pub blob_enc_key_bits: u32,
pub blob_enc_algorithm: u32,
pub blob_enc_padding: u32,
pub blob_enc_mode: u32,
pub encrypted_keyblob_size: u32,
pub encrypted_keyblob1: [u8; 32],
pub encrypted_keyblob2: [u8; 32],
}

impl EncryptedDmgHeader {
pub fn get_signature(&self) -> String {
self.signature.iter().collect::<String>()
}
}
3 changes: 3 additions & 0 deletions src/crypto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod header;
#[cfg(feature = "crypto")]
pub mod reader;
42 changes: 2 additions & 40 deletions src/encrypted_reader.rs → src/crypto/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use openssl::pkey::PKey;
use openssl::sign::Signer;
use openssl::symm::{decrypt as openssl_decrypt, Cipher, Crypter, Mode};
use ring::pbkdf2;
use serde::{Deserialize, Serialize};

static PBKDF2_ALG: pbkdf2::Algorithm = pbkdf2::PBKDF2_HMAC_SHA1;

use super::{Error, Result, Verbosity};
use super::header::EncryptedDmgHeader;
use crate::{Error, Result, Verbosity};

// how can i use macro from super?
macro_rules! printDebug {
Expand All @@ -25,44 +25,6 @@ macro_rules! printDebug {
})
}

/// Header used for encrypted DMGs
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct EncryptedDmgHeader {
signature: [char; 8],
version: u32,
enc_iv_size: u32,
unk1: u32,
unk2: u32,
data_enc_key_bits: u32,
unk4: u32,
hmac_key_bits: u32,
uuid: [u8; 16],
blocksize: u32,
datasize: u64,
dataoffset: u64,
unk6: [u8; 24],
kdf_algorithm: u32,
kdf_prng_algorithm: u32,
kdf_iteration_count: u32,
kdf_salt_len: u32,
kdf_salt: [u8; 32],
blob_enc_iv_size: u32,
blob_enc_iv: [u8; 32],
blob_enc_key_bits: u32,
blob_enc_algorithm: u32,
blob_enc_padding: u32,
blob_enc_mode: u32,
encrypted_keyblob_size: u32,
encrypted_keyblob1: [u8; 32],
encrypted_keyblob2: [u8; 32],
}

impl EncryptedDmgHeader {
pub fn get_signature(&self) -> String {
self.signature.iter().collect::<String>()
}
}

/// Reader to read from encrypted DMGs
///
/// Use this to transparently read from encrypted DMGs.
Expand Down
8 changes: 7 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum Error {
UnsupportedEncryption(String),
/// The DMG could not be decrypted using the given password.
InvalidPassword,

#[cfg(feature = "crypto")]
/// There was an OpenSSL error during decryption.
Decryption(openssl::error::ErrorStack),
}
Expand All @@ -35,6 +37,7 @@ impl std::error::Error for Error {
fn cause(&self) -> Option<&dyn std::error::Error> {
match *self {
Error::Io(ref err) => Some(err),
#[cfg(feature = "crypto")]
Error::Decryption(ref err) => Some(err),
_ => None,
}
Expand All @@ -53,7 +56,6 @@ impl fmt::Display for Error {
write!(f, "unsupported encryption parameters: {}", str)
}
Error::InvalidPassword => write!(f, "invalid password given"),
Error::Decryption(_) => write!(f, "error during decryption"),
Error::Decompress {
partition_num,
chunk_num,
Expand All @@ -65,6 +67,9 @@ impl fmt::Display for Error {
),
Error::Io(ref e) => e.fmt(f),
Error::Parse(ref e) => write!(f, "parse error ({})", e),

#[cfg(feature = "crypto")]
Error::Decryption(_) => write!(f, "error during decryption"),
}
}
}
Expand Down Expand Up @@ -93,6 +98,7 @@ impl From<plist::Error> for Error {
}
}

#[cfg(feature = "crypto")]
impl From<openssl::error::ErrorStack> for Error {
fn from(err: openssl::error::ErrorStack) -> Error {
Error::Decryption(err)
Expand Down
Loading

0 comments on commit 73d6d98

Please sign in to comment.