Skip to content

Commit 2bdd94a

Browse files
committed
its UEF not UEH #110
1 parent 65164e1 commit 2bdd94a

File tree

8 files changed

+58
-43
lines changed

8 files changed

+58
-43
lines changed

crates/libmwemu/src/emu/exception_handlers.rs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ impl Emu {
99
self.threads[self.current_thread_id].veh = value;
1010
}
1111

12-
pub fn ueh(&self) -> u64 {
13-
self.threads[self.current_thread_id].ueh
12+
pub fn uef(&self) -> u64 {
13+
self.threads[self.current_thread_id].uef
1414
}
1515

16-
pub fn set_ueh(&mut self, value: u64) {
17-
self.threads[self.current_thread_id].ueh = value;
16+
pub fn set_uef(&mut self, value: u64) {
17+
self.threads[self.current_thread_id].uef = value;
1818
}
1919

2020
pub fn eh_ctx(&self) -> u32 {
@@ -52,7 +52,7 @@ impl Emu {
5252
};
5353

5454
// No handled exceptions
55-
if self.seh() == 0 && self.veh() == 0 && self.ueh() == 0 {
55+
if self.seh() == 0 && self.veh() == 0 && self.uef() == 0 {
5656
log::info!(
5757
"exception without any SEH handler nor vector configured. pos = {} rip = {:x}",
5858
self.pos,
@@ -67,6 +67,8 @@ impl Emu {
6767
}
6868

6969
if self.veh() > 0 {
70+
// VEH
71+
7072
addr = self.veh();
7173

7274
exception::enter(self, ex_type);
@@ -77,36 +79,33 @@ impl Emu {
7779
self.set_eip(addr, false);
7880
}
7981

82+
} else if self.seh() > 0 {
83+
// SEH
8084

81-
} else if self.seh() == 0 {
82-
} else if self.ueh() > 0 {
83-
addr = self.ueh();
84-
85-
exception::enter(self, ex_type);
85+
8686
if self.cfg.is_64bits {
87-
self.set_rip(addr, false);
87+
// 64bits seh
88+
89+
unimplemented!("check .pdata if exists");
90+
8891
} else {
89-
self.set_eip(addr, false);
92+
// 32bits seh
93+
next = match self.maps.read_dword(self.seh()) {
94+
Some(value) => value.into(),
95+
None => {
96+
log::info!("exception wihout correct SEH");
97+
return;
98+
}
99+
};
100+
101+
addr = match self.maps.read_dword(self.seh() + 4) {
102+
Some(value) => value.into(),
103+
None => {
104+
log::info!("exception without correct SEH.");
105+
return;
106+
}
107+
};
90108
}
91-
} else {
92-
93-
// SEH
94-
95-
next = match self.maps.read_dword(self.seh()) {
96-
Some(value) => value.into(),
97-
None => {
98-
log::info!("exception wihout correct SEH");
99-
return;
100-
}
101-
};
102-
103-
addr = match self.maps.read_dword(self.seh() + 4) {
104-
Some(value) => value.into(),
105-
None => {
106-
log::info!("exception without correct SEH.");
107-
return;
108-
}
109-
};
110109

111110
let con = Console::new();
112111
if self.running_script {
@@ -131,6 +130,22 @@ impl Emu {
131130
self.set_eip(addr, false);
132131
}
133132
}
133+
134+
135+
} else if self.uef() > 0 {
136+
// UEF
137+
138+
addr = self.uef();
139+
140+
exception::enter(self, ex_type);
141+
if self.cfg.is_64bits {
142+
self.set_rip(addr, false);
143+
} else {
144+
self.set_eip(addr, false);
145+
}
146+
147+
} else {
148+
unreachable!();
134149
}
135150
}
136151

crates/libmwemu/src/serialization/emu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct SerializableEmu {
4242
pub bp: Breakpoints,
4343
pub seh: u64,
4444
pub veh: u64,
45-
pub ueh: u64,
45+
pub uef: u64,
4646
pub eh_ctx: u32,
4747
pub cfg: Config,
4848
pub colors: Colors,
@@ -102,7 +102,7 @@ impl<'a> From<&'a Emu> for SerializableEmu {
102102
bp: emu.bp.clone(),
103103
seh: emu.seh(),
104104
veh: emu.veh(),
105-
ueh: emu.ueh(),
105+
uef: emu.uef(),
106106
eh_ctx: emu.eh_ctx(),
107107
cfg: emu.cfg.clone(),
108108
colors: emu.colors.clone(),
@@ -222,7 +222,7 @@ impl Default for SerializableEmu {
222222
bp: emu.bp.clone(),
223223
seh: emu.seh(),
224224
veh: emu.veh(),
225-
ueh: emu.ueh().clone(),
225+
uef: emu.uef().clone(),
226226
eh_ctx: emu.eh_ctx().clone(),
227227
cfg: emu.cfg.clone(),
228228
colors: emu.colors.clone(),

crates/libmwemu/src/serialization/thread_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct SerializableThreadContext {
2323
pub fpu: SerializableFPU,
2424
pub seh: u64,
2525
pub veh: u64,
26-
pub ueh: u64,
26+
pub uef: u64,
2727
pub eh_ctx: u32,
2828
pub tls32: Vec<u32>,
2929
pub tls64: Vec<u64>,
@@ -49,7 +49,7 @@ impl From<&ThreadContext> for SerializableThreadContext {
4949
fpu: thread.fpu.clone().into(),
5050
seh: thread.seh,
5151
veh: thread.veh,
52-
ueh: thread.ueh,
52+
uef: thread.uef,
5353
eh_ctx: thread.eh_ctx,
5454
tls32: thread.tls32.clone(),
5555
tls64: thread.tls64.clone(),
@@ -77,7 +77,7 @@ impl From<SerializableThreadContext> for ThreadContext {
7777
fpu: serialized.fpu.into(),
7878
seh: serialized.seh,
7979
veh: serialized.veh,
80-
ueh: serialized.ueh,
80+
uef: serialized.uef,
8181
eh_ctx: serialized.eh_ctx,
8282
tls32: serialized.tls32,
8383
tls64: serialized.tls64,

crates/libmwemu/src/thread_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct ThreadContext {
1818
pub fpu: FPU,
1919
pub seh: u64,
2020
pub veh: u64,
21-
pub ueh: u64,
21+
pub uef: u64,
2222
pub eh_ctx: u32,
2323
pub tls32: Vec<u32>,
2424
pub tls64: Vec<u64>,
@@ -44,7 +44,7 @@ impl ThreadContext {
4444
fpu: FPU::new(),
4545
seh: 0,
4646
veh: 0,
47-
ueh: 0,
47+
uef: 0,
4848
eh_ctx: 0,
4949
tls32: Vec::new(),
5050
tls64: Vec::new(),

crates/libmwemu/src/winapi/winapi32/kernelbase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn SetUnhandledExceptionFilter(emu: &mut emu::Emu) {
182182
emu.colors.nc
183183
);
184184

185-
emu.set_ueh(ptr1 as u64);
185+
emu.set_uef(ptr1 as u64);
186186

187187
emu.stack_pop32(false);
188188
emu.regs_mut().rax = 0;

crates/libmwemu/src/winapi/winapi32/ntdll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ fn RtlSetUnhandledExceptionFilter(emu: &mut emu::Emu) {
11561156
emu.colors.nc
11571157
);
11581158

1159-
emu.set_ueh(filter);
1159+
emu.set_uef(filter);
11601160
emu.stack_pop32(false);
11611161
emu.regs_mut().rax = 1;
11621162
}

crates/libmwemu/src/winapi/winapi64/kernelbase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,6 @@ fn SetUnhandledExceptionFilter(emu: &mut emu::Emu) {
430430
emu.colors.nc
431431
);
432432

433-
emu.set_ueh(ptr1 as u64);
433+
emu.set_uef(ptr1 as u64);
434434
emu.regs_mut().rax = 0;
435435
}

crates/libmwemu/src/winapi/winapi64/ntdll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ fn RtlSetUnhandledExceptionFilter(emu: &mut emu::Emu) {
10851085
emu.colors.nc
10861086
);
10871087

1088-
emu.set_ueh(filter);
1088+
emu.set_uef(filter);
10891089
emu.regs_mut().rax = 1;
10901090
}
10911091

0 commit comments

Comments
 (0)