<commit_before># Copyright (C) 2017 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import mock
import os.path

from lib.api.dse import Capcom
from lib.core.driver import Driver

@mock.patch("lib.core.driver.os.path.exists")
@mock.patch("lib.core.driver.shutil")
def test_copy_driver(p, q):
    d = Driver("foo", "bar")
    d.is_64bit = True
    d.copy_driver()

    q.assert_called_once_with("bin\\foo-x64.sys")
    sysroot = os.path.expandvars("%SystemRoot%")
    p.copy.assert_called_once_with(
        "bin\\foo-x64.sys", "%s\\sysnative\\drivers\\bar.sys" % sysroot
    )

class TestCapcom(object):
    @mock.patch("lib.core.driver.platform")
    def setup(self, p):
        p.machine.return_value = "amd64"
        self.c = Capcom()

    def test_is64bit(self):
        # Ensure that the above works.
        assert self.c.is_64bit is True

    def test_primitives(self):
        sc = self.c.arch.get_MmGetSystemRoutineAddress().encode("hex")
        assert sc == "48890df1ffffffc3"

        sc = self.c.arch.read32(0x1122334455667788).encode("hex")
        assert sc == "48b88877665544332211488b00488905e4ffffffc3"

        sc = self.c.arch.write32(0x1122334455667788, 0x42424242).encode("hex")
        assert sc == "48b88877665544332211c70042424242c3"<commit_msg>resolve issue with patching lib<commit_after># Copyright (C) 2017 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import mock
import os.path

from lib.api.dse import Capcom
from lib.core.driver import Driver

@mock.patch("os.path.exists")
@mock.patch("shutil.copy")
def test_copy_driver(p, q):
    d = Driver("foo", "bar")
    d.is_64bit = True
    d.copy_driver()

    q.assert_called_once_with("bin\\foo-x64.sys")
    sysroot = os.path.expandvars("%SystemRoot%")
    p.assert_called_once_with(
        "bin\\foo-x64.sys", "%s\\sysnative\\drivers\\bar.sys" % sysroot
    )

class TestCapcom(object):
    @mock.patch("platform.machine")
    def setup(self, p):
        p.return_value = "amd64"
        self.c = Capcom()

    def test_is64bit(self):
        # Ensure that the above works.
        assert self.c.is_64bit is True

    def test_primitives(self):
        sc = self.c.arch.get_MmGetSystemRoutineAddress().encode("hex")
        assert sc == "48890df1ffffffc3"

        sc = self.c.arch.read32(0x1122334455667788).encode("hex")
        assert sc == "48b88877665544332211488b00488905e4ffffffc3"

        sc = self.c.arch.write32(0x1122334455667788, 0x42424242).encode("hex")
        assert sc == "48b88877665544332211c70042424242c3"
{'fraction_non_alphanumeric': 0.13148148148148148, 'fraction_numerical': 0.09851851851851852, 'mean_word_length': 3.328525641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7221798', 'n_tokens_mistral': 1140, 'n_tokens_neox': 967, 'n_words': 183}