Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified install.sh
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions memflow-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ tokio-util = { version = "0.4", features = ["full"] }
tokio-serde = "0.6"
bytes = "0.5"
futures = "0.3.0"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = "0.1"

Expand Down
11 changes: 11 additions & 0 deletions memflow-cli/src/commands/connection/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub const COMMAND_STR: &str = "new";
const CONNECTOR_NAME: &str = "CONNECTOR_NAME";
const CONNECTOR_ARGS: &str = "CONNECTOR_ARGS";
const CONNECTOR_ALIAS: &str = "CONNECTOR_ALIAS";
const CONNECTOR_OS_NAME: &str = "CONNECTOR_OS_NAME";

pub fn command_definition<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name(COMMAND_STR)
Expand All @@ -36,6 +37,14 @@ pub fn command_definition<'a, 'b>() -> App<'a, 'b> {
.takes_value(true)
.required(false),
)
.arg(
Arg::with_name(CONNECTOR_OS_NAME)
.help("os name for the connection")
.long("os_name")
.short("o")
.takes_value(true)
.required(false),
)
}

pub fn handle_command(conf: &Config, matches: &ArgMatches) {
Expand All @@ -44,13 +53,15 @@ pub fn handle_command(conf: &Config, matches: &ArgMatches) {
let name = matches.value_of(CONNECTOR_NAME).unwrap();
let args = matches.value_of(CONNECTOR_ARGS);
let alias = matches.value_of(CONNECTOR_ALIAS);
let os_name = matches.value_of(CONNECTOR_OS_NAME).unwrap();

dispatch_request(
conf,
request::Message::Connect(request::Connect {
name: name.to_string(),
args: args.map(|s| s.to_string()),
alias: alias.map(|a| a.to_string()),
os_name: os_name.to_string(),
}),
)
.unwrap();
Expand Down
10 changes: 4 additions & 6 deletions memflow-daemon-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ categories = [ "api-bindings", "memory-management", "os" ]
crate-type = ["lib", "cdylib"]

[dependencies]
memflow = { version = "0.1", features = ["inventory"] }
memflow-derive = { version = "0.1" }
memflow = { git = "https://github.com/memflow/memflow", branch = "os-layers", features = ["default"] }
memflow-daemon = { path = "../memflow-daemon" }
log = { version = "0.4.8", default-features = false }
log = { version = "0.4", default-features = false }
simple_logger = "1.0"
url = "2.1"

#tokio
Expand All @@ -27,14 +27,12 @@ tokio-util = { version = "0.4", features = ["full"] }
tokio-serde = "0.6"
bytes = "0.5"
futures = "0.3.0"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = "0.1"

[dev-dependencies]
clap = "2.33.0"
simple_logger = "1.0.1"

[features]
default = []
Expand Down
6 changes: 3 additions & 3 deletions memflow-daemon-connector/examples/read_phys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::{info, Level};
extern crate clap;
use clap::{App, Arg};

use memflow::*;
use memflow::prelude::v1::*;

fn main() {
let matches = App::new(crate_name!())
Expand All @@ -30,8 +30,8 @@ fn main() {
.unwrap();

let host = matches.value_of("host").unwrap();
let args = ConnectorArgs::parse(host).unwrap();
let mut conn = match memflow_daemon_connector::create_connector(&args) {
let args = Args::parse(host).unwrap();
let mut conn = match memflow_daemon_connector::create_connector(&args, Level::Debug) {
Ok(br) => br,
Err(e) => {
info!("couldn't open memory read context: {:?}", e);
Expand Down
30 changes: 18 additions & 12 deletions memflow-daemon-connector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{error, info};
use log::{error, info, Level};
use url::Url;

use futures::prelude::*;
Expand All @@ -8,9 +8,9 @@ use tokio_serde::formats::*;
use tokio_serde::{formats::Json, SymmetricallyFramed};
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};

use memflow::*;
use memflow::derive::connector;
use memflow::prelude::v1::*;
use memflow_daemon::{request, response};
use memflow_derive::connector;

// framed udp read/write pairs
type FramedUdsRequestWriter = SymmetricallyFramed<
Expand Down Expand Up @@ -65,15 +65,15 @@ impl FramedStream {
error!("{}", e);
Error::IO("unable to read read message")
})?
.ok_or_else(|| Error::IO("no more messages")),
.ok_or(Error::IO("no more messages")),
FramedStream::Tcp((_, reader)) => reader
.try_next()
.await
.map_err(|e| {
error!("{}", e);
Error::IO("unable to read read message")
})?
.ok_or_else(|| Error::IO("no more messages")),
.ok_or(Error::IO("no more messages")),
}
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn connect_tcp(addr: &str) -> Result<FramedStream> {
}

async fn connect_uds(addr: &str) -> Result<FramedStream> {
println!("trying to open connection to {}", addr);
info!("trying to open connection to {}", addr);
let socket = UnixStream::connect(addr)
.await
.map_err(|_| Error::Other("unable to connect to udp socket"))?;
Expand Down Expand Up @@ -168,7 +168,7 @@ impl DaemonConnector {
.map_err(|_| Error::Other("unable to get phys_mem metadata from daemon"))?;

Ok(Self {
addr: String::new(),
addr: addr.to_owned(),
conn_id: conn_id.to_string(),

runtime: rt,
Expand All @@ -179,6 +179,7 @@ impl DaemonConnector {
}
}

// TODO: bugged
impl Clone for DaemonConnector {
fn clone(&self) -> Self {
DaemonConnector::new(&self.addr, &self.conn_id).unwrap()
Expand Down Expand Up @@ -385,15 +386,20 @@ impl PhysicalMemory for DaemonConnector {
}
}

/// Creates a new Qemu Procfs Connector instance.
#[connector(name = "daemon")]
pub fn create_connector(args: &ConnectorArgs) -> Result<DaemonConnector> {
/// Creates a new Daemon Connector instance.
#[connector(name = "daemon", description = "daemon connector")]
pub fn create_connector(args: &Args, log_level: Level) -> Result<DaemonConnector> {
simple_logger::SimpleLogger::new()
.with_level(log_level.to_level_filter())
.init()
.ok();

let addr = args
.get("host")
.or_else(|| args.get_default())
.ok_or_else(|| Error::Connector("host argument is missing"))?;
.ok_or(Error::Connector("host argument is missing"))?;
let conn_id = args
.get("id")
.ok_or_else(|| Error::Connector("id argument is missing"))?;
.ok_or(Error::Connector("id argument is missing"))?;
DaemonConnector::new(addr, conn_id)
}
8 changes: 4 additions & 4 deletions memflow-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ keywords = [ "memflow", "introspection", "memory" ]
categories = [ "api-bindings", "memory-management", "os" ]

[dependencies]
memflow = { version = "0.1", features = ["inventory", "serde_derive"] }
memflow-win32 = { version = "0.1", features = ["serde_derive"] }
memflow = { git = "https://github.com/memflow/memflow", branch = "os-layers", features = ["serde_derive"] }
memflow-win32 = { git = "https://github.com/memflow/memflow", branch = "os-layers", features = ["serde_derive"] }
clap = { version = "2.33.0" }
log = "0.4.8"
simplelog = "0.8.0"
url = "2.1"
lazy_static = "1.4"
uuid = { version = "0.8", features = ["v4"] }
minidump-writer = { git = "https://github.com/h33p/minidump-writer" }
log-panics = "2.0.0"

# tokio
tokio = { version = "0.3", features = ["full"] }
tokio-util = { version = "0.4", features = ["full"] }
tokio-serde = { version = "0.6", features = ["json"] }
futures = "0.3.0"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_bytes = "0.11"
time = "0.1"
Expand Down
30 changes: 14 additions & 16 deletions memflow-daemon/src/commands/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ use crate::dispatch::*;
use crate::dto::request;
use crate::error::{Error, Result};
use crate::response;
use crate::state::{KernelHandle, STATE};
use crate::state::STATE;

use futures::Sink;
use std::marker::Unpin;

use memflow::*;
use memflow::os::root;
use memflow::prelude::v1::*;

fn create_connector(msg: &request::Connect) -> Result<ConnectorInstance> {
let args = match &msg.args {
Some(a) => ConnectorArgs::parse(a)
.map_err(|_| Error::Connector("unable to parse connector string"))?,
None => ConnectorArgs::default(),
Some(a) => {
Args::parse(a).map_err(|_| Error::Connector("unable to parse connector string"))?
}
None => Args::default(),
};

let inventory = unsafe { ConnectorInventory::try_new() }.map_err(Error::from)?;
unsafe { inventory.create_connector(&msg.name, &args) }.map_err(Error::from)
let inventory = unsafe { Inventory::scan() };
unsafe { inventory.create_connector(&msg.name, None, &args) }.map_err(Error::from)
}

pub async fn new<S: Sink<response::Message> + Unpin>(
Expand All @@ -29,24 +31,20 @@ pub async fn new<S: Sink<response::Message> + Unpin>(
// TODO: add os argument
// TODO: redirect log to client
// TODO: add cache options

send_log_info(frame, "connector created").await?;

// initialize kernel
let kernel = memflow_win32::Kernel::builder(conn)
.build_default_caches()
.build()
.map_err(|_| Error::Connector("unable to find kernel"))?;

send_log_info(frame, "found win32 kernel").await?;
// initialize os
let os = Inventory::build_os_simple(msg.name, msg.os_name)?;

send_log_info(frame, "initialized os").await?;

let mut state = STATE.lock().await;

match state.connection_add(
&msg.name,
msg.args.clone(),
msg.alias,
KernelHandle::Win32(kernel),
os,
) {
Ok(id) => {
send_log_info(
Expand Down
11 changes: 6 additions & 5 deletions memflow-daemon/src/commands/fuse/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod scopes;
use scopes::ConnectionScope;

use crate::error::{Error, Result};
use crate::state::{state_lock_sync, FileSystemHandle, KernelHandle};
use crate::state::{state_lock_sync, FileSystemHandle};

use std::cell::RefCell;
use std::ffi::{OsStr, OsString};
Expand All @@ -12,11 +12,11 @@ use std::time::{Duration, Instant};

use log::info;

use memflow::{mem::PhysicalMemory, prelude::OSInstance};

use fuse_mt::*;
use time::*;

use memflow::mem::phys_mem::PhysicalMemory;

pub type ChildrenList = Vec<Arc<Box<dyn FileSystemEntry>>>;

/// Trait describing an entry into the virtual filesystem.
Expand Down Expand Up @@ -241,12 +241,13 @@ impl VirtualMemoryFileSystem {
id: &str,
conn_id: &str,
mount_point: &str,
kernel: KernelHandle,
os: OSInstance,
uid: u32,
gid: u32,
) -> Self {
let readonly = match &kernel {
let readonly = match &os {
KernelHandle::Win32(kernel) => kernel.phys_mem.metadata().readonly,

};

Self {
Expand Down
2 changes: 1 addition & 1 deletion memflow-daemon/src/commands/fuse/filesystem/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::state::KernelHandle;

use std::sync::{Arc, Mutex};

use memflow_win32::{Win32ModuleInfo, Win32Process, Win32ProcessInfo};
use memflow_win32::prelude::{Win32ModuleInfo, Win32Process, Win32ProcessInfo};

pub struct ConnectionScope {
kernel: Arc<Mutex<KernelHandle>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::super::{FileSystemEntry, FileSystemFileHandler};
use crate::error::{Error, Result};
use crate::state::KernelHandle;

use std::sync::{Arc, Mutex};

use memflow::*;
use memflow::mem::PhysicalMemory;

// TODO: block storage?
pub struct PhysicalDumpFile {
Expand Down
4 changes: 2 additions & 2 deletions memflow-daemon/src/commands/fuse/filesystem/scopes/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::state::{CachedWin32Process, KernelHandle};

use std::sync::{Arc, Mutex};

use memflow::*;
use memflow_win32::*;
use memflow::prelude::v1::*;
use memflow_win32::prelude::v1::*;

use pelite::pe64::imports::Import;
use pelite::pe64::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use minidump_writer::{

use memflow::mem::VirtualMemory;
use memflow::types::size;
use memflow_win32::*;
use memflow_win32::prelude::v1::*;

use std::cell::RefCell;

Expand Down
2 changes: 1 addition & 1 deletion memflow-daemon/src/commands/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::state::{new_uuid, STATE};
use futures::Sink;
use std::marker::Unpin;

use memflow::PID;
use memflow::os::process::PID;

pub async fn attach<S: Sink<response::Message> + Unpin>(
frame: &mut S,
Expand Down
Loading