修改EXE文件图标的问题.

fangjx 2004-08-27 06:36:43
看到以前的帖子有这样的代码,但为什么老提示<目标文件二进制码中未找到图标>呢?
unit UnitOK;//用Delphi编程替代EXE文件图标

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,shellapi;

type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
StatusBar1: TStatusBar;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
readlen=10; //每次读取字节数,可改变
icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据
var
i,j,itemp,nPos:int64;// nPos为目的图标在目的文件的位置
ci,cj:array[0..readlen-1] of char;
SourceFile,DestFile:String;//如果要把记事本图标换成瑞星杀毒软件图标
bOK:boolean;//则SourceFile='C:\windows\notepad.exe',DestFile:='C:\Progra
m Files\rising\rav\ravmon.exe'
SourceIcon,DestIcon:TIcon;
SIconStream,s,sDest:TMemoryStream;
begin
bOK:=false;
if OpenDialog1.Execute then
SourceFile:=OpenDialog1.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(SourceFile))<>'.EXE' then
begin
ShowMessage(AnsiUpperCase(ExtractFileExt(SourceFile)));
exit;
end;
Edit1.Text:=SourceFile;
if OpenDialog2.Execute then
DestFile:=OpenDialog2.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(DestFile))<>'.EXE' then
exit;
Edit2.Text:=DestFile;
SourceIcon:=TIcon.Create;
case ExtractIcon(handle,PChar(SourceFile),UINT(-1)) of
0:begin ShowMessage('源程序没有图标');exit;end;
1:;
else ShowMessage('源程序有多个图标,本程序选择第一个图标');
end;
SourceIcon.Handle:=ExtractIcon(handle,PChar(SourceFile),0);//选择第一个图

DestIcon:=TIcon.Create;//选择第N个图标为 ExtractIcon(handle,PChar(Source
File),N-1)
case ExtractIcon(handle,PChar(DestFile),UINT(-1)) of
0:begin ShowMessage('目的程序没有图标');exit;end;
1:;
else ShowMessage('目的程序有多个图标,本程序选择第一个图标替换');
end;
DestIcon.Handle:=ExtractIcon(handle,PChar(DestFile),0);//选择第一个图标
SIconStream:=TMemoryStream.Create;
DestIcon.SaveToStream(sIconStream);
if sIconStream.size<>icolen then
ShowMessage('SIcon.size<>icolen');
SDest:=TMemoryStream.Create;
sDest.LoadFromFile(DestFile);
i:=0;j:=0; //以下程序查找目的图标在目的程序中的位置
while i< sDest.size do
begin
itemp:=i;
j:=126;
{ repeat
SDest.Position:=i;
sDest.read(ci,Readlen);
SiconStream.Position:=j;
SIconStream.Read(cj,Readlen);
i:=i+Readlen;
j:=j+Readlen;
until (String(ci)=String(cj)) and (i<sDest.size) and (j<icolen);
} ci:='';cj:='';
while (String(ci)=String(cj)) and (i<SDest.size) and (j<
icolen) do
begin
i:=i+readlen;
j:=j+readlen;
SDest.Position:=i;
SDest.read(ci,readlen);
SiconStream.Position:=j;
SiconStream.Read(cj,readlen);
end;
if j<icolen then
i:=itemp+1 //没找到
else
begin
nPos:=itemp; //找到
bOK:=true;
break;
end;
end;
if bOK=false then
exit;//目标文件二进制码中未找到图标
SIconStream.Clear;//将源程序图标存入
SourceIcon.SaveToStream(SIconStream);

SIconStream.position:=126;
s:=TMemoryStream.Create;

sDest.Position:=0;
s.CopyFrom(sDest,nPos);//将目的程序图标前数据拷入
s.CopyFrom(SIconStream,640); //将源程序图标拷入
if sDest.size>sDest.Position+640 then //将目的程序剩余数据拷入
begin
sDest.Position:=sDest.Position+640;
s.CopyFrom(sDest,sDest.Size-sDest.Position);
end;
s.SaveToFile(Extractfilepath(application.exename)+'Result.exe');
SourceIcon.Free;DestIcon.Free; //改造好的程序存放在本目录Result.exe文件中
SIconStream.Free;s.Free;sDest.Free;
ShowMessage(Extractfilepath(application.exename)+'Result.exe');
end;
//以上程序可以将目的程序的第一个图标换成源程序的第一个图标,经实证很多程序有二个
//或更多图标,转换原理相似,不在陈述
end.
...全文
202 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangjx 2004-09-03
  • 打赏
  • 举报
回复
还是不行
wilowind(无风雪亦飘) (能发一份好用的代码给我吗?
FANGJK0002@SINA.COM
fangjx 2004-08-28
  • 打赏
  • 举报
回复
换2000能好.等我测试一下
wilowind 2004-08-28
  • 打赏
  • 举报
回复
关键就是 这个: icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据

不同的系统图标长度可能不同.
而且这个还定死了时32*32 的图标。
fangjx 2004-08-28
  • 打赏
  • 举报
回复
在XP下不能用?晕.怎么修改都不行
fangjx 2004-08-28
  • 打赏
  • 举报
回复
喔.我用DEPHI编的程序只有一个图标,所以怎么也通不过.^_^
我是DELPHI7+WINXP
Allblus(爽) :HIT 不消失可以
Application.HintHidePause=足够长的时间;//停留时间
Application.HintPause=;//显示HIT的延迟时间
这两个函数
wilowind 2004-08-27
  • 打赏
  • 举报
回复
icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据

就是他的问题了, 因为很多程序都是16*16的图标...........所以找不到....
wilowind 2004-08-27
  • 打赏
  • 举报
回复
icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据

难道这个有问题.???>*(*))() 晕了,,..........
wilowind 2004-08-27
  • 打赏
  • 举报
回复
这个程序要求 源exe文件与目标 exe文件都必须有 2个以上图标才能替换.
一个的居然就找不到..

再看看
zzlingaaa 2004-08-27
  • 打赏
  • 举报
回复
嘿嘿,网上那么多资源修改器,改个图标应该没问题
wilowind 2004-08-27
  • 打赏
  • 举报
回复
to: fangjx (烟雨缥缈)

源程序没问题, 我改出问题了.. 抱歉.

你从winnt下找2个exe文件试试..
wilowind 2004-08-27
  • 打赏
  • 举报
回复
Allblus(爽) 你的问题,我也没办法, 期待高手了
Allblus 2004-08-27
  • 打赏
  • 举报
回复
wilowind(无风雪亦飘) ,老兄幫我看看這个:
Hint顯示一下後會消失,能不能弄成只要鼠標在上面就不會消失??


搭个車,樓主別介意哦:)
wilowind 2004-08-27
  • 打赏
  • 举报
回复
最后是在程序目录下有个Result.exe文件 .
wilowind 2004-08-27
  • 打赏
  • 举报
回复
不可能, 我已经调试通过了....

unit ChangeIcon;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,shellapi;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
StatusBar1: TStatusBar;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
readlen=10; //每次读取字节数,可改变
icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据
var
i,j,itemp,nPos:int64;// nPos为目的图标在目的文件的位置
ci,cj:array[0..readlen-1] of char;
SourceFile,DestFile:String;//如果要把记事本图标换成瑞星杀毒软件图标
bOK:boolean;//则SourceFile='C:\windows\notepad.exe',DestFile:='C:\Program Files\rising\rav\ravmon.exe'
SourceIcon,DestIcon:TIcon;
SIconStream,s,sDest:TMemoryStream;
begin
bOK:=false;
if OpenDialog1.Execute then
SourceFile:=OpenDialog1.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(SourceFile))<>'.EXE' then
begin
ShowMessage(AnsiUpperCase(ExtractFileExt(SourceFile)));
exit;
end;
Edit1.Text:=SourceFile;
if OpenDialog2.Execute then
DestFile:=OpenDialog2.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(DestFile))<>'.EXE' then
exit;
Edit2.Text:=DestFile;
SourceIcon:=TIcon.Create;
case ExtractIcon(handle,PChar(SourceFile),UINT(-1)) of
0:begin ShowMessage('源程序没有图标');exit;end;
1:;
else ShowMessage('源程序有多个图标,本程序选择第一个图标');
end;
SourceIcon.Handle:=ExtractIcon(handle,PChar(SourceFile),0);//选择第一个图标
DestIcon:=TIcon.Create;//选择第N个图标为 ExtractIcon(handle,PChar(SourceFile),N-1)
case ExtractIcon(handle,PChar(DestFile),UINT(-1)) of
0:begin ShowMessage('目的程序没有图标');exit;end;
1:;
else ShowMessage('目的程序有多个图标,本程序选择第一个图标替换');
end;
DestIcon.Handle:=ExtractIcon(handle,PChar(DestFile),0);//选择第一个图标
SIconStream:=TMemoryStream.Create;
DestIcon.SaveToStream(sIconStream);
if sIconStream.size<>icolen then
ShowMessage('SIcon.size<>icolen');
SDest:=TMemoryStream.Create;
sDest.LoadFromFile(DestFile);
i:=0;j:=0; //以下程序查找目的图标在目的程序中的位置
while i< sDest.size do
begin
itemp:=i;
j:=126;
{ repeat
SDest.Position:=i;
sDest.read(ci,Readlen);
SiconStream.Position:=j;
SIconStream.Read(cj,Readlen);
i:=i+Readlen;
j:=j+Readlen;
until (String(ci)=String(cj)) and (i<sDest.size) and (j<icolen);
} ci:='';cj:='';
while (String(ci)=String(cj)) and (i<SDest.size) and (j< icolen) do
begin
i:=i+readlen;
j:=j+readlen;
SDest.Position:=i;
SDest.read(ci,readlen);
SiconStream.Position:=j;
SiconStream.Read(cj,readlen);
end;
if i<icolen then
i:=itemp+1 //没找到
else
begin
nPos:=itemp; //找到
bOK:=true;
break;
end;
end;
if bOK=false then begin
showmessage('目标文件二进制码中未找到图标');
exit;//目标文件二进制码中未找到图标
end;
SIconStream.Clear;//将源程序图标存入
SourceIcon.SaveToStream(SIconStream);

SIconStream.position:=126;
s:=TMemoryStream.Create;

sDest.Position:=0;
s.CopyFrom(sDest,nPos);//将目的程序图标前数据拷入
s.CopyFrom(SIconStream,640); //将源程序图标拷入
if sDest.size>sDest.Position+640 then //将目的程序剩余数据拷入
begin
sDest.Position:=sDest.Position+640;
s.CopyFrom(sDest,sDest.Size-sDest.Position);
end;
s.SaveToFile(Extractfilepath(application.exename)+'Result.exe');
SourceIcon.Free;DestIcon.Free; //改造好的程序存放在本目录Result.exe文件中
SIconStream.Free;s.Free;sDest.Free;
ShowMessage(Extractfilepath(application.exename)+'Result.exe');
end;
//以上程序可以将目的程序的第一个图标换成源程序的第一个图标,经实证很多程序有二个
//或更多图标,转换原理相似,不在陈述
end.
qizhanfeng 2004-08-27
  • 打赏
  • 举报
回复
学习
up
fangjx 2004-08-27
  • 打赏
  • 举报
回复
没有用还是不能成功.
fangjx 2004-08-27
  • 打赏
  • 举报
回复
TO:Allblus(爽) 没有源程序你也能这么改吗?^_^
TO:wilowind(无风雪亦飘) 喔.试试.
wilowind 2004-08-27
  • 打赏
  • 举报
回复
找到错误..
if j<icolen then // <-------- 此处 应为 i<icolen
i:=itemp+1 //没找到
else
begin
nPos:=itemp; //找到
bOK:=true;
break;
end;
Allblus 2004-08-27
  • 打赏
  • 举报
回复
我改的是delphi应用程序中project1.exe的图标
Allblus 2004-08-27
  • 打赏
  • 举报
回复
这个EXE图标应该很容易改吧,我怎么一下子就改了,不是在project-->option-->application中改么?

还要玩什么花招??

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧