Skip to content

Commit 5e51b4a

Browse files
committed
v1.0.16
- Fix long nickname issues. (#26) - Widen the key search range.
1 parent 2fe874e commit 5e51b4a

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wechat-dump-rs"
3-
version = "1.0.15"
3+
version = "1.0.16"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/main.rs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
};
1111

1212
use aes::cipher::{block_padding::NoPadding, BlockDecryptMut, KeyIvInit};
13-
use anyhow::{Ok, Result};
13+
use anyhow::Result;
1414
use hmac::{Hmac, Mac};
1515
use pbkdf2::pbkdf2_hmac_array;
1616
use process::Process;
@@ -67,7 +67,7 @@ const RULES_V4: &str = r#"
6767
rule GetPhoneNumberOffset
6868
{
6969
strings:
70-
$a = /[\x01-\x20]\x00{7}\x0f\x00{7}[0-9]{11}\x00{5}\x0b\x00{7}\x0f\x00{7}/
70+
$a = /[\x01-\x20]\x00{7}(\x0f|\x1f)\x00{7}[0-9]{11}\x00{5}\x0b\x00{7}\x0f\x00{7}/
7171
condition:
7272
$a
7373
}
@@ -191,6 +191,16 @@ fn read_string(pid: u32, addr: usize, size: usize) -> Result<String> {
191191
}
192192
}
193193

194+
fn read_string_or_ptr(pid: u32, addr: usize, size: usize) -> Result<String> {
195+
match read_string(pid, addr, size) {
196+
Ok(ss) => Ok(ss),
197+
Err(_) => {
198+
let str_ptr = read_number::<usize>(pid, addr)?;
199+
Ok(read_string(pid, str_ptr, size)?)
200+
}
201+
}
202+
}
203+
194204
fn read_bytes(pid: u32, addr: usize, size: usize) -> Result<Vec<u8>> {
195205
unsafe {
196206
let hprocess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, pid)?;
@@ -496,20 +506,21 @@ fn dump_wechat_info_v4(
496506
.next()
497507
.expect("unable to find phone string");
498508

499-
let key_memory_info = wechat_writeable_private_mem_infos
500-
.iter()
501-
.find(|v| v.base == phone_str_match.base)
502-
.unwrap();
503-
let key_search_range = 0..key_memory_info.base + key_memory_info.region_size;
509+
// let key_memory_info = wechat_writeable_private_mem_infos
510+
// .iter()
511+
// .find(|v| v.base == phone_str_match.base)
512+
// .unwrap();
513+
// let key_search_range = 0..key_memory_info.base + key_memory_info.region_size;
504514

505515
let nick_name_length = u64::from_le_bytes(phone_str_match.data[..8].try_into().unwrap());
506516
let phone_str_address = phone_str_match.base + phone_str_match.offset + 0x10;
507517
let phone_str = read_string(pid, phone_str_address, 11).unwrap();
508-
let nick_name = read_string(pid, phone_str_address - 0x20, nick_name_length as usize).unwrap();
518+
let nick_name =
519+
read_string_or_ptr(pid, phone_str_address - 0x20, nick_name_length as usize).unwrap();
509520

510521
let account_name_length = read_number::<u64>(pid, phone_str_address - 0x30).unwrap();
511522
let account_name =
512-
read_string(pid, phone_str_address - 0x40, account_name_length as _).unwrap();
523+
read_string_or_ptr(pid, phone_str_address - 0x40, account_name_length as _).unwrap();
513524

514525
let data_dir = if special_data_dir.is_some() {
515526
special_data_dir
@@ -545,7 +556,9 @@ fn dump_wechat_info_v4(
545556
.next()
546557
.expect("unable to find data dir");
547558

548-
String::from_utf8(data_dir_match.data.clone()).unwrap().replace("db_storage\\", "")
559+
String::from_utf8(data_dir_match.data.clone())
560+
.unwrap()
561+
.replace("db_storage\\", "")
549562
};
550563

551564
let mut compiler = Compiler::new().unwrap();
@@ -598,7 +611,23 @@ rule GetKeyAddrStub
598611
}
599612
}
600613

601-
if key_stub_str_addresses.is_empty() {
614+
let mut pre_addresses: HashSet<u64> = HashSet::new();
615+
key_stub_str_addresses.sort_by(|&a, &b| {
616+
a.abs_diff(phone_str_address as _)
617+
.cmp(&b.abs_diff(phone_str_address as _))
618+
});
619+
for cur_stub_addr in key_stub_str_addresses {
620+
// if cur_stub_addr < key_search_range.end as _ {
621+
if wechat_writeable_private_mem_infos.iter().any(|v| {
622+
cur_stub_addr >= v.base as _
623+
&& cur_stub_addr <= (v.base + v.region_size - KEY_SIZE) as _
624+
}) {
625+
pre_addresses.insert(cur_stub_addr);
626+
}
627+
// }
628+
}
629+
630+
if pre_addresses.is_empty() {
602631
panic!("unable to find key stub str");
603632
}
604633

@@ -616,22 +645,6 @@ rule GetKeyAddrStub
616645
let mut buf = [0u8; PAGE_SIZE];
617646
db_file.read(&mut buf[..]).expect("read biz.db is failed");
618647

619-
let mut pre_addresses: HashSet<u64> = HashSet::new();
620-
key_stub_str_addresses.sort_by(|&a, &b| {
621-
a.abs_diff(phone_str_address as _)
622-
.cmp(&b.abs_diff(phone_str_address as _))
623-
});
624-
for cur_stub_addr in key_stub_str_addresses {
625-
if cur_stub_addr < key_search_range.end as _ {
626-
if wechat_writeable_private_mem_infos.iter().any(|v| {
627-
cur_stub_addr >= v.base as _
628-
&& cur_stub_addr <= (v.base + v.region_size - KEY_SIZE) as _
629-
}) {
630-
pre_addresses.insert(cur_stub_addr);
631-
}
632-
}
633-
}
634-
635648
// HMAC_SHA512算法比较耗时,使用多线程跑
636649
let n_job = pre_addresses.len();
637650

@@ -1009,7 +1022,7 @@ fn cli() -> clap::Command {
10091022
use clap::{arg, value_parser, Command};
10101023

10111024
Command::new("wechat-dump-rs")
1012-
.version("1.0.15")
1025+
.version("1.0.16")
10131026
.about("A wechat db dump tool")
10141027
.author("REinject")
10151028
.help_template("{name} ({version}) - {author}\n{about}\n{all-args}")

0 commit comments

Comments
 (0)