From 0b1d76e5bcdc8f869f8bb63191a5f0feae355900 Mon Sep 17 00:00:00 2001 From: EphemeralSapient <50352391+EphemeralSapient@users.noreply.github.com> Date: Tue, 22 Oct 2024 05:11:18 +0530 Subject: [PATCH] Windows 11 support (#39) * Windows support * Fixed tokio-wifiscanner * Fixed windows related bugs --------- Co-authored-by: Chleba --- Cargo.lock | 569 ++++++++++++++++++++++++++++++++++- Cargo.toml | 11 +- build.rs | 81 +++++ src/components/export.rs | 20 ++ src/components/interfaces.rs | 24 +- 5 files changed, 692 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba7a62d..c92a03f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,23 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.8.11" @@ -108,6 +125,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + [[package]] name = "async-trait" version = "0.1.82" @@ -135,7 +167,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.4", "object", "rustc-demangle", ] @@ -192,6 +224,27 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "cassowary" version = "0.3.0" @@ -213,6 +266,8 @@ version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -242,6 +297,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdf600c45bd958cf2945c445264471cca8b6c8e67bc87b71affd6d7e5682621" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "clap" version = "4.5.17" @@ -252,6 +317,16 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-verbosity-flag" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e099138e1807662ff75e2cebe4ae2287add879245574489f9b1588eb5e5564ed" +dependencies = [ + "clap", + "log", +] + [[package]] name = "clap_builder" version = "4.5.17" @@ -267,6 +342,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "clap_complete" +version = "4.5.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b378c786d3bde9442d2c6dd7e6080b2a818db2b96e30d6e7f1b6d224eb617d3" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.5.13" @@ -285,6 +369,16 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "clap_mangen" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17415fd4dfbea46e3274fcd8d368284519b358654772afb700dc2e8d2b24eeb" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "color-eyre" version = "0.6.3" @@ -385,6 +479,12 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + [[package]] name = "convert_case" version = "0.6.0" @@ -394,6 +494,16 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -409,6 +519,36 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crossterm" version = "0.28.1" @@ -473,6 +613,32 @@ dependencies = [ "memchr", ] +[[package]] +name = "deflate64" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b" + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "derive_deref" version = "1.1.1" @@ -498,6 +664,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -521,6 +688,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "dlv-list" version = "0.5.2" @@ -580,6 +758,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "flate2" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.0", +] + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "futures" version = "0.3.30" @@ -742,6 +951,25 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "http_req" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0122ab6637149482eb66b57288ac597bc7eb9859cbaa79dee62fa19a350df3d2" +dependencies = [ + "native-tls", + "unicase", +] + [[package]] name = "human-panic" version = "2.0.1" @@ -797,6 +1025,15 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "indoc" version = "2.0.5" @@ -852,6 +1089,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.70" @@ -916,6 +1162,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lockfree-object-pool" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" + [[package]] name = "log" version = "0.4.22" @@ -931,6 +1183,16 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "lzma-rs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" +dependencies = [ + "byteorder", + "crc", +] + [[package]] name = "mac_oui" version = "0.4.11" @@ -981,6 +1243,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" version = "1.0.2" @@ -1003,14 +1274,35 @@ dependencies = [ "serde", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "netscanner" version = "0.6.0" dependencies = [ + "anyhow", "better-panic", "chrono", "cidr", "clap", + "clap-verbosity-flag", + "clap_complete", + "clap_mangen", "color-eyre", "config", "crossterm", @@ -1019,6 +1311,7 @@ dependencies = [ "directories", "dns-lookup", "futures", + "http_req", "human-panic", "ipnetwork", "itertools 0.13.0", @@ -1046,6 +1339,7 @@ dependencies = [ "tracing-error", "tracing-subscriber", "tui-input", + "zip", "tui-scrollview", ] @@ -1075,6 +1369,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.19" @@ -1099,6 +1399,50 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -1173,6 +1517,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", + "hmac", +] + [[package]] name = "pest" version = "2.7.12" @@ -1230,6 +1584,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "pnet" version = "0.35.0" @@ -1373,6 +1733,12 @@ dependencies = [ "serde", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -1541,6 +1907,12 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "roff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" + [[package]] name = "relative-path" version = "1.9.3" @@ -1639,12 +2011,44 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "schannel" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +c +name = "security-framework-sys" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.23" @@ -1692,6 +2096,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1748,6 +2163,12 @@ dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "slab" version = "0.4.9" @@ -1816,6 +2237,12 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "surge-ping" version = "0.8.1" @@ -1854,6 +2281,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "terminal_size" version = "0.3.0" @@ -1894,6 +2334,25 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -1948,8 +2407,6 @@ dependencies = [ [[package]] name = "tokio-wifiscanner" version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3b1b66a051985323600c695b92d22e2df1c63ce2f3c13fb4e2a4169a52fe5e" dependencies = [ "itertools 0.10.5", "regex", @@ -2155,6 +2612,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -2291,6 +2754,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[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-targets" version = "0.48.5" @@ -2456,3 +2928,94 @@ dependencies = [ "quote", "syn 2.0.77", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "zip" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc5e4288ea4057ae23afc69a4472434a87a2495cafce6632fd1c4ec9f5cf3494" +dependencies = [ + "aes", + "arbitrary", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "deflate64", + "displaydoc", + "flate2", + "hmac", + "indexmap", + "lzma-rs", + "memchr", + "pbkdf2", + "rand", + "sha1", + "thiserror", + "time", + "zeroize", + "zopfli", + "zstd", +] + +[[package]] +name = "zopfli" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +dependencies = [ + "bumpalo", + "crc32fast", + "lockfree-object-pool", + "log", + "once_cell", + "simd-adler32", +] + +[[package]] +name = "zstd" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 707dea3..4c0a1ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,9 +85,18 @@ strum = "0.26.3" surge-ping = "0.8.1" tokio = { version = "1.40.0", features = ["full"] } tokio-util = "0.7.12" -tokio-wifiscanner = "0.2.1" +tokio-wifiscanner = { git = "https://github.com/EphemeralSapient/tokio-wifiscanner" } tracing = "0.1.40" tracing-error = "0.2.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] } tui-input = { version = "0.10.1", features = ["serde"] } tui-scrollview = "0.4.0" + +[target.'cfg(target_os = "windows")'.build-dependencies] +anyhow = "1.0.86" +http_req = "0.11.1" +zip = "2.1.6" +clap = { version = "4.5.13", features = ["derive"] } +clap-verbosity-flag = "2.2.1" +clap_complete = "4.5.12" +clap_mangen = "0.2.23" diff --git a/build.rs b/build.rs index 69582c2..84e483c 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,8 @@ + fn main() { + #[cfg(target_os = "windows")] + download_windows_npcap_sdk().unwrap(); + let git_output = std::process::Command::new("git").args(["rev-parse", "--git-dir"]).output().ok(); let git_dir = git_output.as_ref().and_then(|output| { std::str::from_utf8(&output.stdout).ok().and_then(|s| s.strip_suffix('\n').or_else(|| s.strip_suffix("\r\n"))) @@ -44,3 +48,80 @@ fn main() { println!("cargo:rustc-env=_GIT_INFO={}", git_describe); } + +#[cfg(target_os = "windows")] +fn download_windows_npcap_sdk() -> anyhow::Result<()> { + + use anyhow::anyhow; + + use std::{ + fs, + io::{self, Write}, + env, + path::PathBuf + }; + + use http_req::request; + use zip::ZipArchive; + + println!("cargo:rerun-if-changed=build.rs"); + + // get npcap SDK + const NPCAP_SDK: &str = "npcap-sdk-1.13.zip"; + + let npcap_sdk_download_url = format!("https://npcap.com/dist/{NPCAP_SDK}"); + let cache_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("target"); + let npcap_sdk_cache_path = cache_dir.join(NPCAP_SDK); + + let npcap_zip = match fs::read(&npcap_sdk_cache_path) { + // use cached + Ok(zip_data) => { + eprintln!("Found cached npcap SDK"); + zip_data + } + // download SDK + Err(_) => { + eprintln!("Downloading npcap SDK"); + + // download + let mut zip_data = vec![]; + let _res = request::get(npcap_sdk_download_url, &mut zip_data)?; + + // write cache + fs::create_dir_all(cache_dir)?; + let mut cache = fs::File::create(npcap_sdk_cache_path)?; + cache.write_all(&zip_data)?; + + zip_data + } + }; + + // extract DLL + let lib_path = if cfg!(target_arch = "aarch64") { + "Lib/ARM64/Packet.lib" + } else if cfg!(target_arch = "x86_64") { + "Lib/x64/Packet.lib" + } else if cfg!(target_arch = "x86") { + "Lib/Packet.lib" + } else { + panic!("Unsupported target!") + }; + let mut archive = ZipArchive::new(io::Cursor::new(npcap_zip))?; + let mut npcap_lib = archive.by_name(lib_path)?; + + // write DLL + let lib_dir = PathBuf::from(env::var("OUT_DIR")?).join("npcap_sdk"); + let lib_path = lib_dir.join("Packet.lib"); + fs::create_dir_all(&lib_dir)?; + let mut lib_file = fs::File::create(lib_path)?; + io::copy(&mut npcap_lib, &mut lib_file)?; + + println!( + "cargo:rustc-link-search=native={}", + lib_dir + .to_str() + .ok_or(anyhow!("{lib_dir:?} is not valid UTF-8"))? + ); + + Ok(()) +} \ No newline at end of file diff --git a/src/components/export.rs b/src/components/export.rs index 4fc82fb..f3a43c7 100644 --- a/src/components/export.rs +++ b/src/components/export.rs @@ -65,6 +65,26 @@ impl Export { } } + #[cfg(target_os = "windows")] + fn get_user_home_dir(&mut self) { + let mut home_dir = String::from("C:\\Users\\Administrator"); + if let Some(h_dir) = env::var_os("USERPROFILE") { + home_dir = String::from(h_dir.to_str().unwrap()); + } + if let Some(sudo_user) = env::var_os("SUDO_USER") { + home_dir = format!("C:\\Users\\{}", sudo_user.to_str().unwrap()); + } + self.home_dir = format!("{}\\.netscanner", home_dir); + + // -- create .netscanner folder if it doesn't exist + if std::fs::metadata(self.home_dir.clone()).is_err() { + if std::fs::create_dir_all(self.home_dir.clone()).is_err() { + self.export_failed = true; + } + } + } + + pub fn write_discovery(&mut self, data: Vec, timestamp: &String) -> Result<()> { let mut w = Writer::from_path(format!("{}/scanned_ips.{}.csv", self.home_dir, timestamp))?; diff --git a/src/components/interfaces.rs b/src/components/interfaces.rs index df2aed0..a55ce83 100644 --- a/src/components/interfaces.rs +++ b/src/components/interfaces.rs @@ -47,16 +47,19 @@ impl Interfaces { fn get_interfaces(&mut self) { self.interfaces.clear(); self.active_interfaces.clear(); - + let interfaces = datalink::interfaces(); for intf in &interfaces { // -- get active interface with non-local IP - if intf.is_up() && !intf.ips.is_empty() { + if cfg!(windows) || (intf.is_up() && !intf.ips.is_empty()) { + // Windows doesn't have the is_up() method for ip in &intf.ips { - // -- set active interface that's not localhost - if ip.is_ipv4() && ip.ip().to_string().ne("127.0.0.1") { - self.active_interfaces.push(intf.clone()); - break; + // -- set active interface that's not localhost and starts with 192 [for windows compatibility] + if let IpAddr::V4(ipv4) = ip.ip() { + if ipv4.octets()[0] == 192 && ip.ip().to_string().ne("127.0.0.1") { + self.active_interfaces.push(intf.clone()); + break; + } } } } @@ -66,7 +69,7 @@ impl Interfaces { // -- sort interfaces self.interfaces.sort_by(|a, b| a.name.cmp(&b.name)); } - + fn next_active_interface(&mut self) { let mut new_index = self.active_interface_index + 1; if new_index >= self.active_interfaces.len() { @@ -111,8 +114,11 @@ impl Interfaces { if active_interface.is_some() && active_interface.unwrap() == w { active = String::from("*"); } - let name = w.name.clone(); - let mac = w.mac.unwrap_or(MacAddr::default()).to_string(); + let name = if cfg!(windows) { + w.description.clone() + } else { + w.name.clone() + }; let mac = w.mac.unwrap_or(MacAddr::default()).to_string(); let ipv4: Vec = w .ips .iter()