|
1 | 1 | fn main() {
|
2 | 2 | #[cfg(target_os = "windows")]
|
3 |
| - download_winpcap_sdk() |
| 3 | + download_windows_pcap_sdk() |
4 | 4 | }
|
5 | 5 |
|
6 | 6 | #[cfg(target_os = "windows")]
|
7 |
| -fn download_winpcap_sdk() { |
| 7 | +fn download_windows_pcap_sdk() { |
| 8 | + use std::{ |
| 9 | + env, fs, |
| 10 | + io::{self, Write}, |
| 11 | + }; |
| 12 | + |
8 | 13 | use http_req::request;
|
9 |
| - use std::env; |
10 |
| - use std::fs::File; |
11 |
| - use std::io::prelude::*; |
| 14 | + use zip::ZipArchive; |
12 | 15 |
|
13 | 16 | println!("cargo:rerun-if-changed=build.rs");
|
14 | 17 |
|
15 | 18 | let out_dir = env::var("OUT_DIR").unwrap();
|
16 | 19 |
|
17 |
| - let mut reader = Vec::new(); |
18 |
| - let _res = request::get( |
19 |
| - "https://nmap.org/npcap/dist/npcap-sdk-1.05.zip", |
20 |
| - &mut reader, |
21 |
| - ) |
22 |
| - .unwrap(); |
23 |
| - |
24 |
| - let mut pcapzip = File::create(format!("{}{}", out_dir, "/npcap.zip")).unwrap(); |
25 |
| - pcapzip.write_all(reader.as_slice()).unwrap(); |
26 |
| - pcapzip.flush().unwrap(); |
27 |
| - |
28 |
| - pcapzip = File::open(format!("{}{}", out_dir, "/npcap.zip")).unwrap(); |
29 |
| - |
| 20 | + let mut pcap_zip = Vec::new(); |
| 21 | + let res = request::get("https://npcap.com/dist/npcap-sdk-1.13.zip", &mut pcap_zip).unwrap(); |
| 22 | + eprintln!("{:?}", res); |
| 23 | + |
| 24 | + let lib_dir = if cfg!(target_arch = "aarch64") { |
| 25 | + "Lib/ARM64" |
| 26 | + } else if cfg!(target_arch = "x86_64") { |
| 27 | + "Lib/x64" |
| 28 | + } else if cfg!(target_arch = "x86") { |
| 29 | + "Lib" |
| 30 | + } else { |
| 31 | + panic!("Unsupported target!") |
| 32 | + }; |
30 | 33 | let lib_name = "Packet.lib";
|
31 |
| - #[cfg(target_arch = "x86_64")] |
32 |
| - let lib_dir = "Lib/x64"; |
33 |
| - #[cfg(target_arch = "x86")] |
34 |
| - let lib_dir = "Lib"; |
35 |
| - |
36 | 34 | let lib_path = format!("{}/{}", lib_dir, lib_name);
|
37 |
| - let mut zip_archive = zip::ZipArchive::new(pcapzip).unwrap(); |
38 |
| - let mut pcaplib = match zip_archive.by_name(lib_path.as_str()) { |
39 |
| - Ok(pcaplib) => pcaplib, |
| 35 | + |
| 36 | + let mut archive = ZipArchive::new(io::Cursor::new(pcap_zip)).unwrap(); |
| 37 | + let mut pcap_lib = match archive.by_name(&lib_path) { |
| 38 | + Ok(lib) => lib, |
40 | 39 | Err(err) => {
|
41 | 40 | panic!("{}", err);
|
42 | 41 | }
|
43 | 42 | };
|
44 | 43 |
|
45 |
| - let mut pcaplib_bytes = Vec::new(); |
46 |
| - pcaplib.read_to_end(&mut pcaplib_bytes).unwrap(); |
47 |
| - |
48 |
| - std::fs::create_dir_all(format!("{}/{}", out_dir, lib_dir)).unwrap(); |
49 |
| - let mut pcaplib_file = File::create(format!("{}/{}", out_dir, lib_path)).unwrap(); |
50 |
| - pcaplib_file.write_all(pcaplib_bytes.as_slice()).unwrap(); |
51 |
| - pcaplib_file.flush().unwrap(); |
| 44 | + fs::create_dir_all(format!("{}/{}", out_dir, lib_dir)).unwrap(); |
| 45 | + let mut pcap_lib_file = fs::File::create(format!("{}/{}", out_dir, lib_path)).unwrap(); |
| 46 | + io::copy(&mut pcap_lib, &mut pcap_lib_file).unwrap(); |
| 47 | + pcap_lib_file.flush().unwrap(); |
52 | 48 |
|
53 | 49 | println!("cargo:rustc-link-search=native={}/{}", out_dir, lib_dir);
|
54 | 50 | }
|
0 commit comments