<commit_before>#!/usr/bin/env python
# Copyright (C) 2015 <NAME>
# This file is part of my GSoC'15 project for Cuckoo Sandbox:
#	http://www.cuckoosandbox.org
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.

import socket
import datetime
from bson import BSON
from subprocess import check_output
from filetimes import dt_to_filetime

class CuckooHost:

    sockets = {}
    descriptions = {}
    launch_times = {}

    def __init__(self, host_ip, host_port):
        self.ip = host_ip
        self.port = host_port

    def send_api(self, thing):
        """  """
        pid = thing.pid
        api = thing.api

        # We're required to report results of every target process to *its own*
        # result server. So create a communication socket...
        if not self.sockets.has_key(pid):
            self.sockets[pid] = self._socket_for_pid(pid)
            if not self.sockets[pid]:
                raise Exception("CuckooHost error: could not create socket.")
            self._send_new_process(thing)
        # ... and don't forget to explain every single API call again to this server
        self.descriptions.setdefault(pid, ["__process__", "__thread__"])
        try:
            lookup_idx = self.descriptions[pid].index(api)
        except ValueError:
            self.descriptions[pid].append(api)
            lookup_idx = len(self.descriptions[pid]) - 1
            self._send_api_description(lookup_idx, thing)

        # Here's an api object:
        # {
        #     "I"    : (int)<index in the API lookup table>,
        #     "T"    : (int)<caller thread id>,
        #     "t"    : (int)<time (in milliseconds) since a process launch>,
        #     "args" : [
        #         (int)<1 if this API call was successfull, 0 otherwise>,
        #         (int)<return value>,<commit_msg>host.py: improve phrasing<commit_after>#!/usr/bin/env python
# Copyright (C) 2015 <NAME>
# This file is part of my GSoC'15 project for Cuckoo Sandbox:
#	http://www.cuckoosandbox.org
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.

import socket
import datetime
from bson import BSON
from subprocess import check_output
from filetimes import dt_to_filetime

class CuckooHost:

    sockets = {}
    descriptions = {}
    launch_times = {}

    def __init__(self, host_ip, host_port):
        self.ip = host_ip
        self.port = host_port

    def send_api(self, thing):
        """  """
        pid = thing.pid
        api = thing.api

        # We're required to report results of tracing a target process to
        # *its own* result server. So create a communication socket...
        if not self.sockets.has_key(pid):
            self.sockets[pid] = self._socket_for_pid(pid)
            if not self.sockets[pid]:
                raise Exception("CuckooHost error: could not create socket.")
            self._send_new_process(thing)
        # ... and don't forget to explain every single API call again
        self.descriptions.setdefault(pid, ["__process__", "__thread__"])
        try:
            lookup_idx = self.descriptions[pid].index(api)
        except ValueError:
            self.descriptions[pid].append(api)
            lookup_idx = len(self.descriptions[pid]) - 1
            self._send_api_description(lookup_idx, thing)

        # Here's an api object:
        # {
        #     "I"    : (int)<index in the API lookup table>,
        #     "T"    : (int)<caller thread id>,
        #     "t"    : (int)<time (in milliseconds) since a process launch>,
        #     "args" : [
        #         (int)<1 if this API call was successfull, 0 otherwise>,
        #         (int)<return value>,
{'fraction_non_alphanumeric': 0.100398406374502, 'fraction_numerical': 0.004780876494023904, 'mean_word_length': 2.274782608695652, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '2991896', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1080, 'n_words': 341}