一个老问题: 修改Exe文件中的字符串资源(300分)

  • 主题发起人 主题发起人 sleepy
  • 开始时间 开始时间
S

sleepy

Unregistered / Unconfirmed
GUEST, unregistred user!
我的目的是, 可以用程序修改另一个文件的字符串资源。<br>用API Spy跟了一下 eXeScope, 发现它是用 Writefile() 来实现的,<br>这就解决了 updateresource 在Win9x下不能工作的问题。<br><br>我用WriteFile试验了一下, 结果把资源改得一塌糊涂。:-(<br><br>使用WriteFile来修改字串,必须要解决几个问题 :<br>1. 怎样得到自己需要修改的字串的 offset?<br>2. 怎样用自己的字串替换现在的字串, 而不覆盖/修改其它资源?<br><br>有感兴趣的大侠来讨论讨论吧! 谢谢!
 
赫赫,需要PE的文件格式乐.Delphi封装了PE的文件头结构,很好使用的.在Windows单元,TImageXXXXXX之类的<br>根据文件头就可以找到OffSet?我正在研究这个~~~~~~~~我的问题是如何找到Exe的第一个可执行代码在<br>文件中的OffSet?不过看了好久,还是没有明白~~~~~~倒是知道在内存的OffSet如何计算的.<br>我主页的资料包里面有PE的详细的文档,中文的,英文的都有.<br>http://kingron.myetang.com<br>不过mautosoft好像也对PE有比较深的研究?你问问他吧.
 
updateresource 不能在Win9X下用吗?我看API帮助上并没有说啊,我没有Win9X环境,<br>没法试。<br>能不能直接按照字符串搜索的方式找到它?
 
函数包括<br>beginupdateresource<br>updateresource<br>endupdateresource<br>具体的用法大家讨论<br>我的目的是修改图标<br>但是我只能删除一个程序的图标,修改没有成功<br>大家请继续
 
Updateresource其引用前要先BeginUpdateResource <br>HANDLE = BeginUpdateResource( LPCSTR pFileName, BOOL bDeleteExistingResources )<br>LPCTSTR pFileName, // 可执行文件名<br>BOOL bDeleteExistingResources // 是否删除可执行文件的现有资源<br>该函数返回一个句柄,为UpdateResource函数在可执行文件中进行添加、删除、替换资源等操作。 <br>Example:<br>procedure TForm1.Button1Click(Sender: TObject);<br>Var Res : THandle;<br>&nbsp; &nbsp; HD &nbsp;: String;<br>Begin<br>&nbsp; &nbsp; &nbsp;HD := Check_HD;<br>&nbsp; &nbsp; &nbsp;Res := BeginUpdateResource('EXE_A_MODIFICAR',False);<br>&nbsp; &nbsp; &nbsp;UpdateResource(Res,RT_RCDATA,''NOMBRE_DEL_RECURSO',0,Pointer(HD),Length(HD));<br>&nbsp; &nbsp; &nbsp;If EndUpdateResource(hRes,False) then<br>&nbsp; &nbsp; &nbsp;ShowMessage('修改成功!');<br>End;<br><br>你看看Inno Setup的源代码就是经典的例子!
 
另附一段E文,感兴趣的读读!<br><br>Exist any api to make changes in some strings variable direct in &gt; a exe file?? <br>like: On NT (but not Windows9X) you can modify resources (see excerpt from MSDN below). <br>For the sake of completeness I describe the alternative: Directly modifing a running executable file is not <br>possible. You would have to copy it to temporary file and modify that. One way to rename the <br>temporary back again is + start the temporary .exe (e.g. ShellExecute) + terminate the original .exe + the <br>temporary .exe checks its name with GetModuleFileName(0, ...) + if it's not the expected name it <br>deletes the old .exe + copies itself + starts the copy From the MSDN: The UpdateResource function <br>adds, deletes, or replaces a resource in an executable file. BOOL UpdateResource( HANDLE <br>hUpdate, // update-file handle LPCTSTR lpType, // address of resource type to update LPCTSTR <br>lpName, // address of resource name to update WORD wLanguage, // language identifier of resource <br>LPVOID lpData, // address of resource data DWORD cbData // length of resource data, in bytes ); <br>Remarks An application can use UpdateResource repeatedly to make changes to the resource data. <br>Each call to UpdateResource contributes to an internal list of additions, deletions, and replacements but <br>does not actually write the data to the executable file. The application must use the EndUpdateResource <br>function to write the accumulated changes to the executable file. QuickInfo Windows NT: Requires <br>version 3.1 or later. Windows: Unsupported. Windows CE: Unsupported. Header: Declared in <br>winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on <br>Windows NT. <br>
 
UpdateResource的原型:<br>BOOL UpdateResource(<br>&nbsp; &nbsp; HANDLE hUpdate, // update-file handle <br>&nbsp; &nbsp; LPCTSTR lpType, // address of resource type to update <br>&nbsp; &nbsp; LPCTSTR lpName, // address of resource name to update &nbsp;<br>&nbsp; &nbsp; WORD wLanguage, // language identifier of resource <br>&nbsp; &nbsp; LPVOID lpData, // address of resource data <br>&nbsp; &nbsp; DWORD cbData // length of resource data, in bytes <br>&nbsp; &nbsp;);<br><br>UpdateResource是NT专用.
 
后退
顶部