PyNerva 0.0.7__py3-none-any.whl
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.
- nervapy/__init__.py +50 -0
- nervapy/abi.py +91 -0
- nervapy/arm/__init__.py +124 -0
- nervapy/arm/__main__.py +0 -0
- nervapy/arm/abi.py +138 -0
- nervapy/arm/formats.py +49 -0
- nervapy/arm/function.py +2465 -0
- nervapy/arm/generic.py +10796 -0
- nervapy/arm/instructions.py +519 -0
- nervapy/arm/isa.py +409 -0
- nervapy/arm/literal_pool.py +331 -0
- nervapy/arm/microarchitecture.py +211 -0
- nervapy/arm/pseudo.py +652 -0
- nervapy/arm/registers.py +1458 -0
- nervapy/arm/vfpneon.py +4092 -0
- nervapy/arm.py +13 -0
- nervapy/c/__init__.py +1 -0
- nervapy/c/types.py +436 -0
- nervapy/codegen.py +99 -0
- nervapy/common/__init__.py +4 -0
- nervapy/common/function.py +5 -0
- nervapy/common/regalloc.py +121 -0
- nervapy/constant_data.py +282 -0
- nervapy/encoder.py +246 -0
- nervapy/formats/__init__.py +2 -0
- nervapy/formats/elf/__init__.py +4 -0
- nervapy/formats/elf/file.py +178 -0
- nervapy/formats/elf/image.py +106 -0
- nervapy/formats/elf/section.py +422 -0
- nervapy/formats/elf/symbol.py +281 -0
- nervapy/formats/macho/__init__.py +2 -0
- nervapy/formats/macho/file.py +123 -0
- nervapy/formats/macho/image.py +143 -0
- nervapy/formats/macho/section.py +322 -0
- nervapy/formats/macho/symbol.py +158 -0
- nervapy/formats/mscoff/__init__.py +8 -0
- nervapy/formats/mscoff/image.py +132 -0
- nervapy/formats/mscoff/section.py +181 -0
- nervapy/formats/mscoff/symbol.py +148 -0
- nervapy/function.py +136 -0
- nervapy/literal.py +731 -0
- nervapy/loader.py +188 -0
- nervapy/name.py +159 -0
- nervapy/parse.py +52 -0
- nervapy/stream.py +58 -0
- nervapy/util.py +126 -0
- nervapy/writer.py +518 -0
- nervapy/x86_64/__init__.py +324 -0
- nervapy/x86_64/__main__.py +407 -0
- nervapy/x86_64/abi.py +517 -0
- nervapy/x86_64/amd.py +6464 -0
- nervapy/x86_64/avx.py +102029 -0
- nervapy/x86_64/crypto.py +1533 -0
- nervapy/x86_64/encoding.py +424 -0
- nervapy/x86_64/fma.py +19138 -0
- nervapy/x86_64/function.py +2707 -0
- nervapy/x86_64/generic.py +23384 -0
- nervapy/x86_64/instructions.py +500 -0
- nervapy/x86_64/isa.py +476 -0
- nervapy/x86_64/lower.py +126 -0
- nervapy/x86_64/mask.py +2593 -0
- nervapy/x86_64/meta.py +143 -0
- nervapy/x86_64/mmxsse.py +17265 -0
- nervapy/x86_64/nacl.py +327 -0
- nervapy/x86_64/operand.py +1204 -0
- nervapy/x86_64/options.py +21 -0
- nervapy/x86_64/pseudo.py +686 -0
- nervapy/x86_64/registers.py +1225 -0
- nervapy/x86_64/types.py +17 -0
- nervapy/x86_64/uarch.py +580 -0
- pynerva-0.0.7.dist-info/METADATA +310 -0
- pynerva-0.0.7.dist-info/RECORD +74 -0
- pynerva-0.0.7.dist-info/WHEEL +4 -0
- pynerva-0.0.7.dist-info/licenses/LICENSE.rst +15 -0
nervapy/x86_64/meta.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# This file is part of PeachPy package and is licensed under the Simplified BSD license.
|
|
2
|
+
# See license.rst for the full text of the license.
|
|
3
|
+
|
|
4
|
+
from enum import Enum
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SectionType(Enum):
|
|
8
|
+
code = 0
|
|
9
|
+
const_data = 1
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Section(object):
|
|
13
|
+
max_alignment = 4096
|
|
14
|
+
|
|
15
|
+
def __init__(self, type, alignment_byte=None):
|
|
16
|
+
from nervapy.util import is_uint8
|
|
17
|
+
|
|
18
|
+
if not isinstance(type, SectionType):
|
|
19
|
+
raise TypeError("Type %s is not in SectionType enumeration" % str(type))
|
|
20
|
+
if alignment_byte is None:
|
|
21
|
+
alignment_byte = 0
|
|
22
|
+
elif not is_uint8(alignment_byte):
|
|
23
|
+
raise TypeError(
|
|
24
|
+
"Alignment byte %s is not an 8-bit unsigned integer"
|
|
25
|
+
% str(alignment_byte)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
self.type = type
|
|
29
|
+
self.alignment_byte = alignment_byte
|
|
30
|
+
self.content = bytearray()
|
|
31
|
+
self.symbols = list()
|
|
32
|
+
self.relocations = list()
|
|
33
|
+
self._alignment = 1
|
|
34
|
+
|
|
35
|
+
def __len__(self):
|
|
36
|
+
return len(self.content)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def alignment(self):
|
|
40
|
+
return self._alignment
|
|
41
|
+
|
|
42
|
+
@alignment.setter
|
|
43
|
+
def alignment(self, alignment):
|
|
44
|
+
from nervapy.util import is_int
|
|
45
|
+
|
|
46
|
+
if not is_int(alignment):
|
|
47
|
+
raise TypeError("Alignment %s is not an integer" % str(alignment))
|
|
48
|
+
if alignment < 0:
|
|
49
|
+
raise ValueError("Alignment %d is not a positive integer" % alignment)
|
|
50
|
+
if alignment & (alignment - 1) != 0:
|
|
51
|
+
raise ValueError("Alignment %d is not a power of 2" % alignment)
|
|
52
|
+
if alignment > Section.max_alignment:
|
|
53
|
+
raise ValueError(
|
|
54
|
+
"Alignment %d exceeds maximum alignment (%d)"
|
|
55
|
+
% (alignment, Section.max_alignment)
|
|
56
|
+
)
|
|
57
|
+
if alignment == 0:
|
|
58
|
+
alignment = 1
|
|
59
|
+
self._alignment = alignment
|
|
60
|
+
|
|
61
|
+
def add_symbol(self, symbol):
|
|
62
|
+
if not isinstance(symbol, Symbol):
|
|
63
|
+
raise TypeError("Symbol %s is not an instance of Symbol type" % str(symbol))
|
|
64
|
+
self.symbols.append(symbol)
|
|
65
|
+
|
|
66
|
+
def add_relocation(self, relocation):
|
|
67
|
+
if not isinstance(relocation, Relocation):
|
|
68
|
+
raise TypeError(
|
|
69
|
+
"Relocation %s is not an instance of Relocation type" % str(relocation)
|
|
70
|
+
)
|
|
71
|
+
self.relocations.append(relocation)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class RelocationType(Enum):
|
|
75
|
+
"""Relocation for RIP-relative disp32 offset"""
|
|
76
|
+
|
|
77
|
+
rip_disp32 = 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Relocation:
|
|
81
|
+
def __init__(self, offset, type, symbol=None, program_counter=None):
|
|
82
|
+
from nervapy.util import is_int
|
|
83
|
+
|
|
84
|
+
if not is_int(offset):
|
|
85
|
+
raise TypeError("Offset %s is not an integer" % str(offset))
|
|
86
|
+
if offset < 0:
|
|
87
|
+
raise ValueError("Offset %d is negative" % offset)
|
|
88
|
+
if not isinstance(type, RelocationType):
|
|
89
|
+
raise TypeError(
|
|
90
|
+
"Relocation type %s is not in RelocationType enumeration" % str(type)
|
|
91
|
+
)
|
|
92
|
+
if symbol is not None and not isinstance(symbol, Symbol):
|
|
93
|
+
raise TypeError("Symbol %s is not an instance of Symbol type" % str(symbol))
|
|
94
|
+
if program_counter is not None:
|
|
95
|
+
if not is_int(program_counter):
|
|
96
|
+
raise TypeError(
|
|
97
|
+
"Program counter %s is not an integer" % str(program_counter)
|
|
98
|
+
)
|
|
99
|
+
if program_counter < 0:
|
|
100
|
+
raise TypeError("Program counter %d is negative" % program_counter)
|
|
101
|
+
|
|
102
|
+
self.offset = offset
|
|
103
|
+
self.type = type
|
|
104
|
+
self.symbol = symbol
|
|
105
|
+
self.program_counter = program_counter
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class SymbolType(Enum):
|
|
109
|
+
"""Literal constant"""
|
|
110
|
+
|
|
111
|
+
literal_constant = 0
|
|
112
|
+
"""Label"""
|
|
113
|
+
label = 1
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class Symbol:
|
|
117
|
+
def __init__(self, offset, type, name=None, size=None):
|
|
118
|
+
from nervapy.util import is_int
|
|
119
|
+
|
|
120
|
+
if not is_int(offset):
|
|
121
|
+
raise TypeError("Offset %s is not an integer" % str(offset))
|
|
122
|
+
if offset < 0:
|
|
123
|
+
raise ValueError("Offset %d is negative" % offset)
|
|
124
|
+
if not isinstance(type, SymbolType):
|
|
125
|
+
raise TypeError(
|
|
126
|
+
"Symbol type %s is not in SymbolType enumeration" % str(type)
|
|
127
|
+
)
|
|
128
|
+
from nervapy.name import Name
|
|
129
|
+
|
|
130
|
+
if name is not None and not (
|
|
131
|
+
isinstance(name, tuple) and all(isinstance(part, Name) for part in name)
|
|
132
|
+
):
|
|
133
|
+
raise TypeError("Name %s must be a tuple of Name objects" % str(name))
|
|
134
|
+
if size is not None:
|
|
135
|
+
if not is_int(size):
|
|
136
|
+
raise TypeError("Size %s is not an integer" % str(size))
|
|
137
|
+
if size < 0:
|
|
138
|
+
raise ValueError("Size %d is negative" % size)
|
|
139
|
+
|
|
140
|
+
self.offset = offset
|
|
141
|
+
self.type = type
|
|
142
|
+
self.name = ".".join(map(str, name))
|
|
143
|
+
self.size = size
|