Changing argv[0] with winapi

元气小坏坏 提交于 2019-12-23 06:58:32

问题


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.

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

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?

Thanks


回答1:


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.

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

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.



来源:https://stackoverflow.com/questions/29158052/changing-argv0-with-winapi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!