I got a code here which was taken from someone on this site and it might help you but it doesn't show how to change the port though. The function just redirect your client to specific IP defined by IPAdd. For the port, you may ask with with the smart people because I am pretty bad with this memory things :D.
Code:
public static int connect(uint PID, string IPAdd)
{
IntPtr ws2Handle = native.LoadLibrary("WS2_32.dll");
if (ws2Handle == null)
{
native.FreeLibrary(ws2Handle);
return 1;
}
IntPtr cHandle = native.OpenProcess(enumProcessAccessFlags.VMOperation | enumProcessAccessFlags.VMRead | enumProcessAccessFlags.VMWrite | enumProcessAccessFlags.All, true, PID);
if (cHandle == null)
{
native.FreeLibrary(ws2Handle);
return 2;
}
IntPtr inet_addr = native.GetProcAddress(native.GetModuleHandle("WS2_32.dll"), "inet_addr");
if (inet_addr == null)
{
native.FreeLibrary(ws2Handle);
return 3;
}
byte[] buffer = { 0xb8, 0x0, 0x0, 0x0, 0x0, 0xc2, 0x4, 0x0, 0x90, 0x90 };
byte[] byteIPaddress = IPAddress.Parse(IPAdd).GetAddressBytes();
System.Buffer.BlockCopy(byteIPaddress, 0, buffer, 1, byteIPaddress.Length);
//Get the original value
if (firstflg)
{
int bytesRead = 0;
native.ReadProcessMemory(cHandle, inet_addr, bufferread, (uint)bufferread.Length, out bytesRead);
firstflg = false;
}
int bytesWritten = 0;
if (!native.WriteProcessMemory(cHandle, inet_addr, buffer, (uint)buffer.Length, out bytesWritten))
{
native.FreeLibrary(ws2Handle);
return 4;
}
native.CloseHandle(cHandle);
native.FreeLibrary(ws2Handle);
return 0;
}
Hope this will help you.