evmar / retrowin32

windows emulator
https://evmar.github.io/retrowin32/
Apache License 2.0
548 stars 24 forks source link

Getting PocoMan.exe running #43

Open LinusU opened 1 week ago

LinusU commented 1 week ago

This issue is to track my work in getting PocoMan v4.0 running. See more background in #39

My working branch is here: https://github.com/LinusU/retrowin32/tree/pocoman

evmar commented 1 week ago

This looks great so far, thanks for breaking it up! Also if you need any help or advice looking into your binary please reach out. I would love to flesh out the docs with anything useful for you.

evmar commented 6 days ago

By the way, if a function is missing, retrowin32 logs a warning about it but keeps running. So it will only matter if your binary actually calls it (where it will crash after calling a null pointer). Functions like ExitThread might not matter until you get to the end of the program, not sure.

LinusU commented 6 days ago

It seems like the threading is just used to kick of one thread that connects to the internet and check some kind of latest news, stores it in the registry, and then exits. Without ExitThread it crashed the entire program when it tried to exit, which since I've only stubbed the internet connect functions is basically immediately 😅

I'm at a point now where the program can run more than a few milliseconds! Unfortunately, it's a very tiny window, and something with the rendering seems broken. And as soon as I press anywhere it tries to call WideCharToMultiByte.

Screenshot 2024-09-14 at 23 30 00
INFO win32/src/winapi/user32/window.rs:324 user32/window/CreateWindowExA(dwExStyle:Err(300), lpClassName:Name("PocoMan Class"), lpWindowName:Some("PocoMan"), dwStyle:Ok(BORDER | DLGFRAME | SYSMENU | GROUP), X:80000000, Y:0, nWidth:1, nHeight:1, hWndParent:HANDLE(0), hMenu:0, hInstance:400000, lpParam:0) -> HANDLE(1)

This part seems a bit suspicious: X:80000000, Y:0, nWidth:1, nHeight:1

evmar commented 5 days ago

One idea is you could maybe locally stub out the CreateThread impl such that it never starts the thread in the first place, just to see what happens next. Depends on if it waits for the thread to come back though. I saw in your above list you had CreateEvent/SetEvent which are typically used for thread synchronization...


I ran the installer (via wine 😊 ) and I get this:

     Running `target/debug/retrowin32 --win32-trace - '/Users/evmar/.wine/drive_c/Program Files (x86)/PocoMan/pocoman.exe'`
WARN win32/src/winapi/kernel32/dll.rs:216 load_library("wsock32.dll"): not found
WARN win32/src/winapi/kernel32/misc.rs:152 IsProcessorFeaturePresent(Ok(FLOATING_POINT_PRECISION_ERRATA)) => false
thread 'main' panicked at x86/src/ops/basic.rs:478:16:
attempt to shift left with overflow

I guess I need more of your patches?


The window size could indicate a problem, but also some apps I've seen create a window with an unknown size, then resize it later in response to some window messages. ... since I have the exe anyway I checked and that is what it does.

ghidra says:

      g_hwnd = CreateWindowExA(0x300,s_PocoMan_Class_00418174,s_PocoMan_00418184,0xca0000,local_14,
                               local_18,1,1,(HWND)0x0,(HMENU)0x0,pHVar2,(LPVOID)0x0);

and there is some function called by the wndproc that does

  GetWindowRect(g_hwnd,&local_3c);
  GetClientRect(g_hwnd,&tStack_4c);
  SetWindowPos(g_hwnd,(HWND)0x0,0,0, ...
evmar commented 5 days ago

My above crash is fixed in 6427aededc6dc4e161b2ad9a93788af3e342e0c5, which now reveals the actual problem was running from the wrong directory

MessageBox: PocoMan
Can't open PocoMan.map for reading
evmar commented 4 days ago

If it helps you any, feel free to send a PR that is just like "here are all the stubs I need". You don't need to send separate PRs for them if it's too much effort. (I'm fine with separate PRs, just trying to save you some effort...)

LinusU commented 4 days ago

Sorry, I have had limited with time today and just cherry picked som already done work. Will give some more time to the comments later!

If it helps you any, feel free to send a PR that is just like "here are all the stubs I need"

Hehe, yeah I realized that that would probably have been a good strategy 😅

At this point I think that they are all merged though! Well, as far as I have gotten at least, will probably be a bit more when I get more time to dig further!

Thanks for all the help, and for looking into the binary yourself! As said, I'll try to read thru all your comments properly and answer in a few days