Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy-protection for installation media

Copy-protection for installation media

by  Alt255  Posted    (Edited  )
So you have spent several thousand hours working on that killer, to-die-for program that will cause a revolution in Information Technology. You begin to get a little nervous. How can you get every dollar you deserve when there are thousands of neer-do-wells waiting in line to snatch your installation media, copy it and profit from your labor?
This example of code proposes a way to copy-protect your software. It makes at least three assumptions: 1) You have access to MS Quick Basic 4.5 or another programming environment that allows you to use the DOS interrupts (such as MASM), 2) Your application is written in MS Visual Basic and 3) You are able to create a custom setup program, dispensing with the setup.exe provided by the VB Package and Deployment Wizard.
This protection scheme is very simple and begs to be customized to suit your needs. In addition to shipping a CD (or other media) containing your customized setup.exe and its CABS you will ship a floppy that can't be copied. (Well talk about the existential and technological ramifications later.) When a user attempts to install your software the setup program asks for the floppy. If it doesn't find what it expects, the app fails to install.

The Quick Basic 4.5 portion creates the installation key.
[tt]
' $DYNAMIC
DEFINT A-Z[/tt]
' declare the registers[tt]
TYPE RegTypeX
AX AS INTEGER
BX AS INTEGER
CX AS INTEGER
DX AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
FLAGS AS INTEGER
Ds AS INTEGER
ES AS INTEGER
END TYPE
DIM inregs AS RegTypeX, outregs AS RegTypeX
REDIM CDkeys&(1 TO 100)[/tt] 'Allow up to 100 CD Keys[tt]

FOR Sn = 1 TO 100
CDkeys&(Sn) = (31000000 - 1500001) * RND + 1500000
NEXT
[/tt]
' The following file-write only needs to be performed once.
' The file "CDkeys.bin" will be distributed on the installation CD.[tt]
OPEN "CDkeys.bin" FOR BINARY AS #1
FOR Sn = 1 TO 100
PUT #1, , CDkeys&(Sn)
NEXT
CLOSE

RANDOMIZE TIMER
ThisCD& = CDkeys&(INT(100 * RND + 1))[/tt] 'select a CD Key at random[tt]
ThisCD& = ThisCD& \ 512 [/tt] 'Convert to a number small enough to fit in 2 bytes[tt]
X$ = LEFT$(MKL$(ThisCD&), 2)[/tt]
' X$ will go in "total sectors" field of the floppy boot record.

' Get the contents of the boot record[tt]
Sbuffer$ = STRING$(512, 0)
FOR Re = 1 TO 2
inregs.DX = 0: inregs.AX = 0
CALL INTERRUPTX(&H13, inregs, outregs)
inregs.ES = VARSEG(Sbuffer$)
inregs.BX = SADD(Sbuffer$)
inregs.AX = &H201
inregs.CX = &H1
CALL INTERRUPTX(&H13, inregs, outregs)
NEXT

MID$(Sbuffer$, 20, 2) = X$[/tt]
' This sets the apparent size of the floppy anywhere from 1.5mb to 31mb (!!!)
' and encodes the CD Key in a way that it can be understood by Visual Basic.

' Write the CD-Key to the floppy boot record[tt]
FOR Re = 1 TO 2
inregs.DX = 0: inregs.AX = 0
CALL INTERRUPTX(&H13, inregs, outregs)
inregs.ES = VARSEG(Sbuffer$)
inregs.BX = SADD(Sbuffer$)
inregs.AX = &H301
inregs.CX = &H1
CALL INTERRUPTX(&H13, inregs, outregs)
NEXT
[/tt]

The Visual Basic setup.exe checks to see if the apparent size of the floppy matches any of the CD-Keys. No match: no setup, no piracy.
[tt]
Private Sub InstallNow_Click()
On Error GoTo Derror
Dim fs, d, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive("a:")
s = d.TotalSize
Dim CDkeys&(1 TO 100)
Open "CDkeys.bin" FOR BINARY AS #1
For Sn = 1 TO 100
Get #1, , CDkeys&(Sn)
If CDkeys&(Sn) \ 512 = (s \ 512) + 33 Then
OkayToInstall = True
Close #1
SerialNumber& = CDkeys&(Sn)[/tt]
'SerialNumber& will have been declared public at the module level.
'It will be used later to brand the app EXE to prevent it from running without a proper installation.[tt]
Exit Sub
End If
Next
Close #1
MsgBox "Not a valid key disk." & Vbcrlf & "Insert correct disk and try again."
Exit Sub
Derror:
MsgBox "Disk missing from drive A:" & Vbcrlf & "Insert correct disk and try again."
End Sub
[/tt]

More later....
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top