mirror of
https://github.com/hufrea/byedpi.git
synced 2024-11-25 16:25:32 +03:00
--fake on Windows
This commit is contained in:
parent
6b39efdd7a
commit
3da60eb357
5 changed files with 103 additions and 9 deletions
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ all:
|
|||
$(CC) $(CFLAGS) $(SOURCES) -I . -o $(TARGET)
|
||||
|
||||
windows:
|
||||
$(CC) $(CFLAGS) $(SOURCES) -I . -lws2_32 -o $(TARGET).exe
|
||||
$(CC) $(CFLAGS) $(SOURCES) -I . -lws2_32 -lmswsock -o $(TARGET).exe
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) *.o
|
||||
|
|
97
desync.c
97
desync.c
|
@ -24,6 +24,7 @@
|
|||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <mswsock.h>
|
||||
#endif
|
||||
|
||||
#include <params.h>
|
||||
|
@ -124,6 +125,100 @@ int send_fake(int sfd, char *buffer,
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
int send_fake(int sfd, char *buffer,
|
||||
int cnt, long pos, int fa, int ttl)
|
||||
{
|
||||
struct packet pkt = cnt != IS_HTTP ? fake_tls : fake_http;
|
||||
size_t psz = pkt.size;
|
||||
|
||||
char path[MAX_PATH + 1];
|
||||
int ps = GetTempPath(sizeof(path), path);
|
||||
if (!ps) {
|
||||
uniperror("GetTempPath");
|
||||
return -1;
|
||||
}
|
||||
if (!GetTempFileName(path, "t", 0, path)) {
|
||||
uniperror("GetTempFileName");
|
||||
return -1;
|
||||
}
|
||||
LOG(LOG_L, "temp file: %s\n", path);
|
||||
|
||||
HANDLE hfile = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hfile == INVALID_HANDLE_VALUE) {
|
||||
uniperror("CreateFileA");
|
||||
return -1;
|
||||
}
|
||||
|
||||
OVERLAPPED ov = {};
|
||||
int status = -1;
|
||||
|
||||
while (status) {
|
||||
ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (!ov.hEvent) {
|
||||
uniperror("CreateEvent");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!WriteFile(hfile, pkt.data, psz < pos ? psz : pos, 0, 0)) {
|
||||
uniperror("WriteFile");
|
||||
break;
|
||||
}
|
||||
if (psz < pos) {
|
||||
if (SetFilePointer(hfile, pos, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
|
||||
uniperror("SetFilePointer");
|
||||
break;
|
||||
}
|
||||
if (!SetEndOfFile(hfile)) {
|
||||
uniperror("SetFileEnd");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
|
||||
uniperror("SetFilePointer");
|
||||
break;
|
||||
}
|
||||
if (setttl(sfd, ttl, fa) < 0) {
|
||||
break;
|
||||
}
|
||||
if (!TransmitFile(sfd, hfile, pos, pos, &ov,
|
||||
NULL, TF_USE_KERNEL_APC | TF_WRITE_BEHIND)) {
|
||||
if ((GetLastError() != ERROR_IO_PENDING)
|
||||
&& (WSAGetLastError() != WSA_IO_PENDING)) {
|
||||
uniperror("TransmitFile");
|
||||
break;
|
||||
}
|
||||
}
|
||||
delay(params.sfdelay);
|
||||
|
||||
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
|
||||
uniperror("SetFilePointer");
|
||||
break;
|
||||
}
|
||||
if (!WriteFile(hfile, buffer, pos, 0, 0)) {
|
||||
uniperror("WriteFile");
|
||||
break;
|
||||
}
|
||||
if (setttl(sfd, params.def_ttl, fa) < 0) {
|
||||
break;
|
||||
}
|
||||
status = 0;
|
||||
}
|
||||
if (!CloseHandle(hfile)) {
|
||||
uniperror("CloseHandle hfile");
|
||||
}
|
||||
if (!CloseHandle(ov.hEvent)) {
|
||||
uniperror("CloseHandle hEvent");
|
||||
}
|
||||
if (!DeleteFile(path)) {
|
||||
uniperror("DeleteFile");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
int send_oob(int sfd, char *buffer,
|
||||
ssize_t n, long pos)
|
||||
{
|
||||
|
@ -263,7 +358,7 @@ int desync(int sfd, char *buffer, size_t bfsize,
|
|||
|
||||
int s = 0;
|
||||
switch (part.m) {
|
||||
#ifdef __linux__
|
||||
#ifdef FAKE_SUPPORT
|
||||
case DESYNC_FAKE:
|
||||
s = send_fake(sfd,
|
||||
buffer + lp, type, pos - lp, fa, dp.ttl ? dp.ttl : 8);
|
||||
|
|
6
main.c
6
main.c
|
@ -16,15 +16,9 @@
|
|||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#define FAKE_SUPPORT 1
|
||||
#define TIMEOUT_SUPPORT 1
|
||||
#endif
|
||||
#else
|
||||
#include <ws2tcpip.h>
|
||||
#define close(fd) closesocket(fd)
|
||||
#define TIMEOUT_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#define VERSION 6
|
||||
|
|
5
params.h
5
params.h
|
@ -7,6 +7,11 @@
|
|||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(_WIN32)
|
||||
#define FAKE_SUPPORT 1
|
||||
#define TIMEOUT_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#define OFFSET_SNI 1
|
||||
#define OFFSET_HOST 2
|
||||
|
||||
|
|
2
proxy.c
2
proxy.c
|
@ -890,4 +890,4 @@ int run(struct sockaddr_ina *srv)
|
|||
}
|
||||
return event_loop(fd);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue