Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- DWORD __fastcall TForm1::GetDiskSNo(void)
- {
- LPTSTR lpRootPathName="A:";
- LPTSTR lpVolumeNameBuffer=new char[12];
- DWORD nVolumeNameSize=12;
- DWORD lpVolumeSerialNumber;
- DWORD lpMaximumComponentLength;
- DWORD lpFileSystemFlags;
- LPTSTR lpFileSystemNameBuffer=new char[10];
- DWORD nFileSystemNameSize=10;
- GetVolumeInformation(
- lpRootPathName,
- lpVolumeNameBuffer,
- nVolumeNameSize,
- &lpVolumeSerialNumber,
- &lpMaximumComponentLength,
- &lpFileSystemFlags,
- lpFileSystemNameBuffer,
- nFileSystemNameSize);
- return lpVolumeSerialNumber;
- }
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- int ff;
- DWORD dd;
- dd=GetDiskSNo();
- dd^=0x87654321;
- ff = FileCreate("A:\sec.sno");
- if(ff==-1)
- {
- ShowMessage("加密不成功!");
- }
- FileWrite(ff, &dd,sizeof(dd));
- FileClose(ff);
- Edit1->Text=IntToHex((int)dd,1);
- ShowMessage("加密成功!");
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- int ff;
- DWORD dd,dd1;
- dd=GetDiskSNo();
- ff = FileOpen("A:\sec.sno",fmOpenRead);
- if(ff==-1)
- {
- ShowMessage("没有加密文件!");
- }
- FileRead(ff, &dd1,sizeof(dd1));
- FileClose(ff);
- dd1^=0x87654321;
- Edit1->Text=IntToHex((int)dd,1);
- if(dd==dd1)
- ShowMessage("读加密成功!");
- else
- ShowMessage("不是我的加密盘!");
- }
- //---------------------------------------------------------------------------