使用 winapi 更改 argv[0] [英] Changing argv[0] with winapi

查看:27
本文介绍了使用 winapi 更改 argv[0]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是更改应用程序重新启动的路径.我无权访问 main,但我可以通过 ctypes 自由运行 C 代码.

My goal is to change the path the application restarts from. I don't have access to main, but I am free to run C code via ctypes.

我能够使用 getexecname() 在 Solarios 中更改 argv[0],这给了我一个指向它的指针,我做了 memcpy.

I was able to change argv[0] in Solarios with getexecname(), that gave me a pointer to it, to which I did memcpy.

我想知道 winapi 中是否有一种方法可以让我找到 argv[0] 指针,或者改变它的 API 函数?

I was wondering if there is a method in winapi that allows me to either find argv[0] pointer, or an API function that changed it?

谢谢

推荐答案

在 Windows 上,您的命令行位于 PEB(进程环境块)中.您可能不应该修改它,但您可以找到它并对其采取行动.

on Windows, your command line is in the PEB (Process Environment Block). You probably should not modify it, but you can find it and act upon it.

您可以使用 GetCommandLine() 找到它:https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx

you can find it using GetCommandLine(): https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx

并自己解析,或使用 CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx——然后​​启动一个你自己的新实例(使用 CreateProcess或 ShellExecute,无论适用),并终止.您的新实例将拥有正确的参数.

and parse it either yourself, or using CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx -- then launch a new instance of yourself (using CreateProcess or ShellExecute, whatever is applicable), and terminate. New instance of you will have the right params.

这篇关于使用 winapi 更改 argv[0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆