mirror of
				https://github.com/wisdgod/cursor-api.git
				synced 2025-10-31 10:26:59 +08:00 
			
		
		
		
	v0.1.3-rc.5
This commit is contained in:
		
							
								
								
									
										84
									
								
								tools/get-token/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										84
									
								
								tools/get-token/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -15,19 +15,16 @@ dependencies = [ | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "bitflags" | ||||
| version = "2.6.0" | ||||
| name = "base64" | ||||
| version = "0.22.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" | ||||
| checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" | ||||
|  | ||||
| [[package]] | ||||
| name = "cc" | ||||
| version = "1.2.5" | ||||
| name = "bitflags" | ||||
| version = "2.8.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" | ||||
| dependencies = [ | ||||
|  "shlex", | ||||
| ] | ||||
| checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" | ||||
|  | ||||
| [[package]] | ||||
| name = "cfg-if" | ||||
| @@ -51,7 +48,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" | ||||
| name = "get-token" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "base64", | ||||
|  "rusqlite", | ||||
|  "serde_json", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| @@ -72,17 +71,28 @@ dependencies = [ | ||||
|  "hashbrown", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "itoa" | ||||
| version = "1.0.14" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" | ||||
|  | ||||
| [[package]] | ||||
| name = "libsqlite3-sys" | ||||
| version = "0.30.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" | ||||
| dependencies = [ | ||||
|  "cc", | ||||
|  "pkg-config", | ||||
|  "vcpkg", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "memchr" | ||||
| version = "2.7.4" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | ||||
|  | ||||
| [[package]] | ||||
| name = "once_cell" | ||||
| version = "1.20.2" | ||||
| @@ -97,18 +107,18 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" | ||||
|  | ||||
| [[package]] | ||||
| name = "proc-macro2" | ||||
| version = "1.0.92" | ||||
| version = "1.0.93" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" | ||||
| checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" | ||||
| dependencies = [ | ||||
|  "unicode-ident", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "quote" | ||||
| version = "1.0.37" | ||||
| version = "1.0.38" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" | ||||
| checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
| ] | ||||
| @@ -128,10 +138,42 @@ dependencies = [ | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "shlex" | ||||
| version = "1.3.0" | ||||
| name = "ryu" | ||||
| version = "1.0.19" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" | ||||
| checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" | ||||
|  | ||||
| [[package]] | ||||
| name = "serde" | ||||
| version = "1.0.217" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" | ||||
| dependencies = [ | ||||
|  "serde_derive", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "serde_derive" | ||||
| version = "1.0.217" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
|  "syn", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "serde_json" | ||||
| version = "1.0.138" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" | ||||
| dependencies = [ | ||||
|  "itoa", | ||||
|  "memchr", | ||||
|  "ryu", | ||||
|  "serde", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "smallvec" | ||||
| @@ -141,9 +183,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" | ||||
|  | ||||
| [[package]] | ||||
| name = "syn" | ||||
| version = "2.0.91" | ||||
| version = "2.0.98" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" | ||||
| checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
| @@ -152,9 +194,9 @@ dependencies = [ | ||||
|  | ||||
| [[package]] | ||||
| name = "unicode-ident" | ||||
| version = "1.0.14" | ||||
| version = "1.0.16" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" | ||||
| checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" | ||||
|  | ||||
| [[package]] | ||||
| name = "vcpkg" | ||||
|   | ||||
| @@ -4,7 +4,10 @@ version = "0.1.0" | ||||
| edition = "2021" | ||||
|  | ||||
| [dependencies] | ||||
| rusqlite = { version = "0.32.1", default-features = false, features = ["bundled"] } | ||||
| base64 = "0.22.1" | ||||
| # rusqlite = { version = "0.32.1", default-features = false, features = ["bundled"] } | ||||
| rusqlite = "0.32.1" | ||||
| serde_json = "1.0.138" | ||||
|  | ||||
| [profile.release] | ||||
| lto = true | ||||
|   | ||||
| @@ -1,28 +1,150 @@ | ||||
| use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; | ||||
| use rusqlite::Connection; | ||||
| use std::env; | ||||
| use std::path::PathBuf; | ||||
| use std::process::Command; | ||||
|  | ||||
| fn get_machine_id() -> String { | ||||
|     if cfg!(windows) { | ||||
|         let output = Command::new("REG") | ||||
|             .args(&[ | ||||
|                 "QUERY", | ||||
|                 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography", | ||||
|                 "/v", | ||||
|                 "MachineGuid", | ||||
|             ]) | ||||
|             .output() | ||||
|             .expect("无法执行 REG 命令"); | ||||
|         String::from_utf8_lossy(&output.stdout) | ||||
|             .lines() | ||||
|             .find(|line| line.contains("MachineGuid")) | ||||
|             .and_then(|line| line.split_whitespace().last()) | ||||
|             .unwrap_or("unknown") | ||||
|             .to_string() | ||||
|     } else if cfg!(target_os = "macos") { | ||||
|         let output = Command::new("ioreg") | ||||
|             .args(&["-rd1", "-c", "IOPlatformExpertDevice"]) | ||||
|             .output() | ||||
|             .expect("无法执行 ioreg 命令"); | ||||
|         String::from_utf8_lossy(&output.stdout) | ||||
|             .lines() | ||||
|             .find(|line| line.contains("IOPlatformUUID")) | ||||
|             .and_then(|line| line.split("\"").nth(3)) | ||||
|             .unwrap_or("unknown") | ||||
|             .to_string() | ||||
|     } else if cfg!(target_os = "linux") { | ||||
|         let output = Command::new("sh") | ||||
|             .arg("-c") | ||||
|             .arg("( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :") | ||||
|             .output() | ||||
|             .expect("无法获取 machine-id"); | ||||
|         String::from_utf8_lossy(&output.stdout).trim().to_string() | ||||
|     } else if cfg!(target_os = "freebsd") { | ||||
|         let output = Command::new("sh") | ||||
|             .arg("-c") | ||||
|             .arg("kenv -q smbios.system.uuid || sysctl -n kern.hostuuid") | ||||
|             .output() | ||||
|             .expect("无法获取 UUID"); | ||||
|         String::from_utf8_lossy(&output.stdout).trim().to_string() | ||||
|     } else { | ||||
|         "unknown".to_string() | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn obfuscate_bytes(bytes: &mut [u8]) { | ||||
|     let mut prev: u8 = 165; | ||||
|     for (idx, byte) in bytes.iter_mut().enumerate() { | ||||
|         let old_value = *byte; | ||||
|         *byte = (old_value ^ prev).wrapping_add((idx % 256) as u8); | ||||
|         prev = *byte; | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn generate_timestamp_header() -> String { | ||||
|     let timestamp = std::time::SystemTime::now() | ||||
|         .duration_since(std::time::UNIX_EPOCH) | ||||
|         .unwrap() | ||||
|         .as_secs() | ||||
|         / 1_000; | ||||
|  | ||||
|     let mut timestamp_bytes = vec![ | ||||
|         ((timestamp >> 8) & 0xFF) as u8, | ||||
|         (timestamp & 0xFF) as u8, | ||||
|         ((timestamp >> 24) & 0xFF) as u8, | ||||
|         ((timestamp >> 16) & 0xFF) as u8, | ||||
|         ((timestamp >> 8) & 0xFF) as u8, | ||||
|         (timestamp & 0xFF) as u8, | ||||
|     ]; | ||||
|  | ||||
|     obfuscate_bytes(&mut timestamp_bytes); | ||||
|     BASE64.encode(×tamp_bytes) | ||||
| } | ||||
|  | ||||
| fn main() { | ||||
|     let home_dir = env::var("HOME") | ||||
|         .or_else(|_| env::var("USERPROFILE")) | ||||
|         .unwrap(); | ||||
|     let db_path = if cfg!(target_os = "windows") { | ||||
|         PathBuf::from(home_dir).join(r"AppData\Roaming\Cursor\User\globalStorage\state.vscdb") | ||||
|     } else if cfg!(target_os = "linux") { | ||||
|         PathBuf::from(home_dir).join(".config/Cursor/User/globalStorage/state.vscdb") | ||||
|     } else { | ||||
|         PathBuf::from(home_dir) | ||||
|     let db_path = if cfg!(windows) { | ||||
|         let app_data = env::var("APPDATA").unwrap_or_else(|_| { | ||||
|             let profile = env::var("USERPROFILE").expect("未找到 USERPROFILE 环境变量"); | ||||
|             PathBuf::from(profile) | ||||
|                 .join("AppData") | ||||
|                 .join("Roaming") | ||||
|                 .to_string_lossy() | ||||
|                 .to_string() | ||||
|         }); | ||||
|         PathBuf::from(app_data).join(r"Cursor\User\globalStorage\state.vscdb") | ||||
|     } else if cfg!(target_os = "macos") { | ||||
|         let home = env::var("HOME").expect("未找到 HOME 环境变量"); | ||||
|         PathBuf::from(home) | ||||
|             .join("Library/Application Support/Cursor/User/globalStorage/state.vscdb") | ||||
|     } else if cfg!(target_os = "linux") { | ||||
|         let config_home = env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| { | ||||
|             let home = env::var("HOME").expect("未找到 HOME 环境变量"); | ||||
|             format!("{}/.config", home) | ||||
|         }); | ||||
|         PathBuf::from(config_home).join("Cursor/User/globalStorage/state.vscdb") | ||||
|     } else { | ||||
|         panic!("不支持的操作系统平台") | ||||
|     }; | ||||
|  | ||||
|     match Connection::open(&db_path) { | ||||
|         Ok(conn) => { | ||||
|             match conn.query_row( | ||||
|             let token = conn.query_row( | ||||
|                 "SELECT value FROM ItemTable WHERE key = 'cursorAuth/accessToken'", | ||||
|                 [], | ||||
|                 |row| row.get::<_, String>(0), | ||||
|             ) { | ||||
|                 Ok(token) => println!("访问令牌: {}", token.trim()), | ||||
|             ); | ||||
|  | ||||
|             let storage_path = db_path.parent().unwrap().join("storage.json"); | ||||
|             let storage_content = std::fs::read_to_string(storage_path).unwrap_or_default(); | ||||
|             let storage_json: serde_json::Value = | ||||
|                 serde_json::from_str(&storage_content).unwrap_or_default(); | ||||
|  | ||||
|             match token { | ||||
|                 Ok(token) => { | ||||
|                     println!("访问令牌: {}", token.trim()); | ||||
|  | ||||
|                     // if let Some(machine_id) = storage_json["telemetry.machineId"].as_str() { | ||||
|                     //     println!("machineId: {}", machine_id); | ||||
|                     // } | ||||
|  | ||||
|                     // if let Some(mac_machine_id) = storage_json["telemetry.macMachineId"].as_str() { | ||||
|                     //     println!("macMachineId: {}", mac_machine_id); | ||||
|                     // } | ||||
|  | ||||
|                     let sys_machine_id = get_machine_id(); | ||||
|                     println!("系统 machine-id: {}", sys_machine_id); | ||||
|  | ||||
|                     if let (Some(machine_id), Some(mac_machine_id)) = ( | ||||
|                         storage_json["telemetry.machineId"].as_str(), | ||||
|                         storage_json["telemetry.macMachineId"].as_str(), | ||||
|                     ) { | ||||
|                         println!( | ||||
|                             "校验和: {}{}/{}", | ||||
|                             generate_timestamp_header(), | ||||
|                             machine_id, | ||||
|                             mac_machine_id | ||||
|                         ); | ||||
|                     } | ||||
|                 } | ||||
|                 Err(err) => eprintln!("获取令牌时出错: {}", err), | ||||
|             } | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 wisdgod
					wisdgod