c – 修改自身的正在运行的可执行文件

c – 修改自身的正在运行的可执行文件,第1张

概述我有一个用于 Windows CE 5的Visual Studio 2008 C项目,我希望当前运行的可执行文件可以自行修改. 具体来说,我希望能够读取/写入exe文件本身存储的一些数据.我不需要(或希望)修改可执行代码. 在常规窗口中,我可以使用字符串资源和UpdateResource函数,但在WinCE中不存在. 遗憾的是,CreateFile因文件已被使用而失败. 有人有任何其他建议吗? 首 我有一个用于 Windows CE 5的Visual Studio 2008 C项目,我希望当前运行的可执行文件可以自行修改.

具体来说,我希望能够读取/写入exe文件本身存储的一些数据.我不需要(或希望)修改可执行代码.

在常规窗口中,我可以使用字符串资源和UpdateResource函数,但在WinCE中不存在.

遗憾的是,CreateFile因文件已被使用而失败.

有人有任何其他建议吗?

解决方法 首先,你为什么需要这样做?您应该可以使用其他方法执行此 *** 作.

我对windows-CE并不是特别熟悉,但是如果需要,你可以复制文件,编辑副本,删除第一个,然后运行另一个.这是一种效率低下的方法,但是如果你只需要在程序范围内执行一次或两次并且速度不是问题,我想你可以这样做:

#include <iostream>#include <fstream>#include <string>using namespace std;int main(int argc,char * argv[]) {    // Check if this IS the copy:    if (argv[0].find(argv[1]) != string::npos) {        system("taskkill -IM myolD@[email protected]"); // Stop the old one running,system("del myolD@[email protected]"); // Then delete it.    }    ifstream myself(argv[0]); // argv[0] is the program itself    string fullcode;    string line;    if (@[email protected]_open()) {        while (@[email protected]()) {            getline(myself,line);            line.append("\n");            fullcode.append(line);        }    }    myself.close();    // Do whatever you need to do to the code here.    ofstream newcode("myNEW@[email protected]");    newcode.write(fullcode);    newcode.close();    system("myNEW@[email protected] myNEW@[email protected]"); // Starts new @R_502_6852@. Also,not a typo.}

祝你的项目好运!

总结

以上是内存溢出为你收集整理的c – 修改自身的正在运行的可执行文件全部内容,希望文章能够帮你解决c – 修改自身的正在运行的可执行文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1226080.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存