?? dialogformfile.cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DialogFormFile.h"
#include "MyClassFile.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DiskInfo"
#pragma resource "*.dfm"
TDialogForm *DialogForm;
TPascalFun *PascalFun; //引用Delphi函數(shù)的類
TMyClass *MyClass; //作者自定義的類
int errornum;//輸入錯誤的次數(shù)
unsigned long BanMove,CDVOL,tmpCDVOL,tmpBanMove;
int ST,ET;
SYSTEMTIME *nowtime=new SYSTEMTIME;
int randnum;
bool succeed;
AnsiString CryptFile;
//---------------------------------------------------------------------------
__fastcall TDialogForm::TDialogForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDialogForm::Decrypt()
{
MyClass->ShowMyMessage(Caption,"正在解口令......");
GetLocalTime(nowtime);
if((ST<=nowtime->wHour&&nowtime->wHour<=ET)||(ST==24&&ET==24))
{ //先釋放文件,再解密
CryptFile=PascalFun->ExportEncryptFile(Application->ExeName);//生成文件的文件名為XXXXXX.exe.gv
succeed=MyClass->DecryptFile(CryptFile,Password->Text,BanMove,CDVOL,3); //生成文件的文件名為XXXXXX.exe
if(!succeed)
errornum++; //如果不能解密,則記錄失敗次數(shù)
if (succeed)
{
MyClass->CloseMyMessage();
errornum=0;
//CryptFile=XXXXXX.exe
CryptFile=CryptFile.SubString(1,CryptFile.Length()-3);
//由于程序先壓縮再加密,所以解密是要先解密再解壓
MyClass->Expand(CryptFile);
//監(jiān)視進(jìn)程,如果它關(guān)閉,我也關(guān)閉
this->Hide();
if(PascalFun->WinExecAndWait32(CryptFile,SW_NORMAL)==0);
{
this->Close();
}}}
else
errornum++; //如果時間不對
MyClass->CloseMyMessage();
switch (errornum)
{
case 1: ShowMessage("文件解密失敗,請檢查您的操作是否符合“加密方式”。");break;
case 2: ShowMessage("文件解密再次失敗!不要緊,請?jiān)俳釉賲枺?quot;); break;
case 3: ShowMessage("很抱歉,又錯了!"); break;
case 4: ShowMessage("經(jīng)過屢敗屢試之后,令我懷疑你是誰。");this->Close();break;
} }
//---------------------------------------------------------------------------
void __fastcall TDialogForm::FormShow(TObject *Sender)
{
repeat:if(Application->MessageBoxA(PascalFun->MypChar("請問解密的時候是否要使用密鑰光盤?"),Application->Title.c_str(),MB_YESNO)==IDYES)
{
DiskInfo->Disk=MyClass->FindCD(DiskInfo);
if(DiskInfo->DiskSize>1) //檢測是否有光盤
tmpCDVOL=abs(DiskInfo->SerialNumber+DiskInfo->DiskSize/1024);
else
{
ShowMessage("沒有找到光盤!");
goto repeat;
}
}
//由于下面使用的BanMove會因讀文件而出錯,所以使用過渡變量
tmpBanMove=MyClass->GetBanMove(DialogForm->DiskInfo,Application->ExeName);
unsigned long filelength;
unsigned char * pszBuffer;
int filehandle;
filehandle=FileOpen(Application->ExeName,fmOpenRead);
filelength=FileSeek(filehandle,0,2);
FileSeek(filehandle,0,0);
pszBuffer=new char [filelength];
FileRead(filehandle,pszBuffer,filelength);
if(pszBuffer[filelength-5]==197)//197為不使用CDVOL的標(biāo)志
CDVOL=19860308;
if(pszBuffer[filelength-5]==38)//38為使用CDVOL的標(biāo)志
{
CDVOL=tmpCDVOL;
}
if(pszBuffer[filelength-5]!=38&&pszBuffer[filelength-5]!=197)
{
ShowMessage(Application->ExeName+" 已損壞!");
goto end;
}
if(pszBuffer[filelength-6]==197)//197為不使用BanMove的標(biāo)志
BanMove=19851120;
if(pszBuffer[filelength-6]==157)//157為使用BanMove的標(biāo)志
{
BanMove=tmpBanMove;
}
if(pszBuffer[filelength-6]!=157&&pszBuffer[filelength-6]!=197)
{
ShowMessage(Application->ExeName+" 已損壞!");
goto end;
}
ET=pszBuffer[filelength-7]-12;//24表示不使用“限時加密”
ST=pszBuffer[filelength-8]-11;
end:FileClose(filehandle);
delete []pszBuffer;
//產(chǎn)生隨機(jī)數(shù)來阻止破解
randomize();
randnum=abs(rand()*1000000000);
Image->Canvas->Font->Size=28;
Image->Canvas->TextOutA(Image->Width/5,Image->Height/10,String(randnum));
}
//---------------------------------------------------------------------------
void __fastcall TDialogForm::PasswordKeyPress(TObject *Sender, char &Key)
{
if(int(Key)==VK_RETURN)
{
if(Password->Text=="") //不使用密碼
Decrypt();//直接解密
if(Password->Text!=""&&InputNumber->Text==String(randnum)) //使用密碼且輸入的數(shù)字正確
Decrypt();//解密
} }
//---------------------------------------------------------------------------
void __fastcall TDialogForm::FormClose(TObject *Sender,
TCloseAction &Action)
{
PascalFun->WipeFile(CryptFile) ;
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -