-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
775 additions
and
638 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "avml" | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
license = "MIT" | ||
description = "A portable volatile memory acquisition tool" | ||
authors = ["[email protected]"] | ||
|
@@ -13,18 +13,20 @@ readme = "README.md" | |
[features] | ||
default = ["put", "blobstore"] | ||
put = ["reqwest"] | ||
blobstore = ["azure", "retry", "tokio-core", "url"] | ||
blobstore = ["azure", "retry", "tokio-core", "url", "azure_sdk_core", "azure_sdk_storage_core"] | ||
|
||
[dependencies] | ||
elf = "0.0.10" | ||
byteorder = "1.3.2" | ||
clap = {version = "2.33.0", default-features = false} | ||
snap = "0.2.5" | ||
url = { version = "1.7.2", optional = true } | ||
url = { version = "2.1.0", optional = true } | ||
tokio-core = { version = "0.1.17", optional = true } | ||
retry = { version = "0.5.1", optional = true } | ||
reqwest = { version = "0.9.18", default-features = false, features = ["rustls-tls"], optional = true } | ||
azure = { version = "0.12.0", package = "azure_sdk_for_rust", optional = true} | ||
reqwest = { version = "0.9.19", default-features = false, features = ["rustls-tls"], optional = true } | ||
azure = { version = "0.23.1", package = "azure_sdk_storage_blob", optional = true} | ||
azure_sdk_core = { version = "0.20.3", optional = true } | ||
azure_sdk_storage_core = { version = "0.20.4", optional = true } | ||
|
||
[profile.release] | ||
opt-level="z" | ||
|
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,82 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#[macro_use] | ||
extern crate clap; | ||
extern crate avml; | ||
extern crate byteorder; | ||
extern crate elf; | ||
extern crate snap; | ||
|
||
use clap::{App, Arg}; | ||
use snap::Reader; | ||
use std::error::Error; | ||
use std::fs::metadata; | ||
use std::io::prelude::*; | ||
use std::io::SeekFrom; | ||
|
||
fn convert(src: String, dst: String, compress: bool) -> Result<(), Box<dyn Error>> { | ||
let src_len = metadata(&src)?.len(); | ||
let mut image = avml::image::Image::new(1, &src, &dst)?; | ||
|
||
loop { | ||
let current = image.src.seek(SeekFrom::Current(0))?; | ||
if current >= src_len { | ||
break; | ||
} | ||
|
||
let header = avml::image::Header::read(&image.src)?; | ||
let mut new_header = header.clone(); | ||
new_header.version = if compress { 2 } else { 1 }; | ||
|
||
match header.version { | ||
1 => { | ||
avml::image::copy_block(&new_header, &mut image.src, &mut image.dst)?; | ||
} | ||
2 => { | ||
let mut reader = Reader::new(&image.src); | ||
avml::image::copy_block(&new_header, &mut reader, &mut image.dst)?; | ||
image.src.seek(SeekFrom::Current(8))?; | ||
} | ||
_ => unimplemented!(), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn run_app() -> Result<(), Box<dyn Error>> { | ||
let args = App::new("avml-convert") | ||
.author(crate_authors!()) | ||
.about("AVML compress/decompress tool") | ||
.version(crate_version!()) | ||
.args(&[ | ||
Arg::with_name("compress") | ||
.long("compress") | ||
.help("compress pages via snappy"), | ||
Arg::with_name("source") | ||
.help("name of the source file to read to on local system") | ||
.required(true), | ||
Arg::with_name("destination") | ||
.help("name of the destination file to write to on local system") | ||
.required(true), | ||
]) | ||
.get_matches(); | ||
|
||
let compress = args.is_present("compress"); | ||
let src = value_t!(args.value_of("source"), String)?; | ||
let dst = value_t!(args.value_of("destination"), String)?; | ||
|
||
convert(src, dst, compress)?; | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
::std::process::exit(match run_app() { | ||
Ok(_) => 0, | ||
Err(err) => { | ||
eprintln!("error: {:?}", err); | ||
1 | ||
} | ||
}); | ||
} |
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
Oops, something went wrong.