⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decryptformfile.cpp

📁 可以使用硬件指纹作为密钥加密文件
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "MyClassFile.h"
#include "EncryptFormFile.h"
#include "AddShellFormFile.h"
#include "AboutFormFile.h"
#include "DecryptFormFile.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "XPMenu"
#pragma link "DiskInfo"
#pragma link "Explform"
#pragma resource "*.dfm"
TDecryptForm *DecryptForm;
TMyClass *MyClass;  //作者自定义的类
TPascalFun *PascalFun; //引用Delphi函数的类
int errornum;//输入错误的次数
unsigned long BanMove,CDVOL,tmpCDVOL;
//---------------------------------------------------------------------------
__fastcall TDecryptForm::TDecryptForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::EncryptFileClick(TObject *Sender)
{
EncryptForm->Show();
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::StartDecryptClick(TObject *Sender)
{
if(FileList->Items->Text.Length()<1)
{
   ShowMessage("请先选择欲解密的文件!");
   return;
}
int filehandle,ST,ET;
SYSTEMTIME *nowtime=new SYSTEMTIME;

unsigned long filelength;
unsigned char * pszBuffer;
bool succeed;
TStringList *DecryptFileList=new TStringList;
TStringList *UnDecryptFileList=new TStringList;

MyClass->ShowMyMessage("解密普通文件","正在解密文件......");

for(int i=0;i<FileList->Items->Count;i++) //循环解密
{
filehandle=FileOpen(FileList->Items->Strings[i],fmOpenReadWrite);
filelength=FileSeek(filehandle,0,2);
FileSeek(filehandle,0,0);
pszBuffer=new char [filelength];
FileRead(filehandle,pszBuffer,filelength);
if(pszBuffer[filelength-1]==197)//197为不使用CDVOL的标志
   CDVOL=19860308;
if(pszBuffer[filelength-1]==38)//38为使用CDVOL的标志
{
  CDVOL=tmpCDVOL;
}
if(pszBuffer[filelength-1]!=38&&pszBuffer[filelength-1]!=197)
   { //记录出错的文件
    UnDecryptFileList->Add(FileList->Items->Strings[i]);
     goto end;
   }
if(pszBuffer[filelength-2]==197)//197为不使用BanMove的标志
   BanMove=19851120;
if(pszBuffer[filelength-2]==157)//157为使用BanMove的标志
{
   DiskInfo->Disk='C';
   BanMove=abs(DiskInfo->SerialNumber);
}
if(pszBuffer[filelength-2]!=157&&pszBuffer[filelength-2]!=197)
   { //记录出错的文件
   UnDecryptFileList->Add(FileList->Items->Strings[i]);
    goto end;
   }

ET=pszBuffer[filelength-3]-12;//24表示不使用“限时加密”
ST=pszBuffer[filelength-4]-11;
GetLocalTime(nowtime);
end:FileClose(filehandle);
delete []pszBuffer;
if((ST<=nowtime->wHour&&nowtime->wHour<=ET)||(ST==24&&ET==24))
{
 if(ExtractFileExt(FileList->Items->Strings[i])==".gv")//如果是加密文件
  succeed=MyClass->DecryptFile(FileList->Items->Strings[i],Password->Text,BanMove,CDVOL,3);
 if(ExtractFileExt(FileList->Items->Strings[i])==".coco")//如果是加密文件包
  {
   succeed=MyClass->DecryptFile(FileList->Items->Strings[i],Password->Text,BanMove,CDVOL,0);
   if(succeed)
   {AnsiString FileName;
   MyClass->Expand(FileList->Items->Strings[i]);
   try
   {
   ADOTable->LoadFromFile(FileList->Items->Strings[i]);
   ADOTable->First();//指针移到第一项数据
   while(!ADOTable->Eof)//从头读到尾
   {
   FileName=ADOTable->FieldByName("FileName")->Value;
   TMemoryStream  *stream=new TMemoryStream;
   PascalFun->LoadFromPackage(ADOTable,stream);
   stream->SaveToFile(ExtractFileDir(FileList->Items->Strings[i])+"\\"+FileName);
   stream->Free();
   ADOTable->Next();
   }
   DeleteFile(FileList->Items->Strings[i]);
   }
   catch (...)
   {
   ShowMessage("读取文件包出错!");
   }}}
 if (succeed)
   DecryptFileList->Add(FileList->Items->Strings[i]);

 if (!succeed)
   UnDecryptFileList->Add(FileList->Items->Strings[i]);
}
}
if(UnDecryptFileList->Text.Length()>1)
{//如果没有解开一个文件,则记录错误
  errornum++;
}
MyClass->CloseMyMessage();//关闭提示窗口
if(DecryptFileList->Text.Length()>1)
{
 ShowMessage("成功解密以下文件:\n"+DecryptFileList->Text);
TCloseAction *Action;
DecryptForm->FormClose(Sender,*Action);
 errornum=0;
}
if(UnDecryptFileList->Text.Length()>1)
 ShowMessage("以下文件解密失败:\n"+UnDecryptFileList->Text);
FileList->Items->Text=UnDecryptFileList->Text;
DecryptFileList->Free();
UnDecryptFileList->Free();

switch (errornum ){
case 1: ShowMessage("文件解密失败,请检查您的操作是否符合“加密方式”。");break;
case 2: ShowMessage("文件解密再次失败!不要紧,请再接再厉!"); break;
case 3: ShowMessage("很抱歉,又错了!"); break;
case 4: ShowMessage("经过屡败屡试之后,令我怀疑你是谁。"); Application->Terminate();break;
}

}
//---------------------------------------------------------------------------

void __fastcall TDecryptForm::OpenAboutClick(TObject *Sender)
{
AboutForm->Show();
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::AddShellClick(TObject *Sender)
{
AddShellForm->Show();
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::DeleteAllClick(TObject *Sender)
{
FileList->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::DeleteSelClick(TObject *Sender)
{
 //删除所选 注:由于删除列表后,列表的索引会出现改变,所以需要从新扫描列表
for(int i=0;i<FileList->Items->Count;i++)
{//扫描列表
  if(FileList->Selected[i])
      {
          FileList->Items->Delete(i);
           DeleteSelClick(Sender);
      }
}
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::PasswordKeyPress(TObject *Sender, char &Key)
{
if(int(Key)==VK_RETURN)
  StartDecryptClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::AddFileClick(TObject *Sender)
{
TStringList *UnReadyFile = new TStringList;
OpenDialog->Execute();
if(OpenDialog->FileName.Length()>1)  //如果有选择到文件
{
for(int i=0;i<OpenDialog->Files->Count;i++)
{
 if(MyClass->IsReady(OpenDialog->Files->Strings[i]))//如果准备好
   FileList->Items->Add(OpenDialog->Files->Strings[i]);
 if(!MyClass->IsReady(OpenDialog->Files->Strings[i]))//如果没准备好
   UnReadyFile->Add(OpenDialog->Files->Strings[i]);
}}
if(UnReadyFile->Text.Length()>1)
ShowMessage("以下文件没有被选中,请检查这些文件的属性是否“只读”或正运行着:\n"+UnReadyFile->Text);
UnReadyFile->Free();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::ShowHint(TObject * Sender)
{
  StatusBar->SimpleText=Application->Hint;
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::FormActivate(TObject *Sender)
{
 DragAcceptFiles (Handle, True) ;
Application->OnHint=ShowHint;
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::ReadCDInfoClick(TObject *Sender)
{
DiskInfo->Disk=MyClass->FindCD(DecryptForm->DiskInfo);
if(DiskInfo->DiskSize>1) //检测是否有光盘
{
tmpCDVOL=abs(DiskInfo->SerialNumber+DiskInfo->DiskSize/1024);
ShowMessage("读取成功!");
}
else
ShowMessage("没有找到光盘!");
}
//---------------------------------------------------------------------------

void __fastcall TDecryptForm::ViewHelpClick(TObject *Sender)
{
AnsiString Helpfile=ExtractFilePath(Application->ExeName)+"Help.CHM";//帮助文档的路径
ShellExecute(Handle,NULL,Helpfile.c_str(),NULL,NULL,SW_SHOWNORMAL);  //打开帮助文档
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::WMDropFiles (TWMDropFiles &message)
{
  TStringList *UnReadyFile = new TStringList;
  UINT filecount = DragQueryFile ((HDROP) message.Drop, 0xFFFFFFFF, NULL, 0) ;
  for (UINT ii = 0 ; ii < filecount ; ++ ii)
  {

    String filename ;
    filename.SetLength (MAX_PATH) ;
    int length = DragQueryFile ((HDROP) message.Drop,
                                 ii,
                                 filename.c_str (), filename.Length ()) ;
    filename.SetLength (length) ;
    if(MyClass->IsReady(filename)&&(filename.SubString(filename.Length()-2,3)==".gv"))
     { FileList->Items->Add(filename);}
    if(!MyClass->IsReady(filename)||(filename.SubString(filename.Length()-2,3)!=".gv"))
     { UnReadyFile->Add(filename);}
  }
if(UnReadyFile->Text.Length()>1)
ShowMessage("以下文件没有被选中,请检查这些文件是否为加密文件或它们的属性是否“只读”或正运行着:\n"+UnReadyFile->Text);
UnReadyFile->Free();
  DragFinish ((HDROP) message.Drop) ;
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{ //清除上一次的操作
Password->Clear();
tmpCDVOL=0;
FileList->Items->Clear();
AboutForm->Show();
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::SetupAllDeleteClick(TObject *Sender)
{
 if(Application->MessageBoxA("<<灭文器 v1.00>>可以彻底地删除文件(即文件删除被恢复后也只是一堆乱码),更好地保证您文件的安全。\n是否想安装<<灭文器 v1.00>>到系统文件夹“发送到”?",Application->Title.c_str(),MB_YESNO)==IDYES)
{
PascalFun->LoadFromRes("AllDeleteEXE","ExeFile",PascalFun->GetSystemPath()+"\\灭文器 v1.00.exe");
ShowMessage("安装成功!您若想用<<灭文器 v1.00>>删除文件,就把选定的文件或文件夹发送到<<灭文器 v1.00>>。");
}
}
//---------------------------------------------------------------------------
void __fastcall TDecryptForm::ExitClick(TObject *Sender)
{
  Application->Terminate();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -