base
– Base environment¶
-
class
pwnypack.shellcode.base.
BaseEnvironment
[source]¶ The abstract base for all shellcode environments.
-
REGISTER_WIDTH
= None¶ Mapping of register -> width, filled by __init__ based on REGISTER_WIDTH_MAP
-
class
TranslateOutput
[source]¶ Output format the translate function.
-
assembly
= 1¶ Emit assembly source.
-
code
= 0¶ Emit binary, executable code.
-
meta
= 2¶ Emit the declarative version of the translated function.
-
-
alloc_buffer
(length)[source]¶ Allocate a buffer (a range of uninitialized memory).
Parameters: length (int) – The length of the buffer to allocate. Returns: The object used to address this buffer. Return type: Buffer
-
alloc_data
(value)[source]¶ Allocate a piece of data that will be included in the shellcode body.
Parameters: value – The value to add to the shellcode. Can be bytes or string type. Returns: The offset used to address the data. Return type: Offset
-
assemble
(ops)[source]¶ Assemble a list of operations into executable code.
Parameters: ops (list) – A list of shellcode operations. Returns: The executable code that implements the shellcode. Return type: bytes
-
compile
(ops)[source]¶ Translate a list of operations into its assembler source.
Parameters: ops (list) – A list of shellcode operations. Returns: The assembler source code that implements the shellcode. Return type: str
-
reg_add
(reg, value)[source]¶ Add a value to a register. The value can be another
Register
, anOffset
, aBuffer
, an integer orNone
.Parameters: - reg (pwnypack.shellcode.types.Register) – The register to add the value to.
- value – The value to add to the register.
Returns: A list of mnemonics that will add
value
toreg
.Return type: list
-
reg_load
(reg, value)[source]¶ Load a value into a register. The value can be a string or binary (in which case the value is passed to
alloc_data()
), anotherRegister
, anOffset
orBuffer
, an integer immediate, alist
ortuple
or a syscall invocation.Parameters: - reg (pwnypack.shellcode.types.Register) – The register to load the value into.
- value – The value to load into the register.
Returns: A list of mnemonics that will load value into reg.
Return type: list
-
classmethod
translate
(f=None, *, output=TranslateOutput.code, **kwargs)[source]¶ Decorator that turns a function into a shellcode emitting function.
Parameters: - f (callable) – The function to decorate. If
f
isNone
a decorator will be returned instead. - output (TranslateOutput) – The output format the shellcode function will produce.
- **kwargs – Keyword arguments are passed to shellcode environment constructor.
Returns: A decorator that will translate the given function into a shellcode generator
Examples
>>> from pwny import * >>> @sc.LinuxX86Mutable.translate ... def shellcode(): ... sys_exit(0)
>>> @sc.LinuxX86Mutable.translate(output=1) ... def shellcode(): ... sys_exit(0)
- f (callable) – The function to decorate. If
-