|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 小新吧 于 2013-2-18 15:41 编辑
修改一个固定密码的加密程序最后实现一机一码注册时:
为什么delphi中修改了生成的exe文件窗体,运行后不显示修改,还是原来一样的
谁帮忙解决奖励30鱼币···先谢过···
一、设计窗体是修改了生成exe文件的界面,
编译时候设计的窗体
二、保存后,打开运行,预览最后加密生成的exe文件界面。
运行是预览修改后的窗体
三、最后却没有变化,修改的未被显示出来。
最后生成的居然没有变化,不显示修改
求大牛指导,感谢!···
主窗体代码:
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ShellAPI, ExtCtrls, Buttons, Menus;
type
Tfrm_Main = class(TForm)
OpenDialog1: TOpenDialog;
StatusBar1: TStatusBar;
Panel1: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Button_Directory: TSpeedButton;
Button_OpenFile: TSpeedButton;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText_Pass1: TStaticText;
Edit_FileName: TEdit;
Edit_Pass: TEdit;
Button_Go: TBitBtn;
Button_UnGo: TBitBtn;
TabSheet3: TTabSheet;
lb_email: TLabel;
lb_HomePage: TLabel;
homepage: TLabel;
email: TLabel;
update: TLabel;
lb_UpData: TLabel;
lb_Author: TLabel;
Edit_Caption: TEdit;
StaticText_Caption: TStaticText;
GroupBox1: TGroupBox;
cb_Assoc: TCheckBox;
btn_Apply: TButton;
cb_NeedPass: TCheckBox;
Button_Preview: TSpeedButton;
Panel2: TPanel;
Button1: TButton;
StaticText3: TStaticText;
StaticText5: TStaticText;
rb_Speed: TRadioButton;
rb_Comp: TRadioButton;
CheckBox_BackUp: TCheckBox;
lb_Ver: TLabel;
Bevel1: TBevel;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button_GoClick(Sender: TObject);
procedure Btn_ExitClick(Sender: TObject);
procedure Button_OpenFileClick(Sender: TObject);
procedure Button_UnGoClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button_DirectoryClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Edit_FileNameChange(Sender: TObject);
procedure emailClick(Sender: TObject);
procedure homepageClick(Sender: TObject);
procedure updateClick(Sender: TObject);
procedure btn_ApplyClick(Sender: TObject);
procedure Button_PreviewClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure cb_OptionClick(Sender: TObject);
private
sOpFileName,sPassWord,sCaption:String;
procedure ResetForm;
procedure BuzyForm;
procedure DoLock;
procedure DoUnLock;
procedure CheckOpFile(FileName: String);
procedure WMDropFiles(var Msg:TWMDropFiles); message WM_DROPFILES;
procedure StatusText(sMsg_Error: String);
procedure LockFileStream(SFName: String; BBackup: Boolean);
procedure UnLockFileStream(SFName, PassWord: String);
{ Private declarations }
public
{ Public declarations }
end;
const
Ver='2.11';
PassSize=18;
CFlag='...FILE..LOCK...';
{ 用AsPack2.1压缩 }
FileIconStart=$20C1C;
FileExeStart=$21000;
AssocString='用&EXELOCK加密';
Error_FileNotExists='对不起,选取文件不正确,请重新选取。';
Error_NoPass='对不起,密码不能为空,请输入密码。';
Error_PassNotSame='两次密码不一致,请检查并重新输入。';
Error_FileLocked='警告!文件已经加密,请解密后从新加密!';
Error_FileNotLocked='文件没有加密,无法继续。';
Error_PassWrong='密码错误,无法解密文件。';
Error_FileType='文件类型不是EXE,加密后可能出错。';
Error_FileAttribute='文件属性只读,是否改变属性继续。';
Error_FileDelete='文件删除失败,可能被加密的程序正在使用。';
Msg_DoLock='文件没有加密,可以加密。';
Msg_DoUnLock='文件已经加密,可以解密。';
Msg_BeginLock='开始加密文件,请稍后!';
Msg_BeginUnLock='开始解密文件,请稍后!';
Msg_EndLock='文件加密完成,感谢您的支持。';
Msg_EndUnLock='文件解密完成,感谢您的支持。';
Msg_BeginBackUpFile='正在备份文件,请稍后!';
Msg_BeginLH='正在压缩加密文件,请稍后!';
Msg_BeginUnLH='正在解压缩加密文件,请稍后!';
Msg_Ready='准备就绪!';
Msg_DefaultCaption='注册请联系QQ:602852265 淘宝ID:x一切尽喜y';
type
TLockedFile=record
Flag:String[Length(CFlag)];
PassWord:String[PassSize];
Caption:String[52];
Compressed:Boolean;
end;
var
frm_Main: Tfrm_Main;
implementation
{$R *.DFM}
{$R 1.RES}
uses Func, Encrypt_Base64, Compress_LH5, Preview, Password, Login, Unit1,
UnitMD5;
procedure Tfrm_Main.ResetForm;
begin
StatusText(Msg_Ready);
Edit_Pass.Enabled:=True;
Edit_Caption.Enabled:=True;
Edit_Pass.Text:=#0;
Button_Go.Enabled:=True;
Button_Go.Default:=False;
Button_UnGo.Enabled:=True;
Button_UnGo.Default:=False;
Edit_FileName.Enabled:=True;
Button_OpenFile.Enabled:=True;
Button_Directory.Enabled:=True;
Button_Preview.Enabled:=True;
CheckBox_BackUp.Enabled:=True;
StaticText_Pass1.Enabled:=True;
StaticText_Caption.Enabled:=True;
StatusText(Msg_Ready);
end;
procedure Tfrm_Main.BuzyForm;
begin
Edit_Pass.Enabled:=False;
Edit_Caption.Enabled:=False;
Button_Go.Enabled:=False;
Button_UnGo.Enabled:=False;
Edit_FileName.Enabled:=False;
Button_OpenFile.Enabled:=False;
Button_Directory.Enabled:=False;
Button_Preview.Enabled:=False;
CheckBox_BackUp.Enabled:=False;
end;
procedure Tfrm_Main.LockFileStream(SFName:String;BBackup:Boolean);
var
S,T,C:TMemoryStream;
LockedFile:TLockedFile;
procedure GetPassDialogFile(tStream:TStream);
var
m1,m2:TMemoryStream;
ExeRes:TResourceStream;
bb:Byte;r,s:Integer;
sIcon:TIcon;
begin
ExeRes:=TResourceStream.Create(Hinstance,'File1','EXEFILE');
sIcon:=TIcon.Create;
try
sIcon.Handle:=ExtractIcon(Application.Handle,PChar(SFName),0);
if sIcon.Handle<>0 then
begin
m1:=TMemoryStream.Create;
m2:=TMemoryStream.Create;
try
sIcon.SaveToStream(m1);
// sIcon.SaveToFile('test.ico');
m2.LoadFromStream(ExeRes);
s:=m1.Seek(0,2);
m1.seek($16,0);
m2.seek(FileIconStart+$14,0);
repeat
r:=m1.Read(bb,SizeOf(bb));
m2.write(bb,r);
until m1.seek(0,1)=s;
m2.SaveToStream(tStream);
finally
m1.Free;
m2.Free;
end;
end else
ExeRes.SaveToStream(tStream);
finally
sIcon.Free;
ExeRes.Free;
end;
end;
begin
S:=TMemoryStream.Create;
T:=TMemoryStream.Create;
C:=TMemoryStream.Create;
try
S.LoadFromFile(SFName);
if BBackUp then
begin
StatusText(Msg_BeginBackUpFile);
S.SaveToFile(ChangeFileExt(SFName,'.BAK'));
end;
with LockedFile do
begin
Flag:=CFlag;
Caption:=sCaption;
PassWord:=Base64Encode(sPassWord);
Compressed:=rb_Comp.Checked;
end;
GetPassDialogFile(T);
S.Position:=0;
T.Seek(0,2);
StatusText(Msg_BeginLH);
if LockedFile.Compressed then
begin
C.Position:=0;
LHACompress(S,C);
C.Position:=0;
T.CopyFrom(C,C.Size);
end else T.CopyFrom(S,S.Size);
T.Write(LockedFile,SizeOf(LockedFile));
if DeleteFile(SFName) then
begin
T.SaveToFile(SFName);
MessageBox(Handle,Msg_EndLock,'信息',MB_OK);
end else
MessageBox(Handle,Error_FileDelete,'错误',MB_OK);
finally
S.Free;
T.Free;
C.Free;
end;
end;
procedure Tfrm_Main.UnLockFileStream(SFName, PassWord:String);
var
S,T,C:TMemoryStream;
LockedFile:TLockedFile;
begin
S:=TMemoryStream.Create;
T:=TMemoryStream.Create;
C:=TMemoryStream.Create;
try
S.LoadFromFile(SFName);
S.Seek(-SizeOf(LockedFile),2);
S.Read(LockedFile,SizeOf(LockedFile));
if Base64Decode(LockedFile.PassWord)=PassWord then
begin
S.Position:=FileExeStart;
T.Position:=0;
StatusText(Msg_BeginUnLH);
if LockedFile.Compressed then
begin
C.Position:=0;
C.CopyFrom(S,S.Size-FileExeStart-SizeOf(LockedFile));
C.Position:=0;
LHAExpand(C,T);
end else T.CopyFrom(S,S.Size-FileExeStart-SizeOf(LockedFile));
if DeleteFile(SFName) then
begin
T.SaveToFile(SFName);
MessageBox(Handle,Msg_EndUnLock,'信息',MB_OK);
end else
MessageBox(Handle,Error_FileDelete,'错误',MB_OK);
end else
MessageBox(Handle,Error_PassWrong,'警告',MB_OK);
finally
S.Free;
T.Free;
C.Free;
end;
end;
procedure Tfrm_Main.StatusText(sMsg_Error:String);
begin
StatusBar1.Panels[1].Text:=sMsg_Error;
end;
function LockFile(P:pointer):Longint;stdcall;
begin
with frm_Main do
begin
BuzyForm;
StatusText(Msg_BeginLock);
LockFileStream(sOpFileName,CheckBox_BackUp.Checked);
StatusText(Msg_EndLock);
CheckOpFile(sOpFileName);
end;
Result:=-1;
end;
function UnLockFile(P:pointer):Longint;stdcall;
begin
with frm_Main do
begin
BuzyForm;
StatusText(Msg_BeginUnLock);
UnLockFileStream(sOpFileName,sPassWord);
StatusText(Msg_EndUnLock);
CheckOpFile(sOpFileName);
end;
Result:=-1;
end;
procedure Tfrm_Main.Button_GoClick(Sender: TObject); //点击开始注册按钮代码段
var
hThread:Thandle;
ThreadID:DWord;
Name,s2,s3,temp1,temp2,temp3,temp4:string;
begin
begin
Edit1.Text:=GetStrMD5('0123456789'); // 从处此到
Edit2.Text:='1203';
s2 := DESEncrypt(Edit1.Text,Edit2.Text);
temp1:=copy(s2,7,3) ;
temp2:=copy(s2,16,2);
temp3:=copy(s2,32,3);
temp4:=copy(s2,46,3);
s3:=temp1+temp4+temp3+temp2;
Edit_Pass.Text:=s3; // 对exe文件进行加密采用的算法
end;
if not FileExists(Edit_FileName.Text) then
begin
MessageBox(Handle,Error_FileNotExists,'信息',MB_OK);
exit;
end;
if Edit_Pass.Text='' then
begin
MessageBox(Handle,Error_NoPass,'信息',MB_OK);
exit;
end;
if Edit_Caption.Text='' then
begin
Edit_Caption.Text:=Msg_DefaultCaption;
end;
sOpFileName:=Edit_FileName.Text; //从此到
sPassWord:=Edit_Pass.Text;
sCaption:=Edit_Caption.Text;
hThread:=CreateThread(nil,0,@LockFile,nil,0,ThreadID);
if hThread=0 then LockFile(nil); { not use thread } // 这里是对exe文件加密并生成加密后的exe文件
end;
procedure Tfrm_Main.Btn_ExitClick(Sender: TObject);
begin
Close;
end;
procedure Tfrm_Main.Button_OpenFileClick(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Edit_FileName.Text:=OpenDialog1.FileName;
CheckOpFile(Edit_FileName.Text);
end;
end;
procedure Tfrm_Main.Button_UnGoClick(Sender: TObject); //点击解密按钮代码
var
hThread:THandle;
ThreadID:DWord;
Name,s2,s3,temp1,temp2,temp3,temp4:string;
begin
begin
Edit1.Text:=GetStrMD5('0123456789');
Edit2.Text:='1203';
s2 := DESEncrypt(Edit1.Text,Edit2.Text);
temp1:=copy(s2,7,3) ;
temp2:=copy(s2,16,2);
temp3:=copy(s2,32,3);
temp4:=copy(s2,46,3);
s3:=temp1+temp4+temp3+temp2;
Edit_Pass.Text:=s3;
end;
if not FileExists(Edit_FileName.Text) then
begin
MessageBox(Handle,Error_FileNotExists,'信息',MB_OK);
exit;
end;
if Edit_Pass.Text='' then
begin
MessageBox(Handle,Error_NoPass,'信息',MB_OK);
exit;
end;
sOpFileName:=Edit_FileName.Text;
sPassWord:=Edit_Pass.Text;
hThread:=CreateThread(nil,0,@UnLockFile,nil,0,ThreadID);
if hThread=0 then UnLockFile(nil);
end;
procedure Tfrm_Main.FormCreate(Sender: TObject);
begin
{ check need password }
if NeedPass(True,False) then
begin
frm_Login:=Tfrm_Login.Create(Application);
frm_Login.ShowModal;
end;
{ enable dragfile }
DragAcceptFiles(Handle, True);
if (ParamCount>0)and(ParamStr(1)<>'') then
begin
Edit_FileName.Text:=ParamStr(1);
CheckOpFile(ParamStr(1));
end;
{ check sth. }
cb_Assoc.Checked:=AssocExeFile(True,True,AssocString);
cb_NeedPass.Checked:=NeedPass(True,True);
rb_Comp.Checked:=GetCompress(True,True);
rb_Speed.Checked:=not rb_Comp.Checked;
{ initialize size }
Constraints.MinHeight:=Height;
Constraints.MinWidth:=Width;
Edit_Caption.Text:=Msg_DefaultCaption;
Edit_Pass.MaxLength:=PassSize;
lb_Ver.Caption:=Ver;
StatusText(Msg_Ready);
end;
procedure Tfrm_Main.Button_DirectoryClick(Sender: TObject);
var
SDirectory:String;
begin
if not FileExists(Edit_FileName.Text) then
begin
MessageBox(Handle,Error_FileNotExists,'信息',MB_OK);
exit;
end;
SDirectory:=ExtractFilePath(Edit_FileName.Text);
ShellExecute(Handle,nil,PChar(SDirectory),nil,nil,SW_SHOWNORMAL);
end;
procedure Tfrm_Main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// if not Btn_Exit.Enabled then CanClose:=False;
end;
procedure Tfrm_Main.DoLock;
begin
StatusText(Msg_DoLock);
Button_UnGo.Enabled:=False;
Button_Go.Default:=True;
end;
procedure Tfrm_Main.DoUnLock;
begin
StatusText(Msg_DoUnLock);
Button_Go.Enabled:=False;
Button_UnGo.Default:=True;
Button_Preview.Enabled:=False;
Edit_Caption.Enabled:=False;
CheckBox_BackUp.Enabled:=False;
StaticText_Pass1.Enabled:=False;
StaticText_Caption.Enabled:=False;
end;
procedure Tfrm_Main.CheckOpFile(FileName:String);
var
iOpFile:Integer;
LockedFile:TLockedFile;
FileAttr:Integer;
begin
ResetForm;
if CompareText(ExtractFileExt(FileName),'.lnk')=0 then
begin
FileName:=GetShortcutTarget(FileName);
Edit_FileName.Text:=FileName;
end;
if CompareText(ExtractFileExt(FileName),'.exe')<>0 then
MessageBox(Handle,Error_FileType,'警告',MB_OK);
FileAttr:=FileGetAttr(FileName);
if FileAttr and faReadOnly>0 then
begin
if MessageBox(Handle,Error_FileAttribute,'信息',MB_YESNO)=IDNO then
begin
Edit_FileName.Text:='';
exit;
end else
FileSetAttr(FileName,FileAttr - faReadOnly);
end;
iOpFile:=FileOpen(FileName,fmOpenRead);
try
FileSeek(iOpFile,-SizeOf(LockedFile),2);
FileRead(iOpFile,LockedFile,SizeOf(LockedFile));
if LockedFile.Flag=CFlag then
begin
DoUnLock;
end else
begin
DoLock;
end;
finally
FileClose(iOpFile);
end;
end;
procedure Tfrm_Main.WMDropFiles(var Msg: TWMDropFiles);
var
CFileName: array[0..MAX_PATH] of Char;
begin
try
if DragQueryFile(Msg.Drop,0,CFileName,MAX_PATH)>0 then
begin
Edit_FileName.Text:=CFileName;
CheckOpFile(Edit_FileName.Text);
end;
finally
DragFinish(Msg.Drop);
end;
end;
procedure Tfrm_Main.Edit_FileNameChange(Sender: TObject);
begin
Edit_FileName.Hint:=Edit_FileName.Text;
end;
procedure Tfrm_Main.emailClick(Sender: TObject);
begin
ShellExecute(Self.Handle,'Open',PChar('xsks@163.com?Subject=关于EXE文件加密器'),nil,nil,1);
end;
procedure Tfrm_Main.homepageClick(Sender: TObject);
begin
ShellExecute(Self.Handle,'Open',PChar('http://www.2ccc.com'),nil,nil,1);
end;
procedure Tfrm_Main.updateClick(Sender: TObject);
begin
ShellExecute(Self.Handle,'Open',PChar('http://www.2ccc.com/downloads'),nil,nil,1);
end;
procedure Tfrm_Main.btn_ApplyClick(Sender: TObject);
begin
AssocExeFile(False,cb_Assoc.Checked,AssocString);
NeedPass(False,cb_NeedPass.Checked);
GetCompress(False,rb_Comp.Checked);
btn_Apply.Enabled:=False;
end;
procedure Tfrm_Main.Button_PreviewClick(Sender: TObject);
begin
Application.CreateForm(Tfrm_Preview, frm_Preview);
if Edit_Caption.Text='' then
Edit_Caption.Text:=Msg_DefaultCaption;
sCaption:=Edit_Caption.Text;
if FileExists(Edit_FileName.Text) then
begin
frm_Preview.Icon.Handle:=ExtractIcon(Application.Handle,PChar(Edit_FileName.Text),0);
end;
frm_Preview.Label1.Caption:=sCaption;
frm_Preview.ShowModal;
end;
procedure Tfrm_Main.Button1Click(Sender: TObject);
begin
Application.CreateForm(Tfrm_PassWord, frm_PassWord);
frm_PassWord.ShowModal;
end;
procedure Tfrm_Main.cb_OptionClick(Sender: TObject);
begin
btn_Apply.Enabled:=True;
end;
end.
点击预览按钮时候显示界面的代码:
uses
Forms, StdCtrls, Controls, Classes;
type
Tfrm_Preview = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_Preview: Tfrm_Preview;
implementation
{$R *.DFM}
procedure Tfrm_Preview.Button2Click(Sender: TObject);
begin
Close;
end;
procedure Tfrm_Preview.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
end.
|
|