diff --git a/Cargo.lock b/Cargo.lock index 37bbc74..3a9fa94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -175,6 +184,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "build-helper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f" +dependencies = [ + "semver", +] + [[package]] name = "bumpalo" version = "3.17.0" @@ -210,9 +228,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.16" +version = "1.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +checksum = "525046617d8376e3db1deffb079e91cef90a89fc3ca5c185bbf8c9ecdd15cd5c" dependencies = [ "shlex", ] @@ -239,18 +257,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.32" +version = "4.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" +checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.32" +version = "4.5.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" +checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9" dependencies = [ "anstream", "anstyle", @@ -359,9 +377,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.10" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" dependencies = [ "darling_core", "darling_macro", @@ -369,9 +387,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.10" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" dependencies = [ "fnv", "ident_case", @@ -383,9 +401,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.10" +version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core", "quote", @@ -427,9 +445,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", "windows-sys 0.59.0", @@ -461,9 +479,9 @@ checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1" [[package]] name = "flate2" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" dependencies = [ "crc32fast", "miniz_oxide", @@ -477,9 +495,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foldhash" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "generic-array" @@ -542,14 +560,15 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.61" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", + "log", "wasm-bindgen", "windows-core", ] @@ -580,9 +599,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", "hashbrown", @@ -721,6 +740,19 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "libunicorn-sys" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af5b000b833bfe0aebed3ac6fd18cec9e657deb372540f82e2d74da164253a6b" +dependencies = [ + "bitflags 1.3.2", + "build-helper", + "libc", + "os_type", + "pkg-config", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -739,9 +771,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "lru" @@ -771,9 +803,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.8.5" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430" dependencies = [ "adler2", ] @@ -815,9 +847,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "opaque-debug" @@ -825,6 +857,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "os_type" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e24d44c0eea30167516ed8f6daca4b5e3eebcde1bde1e4e6e08b809fb02c7ba5" +dependencies = [ + "regex", +] + [[package]] name = "palette" version = "0.7.6" @@ -1058,13 +1099,42 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" dependencies = [ "bitflags 2.9.0", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1111,6 +1181,21 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.219" @@ -1212,9 +1297,9 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "smallvec" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" [[package]] name = "static_assertions" @@ -1285,7 +1370,7 @@ dependencies = [ [[package]] name = "tek_jack" version = "0.2.0" -source = "git+https://codeberg.org/unspeaker/tek#6a43cea61dc87e1635f7b0a96567adb21d3c63d4" +source = "git+https://codeberg.org/unspeaker/tek#98d56e70092f1eccfb70bfd057258f02f8d00fe1" dependencies = [ "jack", ] @@ -1413,6 +1498,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +[[package]] +name = "unicorn" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbc59d3e610b68f79d11e2252fd7a4205237c23c8d5eb1fbe79c53d8faf0e16" +dependencies = [ + "bitflags 1.3.2", + "libc", + "libunicorn-sys", +] + [[package]] name = "utf8parse" version = "0.2.2" @@ -1430,7 +1526,6 @@ name = "vestal" version = "0.1.0" dependencies = [ "binary-layout", - "clap", "exe", "hexy", "iced-x86", @@ -1442,7 +1537,22 @@ dependencies = [ ] [[package]] -name = "vestal_wrapper" +name = "vestal_cli" +version = "0.1.0" +dependencies = [ + "clap", + "vestal", +] + +[[package]] +name = "vestal_emu" +version = "0.1.0" +dependencies = [ + "unicorn", +] + +[[package]] +name = "vestal_wrap" version = "0.1.0" dependencies = [ "tek_jack", @@ -1524,9 +1634,9 @@ dependencies = [ [[package]] name = "widestring" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" +checksum = "dd7cf3379ca1aac9eea11fba24fd7e315d621f8dfe35c8d7d2be8b793726e07d" [[package]] name = "winapi" @@ -1552,18 +1662,62 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.52.0" +version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" dependencies = [ - "windows-targets", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", ] [[package]] name = "windows-link" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +dependencies = [ + "windows-link", +] [[package]] name = "windows-sys" @@ -1649,18 +1803,18 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "zerocopy" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd97444d05a4328b90e75e503a34bad781f14e28a823ad3557f0750df1ebcbc6" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 3ab8eea..34526c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,19 @@ +[workspace.package] +version = "0.1.0" +edition = "2024" + [workspace] resolver = "2" members = [ - "vestal", - "wrapper" + "cli", + "core", + "emu", + "wrap" ] + +[profile.release] +lto = true + +[profile.coverage] +inherits = "test" +lto = false diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..7c46cc1 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vestal_cli" +version = { workspace = true } +edition = { workspace = true } + +[dependencies] +vestal = { path = "../core" } +clap = { version = "4.5.4", features = [ "cargo" ] } diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..4d5dba5 --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,36 @@ +use std::sync::Arc; +use std::path::PathBuf; +use std::fs::canonicalize; +use clap::{arg, command, value_parser}; +use vestal::Module; + +/// Define command line arguments. +fn cli () -> clap::Command { + command!() + .arg(arg!([path] "Path to VST DLL").value_parser(value_parser!(PathBuf))) + //.arg(arg!(-s --stub "Provide a stub import").required(false)) + .arg(arg!(-i --inspect "Show info, don't run").required(false)) + .arg(arg!(-v --verbose "Show a lot of info").required(false)) +} + +fn main () -> Result<(), Box> { + // Parse command line arguments. + let args = cli().get_matches(); + if let Some(path) = args.get_one::("path") { + Module::from_path(path, *(args.get_one::("verbose").unwrap_or(&false))) + .map(Arc::new) + .unwrap_or_else(|e|panic!("failed to open: {e:?}")) + .search(std::env::current_dir()?) + .search(canonicalize(path.clone().parent().expect("invalid parent path"))?) + .search("/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32") + .load(true) + .unwrap_or_else(|e|panic!("failed to load: {e:?}")) + .resolve(true) + .unwrap_or_else(|e|panic!("failed to resolve: {e:?}")) + .relink() + .unwrap_or_else(|e|panic!("failed to relink: {e:?}")); + } else { + println!("Pass a path to a VST DLL"); + } + Ok(()) +} diff --git a/vestal/Cargo.toml b/core/Cargo.toml similarity index 79% rename from vestal/Cargo.toml rename to core/Cargo.toml index 984e243..bc722ad 100644 --- a/vestal/Cargo.toml +++ b/core/Cargo.toml @@ -1,13 +1,12 @@ [package] -name = "vestal" -version = "0.1.0" -edition = "2021" +name = "vestal" +version = { workspace = true } +edition = { workspace = true } [dependencies] tengri = { git = "https://codeberg.org/unspeaker/tengri", rev = "877b344765" } binary-layout = "4.0.2" -clap = { version = "4.5.4", features = [ "cargo" ] } exe = "0.5.6" hexy = "0.1.4" iced-x86 = "1.21.0" diff --git a/vestal/src/bang.rs b/core/src/bang.rs similarity index 100% rename from vestal/src/bang.rs rename to core/src/bang.rs diff --git a/vestal/src/call_sites.rs b/core/src/call_sites.rs similarity index 100% rename from vestal/src/call_sites.rs rename to core/src/call_sites.rs diff --git a/vestal/src/elf.rs b/core/src/elf.rs similarity index 100% rename from vestal/src/elf.rs rename to core/src/elf.rs diff --git a/vestal/src/exec.rs b/core/src/exec.rs similarity index 100% rename from vestal/src/exec.rs rename to core/src/exec.rs diff --git a/vestal/src/exports.rs b/core/src/exports.rs similarity index 100% rename from vestal/src/exports.rs rename to core/src/exports.rs diff --git a/vestal/src/imports.rs b/core/src/imports.rs similarity index 100% rename from vestal/src/imports.rs rename to core/src/imports.rs diff --git a/vestal/src/main.rs b/core/src/lib.rs similarity index 79% rename from vestal/src/main.rs rename to core/src/lib.rs index 096f471..73d2354 100644 --- a/vestal/src/main.rs +++ b/core/src/lib.rs @@ -8,15 +8,6 @@ mod imports; pub(crate) use self::imports::*; mod exports; pub(crate) use self::exports::*; mod call_sites; pub(crate) use self::call_sites::*; mod bang; -/// Define command line arguments. -fn cli () -> clap::Command { - use clap::{arg, command, value_parser, ArgAction, Command}; - command!() - .arg(arg!([path] "Path to VST DLL").value_parser(value_parser!(PathBuf))) - //.arg(arg!(-s --stub "Provide a stub import").required(false)) - .arg(arg!(-i --inspect "Show info, don't run").required(false)) - .arg(arg!(-v --verbose "Show a lot of info").required(false)) -} /// A DLL that will be linked into the output. pub struct Module { /// Scope. @@ -70,35 +61,13 @@ pub struct CallSite { /// Name of method that is being called pub method: Option>, } -fn main () -> Usually<()> { - use clap::{arg, command, value_parser, ArgAction, Command}; - // Parse command line arguments. - let args = cli().get_matches(); - if let Some(path) = args.get_one::("path") { - Module::from_path(path, *(args.get_one::("verbose").unwrap_or(&false))) - .map(Arc::new) - .unwrap_or_else(|e|panic!("failed to open: {e:?}")) - .search(std::env::current_dir()?) - .search(canonicalize(path.clone().parent().expect("invalid parent path"))?) - .search("/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32") - .load(true) - .unwrap_or_else(|e|panic!("failed to load: {e:?}")) - .resolve(true) - .unwrap_or_else(|e|panic!("failed to resolve: {e:?}")) - .relink() - .unwrap_or_else(|e|panic!("failed to relink: {e:?}")); - } else { - println!("Pass a path to a VST DLL"); - } - Ok(()) -} impl Module { /// Construct a cross-linkable library. /// /// Loads the PE but does not /// extract any imports/exports/callsites. /// For that, invoke the [Module::load] method. - fn from_path (path: impl AsRef, verbose: bool) -> Usually { + pub fn from_path (path: impl AsRef, verbose: bool) -> Usually { Log::load(verbose, &path); let (pe, data, bang) = read_pe(&path)?; let (code, code_start, code_size) = read_code(&pe)?; @@ -126,13 +95,13 @@ impl Module { }) } /// Add a search path - fn search (self: Arc, path: impl AsRef) -> Arc { + pub fn search (self: Arc, path: impl AsRef) -> Arc { Log::add(self.verbose, &path); self.search_paths.write().unwrap().insert(path.as_ref().to_path_buf().into()); self } /// Search for DLL by name in search paths. - fn find (&self, name: &impl AsRef) -> Usually> { + pub fn find (&self, name: &impl AsRef) -> Usually> { let name = name.as_ref(); for base in self.search_paths.read().unwrap().iter() { let mut path = base.as_ref().clone(); @@ -146,7 +115,7 @@ impl Module { Ok(None) } /// Load the dependency tree reachable from this module. - fn load (self: Arc, recurse: bool) -> Usually> { + pub fn load (self: Arc, recurse: bool) -> Usually> { let module = self.load_exports()?; let module = module.load_imports(recurse)?; if module.verbose { @@ -155,7 +124,7 @@ impl Module { Ok(module) } /// Identify call sites and try to match them with their new locations. - fn resolve (self: Arc, recurse: bool) -> Usually> { + pub fn resolve (self: Arc, recurse: bool) -> Usually> { let module = self.load_call_sites(recurse)?; if module.verbose { println!("{:?}", &module); @@ -163,7 +132,7 @@ impl Module { Ok(module) } /// Build an ELF executable out of the DLL - fn relink (self: Arc) -> Usually> { + pub fn relink (self: Arc) -> Usually> { let page = 32*1024; let mut size = 0; for module in self.namespace.read().unwrap().values() { diff --git a/vestal/src/show.rs b/core/src/show.rs similarity index 94% rename from vestal/src/show.rs rename to core/src/show.rs index 2062b95..7b54c37 100644 --- a/vestal/src/show.rs +++ b/core/src/show.rs @@ -128,7 +128,7 @@ impl Module { print!(" {style}{:26}{RESET}", fmt_bytes(&self.code[addr..addr+instruction.len()])); println!(" {style}{instruction}{RESET}"); } - pub fn show_call_site (&self, addr: usize, length: usize, context: usize) { + pub fn show_call_site (&self, addr: usize, length: usize, context: usize) -> Usually<()> { let base = self.code_base as usize; let line = 16; let group = 2; @@ -137,41 +137,42 @@ impl Module { let byte_end = snap(addr) + (context + 1) * line; let mut output = String::new(); for (index, byte) in (byte_start..byte_end).enumerate() { - write!(&mut output, "{DIM}"); + write!(&mut output, "{DIM}")?; if byte % line == 0 { if (byte >= snap(addr)) && (byte < snap(addr) + line) { - write!(&mut output, "{RESET}╭─"); + write!(&mut output, "{RESET}╭─")?; } else if byte >= snap(addr) + line { - write!(&mut output, "┊ "); + write!(&mut output, "┊ ")?; } else { - write!(&mut output, " "); + write!(&mut output, " ")?; } - write!(&mut output, "{:08x}", byte + base); + write!(&mut output, "{:08x}", byte + base)?; } - write!(&mut output, "{DIM}"); + write!(&mut output, "{DIM}")?; if (byte >= addr) && (byte < addr + length) { - write!(&mut output, "{RESET}{BOLD}{INVERT}"); + write!(&mut output, "{RESET}{BOLD}{INVERT}")?; } if byte % group == 0 { if byte == addr { - write!(&mut output, "{}", "▌"); + write!(&mut output, "{}", "▌")?; } else if byte == addr + length { - write!(&mut output, "{RESET}{BOLD}{INVERT}▐{RESET}{DIM}"); + write!(&mut output, "{RESET}{BOLD}{INVERT}▐{RESET}{DIM}")?; } else { - write!(&mut output, "{}", " "); + write!(&mut output, "{}", " ")?; } } - write!(&mut output, "{:02x}", self.code[byte]); - write!(&mut output, "{RESET}"); + write!(&mut output, "{:02x}", self.code[byte])?; + write!(&mut output, "{RESET}")?; if byte % line == line - 1 { if snap(byte) == snap(addr) { let dasm = Show::link_dasm(&self.code[addr..], addr); write!(&mut output, " -> {dasm}"); } - write!(&mut output, " \n"); + write!(&mut output, " \n")?; } } print!("{output}"); + Ok(()) } } impl CallSite { diff --git a/vestal/src/util.rs b/core/src/util.rs similarity index 100% rename from vestal/src/util.rs rename to core/src/util.rs diff --git a/emu/Cargo.toml b/emu/Cargo.toml new file mode 100644 index 0000000..a5b55ac --- /dev/null +++ b/emu/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "vestal_emu" +version = { workspace = true } +edition = { workspace = true } + +[dependencies] +unicorn = "0.9.1" diff --git a/wrapper/src/host.rs b/emu/src/lib.rs similarity index 100% rename from wrapper/src/host.rs rename to emu/src/lib.rs diff --git a/shell.nix b/shell.nix index 78aa3b9..7daf29a 100755 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,7 @@ #dontStrip = true; separateDebugInfo = true; #})); in pkgs.mkShell { + name = "vestal-devshell"; nativeBuildInputs = with pkgs; [ pkg-config freetype @@ -11,6 +12,7 @@ in pkgs.mkShell { #bear ]; buildInputs = with pkgs; [ + unicorn jack2 lilv serd @@ -22,6 +24,7 @@ in pkgs.mkShell { VST3_SDK_DIR = "/home/user/Lab/Music/tek/vst3sdk/"; LIBCLANG_PATH = "${pkgs.libclang.lib.outPath}/lib"; LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [ + unicorn pipewire.jack # for ChowKick.lv2: freetype diff --git a/wrapper/Cargo.toml b/wrap/Cargo.toml similarity index 69% rename from wrapper/Cargo.toml rename to wrap/Cargo.toml index dc2e77b..e707340 100644 --- a/wrapper/Cargo.toml +++ b/wrap/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "vestal_wrapper" -version = "0.1.0" -edition = "2021" +name = "vestal_wrap" +version = { workspace = true } +edition = { workspace = true } [lib] crate-type = ["staticlib"] diff --git a/wrap/src/host.rs b/wrap/src/host.rs new file mode 100644 index 0000000..e69de29 diff --git a/wrapper/src/lib.rs b/wrap/src/lib.rs similarity index 98% rename from wrapper/src/lib.rs rename to wrap/src/lib.rs index c3a0961..20c2832 100644 --- a/wrapper/src/lib.rs +++ b/wrap/src/lib.rs @@ -5,7 +5,7 @@ pub(crate) struct Host(pub Jack); audio!(|self: Host, _c, _s|Control::Continue); -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn main (argc: usize, argv: usize) -> usize { let plugin = run(); let jack = Jack::new("vestal") @@ -27,7 +27,7 @@ unsafe extern "C" { fn VSTPluginMain (callback: *mut MainCallback) -> *mut Plugin; } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn main_callback ( effect: *mut Plugin, opcode: i32, diff --git a/wrapper/src/nih.rs b/wrap/src/nih.rs similarity index 100% rename from wrapper/src/nih.rs rename to wrap/src/nih.rs diff --git a/wrapper/src/vst2.rs b/wrap/src/vst2.rs similarity index 100% rename from wrapper/src/vst2.rs rename to wrap/src/vst2.rs