I am a C++programmer, but I saw a Rust source code on the internet and I want to translate it into C++language, but I completely don't understand Rust language. Can someone tell me the meaning of the following code?
let mut compiler = Compiler::new().unwrap();
compiler = compiler
.add_rules_str(
r#"
rule GetKeyAddrStub
{
strings:
$a = /.{6}\x00{2}\x00{8}\x20\x00{7}\x2f\x00{7}/
condition:
all of them
}
"#,
)
.expect("rule error");
let rules = compiler
.compile_rules()
.expect("Should have compiled rules");
let results = rules.scan_process(pid, 0).expect("Should have scanned");
if results.is_empty() {
panic!("unable to find key stub str");
}
let mut key_stub_str_addresses = vec![];
for result in results {
if let Some(key_stub_str_matches) = result
.strings
.iter()
.filter(|x| {
x.matches.iter().any(|y| {
wechat_writeable_private_mem_infos
.iter()
.any(|z| y.base == z.base)
})
})
.next()
{
let tmp = key_stub_str_matches
.matches
.iter()
.filter(|x| {
wechat_writeable_private_mem_infos
.iter()
.any(|y| x.base == y.base)
})
.map(|x| u64::from_le_bytes(x.data[..8].try_into().unwrap()))
.collect::<Vec<u64>>();
key_stub_str_addresses.extend(tmp);
}
}
let mut pre_addresses: HashSet<u64> = HashSet::new();
key_stub_str_addresses.sort_by(|&a, &b| {
a.abs_diff(phone_str_address as _)
.cmp(&b.abs_diff(phone_str_address as _))
});
for cur_stub_addr in key_stub_str_addresses {
// if cur_stub_addr < key_search_range.end as _ {
if wechat_writeable_private_mem_infos.iter().any(|v| {
cur_stub_addr >= v.base as _
&& cur_stub_addr <= (v.base + v.region_size - KEY_SIZE) as _
}) {
pre_addresses.insert(cur_stub_addr);
}
// }
}
if pre_addresses.is_empty() {
panic!("unable to find key stub str");
}