Fix parsing of symbol table

This commit is contained in:
2024-02-10 17:08:34 +01:00
parent 7a8554d313
commit ff9bda49c2
6 changed files with 880 additions and 111 deletions

665
Cargo.lock generated
View File

@@ -17,6 +17,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.11" version = "0.6.11"
@@ -65,6 +74,18 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.69" version = "0.3.69"
@@ -80,6 +101,27 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "binary-merge"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597bb81c80a54b6a4381b23faba8d7774b144c94cbd1d6fe3f1329bd776554ab"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "brownstone"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5839ee4f953e811bfdcf223f509cb2c6a3e1447959b0bff459405575bc17f22"
dependencies = [
"arrayvec",
]
[[package]] [[package]]
name = "bytecheck" name = "bytecheck"
version = "0.6.11" version = "0.6.11"
@@ -122,6 +164,12 @@ dependencies = [
"syn 2.0.48", "syn 2.0.48",
] ]
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.83" version = "1.0.83"
@@ -210,6 +258,55 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "cpp_demangle"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8227005286ec39567949b33df9896bcadfa6051bccca2488129f108ca23119"
dependencies = [
"cfg-if",
]
[[package]]
name = "crc32fast"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "debugid"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d"
dependencies = [
"serde",
"uuid",
]
[[package]]
name = "dmsort"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0bc8fbe9441c17c9f46f75dfe27fa1ddb6c68a461ccaed0481419219d4f10d3"
[[package]]
name = "elementtree"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3efd4742acf458718a6456e0adf0b4d734d6b783e452bbf1ac36bf31f4085cb3"
dependencies = [
"string_cache",
]
[[package]] [[package]]
name = "elf" name = "elf"
version = "0.1.0" version = "0.1.0"
@@ -222,8 +319,24 @@ dependencies = [
"rend", "rend",
"serde", "serde",
"serde_json", "serde_json",
"symbolic",
] ]
[[package]]
name = "elsa"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d98e71ae4df57d214182a2e5cb90230c0192c6ddfcaa05c36453d46a54713e10"
dependencies = [
"stable_deref_trait",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]] [[package]]
name = "eyre" name = "eyre"
version = "0.6.11" version = "0.6.11"
@@ -234,6 +347,28 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "fallible-iterator"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "fallible-iterator"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
[[package]]
name = "flate2"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.12" version = "0.2.12"
@@ -250,6 +385,27 @@ name = "gimli"
version = "0.28.1" version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
dependencies = [
"fallible-iterator 0.3.0",
"stable_deref_trait",
]
[[package]]
name = "goblin"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27c1b4369c2cd341b5de549380158b105a04c331be5db9110eef7b6d2742134"
dependencies = [
"log",
"plain",
"scroll",
]
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]] [[package]]
name = "heck" name = "heck"
@@ -257,36 +413,110 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "indent_write"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cfe9645a18782869361d9c8732246be7b410ad4e919d3609ebabdac00ba12c3"
[[package]] [[package]]
name = "indenter" name = "indenter"
version = "0.3.3" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "inplace-vec-builder"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf64c2edc8226891a71f127587a2861b132d2b942310843814d5001d99a1d307"
dependencies = [
"smallvec",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.10" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]]
name = "joinery"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72167d68f5fce3b8655487b8038691a3c9984ee769590f93f2a631f4ad64e4f5"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "leb128"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.152" version = "0.2.152"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "maybe-owned"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.1" version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "memmap2"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322"
dependencies = [
"libc",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.1" version = "0.7.1"
@@ -296,6 +526,44 @@ dependencies = [
"adler", "adler",
] ]
[[package]]
name = "msvc-demangler"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb67c6dd0fa9b00619c41c5700b6f92d5f418be49b45ddb9970fbd4569df3c8"
dependencies = [
"bitflags",
]
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "nom-supreme"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bd3ae6c901f1959588759ff51c95d24b491ecb9ff91aa9c2ef4acc5b1dcab27"
dependencies = [
"brownstone",
"indent_write",
"joinery",
"memchr",
"nom",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.32.2" version = "0.32.2"
@@ -317,18 +585,87 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
[[package]]
name = "pdb"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82040a392923abe6279c00ab4aff62d5250d1c8555dc780e4b02783a7aa74863"
dependencies = [
"fallible-iterator 0.2.0",
"scroll",
"uuid",
]
[[package]]
name = "pdb-addr2line"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4e89a9f2f40b2389ba6da0814c8044bf942bece03dffa1514f84e3b525f4f9a"
dependencies = [
"bitflags",
"elsa",
"maybe-owned",
"pdb",
"range-collections",
"thiserror",
]
[[package]]
name = "phf_shared"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
dependencies = [
"siphasher",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.13" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.17" version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "precomputed-hash"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.78" version = "1.0.78"
@@ -397,6 +734,55 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "range-collections"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61fdfd79629e2b44a1d34b4d227957174cb858e6b86ee45fad114edbcfc903ab"
dependencies = [
"binary-merge",
"inplace-vec-builder",
"smallvec",
]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]] [[package]]
name = "rend" name = "rend"
version = "0.4.1" version = "0.4.1"
@@ -419,6 +805,38 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "scroll"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da"
dependencies = [
"scroll_derive",
]
[[package]]
name = "scroll_derive"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "semver"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.196" version = "1.0.196"
@@ -465,12 +883,128 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a"
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "smallvec"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "string_cache"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b"
dependencies = [
"new_debug_unreachable",
"once_cell",
"parking_lot",
"phf_shared",
"precomputed-hash",
"serde",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "symbolic"
version = "12.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ec4f53c56d7ee8809c2322925d362e193bcc7bbe7e777a3304b34ea7e85a36"
dependencies = [
"symbolic-common",
"symbolic-debuginfo",
"symbolic-demangle",
]
[[package]]
name = "symbolic-common"
version = "12.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cccfffbc6bb3bb2d3a26cd2077f4d055f6808d266f9d4d158797a4c60510dfe"
dependencies = [
"debugid",
"memmap2",
"stable_deref_trait",
"uuid",
]
[[package]]
name = "symbolic-debuginfo"
version = "12.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb52777be67777947c5a159f1b6e8bfe4473d91fad7e5d4aff85ee4d3963cc04"
dependencies = [
"debugid",
"dmsort",
"elementtree",
"elsa",
"fallible-iterator 0.3.0",
"flate2",
"gimli",
"goblin",
"lazy_static",
"nom",
"nom-supreme",
"once_cell",
"parking_lot",
"pdb-addr2line",
"regex",
"scroll",
"serde",
"serde_json",
"smallvec",
"symbolic-common",
"symbolic-ppdb",
"thiserror",
"wasmparser",
"zip",
]
[[package]]
name = "symbolic-demangle"
version = "12.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a99812da4020a67e76c4eb41f08c87364c14170495ff780f30dd519c221a68"
dependencies = [
"cc",
"cpp_demangle",
"msvc-demangler",
"rustc-demangle",
"symbolic-common",
]
[[package]]
name = "symbolic-ppdb"
version = "12.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dace84623ccc926886fc880c36e2a81af4b17f8276abc4d77dc947ca3c6c8f8c"
dependencies = [
"flate2",
"indexmap",
"serde",
"serde_json",
"symbolic-common",
"thiserror",
"uuid",
"watto",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@@ -493,6 +1027,26 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "thiserror"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.1.7" version = "1.1.7"
@@ -556,6 +1110,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a"
[[package]] [[package]]
name = "valuable" name = "valuable"
version = "0.1.0" version = "0.1.0"
@@ -568,13 +1128,48 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasmparser"
version = "0.118.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9"
dependencies = [
"indexmap",
"semver",
]
[[package]]
name = "watto"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6746b5315e417144282a047ebb82260d45c92d09bf653fa9ec975e3809be942b"
dependencies = [
"leb128",
"thiserror",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [ dependencies = [
"windows-targets", "windows-targets 0.52.0",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
] ]
[[package]] [[package]]
@@ -583,53 +1178,107 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "windows_aarch64_gnullvm 0.52.0",
"windows_aarch64_msvc", "windows_aarch64_msvc 0.52.0",
"windows_i686_gnu", "windows_i686_gnu 0.52.0",
"windows_i686_msvc", "windows_i686_msvc 0.52.0",
"windows_x86_64_gnu", "windows_x86_64_gnu 0.52.0",
"windows_x86_64_gnullvm", "windows_x86_64_gnullvm 0.52.0",
"windows_x86_64_msvc", "windows_x86_64_msvc 0.52.0",
] ]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.0" version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "zip"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261"
dependencies = [
"byteorder",
"crc32fast",
"crossbeam-utils",
"flate2",
]

View File

@@ -14,3 +14,4 @@ rand = "0.8.5"
rend = { version = "0.4.1", features = ["bytemuck"] } rend = { version = "0.4.1", features = ["bytemuck"] }
serde = { version = "1.0.196", features = ["derive"] } serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113" serde_json = "1.0.113"
symbolic = { version = "12.8.0", features = ["demangle"] }

View File

@@ -11,8 +11,8 @@ pub struct BigEndian;
#[repr(C, packed)] #[repr(C, packed)]
pub struct LittleEndian; pub struct LittleEndian;
pub trait Decode: Copy { pub trait Decode: Copy + Zeroable + Pod {
type Native: Debug + Copy; type Native: Debug + Copy + TryInto<usize> + TryInto<u32> + Into<u64>;
fn to_native(self) -> Self::Native; fn to_native(self) -> Self::Native;
} }

View File

@@ -3,55 +3,43 @@ mod output;
mod structs; mod structs;
use crate::{ use crate::{
ints::BigEndian,
output::Output, output::Output,
structs::{ElfHeader1, ElfHeader2, SectionHeaderEntry, SymbolTableEntry}, structs::{
BigEndian32, BigEndian64, ElfConfig, ElfHeader1, ElfHeader2, LittleEndian32,
LittleEndian64, SectionHeaderEntry, SymbolTableEntry,
},
}; };
use bytemuck::from_bytes; use bytemuck::from_bytes;
use clap::{Parser, Subcommand}; use clap::Parser;
use core::str::from_utf8; use core::str::from_utf8;
use eyre::{bail, eyre, Context}; use eyre::{bail, eyre, Context};
use ints::{Decode, LittleEndian, U32, U64}; use ints::Decode;
use serde_json::Value; use serde_json::{json, Value};
use std::{fs, mem::size_of, path::PathBuf}; use std::{fs, mem::size_of, path::PathBuf};
use symbolic::demangle::demangle;
#[derive(Parser)] #[derive(Parser)]
struct Opt { struct Opt {
elf: PathBuf, elf: PathBuf,
#[clap(subcommand)]
command: Command,
} }
#[derive(Subcommand)]
enum Command {
/// List sections
Sections {},
/// List symbols
Symbols {
#[clap(short, long)]
section: String,
},
}
const HEADER1_LEN: usize = size_of::<ElfHeader1>(); const HEADER1_LEN: usize = size_of::<ElfHeader1>();
macro_rules! parse_elf { macro_rules! parse_elf {
($endian:ty, $word:ty, $out:expr, $header1:expr, $elf:expr) => {{ ($elfcfg:ty, $out:expr, $header1:expr, $elf:expr) => {{
//let header1 = $header1;
let out = $out; let out = $out;
const HEADER2_LEN: usize = size_of::<ElfHeader2<$endian, $word>>(); const HEADER2_LEN: usize = size_of::<ElfHeader2<$elfcfg>>();
let elf = $elf; let elf = $elf;
if elf.len() < HEADER1_LEN + HEADER2_LEN { if elf.len() < HEADER1_LEN + HEADER2_LEN {
bail!("not a valid elf file: file too small"); bail!("not a valid elf file: file too small");
} }
let header2: &[u8; HEADER2_LEN] = elf[HEADER1_LEN..][..HEADER2_LEN].try_into()?; let header2: &[u8; HEADER2_LEN] = elf[HEADER1_LEN..][..HEADER2_LEN].try_into()?;
let header2: ElfHeader2<$endian, $word> = *from_bytes(header2); let header2: ElfHeader2<$elfcfg> = *from_bytes(header2);
out.write("header2", &header2)?; out.write_append("header", &header2)?;
let e_shentsize = usize::from(header2.e_shentsize.to_native()); let e_shentsize = usize::from(header2.e_shentsize.to_native());
if e_shentsize != size_of::<SectionHeaderEntry<$endian, $word>>() { if e_shentsize != size_of::<SectionHeaderEntry<$elfcfg>>() {
bail!("wrong e_shentsize (0x{e_shentsize:x})"); bail!("wrong e_shentsize (0x{e_shentsize:x})");
} }
@@ -72,21 +60,18 @@ macro_rules! parse_elf {
(section_header_table_start..section_header_table_end).step_by(e_shentsize) (section_header_table_start..section_header_table_end).step_by(e_shentsize)
{ {
let entry = &elf[entry_start..][..e_shentsize]; let entry = &elf[entry_start..][..e_shentsize];
let entry: SectionHeaderEntry<$endian, $word> = *from_bytes(entry); let entry: SectionHeaderEntry<$elfcfg> = *from_bytes(entry);
section_header_entries.push(entry); section_header_entries.push(entry);
} }
out.write("section_table", &section_header_entries)?; out.write("sections", &section_header_entries)?;
let names_section_i = usize::from(header2.e_shstrndx.to_native()); let names_section_i = usize::from(header2.e_shstrndx.to_native());
let names_section_entry = &section_header_entries let names_section_entry = &section_header_entries
.get(names_section_i) .get(names_section_i)
.ok_or(eyre!("invalid e_shstrndx"))?; .ok_or(eyre!("invalid e_shstrndx"))?;
let names_section_start: usize = (names_section_entry.sh_offset.to_native().try_into()) let names_section_start: usize = names_section_entry.start()?;
.wrap_err("sh_offset bigger than usize")?; let names_section_end = names_section_entry.end()?;
let names_section_size: usize = (names_section_entry.sh_size.to_native().try_into())
.wrap_err("sh_size bigger than usize")?;
let names_section_end = names_section_start + names_section_size;
let names_section = &elf[names_section_start..names_section_end]; let names_section = &elf[names_section_start..names_section_end];
let mut symtab_i = None; let mut symtab_i = None;
@@ -131,28 +116,30 @@ macro_rules! parse_elf {
fields.insert("name".to_string(), Value::String(name.to_string())); fields.insert("name".to_string(), Value::String(name.to_string()));
section_header_entries_with_names.push(entry_json); section_header_entries_with_names.push(entry_json);
} }
let _ = out.write("section_table", &section_header_entries_with_names); let _ = out.write("sections", &section_header_entries_with_names);
if let Some(symtab_i) = symtab_i { if let Some(symtab_i) = symtab_i {
let mut symbols = vec![];
let symtab = &section_header_entries[symtab_i]; let symtab = &section_header_entries[symtab_i];
const ENTRY_SIZE: usize = size_of::<SymbolTableEntry<$word>>(); const ENTRY_SIZE: usize = size_of::<<$elfcfg as ElfConfig>::SymtabEntry>();
if symtab.sh_size.to_native() as usize != ENTRY_SIZE { if (symtab.sh_entsize.to_native() as usize) != ENTRY_SIZE {
bail!(".symtab size not a multiple of symtab entry size"); bail!(".symtab sh_entsize not equal to symtab entry size");
} }
let section_start: usize = symtab.start().wrap_err(".symtab")?; let section_start: usize = symtab.start().wrap_err(".symtab")?;
let section_end: usize = symtab.end().wrap_err(".symtab")?; let section_end: usize = symtab.end().wrap_err(".symtab")?;
for entry in elf[section_start..section_end].chunks_exact(ENTRY_SIZE) { for (i, entry) in elf[section_start..section_end].chunks_exact(ENTRY_SIZE).enumerate() {
let entry: &[u8; ENTRY_SIZE] = entry.try_into().unwrap(); let entry: &[u8; ENTRY_SIZE] = entry.try_into().unwrap();
let entry: &SymbolTableEntry<$word> = from_bytes(entry); let entry: &<$elfcfg as ElfConfig>::SymtabEntry = from_bytes(entry);
let name_start: usize = (entry.st_name.to_native().try_into()) let entry = SymbolTableEntry::from(*entry);
let name_start: usize = (entry.st_name.try_into())
.wrap_err("symtab entry st_name too big to fit in usize")?; .wrap_err("symtab entry st_name too big to fit in usize")?;
let name = (name_start != 0) let name = (name_start != 0)
.then(|| { .then(|| {
strtab.map(|strtab| { strtab.map(|strtab| {
eprintln!("{name_start} {}", strtab.len());
let name_end = (name_start..strtab.len()) let name_end = (name_start..strtab.len())
.find(|&i| strtab[i] == b'\0') .find(|&i| strtab[i] == b'\0')
.ok_or(eyre!(".strtab entry missing null byte"))?; .ok_or(eyre!(".strtab entry missing null byte"))?;
@@ -164,10 +151,25 @@ macro_rules! parse_elf {
}) })
// Option<Option<Result>> to Result<Option> // Option<Option<Result>> to Result<Option>
.flatten() .flatten()
.transpose()?; .transpose()?
.map(demangle)
.unwrap_or_default();
eprintln!("[.symtab] {name:?}: {entry:?}"); let section = section_header_entries_with_names
.get(usize::from(entry.st_shndx))
.and_then(|v| v.get("name"))
.and_then(|v| v.as_str());
symbols.push(json!({
"i": i,
"value": entry.st_value,
"size": entry.st_size,
"section": section,
"z_name": name,
}));
} }
out.write("symbols", &symbols)?;
} }
}}; }};
} }
@@ -181,25 +183,25 @@ fn main() -> eyre::Result<()> {
if elf.len() < HEADER1_LEN { if elf.len() < HEADER1_LEN {
bail!("not a valid elf file: file too small"); bail!("not a valid elf file: file too small");
} }
let header1: &[u8; HEADER1_LEN] = elf[..HEADER1_LEN].try_into()?; let header: &[u8; HEADER1_LEN] = elf[..HEADER1_LEN].try_into()?;
let header1: ElfHeader1 = *from_bytes(header1); let header: ElfHeader1 = *from_bytes(header);
let mut out = Output::default(); let mut out = Output::default();
out.write("header1", &header1)?; out.write("header", &header)?;
if &header1.ei_magic != b"\x7FELF" { if &header.ei_magic != b"\x7FELF" {
bail!("not a valid elf file: invalid magic"); bail!("not a valid elf file: invalid magic");
} }
if header1.ei_version != 1 { if header.ei_version != 1 {
bail!("unknown elf version: 0x{:x}", header1.ei_version); bail!("unknown elf version: 0x{:x}", header.ei_version);
} }
match (header1.ei_class, header1.ei_data) { match (header.ei_class, header.ei_data) {
(1, 1) => parse_elf!(LittleEndian, U32<LittleEndian>, &mut out, header1, elf), (1, 1) => parse_elf!(LittleEndian32, &mut out, header1, elf),
(2, 1) => parse_elf!(LittleEndian, U64<LittleEndian>, &mut out, header1, elf), (2, 1) => parse_elf!(LittleEndian64, &mut out, header1, elf),
(1, 2) => parse_elf!(BigEndian, U32<BigEndian>, &mut out, header1, elf), (1, 2) => parse_elf!(BigEndian32, &mut out, header1, elf),
(2, 2) => parse_elf!(BigEndian, U64<BigEndian>, &mut out, header1, elf), (2, 2) => parse_elf!(BigEndian64, &mut out, header1, elf),
(1 | 2, ei_data) => bail!("unknown e_ident[EI_DATA]: 0x{ei_data:x}"), (1 | 2, ei_data) => bail!("unknown e_ident[EI_DATA]: 0x{ei_data:x}"),
(ei_class, ..) => bail!("unknown e_ident[EI_CLASS]: 0x{ei_class:x}"), (ei_class, ..) => bail!("unknown e_ident[EI_CLASS]: 0x{ei_class:x}"),
} }

View File

@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use eyre::{bail, Context}; use eyre::{bail, Context};
use serde::Serialize; use serde::Serialize;
use serde_json::Value; use serde_json::{Map, Value};
#[derive(Default)] #[derive(Default)]
pub struct Output { pub struct Output {
@@ -17,6 +17,22 @@ impl Output {
} }
Ok(()) Ok(())
} }
pub fn write_append(&mut self, key: &'static str, v: &impl Serialize) -> eyre::Result<()> {
let Value::Object(mut v) =
serde_json::to_value(v).wrap_err("failed to serialize output")?
else {
bail!("tried to append non-object");
};
let Value::Object(entry) = self.elements.entry(key).or_insert(Map::new().into()) else {
bail!("tried to append to non-object");
};
entry.append(&mut v);
Ok(())
}
} }
impl Drop for Output { impl Drop for Output {

View File

@@ -1,8 +1,55 @@
use crate::ints::{Decode, U16, U32}; use crate::ints::{BigEndian, Decode, LittleEndian, U16, U32, U64};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use eyre::eyre; use eyre::eyre;
use serde::Serialize; use serde::Serialize;
pub trait ElfConfig {
type Word: Decode;
type Half: Decode;
type Addr: Decode;
type SymtabEntry: Pod + Into<SymbolTableEntry>;
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(transparent)]
pub struct LittleEndian32;
impl ElfConfig for LittleEndian32 {
type Word = U32<LittleEndian>;
type Half = U16<LittleEndian>;
type Addr = U32<LittleEndian>;
type SymtabEntry = SymbolTableEntry32<LittleEndian>;
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(transparent)]
pub struct LittleEndian64;
impl ElfConfig for LittleEndian64 {
type Word = U32<LittleEndian>;
type Half = U16<LittleEndian>;
type Addr = U64<LittleEndian>;
type SymtabEntry = SymbolTableEntry64<LittleEndian>;
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(transparent)]
pub struct BigEndian32;
impl ElfConfig for BigEndian32 {
type Word = U32<BigEndian>;
type Half = U16<BigEndian>;
type Addr = U32<BigEndian>;
type SymtabEntry = SymbolTableEntry32<BigEndian>;
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(transparent)]
pub struct BigEndian64;
impl ElfConfig for BigEndian64 {
type Word = U32<BigEndian>;
type Half = U16<BigEndian>;
type Addr = U64<BigEndian>;
type SymtabEntry = SymbolTableEntry64<BigEndian>;
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)] #[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct ElfHeader1 { pub struct ElfHeader1 {
@@ -18,65 +65,79 @@ pub struct ElfHeader1 {
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)] #[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct ElfHeader2<Endian, Word> pub struct ElfHeader2<C: ElfConfig> {
where pub e_type: C::Half,
U16<Endian>: Decode, pub e_machine: C::Half,
U32<Endian>: Decode, pub e_version: C::Word,
Word: Decode, pub e_entry: C::Addr,
{ pub e_phoff: C::Addr,
pub e_type: U16<Endian>, pub e_shoff: C::Addr,
pub e_machine: U16<Endian>, pub e_flags: C::Word,
pub e_version: U32<Endian>, pub e_ehsize: C::Half,
pub e_entry: Word, pub e_phentsize: C::Half,
pub e_phoff: Word, pub e_phnum: C::Half,
pub e_shoff: Word, pub e_shentsize: C::Half,
pub e_flags: U32<Endian>, pub e_shnum: C::Half,
pub e_ehsize: U16<Endian>, pub e_shstrndx: C::Half,
pub e_phentsize: U16<Endian>,
pub e_phnum: U16<Endian>,
pub e_shentsize: U16<Endian>,
pub e_shnum: U16<Endian>,
pub e_shstrndx: U16<Endian>,
} }
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)] #[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(C, packed)] #[repr(C, packed)]
pub struct SectionHeaderEntry<Endian, Word> pub struct SectionHeaderEntry<C: ElfConfig> {
where pub sh_name: C::Word,
U16<Endian>: Decode, pub sh_type: C::Word,
U32<Endian>: Decode, pub sh_flags: C::Addr,
Word: Decode, pub sh_addr: C::Addr,
{ pub sh_offset: C::Addr,
pub sh_name: U32<Endian>, pub sh_size: C::Addr,
pub sh_type: U32<Endian>, pub sh_link: C::Word,
pub sh_flags: Word, pub sh_info: C::Word,
pub sh_addr: Word, pub sh_addralign: C::Addr,
pub sh_offset: Word, pub sh_entsize: C::Addr,
pub sh_size: Word,
pub sh_link: U32<Endian>,
pub sh_info: U32<Endian>,
pub sh_addralign: Word,
pub sh_entsize: Word,
} }
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)] #[derive(Clone, Copy, Debug, Serialize)]
#[repr(C, packed)] pub struct SymbolTableEntry {
pub struct SymbolTableEntry<Word: Decode> { pub st_name: usize,
pub st_name: Word, pub st_value: usize,
pub st_value: Word, pub st_size: usize,
pub st_size: Word,
pub st_info: u8, pub st_info: u8,
pub st_other: u8, pub st_other: u8,
pub st_shndx: Word, pub st_shndx: usize,
} }
impl<Endian, Word> SectionHeaderEntry<Endian, Word> #[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(C, packed)]
pub struct SymbolTableEntry32<Endian>
where where
U16<Endian>: Decode,
U32<Endian>: Decode, U32<Endian>: Decode,
Word: Decode, U16<Endian>: Decode,
<Word as Decode>::Native: TryInto<usize>,
{ {
pub st_name: U32<Endian>,
pub st_value: U32<Endian>,
pub st_size: U32<Endian>,
pub st_info: u8,
pub st_other: u8,
pub st_shndx: U16<Endian>,
}
#[derive(Pod, Zeroable, Clone, Copy, Debug, Serialize)]
#[repr(C, packed)]
pub struct SymbolTableEntry64<Endian>
where
U64<Endian>: Decode,
U32<Endian>: Decode,
U16<Endian>: Decode,
{
pub st_name: U32<Endian>,
pub st_info: u8,
pub st_other: u8,
pub st_shndx: U16<Endian>,
pub st_value: U64<Endian>,
pub st_size: U64<Endian>,
}
impl<C: ElfConfig> SectionHeaderEntry<C> {
pub fn start(&self) -> eyre::Result<usize> { pub fn start(&self) -> eyre::Result<usize> {
self.sh_offset self.sh_offset
.to_native() .to_native()
@@ -94,3 +155,43 @@ where
Ok(self.start()? + size) Ok(self.start()? + size)
} }
} }
impl<Endian> From<SymbolTableEntry32<Endian>> for SymbolTableEntry
where
U32<Endian>: Decode,
<U32<Endian> as Decode>::Native: Into<u32>,
U16<Endian>: Decode,
<U16<Endian> as Decode>::Native: Into<u16>,
{
fn from(entry: SymbolTableEntry32<Endian>) -> Self {
Self {
st_name: entry.st_name.to_native().into() as usize,
st_value: entry.st_value.to_native().into() as usize,
st_size: entry.st_size.to_native().into() as usize,
st_info: entry.st_info,
st_other: entry.st_other,
st_shndx: entry.st_shndx.to_native().into().into(),
}
}
}
impl<Endian> From<SymbolTableEntry64<Endian>> for SymbolTableEntry
where
U64<Endian>: Decode,
<U64<Endian> as Decode>::Native: Into<u64>,
U32<Endian>: Decode,
<U32<Endian> as Decode>::Native: Into<u32>,
U16<Endian>: Decode,
<U16<Endian> as Decode>::Native: Into<u16>,
{
fn from(entry: SymbolTableEntry64<Endian>) -> Self {
Self {
st_name: entry.st_name.to_native().into() as usize,
st_value: entry.st_value.to_native().into() as usize,
st_size: entry.st_size.to_native().into() as usize,
st_info: entry.st_info,
st_other: entry.st_other,
st_shndx: entry.st_shndx.to_native().into().into(),
}
}
}