[UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError
=
true)]
delegate
int
Dconnect(IntPtr s, IntPtr addr,
int
addrsize);
int
connect_Hooked(IntPtr s, IntPtr addr,
int
addrsize)
{
sockaddr_in structure
=
(sockaddr_in)Marshal.PtrToStructure(addr, typeof(sockaddr_in));
string remoteIp
=
new System.Net.IPAddress(structure.sin_addr.S_addr).ToString();
if
(remoteIp.Contains(
"121.138.16.15"
))
{
SetAddr(addr,
"127.0.0.1"
,
"6448"
);
}
var res
=
connect(s, addr, addrsize);
/
/
res始终是
-
1
,不知何解?????
return
res;
}
public struct sockaddr_in
{
public const
int
Size
=
16
;
public short sin_family;
public ushort sin_port;
public struct in_addr
{
public uint S_addr;
public struct _S_un_b
{
public byte s_b1, s_b2, s_b3, s_b4;
}
public _S_un_b S_un_b;
public struct _S_un_w
{
public ushort s_w1, s_w2;
}
public _S_un_w S_un_w;
}
public in_addr sin_addr;
}
private void SetAddr(IntPtr addr, string ip, string port)
{
sockaddr_in structure
=
(sockaddr_in)Marshal.PtrToStructure(addr, typeof(sockaddr_in));
structure.sin_addr.S_addr
=
inet_addr(ip);
structure.sin_port
=
htons(Convert.ToUInt16(port));
Marshal.StructureToPtr(structure, addr, true);
structure
=
(sockaddr_in)Marshal.PtrToStructure(addr, typeof(sockaddr_in));
}