temp file in memory, remove tabs

This commit is contained in:
ruti 2024-03-18 04:42:40 +03:00
parent 3da60eb357
commit 542a04bffb

121
desync.c
View file

@ -135,20 +135,20 @@ int send_fake(int sfd, char *buffer,
char path[MAX_PATH + 1]; char path[MAX_PATH + 1];
int ps = GetTempPath(sizeof(path), path); int ps = GetTempPath(sizeof(path), path);
if (!ps) { if (!ps) {
uniperror("GetTempPath"); uniperror("GetTempPath");
return -1; return -1;
} }
if (!GetTempFileName(path, "t", 0, path)) { if (!GetTempFileName(path, "t", 0, path)) {
uniperror("GetTempFileName"); uniperror("GetTempFileName");
return -1; return -1;
} }
LOG(LOG_L, "temp file: %s\n", path); LOG(LOG_L, "temp file: %s\n", path);
HANDLE hfile = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, HANDLE hfile = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (hfile == INVALID_HANDLE_VALUE) { if (hfile == INVALID_HANDLE_VALUE) {
uniperror("CreateFileA"); uniperror("CreateFileA");
return -1; return -1;
} }
@ -158,63 +158,60 @@ int send_fake(int sfd, char *buffer,
while (status) { while (status) {
ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!ov.hEvent) { if (!ov.hEvent) {
uniperror("CreateEvent"); uniperror("CreateEvent");
break; break;
} }
if (!WriteFile(hfile, pkt.data, psz < pos ? psz : pos, 0, 0)) { if (!WriteFile(hfile, pkt.data, psz < pos ? psz : pos, 0, 0)) {
uniperror("WriteFile"); uniperror("WriteFile");
break; break;
} }
if (psz < pos) { if (psz < 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;
} }
if (!SetEndOfFile(hfile)) { if (!SetEndOfFile(hfile)) {
uniperror("SetFileEnd"); uniperror("SetFileEnd");
break; break;
} }
} }
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer"); uniperror("SetFilePointer");
break; break;
} }
if (setttl(sfd, ttl, fa) < 0) { if (setttl(sfd, ttl, fa) < 0) {
break; break;
} }
if (!TransmitFile(sfd, hfile, pos, pos, &ov, if (!TransmitFile(sfd, hfile, pos, pos, &ov,
NULL, TF_USE_KERNEL_APC | TF_WRITE_BEHIND)) { NULL, TF_USE_KERNEL_APC | TF_WRITE_BEHIND)) {
if ((GetLastError() != ERROR_IO_PENDING) if ((GetLastError() != ERROR_IO_PENDING)
&& (WSAGetLastError() != WSA_IO_PENDING)) { && (WSAGetLastError() != WSA_IO_PENDING)) {
uniperror("TransmitFile"); uniperror("TransmitFile");
break; break;
} }
} }
delay(params.sfdelay); delay(params.sfdelay);
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer"); uniperror("SetFilePointer");
break; break;
} }
if (!WriteFile(hfile, buffer, pos, 0, 0)) { if (!WriteFile(hfile, buffer, pos, 0, 0)) {
uniperror("WriteFile"); uniperror("WriteFile");
break; break;
} }
if (setttl(sfd, params.def_ttl, fa) < 0) { if (setttl(sfd, params.def_ttl, fa) < 0) {
break; break;
} }
status = 0; status = 0;
} }
if (!CloseHandle(hfile)) { if (!CloseHandle(hfile)) {
uniperror("CloseHandle hfile"); uniperror("CloseHandle hfile");
} }
if (!CloseHandle(ov.hEvent)) { if (ov.hEvent && !CloseHandle(ov.hEvent)) {
uniperror("CloseHandle hEvent"); uniperror("CloseHandle hEvent");
} }
if (!DeleteFile(path)) {
uniperror("DeleteFile");
}
return status; return status;
} }
#endif #endif