flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
LocoDelAssembly 22 Apr 2009, 19:19
Shouldn't you use "mov eax, 1" on DllStart before returning? Also, it is "retn 12" not four.
Don't know if you made the export table correctly, try using the export macro if after fixing DllStart you still don't get it working correctly. |
|||
![]() |
|
FrozenKnight 22 Apr 2009, 22:55
Thank you.
Just 1 question what are the other 8 bytes for i thought dll's only had 1 parameter. |
|||
![]() |
|
LocoDelAssembly 22 Apr 2009, 23:05
This comes from the EXAMPLES folder of the fasm's Windows package:
Code: ; DLL creation example format PE GUI 4.0 DLL entry DllEntryPoint include 'win32a.inc' section '.text' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); proc ShowErrorMessage hWnd,dwError local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK invoke LocalFree,[lpBuffer] ret endp ; VOID ShowLastError(HWND hWnd); proc ShowLastError hWnd invoke GetLastError stdcall ShowErrorMessage,[hWnd],eax ret endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetLastError,'GetLastError',\ SetLastError,'SetLastError',\ FormatMessage,'FormatMessageA',\ LocalFree,'LocalFree' import user,\ MessageBox,'MessageBoxA' section '.edata' export data readable export 'ERRORMSG.DLL',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError' section '.reloc' fixups data discardable (Remember that "ret" under a proc context is a macro and is replaced by "retn args_size") DllMain |
|||
![]() |
|
FrozenKnight 23 Apr 2009, 08:41
Thank you, i wonder why that the orig will work under win xp 32?
|
|||
![]() |
|
LocoDelAssembly 23 Apr 2009, 15:06
Well is possible, for instance you can make WindowProc wrong and will work in XP while it will crash on Windows 98. However, I see that your original code called several times a function, perhaps that was making it work because it set EAX to a non-zero value and then the caller of DllMain was immune to the stack unbalancing error. Actually there are situations in which the callee won't make any problem, for example this:
Code: push ebp mov ebp, esp . . . push 3 push 2 push 1 call callee_that_does_ret_4_instead_of_ret_12 ; ESP unbalanced here leave ; Now thanks to EBP, ESP will have the correct value once more ret As long as the caller has an EBP-Based frame and don't use ESP it is OK. But implicit use of ESP should be taken into consideration too, if there is a PUSH before calling then the POP will restore garbage. So, in conclusion, returning in the wrong way doesn't mean that will crash at any situation but yet you are opening the chance so it is better to do it right since that is what the caller is expecting and the times the application survives are just by "miracle". Yes, I'm missing some situation like, for instance, stack overflow caused by the repeated call to a function that returns incorrectly. I just won't enumerate all the possible outcomes. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.