LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LoadLibrary gives "General Protection Fault" in debugger

Hello all,

I'm loading an external DLL (which itself loads several others). The LoadLibrary() call gives a General Protection Fault when I compile in Debug mode. If I compile in release mode and run the program out of CVI, it runs fine.

 

Anybody has any idea as to why there'd be a difference ?

 

Note that one of the sub-DLLs being loaded is HARP, which is a dongle-based security device, so my first guess is that it somehow refuses to run in a debugger. Anybody has experience being forced to program for this **bleep** in CVI ?

 

Thanks

0 Kudos
Message 1 of 8
(2,892 Views)

Hi gdargaud,

 

Would you be able to specifically call the sub-DLL loading HARP to see if we can narrow it down to this call?

 

Also, is any other specific information being passed with the General Protection Fault?

 

It may not be relevant, but there have been some posts about differences between release and debug executables, one of which I have posted below. One of the differences may be responsible for what we are seeing here. 

 

difference between debug and release: https://forums.ni.com/t5/LabWindows-CVI/difference-between-debug-and-release/td-p/294204 

 

Thanks,

 

ShaneK

Applications Engineering

0 Kudos
Message 2 of 8
(2,855 Views)

@gdargaud wrote:

 

 

Note that one of the sub-DLLs being loaded is HARP, which is a dongle-based security device, so my first guess is that it somehow refuses to run in a debugger. Anybody has experience being forced to program for this **bleep** in CVI ?


Almost all dongle based libraries nowadays include various code to detect if they run in a debugged executable context to avoid counterfighting their operation and a very common technique is to cause some assembly code to execute that will bomb when run in a debugged environment. So chances are pretty high that this is your problem and the solution is basically "Don't do that!"

Unless you can get a version of your DLL that does not use the dongle software, I don't think there is anything you or anyone else can do to allow this DLL to be called in a debugged process context, unless you resolve to real hacking.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 8
(2,839 Views)

Well, thanks for confirming my fears. I wrote both our vendor and the security software manufacturer and neither has replied in 2 weeks... Well, that's why I push hard for open-source solutions whenever I have a say in the matter. F**k security software like that which makes our life as developers miserable.

0 Kudos
Message 4 of 8
(2,781 Views)

OK, so this DLL is indeed 'protected' against debugger use (protecting their IP, blah, blah, blah). Going around that is as easy as detaching the process from the debugger just before calling LoadLibrary() and reattaching right behind it, so I've surrounded LoadLibrary() with two getchar(). Woah, look mom, I'm a hacker now !

 

Which brings me to:

- Is there a way to automate detaching / reattaching the debugger to the process programmatically ? I see DebugActiveProcess() in the Windows SDK but I'm not sure how it relates.

- Is there a way to know if I'm running in the debugger (shift-F5) or out of it (Ctrl-F5) ?

- also after I attach the debugger, execution stops at random times just like if there were some breakpoints...

0 Kudos
Message 5 of 8
(2,702 Views)

Your second question is addressed by BeingDebuggedByCVI () function which returns TRUE only if debugging (Shift+F5).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 8
(2,700 Views)

There probably are various breakpoint opcodes all through the code and code paths that happen to run into them when running under a debugger, just to confuse any potential hacker.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 8
(2,695 Views)

The breakpoints happen inside my own code, which is confusing; sometimes on proper lines, sometimes on undefined lines. No, I don't have watchpoint variables defined...

0 Kudos
Message 8 of 8
(2,688 Views)