-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyelfalt.py
89 lines (71 loc) · 2.92 KB
/
pyelfalt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This program is free software; you can redistribute it and/or modify
it under the terms of the Revised BSD License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Revised BSD License for more details.
Copyright 2019 Game Maker 2k - https://github.com/GameMaker2k
Copyright 2019 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: pyelf.py - Last Update: 3/18/2019 Ver. 1.0.0 RC 1 - Author: joshuatp $
'''
import os
import sys
import argparse
__program_name__ = "PyELF"
__project__ = __program_name__
__project_url__ = "https://gist.github.com/KazukiPrzyborowski"
__version_info__ = (1, 0, 0, "RC 1", 1)
__version_date_info__ = (2019, 3, 18, "RC 1", 1)
__version_date__ = f"{__version_date_info__[0]}.{str(__version_date_info__[1]).zfill(2)}.{str(__version_date_info__[2]).zfill(2)}"
__version_date_plusrc__ = __version_date__ if __version_info__[
4] is None else f"{__version_date__}-{str(__version_date_info__[4])}"
__version__ = f"{__version_info__[0]}.{__version_info__[1]}.{__version_info__[2]}" if __version_info__[
3] is None else f"{__version_info__[0]}.{__version_info__[1]}.{__version_info__[2]} {str(__version_info__[3])}"
def get_elf_header(infile):
"""
Read the header of an ELF file.
Args:
infile (str): Path to the ELF file.
Returns:
dict: A dictionary containing information about the ELF file.
"""
if not os.path.exists(infile) or not os.path.isfile(infile):
return False
with open(infile, "rb") as elf_file_pointer:
elf_file_info = {
'ei_magic': elf_file_pointer.read(4),
'ei_class': elf_file_pointer.read(1),
'ei_data': elf_file_pointer.read(1),
'ei_version': elf_file_pointer.read(1),
'ei_osabi': elf_file_pointer.read(1),
'ei_abiversion': elf_file_pointer.read(1),
'ei_pad': elf_file_pointer.read(7),
'e_type': elf_file_pointer.read(2),
'e_machine': elf_file_pointer.read(2),
'e_version': elf_file_pointer.read(4),
'e_entry': None,
'e_phoff': None,
'e_bit': None,
'e_shoff': None,
'p_headers': [],
}
# Rest of the code for reading the ELF file...
return elf_file_info
def main():
"""
Main function to execute the script.
"""
parser = argparse.ArgumentParser(
description='Read the header of an ELF file.')
parser.add_argument('infile', type=str, help='Path to the ELF file.')
args = parser.parse_args()
elf_file_info = get_elf_header(args.infile)
if elf_file_info:
print(elf_file_info['e_file_info'])
else:
print(f"{args.infile}: Not a ELF File")
if __name__ == '__main__':
main()