function FileToHexStr_Lqb(File_Name:String):String;
var
  F1:File of Byte;
  Tmp_Byte:Byte;
  i:Integer;
  Tmp_Str1,Tmp_Str2,Rslt_Str:String;
begin
i:=1;Result:='';Rslt_Str:='';
  AssignFile(F1,File_Name);
  Reset(F1);
  Read(F1,Tmp_Byte);
  Tmp_Str2:=IntToHex(Tmp_Byte,2);
  while Tmp_Str1<>'Read finished!' do
  begin
    if not Eof(F1) then
    begin
     Read(F1,Tmp_Byte);
   Tmp_Str1:=IntToHex(Tmp_Byte,2);
    end
    else
      Tmp_Str1:='Read finished!';
   if (Tmp_Str2=Tmp_Str1)and(i<255)then
     Inc(i)
    else
    begin
     if i>2 then
       Rslt_Str:=Rslt_Str+'G'+IntToHex(i,2)+Tmp_Str2
      else
      Rslt_Str:=Rslt_Str+Repeat_Str_Lqb(Tmp_Str2,i);
     i:=1;
      Tmp_Str2:=Tmp_Str1;
    end;
if Length(Rslt_Str)>249 then
    begin
      Result:=Result+#39+Rslt_Str+#39#13#10#43; //#39:' #13:回车 #10:换行 #43:+
      Rslt_Str:='';
    end;
  end;
  if Length(Rslt_Str)>0 then Result:=Result+#39+Rslt_Str+#39;
  CloseFile(F1);
end;

解决方案 »

  1.   

    反函数:procedure HexStrToFile_Lqb(HexStr,File_Name:String);//将16进制字符串转换为文件
    var
      i:Integer;
      F1:TextFile;
      Tmp_Str:String;
    begin
      i:=1;
      Tmp_Str:='';
      while i<Length(HexStr) do
      begin
        while not(HexStr[i] in ['0'..'9','A'..'G']) do Inc(i);
        if HexStr[i]='G' then
        begin
          Tmp_Str:=Tmp_Str+Repeat_Str_Lqb(Chr(StrToInt('$'+HexStr[i+3]+HexStr[i+4])),StrToInt('$'+HexStr[i+1]+HexStr[i+2]));
          i:=i+5;
        end
        else
        begin
          Tmp_Str:=Tmp_Str+Chr(StrToInt('$'+HexStr[i]+HexStr[i+1]));
          i:=i+2;
        end;
      end;
      AssignFile(F1,File_Name);
      Rewrite(F1);
      Writeln(F1,Tmp_Str);
      CloseFile(F1);
    end;
      

  2.   

    其实就是..以字节方式打开exe
      

  3.   

    不会吧~~~~~你想自己生成并修改EXE?
    在没有正常的修改PE Header的情况下,胡乱些别的EXE的开头也许会导致问题的