问题描述
我的目标是更改应用程序重新启动的路径.我没有访问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/zh-CN/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/zh-cn/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]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!