Anti-piracy tip: Prevent debugging (Windows)

Share your advanced PureBasic knowledge/code with the community.
Opcode
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Jul 18, 2013 4:58 am

Re: Anti-piracy tip: Prevent debugging (Windows)

Post by Opcode »

BarryG wrote:
Opcode wrote:Here's another method to add to the collection. Easy to implement, easy to bypass. Still something though.

Code: Select all

Procedure PatchDbgUiRemoteBreakin()
  
  Protected.l DbgAddr, oProtect
  
  DbgAddr = GetProcAddress_(GetModuleHandle_("ntdll.dll"), "DbgUiRemoteBreakin")
  
  VirtualProtect_(DbgAddr, 6, #PAGE_EXECUTE_READWRITE, @oProtect)
  
  PokeB(DbgAddr + 0, $68)
  PokeL(DbgAddr + 1, GetProcAddress_(GetModuleHandle_("kernel32.dll"), "ExitProcess"))
  PokeB(DbgAddr + 5, $C3)
  
  VirtualProtect_(DbgAddr, 6, oProtect, @oProtect)
  
EndProcedure
What does this do? And do you just call that procedure alone to protect your exe?
waliedassar wrote:A debugger calls the "DebugActiveProcess" function which ends up with calling the "RtlCreateUserThread" function to create a new remote thread into the target process, with the "DbgUiRemoteBreakin" function as the new thread entry point.
This just patches DbgUiRemoteBreakin so it redirects to ExitProcess. You would just call it once somewhere at the start of your program to apply the patch and that's it.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Anti-piracy tip: Prevent debugging (Windows)

Post by Kwai chang caine »

Excuse me if i disturb this nice expert discussion :oops:
But i read three words together "Debug", "attacking" and "piracy" :shock:

Before in my enterprise, i had W7 and SYMANTEC
Since several weeks i have a new laptop with W10 and always SYMANTEC, but apparently the network admin have choose most strict rule for W10 :|
And since i have this new machine, SYMANTEC see virus everywhere, and the admin want to disable all my USB port, for i can't connect any externals devices :evil:

So i have see a strange behavior, if i run a PB code with debugger mode, immediately SYMANTEC notify a virus, and delete the temporary "PureBasic_Compilation0.exe"....and my admin is notify too :?
If i run the same code without debugger mode, nothing is happening :shock: and i have no explanation of this behavior

Do you believe that my problem has something to do with your discussion ?
Thanks in advance 8)
ImageThe happiness is a road...
Not a destination
Post Reply