Page 1 of 1

forcable fail dll load?

Posted: Sat Mar 03, 2012 8:16 am
by jassing
From within a dll

during "attach process" -- under certain conditions, I want the dll to "fail to load" -- is there a way to do that?

EDIT:
it appears if I raise an error in AttachProcess() this causes the dll to not load...
Is this the best approach?

Re: forcable fail dll load?

Posted: Sat Mar 03, 2012 10:05 am
by Shield
It might be enough just to return false in AttachProcess...at least that's how you'd do it in the native WinAPI DllMain function...
Check this out, it might help: http://msdn.microsoft.com/en-us/windows ... 87379.aspx

Re: forcable fail dll load?

Posted: Sun Mar 04, 2012 12:49 am
by jassing
Shield wrote:It might be enough just to return false in AttachProcess...at least that's how you'd do it in the native WinAPI DllMain function...
Check this out, it might help: http://msdn.microsoft.com/en-us/windows ... 87379.aspx
I thought that might be -- but a function w/o a specific "procedurereturn" does return 0/false

So by default, attachprocess procedure returns false.

Re: forcable fail dll load?

Posted: Sun Mar 04, 2012 9:35 am
by Thorium
You could try using DllMain instead of AttachProcess and DetachProcess.
It has a return value that indicates if it was successfull.

http://msdn.microsoft.com/en-us/library ... 82583.aspx

Re: forcable fail dll load?

Posted: Sun Mar 04, 2012 10:19 pm
by Kwai chang caine
I don't know if i have good understand the question :oops:
But there are a long time FREAK give to me this little jewel 8)
I use it for not give acces of my DLL if the key of the EXE is not good :D

Code: Select all

 !ADD esp, 8     ; remove Instance variable and return address from stack 
 !MOV eax, 0     ; set returnvalue to 0 
 !RET 12         ; return from DllEntryPoint 

Re: forcable fail dll load?

Posted: Mon Mar 05, 2012 1:11 am
by jassing
Kwaï chang caïne wrote:I don't know if i have good understand the question :oops:
But there are a long time FREAK give to me this little jewel 8)
I use it for not give acces of my DLL if the key of the EXE is not good :D

Code: Select all

 !ADD esp, 8     ; remove Instance variable and return address from stack 
 !MOV eax, 0     ; set returnvalue to 0 
 !RET 12         ; return from DllEntryPoint 
Thanks -- I was looking for a "proper way" -- but it seems there are many ways. Personally, I like the simple

Code: Select all

RaiseError(#ERROR_DLL_INIT_FAILED)
Error returned to calling program is meaningful...

Re: forcable fail dll load?

Posted: Mon Mar 05, 2012 7:11 pm
by Kwai chang caine
Cool i never see this function :shock: :oops:
Thanks jassing 8)