Skip to content

Commit

Permalink
refine little; publish v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
handy-sun committed Sep 29, 2024
1 parent 65d9efb commit 34b5f3b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Extract crate information
shell: bash
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_NAME=$(perl -nle 'if (/^\[\[bin\]\]/) { $found = 1; next; } if ($found && /^name\s*=\s*"([^"]+)"/) { print $1; $found = 0; }' Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
Expand Down
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.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "rcheat"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["handy-sun <[email protected]>"]
homepage = "https://github.com/handy-sun/rcheat"
repository = "https://github.com/handy-sun/rcheat"
description = "Get/modify variable's value in another Linux running process"
license = "MIT"
readme = "README.md"
keywords = ["ptrace", "elf"]
keywords = ["ptrace", "elf", "cli", "process", "gdb"]
categories = ["command-line-utilities"]
build = "build.rs"
exclude = [
Expand Down Expand Up @@ -39,7 +39,7 @@ features = [
]

[dependencies.clap]
version = "4.5.0"
version = "^4.5"
default-features = false
features = [
"std",
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ sudo rcheat -p 13725

Then will get the output about all global variables about this program
```
[205.405µs] Time of `parse elf`
[497.685µs] Time of `filter_symbol`
...
Matched count: 3
index: var_name | var_size(B)
Index: var_name | var_size(B)
0: sc_sig_arr | 60
1: structure | 8
2: techs | 21
Expand All @@ -134,7 +133,7 @@ Input `2` and `Enter`, you will see the byte value and ascii content of this var
You also can specify the total name or partly keyword of the variable with option `-k`

```sh
sudo rcheat -p 3754914 -k sig_arr
sudo rcheat -p 13725 -k sig_arr
```
```
...
Expand All @@ -145,6 +144,12 @@ sudo rcheat -p 3754914 -k sig_arr
0x0030: 4650 4500 0000 4b49 4c4c 0000 ┃ FPE...KILL..
```

After version `0.1.3`, option `-n/--name` can query pid by process name

```
sudo rcheat -n onlyc -k sig_arr
```

## 3. <a name='Todo'></a>Todo

*The development plan of the project and the functions to be implemented*
Expand All @@ -154,7 +159,7 @@ sudo rcheat -p 3754914 -k sig_arr
- [ ] use log crate such as `log/env_logger` etc.
- [ ] use config.toml to reduce some inputs
- [ ] use `lua` to customized output
- [ ] search pid by process name (like linux command: `pidof/pgrep`)
- [x] search pid by process name (like linux command: `pidof/pgrep`)
- [x] regex replace String.contain
- [x] if match more than 1 entry name, ask for which one to select
- [x] demangle symbols
2 changes: 1 addition & 1 deletion src/ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn further_parse(arg: Args) -> AnyError {
pub fn trace(pid: pid_t, keyword: String, format: String) -> AnyError {
let tracked_pid = Pid::from_raw(pid);
let exe_path = get_abs_path(pid)?;
println!("exe_path: {}", &exe_path);
println!("exe_real_path: {}", &exe_path);

let elf_bytes =
std::fs::read(&exe_path).map_err(|err| anyhow!("Problem reading file {:?}: {}", &exe_path, err))?;
Expand Down
18 changes: 14 additions & 4 deletions src/elf/dwinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,25 @@ impl<'a> DwarfInfoMatcher<'a> {
let mut iter = dwarf.units();
let mut btset_vec: Vec<_> = Vec::with_capacity(8);
while let Some(header) = iter.next()? {
println!(
"## Unit at <.debug_info {:#x}>",
header.offset().as_debug_info_offset().unwrap().0
eprint!(
"## Unit at <.debug_info 0x{:08x}, ver: {}>",
header.offset().as_debug_info_offset().unwrap().0,
header.version()
);
let unit = dwarf.unit(header)?;
let unit_ref = unit.unit_ref(&dwarf);

if let Ok(addr_set) = filter_die_in_unit(unit_ref, demangle, mangle) {
// Output file name of this Unit
if let Some(program) = unit_ref.line_program.clone() {
if let Some(file) = program.header().file_names().iter().next() {
eprint!(" {}", unit_ref.attr_string(file.path_name())?.to_string_lossy()?);
}
}
eprint!("\t| type_addr: {:?}", &addr_set);
btset_vec.push(addr_set);
}
eprintln!();
}
Ok(btset_vec)
}
Expand All @@ -103,7 +113,7 @@ fn filter_die_in_unit<'a>(
demangle: &'a str,
opt_mangle: Option<&'a str>,
) -> Result<BTreeSet<TypeOffset>, gimli::Error> {
// a closure (capture argument: UNitRef<..>) to get indirect string of this DW_AT_...
// a closure (capture argument: UnitRef<..>) to get indirect string of this DW_AT_...
let pick_type_offset = |die: &gimli::DebuggingInformationEntry<CusReader<'a>>,
dw_at: gimli::DwAt,
target: &str|
Expand Down
17 changes: 10 additions & 7 deletions src/elf/elfmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,11 @@ impl<'a> ElfMgr<'a> {
0 => Err(anyhow!("Cannot find")),
1 => {
let entry = entry_vec.first().unwrap().clone();
println!("Matched var: {}", entry.origin_name);
#[cfg(debug_assertions)]
eprintln!(
"Matched var: {}, dbg: {:?}",
entry.origin_name,
self.dw_matcher
.infer_var_type(&entry.origin_name, entry.mangled_name)
);
self.dw_matcher
.infer_var_type(&entry.origin_name, entry.mangled_name)
.ok();
Ok(entry)
}
2.. => {
Expand Down Expand Up @@ -295,13 +293,18 @@ mod tests {
(
"_ZN7MaiData12statMemArrayE",
"MaiData::statMemArray",
Language::Rust, // Rust: rust or cpp
Language::Rust, // Rust: rust or Cpp
),
(
"simple_arr",
"simple_arr",
Language::Unknown, // Unknown sometime includes C
),
(
"_ZL10sc_sig_arr",
"sc_sig_arr",
Language::Cpp, // static var-type in Cpp
),
(
"_Z11splitStringRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEc.cold",
"splitString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char) [clone .cold]",
Expand Down

0 comments on commit 34b5f3b

Please sign in to comment.