pelfy 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pelfy-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nicolas Kruse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pelfy-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.2
2
+ Name: pelfy
3
+ Version: 1.0.0
4
+ Summary: Parser for ELF files written in python
5
+ Author-email: Nicolas Kruse <nicolas.kruse@nonan.net>
6
+ Project-URL: Homepage, https://github.com/Nonannet/pelfy
7
+ Project-URL: Issues, https://github.com/Nonannet/pelfy/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # pelfy
16
+
17
+ ## Description
18
+ Pelfy (Python Executable and Linkable Format analyzer) is an ELF parser written
19
+ in python. It shows header fields, sections, symbols and relocation and gives
20
+ access to all raw data as well as human readable representations.
21
+
22
+ ### Key Features
23
+ - Provide names for fields and values as well as descriptions
24
+ - Relocation types for x86, MIPS, ARM and RISC-V all in 32 and 64 bit
25
+ - Outputs tables in nicely formatted HTML, markdown or text
26
+ - Uses HTML outputs for Jupyter Notebook integration
27
+ - Compact code base
28
+ - Pure fully static typed python and no other dependencies
29
+
30
+ ### Usage Scenarios
31
+ - Reverse engineering tools
32
+ - Testing
33
+ - Documentation
34
+
35
+ ## Installation
36
+ The package has no additional decencies. It can be installed with pip:
37
+
38
+ ```bash
39
+ pip install pelfy
40
+ ```
41
+
42
+ ## Usage
43
+ Example code and its outputs:
44
+
45
+ ```python
46
+ import pelfy
47
+
48
+ elf = pelfy.open_elf_file('obj/test-c-riscv64-linux-gnu-gcc-12-O3.o')
49
+ elf.sections
50
+ ```
51
+ | index | name | type | description |
52
+ |------:|-------------------|--------------|-----------------------------------|
53
+ | 0 | | SHT_NULL | Section header table entry unused |
54
+ | 1 | .text | SHT_PROGBITS | Program data |
55
+ | 2 | .rela.text | SHT_RELA | Relocation entries with addends |
56
+ | 3 | .data | SHT_PROGBITS | Program data |
57
+ | 4 | .bss | SHT_NOBITS | Program space with no data (bss) |
58
+ | 5 | .comment | SHT_PROGBITS | Program data |
59
+ | 6 | .note.GNU-stack | SHT_PROGBITS | Program data |
60
+ | 7 | .riscv.attributes | 0x70000003 | Application-specific |
61
+ | 8 | .symtab | SHT_SYMTAB | Symbol table |
62
+ | 9 | .strtab | SHT_STRTAB | String table |
63
+ | 10 | .shstrtab | SHT_STRTAB | String table |
64
+ ```python
65
+ elf.functions
66
+ ```
67
+ | index | name | info | size | stb | description |
68
+ |-------|--------------------|----------|-----:|------------|-------------------------|
69
+ | 11 | result_float | STT_FUNC | 8 | STB_GLOBAL | Symbol is a code object |
70
+ | 12 | result_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
71
+ | 13 | add_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
72
+ | 14 | mul_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
73
+ | 15 | read_float | STT_FUNC | 16 | STB_GLOBAL | Symbol is a code object |
74
+ ```python
75
+ elf.symbols['read_float'].get_relocations()
76
+ ```
77
+ | index | symbol name | type | calculation |
78
+ |-------|--------------------|----------------------|-------------|
79
+ | 4 | .LANCHOR0 | R_RISCV_PCREL_HI20 | S + A - P |
80
+ | 5 | | R_RISCV_RELAX | |
81
+ | 6 | .L0 | R_RISCV_PCREL_LO12_I | S - P |
82
+ | 7 | | R_RISCV_RELAX | |
83
+ | 8 | result_float_float | R_RISCV_CALL_PLT | S + A - P |
84
+ | 9 | | R_RISCV_RELAX | |
85
+
86
+ ## Contributing
87
+ Contributions are welcome! Please open an issue or submit a pull request on GitHub.
88
+
89
+ ## Developer Guide
90
+ To get started with developing the `pelfy` package, follow these steps:
91
+
92
+ First, clone the repository to your local machine using Git:
93
+
94
+ ```bash
95
+ git clone https://github.com/Nonannet/pelfy.git
96
+ cd pelfy
97
+ ```
98
+
99
+ Install the package while keeping files in the current dev directory:
100
+
101
+ ```bash
102
+ pip install -e .
103
+ ```
104
+
105
+ Install pytest (unit testing), mypy (type checking) and flake8 (style guide checking):
106
+
107
+ ```bash
108
+ pip install pytest mypy flake8
109
+ ```
110
+
111
+ Ensure that everything is set up correctly by running the tests:
112
+
113
+ ```bash
114
+ pytest
115
+ ```
116
+
117
+ For creating additional test object files place the source c-files in the `tests/src/` directory,
118
+ change the current directory to `tests/src/` and run `bash run_cross_compilation.sh`. This
119
+ script uses a docker container to cross compile all c-files to object files and outputs
120
+ them in the tests/obj directory.
121
+
122
+ ## License
123
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
pelfy-1.0.0/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # pelfy
2
+
3
+ ## Description
4
+ Pelfy (Python Executable and Linkable Format analyzer) is an ELF parser written
5
+ in python. It shows header fields, sections, symbols and relocation and gives
6
+ access to all raw data as well as human readable representations.
7
+
8
+ ### Key Features
9
+ - Provide names for fields and values as well as descriptions
10
+ - Relocation types for x86, MIPS, ARM and RISC-V all in 32 and 64 bit
11
+ - Outputs tables in nicely formatted HTML, markdown or text
12
+ - Uses HTML outputs for Jupyter Notebook integration
13
+ - Compact code base
14
+ - Pure fully static typed python and no other dependencies
15
+
16
+ ### Usage Scenarios
17
+ - Reverse engineering tools
18
+ - Testing
19
+ - Documentation
20
+
21
+ ## Installation
22
+ The package has no additional decencies. It can be installed with pip:
23
+
24
+ ```bash
25
+ pip install pelfy
26
+ ```
27
+
28
+ ## Usage
29
+ Example code and its outputs:
30
+
31
+ ```python
32
+ import pelfy
33
+
34
+ elf = pelfy.open_elf_file('obj/test-c-riscv64-linux-gnu-gcc-12-O3.o')
35
+ elf.sections
36
+ ```
37
+ | index | name | type | description |
38
+ |------:|-------------------|--------------|-----------------------------------|
39
+ | 0 | | SHT_NULL | Section header table entry unused |
40
+ | 1 | .text | SHT_PROGBITS | Program data |
41
+ | 2 | .rela.text | SHT_RELA | Relocation entries with addends |
42
+ | 3 | .data | SHT_PROGBITS | Program data |
43
+ | 4 | .bss | SHT_NOBITS | Program space with no data (bss) |
44
+ | 5 | .comment | SHT_PROGBITS | Program data |
45
+ | 6 | .note.GNU-stack | SHT_PROGBITS | Program data |
46
+ | 7 | .riscv.attributes | 0x70000003 | Application-specific |
47
+ | 8 | .symtab | SHT_SYMTAB | Symbol table |
48
+ | 9 | .strtab | SHT_STRTAB | String table |
49
+ | 10 | .shstrtab | SHT_STRTAB | String table |
50
+ ```python
51
+ elf.functions
52
+ ```
53
+ | index | name | info | size | stb | description |
54
+ |-------|--------------------|----------|-----:|------------|-------------------------|
55
+ | 11 | result_float | STT_FUNC | 8 | STB_GLOBAL | Symbol is a code object |
56
+ | 12 | result_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
57
+ | 13 | add_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
58
+ | 14 | mul_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object |
59
+ | 15 | read_float | STT_FUNC | 16 | STB_GLOBAL | Symbol is a code object |
60
+ ```python
61
+ elf.symbols['read_float'].get_relocations()
62
+ ```
63
+ | index | symbol name | type | calculation |
64
+ |-------|--------------------|----------------------|-------------|
65
+ | 4 | .LANCHOR0 | R_RISCV_PCREL_HI20 | S + A - P |
66
+ | 5 | | R_RISCV_RELAX | |
67
+ | 6 | .L0 | R_RISCV_PCREL_LO12_I | S - P |
68
+ | 7 | | R_RISCV_RELAX | |
69
+ | 8 | result_float_float | R_RISCV_CALL_PLT | S + A - P |
70
+ | 9 | | R_RISCV_RELAX | |
71
+
72
+ ## Contributing
73
+ Contributions are welcome! Please open an issue or submit a pull request on GitHub.
74
+
75
+ ## Developer Guide
76
+ To get started with developing the `pelfy` package, follow these steps:
77
+
78
+ First, clone the repository to your local machine using Git:
79
+
80
+ ```bash
81
+ git clone https://github.com/Nonannet/pelfy.git
82
+ cd pelfy
83
+ ```
84
+
85
+ Install the package while keeping files in the current dev directory:
86
+
87
+ ```bash
88
+ pip install -e .
89
+ ```
90
+
91
+ Install pytest (unit testing), mypy (type checking) and flake8 (style guide checking):
92
+
93
+ ```bash
94
+ pip install pytest mypy flake8
95
+ ```
96
+
97
+ Ensure that everything is set up correctly by running the tests:
98
+
99
+ ```bash
100
+ pytest
101
+ ```
102
+
103
+ For creating additional test object files place the source c-files in the `tests/src/` directory,
104
+ change the current directory to `tests/src/` and run `bash run_cross_compilation.sh`. This
105
+ script uses a docker container to cross compile all c-files to object files and outputs
106
+ them in the tests/obj directory.
107
+
108
+ ## License
109
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "pelfy"
3
+ version = "1.0.0"
4
+ authors = [
5
+ { name="Nicolas Kruse", email="nicolas.kruse@nonan.net" },
6
+ ]
7
+ description = "Parser for ELF files written in python"
8
+ readme = "README.md"
9
+ requires-python = ">=3.9"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/Nonannet/pelfy"
18
+ Issues = "https://github.com/Nonannet/pelfy/issues"
19
+
20
+ [build-system]
21
+ requires = ["setuptools>=61.0"]
22
+ build-backend = "setuptools.build_meta"
23
+
24
+ [tool.setuptools.packages.find]
25
+ where = ["src"]
26
+
27
+ [tool.mypy]
28
+ files = ["src", "tests"]
29
+ strict = true
30
+ warn_return_any = true
31
+ warn_unused_configs = true
32
+ check_untyped_defs = true
33
+ no_implicit_optional = true
34
+ show_error_codes = true
35
+
36
+ [tool.pytest.ini_options]
37
+ minversion = "6.0"
38
+ addopts = "-ra -q"
39
+ testpaths = ["tests"]
40
+ pythonpath = ["src"]
pelfy-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+