Skip to content
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
137 changes: 114 additions & 23 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "memflow-native"
version = "0.2.6"
authors = ["Aurimas Blažulionis <0x60@pm.me>", "ko1N <ko1N1337@gmail.com>"]
authors = ["Aurimas Blažulionis <0x60@pm.me>", "ko1N <ko1N1337@gmail.com>", "k1nd0ne <k1nd0ne@mail.com>"]
edition = "2021"
description = "System call based proxy-OS for memflow"
documentation = "https://docs.rs/memflow-native"
Expand All @@ -21,6 +21,7 @@ itertools = "0.14"
libc = { version = "0.2" }
log = "0.4"
memflow = { version = "0.2", features = ["plugins", "goblin"] }
#memflow = { path = "../memflow/memflow" }

# we keep procfs on version 0.15.x because it does not build properly with the backtrace on 0.16.x
# tracking issue: https://github.com/eminence/procfs/pull/309
Expand All @@ -42,6 +43,7 @@ windows = { version = "0.61", features = [
"Win32_UI_Input",
"Win32_UI_Input_KeyboardAndMouse",
] }
sysinfo = "0.37"

[target.'cfg(target_os = "macos")'.dependencies]
mac-sys-info = "0.1"
Expand Down
55 changes: 55 additions & 0 deletions src/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ impl LinuxProcess {
MMapPath::Other(s) => s.as_str().into(),
}
}

fn collect_envars(&self) -> Result<Vec<EnvVarInfo>> {
let path = format!("/proc/{}/environ", self.proc.pid());
let data = std::fs::read(path)
.map_err(|_| Error(ErrorOrigin::OsLayer, ErrorKind::EnvarNotFound))?;

let mut out = Vec::new();
for entry in data.split(|b| *b == 0).filter(|entry| !entry.is_empty()) {
let entry = String::from_utf8_lossy(entry);
if let Some((name, value)) = entry.split_once('=') {
out.push(EnvVarInfo {
name: ReprCString::from(name),
value: ReprCString::from(value),
address: Address::NULL,
arch: self.info.proc_arch,
});
}
}

Ok(out)
}
}

cglue_impl_group!(LinuxProcess, ProcessInstance, {});
Expand Down Expand Up @@ -277,6 +298,40 @@ impl Process for LinuxProcess {
.feed_into(out);
}
}

fn envar_list_callback(
&mut self,
target_arch: Option<&ArchitectureIdent>,
mut callback: EnvVarCallback,
) -> Result<()> {
if let Some(arch) = target_arch {
if *arch != self.info.proc_arch {
return Ok(());
}
}

for envar in self.collect_envars()? {
if !callback.call(envar) {
break;
}
}

Ok(())
}

fn environment_block_address(&mut self, _architecture: ArchitectureIdent) -> Result<Address> {
// Linux does not expose a stable public env-block pointer through procfs.
Ok(Address::NULL)
}

fn envar_list_from_address(
&mut self,
_env_block: Address,
architecture: ArchitectureIdent,
callback: EnvVarCallback,
) -> Result<()> {
self.envar_list_callback(Some(&architecture), callback)
}
}

impl MemoryView for LinuxProcess {
Expand Down
Loading