Use the installer to prevent unauthorized copying of software
Every user does not want their own software to be easily copied and used by others. Naturally, they remember to encrypt the software. This article mainly introduces a method of copying software by installing programs to prevent illegal copying of software. It has been proved that this method is very suitable for the scenario where the software needs to be installed on the hard disk.
I. Working Principle
By setting a special unit in the encrypted software, an installer loads the encrypted software into the specified hard disk (C, D, E, and so on) partition. In the process of copying and attaching a hard disk, fill in the first cluster number of the encrypted software in the hard disk to the specified unit. At the same time, an inspection Program is embedded in the encrypted software. When the encrypted software runs on the hard disk, the Inspection Program first checks whether the first cluster number of the encrypted software on the hard disk is the same as the content of the specified unit in its own program. Otherwise, the software is deemed to have been illegally copied and the operation of the software is terminated. If they are equal, the software is considered to have been properly installed by the installer, allowing the software to continue running.
This method uses some in-depth knowledge of DOS interrupt calls for file operations, such as 11 h, 1ah, 3ch, 3DH, 3eh, 3fh, 40 h of int21h interrupt, 42h function call and file control block (FCB) data format. Here is a brief introduction. For more detailed usage instructions, see documents.
1. Int 21h interrupt function call
① Int 21 interrupts the 11h Function
Purpose: Find the matching file name in the current directory of the specified disk.
Call: Ah = 11 h
DS: DS = file control block: displacement
Return: Al = 00. succeeded. The matching file name is found.
Al = 0ffh, failed, no matching file name found
② Int 21 interrupts the 1ah Function
Purpose: set the disk transfer zone address
Call: Ah = 1ah
DS: dx = disk transmission segment: displacement
Return: None
③ Int 21 interrupts the 3ch Function
Purpose: create a file
Call: Ah = 3ch
Cx = file attribute, 00 h: Standard, 01 H: Read-only, 02 h: implicit, 04 H: System
DS: dx = file description section: displacement
Return: Successful
Carry Sign = clear
Ax = file description
Failed
Carry flag = Set
Ax = Error code, 3: path not found, 4: no description available, 5: Access Denied
④ Int 21 interrupts the 3DH number Function
Purpose: open a file
Call: Ah = 3DH
Al = access mode, 000: read, 001: Write, 010: read/write
DS: dx = file description section: displacement
Return: Successful
Carry Sign = clear
Ax = file description
Failed
Carry flag = Set
Ax = Error code, 1: Invalid function number, 2: file not found, 3: path not found,
4: no description available, 5: Access Denied
⑤ Int 21 interrupts the 3eh Function
Purpose: close a file.
Call: Ah = 3eh
BX = file description
Return: Successful
Carry Sign = clear
Failed
Carry flag = Set
Ax = Error code, 6: Invalid description
⑥ Int 21h interrupts the 3fh Function
Purpose: Read files.
Call: Ah = 3fh
BX = file description
Cx = number of read bytes
DS: dx = segment: Buffer Zone Displacement
Return: Successful
Carry Sign = clear
Ax = actual number of read bytes, 0: End of File
Failed
Carry flag = Set
Ax = Error code, 5: Access Denied, 6: no description available
7. Int 21h interrupt the 40 h Function
Purpose: Write a file.
Call: Ah = 40 h
BX = file description
Cx = number of written bytes
DS: dx = buffer segment: displacement
Return: Successful
Carry Sign = clear
Ax = actual number of writing segments, 0: full disk
Failed
Carry flag = Set
Ax = Error code, 5: Access Denied, 6: no description available
⑧ Int 21h interrupts the 42h Function
Purpose: Move the file pointer.
Call: Ah = 42 h
Al = mode code, 0: absolute byte displacement starting from the file
1: byte displacement from the current position
2: byte shift from the end of the file
BX = file description
Cx = the most effective half displacement (high)
DX = second valid half displacement (low words)
Return: Successful
Carry Sign = clear
DX = the most effective half displacement (high)
Ax = second valid half displacement (low words)
Failed
Carry flag = Set
Ax = error code. 1: Invalid function number and 6: Invalid description word
2. File control block (FCB) Data Format
Drive letter, "file name extension"
For the drive letter, 1: a drive, 2: B Drive, 3: C drive, 4: D Drive, and so on.
For file names and extensions, a file is constructed in 8.3 format, with a total of 11 characters. The file name cannot exceed 8 characters and must be filled with spaces.
For example, DB 4, 'My _ run com ', 21 DUP (?)
Define a file control block named my_run.com on a drive D.
II. Implementation Method
The following two procedures are provided: one is the installation program and the other is the Inspection Program. The following figure shows the working process:
Hard disk memory floppy disk
┌ ── ─ ┐
├ ── ─ ┤ ① ├ ── ─ ┤
│ Directory area │ ── ─ ── ┤ │
│ First cluster No. ─ ── %③ ── │ installer │
├ ── ─ ┤ └ ── → │ Buffer │ ② ├ ── ─ ┤
│ Data zone │ ── encrypted file │
│ Encrypted file │ ── ─ encrypted file │ (including inspection procedures) │
│ (Including inspection procedures) │ ④ │ (including inspection procedures) │ ── ─ ┤
├ ── ┤ │
│
└ ── ─ ┘ └ ──
① Use the installer to copy the encrypted software on the floppy disk to the hard disk. In this way, a directory item can be generated in the directory area of the hard disk and a first cluster number can be determined for the file.
② Send encrypted files on a floppy disk to the memory buffer.
③ Send the first cluster number of the encrypted file on the hard disk to the specified unit in the file encrypted in the memory buffer.
④ Save the contents of the encrypted file in the memory buffer to the encrypted file on the hard disk.
3. One demo
; ***** My_inst.asm ****
Code segment
Assume Cs: code, DS: code, ES: Code
Org 100 h
Begin:
MoV dx, offset dime_2; open the my_run.com file on disk
MoV Al, 2
MoV ah, 3DH
Int 21 h
Push ax; save the file handle
MoV BX, ax
MoV CX, 0fff0h
MoV dx, offset dime_0; read my_run.com on disk A to the memory
MoV ah, 3fh
Int 21 h
Pop BX
Push ax; save the file handle
MoV ah, 3eh; close the file
Int 21 h
MoV dx, offset dime_1; create the my_run.com file on drive D.
MoV CX, 20 h
MoV ah, 3ch
Int 21 h
Push ax; save the file handle
MoV dx, offset dime_0
Pop BX
Pop CX
Push BX
MoV ah, 40 h; write my_run.com content in memory to disk D my_rum.com
Int 21 h
Pop BX
MoV ah, 3eh
Int 21 h; close the file
MoV dx, offset dime_3
MoV ah, 1ah; set the disk transfer address
Int 21 h
MoV dx, offset dime_4
MoV ah, 11 h; find directory items
Int 21 h
MoV dx, offset dime_1
MoV ah, 3DH
MoV Al, 02 h
Int 21 h; open the file
Push ax; save the file handle
MoV BX, ax
MoV ax, 4200 H
MoV CX, 0
MoV dx, word PTR dime_5; move the file pointer to the specified unit of my_run.com
Int 21 h
Pop BX
MoV ah, 40 h
MoV dx, offset dime_3 + 1bh; buffer 26th and 27 bytes are the first cluster number of the file on the hard disk.
MoV CX, 2
Int 21 h; write the first cluster number of the my_run.com file to the file.
MoV ah, 3eh
Int 21 h; close the file
MoV ax, 4c00h
Int 21 h; returns DoS
Dime_0 dB 7000 h dup (?); Open up a data zone to store Encrypted Files
Dime_1 DB "D: my_run.com", 0
Dime_2 DB "A:/my_run.com", 0
Dime_3 dB 40 h DUP (?); Memory buffer with 40 h bytes retained
Dime_4 DB 4, "my_run com", 21 DUP (?); File control block data format
Dime_5 DW 0064 H
Code ends
End begin
; ***** My_run.asm ****
Code segment
Assume Cs: code, DS: code, ES: Code
Org 100 h
Begin:
JMP start
Dime_1 dB 40 h DUP (0); reserved 40 h Buffer
Dime_2 DB 4, "my_run com", 21 DUP (0); file control block data format
Dime_3 db 0, 0
Start:
MoV ah, 1ah
MoV dx, offset dime_1; set the data transmission address
Int 21 h
MoV ah, 11 h
MoV dx, offset dime_2; find directory items
Int 21 h
MoV Di, offset dime_3
MoV Si, offset dime_1 + 1bh; directory item 26th and 27 bytes are the first cluster number of the file
MoV CX, 2
ClD
Repz cmpsb; compare whether the actual first cluster number of the file in disk D is equal to the value of unit dime_3 of the file
JZ exit1; equal, convert
MoV ah, 09 h; not equal
MoV dx, offset msg2; alert message
Int 21 h
MoV ax, 4c00h; terminate the program and return DoS
Int 21 h
Exit1:
MoV ah, 09 h
MoV dx, offset msg1; displays the correct information to continue running the program
Int 21 h
MoV ax, 4c00h
Int 21 h
Msg1 DB "Copyright is good", 0dh, 0ah, '$'
Msg2 dB 07,07, "Copyright is invalid", 0dh, 0ah, 0dh, 0ah
DB "copyright by 607 Software Group 1999", 0dh, 0ah, '$'
Code ends
End begin
In this article, the two programs my_inst.asm and my_run.asm are compiled and connected to generate COM files under Turbo MASM V2.0, and are debugged under dos6.22.
Iv. Usage
During use, insert the files containing my_inst.com and my_run.com to drive a, and run the my_inst.com file to copy my_run.com on the floppy disk to the current directory of the hard disk (such as partition D. & 127; when running my_run. & 127; COM file, & 127; & 127; if the verification program prompts "Copyright is good", the program is installed on the hard disk through the installation program my_inst.com on the floppy disk. If you use the copy command or other tools to copy my_run.com on the floppy disk to drive D and run the command & 127; then the system prompts & 127; "Copyright & 127; is & 127; invalid "& 127; & 127;," copyright by 607 Software Group 1999 "indicates that the program is obtained through illegal copying.
V. Conclusion
Finally, I want to explain that the method described above is only a demo, which aims to serve as an example. In specific applications, You can embed the verification program my_run.com into the software you want to encrypt, and install the program using my_inst. & 127; COM. In order to better protect the software, the following aspects should also be considered. ① To enhance security, you can set the "First cluster number" in the encrypted software for inspection. ② To prevent copying the installer, you can destroy the installer after completing its functions. You can enter disordered data to destroy the functions of the installation program. ③ The key technology can be combined with the key technology used to install a floppy disk. When the software is encrypted or the installation program runs, the key of the floppy disk can be checked to prevent replication of the installer.