1use std::io::Write;
2use std::num::ParseIntError;
3
4pub struct Console {}
5
6impl Console {
7 pub fn new() -> Console {
8 log::info!("--- console ---");
9 Console {}
10 }
11
12 pub fn print(&self, msg: &str) {
13 print!("{}", msg);
14 std::io::stdout().flush().unwrap();
15 }
16
17 pub fn cmd(&self) -> String {
18 let mut line = String::new();
19 self.print("=>");
20 std::io::stdin().read_line(&mut line).unwrap();
21 line = line.replace("\r", ""); line.truncate(line.len() - 1);
23 line.to_lowercase()
24 }
25
26 pub fn cmd2(&self) -> String {
27 let mut line = String::new();
28 self.print("=>");
29 std::io::stdin().read_line(&mut line).unwrap();
30 line = line.replace("\r", ""); line.truncate(line.len() - 1);
32 line
33 }
34
35 pub fn cmd_hex32(&self) -> Result<u32, ParseIntError> {
36 let mut x = self.cmd();
37
38 if x.ends_with('h') {
39 x = x[0..x.len() - 1].to_string();
40 }
41 if x.starts_with("0x") {
42 x = x[2..x.len()].to_string();
43 }
44
45 return u32::from_str_radix(x.as_str(), 16);
46 }
47
48 pub fn cmd_hex64(&self) -> Result<u64, ParseIntError> {
49 let mut x = self.cmd();
50 if x.ends_with('h') {
51 x = x[0..x.len() - 1].to_string();
52 }
53 if x.starts_with("0x") {
54 x = x[2..x.len()].to_string();
55 }
56
57 return u64::from_str_radix(x.as_str(), 16);
58 }
59
60 pub fn cmd_num(&self) -> Result<u64, ParseIntError> {
61 u64::from_str_radix(self.cmd().as_str(), 10)
62 }
63
64 pub fn help(&self) {
70 log::info!("--- help ---");
71 log::info!("q ...................... quit");
72 log::info!("cls .................... clear screen");
73 log::info!("h ...................... help");
74 log::info!("s ...................... stack");
75 log::info!("v ...................... vars");
76 log::info!("sv ..................... set verbose level 0, 1 or 2");
77 log::info!("r ...................... register show all");
78 log::info!("r reg .................. show reg");
79 log::info!("rc ..................... register change");
80 log::info!("f ...................... show all flags");
81 log::info!("fc ..................... clear all flags");
82 log::info!("fz ..................... toggle flag zero");
83 log::info!("fs ..................... toggle flag sign");
84 log::info!("c ...................... continue");
85 log::info!("b ...................... breakpoint list");
86 log::info!("ba ..................... breakpoint on address");
87 log::info!("bi ..................... breakpoint on instruction number");
88 log::info!("bmr .................... breakpoint on read memory");
89 log::info!("bmw .................... breakpoint on write memory");
90 log::info!("bmx .................... breakpoint on execute memory");
91 log::info!("bcmp ................... break on next cmp or test");
92 log::info!("bc ..................... clear breakpoint");
93 log::info!("n ...................... next instruction");
94 log::info!("eip .................... change eip");
95 log::info!("rip .................... change rip");
96 log::info!("push ................... push dword to the stack");
97 log::info!("pop .................... pop dword from stack");
98 log::info!("fpu .................... fpu view");
99 log::info!("md5 .................... check the md5 of a memory map");
100 log::info!("seh .................... view SEH");
101 log::info!("veh .................... view vectored execption pointer");
102 log::info!("m ...................... memory maps");
103 log::info!("ms ..................... memory filtered by keyword string");
104 log::info!("ma ..................... memory allocs");
105 log::info!("mc ..................... memory create map");
106 log::info!("mn ..................... memory name of an address");
107 log::info!("ml ..................... memory load file content to map");
108 log::info!("mr ..................... memory read, speficy ie: dword ptr [esi]");
109 log::info!(
110 "mw ..................... memory write, speficy ie: dword ptr [esi] and then: 1af"
111 );
112 log::info!("mwb .................... memory write bytes, input spaced bytes");
113 log::info!("md ..................... memory dump");
114 log::info!("mrd .................... memory read dwords");
115 log::info!("mrq .................... memory read qwords");
116 log::info!("mds .................... memory dump string");
117 log::info!("mdw .................... memory dump wide string");
118 log::info!("mdd .................... memory dump to disk");
119 log::info!("mdda ................... memory dump all allocations to disk");
120 log::info!("mt ..................... memory test");
121 log::info!("ss ..................... search string");
122 log::info!("sb ..................... search bytes");
123 log::info!("sba .................... search bytes in all the maps");
124 log::info!("ssa .................... search string in all the maps");
125 log::info!("ll ..................... linked list walk");
126 log::info!("d ...................... dissasemble");
127 log::info!("dt ..................... dump structure");
128 log::info!("enter .................. step into");
129 log::info!("tr ..................... trace reg");
130 log::info!("trc .................... trace regs clear");
131 log::info!("ldr .................... show ldr linked list");
132 log::info!("iat .................... find api name in all iat's ");
133 log::info!("iatx ................... addr to api name");
134 log::info!("iatd ................... dump the iat of specific module");
135
136 log::info!("");
138 log::info!("---");
139 }
140}