diff --git a/Cargo.lock b/Cargo.lock index 63aa6590..081e4797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ "cpp_demangle", "fallible-iterator", @@ -24,9 +24,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991984e3fd003e7ba02eb724f87a0f997b78677c46c0e91f8424ad7394c9886a" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ "getrandom", "once_cell", @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" [[package]] name = "arrayvec" @@ -85,44 +85,30 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01" +checksum = "321629d8ba6513061f26707241fa9bc89524ff1cd7a915a97ef0c62c666ce1b6" dependencies = [ "addr2line", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", ] -[[package]] -name = "benfred-read-process-memory" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ba08144670324a93f7b6502ff6ca679bfd1efa5230c4efff49801714b3854a" -dependencies = [ - "kernel32-sys", - "libc", - "log", - "mach", - "winapi 0.2.8", -] - [[package]] name = "bindgen" -version = "0.53.3" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c72a978d268b1d70b0e963217e60fdabd9523a941457a6c42a7315d15c7e89e5" +checksum = "453c49e5950bb0eb63bb3df640e31618846c89d5b7faa54040d76e98e0134375" dependencies = [ "bitflags", "cexpr", - "cfg-if 0.1.10", "clang-sys", "clap", - "env_logger 0.7.1", + "env_logger 0.8.4", "lazy_static", "lazycell", "log", @@ -141,6 +127,18 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitvec" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "bytemuck" version = "1.7.2" @@ -149,25 +147,19 @@ checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" [[package]] name = "cc" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cexpr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +checksum = "db507a7679252d2276ed0dd8113c6875ec56d3089f9225b2b42c30cc1f8e5c89" dependencies = [ "nom", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -189,9 +181,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "0.29.3" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a" +checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" dependencies = [ "glob", "libc", @@ -216,13 +208,13 @@ dependencies = [ [[package]] name = "console" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" +checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" dependencies = [ "encode_unicode", - "lazy_static", "libc", + "once_cell", "regex", "terminal_size", "unicode-width", @@ -235,7 +227,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea47428dc9d2237f3c6bc134472edfd63ebba0af932e783506dcfd66f10d18a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -244,7 +236,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -253,7 +245,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -263,7 +255,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "lazy_static", ] @@ -283,7 +275,7 @@ version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "num_cpus", ] @@ -295,12 +287,12 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "env_logger" -version = "0.7.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", - "humantime 1.3.0", + "humantime", "log", "regex", "termcolor", @@ -313,7 +305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log", "regex", "termcolor", @@ -321,9 +313,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa68f2fb9cae9d37c9b2b3584aba698a2e97f72d7aef7b9f7aa71d8b54ce46fe" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", @@ -374,28 +366,34 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crc32fast", "libc", "miniz_oxide", ] +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + [[package]] name = "getrandom" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" dependencies = [ "fallible-iterator", "stable_deref_trait", @@ -445,15 +443,6 @@ dependencies = [ "libc", ] -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "humantime" version = "2.1.0" @@ -484,9 +473,9 @@ dependencies = [ [[package]] name = "inferno" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa5bd9a10b38bf5f3c670f9d75c194adbecd2b1573f737668ab8599f41edc87" +checksum = "d5e0d042b82d2153d831ad6f4b865ddb06d9941a086eb9974f8f58cf0368b6e3" dependencies = [ "ahash", "atty", @@ -536,17 +525,17 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" [[package]] name = "libloading" -version = "0.5.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0" dependencies = [ - "cc", + "cfg-if", "winapi 0.3.9", ] @@ -556,16 +545,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" -[[package]] -name = "libproc" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15fb50befee2d3be15b38c93ef79ba22ecbd667874bf692309ffdff179282b8d" -dependencies = [ - "errno", - "libc", -] - [[package]] name = "libproc" version = "0.10.0" @@ -582,7 +561,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -594,6 +573,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "mach" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196697f416cf23cf0d3319cf5b2904811b035c82df1dfec2117fb457699bf277" +dependencies = [ + "libc", +] + [[package]] name = "mach" version = "0.3.2" @@ -652,7 +640,7 @@ checksum = "f305c2c2e4c39a82f7bf0bf65fb557f9070ce06781d4f2454295cc34b1c43188" dependencies = [ "bitflags", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "memoffset", ] @@ -665,10 +653,12 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" [[package]] name = "nom" -version = "5.1.2" +version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" dependencies = [ + "bitvec", + "funty", "memchr", "version_check", ] @@ -721,9 +711,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.26.2" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" dependencies = [ "flate2", "memchr", @@ -749,9 +739,9 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" [[package]] name = "proc-macro-error" @@ -779,24 +769,24 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.30" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" dependencies = [ "unicode-xid", ] [[package]] name = "proc-maps" -version = "0.1.9" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54abe6d3c62735694c58def54d333b0023864993f9fc496dcf58efeefb7c2fa6" +checksum = "5d01e71493938bee4c460ec61aabbf0801e08cd2714d1677365b4d7f81475353" dependencies = [ "anyhow", "bindgen", "libc", - "libproc 0.9.1", - "mach", + "libproc", + "mach 0.3.2", "winapi 0.3.9", ] @@ -832,12 +822,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quick-xml" version = "0.22.0" @@ -856,6 +840,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + [[package]] name = "rand" version = "0.8.4" @@ -906,6 +896,19 @@ dependencies = [ "rand_core", ] +[[package]] +name = "read-process-memory" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "716f2d467d9040ec18a771e037e7533ea74c9bbd3a0911491855f37a59609f60" +dependencies = [ + "kernel32-sys", + "libc", + "log", + "mach 0.0.5", + "winapi 0.2.8", +] + [[package]] name = "redox_syscall" version = "0.2.10" @@ -934,23 +937,23 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "remoteprocess" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7317b44be29693113188afb1b9f3e9f11edf923043cdbbda38915e3e4d9e4196" +checksum = "e1235aa3cb32fd5d4e56c9de8560ab57095dd8528be2158360f044255946e091" dependencies = [ "addr2line", - "benfred-read-process-memory", "goblin", "lazy_static", "libc", - "libproc 0.10.0", + "libproc", "log", - "mach", + "mach 0.3.2", "mach_o_sys", "memmap", "nix", "object", "proc-maps", + "read-process-memory", "regex", "winapi 0.3.9", ] @@ -966,9 +969,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.27" +version = "0.8.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fddb3b23626145d1776addfc307e1a1851f60ef6ca64f376bcb889697144cf0" +checksum = "a27fa03bb1e3e2941f52d4a555a395a72bf79b0a85fbbaab79447050c97d978c" dependencies = [ "bytemuck", ] @@ -1030,9 +1033,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8" dependencies = [ "itoa", "ryu", @@ -1041,9 +1044,9 @@ dependencies = [ [[package]] name = "shlex" -version = "0.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "smallvec" @@ -1071,9 +1074,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" dependencies = [ "clap", "lazy_static", @@ -1082,9 +1085,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.16" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error", @@ -1095,9 +1098,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" dependencies = [ "proc-macro2", "quote", @@ -1116,13 +1119,19 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "rand", "redox_syscall", @@ -1276,3 +1285,9 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/Cargo.toml b/Cargo.toml index 0054a9df..d185cff4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition="2018" [dependencies] clap = {version="2", features=["wrap_help"]} -console = "0.14" +console = "0.15" ctrlc = "3" indicatif = "0.16" env_logger = "0.9" @@ -26,7 +26,7 @@ log = "0.4" lru = "0.7" regex = "1" tempfile = "3.0.3" -proc-maps = "0.1.9" +proc-maps = "0.2.0" memmap = "0.7.0" cpp_demangle = "0.3" serde = {version="1.0", features=["rc"]} @@ -34,7 +34,7 @@ serde_derive = "1.0" serde_json = "1.0" rand = "0.8" rand_distr = "0.4" -remoteprocess = {version="0.4.6", features=["unwind"]} +remoteprocess = {version="0.4.7", features=["unwind"]} chrono = "0.4.19" [target.'cfg(unix)'.dependencies] diff --git a/src/binary_parser.rs b/src/binary_parser.rs index 357101f4..8ea590b8 100644 --- a/src/binary_parser.rs +++ b/src/binary_parser.rs @@ -9,7 +9,7 @@ use goblin::Object; use memmap::Mmap; pub struct BinaryInfo { - pub filename: String, + pub filename: std::path::PathBuf, pub symbols: HashMap, pub bss_addr: u64, pub bss_size: u64, @@ -26,23 +26,23 @@ impl BinaryInfo { } /// Uses goblin to parse a binary file, returns information on symbols/bss/adjusted offset etc -pub fn parse_binary(_pid: remoteprocess::Pid, filename: &str, addr: u64, size: u64, _is_bin: bool) -> Result { +pub fn parse_binary(_pid: remoteprocess::Pid, filename: &Path, addr: u64, size: u64, _is_bin: bool) -> Result { // on linux the process could be running in docker, access the filename through procfs // if filename is the binary executable (not libpython) - take it from /proc/pid/exe, which works // across namespaces just like /proc/pid/root, and also if the file was deleted. #[cfg(target_os="linux")] - let filename = &if _is_bin { + let filename = &std::path::PathBuf::from(&if _is_bin { format!("/proc/{}/exe", _pid) } else { - format!("/proc/{}/root{}", _pid, filename) - }; + format!("/proc/{}/root{}", _pid, filename.display()) + }); let offset = addr; let mut symbols = HashMap::new(); // Read in the filename - let file = File::open(Path::new(filename))?; + let file = File::open(filename)?; let buffer = unsafe { Mmap::map(&file)? }; // Use goblin to parse the binary @@ -57,7 +57,7 @@ pub fn parse_binary(_pid: remoteprocess::Pid, filename: &str, addr: u64, size: u Ok(arch) => arch.is_64(), Err(_) => false } - ).ok_or_else(|| format_err!("Failed to find 64 bit arch in FAT archive in {}", filename))??; + ).ok_or_else(|| format_err!("Failed to find 64 bit arch in FAT archive in {}", filename.display()))??; let bytes = &buffer[arch.offset as usize..][..arch.size as usize]; goblin::mach::MachO::parse(bytes, 0)? } @@ -92,14 +92,14 @@ pub fn parse_binary(_pid: remoteprocess::Pid, filename: &str, addr: u64, size: u let bss_header = elf.section_headers .iter() .find(|ref header| header.sh_type == goblin::elf::section_header::SHT_NOBITS) - .ok_or_else(|| format_err!("Failed to find BSS section header in {}", filename))?; + .ok_or_else(|| format_err!("Failed to find BSS section header in {}", filename.display()))?; let program_header = elf.program_headers .iter() .find(|ref header| header.p_type == goblin::elf::program_header::PT_LOAD && header.p_flags & goblin::elf::program_header::PF_X != 0) - .ok_or_else(|| format_err!("Failed to find executable PT_LOAD program header in {}", filename))?; + .ok_or_else(|| format_err!("Failed to find executable PT_LOAD program header in {}", filename.display()))?; // p_vaddr may be larger than the map address in case when the header has an offset and // the map address is relatively small. In this case we can default to 0. @@ -131,7 +131,7 @@ pub fn parse_binary(_pid: remoteprocess::Pid, filename: &str, addr: u64, size: u pe.sections .iter() .find(|ref section| section.name.starts_with(b".data")) - .ok_or_else(|| format_err!("Failed to find .data section in PE binary of {}", filename)) + .ok_or_else(|| format_err!("Failed to find .data section in PE binary of {}", filename.display())) .map(|data_section| { let bss_addr = u64::from(data_section.virtual_address) + offset; let bss_size = u64::from(data_section.virtual_size); diff --git a/src/python_spy.rs b/src/python_spy.rs index 90127110..d3ce67a5 100644 --- a/src/python_spy.rs +++ b/src/python_spy.rs @@ -34,7 +34,7 @@ pub struct PythonSpy { pub version: Version, pub interpreter_address: usize, pub threadstate_address: usize, - pub python_filename: String, + pub python_filename: std::path::PathBuf, pub version_string: String, pub config: Config, #[cfg(unwind)] @@ -558,7 +558,7 @@ fn get_python_version(python_info: &PythonProcessInfo, process: &remoteprocess:: // the python_filename might have the version encoded in it (/usr/bin/python3.5 etc). // try reading that in (will miss patch level on python, but that shouldn't matter) - info!("Trying to get version from path: {}", python_info.python_filename); + info!("Trying to get version from path: {}", python_info.python_filename.display()); let path = Path::new(&python_info.python_filename); if let Some(python) = path.file_name() { if let Some(python) = python.to_str() { @@ -716,7 +716,7 @@ pub struct PythonProcessInfo { // be in a libpython.so file instead of the executable. support that. libpython_binary: Option, maps: Vec, - python_filename: String, + python_filename: std::path::PathBuf, #[cfg(target_os="linux")] dockerized: bool, } @@ -728,6 +728,7 @@ impl PythonProcessInfo { #[cfg(windows)] let filename = filename.to_lowercase(); + #[cfg(windows)] let is_python_bin = |pathname: &str| pathname.to_lowercase() == filename; @@ -740,16 +741,19 @@ impl PythonProcessInfo { for map in &maps { debug!("map: {:016x}-{:016x} {}{}{} {}", map.start(), map.start() + map.size(), if map.is_read() {'r'} else {'-'}, if map.is_write() {'w'} else {'-'}, if map.is_exec() {'x'} else {'-'}, - map.filename().as_ref().unwrap_or(&"".to_owned())); + map.filename().unwrap_or(&std::path::PathBuf::from("")).display()); } // parse the main python binary let (python_binary, python_filename) = { // Get the memory address for the executable by matching against virtual memory maps let map = maps.iter() - .find(|m| if let Some(pathname) = &m.filename() { - is_python_bin(pathname) && m.is_exec() - } else { + .find(|m| { + if let Some(pathname) = m.filename() { + if let Some(pathname) = pathname.to_str() { + return is_python_bin(pathname) && m.is_exec(); + } + } false }); @@ -764,6 +768,8 @@ impl PythonProcessInfo { } }; + let filename = std::path::PathBuf::from(filename); + // TODO: consistent types? u64 -> usize? for map.start etc #[allow(unused_mut)] let python_binary = parse_binary(process.pid, &filename, map.start() as u64, map.size() as u64, true) @@ -800,16 +806,19 @@ impl PythonProcessInfo { // likewise handle libpython for python versions compiled with --enabled-shared let libpython_binary = { let libmap = maps.iter() - .find(|m| if let Some(ref pathname) = &m.filename() { - is_python_lib(pathname) && m.is_exec() - } else { + .find(|m| { + if let Some(pathname) = m.filename() { + if let Some(pathname) = pathname.to_str() { + return is_python_lib(pathname) && m.is_exec(); + } + } false }); let mut libpython_binary: Option = None; if let Some(libpython) = libmap { if let Some(filename) = &libpython.filename() { - info!("Found libpython binary @ {}", filename); + info!("Found libpython binary @ {}", filename.display()); #[allow(unused_mut)] let mut parsed = parse_binary(process.pid, filename, libpython.start() as u64, libpython.size() as u64, false)?; #[cfg(windows)] @@ -831,15 +840,21 @@ impl PythonProcessInfo { let segname = unsafe { std::ffi::CStr::from_ptr(dyld.segment.segname.as_ptr()) }; debug!("dyld: {:016x}-{:016x} {:10} {}", dyld.segment.vmaddr, dyld.segment.vmaddr + dyld.segment.vmsize, - segname.to_string_lossy(), dyld.filename); + segname.to_string_lossy(), dyld.filename.display()); } let python_dyld_data = dyld_infos.iter() - .find(|m| is_python_framework(&m.filename) && - m.segment.segname[0..7] == [95, 95, 68, 65, 84, 65, 0]); + .find(|m| { + if let Some(filename) = m.filename.to_str() { + return is_python_framework(filename) && + m.segment.segname[0..7] == [95, 95, 68, 65, 84, 65, 0]; + } + false + }); + if let Some(libpython) = python_dyld_data { - info!("Found libpython binary from dyld @ {}", libpython.filename); + info!("Found libpython binary from dyld @ {}", libpython.filename.display()); let mut binary = parse_binary(process.pid, &libpython.filename, libpython.segment.vmaddr, libpython.segment.vmsize, false)?; @@ -901,7 +916,7 @@ fn is_dockerized(pid: Pid) -> Result { // So use the win32 api to load up the couple of symbols we need on windows. Note: // we still can get export's from the PE file #[cfg(windows)] -pub fn get_windows_python_symbols(pid: Pid, filename: &str, offset: u64) -> std::io::Result> { +pub fn get_windows_python_symbols(pid: Pid, filename: &Path, offset: u64) -> std::io::Result> { use proc_maps::win_maps::SymbolLoader; let handler = SymbolLoader::new(pid)?;