Page 1 of 1

PB DLL Protector - beta 1

Posted: Thu Apr 27, 2006 10:39 am
by netmaestro
Ok, I'm probably going to get shot down real fast as I've never tried anything like this before. But I post for your target practice a little library which might develop into a protection system for PB 4 dlls. The aim is to provide a way for a dll producer to be reasonably confident that his dll cannot be run from a programming language other than PB 4.

You are invited to download the library (just 2 commands) and show me just how easy it is to beat it. As PureBasic v3.94 is considered a "foreign language" by the protector, perhaps you can try to break it with that. I hope you'll help me test this thing, if nothing else it should be a bit of fun.

PrepareAuthCode()

The PrepareAuthCode() command prepares a key that a calling program must supply
to a protected dll in order to call its functions. While the less said about the key the
better, suffice to say that many steps have been taken to protect the key from being
copied, examined, or created from a "cheater" dll. If a user attempts to create a dll in
PB 4 that calls the PrepareAuthCode() function and returns the code, unlicensed usage
will be detected. The command must be executed from a toplevel process that has a
window at least 640*480 in size, is foreground and visible.

Code: Select all

; Example of authorized usage
; The window must be foreground, visible and at least 640*480 in size
; A screen is ok too
;
OpenWindow(0,0,0,640,480,"DLLAuth Library Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
vcode=PrepareAuthCode()

OpenLibrary(0,"secured.dll")
CallFunction(0,"Init",vcode)
CallFunction(0,"ShowBox")

Repeat:Until WaitWindowEvent()=#WM_CLOSE
ExamineAuthCode(vcode)

Code: Select all

; Example of a dll you might write that protects itself
; with the PB DLL Protector
;
Global auth_ok

ProcedureDLL Init(key)
  If ExamineAuthCode(key)
    auth_ok = #True
  Else
    auth_ok = #False
  EndIf
EndProcedure

ProcedureDLL ShowBox()
  If Not auth_ok
    ProcedureReturn 0
  EndIf
  MessageRequester("Notice","I'm doing this because I'm called by a PureBasic program!")
EndProcedure
And here's the link:http://www.networkmaestro.com/DLLAuth.zip ...** /me ducks **

Posted: Thu Apr 27, 2006 12:00 pm
by dell_jockey
EDIT: removed my message, didn't make sense...

Posted: Thu Apr 27, 2006 12:01 pm
by netmaestro
No, it shouldn't. I spent a fair amount of effort in detecting that sort of implementation, so hopefully it will work.

[edit] No, it made perfect sense! I had to jump through several hoops to teach the key generator to defend against just that.

Posted: Thu Apr 27, 2006 12:04 pm
by dell_jockey
netmaestro wrote:No, it shouldn't. I spent a fair amount of effort in detecting that sort of implementation, so hopefully it will work.

[edit] No, it made perfect sense! I had to jump through several hoops to teach the key generator to defend against it.
Why would you want to limit DLL usage to a single programming language? What's in it for me as a programmer?

Posted: Thu Apr 27, 2006 12:15 pm
by netmaestro
For me it's mostly for fun, to see if I can do it. But some programmers have expressed an interest in the functionality.

Posted: Thu Apr 27, 2006 1:54 pm
by SFSxOI
Its interesting but why bother to do this at all to begin with?

Are you talking about a .dll produced with PB and can only run with PB - right? Will this not cause problems with producing an application in PB and then distributing it (legally) with a .dll produced for the application - will it not cause problems because of a non-standard method employed in the .dll or because a PB4 runtime module (or something or other from PB 4 is not installed on the computer the distributed application is installed on??

Theres probably a reason why .dll's are generally not done this way to begin with isn't there?

So what happens if I produce a .dll in say PB 4, then later upgrade in the future to PB5, will the .dll still work?

If its got real functions in the .dll can it be extracted to a library and used that way?

Posted: Thu Apr 27, 2006 7:52 pm
by netmaestro
Once the dll is compiled and distributed with its calling program it will run on any target machine. The end user's computer doesn't need any PB components installed.

Future versions of PureBasic won't break the functionality.

Extracting the functions with DLL2Lib-style tools isn't a way to defeat the protection as each function checks for the code having been verified before proceeding.

Posted: Thu Apr 27, 2006 8:05 pm
by thefool
the way of cracking this protection is to patch the dll at the point where it compares the key one that works. (other places i can think of would be where it checks if the key was correct, at the other procedures.
a third method would be to switch the FALSE value in memory with a TRUE.

Posted: Thu Apr 27, 2006 9:22 pm
by netmaestro
Why would you want to limit DLL usage to a single programming language? What's in it for me as a programmer?
I can think of one good reason right away. I can personally make use of this (if it turns out to actually work) with my Transpetris program. I charge nine bucks for it on my website, but I wouldn't dream of asking money for it from the people on the PB forum. I've gotten too much help with various projects from people here, anything I can give back is the least I can do. But if you google Transpetris, the freely available version found on this forum comes right up. :evil: If I were to convert that to a protected dll and post a code snippet of how to call it, it becomes available free of charge to PB folks and useless to anyone else. They want it, it's nine bucks. For you - free. :wink:

Posted: Tue May 02, 2006 4:17 pm
by Thade
This is the same as if Adobe would say ... You can create and save your jpgs with photoshop, but they are protected so you cannot use them in IE or in Paint Shop Pro or anywhere else.. other than Adobe Photoshop.
More examples wanted?
A car manufacturer building cars you can only drive on roads in china...
ID Software producing PC-Games you can only play on Model XF800 of Drell Computers

Who needs this?

Have you ever thought that Microsoft could say: You are not allowed to use my software to make money with it? Then each producer of Software is illegal...
Or they could say ... you are not allowed using Pure Basic to produce DLLs at all, because they all are based on our API development ?
And then?
Or they could say ... Pure Basic is illegal because its completely based on our technology ?

There are enough stupid ideas in the world ...

It is a good idea to protect a dll, that only authorized people can use it ... but what you announce ... sorry to say it that harsh (but its needed to express my view on it) ... its imbecile rubbish

Posted: Tue May 02, 2006 4:23 pm
by netmaestro
Thank you. I can see where a tool like this would be of no use to you. You have my permission to ignore it.

Posted: Tue May 02, 2006 6:00 pm
by Trond
Thade wrote:Have you ever thought that Microsoft could say: You are not allowed to use my software to make money with it?
Borland Delphi is cheaper if you buy the "personal" version. And you're not allowed to make money with it.

By the way, this can be very easily cracked no matter what you do.

Posted: Tue May 02, 2006 7:39 pm
by SFSxOI
Been playing around with the example you gave in your original post. I see some possibilities for use, or at least i'm thinking of some. The thing about cracking, or getting around, the protection tho is maybe worth exploring some more. At least it will keep the casual novice type people at bay for a bit. Will you let us know of your progress? I'm interested, and while i'm no expert I can see possibilities.

Wheres the free version of Transpertis at? :) Just kidding.

I'm gonna pay the $9.00 for it 'cause after dabbling in this stuff for a while now i realize that some of it isn't easy and I think you deserve what ever you charge for it.
netmaestro wrote:
Why would you want to limit DLL usage to a single programming language? What's in it for me as a programmer?
I can think of one good reason right away. I can personally make use of this (if it turns out to actually work) with my Transpetris program. I charge nine bucks for it on my website, but I wouldn't dream of asking money for it from the people on the PB forum. I've gotten too much help with various projects from people here, anything I can give back is the least I can do. But if you google Transpetris, the freely available version found on this forum comes right up. :evil: If I were to convert that to a protected dll and post a code snippet of how to call it, it becomes available free of charge to PB folks and useless to anyone else. They want it, it's nine bucks. For you - free. :wink:

Posted: Tue May 02, 2006 7:45 pm
by netmaestro

Re: PB DLL Protector - beta 1

Posted: Tue May 02, 2006 7:58 pm
by Berikco
netmaestro wrote:Ok, I'm probably going to get shot down real fast ...** /me ducks **
Damn, i read this to late...
Better late dan never...
Image

:lol: