unit ISDNUNIT;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSrbIoControl=packed record
HeaderLength: ULONG;
Signature: Array[0..7] of char;
Timeout: ULONG;
ControlCode: ULONG;
ReturnCode: ULONG;
Length: ULONG;
END;
SRB_IO_CONTROL=TSrbIoControl;
PSrbIoControl=^TSrbIoControl;
TIDERegs=packed record
bFeaturesReg: Byte;
bSectorCountReg: Byte;
bSectorNumberReg: byte;
bCyllowReg: byte;
bCylhighreg:byte;
bDriveHeadReg: byte;
bCommandReg: byte;
bReserved: byte;
end;
IDEREGS=TIDERegs;
PIDERegs=^TIDERegs;
TSendCmdInParams=packed record
cBufferSize: DWORD;
irDriveRegs: TIDEREGS;
bDriveNumber:byte;
bReserved: Array[0..2] of byte;
dwReserved: Array[0..3] of DWORD;
bBUFFER: array[0..10] of byte;
end;
SENDCMDINPARAMS=TSendCmdInParams;
PSendcmdinparams=^Tsendcmdinparams;
TIdSector=packed record
wGenConfig: word;
wNumCyls: word;
wReserved: word;
wNumHeads: word;
wBytesPerTrack: word;
wBytesPerSector:word;
wSectorsPerTrack:word;
wVendorUnique: array[0..2] of word;
sSerialNumber: Array[0..19] of char;
wBufferType: word;
wBufferSize : word;
wECCSize: word;
sFirmwareRev: array[0..7] of char;
sModelNumber: array[0..39] of char;
wMorevendorUnique: word;
wDoubleWordIO: WORD;
wcapabilities:word;
wreservedL:word;
wPIOTiming:word;
wDMATiming:word;
wBS:WORD;
wNUMcurrentCYls:word;
wNUMcurrentHeads:word;
wNUMCurrentsectorsPerTRACK:WORD;
ulCurrentSectorCapacity:ULONG;
wMultSectorStuff:Word;
ulTotalAddressableSectors:ULONG;
wSingleWordDMA:Word;
wMultiwordDMA:word;
bReserved: Array[0..127] of byte;
end;
PIdSector=^TidSECTOR;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
// procedure ChangeByteorder(var data; Size:INTEGER);
// Function readhdserial:string;
// FUNCTION ENCRyPT(serial:string):string;
var
Form1: TForm1;
serial:string;
inputserial:string;
CONST
IDENTIFY_BUFFER_SIZE=512;
DataSize=sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;
IOCTL_SCSI_MINIPORT=$0004d008;
IOCTL_SCSI_MINIPORT_IDENTIFY=$001b0501;
IDE_ID_FUNCTION=$EC;
BufferSize=1280;
implementation
{$R *.DFM}
procedure ChangeByteorder(var data; size:integer);
var
ptr
Char;
i:INTEGER;
C:CHAR;
BEGIN
ptr:=@data;
for i:=0 to (size shr 1)-1 do
begin
c:=ptr^;
ptr^:=(ptr+1)^;
(ptr+1)^:=c;
Inc(ptr,2);
end;
end;
function readhdserial:string;
var
hDevice:THandle;
cbBYTESReturned
WORD;
pindata
SendCmdInParams;
//pide
ideregs;
pOutData
ointer;
Buffer:Array[0..BufferSize-1] of Byte;
srbCONTROL:tSrbIoControl absolute Buffer;
begin
result:='';
Fillchar(Buffer,buffersize,#0);
hDevice:=CreateFile('//./Scsi0:',GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
if hDevice=INVALID_HANDLE_VALUE then exit;
try
srbControl.HeaderLength:=sizeof(SRB_IO_CONTROL);
System.Move('SCSIDISK',srbControl.signature,8);
srbcontrol.timeout:=2;
srbcontrol.Length:=datasize;
srbcontrol.ControlCode:=IOCTL_SCSI_MINIPORT_IDENTIFY;
pInData:=PSendCmdInparams(pchar(@buffer)+sizeof(SRB_IO_CONTROL));
pOutData:=pInData;
with pInDATA^ DO
begin
cBuffersize:=IDENTIFY_BUFFER_SIZE;
bDriveNumber:=0;
// irDriveRegs:=0;
with irDriveRegs do
begin
bFeaturesreg:=1;
bsectorcountreg:=1;
bsectornumberreg:=1;
bcyllowreg:=0;
bcylhighreg:=0;
bdriveheadreg:=$A0;
bcommandreg:=IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl(hDevice,IOCTL_SCSI_MINIPORT,
@Buffer,BufferSize,@buffer,buffersize,cbbytesreturned,nil) then
exit;
with Pidsector(pchar(poutdata)+16)^ do
begin
changebyteorder(sSerialNUMber,sizeof(sserialnumber));
setstring(result,sserialnumber,sizeof(sserialnumber));
end;
finally
closehandle(hdevice);
end;
end;
function encrypt(serial:string):string;
var
i
woRD;
LEN
WORD;
R
WORD;
begin
R:=0;
LEN:=LENGTH(SERIAL);
FOR I:=1 TO LEN DO
BEGIN
R:=R+DWORD(SERIAL
);
R:=R * 10;
END;
RESULT:=INTTOSTR(R);
END;