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/nacl.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
|
|
7
|
+
import nervapy.stream
|
|
8
|
+
from nervapy.x86_64.instructions import Instruction
|
|
9
|
+
from nervapy.x86_64.operand import (check_operand, format_operand_type,
|
|
10
|
+
is_imm32, is_r32)
|
|
11
|
+
|
|
12
|
+
# Permitted pseudo-instructions:
|
|
13
|
+
#
|
|
14
|
+
# - [rep] cmps %nacl:(%rsi),%nacl:(%rdi),%rZP (sandboxed cmps)
|
|
15
|
+
# mov %esi,%esi
|
|
16
|
+
# lea (%rZP,%rsi,1),%rsi
|
|
17
|
+
# mov %edi,%edi
|
|
18
|
+
# lea (%rZP,%rdi,1),%rdi
|
|
19
|
+
# [rep] cmps (%rsi),(%rdi)
|
|
20
|
+
#
|
|
21
|
+
# - [rep] movs %nacl:(%rsi),%nacl:(%rdi),%rZP (sandboxed movs)
|
|
22
|
+
# mov %esi,%esi
|
|
23
|
+
# lea (%rZP,%rsi,1),%rsi
|
|
24
|
+
# mov %edi,%edi
|
|
25
|
+
# lea (%rZP,%rdi,1),%rdi
|
|
26
|
+
# [rep] movs (%rsi),(%rdi)
|
|
27
|
+
#
|
|
28
|
+
# - naclasp ...,%rZP (sandboxed stack increment)
|
|
29
|
+
# add ...,%esp
|
|
30
|
+
# add %rZP,%rsp
|
|
31
|
+
#
|
|
32
|
+
# - naclcall %eXX,%rZP (sandboxed indirect call)
|
|
33
|
+
# and $-32, %eXX
|
|
34
|
+
# add %rZP, %rXX
|
|
35
|
+
# call *%rXX
|
|
36
|
+
# Note: the assembler ensures all calls (including naclcall) will end at the bundle boundary.
|
|
37
|
+
#
|
|
38
|
+
# - nacljmp %eXX,%rZP (sandboxed indirect jump)
|
|
39
|
+
# and $-32,%eXX
|
|
40
|
+
# add %rZP,%rXX
|
|
41
|
+
# jmp *%rXX
|
|
42
|
+
#
|
|
43
|
+
# - naclrestbp ...,%rZP (sandboxed %ebp/rbp restore)
|
|
44
|
+
# mov ...,%ebp
|
|
45
|
+
# add %rZP,%rbp
|
|
46
|
+
#
|
|
47
|
+
# - naclrestsp ...,%rZP (sandboxed %esp/rsp restore)
|
|
48
|
+
# mov ...,%esp
|
|
49
|
+
# add %rZP,%rsp
|
|
50
|
+
#
|
|
51
|
+
# - naclrestsp_noflags ...,%rZP (sandboxed %esp/rsp restore)
|
|
52
|
+
# mov ...,%esp
|
|
53
|
+
# lea (%rsp,%rZP,1),%rsp
|
|
54
|
+
#
|
|
55
|
+
# - naclspadj $N,%rZP (sandboxed %esp/rsp restore from %rbp; includes $N offset)
|
|
56
|
+
# lea N(%rbp),%esp
|
|
57
|
+
# add %rZP,%rsp
|
|
58
|
+
#
|
|
59
|
+
# - naclssp ...,%rZP (sandboxed stack decrement)
|
|
60
|
+
# SUB(esp, ...)
|
|
61
|
+
# ADD(rZP, rsp)
|
|
62
|
+
#
|
|
63
|
+
# - [rep] scas %nacl:(%rdi),%?ax,%rZP (sandboxed stos)
|
|
64
|
+
# mov %edi,%edi
|
|
65
|
+
# lea (%rZP,%rdi,1),%rdi
|
|
66
|
+
# [rep] scas (%rdi),%?ax
|
|
67
|
+
# [rep] stos %?ax,%nacl:(%rdi),%rZP
|
|
68
|
+
#
|
|
69
|
+
# - (sandboxed stos) mov %edi,%edi
|
|
70
|
+
# LEA(rdi, [rZP + rdi*1])
|
|
71
|
+
# REP.STOS([rdi], al/ax/eax/rax)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class NACLJMP(Instruction):
|
|
75
|
+
"""Sandboxed Indirect Jump"""
|
|
76
|
+
|
|
77
|
+
def __init__(self, *args, **kwargs):
|
|
78
|
+
"""Supported forms:
|
|
79
|
+
|
|
80
|
+
* NACLJMP(r32)
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
origin = kwargs.get("origin")
|
|
84
|
+
prototype = kwargs.get("prototype")
|
|
85
|
+
if (
|
|
86
|
+
origin is None
|
|
87
|
+
and prototype is None
|
|
88
|
+
and nervapy.x86_64.options.get_debug_level() > 0
|
|
89
|
+
):
|
|
90
|
+
origin = inspect.stack()
|
|
91
|
+
super(NACLJMP, self).__init__("NACLJMP", origin=origin, prototype=prototype)
|
|
92
|
+
self.operands = tuple(map(check_operand, args))
|
|
93
|
+
if len(self.operands) != 1:
|
|
94
|
+
raise SyntaxError('Instruction "NACLJMP" requires 1 operand')
|
|
95
|
+
self.in_regs = (True,)
|
|
96
|
+
self.out_regs = (False,)
|
|
97
|
+
self.out_operands = (True,)
|
|
98
|
+
self._gas_name = "nacljmp"
|
|
99
|
+
if not is_r32(self.operands[0]):
|
|
100
|
+
raise SyntaxError(
|
|
101
|
+
"Invalid operand types: NACLJMP "
|
|
102
|
+
+ ", ".join(map(format_operand_type, self.operands))
|
|
103
|
+
)
|
|
104
|
+
if nervapy.stream.active_stream is not None:
|
|
105
|
+
nervapy.stream.active_stream.add_instruction(self)
|
|
106
|
+
|
|
107
|
+
def _lower(self):
|
|
108
|
+
from nervapy.stream import InstructionStream
|
|
109
|
+
from nervapy.x86_64.generic import ADD, AND, JMP
|
|
110
|
+
from nervapy.x86_64.registers import r15
|
|
111
|
+
|
|
112
|
+
with InstructionStream() as stream:
|
|
113
|
+
AND(self.operands[0], -32)
|
|
114
|
+
ADD(self.operands[0].as_qword, r15)
|
|
115
|
+
JMP(self.operands[0].as_qword)
|
|
116
|
+
return stream.instructions
|
|
117
|
+
|
|
118
|
+
def encode(self):
|
|
119
|
+
import operator
|
|
120
|
+
|
|
121
|
+
return bytearray().join(map(operator.methodcaller("encode"), self._lower()))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class NACLASP(Instruction):
|
|
125
|
+
"""Sandboxed RSP Increment (Addition)"""
|
|
126
|
+
|
|
127
|
+
def __init__(self, *args, **kwargs):
|
|
128
|
+
"""Supported forms:
|
|
129
|
+
|
|
130
|
+
* NACLASP(r32)
|
|
131
|
+
* NACLASP(imm32)
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
origin = kwargs.get("origin")
|
|
135
|
+
prototype = kwargs.get("prototype")
|
|
136
|
+
if (
|
|
137
|
+
origin is None
|
|
138
|
+
and prototype is None
|
|
139
|
+
and nervapy.x86_64.options.get_debug_level() > 0
|
|
140
|
+
):
|
|
141
|
+
origin = inspect.stack()
|
|
142
|
+
super(NACLASP, self).__init__("NACLASP", origin=origin, prototype=prototype)
|
|
143
|
+
self.operands = tuple(map(check_operand, args))
|
|
144
|
+
if len(self.operands) != 1:
|
|
145
|
+
raise SyntaxError('Instruction "NACLASP" requires 1 operand')
|
|
146
|
+
self.in_regs = (True,)
|
|
147
|
+
self.out_regs = (False,)
|
|
148
|
+
self.out_operands = (True,)
|
|
149
|
+
self._gas_name = "naclasp"
|
|
150
|
+
if not is_r32(self.operands[0]) and not is_imm32(self.operands[0]):
|
|
151
|
+
raise SyntaxError(
|
|
152
|
+
"Invalid operand types: NACLASP"
|
|
153
|
+
+ ", ".join(map(format_operand_type, self.operands))
|
|
154
|
+
)
|
|
155
|
+
if nervapy.stream.active_stream is not None:
|
|
156
|
+
nervapy.stream.active_stream.add_instruction(self)
|
|
157
|
+
|
|
158
|
+
def _lower(self):
|
|
159
|
+
from nervapy.stream import InstructionStream
|
|
160
|
+
from nervapy.x86_64.generic import ADD
|
|
161
|
+
from nervapy.x86_64.registers import esp, r15, rsp
|
|
162
|
+
|
|
163
|
+
with InstructionStream() as stream:
|
|
164
|
+
ADD(esp, self.operands[0])
|
|
165
|
+
ADD(rsp, r15)
|
|
166
|
+
return stream.instructions
|
|
167
|
+
|
|
168
|
+
def encode(self):
|
|
169
|
+
import operator
|
|
170
|
+
|
|
171
|
+
return bytearray().join(map(operator.methodcaller("encode"), self._lower()))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class NACLSSP(Instruction):
|
|
175
|
+
"""Sandboxed RSP Decrement (Subtraction)"""
|
|
176
|
+
|
|
177
|
+
def __init__(self, *args, **kwargs):
|
|
178
|
+
"""Supported forms:
|
|
179
|
+
|
|
180
|
+
* NACLSSP(r32)
|
|
181
|
+
* NACLSSP(imm32)
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
origin = kwargs.get("origin")
|
|
185
|
+
prototype = kwargs.get("prototype")
|
|
186
|
+
if (
|
|
187
|
+
origin is None
|
|
188
|
+
and prototype is None
|
|
189
|
+
and nervapy.x86_64.options.get_debug_level() > 0
|
|
190
|
+
):
|
|
191
|
+
origin = inspect.stack()
|
|
192
|
+
super(NACLSSP, self).__init__("NACLSSP", origin=origin, prototype=prototype)
|
|
193
|
+
self.operands = tuple(map(check_operand, args))
|
|
194
|
+
if len(self.operands) != 1:
|
|
195
|
+
raise SyntaxError('Instruction "NACLSSP" requires 1 operand')
|
|
196
|
+
self.in_regs = (True,)
|
|
197
|
+
self.out_regs = (False,)
|
|
198
|
+
self.out_operands = (True,)
|
|
199
|
+
self._gas_name = "naclssp"
|
|
200
|
+
if not is_r32(self.operands[0]) and not is_imm32(self.operands[0]):
|
|
201
|
+
raise SyntaxError(
|
|
202
|
+
"Invalid operand types: NACLSSP"
|
|
203
|
+
+ ", ".join(map(format_operand_type, self.operands))
|
|
204
|
+
)
|
|
205
|
+
if nervapy.stream.active_stream is not None:
|
|
206
|
+
nervapy.stream.active_stream.add_instruction(self)
|
|
207
|
+
|
|
208
|
+
def _lower(self):
|
|
209
|
+
from nervapy.stream import InstructionStream
|
|
210
|
+
from nervapy.x86_64.generic import ADD, SUB
|
|
211
|
+
from nervapy.x86_64.registers import esp, r15, rsp
|
|
212
|
+
|
|
213
|
+
with InstructionStream() as stream:
|
|
214
|
+
SUB(esp, self.operands[0])
|
|
215
|
+
ADD(rsp, r15)
|
|
216
|
+
return stream.instructions
|
|
217
|
+
|
|
218
|
+
def encode(self):
|
|
219
|
+
import operator
|
|
220
|
+
|
|
221
|
+
return bytearray().join(map(operator.methodcaller("encode"), self._lower()))
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class NACLRESTSP(Instruction):
|
|
225
|
+
"""Sandboxed RSP Restore"""
|
|
226
|
+
|
|
227
|
+
def __init__(self, *args, **kwargs):
|
|
228
|
+
"""Supported forms:
|
|
229
|
+
|
|
230
|
+
* NACLRESTSP(r32)
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
origin = kwargs.get("origin")
|
|
234
|
+
prototype = kwargs.get("prototype")
|
|
235
|
+
if (
|
|
236
|
+
origin is None
|
|
237
|
+
and prototype is None
|
|
238
|
+
and nervapy.x86_64.options.get_debug_level() > 0
|
|
239
|
+
):
|
|
240
|
+
origin = inspect.stack()
|
|
241
|
+
super(NACLRESTSP, self).__init__(
|
|
242
|
+
"NACLRESTSP", origin=origin, prototype=prototype
|
|
243
|
+
)
|
|
244
|
+
self.operands = tuple(map(check_operand, args))
|
|
245
|
+
if len(self.operands) != 1:
|
|
246
|
+
raise SyntaxError('Instruction "NACLRESTSP" requires 1 operand')
|
|
247
|
+
self.in_regs = (True,)
|
|
248
|
+
self.out_regs = (False,)
|
|
249
|
+
self.out_operands = (True,)
|
|
250
|
+
self._gas_name = "naclrestsp"
|
|
251
|
+
if is_r32(self.operands[0]):
|
|
252
|
+
pass
|
|
253
|
+
else:
|
|
254
|
+
raise SyntaxError(
|
|
255
|
+
"Invalid operand types: NACLRESTSP "
|
|
256
|
+
+ ", ".join(map(format_operand_type, self.operands))
|
|
257
|
+
)
|
|
258
|
+
if nervapy.stream.active_stream is not None:
|
|
259
|
+
nervapy.stream.active_stream.add_instruction(self)
|
|
260
|
+
|
|
261
|
+
def _lower(self):
|
|
262
|
+
from nervapy.stream import InstructionStream
|
|
263
|
+
from nervapy.x86_64.generic import ADD, MOV
|
|
264
|
+
from nervapy.x86_64.registers import esp, r15, rsp
|
|
265
|
+
|
|
266
|
+
with InstructionStream() as stream:
|
|
267
|
+
MOV(esp, self.operands[0])
|
|
268
|
+
ADD(rsp, r15)
|
|
269
|
+
return stream.instructions
|
|
270
|
+
|
|
271
|
+
def encode(self):
|
|
272
|
+
import operator
|
|
273
|
+
|
|
274
|
+
return bytearray().join(map(operator.methodcaller("encode"), self._lower()))
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class NACLRESTBP(Instruction):
|
|
278
|
+
"""Sandboxed RBP Restore"""
|
|
279
|
+
|
|
280
|
+
def __init__(self, *args, **kwargs):
|
|
281
|
+
"""Supported forms:
|
|
282
|
+
|
|
283
|
+
* NACLRESTBP(r32)
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
origin = kwargs.get("origin")
|
|
287
|
+
prototype = kwargs.get("prototype")
|
|
288
|
+
if (
|
|
289
|
+
origin is None
|
|
290
|
+
and prototype is None
|
|
291
|
+
and nervapy.x86_64.options.get_debug_level() > 0
|
|
292
|
+
):
|
|
293
|
+
origin = inspect.stack()
|
|
294
|
+
super(NACLRESTBP, self).__init__(
|
|
295
|
+
"NACLRESTBP", origin=origin, prototype=prototype
|
|
296
|
+
)
|
|
297
|
+
self.operands = tuple(map(check_operand, args))
|
|
298
|
+
if len(self.operands) != 1:
|
|
299
|
+
raise SyntaxError('Instruction "NACLRESTBP" requires 1 operand')
|
|
300
|
+
self.in_regs = (True,)
|
|
301
|
+
self.out_regs = (False,)
|
|
302
|
+
self.out_operands = (True,)
|
|
303
|
+
self._gas_name = "naclrestbp"
|
|
304
|
+
if is_r32(self.operands[0]):
|
|
305
|
+
pass
|
|
306
|
+
else:
|
|
307
|
+
raise SyntaxError(
|
|
308
|
+
"Invalid operand types: NACLRESTBP "
|
|
309
|
+
+ ", ".join(map(format_operand_type, self.operands))
|
|
310
|
+
)
|
|
311
|
+
if nervapy.stream.active_stream is not None:
|
|
312
|
+
nervapy.stream.active_stream.add_instruction(self)
|
|
313
|
+
|
|
314
|
+
def _lower(self):
|
|
315
|
+
from nervapy.stream import InstructionStream
|
|
316
|
+
from nervapy.x86_64.generic import ADD, MOV
|
|
317
|
+
from nervapy.x86_64.registers import ebp, r15, rbp
|
|
318
|
+
|
|
319
|
+
with InstructionStream() as stream:
|
|
320
|
+
MOV(ebp, self.operands[0])
|
|
321
|
+
ADD(rbp, r15)
|
|
322
|
+
return stream.instructions
|
|
323
|
+
|
|
324
|
+
def encode(self):
|
|
325
|
+
import operator
|
|
326
|
+
|
|
327
|
+
return bytearray().join(map(operator.methodcaller("encode"), self._lower()))
|