firefox_search/
firefox_search.rs

1//! This example changes the current text in Firefox's browser search bar from 
2//! "Old search text" to "New search text". To run this example, open an instance
3//! of Firefox and type "Old search text" in the search bar. If all goes well, when
4//! you run this example as root, it should be replaced with "New search text",
5//! although you may have to click on the search bar again in order for it to
6//! render the new text.
7
8fn main() {
9    use raminspect::RamInspector;
10    // Iterate over all running Firefox instances
11    for pid in raminspect::find_processes("/usr/lib/firefox/firefox") {
12        let mut inspector = match RamInspector::new(pid) {
13            Ok(inspector) => inspector,
14            Err(_) => continue,
15        };
16        
17        for (proc_addr, memory_region) in inspector.search_for_term(b"Old search text").unwrap() {
18            if !memory_region.writable() {
19                continue;
20            }
21
22            unsafe {
23                // This is safe because modifying the text in the Firefox search bar will not crash
24                // the browser or negatively impact system stability in any way.
25
26                println!("Writing to process virtual address: 0x{:X}", proc_addr);
27                inspector.queue_write(proc_addr, b"New search text");
28            }
29        }
30
31        unsafe {
32            // This is safe since the process is not currently resumed, which would possibly cause a data race.
33            inspector.flush().unwrap();
34        }
35    }
36}