Skip to content

Commit b373dad

Browse files
committed
more structures for DT command, for study exceptions
1 parent e67babb commit b373dad

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,49 @@ LdrDataTableEntry {
216216
```
217217

218218

219+
220+
A malware is hiding something in an exception
221+
```
222+
3307726 0x4f9673: push ebp
223+
3307727 0x4f9674: push edx
224+
3307728 0x4f9675: push eax
225+
3307729 0x4f9676: push ecx
226+
3307730 0x4f9677: push ecx
227+
3307731 0x4f9678: push 4F96F4h
228+
3307732 0x4f967d: push dword ptr fs:[0]
229+
Reading SEH 0x0
230+
-------
231+
3307733 0x4f9684: mov eax,[51068Ch]
232+
--- console ---
233+
=>
234+
```
235+
236+
Let's inspect exception structures:
237+
```
238+
--- console ---
239+
=>r esp
240+
esp: 0x22de98
241+
=>dt
242+
structure=>cppeh_record
243+
address=>0x22de98
244+
CppEhRecord {
245+
old_esp: 0x0,
246+
exc_ptr: 0x4f96f4,
247+
next: 0xfffffffe,
248+
exception_handler: 0xfffffffe,
249+
scope_table: PScopeTableEntry {
250+
enclosing_level: 0x278,
251+
filter_func: 0x51068c,
252+
handler_func: 0x288,
253+
},
254+
try_level: 0x288,
255+
}
256+
=>
257+
```
258+
259+
And here we have the error routine 0x4f96f4 and the filter 0x51068c
260+
261+
262+
263+
264+

src/emu32.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,10 @@ impl Emu32 {
15531553
let s = structures::ListEntry::load(addr, &self.maps);
15541554
s.print();
15551555
}
1556+
"cppeh_record" => {
1557+
let s = structures::CppEhRecord::load(addr, &self.maps);
1558+
s.print();
1559+
}
15561560

15571561
_ => println!("unrecognized structure."),
15581562
}
@@ -1684,20 +1688,20 @@ impl Emu32 {
16841688
0x30 => {
16851689
let peb = self.maps.get_mem("peb");
16861690
if self.cfg.verbose >= 1 {
1687-
println!("{} Reding PEB 0x{:x}", self.pos, peb.get_base());
1691+
println!("{} Reading PEB 0x{:x}", self.pos, peb.get_base());
16881692
}
16891693
peb.get_base()
16901694
}
16911695
0x18 => {
16921696
let teb = self.maps.get_mem("teb");
16931697
if self.cfg.verbose >= 1 {
1694-
println!("{} Reding TEB 0x{:x}", self.pos, teb.get_base());
1698+
println!("{} Reading TEB 0x{:x}", self.pos, teb.get_base());
16951699
}
16961700
teb.get_base()
16971701
}
16981702
0x00 => {
16991703
if self.cfg.verbose >= 1 {
1700-
println!("Reding SEH 0x{:x}", self.seh);
1704+
println!("Reading SEH 0x{:x}", self.seh);
17011705
}
17021706
self.seh
17031707
}

src/emu32/structures.rs

+94
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::emu32::maps::Maps;
22

33

4+
////// PEB / TEB //////
5+
46
#[derive(Debug)]
57
pub struct ListEntry {
68
flink: u32,
@@ -148,3 +150,95 @@ impl PEB {
148150
}
149151
}
150152

153+
154+
155+
156+
////// EXCEPTIONS //////
157+
158+
159+
/*
160+
ypedef struct _SCOPETABLE_ENTRY {
161+
DWORD EnclosingLevel;
162+
PVOID FilterFunc;
163+
PVOID HandlerFunc;
164+
} SCOPETABLE_ENTRY, *PSCOPETABLE_ENTRY;
165+
*/
166+
167+
168+
#[derive(Debug)]
169+
pub struct PScopeTableEntry {
170+
enclosing_level: u32,
171+
filter_func: u32,
172+
handler_func: u32,
173+
}
174+
175+
impl PScopeTableEntry {
176+
pub fn load(addr:u32, maps:&Maps) -> PScopeTableEntry {
177+
PScopeTableEntry {
178+
enclosing_level: maps.read_dword(addr).unwrap(),
179+
filter_func: maps.read_dword(addr + 4).unwrap(),
180+
handler_func: maps.read_dword(addr + 8).unwrap(),
181+
}
182+
}
183+
184+
pub fn size() -> u32 {
185+
return 12;
186+
}
187+
188+
pub fn print(&self) {
189+
println!("{:#x?}", self);
190+
}
191+
}
192+
193+
194+
195+
#[derive(Debug)]
196+
pub struct CppEhRecord {
197+
old_esp: u32,
198+
exc_ptr: u32,
199+
next: u32, // ptr to _EH3_EXCEPTION_REGISTRATION
200+
exception_handler: u32,
201+
scope_table: PScopeTableEntry,
202+
try_level: u32,
203+
}
204+
205+
impl CppEhRecord {
206+
pub fn load(addr:u32, maps:&Maps) -> CppEhRecord {
207+
CppEhRecord{
208+
old_esp: maps.read_dword(addr).unwrap(),
209+
exc_ptr: maps.read_dword(addr + 4).unwrap(),
210+
next: maps.read_dword(addr + 8).unwrap(),
211+
exception_handler: maps.read_dword(addr + 12).unwrap(),
212+
scope_table: PScopeTableEntry::load(addr + 16, &maps),
213+
try_level: maps.read_dword(addr + 16 + PScopeTableEntry::size()).unwrap(),
214+
}
215+
}
216+
217+
pub fn print(&self) {
218+
println!("{:#x?}", self);
219+
}
220+
}
221+
222+
223+
#[derive(Debug)]
224+
pub struct ExceptionPointers {
225+
exception_record: u32,
226+
context_record: u32,
227+
}
228+
229+
impl ExceptionPointers {
230+
pub fn load(addr:u32, maps:&Maps) -> ExceptionPointers {
231+
ExceptionPointers {
232+
exception_record: maps.read_dword(addr).unwrap(),
233+
context_record: maps.read_dword(addr + 4).unwrap(),
234+
}
235+
}
236+
237+
pub fn size() -> u32 {
238+
return 8;
239+
}
240+
241+
pub fn print(&self) {
242+
println!("{:#x?}", self);
243+
}
244+
}

0 commit comments

Comments
 (0)