📄 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函数的类
TMyClass *MyClass; //作者自定义的类
int errornum;//输入错误的次数
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++; //如果不能解密,则记录失败次数
if (succeed)
{
MyClass->CloseMyMessage();
errornum=0;
//CryptFile=XXXXXX.exe
CryptFile=CryptFile.SubString(1,CryptFile.Length()-3);
//由于程序先压缩再加密,所以解密是要先解密再解压
MyClass->Expand(CryptFile);
//监视进程,如果它关闭,我也关闭
this->Hide();
if(PascalFun->WinExecAndWait32(CryptFile,SW_NORMAL)==0);
{
this->Close();
}}}
else
errornum++; //如果时间不对
MyClass->CloseMyMessage();
switch (errornum)
{
case 1: ShowMessage("文件解密失败,请检查您的操作是否符合“加密方式”。");break;
case 2: ShowMessage("文件解密再次失败!不要紧,请再接再厉!"); break;
case 3: ShowMessage("很抱歉,又错了!"); break;
case 4: ShowMessage("经过屡败屡试之后,令我怀疑你是谁。");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的标志
CDVOL=19860308;
if(pszBuffer[filelength-5]==38)//38为使用CDVOL的标志
{
CDVOL=tmpCDVOL;
}
if(pszBuffer[filelength-5]!=38&&pszBuffer[filelength-5]!=197)
{
ShowMessage(Application->ExeName+" 已损坏!");
goto end;
}
if(pszBuffer[filelength-6]==197)//197为不使用BanMove的标志
BanMove=19851120;
if(pszBuffer[filelength-6]==157)//157为使用BanMove的标志
{
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;
//产生随机数来阻止破解
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)) //使用密码且输入的数字正确
Decrypt();//解密
} }
//---------------------------------------------------------------------------
void __fastcall TDialogForm::FormClose(TObject *Sender,
TCloseAction &Action)
{
PascalFun->WipeFile(CryptFile) ;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -