Exemplo n.º 1
0
def test_target_assume():
    target = pwny.Target()
    target.assume(
        pwny.Target(arch=pwny.Target.Arch.arm,
                    endian=pwny.Target.Endian.little,
                    bits=64,
                    mode=2))
    assert target.arch is pwny.Target.Arch.arm and \
           target.endian == pwny.Target.Endian.little and \
           target.bits == 64 and \
           target.mode == 2
Exemplo n.º 2
0
def setup():
    pwny.target.assume(pwny.Target(arch=pwny.Target.Arch.x86))
Exemplo n.º 3
0
from nose.tools import raises
import pwny

target_little_endian = pwny.Target(arch=pwny.Target.Arch.unknown,
                                   endian=pwny.Target.Endian.little)
target_big_endian = pwny.Target(arch=pwny.Target.Arch.unknown,
                                endian=pwny.Target.Endian.big)


def test_pack():
    assert pwny.pack('I', 0x41424344) == b'DCBA'


def test_pack_format_with_endian():
    assert pwny.pack('>I', 0x41424344) == b'ABCD'


def test_pack_explicit_endian():
    assert pwny.pack('I', 0x41424344, endian=pwny.Target.Endian.big) == b'ABCD'


def test_pack_explicit_target():
    assert pwny.pack('I', 0x41424344, target=target_big_endian) == b'ABCD'


@raises(NotImplementedError)
def test_pack_invalid_endian():
    pwny.pack('I', 1, endian='invalid')


def test_unpack():
Exemplo n.º 4
0
import pytest

import pwny


target_x86_32 = pwny.Target('x86', 32)
target_x86_64 = pwny.Target('x86', 64)
target_arm_32_le = pwny.Target('arm', 32, pwny.Target.Endian.little)
target_arm_32_be = pwny.Target('arm', 32, pwny.Target.Endian.big)
target_armv7m_32_le = pwny.Target('arm', 32, pwny.Target.Endian.little, mode=pwny.Target.Mode.arm_m_class)
target_armv7m_32_be = pwny.Target('arm', 32, pwny.Target.Endian.big, mode=pwny.Target.Mode.arm_m_class)
target_arm_64_le = pwny.Target('arm', 64, pwny.Target.Endian.little)
target_arm_64_be = pwny.Target('arm', 64, pwny.Target.Endian.big)
target_unknown_32 = pwny.Target('unknown', 32, pwny.Target.Endian.little)


ASM_TESTS = [
    # Note: set up sets default arch to x86 32bit
    (None, pwny.AsmSyntax.nasm, 'mov al,[0xced]', b'\xa0\xed\x0c\x00\x00'),
    (target_x86_32, None, 'mov al,[0xced]', b'\xa0\xed\x0c\x00\x00'),
    (target_x86_32, pwny.AsmSyntax.nasm, 'mov al,[0xced]', b'\xa0\xed\x0c\x00\x00'),
    (target_x86_32, pwny.AsmSyntax.att, 'movb 0xced, %al', b'\xa0\xed\x0c\x00\x00'),
    (target_x86_32, pwny.AsmSyntax.intel, 'mov al, byte ptr [0xced]', b'\xa0\xed\x0c\x00\x00'),

    (target_x86_64, None, 'mov al,[0xced]', b'\x8a\x04%\xed\x0c\x00\x00'),
    (target_x86_64, pwny.AsmSyntax.nasm, 'mov al,[0xced]', b'\x8a\x04%\xed\x0c\x00\x00'),
    (target_x86_64, pwny.AsmSyntax.att, 'movb 0xced, %al', b'\x8a\x04%\xed\x0c\x00\x00'),
    (target_x86_64, pwny.AsmSyntax.intel, 'mov al, byte ptr [0xced]', b'\x8a\x04%\xed\x0c\x00\x00'),

    (target_arm_32_le, None, 'add r0, r1, #0', b'\x00\x00\x81\xe2'),
    (target_arm_32_be, None, 'add r0, r1, #0', b'\xe2\x81\x00\x00'),
Exemplo n.º 5
0
from nose.tools import raises
import pwny

SOURCE_ASM = 'mov al, [0xced]'
RESULT_BIN_32 = b'\xa0\xed\x0c\x00\x00'
RESULT_BIN_64 = b'\x8a\x04%\xed\x0c\x00\x00'

SOURCE_DISASM = b'\x5f'
RESULT_DISASM_32 = ['pop edi']
RESULT_DISASM_64 = ['pop rdi']

target_x86_32 = pwny.Target('x86', 32)
target_x86_64 = pwny.Target('x86', 64)
target_arm_32 = pwny.Target('arm', 32)


def test_asm_with_default_target():
    # Note: set up sets default arch to x86 32bit
    assert pwny.asm(SOURCE_ASM) == RESULT_BIN_32


def test_asm_with_target_x86_32():
    assert pwny.asm(SOURCE_ASM, target=target_x86_32) == RESULT_BIN_32


def test_asm_with_target_x86_64():
    assert pwny.asm(SOURCE_ASM, target=target_x86_64) == RESULT_BIN_64


@raises(SyntaxError)
def test_asm_syntax_error():
Exemplo n.º 6
0
def target():
    pwny.target.assume(
        pwny.Target(arch=pwny.Target.Arch.x86, bits=pwny.Target.Bits.bits_32))
Exemplo n.º 7
0
def test_set_invalid_bits():
    pwny.Target(bits=33)
Exemplo n.º 8
0
def test_default_bits_unsupported():
    target = pwny.Target(arch=pwny.Target.Arch.unknown)
    _ = target.bits
Exemplo n.º 9
0
def test_set__bits():
    target = pwny.Target(arch=pwny.Target.Arch.x86, bits=64)
    assert target.bits == 64
Exemplo n.º 10
0
def test_default_arch_x86():
    with mock.patch('platform.machine') as platform_mock:
        platform_mock.return_value = 'i386'
        assert pwny.Target().arch is pwny.Target.Arch.x86
Exemplo n.º 11
0
def test_default_bits_x86():
    target = pwny.Target(arch=pwny.Target.Arch.x86)
    assert target.bits == 32
Exemplo n.º 12
0
def test_set_endian():
    target = pwny.Target(arch=pwny.Target.Arch.unknown,
                         endian=pwny.Target.Endian.big)
    assert target.endian is pwny.Target.Endian.big
Exemplo n.º 13
0
def test_default_endian():
    assert pwny.Target().endian is pwny.Target.Endian.little
Exemplo n.º 14
0
def test_set_arch():
    with mock.patch('platform.architecture') as platform_mock:
        platform_mock.return_value = ('64bit', )
        target = pwny.Target(arch=pwny.Target.Arch.x86)
        assert target.arch is pwny.Target.Arch.x86
Exemplo n.º 15
0
def test_default_arch_64bit():
    with mock.patch('platform.architecture') as platform_mock:
        platform_mock.return_value = ('64bit', )
        assert pwny.Target().bits is pwny.Target.Bits.bits_64
Exemplo n.º 16
0
def test_default_arch_unknown():
    with mock.patch('platform.machine') as platform_mock:
        platform_mock.return_value = 'unknown'
        assert pwny.Target().arch is pwny.Target.Arch.unknown