窗体上放MPHexEditorEx控件
用以下函数替换EXE文件字符
设置MPHexEditorEx的CrateBackup为False;
function TFormMain.ReplacePass(Filename,Find, Replace: string): boolean;
var
LIntSize,
LIntPos,
LIntPos2: Integer;
var
LIntSize,
LIntPos,
LIntPos2: Integer;
strdata,
LStrFind,
LStrReplace: string;
LStrFind,
LStrReplace: string;
begin
//result:=false;
mphexeditorex1.LoadFromFile(filename); //exe file name
strdata:=find ; // want to find string
LstrReplace:=replace ; // want to replace string
LIntPos := 0 ;
with mphexeditorex1 do
begin
LStrFind := PrepareFindReplaceData(StrData, false, true);
LIntPos2 := Find(pchar(LStrFind), Length(LStrFind), LIntPos, DataSize -1,false);
SelStart := LIntPos2;
SelEnd := LIntPos2 + Length(LStrFind)-1;
if LStrReplace <> '' then ReplaceSelection(PChar(LStrReplace), Length(LStrReplace), '', False);
mphexeditorex1.SaveToFile(filename);
end;
result:=true
end;
//result:=false;
mphexeditorex1.LoadFromFile(filename); //exe file name
strdata:=find ; // want to find string
LstrReplace:=replace ; // want to replace string
LIntPos := 0 ;
with mphexeditorex1 do
begin
LStrFind := PrepareFindReplaceData(StrData, false, true);
LIntPos2 := Find(pchar(LStrFind), Length(LStrFind), LIntPos, DataSize -1,false);
SelStart := LIntPos2;
SelEnd := LIntPos2 + Length(LStrFind)-1;
if LStrReplace <> '' then ReplaceSelection(PChar(LStrReplace), Length(LStrReplace), '', False);
mphexeditorex1.SaveToFile(filename);
end;
result:=true
end;
本文介绍如何利用MPHexEditorEx组件在Windows环境下替换EXE文件中的特定字符串。通过定义函数ReplacePass,实现了查找并替换指定字符串的功能,并确保了替换后的EXE文件能正常保存。

被折叠的 条评论
为什么被折叠?



