Page 1 of 2
How to generate a serial number?
Posted: Sat Sep 05, 2020 10:05 am
by AMpos
I want to implement a licensing, generating a serial number from the computer the software is running on (so the program at start will check his licensing against my database).
How do I get a unique serial number, from a computer?
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 10:21 am
by Saki
Hi, just in advance.
Software with such constructions is often hated like the plague and rightly so, as I think myself.
It is possible, business models of windy distributors are based on such a thing, then it is added that you can only install it three times and the software is offered under about five different names.
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 10:31 am
by infratec
Use the MAC address. It should be unique.
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 11:15 am
by Caronte3D
If you want a more robust implementation, you can use "the enigma protector", it's not free, but you have many ways of protect your software.
I was use it sometimes in the past, however infalible protection doesn't exists

Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 11:27 am
by BarryG
infratec wrote:Use the MAC address.
The MAC address is easily changed ->
https://www.howtogeek.com/192173/how-an ... x-and-mac/
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 11:53 am
by infratec
In the properties window, on the “Advanced” tab and select the “Network Address” entry in the “Property” list. If you don’t see this option, then your network driver doesn’t support this feature.
My network drivers don't support this.
Btw.: each 'security' stuff is 'hackable'. It is only a question of 'do I really want to crack it'
And even if someone changes the MAC address, to which address should it be changed?
For this knowledge the user needs an alreday installed version of the software, or he has to test a lot of numbers.
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 12:05 pm
by BarryG
The point I'm making is that if two or more friends have supported MAC addresses that can be changed, then only one has to buy and the others can use his MAC address on their PC to avoid buying.
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 12:13 pm
by AMpos
Mac address should work for me. Anyway, it's there a way to get a hardware Id?
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 12:25 pm
by Caronte3D
You can use a mix of: HardDisk SN, Processor,BIOS, MAC, Windows User, and so on...
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 12:32 pm
by AMpos
Yeah, I know. My question is how to read this numbers...

Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 1:39 pm
by infratec
You have to search for it
viewtopic.php?f=12&t=26950
MAC address is on page 3
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 1:45 pm
by Caronte3D
AMpos wrote:Yeah, I know. My question is how to read this numbers...

Sometimes is better if you search through google instead of forum it self:
Something like: Purebasic + "whatever you are searching" cast interesting results

Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 3:26 pm
by morosh
You can use also the cpu serial number (not my job):
Code: Select all
Procedure.s GetCPUSerialNumber()
Define highbits.l
Define lowbits.l
Define serial.q
!MOV eax, $80000003
!CPUID
!MOV dword [p.v_lowbits], ecx
!MOV dword [p.v_highbits], edx
serial = lowbits | highbits << 32
ProcedureReturn Hex(serial,#PB_Quad)
EndProcedure
Debug GetCPUSerialNumber()
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 4:00 pm
by J. Baker
Online and hardware activation sucks when the developer ups and quits development and you no longer can activate your purchased software. Here's some code. Read the comments.
Code: Select all
;-Run this bit of code in a separate progam to create the encrupted key.
UseSHA2Fingerprint()
Debug StringFingerprint("G4112h78ab", #PB_Cipher_SHA2)
;-Use this in your actual program so a user can activate their software.
Activation.a = 0
If OpenWindow(0, 0, 0, 310, 40, "Verify Key", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 200, 20, "")
ButtonGadget(1, 210, 10, 100, 20, "Activate")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If Activation = 0 ;-You will have to figure out how to store Activation if it equals 1 on your own.
If StringFingerprint(GetGadgetText(0), #PB_Cipher_SHA2) = "048339c50de4e5f29f5c91c7eba9c9a0a3e294fea0fa684193664f21f6c0a78c"
Debug "Yahoo!"
Else
Debug "Incorrect Key"
EndIf
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: How to generate a serial number?
Posted: Sat Sep 05, 2020 9:31 pm
by Paul
Just a note... anyone who is wanting a simple licensing system "to protect their software" needs to be aware that once their application is compiled/assembled it can also be disassembled.
You can end up spending more time trying to protect your software than actually developing it.
For example, in J.Baker's code the line that checks if the correct code has been entered...
Code: Select all
If StringFingerprint(GetGadgetText(0), #PB_Cipher_SHA2) = "048339c50de4e5f29f5c91c7eba9c9a0a3e294fea0fa684193664f21f6c0a78c"
Of course mean "If entered code" = "Correct Code" then "Success"
and in ASM the "=" is "JE" , jump if equal, or opcode $74
Now if you reverse this logic you get...
"If entered code"
<> "Correct Code" then "Success"
and in ASM the "<>" is "JNE", jump not equal, or opcode $75
Poke can easily change $74 to $75 so incorrect code will always give "Success".
A very simplified example... compile J.Baker's code to "MyApp.exe" either 64bit or 32bit
Code: Select all
UseSHA2Fingerprint()
Activation.a = 0
If OpenWindow(0, 0, 0, 310, 40, "Verify Key", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 200, 20, "")
ButtonGadget(1, 210, 10, 100, 20, "Activate")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If Activation = 0 ;-You will have to figure out how to store Activation if it equals 1 on your own.
If StringFingerprint(GetGadgetText(0), #PB_Cipher_SHA2) = "048339c50de4e5f29f5c91c7eba9c9a0a3e294fea0fa684193664f21f6c0a78c"
MessageRequester("Success","Yahoo!")
Else
MessageRequester("Error","Incorrect Key")
EndIf
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Now run the following code which will scan through your compiled EXE and find the $74, change it to $75 and save it as a new EXE
This demonstrated how modifying a single byte in a file can totally change it's behavior.
Code: Select all
file$="C:\MyApp.exe"
hFile=ReadFile(#PB_Any,file$)
If hFile
lf=Lof(hFile)
*buf=AllocateMemory(lf)
ReadData(hFile,*buf,lf)
CloseFile(hFile)
For tmp=0 To lf-3
If (PeekA(*buf+tmp)=$74 And PeekA(*buf+tmp+1)=$28 And PeekA(*buf+tmp+2)=$48 And PeekA(*buf+tmp+3)=$B8) Or ;64bit EXE byte sequence
(PeekA(*buf+tmp)=$74 And PeekA(*buf+tmp+1)=$13 And PeekA(*buf+tmp+2)=$B8) ;32bit EXE byte sequence
PokeA(*buf+tmp,$75)
hFile=CreateFile(#PB_Any,GetPathPart(file$)+GetFilePart(file$,#PB_FileSystem_NoExtension)+"-patched.exe")
If hFile
WriteData(hFile,*buf,lf)
CloseFile(hFile)
Debug "File Patched"
EndIf
FreeMemory(*buf)
Break
EndIf
Next
EndIf