From 31276fb4841dcc847d50360471b577806f6a082d Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Thu, 11 Sep 2025 21:43:23 +0930 Subject: [PATCH 1/2] restructure project files --- .gitignore => wine-client/.gitignore | 0 Cargo.lock => wine-client/Cargo.lock | 0 Cargo.toml => wine-client/Cargo.toml | 0 {src => wine-client/src}/environment.rs | 0 {src => wine-client/src}/environment/wine.rs | 0 {src => wine-client/src}/environment/wine/errors.rs | 0 {src => wine-client/src}/environment/wine/request.rs | 0 {src => wine-client/src}/environment/wine/request/create_event.rs | 0 .../src}/environment/wine/request/create_named_pipe.rs | 0 .../src}/environment/wine/request/get_async_result.rs | 0 {src => wine-client/src}/environment/wine/request/header.rs | 0 .../src}/environment/wine/request/init_first_thread.rs | 0 .../src}/environment/wine/request/init_process_done.rs | 0 {src => wine-client/src}/environment/wine/request/ioctl.rs | 0 {src => wine-client/src}/environment/wine/request/read.rs | 0 {src => wine-client/src}/environment/wine/request/select.rs | 0 {src => wine-client/src}/environment/wine/request/utils.rs | 0 .../src}/environment/wine/request/utils/apc_result.rs | 0 .../src}/environment/wine/request/utils/async_data.rs | 0 .../src}/environment/wine/request/utils/object_attributes.rs | 0 {src => wine-client/src}/environment/wine/request/write.rs | 0 {src => wine-client/src}/environment/wine/utils.rs | 0 {src => wine-client/src}/environment/wine/versions.rs | 0 {src => wine-client/src}/environment/wine/wine_client.rs | 0 {src => wine-client/src}/handler.rs | 0 {src => wine-client/src}/handler/emulator.rs | 0 {src => wine-client/src}/handler/forwarder.rs | 0 {src => wine-client/src}/main.rs | 0 {src => wine-client/src}/protocols.rs | 0 {src => wine-client/src}/protocols/discord.rs | 0 {src => wine-client/src}/protocols/discord/enums.rs | 0 {src => wine-client/src}/protocols/discord/structs.rs | 0 {src => wine-client/src}/protocols/discord/utils.rs | 0 {src => wine-client/src}/protocols/packet.rs | 0 {src => wine-client/src}/utils/binary_reader.rs | 0 {src => wine-client/src}/utils/binary_writer.rs | 0 {src => wine-client/src}/utils/mod.rs | 0 {src => wine-client/src}/wine_client.rs | 0 38 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => wine-client/.gitignore (100%) rename Cargo.lock => wine-client/Cargo.lock (100%) rename Cargo.toml => wine-client/Cargo.toml (100%) rename {src => wine-client/src}/environment.rs (100%) rename {src => wine-client/src}/environment/wine.rs (100%) rename {src => wine-client/src}/environment/wine/errors.rs (100%) rename {src => wine-client/src}/environment/wine/request.rs (100%) rename {src => wine-client/src}/environment/wine/request/create_event.rs (100%) rename {src => wine-client/src}/environment/wine/request/create_named_pipe.rs (100%) rename {src => wine-client/src}/environment/wine/request/get_async_result.rs (100%) rename {src => wine-client/src}/environment/wine/request/header.rs (100%) rename {src => wine-client/src}/environment/wine/request/init_first_thread.rs (100%) rename {src => wine-client/src}/environment/wine/request/init_process_done.rs (100%) rename {src => wine-client/src}/environment/wine/request/ioctl.rs (100%) rename {src => wine-client/src}/environment/wine/request/read.rs (100%) rename {src => wine-client/src}/environment/wine/request/select.rs (100%) rename {src => wine-client/src}/environment/wine/request/utils.rs (100%) rename {src => wine-client/src}/environment/wine/request/utils/apc_result.rs (100%) rename {src => wine-client/src}/environment/wine/request/utils/async_data.rs (100%) rename {src => wine-client/src}/environment/wine/request/utils/object_attributes.rs (100%) rename {src => wine-client/src}/environment/wine/request/write.rs (100%) rename {src => wine-client/src}/environment/wine/utils.rs (100%) rename {src => wine-client/src}/environment/wine/versions.rs (100%) rename {src => wine-client/src}/environment/wine/wine_client.rs (100%) rename {src => wine-client/src}/handler.rs (100%) rename {src => wine-client/src}/handler/emulator.rs (100%) rename {src => wine-client/src}/handler/forwarder.rs (100%) rename {src => wine-client/src}/main.rs (100%) rename {src => wine-client/src}/protocols.rs (100%) rename {src => wine-client/src}/protocols/discord.rs (100%) rename {src => wine-client/src}/protocols/discord/enums.rs (100%) rename {src => wine-client/src}/protocols/discord/structs.rs (100%) rename {src => wine-client/src}/protocols/discord/utils.rs (100%) rename {src => wine-client/src}/protocols/packet.rs (100%) rename {src => wine-client/src}/utils/binary_reader.rs (100%) rename {src => wine-client/src}/utils/binary_writer.rs (100%) rename {src => wine-client/src}/utils/mod.rs (100%) rename {src => wine-client/src}/wine_client.rs (100%) diff --git a/.gitignore b/wine-client/.gitignore similarity index 100% rename from .gitignore rename to wine-client/.gitignore diff --git a/Cargo.lock b/wine-client/Cargo.lock similarity index 100% rename from Cargo.lock rename to wine-client/Cargo.lock diff --git a/Cargo.toml b/wine-client/Cargo.toml similarity index 100% rename from Cargo.toml rename to wine-client/Cargo.toml diff --git a/src/environment.rs b/wine-client/src/environment.rs similarity index 100% rename from src/environment.rs rename to wine-client/src/environment.rs diff --git a/src/environment/wine.rs b/wine-client/src/environment/wine.rs similarity index 100% rename from src/environment/wine.rs rename to wine-client/src/environment/wine.rs diff --git a/src/environment/wine/errors.rs b/wine-client/src/environment/wine/errors.rs similarity index 100% rename from src/environment/wine/errors.rs rename to wine-client/src/environment/wine/errors.rs diff --git a/src/environment/wine/request.rs b/wine-client/src/environment/wine/request.rs similarity index 100% rename from src/environment/wine/request.rs rename to wine-client/src/environment/wine/request.rs diff --git a/src/environment/wine/request/create_event.rs b/wine-client/src/environment/wine/request/create_event.rs similarity index 100% rename from src/environment/wine/request/create_event.rs rename to wine-client/src/environment/wine/request/create_event.rs diff --git a/src/environment/wine/request/create_named_pipe.rs b/wine-client/src/environment/wine/request/create_named_pipe.rs similarity index 100% rename from src/environment/wine/request/create_named_pipe.rs rename to wine-client/src/environment/wine/request/create_named_pipe.rs diff --git a/src/environment/wine/request/get_async_result.rs b/wine-client/src/environment/wine/request/get_async_result.rs similarity index 100% rename from src/environment/wine/request/get_async_result.rs rename to wine-client/src/environment/wine/request/get_async_result.rs diff --git a/src/environment/wine/request/header.rs b/wine-client/src/environment/wine/request/header.rs similarity index 100% rename from src/environment/wine/request/header.rs rename to wine-client/src/environment/wine/request/header.rs diff --git a/src/environment/wine/request/init_first_thread.rs b/wine-client/src/environment/wine/request/init_first_thread.rs similarity index 100% rename from src/environment/wine/request/init_first_thread.rs rename to wine-client/src/environment/wine/request/init_first_thread.rs diff --git a/src/environment/wine/request/init_process_done.rs b/wine-client/src/environment/wine/request/init_process_done.rs similarity index 100% rename from src/environment/wine/request/init_process_done.rs rename to wine-client/src/environment/wine/request/init_process_done.rs diff --git a/src/environment/wine/request/ioctl.rs b/wine-client/src/environment/wine/request/ioctl.rs similarity index 100% rename from src/environment/wine/request/ioctl.rs rename to wine-client/src/environment/wine/request/ioctl.rs diff --git a/src/environment/wine/request/read.rs b/wine-client/src/environment/wine/request/read.rs similarity index 100% rename from src/environment/wine/request/read.rs rename to wine-client/src/environment/wine/request/read.rs diff --git a/src/environment/wine/request/select.rs b/wine-client/src/environment/wine/request/select.rs similarity index 100% rename from src/environment/wine/request/select.rs rename to wine-client/src/environment/wine/request/select.rs diff --git a/src/environment/wine/request/utils.rs b/wine-client/src/environment/wine/request/utils.rs similarity index 100% rename from src/environment/wine/request/utils.rs rename to wine-client/src/environment/wine/request/utils.rs diff --git a/src/environment/wine/request/utils/apc_result.rs b/wine-client/src/environment/wine/request/utils/apc_result.rs similarity index 100% rename from src/environment/wine/request/utils/apc_result.rs rename to wine-client/src/environment/wine/request/utils/apc_result.rs diff --git a/src/environment/wine/request/utils/async_data.rs b/wine-client/src/environment/wine/request/utils/async_data.rs similarity index 100% rename from src/environment/wine/request/utils/async_data.rs rename to wine-client/src/environment/wine/request/utils/async_data.rs diff --git a/src/environment/wine/request/utils/object_attributes.rs b/wine-client/src/environment/wine/request/utils/object_attributes.rs similarity index 100% rename from src/environment/wine/request/utils/object_attributes.rs rename to wine-client/src/environment/wine/request/utils/object_attributes.rs diff --git a/src/environment/wine/request/write.rs b/wine-client/src/environment/wine/request/write.rs similarity index 100% rename from src/environment/wine/request/write.rs rename to wine-client/src/environment/wine/request/write.rs diff --git a/src/environment/wine/utils.rs b/wine-client/src/environment/wine/utils.rs similarity index 100% rename from src/environment/wine/utils.rs rename to wine-client/src/environment/wine/utils.rs diff --git a/src/environment/wine/versions.rs b/wine-client/src/environment/wine/versions.rs similarity index 100% rename from src/environment/wine/versions.rs rename to wine-client/src/environment/wine/versions.rs diff --git a/src/environment/wine/wine_client.rs b/wine-client/src/environment/wine/wine_client.rs similarity index 100% rename from src/environment/wine/wine_client.rs rename to wine-client/src/environment/wine/wine_client.rs diff --git a/src/handler.rs b/wine-client/src/handler.rs similarity index 100% rename from src/handler.rs rename to wine-client/src/handler.rs diff --git a/src/handler/emulator.rs b/wine-client/src/handler/emulator.rs similarity index 100% rename from src/handler/emulator.rs rename to wine-client/src/handler/emulator.rs diff --git a/src/handler/forwarder.rs b/wine-client/src/handler/forwarder.rs similarity index 100% rename from src/handler/forwarder.rs rename to wine-client/src/handler/forwarder.rs diff --git a/src/main.rs b/wine-client/src/main.rs similarity index 100% rename from src/main.rs rename to wine-client/src/main.rs diff --git a/src/protocols.rs b/wine-client/src/protocols.rs similarity index 100% rename from src/protocols.rs rename to wine-client/src/protocols.rs diff --git a/src/protocols/discord.rs b/wine-client/src/protocols/discord.rs similarity index 100% rename from src/protocols/discord.rs rename to wine-client/src/protocols/discord.rs diff --git a/src/protocols/discord/enums.rs b/wine-client/src/protocols/discord/enums.rs similarity index 100% rename from src/protocols/discord/enums.rs rename to wine-client/src/protocols/discord/enums.rs diff --git a/src/protocols/discord/structs.rs b/wine-client/src/protocols/discord/structs.rs similarity index 100% rename from src/protocols/discord/structs.rs rename to wine-client/src/protocols/discord/structs.rs diff --git a/src/protocols/discord/utils.rs b/wine-client/src/protocols/discord/utils.rs similarity index 100% rename from src/protocols/discord/utils.rs rename to wine-client/src/protocols/discord/utils.rs diff --git a/src/protocols/packet.rs b/wine-client/src/protocols/packet.rs similarity index 100% rename from src/protocols/packet.rs rename to wine-client/src/protocols/packet.rs diff --git a/src/utils/binary_reader.rs b/wine-client/src/utils/binary_reader.rs similarity index 100% rename from src/utils/binary_reader.rs rename to wine-client/src/utils/binary_reader.rs diff --git a/src/utils/binary_writer.rs b/wine-client/src/utils/binary_writer.rs similarity index 100% rename from src/utils/binary_writer.rs rename to wine-client/src/utils/binary_writer.rs diff --git a/src/utils/mod.rs b/wine-client/src/utils/mod.rs similarity index 100% rename from src/utils/mod.rs rename to wine-client/src/utils/mod.rs diff --git a/src/wine_client.rs b/wine-client/src/wine_client.rs similarity index 100% rename from src/wine_client.rs rename to wine-client/src/wine_client.rs From d47f88ffa5c4ad6d10ef8e79966063d3c5ab525e Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Thu, 11 Sep 2025 23:20:05 +0930 Subject: [PATCH 2/2] refactor wine client to seperate package --- rich-status/.gitignore | 2 + rich-status/Cargo.lock | 871 ++++++++++++++++++ rich-status/Cargo.toml | 13 + {wine-client => rich-status}/src/handler.rs | 2 - rich-status/src/main.rs | 71 ++ {wine-client => rich-status}/src/protocols.rs | 0 .../src/protocols/discord.rs | 1 + .../src/protocols/discord/enums.rs | 0 rich-status/src/protocols/discord/handler.rs | 1 + .../protocols/discord}/handler/emulator.rs | 0 .../protocols/discord}/handler/forwarder.rs | 0 .../src/protocols/discord/structs.rs | 0 .../src/protocols/discord/utils.rs | 21 +- .../src/protocols/packet.rs | 0 wine-client/Cargo.lock | 247 +---- wine-client/Cargo.toml | 5 +- wine-client/src/api.rs | 1 + wine-client/src/api/wine_api.rs | 284 ++++++ wine-client/src/environment.rs | 5 - wine-client/src/environment/wine.rs | 542 ----------- wine-client/src/lib.rs | 3 + wine-client/src/main.rs | 42 - wine-client/src/wine.rs | 6 + .../src/{environment => }/wine/errors.rs | 4 + .../src/{environment => }/wine/request.rs | 2 +- .../wine/request/create_event.rs | 6 +- .../wine/request/create_named_pipe.rs | 6 +- .../wine/request/get_async_result.rs | 6 +- .../{environment => }/wine/request/header.rs | 7 +- .../wine/request/init_first_thread.rs | 6 +- .../wine/request/init_process_done.rs | 6 +- .../{environment => }/wine/request/ioctl.rs | 6 +- .../{environment => }/wine/request/read.rs | 8 +- .../{environment => }/wine/request/select.rs | 8 +- .../{environment => }/wine/request/utils.rs | 0 .../wine/request/utils/apc_result.rs | 6 +- .../wine/request/utils/async_data.rs | 6 +- .../wine/request/utils/object_attributes.rs | 6 +- .../{environment => }/wine/request/write.rs | 6 +- .../src/{environment => }/wine/utils.rs | 2 +- .../src/{environment => }/wine/versions.rs | 0 .../src/{environment => }/wine/wine_client.rs | 61 +- wine-client/src/wine_client.rs | 9 - 43 files changed, 1352 insertions(+), 926 deletions(-) create mode 100644 rich-status/.gitignore create mode 100644 rich-status/Cargo.lock create mode 100644 rich-status/Cargo.toml rename {wine-client => rich-status}/src/handler.rs (89%) create mode 100644 rich-status/src/main.rs rename {wine-client => rich-status}/src/protocols.rs (100%) rename {wine-client => rich-status}/src/protocols/discord.rs (73%) rename {wine-client => rich-status}/src/protocols/discord/enums.rs (100%) create mode 100644 rich-status/src/protocols/discord/handler.rs rename {wine-client/src => rich-status/src/protocols/discord}/handler/emulator.rs (100%) rename {wine-client/src => rich-status/src/protocols/discord}/handler/forwarder.rs (100%) rename {wine-client => rich-status}/src/protocols/discord/structs.rs (100%) rename {wine-client => rich-status}/src/protocols/discord/utils.rs (64%) rename {wine-client => rich-status}/src/protocols/packet.rs (100%) create mode 100644 wine-client/src/api.rs create mode 100644 wine-client/src/api/wine_api.rs delete mode 100644 wine-client/src/environment.rs delete mode 100644 wine-client/src/environment/wine.rs create mode 100644 wine-client/src/lib.rs delete mode 100644 wine-client/src/main.rs create mode 100644 wine-client/src/wine.rs rename wine-client/src/{environment => }/wine/errors.rs (86%) rename wine-client/src/{environment => }/wine/request.rs (90%) rename wine-client/src/{environment => }/wine/request/create_event.rs (92%) rename wine-client/src/{environment => }/wine/request/create_named_pipe.rs (94%) rename wine-client/src/{environment => }/wine/request/get_async_result.rs (92%) rename wine-client/src/{environment => }/wine/request/header.rs (93%) rename wine-client/src/{environment => }/wine/request/init_first_thread.rs (93%) rename wine-client/src/{environment => }/wine/request/init_process_done.rs (89%) rename wine-client/src/{environment => }/wine/request/ioctl.rs (93%) rename wine-client/src/{environment => }/wine/request/read.rs (93%) rename wine-client/src/{environment => }/wine/request/select.rs (98%) rename wine-client/src/{environment => }/wine/request/utils.rs (100%) rename wine-client/src/{environment => }/wine/request/utils/apc_result.rs (96%) rename wine-client/src/{environment => }/wine/request/utils/async_data.rs (83%) rename wine-client/src/{environment => }/wine/request/utils/object_attributes.rs (97%) rename wine-client/src/{environment => }/wine/request/write.rs (93%) rename wine-client/src/{environment => }/wine/utils.rs (97%) rename wine-client/src/{environment => }/wine/versions.rs (100%) rename wine-client/src/{environment => }/wine/wine_client.rs (83%) delete mode 100644 wine-client/src/wine_client.rs diff --git a/rich-status/.gitignore b/rich-status/.gitignore new file mode 100644 index 0000000..7c08ed8 --- /dev/null +++ b/rich-status/.gitignore @@ -0,0 +1,2 @@ +/target +out.txt diff --git a/rich-status/Cargo.lock b/rich-status/Cargo.lock new file mode 100644 index 0000000..05c1e85 --- /dev/null +++ b/rich-status/Cargo.lock @@ -0,0 +1,871 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "backtrace" +version = "0.3.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "binary-util" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2f599f0117a1e347fd2f91547c2e052fc7978072e9cbadc250a77f39c1dc3f" +dependencies = [ + "binary-util-derive", + "bytes", +] + +[[package]] +name = "binary-util-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7209fcca2dab9eada1b57712e60eb86e869fc9f8bd5fd7b08ba2a9ce59959ceb" +dependencies = [ + "lazy_static", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "cfg-if" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" + +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + +[[package]] +name = "deranged" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hexdump" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf31ab66ed8145a1c7427bd8e9b42a6131bd74ccf444f69b9e620c2e73ded832" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "inotify" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" +dependencies = [ + "bitflags 2.9.4", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "io-uring" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" +dependencies = [ + "bitflags 2.9.4", + "cfg-if", + "libc", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "kqueue" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac30106d7dce88daf4a3fcb4879ea939476d5074a9b7ddd0fb97fa4bed5596a" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.175" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" + +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.59.0", +] + +[[package]] +name = "notify" +version = "8.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" +dependencies = [ + "bitflags 2.9.4", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "notify-types", + "walkdir", + "windows-sys 0.60.2", +] + +[[package]] +name = "notify-types" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" +dependencies = [ + "bitflags 2.9.4", +] + +[[package]] +name = "regex" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + +[[package]] +name = "rich_status" +version = "0.1.0" +dependencies = [ + "binary-util", + "log", + "serde", + "serde_json", + "simple_logger", + "tokio", + "wine_client", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "safe-transmute" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3944826ff8fa8093089aba3acb4ef44b9446a99a16f3bf4e74af3f77d340ab7d" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.143" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +dependencies = [ + "libc", +] + +[[package]] +name = "simple_logger" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb" +dependencies = [ + "colored", + "log", + "time", + "windows-sys 0.48.0", +] + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" +dependencies = [ + "deranged", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tokio" +version = "1.47.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" +dependencies = [ + "backtrace", + "bytes", + "io-uring", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "slab", + "socket2", + "tokio-macros", + "windows-sys 0.59.0", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.60.2", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "wine_client" +version = "0.1.0" +dependencies = [ + "base64", + "binary-util", + "hexdump", + "libc", + "log", + "notify", + "safe-transmute", + "signal-hook", + "simple_logger", +] diff --git a/rich-status/Cargo.toml b/rich-status/Cargo.toml new file mode 100644 index 0000000..cae41bb --- /dev/null +++ b/rich-status/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rich_status" +version = "0.1.0" +edition = "2024" + +[dependencies] +tokio = { version = "1", features = ["full"] } +wine_client = { path = "../wine-client" } +log = "0.4.28" +simple_logger = "5.0.0" +binary-util = "0.3.4" +serde_json = "1.0.143" +serde = { version = "1.0.219", features = ["derive"] } diff --git a/wine-client/src/handler.rs b/rich-status/src/handler.rs similarity index 89% rename from wine-client/src/handler.rs rename to rich-status/src/handler.rs index e137a3d..eb965ed 100644 --- a/wine-client/src/handler.rs +++ b/rich-status/src/handler.rs @@ -1,7 +1,5 @@ use crate::protocols::packet::ProtocolPacket; -pub mod emulator; - pub trait MessageHandler { fn handle_packet(&mut self, data: ProtocolPacket) -> Option; } diff --git a/rich-status/src/main.rs b/rich-status/src/main.rs new file mode 100644 index 0000000..d623d78 --- /dev/null +++ b/rich-status/src/main.rs @@ -0,0 +1,71 @@ +use log::{LevelFilter, error, info}; +use simple_logger::SimpleLogger; + +use crate::{ + handler::MessageHandler, + protocols::{discord, packet::ProtocolPacket}, +}; + +mod handler; +mod protocols; + +#[tokio::main] +async fn main() { + SimpleLogger::new() + .with_level(LevelFilter::Off) + .with_module_level("rich_status", LevelFilter::Info) + .with_module_level("wine_client", LevelFilter::Trace) + .init() + .unwrap(); + + info!("Connecting to wineserver"); + + let mut api = wine_client::api::wine_api::connect( + "/tmp/.wine-1000/server-fc01-d29a92/socket".to_string(), + ) + .unwrap(); + + info!("Connected!"); + + info!("Creating pipe"); + let pipe = api + .create_named_pipe("\\??\\pipe\\discord-ipc-0".to_string()) + .unwrap(); + + info!("Created pipe, waiting for connection"); + api.accept_connection(&pipe); + info!("Received connection, reading data"); + + let mut handler: Box = Box::new(discord::handler::emulator::Emulator {}); + + let mut buffer = Vec::::new(); + loop { + let mut result = api.read(&pipe, 80); + + info!("Read data: {:?}", result); + + buffer.append(&mut result); + + let packet = protocols::discord::utils::try_read_packet(&mut buffer); + match packet { + Ok((packet, remaining_data)) => { + buffer = remaining_data; + + let response = handler.handle_packet(ProtocolPacket::Discord(packet)); + + match response { + Some(response) => match response { + ProtocolPacket::Discord(ipc_packet) => { + let data = discord::utils::write_packet(ipc_packet).unwrap(); + api.write(&pipe, data); + } + }, + None => {} + } + } + Err(_) => { + error!("Failed to parse packet!"); + } + } + } +} diff --git a/wine-client/src/protocols.rs b/rich-status/src/protocols.rs similarity index 100% rename from wine-client/src/protocols.rs rename to rich-status/src/protocols.rs diff --git a/wine-client/src/protocols/discord.rs b/rich-status/src/protocols/discord.rs similarity index 73% rename from wine-client/src/protocols/discord.rs rename to rich-status/src/protocols/discord.rs index 8a04079..c44e81b 100644 --- a/wine-client/src/protocols/discord.rs +++ b/rich-status/src/protocols/discord.rs @@ -1,3 +1,4 @@ pub mod enums; +pub mod handler; pub mod structs; pub mod utils; diff --git a/wine-client/src/protocols/discord/enums.rs b/rich-status/src/protocols/discord/enums.rs similarity index 100% rename from wine-client/src/protocols/discord/enums.rs rename to rich-status/src/protocols/discord/enums.rs diff --git a/rich-status/src/protocols/discord/handler.rs b/rich-status/src/protocols/discord/handler.rs new file mode 100644 index 0000000..6e7f9b4 --- /dev/null +++ b/rich-status/src/protocols/discord/handler.rs @@ -0,0 +1 @@ +pub mod emulator; diff --git a/wine-client/src/handler/emulator.rs b/rich-status/src/protocols/discord/handler/emulator.rs similarity index 100% rename from wine-client/src/handler/emulator.rs rename to rich-status/src/protocols/discord/handler/emulator.rs diff --git a/wine-client/src/handler/forwarder.rs b/rich-status/src/protocols/discord/handler/forwarder.rs similarity index 100% rename from wine-client/src/handler/forwarder.rs rename to rich-status/src/protocols/discord/handler/forwarder.rs diff --git a/wine-client/src/protocols/discord/structs.rs b/rich-status/src/protocols/discord/structs.rs similarity index 100% rename from wine-client/src/protocols/discord/structs.rs rename to rich-status/src/protocols/discord/structs.rs diff --git a/wine-client/src/protocols/discord/utils.rs b/rich-status/src/protocols/discord/utils.rs similarity index 64% rename from wine-client/src/protocols/discord/utils.rs rename to rich-status/src/protocols/discord/utils.rs index b7b4b18..d1ebd03 100644 --- a/wine-client/src/protocols/discord/utils.rs +++ b/rich-status/src/protocols/discord/utils.rs @@ -1,14 +1,13 @@ use std::io::{self, Error}; -use crate::{ - protocols::discord::{enums::Opcode, structs::IpcPacket}, - utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, -}; +use binary_util::{ByteReader, ByteWriter}; + +use crate::protocols::discord::{enums::Opcode, structs::IpcPacket}; pub fn try_read_packet(buffer: &[u8]) -> Result<(IpcPacket, Vec), io::Error> { - let mut reader = BinaryReader::from(buffer); + let mut reader = ByteReader::from(buffer); - let opcode = reader.u32()?; + let opcode = reader.read_u32_le()?; let opcode = match Opcode::try_from(opcode) { Ok(opcode) => opcode, Err(_) => { @@ -19,7 +18,7 @@ pub fn try_read_packet(buffer: &[u8]) -> Result<(IpcPacket, Vec), io::Error> } }; - let length: usize = reader.u32()?.try_into().unwrap(); + let length: usize = reader.read_u32_le()?.try_into().unwrap(); let mut buffer: Vec = vec![0; length]; reader.read(&mut buffer)?; @@ -42,10 +41,10 @@ pub fn try_read_packet(buffer: &[u8]) -> Result<(IpcPacket, Vec), io::Error> } pub fn write_packet(packet: IpcPacket) -> Result, io::Error> { - let mut writer = BinaryWriter::new(); - writer.u32(packet.opcode as u32)?; - writer.u32(packet.data.len().try_into().unwrap())?; + let mut writer = ByteWriter::new(); + writer.write_u32_le(packet.opcode as u32)?; + writer.write_u32_le(packet.data.len().try_into().unwrap())?; writer.write(&packet.data)?; - return Ok(writer.as_vec()); + return Ok(writer.as_slice().to_vec()); } diff --git a/wine-client/src/protocols/packet.rs b/rich-status/src/protocols/packet.rs similarity index 100% rename from wine-client/src/protocols/packet.rs rename to rich-status/src/protocols/packet.rs diff --git a/wine-client/Cargo.lock b/wine-client/Cargo.lock index 57bedd2..bd6aaea 100644 --- a/wine-client/Cargo.lock +++ b/wine-client/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "addr2line" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" - [[package]] name = "aho-corasick" version = "1.1.3" @@ -32,27 +17,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "backtrace" -version = "0.3.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", - "windows-targets 0.52.6", -] - [[package]] name = "base64" version = "0.22.1" @@ -100,12 +64,6 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" -[[package]] -name = "cfg-if" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" - [[package]] name = "colored" version = "2.2.0" @@ -134,12 +92,6 @@ dependencies = [ "libc", ] -[[package]] -name = "gimli" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" - [[package]] name = "hexdump" version = "0.1.2" @@ -169,23 +121,6 @@ dependencies = [ "libc", ] -[[package]] -name = "io-uring" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" -dependencies = [ - "bitflags 2.9.3", - "cfg-if", - "libc", -] - -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - [[package]] name = "kqueue" version = "1.1.1" @@ -218,16 +153,6 @@ version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" -[[package]] -name = "lock_api" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.28" @@ -240,15 +165,6 @@ version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" -[[package]] -name = "miniz_oxide" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" -dependencies = [ - "adler2", -] - [[package]] name = "mio" version = "1.0.4" @@ -300,44 +216,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.36.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.6", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - [[package]] name = "powerfmt" version = "0.2.0" @@ -362,15 +240,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" -dependencies = [ - "bitflags 2.9.3", -] - [[package]] name = "regex" version = "1.11.2" @@ -400,36 +269,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" -[[package]] -name = "rich-status" -version = "0.1.0" -dependencies = [ - "base64", - "binary-util", - "hexdump", - "libc", - "log", - "notify", - "safe-transmute", - "serde", - "serde_json", - "signal-hook", - "simple_logger", - "tokio", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" - -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "safe-transmute" version = "0.11.3" @@ -445,12 +284,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.219" @@ -471,18 +304,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.143" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "signal-hook" version = "0.3.18" @@ -514,28 +335,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "slab" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" - -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - -[[package]] -name = "socket2" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" -dependencies = [ - "libc", - "windows-sys 0.59.0", -] - [[package]] name = "syn" version = "2.0.106" @@ -579,37 +378,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tokio" -version = "1.47.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" -dependencies = [ - "backtrace", - "bytes", - "io-uring", - "libc", - "mio", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "slab", - "socket2", - "tokio-macros", - "windows-sys 0.59.0", -] - -[[package]] -name = "tokio-macros" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "unicode-ident" version = "1.0.18" @@ -859,3 +627,18 @@ name = "windows_x86_64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "wine_client" +version = "0.1.0" +dependencies = [ + "base64", + "binary-util", + "hexdump", + "libc", + "log", + "notify", + "safe-transmute", + "signal-hook", + "simple_logger", +] diff --git a/wine-client/Cargo.toml b/wine-client/Cargo.toml index 83f273f..a9ffb4d 100644 --- a/wine-client/Cargo.toml +++ b/wine-client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rich-status" +name = "wine_client" version = "0.1.0" edition = "2024" @@ -12,7 +12,4 @@ log = "0.4.28" notify = "8.2.0" safe-transmute = "0.11.3" simple_logger = "5.0.0" -tokio = { version = "1.47.1", features = ["io-util", "net", "full"] } -serde_json = "1.0.143" -serde = { version = "1.0.219", features = ["derive"] } signal-hook = "0.3.18" diff --git a/wine-client/src/api.rs b/wine-client/src/api.rs new file mode 100644 index 0000000..7e13a71 --- /dev/null +++ b/wine-client/src/api.rs @@ -0,0 +1 @@ +pub mod wine_api; diff --git a/wine-client/src/api/wine_api.rs b/wine-client/src/api/wine_api.rs new file mode 100644 index 0000000..1d40f57 --- /dev/null +++ b/wine-client/src/api/wine_api.rs @@ -0,0 +1,284 @@ +use std::{io::Error, time::Duration}; + +use log::{debug, info, trace}; + +use crate::wine::{ + errors::{self, KnownWineError}, + request::{ + create_event::{CreateEventReply, CreateEventRequest}, + create_named_pipe::{CreateNamedPipeReply, CreateNamedPipeRequest}, + get_async_result::{GetAsyncResultReply, GetAsyncResultRequest}, + init_process_done::{InitProcessDoneReply, InitProcessDoneRequest}, + ioctl::{IoctlCode, IoctlReply, IoctlRequest}, + read::{ReadReply, ReadRequest}, + select::{SelectOp, SelectReply, SelectRequest}, + utils::{ + apc_result::{ApcResult, ApcResultData, ApcType}, + async_data::AsyncData, + object_attributes::WineObjectAttributes, + }, + write::{WriteReply, WriteRequest}, + }, + utils::{NtFileDisposition, TIMEOUT_INFINITE, obj_handle_t}, + wine_client::WineClient, +}; + +pub struct WineApi { + client: WineClient, +} + +pub struct NamedPipe { + handle: obj_handle_t, +} + +pub fn connect(socket_path: String) -> Result { + let mut client = WineClient::connect(socket_path)?; + + let reply = client + .send_request::(InitProcessDoneRequest { + teb: 0, + peb: 0, + ldt_copy: 0, + }) + .unwrap(); + + return Ok(WineApi { client: client }); +} + +impl WineApi { + pub fn create_named_pipe(&mut self, pipe_path: String) -> Result { + const GENERIC_READ: u32 = 0x80000000; + const GENERIC_WRITE: u32 = 0x40000000; + const SYNCRONIZE: u32 = 0x00100000; + const FILE_SHARE_READ: u32 = 0x00000001; + const FILE_SHARE_WRITE: u32 = 0x00000002; + const NAMED_PIPE_MESSAGE_STREAM_WRITE: u32 = 0x0001; + const NAMED_PIPE_MESSAGE_STREAM_READ: u32 = 0x0002; + const NAMED_PIPE_NONBLOCKING_MODE: u32 = 0x0004; + const FILE_DIRECTORY_FILE: u32 = 0x00000001; + const FILE_WRITE_THROUGH: u32 = 0x00000002; + const FILE_SYNCHRONOUS_IO_NONALERT: u32 = 0x00000020; + + let reply = self + .client + .send_request::(CreateNamedPipeRequest { + access: 0xc0100000, // GENERIC_READ | GENERIC_WRITE | SYNCRONIZE, + options: 0x00000020c, + sharing: 3, + disposition: NtFileDisposition::FILE_OPEN_IF, + max_instances: 0xffffffff, + out_size: 0x00004000, + in_size: 0x00004000, + timeout: 0, + flags: 0, + object: WineObjectAttributes { + rootdir: 0, + attributes: 64, + sd_len: 0, + name: Some(pipe_path), + }, + }); + + debug!("Created Named Pipe: {:?}", reply); + + match reply { + Ok(reply) => { + return Ok(NamedPipe { + handle: reply.handle, + }); + } + Err(_) => { + return Err(Error::new( + std::io::ErrorKind::BrokenPipe, + "Failed to open pipe", + )); + } + } + } + + pub fn accept_connection(&mut self, pipe: &NamedPipe) { + let accept_event = self + .client + .send_request::(CreateEventRequest { + access: 0x001f0003, + manual_reset: 1, + initial_state: 1, + object: WineObjectAttributes { + rootdir: 0, + attributes: 0x00000080, + sd_len: 0, + name: None, + }, + }) + .unwrap(); + + let ioctl_reply = self + .client + .send_request::(IoctlRequest { + code: IoctlCode::FSCTL_PIPE_LISTEN, + async_data: AsyncData { + handle: pipe.handle, + event: accept_event.handle, + iosb: 0xc000372b60, + user: 0x55555e1059c0, + apc: 0, + apc_context: 0xc000372b60, + }, + }) + .unwrap(); + + info!("Received: {:?}", ioctl_reply); + + self.wait_for_event(accept_event, 0x1203712983); + } + + pub fn read(&mut self, pipe: &NamedPipe, amount: u32) -> Vec { + let mut user_arg = 0x55555e1059c0; + + let read_event = self + .client + .send_request::(CreateEventRequest { + access: 0x001f0003, + manual_reset: 1, + initial_state: 1, + object: WineObjectAttributes { + rootdir: 0, + attributes: 0x00000080, + sd_len: 0, + name: None, + }, + }) + .unwrap(); + + let reply = self + .client + .send_request::(ReadRequest { + async_data: AsyncData { + handle: pipe.handle, + event: read_event.handle, + iosb: 0xc000372b80, + user: user_arg, + apc: 0, + apc_context: 0xc000372b80, + }, + pos: 0, + amount: 1000, + }); + + match reply { + Ok(reply) => reply.data, + Err(_) => { + self.wait_for_event(read_event, 0x838629); + + let reply = self + .client + .send_request::( + GetAsyncResultRequest { user: user_arg }, + ) + .unwrap(); + + reply.data + } + } + } + + pub fn write(&mut self, pipe: &NamedPipe, data: Vec) { + let event = self + .client + .send_request::(CreateEventRequest { + access: 0x001f0003, + manual_reset: 1, + initial_state: 1, + object: WineObjectAttributes { + rootdir: 0, + attributes: 0x00000080, + sd_len: 0, + name: None, + }, + }) + .unwrap(); + + let write_reply = self + .client + .send_request::(WriteRequest { + async_data: AsyncData { + handle: pipe.handle, + event: event.handle, + iosb: 0xc000163c80, + user: 0x55555e1059c0, + apc: 0, + apc_context: 0xc000163c80, + }, + pos: 0, + data: data.clone(), + }); + + if write_reply.unwrap().header.error.is_none() { + return; + } + + loop { + let select_reply = self + .client + .send_request::(SelectRequest { + flags: 2, + cookie: 0x13371337, + timeout: TIMEOUT_INFINITE, + prev_apc: 0, + result: ApcResult { + apc_type: ApcType::APC_NONE, + data: ApcResultData::APC_NONE, + }, + data: vec![SelectOp::Wait { + handles: vec![event.handle], + }], + }) + .unwrap(); + + match select_reply.header.error { + Some(error) => match error { + errors::WineError::Known(known_wine_error) => match known_wine_error { + KnownWineError::STATUS_KERNEL_APC => return, + _ => (), + }, + errors::WineError::Unknown(_) => (), + }, + None => todo!(), + } + } + } + + fn wait_for_event(&mut self, event: CreateEventReply, cookie: u64) { + loop { + let select_reply = self + .client + .send_request::(SelectRequest { + flags: 2, + cookie: cookie, + timeout: TIMEOUT_INFINITE, + prev_apc: 0, + result: ApcResult { + apc_type: ApcType::APC_NONE, + data: ApcResultData::APC_NONE, + }, + data: vec![SelectOp::Wait { + handles: vec![event.handle], + }], + }) + .unwrap(); + + match &select_reply.header.error { + Some(error) => match error { + errors::WineError::Known(known_wine_error) => match known_wine_error { + KnownWineError::STATUS_KERNEL_APC => return, + _ => (), + }, + errors::WineError::Unknown(_) => (), + }, + None => return, + } + + std::thread::sleep(Duration::from_millis(500)); + } + } +} diff --git a/wine-client/src/environment.rs b/wine-client/src/environment.rs deleted file mode 100644 index a4986c9..0000000 --- a/wine-client/src/environment.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod wine; - -pub trait Environment { - async fn start(&mut self); -} diff --git a/wine-client/src/environment/wine.rs b/wine-client/src/environment/wine.rs deleted file mode 100644 index 67e5c12..0000000 --- a/wine-client/src/environment/wine.rs +++ /dev/null @@ -1,542 +0,0 @@ -use std::{ - os::{self, unix::fs::DirBuilderExt}, - path::{self, Path}, - sync::{Arc, Mutex}, - time::Duration, -}; - -use binary_util::{error, types}; -use libc::getuid; -use log::{error, info}; -use notify::Watcher; -use tokio::{ - fs, - sync::{ - mpsc::channel, - oneshot::{self, Sender}, - }, -}; - -use crate::{ - environment::{ - Environment, - wine::{ - errors::KnownWineError, - request::{ - create_event::{CreateEventReply, CreateEventRequest}, - create_named_pipe::{CreateNamedPipeReply, CreateNamedPipeRequest}, - get_async_result::{GetAsyncResultReply, GetAsyncResultRequest}, - init_process_done::{InitProcessDoneReply, InitProcessDoneRequest}, - ioctl::{IoctlCode::FSCTL_PIPE_LISTEN, IoctlReply, IoctlRequest}, - read::{ReadReply, ReadRequest}, - select::{SelectOp, SelectReply, SelectRequest}, - utils::{ - apc_result::{ApcResult, ApcResultData, ApcType}, - async_data::AsyncData, - object_attributes::WineObjectAttributes, - }, - write::{WriteReply, WriteRequest}, - }, - utils::{NtFileDisposition, TIMEOUT_INFINITE}, - wine_client::WineClient, - }, - }, - handler::MessageHandler, - protocols::{ - discord::{self, structs::IpcPacket}, - packet::ProtocolPacket, - }, - utils::binary_reader::BinaryReader, -}; - -mod errors; -mod request; -mod utils; -mod versions; -mod wine_client; - -pub struct WineEnvironment { - pub event_handler: Box, -} - -#[derive(Debug)] -enum WineEnvironmentMessage { - HandleSocket(String), - ReceivedPacket(IpcPacket, Sender>), - Finished, -} - -async fn handle_socket(sender: tokio::sync::mpsc::Sender, path: String) { - info!("Handling new socket: {}", path); - let mut client = WineClient::connect(path).await; - - let mut client = match client { - Ok(client) => client, - Err(_) => return, - }; - - info!("Socket connected!"); - let reply = client - .send_request::(InitProcessDoneRequest { - teb: 0, - peb: 0, - ldt_copy: 0, - }) - .await; - - info!("Received: {:?}", reply); - - const GENERIC_READ: u32 = 0x80000000; - const GENERIC_WRITE: u32 = 0x40000000; - const SYNCRONIZE: u32 = 0x00100000; - const FILE_SHARE_READ: u32 = 0x00000001; - const FILE_SHARE_WRITE: u32 = 0x00000002; - const NAMED_PIPE_MESSAGE_STREAM_WRITE: u32 = 0x0001; - const NAMED_PIPE_MESSAGE_STREAM_READ: u32 = 0x0002; - const NAMED_PIPE_NONBLOCKING_MODE: u32 = 0x0004; - const FILE_DIRECTORY_FILE: u32 = 0x00000001; - const FILE_WRITE_THROUGH: u32 = 0x00000002; - const FILE_SYNCHRONOUS_IO_NONALERT: u32 = 0x00000020; - - info!("Requesting to create named pipe: {:?}", reply); - - let reply = client - .send_request::(CreateNamedPipeRequest { - access: 0xc0100000, // GENERIC_READ | GENERIC_WRITE | SYNCRONIZE, - options: 0x00000020c, - sharing: 3, - disposition: NtFileDisposition::FILE_OPEN_IF, - max_instances: 0xffffffff, - out_size: 0x00004000, - in_size: 0x00004000, - timeout: 0, - flags: 0, - object: WineObjectAttributes { - rootdir: 0, - attributes: 64, - sd_len: 0, - name: Some("\\??\\pipe\\discord-ipc-0".to_string()), - }, - }) - .await - .unwrap(); - info!("Received: {:?}", reply); - - let create_pipe_event = client - .send_request::(CreateEventRequest { - access: 0x001f0003, - manual_reset: 1, - initial_state: 1, - object: WineObjectAttributes { - rootdir: 0, - attributes: 0x00000080, - sd_len: 0, - name: None, - }, - }) - .await - .unwrap(); - - info!("Received: {:?}", create_pipe_event); - - let ioctl_reply = client - .send_request::(IoctlRequest { - code: FSCTL_PIPE_LISTEN, - async_data: AsyncData { - handle: reply.handle, - event: create_pipe_event.handle, - iosb: 0xc000372b60, - user: 0x55555e1059c0, - apc: 0, - apc_context: 0xc000372b60, - }, - }) - .await - .unwrap(); - - info!("Received: {:?}", ioctl_reply); - - let select_reply = wait_for_select(&mut client, &create_pipe_event, 0x0000c0).await; - - let select_reply = client - .send_request::(SelectRequest { - flags: 2, - cookie: 0x0000c0, - timeout: TIMEOUT_INFINITE, - prev_apc: select_reply.apc_handle, - result: ApcResult { - apc_type: ApcType::APC_ASYNC_IO, - data: ApcResultData::APC_NONE, - }, - data: vec![SelectOp::Wait { - handles: vec![create_pipe_event.handle], - }], - }) - .await - .unwrap(); - - info!("Received Select Reply: {:?}", select_reply); - - info!("Requesting to read data!"); - - let mut buffer = Vec::::new(); - - let pipe_handle = reply.handle; - - let mut user_arg = 0x55555e1059c0; - loop { - user_arg += 1; - tokio::time::sleep(Duration::from_millis(50)).await; - info!("Sending read request"); - let read_event = client - .send_request::(CreateEventRequest { - access: 0x001f0003, - manual_reset: 1, - initial_state: 1, - object: WineObjectAttributes { - rootdir: 0, - attributes: 0x00000080, - sd_len: 0, - name: None, - }, - }) - .await - .unwrap(); - - let reply = client - .send_request::(ReadRequest { - async_data: AsyncData { - handle: pipe_handle, - event: read_event.handle, - iosb: 0xc000372b80, - user: user_arg, - apc: 0, - apc_context: 0xc000372b80, - }, - pos: 0, - amount: 1000, - }) - .await; - - let mut data = match reply { - Ok(reply) => reply.data, - Err(_) => { - info!("Waiting for select"); - let select_reply = wait_for_select(&mut client, &read_event, 21329387).await; - info!("Received select reply: {:?}", select_reply); - info!("Sending get async result:",); - let reply = client - .send_request::( - GetAsyncResultRequest { user: user_arg }, - ) - .await - .unwrap(); - - info!("Got async result reply: {:?}", reply); - - reply.data - } - }; - - if data.len() < 8 { - continue; - } - - buffer.append(&mut data); - - let result = discord::utils::try_read_packet(&buffer); - - match result { - Ok((packet, remaining_data)) => { - buffer = remaining_data; - - let (response_sender, response_receiver) = oneshot::channel::>(); - - _ = sender - .send(WineEnvironmentMessage::ReceivedPacket( - packet, - response_sender, - )) - .await; - - let response = response_receiver.await; - match response { - Ok(response) => match response { - Some(packet) => { - let bytes = discord::utils::write_packet(packet); - - match bytes { - Ok(bytes) => { - let event = client - .send_request::( - CreateEventRequest { - access: 0x001f0003, - manual_reset: 1, - initial_state: 1, - object: WineObjectAttributes { - rootdir: 0, - attributes: 0x00000080, - sd_len: 0, - name: None, - }, - }, - ) - .await - .unwrap(); - - info!("Created event: {:?}", event); - - info!("Sending write request"); - let write_reply = client - .send_request::(WriteRequest { - async_data: AsyncData { - handle: pipe_handle, - event: event.handle, - iosb: 0xc000163c80, - user: 0x55555e1059c0, - apc: 0, - apc_context: 0xc000163c80, - }, - pos: 0, - data: bytes.clone(), - }) - .await; - - info!("Received Write Reply: {:?}", write_reply); - - if write_reply.unwrap().header.error.is_none() { - continue; - } - - loop { - tokio::time::sleep(Duration::from_millis(500)).await; - let select_reply = client - .send_request::( - SelectRequest { - flags: 2, - cookie: 0x13371337, - timeout: TIMEOUT_INFINITE, - prev_apc: 0, - result: ApcResult { - apc_type: ApcType::APC_NONE, - data: ApcResultData::APC_NONE, - }, - data: vec![SelectOp::Wait { - handles: vec![event.handle], - }], - }, - ) - .await - .unwrap(); - info!("Received Write Select Reply: {:?}", select_reply); - - match select_reply.header.error { - Some(error) => match error { - errors::WineError::Known(known_wine_error) => { - match known_wine_error { - KnownWineError::STATUS_KERNEL_APC => break, - _ => continue, - } - } - errors::WineError::Unknown(_) => continue, - }, - None => todo!(), - } - } - } - Err(_) => (), - } - } - None => (), - }, - Err(_) => (), - } - } - Err(_) => (), - } - } -} - -async fn wait_for_select( - client: &mut WineClient, - create_pipe_event: &CreateEventReply, - cookie: u64, -) -> SelectReply { - loop { - tokio::time::sleep(Duration::from_millis(500)).await; - let select_reply = client - .send_request::(SelectRequest { - flags: 2, - cookie: cookie, - timeout: TIMEOUT_INFINITE, - prev_apc: 0, - result: ApcResult { - apc_type: ApcType::APC_NONE, - data: ApcResultData::APC_NONE, - }, - data: vec![SelectOp::Wait { - handles: vec![create_pipe_event.handle], - }], - }) - .await - .unwrap(); - - match &select_reply.header.error { - Some(error) => match error { - errors::WineError::Known(known_wine_error) => match known_wine_error { - KnownWineError::STATUS_KERNEL_APC => return select_reply, - _ => continue, - }, - errors::WineError::Unknown(_) => continue, - }, - None => todo!(), - } - } -} - -impl Environment for WineEnvironment { - async fn start(&mut self) { - info!("Starting Wine Environment"); - let uid = unsafe { getuid() }; - - let (mut tx, mut rx) = channel::(1); - - let wine_directory = format!("/tmp/.wine-{}", uid); - - let path = Path::new(&wine_directory); - - if path.exists() == false { - std::fs::DirBuilder::new().mode(0o700).create(path).unwrap(); - } - - handle_existing_sockets(tx.clone(), &wine_directory).await; - - let _monitor = monitor_new_sockets(tx.clone(), path, wine_directory.clone()); - - loop { - let message = rx.recv().await; - - match message { - Some(msg) => match msg { - WineEnvironmentMessage::HandleSocket(socket) => { - let tx = tx.clone(); - tokio::spawn(async move { handle_socket(tx, socket).await }); - } - WineEnvironmentMessage::Finished => return, - WineEnvironmentMessage::ReceivedPacket(packet, response_sender) => { - let result = self - .event_handler - .handle_packet(ProtocolPacket::Discord(packet)); - - match result { - Some(result) => match result { - ProtocolPacket::Discord(ipc_packet) => { - _ = response_sender.send(Some(ipc_packet)); - } - }, - None => { - _ = response_sender.send(None); - } - } - } - }, - None => info!("Received none!"), - } - } - } -} - -fn handle_filesystem_event( - event: Result, - clone: tokio::sync::mpsc::Sender, -) { - let event = match event { - Ok(event) => event, - Err(_) => return, - }; - - match event.kind { - notify::EventKind::Create(create_kind) => (), - _ => return, - }; - - let path = match event.paths.first() { - Some(path) => path, - None => return, - }; - - let path = match path.to_str() { - Some(path) => path, - None => return, - }; - - if !path.ends_with("/socket") { - return; - } - - info!("Found new WINE socket!"); - info!("Path: {:?}", path); - match clone.blocking_send(WineEnvironmentMessage::HandleSocket(path.to_string())) { - Ok(_) => info!("Sending request to handle new socket: {}", path), - Err(_) => info!("Failed to handle new socket!"), - } -} - -fn monitor_new_sockets( - tx: tokio::sync::mpsc::Sender, - path: &Path, - wine_directory: String, -) -> Result { - let mut watcher: Result = - notify::recommended_watcher(move |event| { - handle_filesystem_event(event, tx.clone()); - }); - - match &mut watcher { - Ok(watcher) => { - info!("Watching wine directory: {}", wine_directory); - - let mut paths = watcher.paths_mut(); - - paths.add(path, notify::RecursiveMode::Recursive).unwrap(); - paths.commit().unwrap(); - } - Err(_) => todo!(), - } - - watcher -} - -async fn handle_existing_sockets( - sender: tokio::sync::mpsc::Sender, - wine_directory: &String, -) { - let paths = std::fs::read_dir(Path::new(wine_directory)); - match paths { - Ok(paths) => { - for path in paths.into_iter() { - match path { - Ok(path) => { - info!("Path: {:?}", path); - - match path.file_type() { - Ok(file_type) => { - if file_type.is_dir() { - let socket_path = path.path().to_str().unwrap().to_string(); - let socket_path = format!("{}/socket", socket_path); - let sender = sender.clone(); - tokio::spawn(async move { - handle_socket(sender, socket_path).await - }); - } - } - Err(_) => todo!(), - } - } - Err(_) => todo!(), - } - } - } - Err(_) => todo!(), - } -} diff --git a/wine-client/src/lib.rs b/wine-client/src/lib.rs new file mode 100644 index 0000000..3e62bed --- /dev/null +++ b/wine-client/src/lib.rs @@ -0,0 +1,3 @@ +pub mod api; +pub(crate) mod utils; +pub(crate) mod wine; diff --git a/wine-client/src/main.rs b/wine-client/src/main.rs deleted file mode 100644 index 424e2b8..0000000 --- a/wine-client/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -use libc::{SIGINT, SIGUSR1}; -use log::{LevelFilter, info}; -use signal_hook::iterator::Signals; -use simple_logger::SimpleLogger; -use std::io::Error; -use std::thread; - -use crate::environment::Environment; -use crate::environment::wine::WineEnvironment; -use crate::handler::emulator::Emulator; -pub mod environment; -pub mod handler; -pub mod protocols; -pub mod utils; -pub mod wine_client; - -#[tokio::main] -async fn main() -> Result<(), Error> { - SimpleLogger::new() - .with_level(LevelFilter::Off) - .with_module_level("rich_status", LevelFilter::Info) - .init() - .unwrap(); - - let mut signals = Signals::new([SIGUSR1])?; - - thread::spawn(move || { - for sig in signals.forever() { - info!("Received signal {:?}", sig); - } - }); - - let handler = Emulator {}; - - let mut env = WineEnvironment { - event_handler: Box::new(handler), - }; - - env.start().await; - - Ok(()) -} diff --git a/wine-client/src/wine.rs b/wine-client/src/wine.rs new file mode 100644 index 0000000..3d4fb7c --- /dev/null +++ b/wine-client/src/wine.rs @@ -0,0 +1,6 @@ +pub mod errors; +pub mod request; +pub mod utils; + +mod versions; +pub(crate) mod wine_client; diff --git a/wine-client/src/environment/wine/errors.rs b/wine-client/src/wine/errors.rs similarity index 86% rename from wine-client/src/environment/wine/errors.rs rename to wine-client/src/wine/errors.rs index 7199a3a..9e69f57 100644 --- a/wine-client/src/environment/wine/errors.rs +++ b/wine-client/src/wine/errors.rs @@ -9,6 +9,7 @@ pub enum KnownWineError { STATUS_PIPE_EMPTY = 0xC00000D9, STATUS_PIPE_BROKEN = 0xC000014B, STATUS_KERNEL_APC = 0x00000100, + STATUS_OBJECT_TYPE_MISMATCH = 0xC0000024, } #[derive(Debug)] @@ -39,6 +40,9 @@ impl WineError { x if x == KnownWineError::STATUS_KERNEL_APC as u32 => { Some(Self::Known(KnownWineError::STATUS_KERNEL_APC)) } + x if x == KnownWineError::STATUS_OBJECT_TYPE_MISMATCH as u32 => { + Some(Self::Known(KnownWineError::STATUS_OBJECT_TYPE_MISMATCH)) + } _ => Some(WineError::Unknown(v)), } } diff --git a/wine-client/src/environment/wine/request.rs b/wine-client/src/wine/request.rs similarity index 90% rename from wine-client/src/environment/wine/request.rs rename to wine-client/src/wine/request.rs index d0fed6c..07fa190 100644 --- a/wine-client/src/environment/wine/request.rs +++ b/wine-client/src/wine/request.rs @@ -1,6 +1,6 @@ use std::io::Error; -use crate::environment::wine::versions::WineVersion; +use crate::wine::versions::WineVersion; pub mod create_event; pub mod create_named_pipe; diff --git a/wine-client/src/environment/wine/request/create_event.rs b/wine-client/src/wine/request/create_event.rs similarity index 92% rename from wine-client/src/environment/wine/request/create_event.rs rename to wine-client/src/wine/request/create_event.rs index a2ceba6..7d404db 100644 --- a/wine-client/src/environment/wine/request/create_event.rs +++ b/wine-client/src/wine/request/create_event.rs @@ -1,7 +1,7 @@ use std::io::Error; use crate::{ - environment::wine::{ + wine::{ request::{ WineReply, WineRequest, header::{RequestHeader, read_reply_header, write_header}, @@ -29,7 +29,7 @@ pub struct CreateEventReply { impl WineRequest for CreateEventRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let mut writer = BinaryWriter::new(); @@ -68,7 +68,7 @@ impl WineRequest for CreateEventRequest { impl WineReply for CreateEventReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, _data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/create_named_pipe.rs b/wine-client/src/wine/request/create_named_pipe.rs similarity index 94% rename from wine-client/src/environment/wine/request/create_named_pipe.rs rename to wine-client/src/wine/request/create_named_pipe.rs index 494f486..2fc29d4 100644 --- a/wine-client/src/environment/wine/request/create_named_pipe.rs +++ b/wine-client/src/wine/request/create_named_pipe.rs @@ -1,7 +1,7 @@ use std::io::Error; use crate::{ - environment::wine::{ + wine::{ request::{ WineReply, WineRequest, header::{RequestHeader, read_reply_header, write_header}, @@ -37,7 +37,7 @@ pub struct CreateNamedPipeReply { impl WineRequest for CreateNamedPipeRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let mut writer = BinaryWriter::new(); @@ -81,7 +81,7 @@ impl WineRequest for CreateNamedPipeRequest { impl WineReply for CreateNamedPipeReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, _data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/get_async_result.rs b/wine-client/src/wine/request/get_async_result.rs similarity index 92% rename from wine-client/src/environment/wine/request/get_async_result.rs rename to wine-client/src/wine/request/get_async_result.rs index 084449b..5174fc9 100644 --- a/wine-client/src/environment/wine/request/get_async_result.rs +++ b/wine-client/src/wine/request/get_async_result.rs @@ -1,7 +1,7 @@ use std::io::Error; use crate::{ - environment::wine::{ + wine::{ request::{ WineReply, WineRequest, header::{ReplyHeader, RequestHeader, read_reply_header, write_header}, @@ -26,7 +26,7 @@ pub struct GetAsyncResultReply { impl WineRequest for GetAsyncResultRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let mut writer = BinaryWriter::new(); @@ -54,7 +54,7 @@ impl WineRequest for GetAsyncResultRequest { impl WineReply for GetAsyncResultReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/header.rs b/wine-client/src/wine/request/header.rs similarity index 93% rename from wine-client/src/environment/wine/request/header.rs rename to wine-client/src/wine/request/header.rs index b870738..57cb8a6 100644 --- a/wine-client/src/environment/wine/request/header.rs +++ b/wine-client/src/wine/request/header.rs @@ -1,14 +1,11 @@ use std::io::Error; -use binary_util::{ByteReader, ByteWriter}; - use crate::{ - environment::wine::{ + utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, + wine::{ errors::{KnownWineError, WineError}, versions::WineVersion, }, - utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, - wine_client::WineClient, }; #[derive(Debug)] diff --git a/wine-client/src/environment/wine/request/init_first_thread.rs b/wine-client/src/wine/request/init_first_thread.rs similarity index 93% rename from wine-client/src/environment/wine/request/init_first_thread.rs rename to wine-client/src/wine/request/init_first_thread.rs index 5eaea40..44d9ab1 100644 --- a/wine-client/src/environment/wine/request/init_first_thread.rs +++ b/wine-client/src/wine/request/init_first_thread.rs @@ -1,7 +1,7 @@ use std::io::Error; use crate::{ - environment::wine::request::{ + wine::request::{ WineReply, WineRequest, header::{RequestHeader, read_reply_header, write_header}, }, @@ -30,7 +30,7 @@ pub struct InitFirstThreadReply { impl WineRequest for InitFirstThreadRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let mut writer = BinaryWriter::new(); @@ -58,7 +58,7 @@ impl WineRequest for InitFirstThreadRequest { impl WineReply for InitFirstThreadReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/init_process_done.rs b/wine-client/src/wine/request/init_process_done.rs similarity index 89% rename from wine-client/src/environment/wine/request/init_process_done.rs rename to wine-client/src/wine/request/init_process_done.rs index 6edf3b1..87697a7 100644 --- a/wine-client/src/environment/wine/request/init_process_done.rs +++ b/wine-client/src/wine/request/init_process_done.rs @@ -1,7 +1,7 @@ use std::io::Error; use crate::{ - environment::wine::request::{ + wine::request::{ WineReply, WineRequest, header::{RequestHeader, read_reply_header, write_header}, }, @@ -21,7 +21,7 @@ pub struct InitProcessDoneReply {} impl WineRequest for InitProcessDoneRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let mut writer = BinaryWriter::new(); @@ -48,7 +48,7 @@ impl WineRequest for InitProcessDoneRequest { impl WineReply for InitProcessDoneReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, _data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/ioctl.rs b/wine-client/src/wine/request/ioctl.rs similarity index 93% rename from wine-client/src/environment/wine/request/ioctl.rs rename to wine-client/src/wine/request/ioctl.rs index 0839e0e..d5c64c6 100644 --- a/wine-client/src/environment/wine/request/ioctl.rs +++ b/wine-client/src/wine/request/ioctl.rs @@ -4,7 +4,7 @@ use base64::{Engine, prelude::BASE64_STANDARD}; use log::{error, info}; use crate::{ - environment::wine::{ + wine::{ errors::KnownWineError, request::{ WineReply, WineRequest, @@ -50,7 +50,7 @@ pub struct IoctlReply { impl WineRequest for IoctlRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { // typically this is `write + 1` let request_id = match version { @@ -81,7 +81,7 @@ impl WineRequest for IoctlRequest { impl WineReply for IoctlReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/read.rs b/wine-client/src/wine/request/read.rs similarity index 93% rename from wine-client/src/environment/wine/request/read.rs rename to wine-client/src/wine/request/read.rs index 799dcc8..69cda8d 100644 --- a/wine-client/src/environment/wine/request/read.rs +++ b/wine-client/src/wine/request/read.rs @@ -3,7 +3,8 @@ use std::io::{self, Error}; use log::{error, info}; use crate::{ - environment::wine::{ + utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, + wine::{ errors::KnownWineError, request::{ WineReply, WineRequest, @@ -13,7 +14,6 @@ use crate::{ utils::{file_pos_t, obj_handle_t}, versions::WineVersion, }, - utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, }; #[derive(Debug)] @@ -33,7 +33,7 @@ pub struct ReadReply { impl WineRequest for ReadRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let request_id = match version { WineVersion::PROTON_10_0_2_BETA => 137, @@ -64,7 +64,7 @@ impl WineRequest for ReadRequest { impl WineReply for ReadReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/request/select.rs b/wine-client/src/wine/request/select.rs similarity index 98% rename from wine-client/src/environment/wine/request/select.rs rename to wine-client/src/wine/request/select.rs index b36ba09..65f83b4 100644 --- a/wine-client/src/environment/wine/request/select.rs +++ b/wine-client/src/wine/request/select.rs @@ -4,7 +4,8 @@ use base64::{Engine, prelude::BASE64_STANDARD}; use log::{error, info}; use crate::{ - environment::wine::{ + utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, + wine::{ errors::KnownWineError, request::{ WineReply, WineRequest, @@ -16,7 +17,6 @@ use crate::{ utils::{abstime_t, client_ptr_t, data_size_t, obj_handle_t}, versions::WineVersion, }, - utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, }; #[allow(non_camel_case_types)] @@ -92,7 +92,7 @@ pub struct SelectReply { impl SelectRequest { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result @@ -169,7 +169,7 @@ impl SelectRequest { impl WineRequest for SelectRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { let request_id = match version { WineVersion::WINE_10_0 => 29, diff --git a/wine-client/src/environment/wine/request/utils.rs b/wine-client/src/wine/request/utils.rs similarity index 100% rename from wine-client/src/environment/wine/request/utils.rs rename to wine-client/src/wine/request/utils.rs diff --git a/wine-client/src/environment/wine/request/utils/apc_result.rs b/wine-client/src/wine/request/utils/apc_result.rs similarity index 96% rename from wine-client/src/environment/wine/request/utils/apc_result.rs rename to wine-client/src/wine/request/utils/apc_result.rs index 1a1adef..6b86de1 100644 --- a/wine-client/src/environment/wine/request/utils/apc_result.rs +++ b/wine-client/src/wine/request/utils/apc_result.rs @@ -1,7 +1,7 @@ use std::io; use crate::{ - environment::wine::{ + wine::{ utils::{apc_param_t, client_ptr_t, obj_handle_t}, versions::WineVersion, }, @@ -103,7 +103,7 @@ pub struct ApcResult { impl ApcResult { pub fn from_bytes( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, reader: &mut BinaryReader, ) -> Result { // TODO: probably need to implement this properly @@ -121,7 +121,7 @@ impl ApcResult { pub fn write( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, writer: &mut BinaryWriter, ) -> Result<(), io::Error> { writer.u32(self.apc_type.to_value(version))?; diff --git a/wine-client/src/environment/wine/request/utils/async_data.rs b/wine-client/src/wine/request/utils/async_data.rs similarity index 83% rename from wine-client/src/environment/wine/request/utils/async_data.rs rename to wine-client/src/wine/request/utils/async_data.rs index af32e04..f098206 100644 --- a/wine-client/src/environment/wine/request/utils/async_data.rs +++ b/wine-client/src/wine/request/utils/async_data.rs @@ -1,7 +1,7 @@ use std::io; use crate::{ - environment::wine::utils::{apc_param_t, client_ptr_t, obj_handle_t}, + wine::utils::{apc_param_t, client_ptr_t, obj_handle_t}, utils::{binary_reader::BinaryReader, binary_writer::BinaryWriter}, }; @@ -17,7 +17,7 @@ pub struct AsyncData { impl AsyncData { pub fn from_bytes( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, reader: &mut BinaryReader, ) -> Result { let result = AsyncData { @@ -34,7 +34,7 @@ impl AsyncData { pub fn write( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, writer: &mut BinaryWriter, ) -> Result<(), io::Error> { writer.u32(self.handle)?; diff --git a/wine-client/src/environment/wine/request/utils/object_attributes.rs b/wine-client/src/wine/request/utils/object_attributes.rs similarity index 97% rename from wine-client/src/environment/wine/request/utils/object_attributes.rs rename to wine-client/src/wine/request/utils/object_attributes.rs index ca3d556..7125da3 100644 --- a/wine-client/src/environment/wine/request/utils/object_attributes.rs +++ b/wine-client/src/wine/request/utils/object_attributes.rs @@ -4,7 +4,7 @@ use binary_util::{ByteReader, ByteWriter}; use safe_transmute::{SingleManyGuard, base::transmute_many, transmute_to_bytes}; use crate::{ - environment::wine::{ + wine::{ utils::{data_size_t, obj_handle_t}, versions::WineVersion, }, @@ -21,7 +21,7 @@ pub struct WineObjectAttributes { impl WineObjectAttributes { pub fn from_bytes( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, bytes: Vec, ) -> Result { let mut reader = BinaryReader::from(bytes); @@ -74,7 +74,7 @@ impl WineObjectAttributes { pub fn to_bytes( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, io::Error> { let mut writer = BinaryWriter::new(); diff --git a/wine-client/src/environment/wine/request/write.rs b/wine-client/src/wine/request/write.rs similarity index 93% rename from wine-client/src/environment/wine/request/write.rs rename to wine-client/src/wine/request/write.rs index 65d9b2f..0f34cb6 100644 --- a/wine-client/src/environment/wine/request/write.rs +++ b/wine-client/src/wine/request/write.rs @@ -3,7 +3,7 @@ use std::io::{self, Error}; use log::info; use crate::{ - environment::wine::{ + wine::{ errors::KnownWineError, request::{ WineReply, WineRequest, @@ -34,7 +34,7 @@ pub struct WriteReply { impl WineRequest for WriteRequest { fn serialize( &self, - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, ) -> Result, std::io::Error> { // typically this is the request_id for `read` + 1 let request_id = match version { @@ -71,7 +71,7 @@ impl WineRequest for WriteRequest { impl WineReply for WriteReply { fn deserialize( - version: crate::environment::wine::versions::WineVersion, + version: crate::wine::versions::WineVersion, response: Vec, data: Option>, ) -> Result diff --git a/wine-client/src/environment/wine/utils.rs b/wine-client/src/wine/utils.rs similarity index 97% rename from wine-client/src/environment/wine/utils.rs rename to wine-client/src/wine/utils.rs index 17a5325..5f298fe 100644 --- a/wine-client/src/environment/wine/utils.rs +++ b/wine-client/src/wine/utils.rs @@ -5,7 +5,7 @@ use binary_util::{ByteReader, ByteWriter}; use safe_transmute::{SingleManyGuard, base::transmute_many, transmute_to_bytes}; -use crate::{environment::wine::versions::WineVersion, utils::binary_writer::BinaryWriter}; +use crate::{utils::binary_writer::BinaryWriter, wine::versions::WineVersion}; #[allow(non_camel_case_types)] pub type obj_handle_t = u32; diff --git a/wine-client/src/environment/wine/versions.rs b/wine-client/src/wine/versions.rs similarity index 100% rename from wine-client/src/environment/wine/versions.rs rename to wine-client/src/wine/versions.rs diff --git a/wine-client/src/environment/wine/wine_client.rs b/wine-client/src/wine/wine_client.rs similarity index 83% rename from wine-client/src/environment/wine/wine_client.rs rename to wine-client/src/wine/wine_client.rs index 19dcb71..f824ccd 100644 --- a/wine-client/src/environment/wine/wine_client.rs +++ b/wine-client/src/wine/wine_client.rs @@ -1,25 +1,21 @@ use std::{ - io::{self, Error}, + io::{self, Error, PipeReader, PipeWriter, Read, Write, pipe}, mem, - os::{fd::RawFd, raw::c_void}, + os::{ + fd::{FromRawFd, RawFd}, + raw::c_void, + unix::net::UnixStream, + }, path::Path, }; use libc::getsockopt; use log::info; use std::os::fd::AsRawFd; -use std::os::unix::{net::UnixStream as OsUnixStream, prelude::FromRawFd}; -use tokio::{ - io::AsyncReadExt, - net::{UnixStream, unix::pipe::Receiver}, -}; -use tokio::{ - io::AsyncWriteExt, - net::unix::pipe::{Sender, pipe}, -}; use crate::{ - environment::wine::{ + utils::binary_reader::BinaryReader, + wine::{ errors::KnownWineError, request::{ WineReply, WineRequest, @@ -28,26 +24,25 @@ use crate::{ }, versions::{WineType, WineVersion}, }, - utils::binary_reader::BinaryReader, }; pub struct WineClient { pub server_version: WineVersion, pub master_socket: UnixStream, pub request_socket: UnixStream, - pub reply_read_socket: Receiver, - pub wait_read_socket: Receiver, + pub reply_read_socket: PipeReader, + pub wait_read_socket: PipeReader, } impl WineClient { - pub async fn connect(socket: String) -> Result { - let stream = UnixStream::connect(socket).await?; + pub fn connect(socket: String) -> Result { + let stream = UnixStream::connect(socket).unwrap(); enable_passcred(&stream)?; let cred = get_partner_process(&stream)?; info!("Got partner process: {:?}", cred.pid); let exe_path = format!("/proc/{}/exe", cred.pid); - let exe_path = tokio::fs::read_link(Path::new(&exe_path)).await; + let exe_path = std::fs::read_link(Path::new(&exe_path)); let exe_path = match exe_path { Ok(exe_path) => exe_path, Err(_) => todo!(), @@ -67,7 +62,7 @@ impl WineClient { info!("Wine Server exe path: {:?}", exe_path); - let (request_stream, server_version) = receive_initial_handshake(&stream).await?; + let (request_stream, server_version) = receive_initial_handshake(&stream).unwrap(); info!("Server Version: {}", server_version); @@ -77,14 +72,14 @@ impl WineClient { Some(version) => { info!("Detected wine version: {:?}", version); - let (reply_write, reply_read) = pipe()?; - let (wait_write, wait_reader) = pipe()?; + let (reply_read, reply_write) = pipe()?; + let (wait_reader, wait_write) = pipe()?; let reply_fd = reply_write.as_raw_fd(); let wait_fd = wait_write.as_raw_fd(); - send_fd_to_server(&stream, reply_write)?; - send_fd_to_server(&stream, wait_write)?; + send_fd_to_server(&stream, reply_write.as_raw_fd())?; + send_fd_to_server(&stream, wait_write.as_raw_fd())?; let mut client = WineClient { server_version: version, @@ -104,7 +99,7 @@ impl WineClient { reply_fd: reply_fd, wait_fd: wait_fd, }) - .await?; + .unwrap(); info!("First thread reply: {:?}", reply); @@ -121,25 +116,25 @@ impl WineClient { )) } - pub async fn send_request( + pub fn send_request( &mut self, request: Req, ) -> Result { let data = request.serialize(self.server_version)?; - self.request_socket.write(&data).await?; + self.request_socket.write(&data); let reply_size = 64; let mut reply: Vec = vec![0; reply_size]; - self.reply_read_socket.read_exact(&mut reply).await?; + self.reply_read_socket.read_exact(&mut reply); let mut reader = BinaryReader::from(reply.clone()); let header = read_reply_header(self.server_version, &mut reader)?; let payload = if header.size > 0 { let mut extra_data: Vec = vec![0; usize::try_from(header.size).unwrap()]; - self.reply_read_socket.read_exact(&mut extra_data).await?; + self.reply_read_socket.read_exact(&mut extra_data); Some(extra_data) } else { None @@ -197,8 +192,7 @@ fn get_partner_process(socket: &UnixStream) -> Result Result<(UnixStream, u32), io::Error> { - stream.readable().await?; +fn receive_initial_handshake(stream: &UnixStream) -> Result<(UnixStream, u32), io::Error> { return receive_request_fd(stream.as_raw_fd()); } @@ -245,16 +239,15 @@ fn receive_request_fd(socket_fd: RawFd) -> io::Result<(UnixStream, u32)> { )); } info!("FD: {}, Version: {}", received_fd, handle); - let os_stream = unsafe { OsUnixStream::from_raw_fd(received_fd) }; + let os_stream = unsafe { UnixStream::from_raw_fd(received_fd) }; os_stream.set_nonblocking(true)?; - let peer_stream = UnixStream::from_std(os_stream)?; + let peer_stream = os_stream; Ok((peer_stream, handle)) } -fn send_fd_to_server(server: &UnixStream, stream_to_send: Sender) -> io::Result<()> { +fn send_fd_to_server(server: &UnixStream, fd_to_send: i32) -> io::Result<()> { let socket_fd = server.as_raw_fd(); - let fd_to_send = stream_to_send.as_raw_fd(); // Wine expects 8 bytes of data: 4 zero bytes + 4 bytes containing the fd number let mut data = [0u8; 8]; diff --git a/wine-client/src/wine_client.rs b/wine-client/src/wine_client.rs deleted file mode 100644 index aabd896..0000000 --- a/wine-client/src/wine_client.rs +++ /dev/null @@ -1,9 +0,0 @@ -use tokio::net::{UnixStream, unix::pipe::Receiver}; - -pub struct WineClient { - pub server_version: u32, - pub master_socket: UnixStream, - pub request_socket: UnixStream, - pub reply_read_socket: Receiver, - pub wait_read_socket: Receiver, -}