@@ -2776,35 +2776,59 @@ fn GetModuleHandleA(emu: &mut emu::Emu) {
27762776 Some ( base) => base,
27772777 None => helper:: handler_create ( & module_name) ,
27782778 }
2779+
27792780 } else {
2780- let module_name = emu. maps . read_string ( module_name_ptr) ;
2781- let handle = get_library_handle ( emu, & module_name) ;
2781+ module_name = emu. maps . read_string ( module_name_ptr) . to_lowercase ( ) ;
2782+ let mod_mem = match emu. maps . get_mem2 ( & module_name) {
2783+ Some ( m) => m,
2784+ None => {
2785+ emu. regs . rax = 0 ;
2786+ return ;
2787+ }
2788+ } ;
27822789
2783- log:: info!(
2784- "{}** {} kernel32!GetModuleHandleA module_name: {} handle: 0x{:x} {}" ,
2785- emu. colors. light_red,
2786- emu. pos,
2787- module_name,
2788- handle,
2789- emu. colors. nc
2790- ) ;
2790+ emu. regs . rax = mod_mem. get_base ( ) ;
27912791 }
27922792
2793- emu. regs . rax = handle;
2793+ log:: info!(
2794+ "{}** {} kernel32!GetModuleHandleA `{}` {}" ,
2795+ emu. colors. light_red,
2796+ emu. pos,
2797+ module_name,
2798+ emu. colors. nc
2799+ ) ;
2800+
27942801}
27952802
27962803fn GetModuleHandleW ( emu : & mut emu:: Emu ) {
2797- let module_name = emu. maps . read_wide_string ( emu. regs . rcx ) ;
2798- let handle = get_library_handle ( emu, & module_name) ;
2804+ let module_name_ptr = emu. regs . rcx ;
2805+ let module_name: String ;
2806+
2807+ if module_name_ptr == 0 {
2808+ module_name = "self" . to_string ( ) ;
2809+ emu. regs . rax = match emu. maps . get_base ( ) {
2810+ Some ( base) => base,
2811+ None => helper:: handler_create ( & module_name) ,
2812+ }
2813+
2814+ } else {
2815+ module_name = emu. maps . read_wide_string ( module_name_ptr) . to_lowercase ( ) ;
2816+ let mod_mem = match emu. maps . get_mem2 ( & module_name) {
2817+ Some ( m) => m,
2818+ None => {
2819+ emu. regs . rax = 0 ;
2820+ return ;
2821+ }
2822+ } ;
2823+
2824+ emu. regs . rax = mod_mem. get_base ( ) ;
2825+ }
27992826
28002827 log:: info!(
2801- "{}** {} kernel32!GetModuleHandleW module_name: {} handle: 0x{:x} {}" ,
2828+ "{}** {} kernel32!GetModuleHandleW `{}` {}" ,
28022829 emu. colors. light_red,
28032830 emu. pos,
28042831 module_name,
2805- handle,
28062832 emu. colors. nc
28072833 ) ;
2808-
2809- emu. regs . rax = handle;
28102834}
0 commit comments