PROBLEM:
I have a program dummy.exe on windows. this program will bind to UDP port 5060, after started. but another program also want to bind port 5060.
WHAT I HAVE DONE:
- using windbg to start dummy.exe, and set breakpoint on ws2_32!bind
- when the breakpoint hit, i changed the parameter (port val开发者_StackOverflow中文版ue) with command ew
- this dummy.exe will bind to the new port, and worked well.
QUESTION:
- How can i do that easily? write a simple windows debugger?
- Maybe i can hacking or modify the dummy.exe file, but how to do that?
- what's your way to achieve this?
thanks
EDIT1:
Thanks very much @Cody Gray and @cdhowie
- This software do not provide functionality to change port.
- I need use this software to communicate with others who also use this software.
- For 'simple' debugger, i mean call CreateProcess with flag DEBUG_PROCESS to start dummy.exe, and WaitForDebugEvent, then hook the ws2_32!bind function to modify the port parameter, but i do not sure wheather it works
- i used UltraEdit to find the value 0x13C4 (5060), but after i changed the value, it does not works :( , any suggestion?
I see two options here. First, along the lines of what you already mentioned, you can patch the parameters to the bind()
call at runtime, using hooking. Popular libraries to do that are Detours or madCodeHook, or example. This would definitely work, I used to do that myself.
The second option you also already mentioned, although I'd suggest not using a hex editor to simply search for those values, there might be multiple occurrences in the file and using only a hex editor, it might be hard to find the right one. What you can do, however, is use a debugger that is able to write a modified image back to disk. OllyDbg offers a very comfortable way to do that.
I'd suggest going for the hooking method though, that way, you can inject code around the binding to read the port from a configuration file, or similar in order to avoid the need to patch the executable or recompile your code time and again.
精彩评论