Custom DllMain Windows

2020-07-30 Thread Recruit_main707
This code works import winim/com proc mainThread(hModule: HINSTANCE) = AllocConsole() discard stdout.reopen("CONOUT$", fmWrite) while true: echo "Hello World YEY", hModule proc NimMain() {.cdecl, importc.} proc DllMain(hMo

Custom DllMain Windows

2020-07-30 Thread Recruit_main707
@Shucks ive found out, using nim threads is what causes the issue, try creating the new thread with winim directly

Custom DllMain Windows

2020-07-24 Thread Recruit_main707
That’s a way to do it, but I think I know what’s wrong with the first example, (which is the most convenient one imo too), add the dynlib pragma to entryPoint, I bet that’s what was happening

Custom DllMain Windows

2020-07-24 Thread Shucks
I guess I've found a workaround to access the library handle: import winim/inc/[windef, wincon, winbase] proc getCurrentModule: HINSTANCE = discard GetModuleHandleEx( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS or GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,

Custom DllMain Windows

2020-07-24 Thread Shucks
Also since I'm currently working with the emitting dllmain, does someone know if there are risks calling NimMain and then spawn a thread for the maincode? I could imagine that the gc isn't running anymore or isnt aware of that I spawned Nimcode with windows' CreateThread

Custom DllMain Windows

2020-07-24 Thread Shucks
@Recruit_main707 meow is me. However that again will cause timeout issues for injectors once your code base gets bigger.

Custom DllMain Windows

2020-07-24 Thread Shucks
@Yardanico I know but thats not I've asked for. The issue is that I need to pass the first argument (hinstDLL) from dllmain to my main function and AFAIK nim's default entry point doesn't spawns a thread for the main code. That causes issues in some cases because a injector for example waits for

Custom DllMain Windows

2020-07-24 Thread Recruit_main707
Ok thank you :)

Custom DllMain Windows

2020-07-23 Thread Yardanico
" cpu:i386 is specified to compile the dll as 32bit" \- of course, yes, that's what it means. "And if yes, do you know if it is actually needed or it’s just for convenience of some type?" \- maybe the game itself is 32-bit, then the DLL should be 32-bit as well

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
That’s really nice, I didn’t know that. Do you know if, in the url I sent, cpu:i386 is specified to compile the dll as 32bit? And if yes, do you know if it is actually needed or it’s just for convenience of some type?

Custom DllMain Windows

2020-07-23 Thread Yardanico
Yes, exactly - Nim is sometimes smarter than people think - with --app:lib on Windows Nim automatically makes a DllMain entry-point which calls into your starting code. There's no need to add it manually at all

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
@Shucks I have made a little research, this guy doesnt seem to have any problems using winim functions, and another method to do things, have a look at it also [https://guidedhacking.com/threads/internal-with-nim.15281](https://guidedhacking.com/threads/internal-with-nim.15281)/

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
Thats because you disnt define DllMain, rename entryPoint to DllMain

Custom DllMain Windows

2020-07-23 Thread Shucks
That code snippets I've coded are ofcourse compiled with --noMain. However the "nim" way didn't produces a valid dllmain. The emitting one does but I wan't to keep my code on nim.

Custom DllMain Windows

2020-07-23 Thread Recruit_main707
You can define DllMain and compile your code with —NoMain so that there are no issues, however I did have problems when using winim functions, I think it was because it tried to load kernel32, even though it was already loaded (in the injected process)

Custom DllMain Windows

2020-07-23 Thread Shucks
So this got asked [here](https://forum.nim-lang.org/t/3190) already. How to define a DllMain Entrypoint without emitting raw c code? My example doesn't works. Looking at the raw cache .c file it also doesn't looks correct at all. import winim/inc/[windef, wincon] proc mainT