7 Commits

Author SHA1 Message Date
9bec33c358 Update bug_report.md 2025-04-08 11:36:51 +03:00
3e6b5dbb43 Merge branch 'master' of https://github.com/EnderIce2/rpc-bridge 2025-04-08 11:14:41 +03:00
4c432a0e50 Fix #12, socket -14 (EFAULT) 2025-04-08 11:14:32 +03:00
65b5625a57 Update error message for Wine compatibility check 2025-04-08 08:21:03 +03:00
EnderIce2
9d2440f616 Update LICENSE
Some checks failed
Build and Deploy docs / deploy (push) Failing after 12m12s
Build and Deploy docs / build (push) Failing after 6m5s
2025-01-04 06:55:43 +02:00
EnderIce2
51cbb666f9 Update build-deploy.yml
Some checks failed
Build and Deploy docs / build (push) Failing after 4m46s
Build and Deploy docs / deploy (push) Failing after 48s
2024-12-30 00:27:21 +02:00
EnderIce2
1deccc5a63 Update CODE_OF_CONDUCT.md
Some checks failed
Build and Deploy docs / build (push) Failing after 28s
Build and Deploy docs / deploy (push) Failing after 34s
2024-12-11 05:54:45 +02:00
7 changed files with 69 additions and 58 deletions

View File

@@ -21,11 +21,11 @@ Steps to reproduce the behavior:
If applicable, add screenshots to help explain your problem. If applicable, add screenshots to help explain your problem.
**Log File** **Log File**
Located in `/path/to/prefix/drive_c/windows/logs/bridge.log` Located in `/path/to/prefix/drive_c/windows/logs/bridge.log` or a screenshot with the terminal should suffice.
**Device (please complete the following information):** **System Info (please complete the following information):**
- OS: [e.g. SteamOS, Ubuntu, macOS] - OS: [e.g. SteamOS 3.0, Ubuntu 22.04, macOS 15, or output from command `uname -srm`]
- Version [e.g. 22.04] - Wine: [e.g. 10.5]
**Additional context** **Additional context**
Add any other context about the problem here. Add any other context about the problem here.

View File

@@ -15,7 +15,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: dependencies - name: dependencies
run: sudo apt-get update && sudo apt-get install gcc-mingw-w64 make run: sudo apt update && sudo apt -y install gcc-mingw-w64 make
- name: make - name: make
run: make run: make
- name: artifact - name: artifact

View File

@@ -60,7 +60,7 @@ representative at an online or offline event.
Instances of abusive, harassing, or otherwise unacceptable behavior may be Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at reported to the community leaders responsible for enforcement at
contact@enderice2.com. enderice2@protonmail.com.
All complaints will be reviewed and investigated promptly and fairly. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the All community leaders are obligated to respect the privacy and security of the

View File

@@ -1,4 +1,4 @@
Copyright (c) 2024 EnderIce2 Copyright (c) 2025 EnderIce2
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -5,7 +5,7 @@ GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD) GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
CFLAGS = -std=c17 -Wno-int-conversion -DGIT_COMMIT='"$(GIT_COMMIT)"' -DGIT_BRANCH='"$(GIT_BRANCH)"' CFLAGS = -std=c17 -Wno-int-conversion -DGIT_COMMIT='"$(GIT_COMMIT)"' -DGIT_BRANCH='"$(GIT_BRANCH)"'
LFLAGS = -lgdi32 LFLAGS = -lgdi32 -lws2_32
# DBGFLAGS = -Wl,--export-all-symbols -g -O0 -ggdb3 -Wall # DBGFLAGS = -Wl,--export-all-symbols -g -O0 -ggdb3 -Wall

109
bridge.c
View File

@@ -195,11 +195,7 @@ char *native_getenv(const char *name)
/* I hope the 0x20000 is okay */ /* I hope the 0x20000 is okay */
if (environStr == NULL) if (environStr == NULL)
{ environStr = sys_mmap(0x20000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
environStr = sys_mmap(0x20000, 4096, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
print("Allocated 4096 bytes at %#lx\n", environStr);
}
if ((uintptr_t)environStr > 0x7effffff) if ((uintptr_t)environStr > 0x7effffff)
print("Warning: environStr %#lx is above 2GB\n", environStr); print("Warning: environStr %#lx is above 2GB\n", environStr);
@@ -209,18 +205,17 @@ char *native_getenv(const char *name)
int fd = sys_open(environStr, O_RDONLY, 0); int fd = sys_open(environStr, O_RDONLY, 0);
// sys_munmap(environStr, 4096);
if (fd < 0) if (fd < 0)
{ {
print("Failed to open /proc/self/environ: %d\n", fd); print("Failed to open /proc/self/environ: %d\n", fd);
return NULL; return NULL;
} }
char buffer[4096]; char *buffer = sys_mmap(0x22000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
char *result = NULL; char *result = NULL;
int bytesRead; int bytesRead;
while ((bytesRead = sys_read(fd, buffer, sizeof(buffer) - 1)) > 0) while ((bytesRead = sys_read(fd, buffer, 0x1000 - 1)) > 0)
{ {
buffer[bytesRead] = '\0'; buffer[bytesRead] = '\0';
char *env = buffer; char *env = buffer;
@@ -290,8 +285,8 @@ void ConnectToSocket(int fd)
"%s/snap.discord-canary/discord-ipc-%d", "%s/snap.discord-canary/discord-ipc-%d",
}; };
struct sockaddr_un socketAddr; struct sockaddr_un *socketAddr = sys_mmap(0x23000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
socketAddr.sun_family = AF_UNIX; socketAddr->sun_family = AF_UNIX;
int sockRet = 0; int sockRet = 0;
for (int i = 0; i < sizeof(discordUnixSockets) / sizeof(discordUnixSockets[0]); i++) for (int i = 0; i < sizeof(discordUnixSockets) / sizeof(discordUnixSockets[0]); i++)
@@ -302,15 +297,20 @@ void ConnectToSocket(int fd)
for (int j = 0; j < 16; j++) for (int j = 0; j < 16; j++)
{ {
snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j); snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j);
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath); strcpy_s(socketAddr->sun_path, sizeof(socketAddr->sun_path), pipePath);
print("Probing %s\n", pipePath); print("Probing %s\n", pipePath);
if (IsLinux) if (IsLinux)
{ {
unsigned long socketArgs[] = { // unsigned long socketArgs[] = {
(unsigned long)fd, // (unsigned long)fd,
(unsigned long)(intptr_t)&socketAddr, // (unsigned long)(intptr_t)&socketAddr,
sizeof(socketAddr)}; // sizeof(socketAddr)};
unsigned long *socketArgs = sys_mmap(0x24000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
socketArgs[0] = (unsigned long)fd;
socketArgs[1] = (unsigned long)(intptr_t)socketAddr;
socketArgs[2] = sizeof(struct sockaddr_un);
socketArgs[3] = 0;
sockRet = sys_socketcall(SYS_CONNECT, socketArgs); sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
} }
@@ -345,18 +345,17 @@ void ConnectToSocket(int fd)
void PipeBufferInThread(LPVOID lpParam) void PipeBufferInThread(LPVOID lpParam)
{ {
bridge_thread *bt = (bridge_thread *)lpParam; bridge_thread *bt = (bridge_thread *)lpParam;
print("In thread started using fd %d and pipe %#x\n", print("In thread started using fd %d and pipe %#x\n", bt->fd, bt->hPipe);
bt->fd, bt->hPipe);
int EOFCount = 0; int EOFCount = 0;
char *l_buffer = sys_mmap(0x25000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
while (TRUE) while (TRUE)
{ {
char buffer[BUFFER_LENGTH]; char buffer[BUFFER_LENGTH];
int read = sys_read(bt->fd, buffer, sizeof(buffer)); int read = sys_read(bt->fd, l_buffer, BUFFER_LENGTH);
if (unlikely(read < 0)) if (unlikely(read < 0))
{ {
print("Failed to read from unix pipe: %d\n", print("Failed to read from unix pipe: %d\n", read);
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
@@ -378,14 +377,16 @@ void PipeBufferInThread(LPVOID lpParam)
} }
EOFCount = 0; EOFCount = 0;
memcpy(buffer, l_buffer, read);
print("Reading %d bytes from unix pipe: \"", read); print("Reading %d bytes from unix pipe: \"", read);
for (int i = 0; i < read; i++) for (int i = 0; i < read; i++)
print("%c", buffer[i]); print("%c", buffer[i]);
print("\"\n"); print("\"\n");
DWORD dwWritten; DWORD dwWritten;
if (unlikely(!WriteFile(bt->hPipe, buffer, read, WINBOOL bResult = WriteFile(bt->hPipe, buffer, read, &dwWritten, NULL);
&dwWritten, NULL))) if (unlikely(bResult == FALSE))
{ {
if (GetLastError() == ERROR_BROKEN_PIPE) if (GetLastError() == ERROR_BROKEN_PIPE)
{ {
@@ -394,16 +395,14 @@ void PipeBufferInThread(LPVOID lpParam)
break; break;
} }
print("Failed to read from pipe: %d\n", print("Failed to read from pipe: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
if (unlikely(dwWritten < 0)) if (unlikely(dwWritten < 0))
{ {
print("Failed to write to pipe: %d\n", print("Failed to write to pipe: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
@@ -411,8 +410,8 @@ void PipeBufferInThread(LPVOID lpParam)
while (dwWritten < read) while (dwWritten < read)
{ {
int last_written = dwWritten; int last_written = dwWritten;
if (unlikely(!WriteFile(bt->hPipe, buffer + dwWritten, WINBOOL bResult = WriteFile(bt->hPipe, buffer + dwWritten, read - dwWritten, &dwWritten, NULL);
read - dwWritten, &dwWritten, NULL))) if (unlikely(bResult == FALSE))
{ {
if (GetLastError() == ERROR_BROKEN_PIPE) if (GetLastError() == ERROR_BROKEN_PIPE)
{ {
@@ -421,16 +420,14 @@ void PipeBufferInThread(LPVOID lpParam)
break; break;
} }
print("Failed to read from pipe: %d\n", print("Failed to read from pipe: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
if (unlikely(last_written == dwWritten)) if (unlikely(last_written == dwWritten))
{ {
print("Failed to write to pipe: %d\n", print("Failed to write to pipe: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
@@ -441,15 +438,14 @@ void PipeBufferInThread(LPVOID lpParam)
void PipeBufferOutThread(LPVOID lpParam) void PipeBufferOutThread(LPVOID lpParam)
{ {
bridge_thread *bt = (bridge_thread *)lpParam; bridge_thread *bt = (bridge_thread *)lpParam;
print("Out thread started using fd %d and pipe %#x\n", print("Out thread started using fd %d and pipe %#x\n", bt->fd, bt->hPipe);
bt->fd, bt->hPipe); char *l_buffer = sys_mmap(0x25000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
while (TRUE) while (TRUE)
{ {
char buffer[BUFFER_LENGTH]; char buffer[BUFFER_LENGTH];
DWORD dwRead; DWORD dwRead;
WINBOOL bResult = ReadFile(bt->hPipe, buffer, BUFFER_LENGTH, &dwRead, NULL);
if (unlikely(!ReadFile(bt->hPipe, buffer, sizeof(buffer), if (unlikely(bResult == FALSE))
&dwRead, NULL)))
{ {
if (GetLastError() == ERROR_BROKEN_PIPE) if (GetLastError() == ERROR_BROKEN_PIPE)
{ {
@@ -458,8 +454,7 @@ void PipeBufferOutThread(LPVOID lpParam)
break; break;
} }
print("Failed to read from pipe: %d\n", print("Failed to read from pipe: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
@@ -469,11 +464,11 @@ void PipeBufferOutThread(LPVOID lpParam)
print("%c", buffer[i]); print("%c", buffer[i]);
print("\"\n"); print("\"\n");
int written = sys_write(bt->fd, buffer, dwRead); memcpy(l_buffer, buffer, dwRead);
int written = sys_write(bt->fd, l_buffer, dwRead);
if (unlikely(written < 0)) if (unlikely(written < 0))
{ {
print("Failed to write to socket: %d\n", print("Failed to write to socket: %d\n", written);
written);
continue; continue;
} }
@@ -483,8 +478,7 @@ void PipeBufferOutThread(LPVOID lpParam)
written += sys_write(bt->fd, buffer + written, dwRead - written); written += sys_write(bt->fd, buffer + written, dwRead - written);
if (unlikely(last_written == written)) if (unlikely(last_written == written))
{ {
print("Failed to write to socket: %d\n", print("Failed to write to socket: %s\n", GetErrorMessage());
GetErrorMessage());
Sleep(1000); Sleep(1000);
continue; continue;
} }
@@ -547,16 +541,31 @@ NewConnection:
int fd; int fd;
if (IsLinux) if (IsLinux)
{ {
unsigned long socketArgs[] = { // unsigned long socketArgs[] = {
(unsigned long)AF_UNIX, // (unsigned long)AF_UNIX,
(unsigned long)SOCK_STREAM, // (unsigned long)SOCK_STREAM,
0}; // 0};
unsigned long *socketArgs = sys_mmap(0x21000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
socketArgs[0] = (unsigned long)AF_UNIX;
socketArgs[1] = (unsigned long)SOCK_STREAM;
socketArgs[2] = 0;
fd = sys_socketcall(SYS_SOCKET, socketArgs); fd = sys_socketcall(SYS_SOCKET, socketArgs);
/* FIXME: WSAEAFNOSUPPORT: https://gitlab.winehq.org/wine/wine/-/merge_requests/2786 */
// WSADATA wsaData;
// int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
// if (iResult != 0)
// printf("WSAStartup failed: %d\n", iResult);
// fd = socket(AF_UNIX, SOCK_STREAM, 0);
} }
else else
fd = sys_socket(AF_UNIX, SOCK_STREAM, 0); fd = sys_socket(AF_UNIX, SOCK_STREAM, 0);
print("Socket %d created\n", fd); if (fd == INVALID_SOCKET)
{
print("invalid socket: %d %d\n", fd, WSAGetLastError());
ExitProcess(1);
}
if (fd < 0) if (fd < 0)
{ {
@@ -567,6 +576,8 @@ NewConnection:
ExitProcess(1); ExitProcess(1);
} }
print("Socket %d created\n", fd);
ConnectToSocket(fd); ConnectToSocket(fd);
print("Connected to Discord\n"); print("Connected to Discord\n");

2
main.c
View File

@@ -59,7 +59,7 @@ void DetectWine()
if (!GetProcAddress(hNTdll, "wine_get_version")) if (!GetProcAddress(hNTdll, "wine_get_version"))
{ {
MessageBox(NULL, "This program is only intended to run under Wine.", MessageBox(NULL, "This program is only intended to run under Wine.",
GetErrorMessage(), MB_OK | MB_ICONINFORMATION); "Error", MB_OK | MB_ICONINFORMATION);
ExitProcess(1); ExitProcess(1);
} }