Skip to content

Commit

Permalink
Replace https with http
Browse files Browse the repository at this point in the history
  • Loading branch information
hdrover committed Nov 5, 2024
1 parent 91143ae commit 45fab1a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Discord Drover

Discord Drover is a program that forces the Discord application for Windows to use a specified proxy server (HTTPS or SOCKS5) for TCP connections (chat, updates). This may be necessary because the original Discord application lacks proxy settings, and the global system proxy is also not used. Additionally, the program slightly interferes with Discord's outgoing UDP traffic, which helps bypass some local restrictions on voice chats.
Discord Drover is a program that forces the Discord application for Windows to use a specified proxy server (HTTP or SOCKS5) for TCP connections (chat, updates). This may be necessary because the original Discord application lacks proxy settings, and the global system proxy is also not used. Additionally, the program slightly interferes with Discord's outgoing UDP traffic, which helps bypass some local restrictions on voice chats.

The program works locally at the specific process level (without drivers) and does not affect the operating system globally. This approach serves as an alternative to using a global VPN (such as TUN interfaces and others).

Expand All @@ -10,16 +10,16 @@ To use Discord Drover, copy the `version.dll` and `drover.ini` files into the fo

### Example `drover.ini` Configuration:

```
```ini
[drover]
; Proxy can use https or socks5 protocols
proxy = https://127.0.0.1:1080
; Proxy can use http or socks5 protocols
proxy = http://127.0.0.1:1080

;use-nekobox-proxy = 1
;nekobox-proxy = https://127.0.0.1:2080
;nekobox-proxy = http://127.0.0.1:2080
```

- **proxy**: Defines the main proxy server to use for Discord (HTTPS or SOCKS5).
- **proxy**: Defines the main proxy server to use for Discord (HTTP or SOCKS5).
- **use-nekobox-proxy**: Enables the feature to detect if NekoBox is running and use a different proxy if found.
- **nekobox-proxy**: The proxy used when NekoBox is detected, typically `127.0.0.1:2080`.

Expand Down
18 changes: 9 additions & 9 deletions SocketManager.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TSocketManagerItem = record
isTcp: boolean;
isUdp: boolean;
hasSent: boolean;
fakeHttpsProxyFlag: boolean;
fakeHttpProxyFlag: boolean;
createdAt: integer;
end;

Expand All @@ -29,8 +29,8 @@ TSocketManager = class
public
procedure Add(sock: TSocket; sockType, sockProtocol: integer);
function IsFirstSend(sock: TSocket; var item: TSocketManagerItem): boolean;
procedure SetFakeHttpsProxyFlag(sock: TSocket);
function ResetFakeHttpsProxyFlag(sock: TSocket): boolean;
procedure SetFakeHttpProxyFlag(sock: TSocket);
function ResetFakeHttpProxyFlag(sock: TSocket): boolean;

constructor Create;
destructor Destroy; override;
Expand Down Expand Up @@ -94,7 +94,7 @@ procedure TSocketManager.Add(sock: TSocket; sockType, sockProtocol: integer);
item.isTcp := (sockType = SOCK_STREAM) and ((sockProtocol = IPPROTO_TCP) or (sockProtocol = 0));
item.isUdp := (sockType = SOCK_DGRAM) and ((sockProtocol = IPPROTO_UDP) or (sockProtocol = 0));
item.hasSent := false;
item.fakeHttpsProxyFlag := false;
item.fakeHttpProxyFlag := false;
item.createdAt := GetTickCount64;

criticalSection.Enter;
Expand Down Expand Up @@ -132,31 +132,31 @@ function TSocketManager.IsFirstSend(sock: TSocket; var item: TSocketManagerItem)
end;
end;

procedure TSocketManager.SetFakeHttpsProxyFlag(sock: TSocket);
procedure TSocketManager.SetFakeHttpProxyFlag(sock: TSocket);
var
i: integer;
begin
criticalSection.Enter;
try
i := FindIndexBySock(sock);
if i >= 0 then
items[i].fakeHttpsProxyFlag := true;
items[i].fakeHttpProxyFlag := true;
finally
criticalSection.Leave;
end;
end;

function TSocketManager.ResetFakeHttpsProxyFlag(sock: TSocket): boolean;
function TSocketManager.ResetFakeHttpProxyFlag(sock: TSocket): boolean;
var
i: integer;
begin
criticalSection.Enter;
try
i := FindIndexBySock(sock);
if (i = -1) or (not items[i].fakeHttpsProxyFlag) then
if (i = -1) or (not items[i].fakeHttpProxyFlag) then
exit(false);

items[i].fakeHttpsProxyFlag := false;
items[i].fakeHttpProxyFlag := false;
result := true;
finally
criticalSection.Leave;
Expand Down
37 changes: 22 additions & 15 deletions drover.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type

TProxyValue = record
url: string;
ipAndPort: string;
hostAndPort: string;
isSpecified: boolean;
isSocks5: boolean;

Expand Down Expand Up @@ -76,18 +76,25 @@ var
procedure TProxyValue.ParseFromString(url: string);
var
match: TMatch;
prot: string;
begin
self.url := url;
self.ipAndPort := url;
self.isSpecified := (url <> '');
self.url := '';
self.hostAndPort := '';
self.isSpecified := false;
self.isSocks5 := false;

match := TRegEx.match(url, '\Asocks5://(.*)\z');
if match.Success then
begin
self.ipAndPort := match.Groups[1].Value;
self.isSocks5 := true;
end;
match := TRegEx.match(Trim(url), '\A(?:([a-z\d]+)://)?(?:(.+):(.+)@)?(.+):(\d+)\z', [roIgnoreCase]);
if not match.Success then
exit;

prot := LowerCase(match.Groups[1].Value);
if (prot = '') or (prot = 'https') then
prot := 'http';

self.hostAndPort := match.Groups[4].Value + ':' + match.Groups[5].Value;
self.url := prot + '://' + self.hostAndPort;
self.isSpecified := true;
self.isSocks5 := (prot = 'socks5');
end;

function MyGetFileVersionInfoA(lptstrFilename: LPSTR; dwHandle, dwLen: DWORD; lpData: Pointer): bool; stdcall;
Expand Down Expand Up @@ -167,7 +174,7 @@ begin
if (Pos('http_proxy', s) > 0) or (Pos('HTTP_PROXY', s) > 0) or (Pos('https_proxy', s) > 0) or
(Pos('HTTPS_PROXY', s) > 0) then
begin
newValue := proxyValue.ipAndPort;
newValue := proxyValue.hostAndPort;
StringToWideChar(newValue, lpBuffer, nSize);
result := Length(newValue);
exit;
Expand Down Expand Up @@ -263,7 +270,7 @@ begin
lpCompletionRoutine);
end;

function ConvertHttpsToSocks5(socketManagerItem: TSocketManagerItem; const buf; len, flags: integer): bool;
function ConvertHttpToSocks5(socketManagerItem: TSocketManagerItem; const buf; len, flags: integer): bool;
var
s, targetHost: RawByteString;
targetPort: word;
Expand Down Expand Up @@ -325,7 +332,7 @@ begin
if RealSend(sock, s[1], i, flags) <> i then
exit;

sockManager.SetFakeHttpsProxyFlag(sock);
sockManager.SetFakeHttpProxyFlag(sock);

result := true;
end;
Expand All @@ -336,7 +343,7 @@ var
begin
if sockManager.IsFirstSend(sock, sockManagerItem) then
begin
if ConvertHttpsToSocks5(sockManagerItem, buf, len, flags) then
if ConvertHttpToSocks5(sockManagerItem, buf, len, flags) then
exit(len);
end;

Expand All @@ -350,7 +357,7 @@ var
begin
result := RealRecv(sock, buf, len, flags);

if (result > 0) and sockManager.ResetFakeHttpsProxyFlag(sock) then
if (result > 0) and sockManager.ResetFakeHttpProxyFlag(sock) then
begin
if result >= 10 then
begin
Expand Down
6 changes: 3 additions & 3 deletions drover.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[drover]
; Proxy can use https or socks5 protocols
proxy = https://127.0.0.1:1080
; Proxy can use http or socks5 protocols
proxy = http://127.0.0.1:1080

;use-nekobox-proxy = 1
;nekobox-proxy = https://127.0.0.1:2080
;nekobox-proxy = http://127.0.0.1:2080

0 comments on commit 45fab1a

Please sign in to comment.