How to generate a serial number?

Just starting out? Need help? Post your questions and find answers here.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

How to generate a serial number?

Post 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?
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: How to generate a serial number?

Post 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.
Last edited by Saki on Sat Sep 05, 2020 10:31 am, edited 1 time in total.
地球上の平和
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to generate a serial number?

Post by infratec »

Use the MAC address. It should be unique.
User avatar
Caronte3D
Addict
Addict
Posts: 1056
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to generate a serial number?

Post 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 :wink:
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: How to generate a serial number?

Post by BarryG »

infratec wrote:Use the MAC address.
The MAC address is easily changed -> https://www.howtogeek.com/192173/how-an ... x-and-mac/
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to generate a serial number?

Post 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. :wink:

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.
Last edited by infratec on Sat Sep 05, 2020 1:39 pm, edited 1 time in total.
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: How to generate a serial number?

Post 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.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: How to generate a serial number?

Post by AMpos »

Mac address should work for me. Anyway, it's there a way to get a hardware Id?
User avatar
Caronte3D
Addict
Addict
Posts: 1056
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to generate a serial number?

Post by Caronte3D »

You can use a mix of: HardDisk SN, Processor,BIOS, MAC, Windows User, and so on...
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: How to generate a serial number?

Post by AMpos »

Yeah, I know. My question is how to read this numbers... :oops:
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to generate a serial number?

Post by infratec »

You have to search for it :wink:

viewtopic.php?f=12&t=26950

MAC address is on page 3
User avatar
Caronte3D
Addict
Addict
Posts: 1056
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to generate a serial number?

Post by Caronte3D »

AMpos wrote:Yeah, I know. My question is how to read this numbers... :oops:
Sometimes is better if you search through google instead of forum it self:
Something like: Purebasic + "whatever you are searching" cast interesting results :wink:
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: How to generate a serial number?

Post 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()
PureBasic: Surprisingly simple, diabolically powerful
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: How to generate a serial number?

Post 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
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: How to generate a serial number?

Post 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
Image Image
Post Reply