805 lines
38 KiB
C
805 lines
38 KiB
C
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include "startup_locale_windows.h"
|
|
|
|
#include "bridge_coordinator.private.h"
|
|
#include "wine_preopen_hook.private.h"
|
|
#include "poll_coordinator.private.h"
|
|
#include "direct_profile5_prepare.h"
|
|
#include "direct_two_site_install.h"
|
|
#include "pipe_live_input.h"
|
|
#include "pipe_return_callback.h"
|
|
#include "wire_public_hash_v1.private.h"
|
|
#include "wire_public_addon_v1.private.h"
|
|
#include "realm_install_diagnostic.h"
|
|
#include "realm_seam_page.h"
|
|
#include "clogin_realm_rows.h"
|
|
#include "wine_engine_realm.h"
|
|
#include "wire_realm_owner_bind.private.h"
|
|
#include "wine_session_retirement.h"
|
|
#include "login_state_journal.h"
|
|
#include "original_c49_capture.h"
|
|
#include "original_connect_export_hook.h"
|
|
|
|
_Static_assert(MEM_COMMIT == 0x1000u && MEM_PRIVATE == 0x20000u &&
|
|
MEM_MAPPED == 0x40000u && PAGE_NOACCESS == 0x01u,
|
|
"Win32 page constants changed");
|
|
|
|
/* Exact exported profile5 frame ABI; the Wire module owns the storage. */
|
|
struct GwWireFrameMirror {
|
|
uint32_t abi, size;
|
|
volatile LONG command, completed, calls, thread, error;
|
|
volatile LONG initialize_status, call_status, result, echoed, elapsed_ms;
|
|
struct GwPollHost *host;
|
|
WCHAR filename[512];
|
|
};
|
|
_Static_assert(sizeof(struct GwWireFrameMirror) == 1080,
|
|
"Profile5 frame ABI changed");
|
|
|
|
typedef void (WINAPI *GwWireFrameCallback)(void *owner);
|
|
extern void gw_pipe_return_thunk(void);
|
|
extern void gw_bridge_nohelper_log(uint32_t event, uint32_t result, uint32_t error);
|
|
|
|
__declspec(dllexport) struct GwBridgeNohelperStatus gw_bridge_nohelper_status = {
|
|
1, sizeof(struct GwBridgeNohelperStatus)
|
|
};
|
|
|
|
static HMODULE bridge_module, wire_module;
|
|
static GwWireFrameCallback wire_frame_callback;
|
|
static struct GwWireFrameMirror *wire_frame;
|
|
static struct GwWirePreOpenHook *preopen_hook;
|
|
static struct GwWirePreOpenHook *postopen_hook;
|
|
static struct GwPollHost poll_host = {1, sizeof(struct GwPollHost)};
|
|
static struct GwPollCoordinator poll_coordinator;
|
|
static struct GwPollOwnerSnapshot poll_snapshot;
|
|
static struct GwDirectInstallation direct_installation;
|
|
static struct gw_wire_auth_control *wire_auth;
|
|
static struct gw_engine_realm_control *wire_realm;
|
|
static struct gw_wire_auth_credentials *wire_credentials;
|
|
static struct gw_session_retirement_control *wire_retirement;
|
|
static struct GwWirePublicHashV1 *wire_public_hash;
|
|
static struct GwWirePublicAddonV1 *wire_public_addon;
|
|
static struct gw_pipe_control *wire_pipe_control;
|
|
static struct gw_session_pipe_tables *wire_pipe_tables;
|
|
static struct gw_session_pipe_callbacks *wire_pipe_callbacks;
|
|
static struct gw_session_pipe_receivers *wire_pipe_receivers;
|
|
static uint32_t (*wire_pipe_generation)(void);
|
|
/* Existing Wire export: one bounded numeric challenge/proof rejection detail. */
|
|
static uint32_t (WINAPI *wire_auth_detail_v1)(uint32_t);
|
|
static LONG (WINAPI *wire_priority_begin)(uint32_t);
|
|
static struct gw_pipe_live_input_context pipe_input;
|
|
static struct gw_pipe_return_runtime pipe_runtime;
|
|
static uint32_t credential_generation;
|
|
#define GW_OWNED_INPUT_RETRY_LIMIT 8
|
|
#define GW_FRAME_ADMISSION_RETRY_LIMIT 120
|
|
static volatile LONG start_once, input_once, input_attempts, frame_once,
|
|
frame_admission_attempts, preopen_once, preopen_defer_once,
|
|
preopen_touch_once, auth_detail_once;
|
|
static char version_hash_path[1024], addon_tail_path[1024];
|
|
|
|
static void profile_input(void *owner, struct GwDirectProfile5Input *profile) {
|
|
*profile = (struct GwDirectProfile5Input){0};
|
|
profile->abi = 1;
|
|
profile->size = sizeof(*profile);
|
|
profile->wire_module = wire_module;
|
|
profile->owner = owner;
|
|
profile->original_owner_slot = (void *volatile *)(uintptr_t)0x145e7a098ULL;
|
|
profile->client_thread = poll_snapshot.primary_thread;
|
|
profile->frame_admitted = 1;
|
|
profile->frame_host = &poll_host;
|
|
profile->version_hash_path = version_hash_path;
|
|
profile->addon_tail_path = addon_tail_path;
|
|
}
|
|
|
|
static int same_directory_file(HMODULE module, const char *file,
|
|
char output[1024]) {
|
|
DWORD length = GetModuleFileNameA(module, output, 1024);
|
|
DWORD last = 0, i, j;
|
|
if (!length || length >= 1024) return 0;
|
|
for (i = 0; i < length; ++i)
|
|
if (output[i] == '\\' || output[i] == '/') last = i + 1;
|
|
if (!last) return 0;
|
|
for (j = 0; file[j]; ++j) {
|
|
if (last + j + 1 >= 1024) return 0;
|
|
output[last + j] = file[j];
|
|
}
|
|
output[last + j] = 0;
|
|
return 1;
|
|
}
|
|
|
|
/* Read a public, immutable 20-byte version hash on the Windows side. The
|
|
* backend receives the bytes through Wire-owned storage, never this path. */
|
|
static int read_public_version_hash(const char *path, uint8_t output[20]) {
|
|
HANDLE file;
|
|
DWORD count = 0;
|
|
uint8_t exact[21] = {0};
|
|
int accepted = 0;
|
|
if (!path || !output) return 0;
|
|
file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,
|
|
FILE_ATTRIBUTE_NORMAL, 0);
|
|
if (file == INVALID_HANDLE_VALUE) return 0;
|
|
if (ReadFile(file, exact, sizeof(exact), &count, 0) && count == 20) {
|
|
memcpy(output, exact, 20);
|
|
accepted = 1;
|
|
}
|
|
SecureZeroMemory(exact, sizeof(exact));
|
|
CloseHandle(file);
|
|
return accepted;
|
|
}
|
|
|
|
static int read_public_addon_tail(const char *path, uint8_t output[10000],
|
|
uint32_t *bytes) {
|
|
HANDLE file;
|
|
DWORD count = 0;
|
|
int accepted = 0;
|
|
if (!path || !output || !bytes) return 0;
|
|
file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,
|
|
FILE_ATTRIBUTE_NORMAL, 0);
|
|
if (file == INVALID_HANDLE_VALUE) return 0;
|
|
if (ReadFile(file, output, 10000, &count, 0) && count < 10000) {
|
|
*bytes = count;
|
|
accepted = 1;
|
|
}
|
|
CloseHandle(file);
|
|
return accepted;
|
|
}
|
|
|
|
static uint32_t publish_public_login_inputs(uint32_t generation) {
|
|
uint8_t version_hash[20] = {0};
|
|
uint8_t addon_bytes[10000] = {0};
|
|
uint32_t addon_count = 0;
|
|
uint32_t result = 0;
|
|
if (!wire_public_hash ||
|
|
!read_public_version_hash(version_hash_path, version_hash)) {
|
|
result = 7;
|
|
goto done;
|
|
}
|
|
if (!wire_public_addon ||
|
|
!read_public_addon_tail(addon_tail_path, addon_bytes, &addon_count)) {
|
|
result = 8;
|
|
goto done;
|
|
}
|
|
if (!gw_wire_public_hash_publish(wire_public_hash, generation, version_hash)) {
|
|
result = 7;
|
|
goto done;
|
|
}
|
|
if (!gw_wire_public_addon_publish(wire_public_addon, generation,
|
|
addon_bytes, addon_count)) {
|
|
result = 8;
|
|
goto done;
|
|
}
|
|
done:
|
|
SecureZeroMemory(version_hash, sizeof(version_hash));
|
|
SecureZeroMemory(addon_bytes, sizeof(addon_bytes));
|
|
return result;
|
|
}
|
|
|
|
static int bridge_read(void *context, uintptr_t address, void *destination,
|
|
size_t bytes) {
|
|
SIZE_T copied = 0;
|
|
(void)context;
|
|
return address && destination && bytes &&
|
|
ReadProcessMemory(GetCurrentProcess(), (const void *)address,
|
|
destination, bytes, &copied) && copied == bytes;
|
|
}
|
|
|
|
static int bridge_page(uintptr_t address, size_t bytes, int write, int execute) {
|
|
MEMORY_BASIC_INFORMATION info = {0};
|
|
uintptr_t beginning, ending;
|
|
DWORD protect;
|
|
if (!address || !bytes || VirtualQuery((const void *)address, &info,
|
|
sizeof(info)) != sizeof(info) ||
|
|
info.State != MEM_COMMIT || (info.Protect & (PAGE_GUARD | PAGE_NOACCESS)))
|
|
return 0;
|
|
beginning = (uintptr_t)info.BaseAddress;
|
|
ending = beginning + info.RegionSize;
|
|
if (ending < beginning || address < beginning || bytes > ending - address)
|
|
return 0;
|
|
protect = info.Protect & 0xffu;
|
|
if (execute)
|
|
return protect == PAGE_EXECUTE || protect == PAGE_EXECUTE_READ ||
|
|
protect == PAGE_EXECUTE_READWRITE || protect == PAGE_EXECUTE_WRITECOPY;
|
|
if (write)
|
|
return protect == PAGE_READWRITE || protect == PAGE_WRITECOPY ||
|
|
protect == PAGE_EXECUTE_READWRITE || protect == PAGE_EXECUTE_WRITECOPY;
|
|
return 1;
|
|
}
|
|
|
|
static int bridge_executable(void *context, uintptr_t address) {
|
|
(void)context;
|
|
return bridge_page(address, 1, 0, 1);
|
|
}
|
|
|
|
static int bridge_writable(void *context, uintptr_t address, size_t bytes) {
|
|
(void)context;
|
|
return bridge_page(address, bytes, 1, 0);
|
|
}
|
|
|
|
static uint32_t bridge_current_thread(void *context) {
|
|
(void)context;
|
|
return GetCurrentThreadId();
|
|
}
|
|
|
|
static int wire_image_span(HMODULE module, uintptr_t *begin, uintptr_t *end) {
|
|
IMAGE_DOS_HEADER dos = {0};
|
|
IMAGE_NT_HEADERS64 nt = {0};
|
|
uintptr_t base = (uintptr_t)module;
|
|
if (!base || !begin || !end || !bridge_read(0, base, &dos, sizeof(dos)) ||
|
|
dos.e_magic != IMAGE_DOS_SIGNATURE || dos.e_lfanew < 0 ||
|
|
dos.e_lfanew > 4096 ||
|
|
!bridge_read(0, base + (uintptr_t)dos.e_lfanew, &nt, sizeof(nt)) ||
|
|
nt.Signature != IMAGE_NT_SIGNATURE ||
|
|
nt.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC ||
|
|
nt.OptionalHeader.SizeOfImage < 4096 ||
|
|
nt.OptionalHeader.SizeOfImage > 64u * 1024u * 1024u ||
|
|
base + nt.OptionalHeader.SizeOfImage < base)
|
|
return 0;
|
|
*begin = base;
|
|
*end = base + nt.OptionalHeader.SizeOfImage;
|
|
return 1;
|
|
}
|
|
|
|
static int WINAPI bridge_preopen(void *owner) {
|
|
struct GwRealmInstallDiagnostic page_probe = {0};
|
|
int seam_page, seam_touched = 0;
|
|
if (gw_bridge_nohelper_status.stage != 2 ||
|
|
!gw_bridge_nohelper_status.login_installed ||
|
|
(uintptr_t)owner != poll_snapshot.owner ||
|
|
GetCurrentThreadId() != poll_snapshot.primary_thread ||
|
|
!wire_auth || !wire_credentials ||
|
|
InterlockedCompareExchange((volatile LONG *)&wire_auth->state, 2, 2) != 2 ||
|
|
InterlockedCompareExchange((volatile LONG *)&wire_auth->server_proof_verified, 1, 1) != 1 ||
|
|
InterlockedCompareExchange((volatile LONG *)&wire_auth->transport_prepared, 1, 1) != 1 ||
|
|
InterlockedCompareExchange((volatile LONG *)&wire_credentials->state, 3, 3) != 3 ||
|
|
wire_credentials->generation != credential_generation ||
|
|
wire_credentials->consumed_generation != credential_generation) {
|
|
gw_bridge_nohelper_log(10, 0, 1);
|
|
return 0;
|
|
}
|
|
/* Lazily protected seam page: run its in-page ret once (as original
|
|
* OpenRealm's first call into this page would), then defer if still
|
|
* protected. Event102 records the post-touch protection. */
|
|
seam_page = gw_realm_seam_page_prepare(0x141e448adULL, 16, 0x141e448b2ULL,
|
|
gw_realm_install_probe_page,
|
|
&preopen_touch_once, &page_probe,
|
|
&seam_touched);
|
|
if (seam_touched)
|
|
gw_bridge_nohelper_log(102, page_probe.page_protect,
|
|
page_probe.page_identity_bits);
|
|
if (seam_page == 2) {
|
|
if (InterlockedCompareExchange(&preopen_defer_once, 1, 0) == 0) {
|
|
gw_bridge_nohelper_log(36, page_probe.page_state,
|
|
page_probe.page_protect);
|
|
gw_bridge_nohelper_log(37, page_probe.page_type,
|
|
page_probe.page_identity_bits);
|
|
}
|
|
return 2;
|
|
}
|
|
if (InterlockedCompareExchange(&preopen_once, 1, 0) != 0) {
|
|
gw_bridge_nohelper_log(10, 0, 1);
|
|
return 0;
|
|
}
|
|
pipe_input.abi = 1;
|
|
pipe_input.size = sizeof(pipe_input);
|
|
pipe_input.owner = poll_snapshot.owner;
|
|
pipe_input.bound_owner_vtable = poll_snapshot.clone_vtable;
|
|
pipe_input.primary_thread = poll_snapshot.primary_thread;
|
|
pipe_input.auth = wire_auth;
|
|
pipe_input.credentials = wire_credentials;
|
|
pipe_input.pipe_generation = wire_pipe_generation;
|
|
pipe_input.control = wire_pipe_control;
|
|
pipe_input.tables = wire_pipe_tables;
|
|
pipe_input.callbacks = wire_pipe_callbacks;
|
|
pipe_input.receivers = wire_pipe_receivers;
|
|
pipe_input.probe_context = 0;
|
|
pipe_input.read = bridge_read;
|
|
pipe_input.executable = bridge_executable;
|
|
pipe_input.writable = bridge_writable;
|
|
pipe_runtime.abi = 1;
|
|
pipe_runtime.size = sizeof(pipe_runtime);
|
|
pipe_runtime.expected_owner = poll_snapshot.owner;
|
|
pipe_runtime.primary_thread = poll_snapshot.primary_thread;
|
|
pipe_runtime.context = &pipe_input;
|
|
pipe_runtime.current_thread = bridge_current_thread;
|
|
pipe_runtime.prepare_input = gw_pipe_live_prepare_input;
|
|
pipe_runtime.read = pipe_input.read;
|
|
pipe_runtime.read_context = pipe_input.probe_context;
|
|
pipe_runtime.control = wire_pipe_control;
|
|
pipe_runtime.tables = (struct gw_private_pipe_tables *)wire_pipe_tables;
|
|
if ((direct_installation.state == 1 &&
|
|
gw_pipe_return_bind(&pipe_runtime)) ||
|
|
(direct_installation.state == 2 && pipe_runtime.state != 1)) {
|
|
gw_bridge_nohelper_log(10, 0, 2);
|
|
return 0;
|
|
}
|
|
/* V19 Wire binds realm.owner only in its retired hardware-postreturn
|
|
* mode. Bind the same owned export here before the genuine OpenRealm call.
|
|
* No original owner field or login readiness state is changed. */
|
|
if (gw_wire_realm_bind_direct_owner(wire_realm, preopen_hook,
|
|
owner, GetCurrentThreadId(), credential_generation,
|
|
wire_pipe_generation ? wire_pipe_generation() : 0) != 1) {
|
|
(void)gw_pipe_return_disarm_if_unpublished(&pipe_runtime);
|
|
gw_bridge_nohelper_log(33, 0, 1);
|
|
return 0;
|
|
}
|
|
gw_bridge_nohelper_log(33, 1, 0);
|
|
/* V21 uses the single exact constructor-seam transaction. The prior
|
|
* postreturn hardware route did not bind before first native pipe use. */
|
|
|
|
{
|
|
int realm_install_result = direct_installation.state == 1
|
|
? gw_direct_install_realm_site(&direct_installation, 1) : 0;
|
|
if (realm_install_result) {
|
|
int disarmed = gw_pipe_return_disarm_if_unpublished(&pipe_runtime);
|
|
/* The installer already observed this site and, for a transaction
|
|
* failure, the admission page. Publish numeric facts once here. */
|
|
gw_bridge_nohelper_log(10, (uint32_t)-realm_install_result,
|
|
gw_realm_install_diagnostic.detail);
|
|
if (realm_install_result == -2 || realm_install_result == -3) {
|
|
gw_bridge_nohelper_log(12,
|
|
gw_realm_install_diagnostic.read_bytes,
|
|
gw_realm_install_diagnostic.winerror);
|
|
gw_bridge_nohelper_log(13,
|
|
gw_realm_install_diagnostic.page_query_bytes,
|
|
gw_realm_install_diagnostic.page_query_error);
|
|
gw_bridge_nohelper_log(15,
|
|
gw_realm_install_diagnostic.page_state,
|
|
gw_realm_install_diagnostic.page_protect);
|
|
gw_bridge_nohelper_log(16,
|
|
gw_realm_install_diagnostic.page_type,
|
|
gw_realm_install_diagnostic.page_identity_bits);
|
|
}
|
|
if (realm_install_result == -4) {
|
|
gw_bridge_nohelper_log(12,
|
|
gw_realm_install_diagnostic.page_state,
|
|
gw_realm_install_diagnostic.page_protect);
|
|
gw_bridge_nohelper_log(13,
|
|
gw_realm_install_diagnostic.admission_reason,
|
|
gw_realm_install_diagnostic.winerror);
|
|
}
|
|
if (gw_wire_realm_unbind_direct_owner(wire_realm, owner) != 1)
|
|
gw_bridge_nohelper_log(33, 0, 2);
|
|
if (disarmed)
|
|
gw_bridge_nohelper_log(14, 0, (uint32_t)disarmed);
|
|
return 0;
|
|
}
|
|
}
|
|
/* Reuse the installer observation; no second page query or RPM. */
|
|
gw_bridge_nohelper_log(12, gw_realm_install_diagnostic.read_bytes,
|
|
gw_realm_install_diagnostic.winerror);
|
|
gw_bridge_nohelper_log(13, gw_realm_install_diagnostic.page_query_bytes,
|
|
gw_realm_install_diagnostic.page_query_error);
|
|
gw_bridge_nohelper_log(15, gw_realm_install_diagnostic.page_state,
|
|
gw_realm_install_diagnostic.page_protect);
|
|
gw_bridge_nohelper_log(16, gw_realm_install_diagnostic.page_type,
|
|
gw_realm_install_diagnostic.page_identity_bits);
|
|
gw_bridge_nohelper_log(10, 1, 0);
|
|
return 1;
|
|
}
|
|
|
|
/* Host submit for the owned sign-in row (engine_registration.c contract:
|
|
* borrowed bytes and lengths for this call, positive attempt or negative). */
|
|
static int owned_signin_submit(void *context, const char *account, size_t account_size,
|
|
const char *password, size_t password_size) {
|
|
(void)context;
|
|
return gw_direct_login_submit_texts(account, account_size, password, password_size);
|
|
}
|
|
|
|
static void bridge_rearm_after_retire(void *owner) {
|
|
struct GwDirectProfile5Input profile;
|
|
struct GwDirectLoginBinding login = {0};
|
|
uint32_t next;
|
|
if (gw_bridge_nohelper_status.stage != 2 || !credential_generation ||
|
|
!wire_retirement || !wire_frame || !wire_auth || !wire_credentials ||
|
|
(uint64_t)(uintptr_t)owner != poll_snapshot.owner ||
|
|
GetCurrentThreadId() != poll_snapshot.primary_thread ||
|
|
(direct_installation.state != 1 && direct_installation.state != 2) ||
|
|
wire_retirement->abi != 1 ||
|
|
wire_retirement->size != sizeof(*wire_retirement) ||
|
|
InterlockedCompareExchange((volatile LONG *)&wire_retirement->state,
|
|
2, 2) != 2 ||
|
|
wire_retirement->owner != (uint64_t)(uintptr_t)owner ||
|
|
wire_retirement->completed_credentials_generation !=
|
|
credential_generation)
|
|
return;
|
|
if (gw_direct_login_site_retired()) {
|
|
/* Always re-arm: restore the verified one-shot patch for the next
|
|
* Login once the previous generation is fully retired. */
|
|
int rearm = gw_direct_rearm_login_site(&direct_installation);
|
|
if (rearm == -5) return; /* retry on a later frame */
|
|
gw_bridge_nohelper_log(101, rearm == 0, (uint32_t)-rearm);
|
|
if (rearm != 0) {
|
|
gw_bridge_nohelper_status.error = 28;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(100, credential_generation, 28);
|
|
return;
|
|
}
|
|
}
|
|
next = wire_retirement->next_credentials_generation;
|
|
if (next != credential_generation + 1 ||
|
|
wire_frame->completed != 1 || wire_frame->error != 0 ||
|
|
InterlockedCompareExchange(&wire_frame->command, 2, 2) != 2 ||
|
|
wire_auth->state != 0 || wire_credentials->state != 0) {
|
|
gw_bridge_nohelper_status.error = 17;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return;
|
|
}
|
|
profile_input(owner, &profile);
|
|
if (gw_direct_profile5_prepare(&profile, &login) ||
|
|
login.generation != next ||
|
|
publish_public_login_inputs(next) ||
|
|
(direct_installation.state == 2 &&
|
|
gw_pipe_return_rearm_after_retire(&pipe_runtime,
|
|
(uintptr_t)owner, poll_snapshot.primary_thread)) ||
|
|
gw_direct_login_rebind(&login)) {
|
|
gw_bridge_nohelper_status.error = 18;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return;
|
|
}
|
|
credential_generation = next;
|
|
if (!wire_priority_begin || wire_priority_begin(next) != 0) {
|
|
gw_bridge_nohelper_status.error = 31;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return;
|
|
}
|
|
InterlockedExchange(&preopen_once, 0);
|
|
InterlockedExchange(&preopen_defer_once, 0);
|
|
InterlockedExchange(&preopen_touch_once, 0);
|
|
InterlockedExchange(&auth_detail_once, 0);
|
|
gw_bridge_nohelper_log(38, next, 0);
|
|
}
|
|
|
|
static void WINAPI bridge_frame_wrapper(void *owner) {
|
|
struct GwDirectProfile5Input profile = {0};
|
|
struct GwDirectLoginBinding login = {0};
|
|
struct GwDirectInstallConfig install = {0};
|
|
uint32_t public_input_error;
|
|
int install_result, pages_ready;
|
|
if (!wire_frame_callback) return;
|
|
wire_frame_callback(owner);
|
|
if(wire_auth && wire_credentials && wire_frame && wire_retirement){
|
|
const struct GwLoginJournalState state={
|
|
(int32_t)credential_generation,(int32_t)gw_direct_login_published_generation(),
|
|
wire_credentials->state,(int32_t)wire_credentials->consumed_generation,
|
|
wire_auth->state,wire_auth->error,wire_auth->auth_result,
|
|
wire_auth->discovery_result,wire_auth->realm_count,wire_auth->transport_prepared,
|
|
wire_frame->command,wire_frame->error,wire_retirement->state,wire_retirement->result};
|
|
gw_startup_record_login_state(&state);
|
|
}
|
|
if (gw_bridge_nohelper_status.stage == 2 && credential_generation &&
|
|
!gw_direct_login_site_retired() &&
|
|
gw_direct_login_published_generation() == credential_generation &&
|
|
(uint64_t)(uintptr_t)owner == poll_snapshot.owner &&
|
|
GetCurrentThreadId() == poll_snapshot.primary_thread) {
|
|
static uint32_t retry_generation;
|
|
static uint64_t retry_at, retry_until;
|
|
const uint64_t now = GetTickCount64();
|
|
int retirement;
|
|
if (retry_generation != credential_generation) {
|
|
retry_generation = credential_generation;
|
|
retry_at = retry_until = 0;
|
|
}
|
|
if (now < retry_at) return;
|
|
retirement = gw_direct_retire_login_site_after_capture(
|
|
&direct_installation, credential_generation, owner);
|
|
gw_bridge_nohelper_log(99, retirement == 0,
|
|
retirement == 0 ? 0u : (uint32_t)-retirement);
|
|
if (retirement != 0) {
|
|
if (retirement == -2 || retirement == -5) {
|
|
/* Preserve the transaction class: admission.reason is zero
|
|
* for failures after the page-admission phase. */
|
|
gw_bridge_nohelper_log(104,
|
|
gw_direct_retire_diagnostic.transaction_result,
|
|
gw_direct_retire_diagnostic.reason);
|
|
gw_bridge_nohelper_log(105,
|
|
gw_direct_retire_diagnostic.index,
|
|
gw_direct_retire_diagnostic.winerror);
|
|
gw_bridge_nohelper_log(106,
|
|
gw_direct_retire_diagnostic.state,
|
|
gw_direct_retire_diagnostic.protect);
|
|
}
|
|
if (retirement == -5) {
|
|
/* No writes, or verified rollback. Do not kill a live Bridge
|
|
* for a transient thread/page admission failure after reject/cancel. */
|
|
if (!retry_until) retry_until = now + 15000;
|
|
if (now < retry_until) { retry_at = now + 100; return; }
|
|
}
|
|
gw_bridge_nohelper_status.error = 29;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return;
|
|
}
|
|
retry_at = retry_until = 0;
|
|
}
|
|
bridge_rearm_after_retire(owner);
|
|
if (gw_bridge_nohelper_status.stage == 2 &&
|
|
gw_direct_login_published_generation() == credential_generation &&
|
|
(uint64_t)(uintptr_t)owner == poll_snapshot.owner)
|
|
gw_c49_capture_on_owned_frame(owner, poll_snapshot.primary_thread);
|
|
/* A failed Source attempt is observed once on the same admitted owner.
|
|
* The value is zero for a generic local exception, or the existing Wire
|
|
* phase/code detail for a server challenge/proof rejection. No account,
|
|
* password, pointer, or packet content is logged. */
|
|
if (wire_auth && wire_credentials && credential_generation &&
|
|
(uint64_t)(uintptr_t)owner == poll_snapshot.owner &&
|
|
InterlockedCompareExchange((volatile LONG *)&wire_auth->state, 3, 3) == 3 &&
|
|
InterlockedCompareExchange((volatile LONG *)&wire_auth->auth_result, -2, -2) == -2 &&
|
|
wire_credentials->consumed_generation == credential_generation &&
|
|
InterlockedCompareExchange(&auth_detail_once, 1, 0) == 0) {
|
|
uint32_t detail = wire_auth_detail_v1 ? wire_auth_detail_v1(credential_generation) : 0;
|
|
gw_bridge_nohelper_log(11, detail, wire_auth_detail_v1 ? 0 : 1);
|
|
}
|
|
if (InterlockedCompareExchange(&input_once, 1, 1) != 1 ||
|
|
InterlockedCompareExchange(&frame_once, 0, 0) != 0 ||
|
|
gw_bridge_nohelper_status.stage != 1)
|
|
return;
|
|
/* Qualify the callback before executing a pinned in-page ret. Both pages
|
|
* can remain lazy-protected indefinitely without a first execution; their
|
|
* client-owned handler and later owner frames do the bounded retry. */
|
|
if (!gw_poll_coordinator_frame_admitted(&poll_coordinator, &poll_snapshot) ||
|
|
(uint64_t)(uintptr_t)owner != poll_snapshot.owner) {
|
|
LONG attempts = InterlockedIncrement(&frame_admission_attempts);
|
|
gw_bridge_nohelper_status.error = 4;
|
|
if (attempts >= GW_FRAME_ADMISSION_RETRY_LIMIT) {
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(3, 0, 4);
|
|
} else if (attempts == 1) {
|
|
gw_bridge_nohelper_log(3, 0, 4);
|
|
}
|
|
return;
|
|
}
|
|
InterlockedExchange(&frame_admission_attempts, 0);
|
|
InterlockedCompareExchange(&gw_bridge_nohelper_status.error, 0, 4);
|
|
pages_ready = gw_direct_front_pages_prepare();
|
|
if (pages_ready == 2) return;
|
|
if (pages_ready != 1) {
|
|
gw_bridge_nohelper_status.error = 30;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(5, 0, 30);
|
|
return;
|
|
}
|
|
if (InterlockedCompareExchange(&frame_once, 1, 0) != 0) return;
|
|
gw_bridge_nohelper_status.frame_admitted = 1;
|
|
gw_bridge_nohelper_log(3, 1, 0);
|
|
profile_input(owner, &profile);
|
|
if (gw_direct_profile5_prepare(&profile, &login)) {
|
|
gw_bridge_nohelper_status.error = 5;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(4, 0, 5);
|
|
return;
|
|
}
|
|
credential_generation = login.generation;
|
|
public_input_error = publish_public_login_inputs(credential_generation);
|
|
if (public_input_error) {
|
|
gw_bridge_nohelper_status.error = (LONG)public_input_error;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(4, 0, public_input_error);
|
|
return;
|
|
}
|
|
gw_bridge_nohelper_log(4, 1, 0);
|
|
install.abi = 1;
|
|
install.size = sizeof(install);
|
|
install.frame_admitted = 1;
|
|
install.pipe_return_thunk = (uintptr_t)&gw_pipe_return_thunk;
|
|
install.login = login;
|
|
install_result = gw_direct_install_login_site(&install, &direct_installation);
|
|
if (install_result) {
|
|
/* Exact installer branch only; no client bytes or credentials. */
|
|
gw_bridge_nohelper_log(45, (uint32_t)-install_result,
|
|
gw_direct_admission.reason);
|
|
gw_bridge_nohelper_status.error = 6;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
gw_bridge_nohelper_log(5, 0, 6);
|
|
return;
|
|
}
|
|
gw_bridge_nohelper_status.login_installed = 1;
|
|
preopen_hook->owner = owner;
|
|
preopen_hook->primary_thread = poll_snapshot.primary_thread;
|
|
preopen_hook->bridge_module = bridge_module;
|
|
preopen_hook->callback = bridge_preopen;
|
|
InterlockedExchange(&preopen_hook->ready, 1);
|
|
gw_bridge_nohelper_status.preopen_ready = 1;
|
|
gw_bridge_nohelper_status.stage = 2;
|
|
/* The native authorization worker opens the system browser after the
|
|
* admitted login frame. This returns immediately and sees no game creds. */
|
|
if (!wire_priority_begin || wire_priority_begin(credential_generation) != 0) {
|
|
gw_bridge_nohelper_status.error = 31;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return;
|
|
}
|
|
gw_bridge_nohelper_log(5, 1, 0);
|
|
}
|
|
|
|
int gw_bridge_nohelper_start(HMODULE module, DWORD primary_thread) {
|
|
char wire_path[1024];
|
|
LONG reason = 11;
|
|
if (InterlockedCompareExchange(&start_once, 1, 0) != 0) return 0;
|
|
bridge_module = module;
|
|
if (!module || !primary_thread ||
|
|
!same_directory_file(module, "GWNativeWire.dll", wire_path) ||
|
|
!same_directory_file(module, "version-hash.bin", version_hash_path) ||
|
|
!same_directory_file(module, "addon-tail.bin", addon_tail_path))
|
|
goto fail;
|
|
wire_module = LoadLibraryExA(wire_path, 0, 0x00000100u | 0x00001000u);
|
|
if (!wire_module) { reason = 12000 + (LONG)GetLastError(); goto fail; }
|
|
reason = 13;
|
|
wire_frame = (struct GwWireFrameMirror *)GetProcAddress(wire_module, "gw_wire_frame_data");
|
|
{
|
|
FARPROC proc = GetProcAddress(wire_module, "gw_wire_frame_callback");
|
|
_Static_assert(sizeof(proc) == sizeof(wire_frame_callback),
|
|
"Wire frame callback pointer size changed");
|
|
memcpy(&wire_frame_callback, &proc, sizeof(proc));
|
|
}
|
|
preopen_hook = (struct GwWirePreOpenHook *)GetProcAddress(wire_module, "gw_wire_preopen_hook_data");
|
|
postopen_hook = (struct GwWirePreOpenHook *)GetProcAddress(wire_module, "gw_wire_postopen_hook_data");
|
|
wire_auth = (struct gw_wire_auth_control *)GetProcAddress(wire_module, "gw_wire_auth_data");
|
|
wire_realm = (struct gw_engine_realm_control *)GetProcAddress(wire_module, "gw_wire_realm_data");
|
|
wire_credentials = (struct gw_wire_auth_credentials *)GetProcAddress(wire_module, "gw_wire_auth_credentials_data");
|
|
wire_retirement = (struct gw_session_retirement_control *)GetProcAddress(
|
|
wire_module, "gw_wire_session_retirement_data");
|
|
wire_public_hash = (struct GwWirePublicHashV1 *)GetProcAddress(wire_module, "gw_wire_public_hash_data");
|
|
wire_public_addon = (struct GwWirePublicAddonV1 *)GetProcAddress(wire_module, "gw_wire_public_addon_data");
|
|
wire_pipe_control = (struct gw_pipe_control *)GetProcAddress(wire_module, "gw_wire_pipe_data");
|
|
wire_pipe_tables = (struct gw_session_pipe_tables *)GetProcAddress(wire_module, "gw_wire_session_pipe_tables");
|
|
wire_pipe_callbacks = (struct gw_session_pipe_callbacks *)GetProcAddress(wire_module, "gw_wire_session_pipe_callbacks");
|
|
wire_pipe_receivers = (struct gw_session_pipe_receivers *)GetProcAddress(wire_module, "gw_wire_session_pipe_receivers");
|
|
{
|
|
FARPROC pipe_generation = GetProcAddress(wire_module, "gw_wire_pipe_generation_export");
|
|
FARPROC auth_detail = GetProcAddress(wire_module, "gw_source_auth_detail_v1");
|
|
FARPROC priority_begin = GetProcAddress(wire_module, "gw_wire_priority_begin");
|
|
_Static_assert(sizeof(pipe_generation) == sizeof(wire_pipe_generation) &&
|
|
sizeof(auth_detail) == sizeof(wire_auth_detail_v1) &&
|
|
sizeof(priority_begin) == sizeof(wire_priority_begin),
|
|
"Wire function pointer size changed");
|
|
memcpy(&wire_pipe_generation, &pipe_generation, sizeof(pipe_generation));
|
|
memcpy(&wire_auth_detail_v1, &auth_detail, sizeof(auth_detail));
|
|
memcpy(&wire_priority_begin, &priority_begin, sizeof(priority_begin));
|
|
}
|
|
if (!wire_frame || wire_frame->abi != 1 || wire_frame->size != sizeof(*wire_frame) ||
|
|
!wire_frame_callback || !preopen_hook || preopen_hook->abi != 1 ||
|
|
preopen_hook->size != sizeof(*preopen_hook) || preopen_hook->ready ||
|
|
(postopen_hook && (postopen_hook->abi != 1 ||
|
|
postopen_hook->size != sizeof(*postopen_hook) ||
|
|
postopen_hook->ready || postopen_hook->error ||
|
|
postopen_hook->owner || postopen_hook->primary_thread ||
|
|
postopen_hook->bridge_module || postopen_hook->callback ||
|
|
preopen_hook->reserved)) ||
|
|
!wire_auth || !wire_realm || wire_realm->abi != 1 ||
|
|
wire_realm->size != sizeof(*wire_realm) || wire_realm->stage ||
|
|
wire_realm->error || wire_realm->owner ||
|
|
!wire_credentials || !wire_retirement || !wire_priority_begin ||
|
|
wire_retirement->abi != 1 ||
|
|
wire_retirement->size != sizeof(*wire_retirement) ||
|
|
!wire_public_hash || !wire_public_addon ||
|
|
wire_public_hash->abi != 1 || wire_public_hash->size != sizeof(*wire_public_hash) ||
|
|
wire_public_hash->state || wire_public_hash->generation ||
|
|
wire_public_addon->abi != 1 || wire_public_addon->size != sizeof(*wire_public_addon) ||
|
|
wire_public_addon->state || wire_public_addon->generation ||
|
|
wire_public_addon->byte_count ||
|
|
!wire_pipe_control || !wire_pipe_tables ||
|
|
!wire_pipe_callbacks || !wire_pipe_receivers || !wire_pipe_generation ||
|
|
!wire_image_span(wire_module, &pipe_input.callback_module_begin,
|
|
&pipe_input.callback_module_end))
|
|
goto fail;
|
|
{
|
|
/* Helper-free equivalent of engine_wire_host.prepare_realm_snapshot. */
|
|
extern struct RegistrationRealmBinding { uint32_t abi, size; volatile uint32_t ready, error; uint64_t module, snapshot, select; }
|
|
gw_registration_realm_binding;
|
|
FARPROC snapshot = GetProcAddress(wire_module, "gw_wire_account_ui_snapshot");
|
|
FARPROC select = GetProcAddress(wire_module, "gw_wire_account_ui_select");
|
|
if (snapshot && select && gw_registration_realm_binding.abi == 2 &&
|
|
gw_registration_realm_binding.size == 40 && !gw_registration_realm_binding.ready) {
|
|
gw_registration_realm_binding.module = (uint64_t)(uintptr_t)wire_module;
|
|
gw_registration_realm_binding.snapshot = (uint64_t)(uintptr_t)snapshot;
|
|
gw_registration_realm_binding.select = (uint64_t)(uintptr_t)select;
|
|
MemoryBarrier();
|
|
gw_registration_realm_binding.ready = 1;
|
|
}
|
|
/* Owned sign-in row: the page's two texts go through the same
|
|
* capture binding, mailbox command and generation as a stock-site
|
|
* Login; the submit copies them for the call only. */
|
|
{
|
|
extern struct RegistrationSignInBinding { uint32_t abi, size; volatile uint32_t ready, error; uint64_t module, submit, context; }
|
|
gw_registration_signin_binding;
|
|
if (gw_registration_signin_binding.abi == 1 &&
|
|
gw_registration_signin_binding.size == 40 && !gw_registration_signin_binding.ready) {
|
|
gw_registration_signin_binding.module = (uint64_t)(uintptr_t)bridge_module;
|
|
gw_registration_signin_binding.submit = (uint64_t)(uintptr_t)&owned_signin_submit;
|
|
gw_registration_signin_binding.context = 0;
|
|
MemoryBarrier();
|
|
gw_registration_signin_binding.ready = 1;
|
|
}
|
|
}
|
|
/* Both public and local creation glue require this bound provider.
|
|
* It reads the actual Wire-owned realm state and queues genuine
|
|
* Source creation; endpoint selection and auth are unchanged. */
|
|
{
|
|
int rows = gw_clogin_realm_rows_install();
|
|
gw_bridge_nohelper_log(120, rows ? 0u : 1u, (uint32_t)-rows);
|
|
}
|
|
/* Gitea #13: no client traffic to Blizzard (breaking news, telemetry). Event 123: see gw_blizzard_egress_install. */
|
|
{
|
|
extern uint32_t gw_blizzard_egress_install(void);
|
|
uint32_t hosts = gw_blizzard_egress_install();
|
|
gw_bridge_nohelper_log(123, hosts & 0xff00u ? 1u : 0u, hosts);
|
|
{ /* #119: how long the private-memory scan took (ms) and how much it read (MiB) */
|
|
extern uint32_t gw_blizzard_egress_scan_ms, gw_blizzard_egress_scan_mb;
|
|
gw_bridge_nohelper_log(124, gw_blizzard_egress_scan_mb, gw_blizzard_egress_scan_ms);
|
|
}
|
|
}
|
|
}
|
|
poll_coordinator.abi = 1;
|
|
poll_coordinator.size = sizeof(poll_coordinator);
|
|
poll_coordinator.region.owner_global = 0x145e7a098ULL;
|
|
poll_coordinator.region.vtable_low = 0x1447c2000ULL;
|
|
poll_coordinator.region.vtable_high = 0x145663024ULL;
|
|
poll_coordinator.region.code_low = 0x140001000ULL;
|
|
poll_coordinator.region.code_high = 0x1447c145cULL;
|
|
poll_coordinator.region.primary_thread = primary_thread;
|
|
poll_coordinator.host = &poll_host;
|
|
poll_coordinator.frame_host_slot = (void **)&wire_frame->host;
|
|
poll_coordinator.frame_callback = bridge_frame_wrapper;
|
|
poll_coordinator.frame_command = &wire_frame->command;
|
|
poll_coordinator.frame_completed = &wire_frame->completed;
|
|
poll_coordinator.frame_initialize_status = &wire_frame->initialize_status;
|
|
poll_coordinator.frame_error = &wire_frame->error;
|
|
gw_bridge_nohelper_status.primary_thread = primary_thread;
|
|
gw_bridge_nohelper_status.wire_loaded = 1;
|
|
gw_bridge_nohelper_status.stage = 1;
|
|
return 1;
|
|
fail:
|
|
gw_bridge_nohelper_status.error = reason;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return 0;
|
|
}
|
|
|
|
int gw_bridge_nohelper_on_owned_input(HWND hwnd, DWORD owner_thread,
|
|
DWORD owner_pid) {
|
|
LONG attempts;
|
|
int bind_result;
|
|
(void)hwnd;
|
|
if (InterlockedCompareExchange(&input_once, 1, 0) != 0) return 0;
|
|
gw_bridge_nohelper_status.owned_input = 1;
|
|
/* The UI hook can observe Enter before startup has published stage 1.
|
|
* Do not consume the one allowed bind attempt on that transient ordering. */
|
|
if (gw_bridge_nohelper_status.stage != 1) {
|
|
gw_bridge_nohelper_status.error = 2;
|
|
InterlockedExchange(&input_once, 0);
|
|
return 0;
|
|
}
|
|
if (owner_thread != poll_coordinator.region.primary_thread ||
|
|
owner_pid != GetCurrentProcessId()) {
|
|
gw_bridge_nohelper_status.error = 5;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return 0;
|
|
}
|
|
attempts = InterlockedIncrement(&input_attempts);
|
|
if (attempts > GW_OWNED_INPUT_RETRY_LIMIT) {
|
|
gw_bridge_nohelper_status.error = 2;
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return 0;
|
|
}
|
|
bind_result = gw_poll_coordinator_on_owned_input(&poll_coordinator, &poll_snapshot);
|
|
if (bind_result != GW_POLL_BOUND) {
|
|
gw_bridge_nohelper_status.error = 2;
|
|
if (attempts >= GW_OWNED_INPUT_RETRY_LIMIT) {
|
|
gw_bridge_nohelper_status.stage = 3;
|
|
return 0;
|
|
}
|
|
/* Keep stage 1 so the next owned input can retry boundedly. */
|
|
InterlockedExchange(&input_once, 0);
|
|
return 0;
|
|
}
|
|
gw_bridge_nohelper_status.poll_bound = 1;
|
|
gw_bridge_nohelper_status.owner = poll_snapshot.owner;
|
|
return 1;
|
|
}
|
|
|
|
uint32_t gw_bridge_nohelper_error(void) {
|
|
return (uint32_t)InterlockedCompareExchange(&gw_bridge_nohelper_status.error, 0, 0);
|
|
}
|
|
|
|
uint32_t gw_bridge_nohelper_stage(void) {
|
|
return (uint32_t)InterlockedCompareExchange(&gw_bridge_nohelper_status.stage, 0, 0);
|
|
}
|