Fix --fake on Windows

This commit is contained in:
ruti 2024-08-25 11:28:24 +03:00
parent 9fb5cfbd63
commit 2e244fd1b8
2 changed files with 8 additions and 8 deletions

View File

@ -270,13 +270,12 @@ ssize_t send_fake(int sfd, char *buffer,
else { else {
pkt = cnt != IS_HTTP ? fake_tls : fake_http; pkt = cnt != IS_HTTP ? fake_tls : fake_http;
} }
size_t psz = pkt.size;
if (opt->fake_offset) { if (opt->fake_offset) {
if (psz > opt->fake_offset) { if (pkt.size > opt->fake_offset) {
psz -= opt->fake_offset; pkt.size -= opt->fake_offset;
pkt.data += opt->fake_offset; pkt.data += opt->fake_offset;
} }
else psz = 0; else pkt.size = 0;
} }
char path[MAX_PATH], temp[MAX_PATH + 1]; char path[MAX_PATH], temp[MAX_PATH + 1];
@ -306,11 +305,12 @@ ssize_t send_fake(int sfd, char *buffer,
uniperror("CreateEvent"); uniperror("CreateEvent");
break; break;
} }
if (!WriteFile(hfile, pkt.data, psz < pos ? psz : pos, 0, 0)) { DWORD wrtcnt = 0;
if (!WriteFile(hfile, pkt.data, pkt.size < pos ? pkt.size : pos, &wrtcnt, 0)) {
uniperror("WriteFile"); uniperror("WriteFile");
break; break;
} }
if (psz < pos) { if (pkt.size < pos) {
if (SetFilePointer(hfile, pos, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { if (SetFilePointer(hfile, pos, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer"); uniperror("SetFilePointer");
break; break;
@ -341,7 +341,7 @@ ssize_t send_fake(int sfd, char *buffer,
uniperror("SetFilePointer"); uniperror("SetFilePointer");
break; break;
} }
if (!WriteFile(hfile, buffer, pos, 0, 0)) { if (!WriteFile(hfile, buffer, pos, &wrtcnt, 0)) {
uniperror("WriteFile"); uniperror("WriteFile");
break; break;
} }

2
main.c
View File

@ -23,7 +23,7 @@
#define close(fd) closesocket(fd) #define close(fd) closesocket(fd)
#endif #endif
#define VERSION "13" #define VERSION "13.1"
char ip_option[1] = "\0"; char ip_option[1] = "\0";