diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 27 | ||||
-rw-r--r-- | poetry.lock | 292 | ||||
-rw-r--r-- | pyproject.toml | 3 | ||||
-rwxr-xr-x | src/delf.py | 191 | ||||
-rw-r--r-- | test/compile_commands.json | 7 | ||||
-rw-r--r-- | test/makefile | 35 | ||||
-rw-r--r-- | test/test.c | 32 |
7 files changed, 372 insertions, 215 deletions
@@ -22,21 +22,18 @@ You can then run it with `poetry shell` or `poetry run`.<br/> ## Options -For a list of available options just run `delf -h`:<br/> +For a list of available options just run `delf --help`:<br/> ```txt -usage: delf [-h] [--dbg] [--obj OBJ] [--header] [--symboltable] [--phdrs] - [--shdrs] [--symbolindex] [--stentries] [--objcode] [--test] - [--test2] [--funcs] [--objs] [--dynsym] [--dlpath] [--phdynent] - [--section SECTION] [--dumpfunc DUMPFUNC] - [--dumpfuncasm DUMPFUNCASM] [--textasm] [--dynsecents] [--reladyn] - [--relaplt] [--rodata] [--disass DISASS] - -optional arguments: +$ delf --help +usage: delf [-h] [--dbg] [--obj OBJ] [--header] [--symboltable] [--phdrs] [--shdrs] [--symbolindex] [--stentries] [--objcode] [--test] [--test2] [--listdso] [--funcs] [--objs] [--dynsym] [--dlpath] [--phdynent] + [--section SECTION] [--dumpfunc DUMPFUNC] [--dumpfuncasm DUMPFUNCASM] [--textasm] [--dynsecents] [--reladyn] [--relaplt] [--rodata] [--disass DISASS] [--disassp DISASSP] [--got] [--gotplt] + [--noclor] + +options: -h, --help show this help message and exit --dbg debug - --obj OBJ path to the executbale, shared object or object you - want to load in bruiser + --obj OBJ path to the executbale, shared object or object you want to load in bruiser --header dump headers --symboltable dump symbol table --phdrs dump program haeders @@ -46,6 +43,7 @@ optional arguments: --objcode dump objects --test test switch --test2 test switch 2 + --listdso list DSOs --funcs dump functions --objs dump objects --dynsym dump dynamic symbol table @@ -60,8 +58,11 @@ optional arguments: --reladyn .rela.dyn entries --relaplt .rela.plt entries --rodata dump .rodata - --disass DISASS disassemblt a section - + --disass DISASS disassembls a section by name in section headers + --disassp DISASSP disassembls a section by index in program headers + --got dump .got section + --gotplt dump .got.plt section + --noclor dont use color ``` ## Example usage diff --git a/poetry.lock b/poetry.lock index 1f51b04..cdfbfa8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,6 +1,37 @@ # This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] +name = "annotated-types" +version = "0.7.0" +description = "Reusable constraint types to use with typing.Annotated" +optional = false +python-versions = ">=3.8" +files = [ + {file = "annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53"}, + {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, +] + +[[package]] +name = "anyio" +version = "4.4.0" +description = "High level compatibility layer for multiple asynchronous event loop implementations" +optional = false +python-versions = ">=3.8" +files = [ + {file = "anyio-4.4.0-py3-none-any.whl", hash = "sha256:c1b2d8f46a8a812513012e1107cb0e68c17159a7a594208005a57dc776e1bdc7"}, + {file = "anyio-4.4.0.tar.gz", hash = "sha256:5aadc6a1bbb7cdb0bede386cac5e2940f5e2ff3aa20277e991cf028e0585ce94"}, +] + +[package.dependencies] +idna = ">=2.8" +sniffio = ">=1.1" + +[package.extras] +doc = ["Sphinx (>=7)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"] +test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (>=0.17)"] +trio = ["trio (>=0.23)"] + +[[package]] name = "astroid" version = "3.2.2" description = "An abstract syntax tree for Python with inference support." @@ -94,6 +125,17 @@ files = [ ] [[package]] +name = "certifi" +version = "2024.6.2" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.6" +files = [ + {file = "certifi-2024.6.2-py3-none-any.whl", hash = "sha256:ddc6c8ce995e6987e7faf5e3f1b02b302836a0e5d98ece18392cb1a36c72ad56"}, + {file = "certifi-2024.6.2.tar.gz", hash = "sha256:3cd43f1c6fa7dedc5899d69d3ad0398fd018ad1a17fba83ddaf78aa46c747516"}, +] + +[[package]] name = "click" version = "8.1.7" description = "Composable command line interface toolkit" @@ -134,6 +176,84 @@ graph = ["objgraph (>=1.7.2)"] profile = ["gprof2dot (>=2022.7.29)"] [[package]] +name = "distro" +version = "1.9.0" +description = "Distro - an OS platform information API" +optional = false +python-versions = ">=3.6" +files = [ + {file = "distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2"}, + {file = "distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed"}, +] + +[[package]] +name = "h11" +version = "0.14.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +optional = false +python-versions = ">=3.7" +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + +[[package]] +name = "httpcore" +version = "1.0.5" +description = "A minimal low-level HTTP client." +optional = false +python-versions = ">=3.8" +files = [ + {file = "httpcore-1.0.5-py3-none-any.whl", hash = "sha256:421f18bac248b25d310f3cacd198d55b8e6125c107797b609ff9b7a6ba7991b5"}, + {file = "httpcore-1.0.5.tar.gz", hash = "sha256:34a38e2f9291467ee3b44e89dd52615370e152954ba21721378a87b2960f7a61"}, +] + +[package.dependencies] +certifi = "*" +h11 = ">=0.13,<0.15" + +[package.extras] +asyncio = ["anyio (>=4.0,<5.0)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +trio = ["trio (>=0.22.0,<0.26.0)"] + +[[package]] +name = "httpx" +version = "0.27.0" +description = "The next generation HTTP client." +optional = false +python-versions = ">=3.8" +files = [ + {file = "httpx-0.27.0-py3-none-any.whl", hash = "sha256:71d5465162c13681bff01ad59b2cc68dd838ea1f10e51574bac27103f00c91a5"}, + {file = "httpx-0.27.0.tar.gz", hash = "sha256:a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5"}, +] + +[package.dependencies] +anyio = "*" +certifi = "*" +httpcore = "==1.*" +idna = "*" +sniffio = "*" + +[package.extras] +brotli = ["brotli", "brotlicffi"] +cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] +http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] + +[[package]] +name = "idna" +version = "3.7" +description = "Internationalized Domain Names in Applications (IDNA)" +optional = false +python-versions = ">=3.5" +files = [ + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, +] + +[[package]] name = "isort" version = "5.13.2" description = "A Python utility / library to sort Python imports." @@ -251,6 +371,29 @@ files = [ ] [[package]] +name = "openai" +version = "1.31.0" +description = "The official Python library for the openai API" +optional = false +python-versions = ">=3.7.1" +files = [ + {file = "openai-1.31.0-py3-none-any.whl", hash = "sha256:82044ee3122113f2a468a1f308a8882324d09556ba5348687c535d3655ee331c"}, + {file = "openai-1.31.0.tar.gz", hash = "sha256:54ae0625b005d6a3b895db2b8438dae1059cffff0cd262a26e9015c13a29ab06"}, +] + +[package.dependencies] +anyio = ">=3.5.0,<5" +distro = ">=1.7.0,<2" +httpx = ">=0.23.0,<1" +pydantic = ">=1.9.0,<3" +sniffio = "*" +tqdm = ">4" +typing-extensions = ">=4.7,<5" + +[package.extras] +datalib = ["numpy (>=1)", "pandas (>=1.2.3)", "pandas-stubs (>=1.1.0.11)"] + +[[package]] name = "packaging" version = "24.0" description = "Core utilities for Python packages" @@ -300,6 +443,116 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest- type = ["mypy (>=1.8)"] [[package]] +name = "pydantic" +version = "2.7.3" +description = "Data validation using Python type hints" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pydantic-2.7.3-py3-none-any.whl", hash = "sha256:ea91b002777bf643bb20dd717c028ec43216b24a6001a280f83877fd2655d0b4"}, + {file = "pydantic-2.7.3.tar.gz", hash = "sha256:c46c76a40bb1296728d7a8b99aa73dd70a48c3510111ff290034f860c99c419e"}, +] + +[package.dependencies] +annotated-types = ">=0.4.0" +pydantic-core = "2.18.4" +typing-extensions = ">=4.6.1" + +[package.extras] +email = ["email-validator (>=2.0.0)"] + +[[package]] +name = "pydantic-core" +version = "2.18.4" +description = "Core functionality for Pydantic validation and serialization" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pydantic_core-2.18.4-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:f76d0ad001edd426b92233d45c746fd08f467d56100fd8f30e9ace4b005266e4"}, + {file = "pydantic_core-2.18.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:59ff3e89f4eaf14050c8022011862df275b552caef8082e37b542b066ce1ff26"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a55b5b16c839df1070bc113c1f7f94a0af4433fcfa1b41799ce7606e5c79ce0a"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4d0dcc59664fcb8974b356fe0a18a672d6d7cf9f54746c05f43275fc48636851"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8951eee36c57cd128f779e641e21eb40bc5073eb28b2d23f33eb0ef14ffb3f5d"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4701b19f7e3a06ea655513f7938de6f108123bf7c86bbebb1196eb9bd35cf724"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e00a3f196329e08e43d99b79b286d60ce46bed10f2280d25a1718399457e06be"}, + {file = "pydantic_core-2.18.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:97736815b9cc893b2b7f663628e63f436018b75f44854c8027040e05230eeddb"}, + {file = "pydantic_core-2.18.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:6891a2ae0e8692679c07728819b6e2b822fb30ca7445f67bbf6509b25a96332c"}, + {file = "pydantic_core-2.18.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:bc4ff9805858bd54d1a20efff925ccd89c9d2e7cf4986144b30802bf78091c3e"}, + {file = "pydantic_core-2.18.4-cp310-none-win32.whl", hash = "sha256:1b4de2e51bbcb61fdebd0ab86ef28062704f62c82bbf4addc4e37fa4b00b7cbc"}, + {file = "pydantic_core-2.18.4-cp310-none-win_amd64.whl", hash = "sha256:6a750aec7bf431517a9fd78cb93c97b9b0c496090fee84a47a0d23668976b4b0"}, + {file = "pydantic_core-2.18.4-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:942ba11e7dfb66dc70f9ae66b33452f51ac7bb90676da39a7345e99ffb55402d"}, + {file = "pydantic_core-2.18.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:b2ebef0e0b4454320274f5e83a41844c63438fdc874ea40a8b5b4ecb7693f1c4"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a642295cd0c8df1b86fc3dced1d067874c353a188dc8e0f744626d49e9aa51c4"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:5f09baa656c904807e832cf9cce799c6460c450c4ad80803517032da0cd062e2"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:98906207f29bc2c459ff64fa007afd10a8c8ac080f7e4d5beff4c97086a3dabd"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:19894b95aacfa98e7cb093cd7881a0c76f55731efad31073db4521e2b6ff5b7d"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0fbbdc827fe5e42e4d196c746b890b3d72876bdbf160b0eafe9f0334525119c8"}, + {file = "pydantic_core-2.18.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:f85d05aa0918283cf29a30b547b4df2fbb56b45b135f9e35b6807cb28bc47951"}, + {file = "pydantic_core-2.18.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e85637bc8fe81ddb73fda9e56bab24560bdddfa98aa64f87aaa4e4b6730c23d2"}, + {file = "pydantic_core-2.18.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:2f5966897e5461f818e136b8451d0551a2e77259eb0f73a837027b47dc95dab9"}, + {file = "pydantic_core-2.18.4-cp311-none-win32.whl", hash = "sha256:44c7486a4228413c317952e9d89598bcdfb06399735e49e0f8df643e1ccd0558"}, + {file = "pydantic_core-2.18.4-cp311-none-win_amd64.whl", hash = "sha256:8a7164fe2005d03c64fd3b85649891cd4953a8de53107940bf272500ba8a788b"}, + {file = "pydantic_core-2.18.4-cp311-none-win_arm64.whl", hash = "sha256:4e99bc050fe65c450344421017f98298a97cefc18c53bb2f7b3531eb39bc7805"}, + {file = "pydantic_core-2.18.4-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:6f5c4d41b2771c730ea1c34e458e781b18cc668d194958e0112455fff4e402b2"}, + {file = "pydantic_core-2.18.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2fdf2156aa3d017fddf8aea5adfba9f777db1d6022d392b682d2a8329e087cef"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4748321b5078216070b151d5271ef3e7cc905ab170bbfd27d5c83ee3ec436695"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:847a35c4d58721c5dc3dba599878ebbdfd96784f3fb8bb2c356e123bdcd73f34"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3c40d4eaad41f78e3bbda31b89edc46a3f3dc6e171bf0ecf097ff7a0ffff7cb1"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:21a5e440dbe315ab9825fcd459b8814bb92b27c974cbc23c3e8baa2b76890077"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:01dd777215e2aa86dfd664daed5957704b769e726626393438f9c87690ce78c3"}, + {file = "pydantic_core-2.18.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4b06beb3b3f1479d32befd1f3079cc47b34fa2da62457cdf6c963393340b56e9"}, + {file = "pydantic_core-2.18.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:564d7922e4b13a16b98772441879fcdcbe82ff50daa622d681dd682175ea918c"}, + {file = "pydantic_core-2.18.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:0eb2a4f660fcd8e2b1c90ad566db2b98d7f3f4717c64fe0a83e0adb39766d5b8"}, + {file = "pydantic_core-2.18.4-cp312-none-win32.whl", hash = "sha256:8b8bab4c97248095ae0c4455b5a1cd1cdd96e4e4769306ab19dda135ea4cdb07"}, + {file = "pydantic_core-2.18.4-cp312-none-win_amd64.whl", hash = "sha256:14601cdb733d741b8958224030e2bfe21a4a881fb3dd6fbb21f071cabd48fa0a"}, + {file = "pydantic_core-2.18.4-cp312-none-win_arm64.whl", hash = "sha256:c1322d7dd74713dcc157a2b7898a564ab091ca6c58302d5c7b4c07296e3fd00f"}, + {file = "pydantic_core-2.18.4-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:823be1deb01793da05ecb0484d6c9e20baebb39bd42b5d72636ae9cf8350dbd2"}, + {file = "pydantic_core-2.18.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ebef0dd9bf9b812bf75bda96743f2a6c5734a02092ae7f721c048d156d5fabae"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ae1d6df168efb88d7d522664693607b80b4080be6750c913eefb77e34c12c71a"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f9899c94762343f2cc2fc64c13e7cae4c3cc65cdfc87dd810a31654c9b7358cc"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:99457f184ad90235cfe8461c4d70ab7dd2680e28821c29eca00252ba90308c78"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:18f469a3d2a2fdafe99296a87e8a4c37748b5080a26b806a707f25a902c040a8"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b7cdf28938ac6b8b49ae5e92f2735056a7ba99c9b110a474473fd71185c1af5d"}, + {file = "pydantic_core-2.18.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:938cb21650855054dc54dfd9120a851c974f95450f00683399006aa6e8abb057"}, + {file = "pydantic_core-2.18.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:44cd83ab6a51da80fb5adbd9560e26018e2ac7826f9626bc06ca3dc074cd198b"}, + {file = "pydantic_core-2.18.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:972658f4a72d02b8abfa2581d92d59f59897d2e9f7e708fdabe922f9087773af"}, + {file = "pydantic_core-2.18.4-cp38-none-win32.whl", hash = "sha256:1d886dc848e60cb7666f771e406acae54ab279b9f1e4143babc9c2258213daa2"}, + {file = "pydantic_core-2.18.4-cp38-none-win_amd64.whl", hash = "sha256:bb4462bd43c2460774914b8525f79b00f8f407c945d50881568f294c1d9b4443"}, + {file = "pydantic_core-2.18.4-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:44a688331d4a4e2129140a8118479443bd6f1905231138971372fcde37e43528"}, + {file = "pydantic_core-2.18.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a2fdd81edd64342c85ac7cf2753ccae0b79bf2dfa063785503cb85a7d3593223"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:86110d7e1907ab36691f80b33eb2da87d780f4739ae773e5fc83fb272f88825f"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:46387e38bd641b3ee5ce247563b60c5ca098da9c56c75c157a05eaa0933ed154"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:123c3cec203e3f5ac7b000bd82235f1a3eced8665b63d18be751f115588fea30"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:dc1803ac5c32ec324c5261c7209e8f8ce88e83254c4e1aebdc8b0a39f9ddb443"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:53db086f9f6ab2b4061958d9c276d1dbe3690e8dd727d6abf2321d6cce37fa94"}, + {file = "pydantic_core-2.18.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:abc267fa9837245cc28ea6929f19fa335f3dc330a35d2e45509b6566dc18be23"}, + {file = "pydantic_core-2.18.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:a0d829524aaefdebccb869eed855e2d04c21d2d7479b6cada7ace5448416597b"}, + {file = "pydantic_core-2.18.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:509daade3b8649f80d4e5ff21aa5673e4ebe58590b25fe42fac5f0f52c6f034a"}, + {file = "pydantic_core-2.18.4-cp39-none-win32.whl", hash = "sha256:ca26a1e73c48cfc54c4a76ff78df3727b9d9f4ccc8dbee4ae3f73306a591676d"}, + {file = "pydantic_core-2.18.4-cp39-none-win_amd64.whl", hash = "sha256:c67598100338d5d985db1b3d21f3619ef392e185e71b8d52bceacc4a7771ea7e"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:574d92eac874f7f4db0ca653514d823a0d22e2354359d0759e3f6a406db5d55d"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:1f4d26ceb5eb9eed4af91bebeae4b06c3fb28966ca3a8fb765208cf6b51102ab"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:77450e6d20016ec41f43ca4a6c63e9fdde03f0ae3fe90e7c27bdbeaece8b1ed4"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d323a01da91851a4f17bf592faf46149c9169d68430b3146dcba2bb5e5719abc"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:43d447dd2ae072a0065389092a231283f62d960030ecd27565672bd40746c507"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:578e24f761f3b425834f297b9935e1ce2e30f51400964ce4801002435a1b41ef"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:81b5efb2f126454586d0f40c4d834010979cb80785173d1586df845a632e4e6d"}, + {file = "pydantic_core-2.18.4-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:ab86ce7c8f9bea87b9d12c7f0af71102acbf5ecbc66c17796cff45dae54ef9a5"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:90afc12421df2b1b4dcc975f814e21bc1754640d502a2fbcc6d41e77af5ec312"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:51991a89639a912c17bef4b45c87bd83593aee0437d8102556af4885811d59f5"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:293afe532740370aba8c060882f7d26cfd00c94cae32fd2e212a3a6e3b7bc15e"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b48ece5bde2e768197a2d0f6e925f9d7e3e826f0ad2271120f8144a9db18d5c8"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:eae237477a873ab46e8dd748e515c72c0c804fb380fbe6c85533c7de51f23a8f"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:834b5230b5dfc0c1ec37b2fda433b271cbbc0e507560b5d1588e2cc1148cf1ce"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:e858ac0a25074ba4bce653f9b5d0a85b7456eaddadc0ce82d3878c22489fa4ee"}, + {file = "pydantic_core-2.18.4-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:2fd41f6eff4c20778d717af1cc50eca52f5afe7805ee530a4fbd0bae284f16e9"}, + {file = "pydantic_core-2.18.4.tar.gz", hash = "sha256:ec3beeada09ff865c344ff3bc2f427f5e6c26401cc6113d77e372c3fdac73864"}, +] + +[package.dependencies] +typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" + +[[package]] name = "pygments" version = "2.18.0" description = "Pygments is a syntax highlighting package written in Python." @@ -458,6 +711,17 @@ testing = ["build[virtualenv]", "filelock (>=3.4.0)", "importlib-metadata", "ini testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] [[package]] +name = "sniffio" +version = "1.3.1" +description = "Sniff out which async library your code is running under" +optional = false +python-versions = ">=3.7" +files = [ + {file = "sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"}, + {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, +] + +[[package]] name = "stevedore" version = "5.2.0" description = "Manage dynamic plugins for Python applications" @@ -483,17 +747,37 @@ files = [ ] [[package]] +name = "tqdm" +version = "4.66.4" +description = "Fast, Extensible Progress Meter" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tqdm-4.66.4-py3-none-any.whl", hash = "sha256:b75ca56b413b030bc3f00af51fd2c1a1a5eac6a0c1cca83cbb37a5c52abce644"}, + {file = "tqdm-4.66.4.tar.gz", hash = "sha256:e4d936c9de8727928f3be6079590e97d9abfe8d39a590be678eb5919ffc186bb"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[package.extras] +dev = ["pytest (>=6)", "pytest-cov", "pytest-timeout", "pytest-xdist"] +notebook = ["ipywidgets (>=6)"] +slack = ["slack-sdk"] +telegram = ["requests"] + +[[package]] name = "typing-extensions" -version = "4.12.0" +version = "4.12.1" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.12.0-py3-none-any.whl", hash = "sha256:b349c66bea9016ac22978d800cfff206d5f9816951f12a7d0ec5578b0a819594"}, - {file = "typing_extensions-4.12.0.tar.gz", hash = "sha256:8cbcdc8606ebcb0d95453ad7dc5065e6237b6aa230a31e81d0f440c30fed5fd8"}, + {file = "typing_extensions-4.12.1-py3-none-any.whl", hash = "sha256:6024b58b69089e5a89c347397254e35f1bf02a907728ec7fee9bf0fe837d203a"}, + {file = "typing_extensions-4.12.1.tar.gz", hash = "sha256:915f5e35ff76f56588223f15fdd5938f9a1cf9195c0de25130c627e4d597f6d1"}, ] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "44f3792468ec77f2bcddb771ef4e0b2c764f563d303ede7e73b57f29dbd303c8" +content-hash = "d7d498122fe3199160c29d596705d07ef5f13c53082da671249ede114ca2b94f" diff --git a/pyproject.toml b/pyproject.toml index e46b8dd..6747372 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "delf" -version = "0.1.5" +version = "0.2.0" description = "yet another elf dump tool" authors = ["terminaldweller <devi@terminaldweller.com>"] license = "GPL-3.0" @@ -29,6 +29,7 @@ pylint = "^3.0.2" bandit = "^1.7.5" ruff = "^0.1.1" black = ">=23.10,<25.0" +openai = "^1.30.4" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/src/delf.py b/src/delf.py index c988098..f4b114b 100755 --- a/src/delf.py +++ b/src/delf.py @@ -19,10 +19,10 @@ # MA 02110-1301, USA.*/ # *****************************************************************************/ import argparse -import code import os import subprocess import sys +import typing from capstone import CS_ARCH_X86, CS_MODE_64, Cs @@ -30,6 +30,8 @@ from capstone import CS_ARCH_X86, CS_MODE_64, Cs class ELF_TYPE_SIZES: + """Const class that holds ELF type sizes in bytes""" + ELF32_HALF = 2 ELF64_HALF = 2 ELF32_WORD = 4 @@ -53,7 +55,7 @@ def SigHandler_SIGINT(signum, frame): sys.exit(0) -class CLIArgParser(object): +class CLIArgParser: def __init__(self): parser = argparse.ArgumentParser() parser.add_argument("--dbg", action="store_true", help="debug", default=False) @@ -194,6 +196,12 @@ class CLIArgParser(object): help="dump .got.plt section", default=False, ) + parser.add_argument( + "--nocolor", + action="store_true", + help="dont use color", + default=False, + ) self.args = parser.parse_args() if self.args.obj is None: raise Exception( @@ -273,16 +281,29 @@ class ELF_RELA: self.r_addend = r_addend -def ffs(offset, header_list, numbered, *args): +def ffs( + offset, + header_list, + numbered, + nocolor, + *args, +): # cn = Colors.green - ch = Colors.cyan - cd = Colors.blue - cb = Colors.BOLD - ci = Colors.red - ce = Colors.ENDC + if nocolor: + ch = "" + cd = "" + cb = "" + ci = "" + ce = "" + else: + ch = Colors.cyan + cd = Colors.blue + cb = Colors.BOLD + ci = Colors.red + ce = Colors.ENDC max_column_width = [] - lines = [] - numbers_f = [] + lines: typing.List[str] = [] + numbers_f: typing.List[int] = [] dummy = [] if numbered: @@ -1210,8 +1231,10 @@ class Symbol_Table_Entry64: self.st_type = st_type -class ELF(object): - def __init__(self, so): +class ELF: + """The ELF class that holds everything about the ELF file.""" + + def __init__(self, so, argparser): self.so = so self.so.seek(0, 0) self.elfhdr = ELFHDR(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) @@ -1240,6 +1263,7 @@ class ELF(object): self.plt_got_ents = [] self.got_ents = [] self.got_plt_ents = [] + self.argparser = argparser def init(self, size): self.size = size @@ -1420,7 +1444,7 @@ class ELF(object): header = ["d_tag", "d_un"] tag_list = [get_ph_dynamic_ent_tag_type(ph.d_tag) for ph in self.ph_dyn_ent] un_list = [ph.d_un for ph in self.ph_dyn_ent] - lines = ffs(2, header, True, tag_list, un_list) + lines = ffs(2, header, True, self.argparser.args.nocolor, tag_list, un_list) for line in lines: print(line) @@ -1473,7 +1497,7 @@ class ELF(object): self.dlpath = repr(obj) count = int() if dump: - strrep = [] + strrep: typing.List[str] = [] for byte in obj: if count % 16 == 0: for ch in strrep: @@ -1529,6 +1553,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocoor, name_list, size_list, value_list, @@ -1551,6 +1576,7 @@ class ELF(object): 2, header, True, + self.argparser.args.noclor, name_list, size_list, value_list, @@ -1609,6 +1635,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, mag_list, class_list, data_list, @@ -1661,6 +1688,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, type_list, flags_list, offset_list, @@ -1706,6 +1734,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, name_list, type_list, flag_list, @@ -1765,6 +1794,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, idx_list, name_list, value_list, @@ -1811,6 +1841,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, idx_list, name_list, value_list, @@ -1834,6 +1865,7 @@ class ELF(object): 2, header, True, + self.argparser.args.nocolor, tag_string_list, tag_list, value_list, @@ -1847,7 +1879,15 @@ class ELF(object): r_offset_list = [entry["r_offset"] for entry in to_dump] r_info_list = [entry["r_info"] for entry in to_dump] addend_list = [entry["r_addend"] for entry in to_dump] - lines = ffs(2, header, True, r_offset_list, r_info_list, addend_list) + lines = ffs( + 2, + header, + True, + self.argparser.args.nocolor, + r_offset_list, + r_info_list, + addend_list, + ) for line in lines: print(line) @@ -1855,7 +1895,9 @@ class ELF(object): header = ["r_offset", "r_info"] r_offset_list = [entry["r_offset"] for entry in to_dump] r_info_list = [entry["r_info"] for entry in to_dump] - lines = ffs(2, header, True, r_offset_list, r_info_list) + lines = ffs( + 2, header, True, self.argparser.args.nocolor, r_offset_list, r_info_list + ) for line in lines: print(line) @@ -2037,14 +2079,14 @@ class ELF(object): def dump_got(self): header = ["value"] value_list = [entry for entry in self.got_ents] - lines = ffs(2, header, True, value_list) + lines = ffs(2, header, True, self.argparser.args.nocolor, value_list) for line in lines: print(line) def dump_got_plt(self): header = ["value"] value_list = [entry for entry in self.got_plt_ents] - lines = ffs(2, header, True, value_list) + lines = ffs(2, header, True, self.argparser.args.nocolor, value_list) for line in lines: print(line) @@ -2074,109 +2116,11 @@ def ch_exe_to_so(path): so.close -def elf_init(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - - -def elf_get_func_names(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_symbol_string(ELF_ST_TYPE.STT_FUNC, False) - - -def elf_get_text_section(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_section(".text", False) - - -def elf_get_section(name): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_section(name, False) - - -def elf_get_rodata_section(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_section(".rodata", False) - - -# obj here means variables or what the C standard means by objects - - -def elf_get_obj_names(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_symbol_string(ELF_ST_TYPE.STT_OBJECT, False) - - -# obj here means variables or what the C standard means by objects - - -def elf_get_obj_sizes(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_obj_size(ELF_ST_TYPE.STT_OBJECT, False) - - -def elf_get_func_code(): - so = openSO_r(sys.argv[1]) - elf = ELF(so) - elf.init(64) - return elf.dump_funcs(False) - - -def elf_get_func_code_byname(): - so = openSO_r(sys.argv[1]) - arg = openSO_r(sys.argv[2]) - elf = ELF(so) - elf.init(64) - counter = 0 - # hit = False - for name in elf.dump_symbol_string(ELF_ST_TYPE.STT_FUNC, False): - if name == arg: - code = elf.dump_funcs(False)[counter] - # hit = True - counter += 1 - return code - - -class Call_Rewriter(object): - # def __init__(self, obj_code, arch, mode): - def __init__(self, obj_code): - self.obj_code = bytes(obj_code) - self.md = Cs(CS_ARCH_X86, CS_MODE_64) - # self.md = Cs(arch, mode) - - def dumpall(self): - for i in self.md.disasm(self.obj_code, 0x1): - print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str)) - - def run(self): - for i in self.md.disasm(self.obj_code, 0x1): - if i.mnemonic == "call": - print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str)) - print(i.bytes) - - -class Global_Rewriter(object): - def __init__(self): - pass - - -class Rewriter(object): - def __init__(self, path, new_name): +class Rewriter: + def __init__(self, path, new_name, argparser): so = openSO_r(path) - self.elf = ELF(so) + self.argparser = argparser + self.elf = ELF(so, argparser) self.elf.init(64) # shutil.copyfile(path, "/tmp/exe") self.magic_section_number = int() @@ -2223,9 +2167,10 @@ class Rewriter(object): def main() -> None: + """The entryp point.""" argparser = CLIArgParser() so = openSO_r(argparser.args.obj) - elf = ELF(so) + elf = ELF(so, argparser) elf.init(64) if argparser.args.header: elf.dump_header() @@ -2253,7 +2198,7 @@ def main() -> None: elif argparser.args.section: elf.dump_section(argparser.args.section, True) elif argparser.args.test2: - rewriter = Rewriter(argparser.args.obj, "new_exe") + rewriter = Rewriter(argparser.args.obj, "new_exe", argparser) new_text = bytes() rewriter.fix_section_offsets(".text", 1000, new_text) elif argparser.args.dumpfunc: @@ -2296,7 +2241,7 @@ def main() -> None: index = argparser.args.disassp # section not executable message if byte2int(elf.phdr[index].p_flags) & 0x1 != 1: - print("program header section is not " "executable but since you asked...") + print("program header section is not executable but since you asked...") header_offset = elf.phdr[index].p_offset header_size = elf.phdr[index].p_filesz elf.so.seek(byte2int(header_offset)) diff --git a/test/compile_commands.json b/test/compile_commands.json deleted file mode 100644 index ca764a6..0000000 --- a/test/compile_commands.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "command": "cc -c -fpic -O0 -g -v --debug -o test.o test.c", - "directory": "/home/bloodstalker/extra/delf/test", - "file": "/home/bloodstalker/extra/delf/test/test.c" - } -]
\ No newline at end of file diff --git a/test/makefile b/test/makefile deleted file mode 100644 index 9414f84..0000000 --- a/test/makefile +++ /dev/null @@ -1,35 +0,0 @@ - -##################################VARS################################# -CC?=gcc -CC=gcc -CC_FLAGS=-fpic -O0 -g -v --debug -#LD_FLAGS= -l bfd -LD_FLAGS= -TARGET=test -##################################RULES################################ -.DEFAULT:all - -.PHONY:all clean help - -all:$(TARGET) $(TARGET).so $(TARGET).asm - -.c.o: - $(CC) $(CC_FLAGS) -c $< -o $@ - -$(TARGET): $(TARGET).o - $(CC) $^ $(LD_FLAGS) -o $@ - -$(TARGET).asm: $(TARGET).o - objdump -r -d -M intel -S $(TARGET).o > $(TARGET).asm - -$(TARGET).so: $(TARGET).o - $(CC) $^ $(LD_FLAGS) -shared -o $@ - -clean: - rm -f *.o *~ $(TARGET) $(TARGET).so $(TARGET).asm - -help: - @echo 'all builds so and exe. all is the default.' - @echo 'clean runs clean.' - @echo 'help runs help.' - diff --git a/test/test.c b/test/test.c deleted file mode 100644 index 00f92ad..0000000 --- a/test/test.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "stdio.h" - -int myfunc1(void) {return 1;} -int myfunc2(void) {return 2;} -int myfunc3(void) {return 3;} -int myfunc4(void) {return 4;} -int myfunc5(void) {return 5;} -int myfunc6(void) {return 6;} -int add2(int a, int b) {return a + b;} -int sub2(int a, int b) {return a - b;} -double adddouble(double a, double b) {return a+b;} -double subdouble(double a, double b) {return a-b;} -double triple(double a, double b, double c) {return a+b+c;} -int quad(int a, int b, int c, int d) {return add2(a,b) + add2(c,d);} -const char* passthrough(const char* a) {return a;} -void ext_1(void) {printf("%s", "hey there sleepy-head.\n");} - -int myvar1 = 1; -int myvar2 = 2; -int myvar3 = 3; -int myvar4 = 4; - -int glob(void) {return myvar1+myvar2+myvar3+myvar4;} - -int main(int argc, char** argv) { - int sum; - sum = add2(10, 20); - printf("i live!\n"); - int res = sub2(20, 10); - ext_1(); - return quad(1,2,3,4); -} |