# Path: src/funfuzz/util/create_collector.py
# def make_collector():
# def printCrashInfo(crashInfo):  # pylint: disable=invalid-name,missing-docstring
# def printMatchingSignature(match):  # pylint: disable=invalid-name,missing-docstring
# def submit_collector(collector, crash_info, testcase, quality, meta_data=None):
# 
# Path: src/funfuzz/util/os_ops.py
# NO_DUMP_MSG = r"""
# WARNING: Minidumps are not being generated, so all crashes will be uninteresting.
# WARNING: Make sure the following key value exists in this key:
# WARNING: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
# WARNING: Name: DumpType  Type: REG_DWORD
# WARNING: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787181%28v=vs.85%29.aspx
# """
# def make_cdb_cmd(prog_full_path, crashed_pid):
# def make_gdb_cmd(prog_full_path, crashed_pid):
# def disable_corefile():
# def get_core_limit():
# def make_dbg_cmd(prog_full_path, crashed_pid):
# def grab_crash_log(prog_full_path, crashed_pid, log_prefix, want_stack):
# def grab_mac_crash_log(crash_pid, log_prefix, use_log_files):
# def is_win_dumping_to_default():  # pylint: disable=too-complex
# def make_wtmp_dir(base_dir):


from copy import deepcopy
from optparse import OptionParser  # pylint: disable=deprecated-module
from pathlib import Path
from shlex import quote
from FTB.ProgramConfiguration import ProgramConfiguration
from . import inspect_shell
from ..util import create_collector
from ..util import file_manipulation
from ..util import os_ops
import io
import os
import platform
import shutil
import subprocess
import sys
import zipfile
import FTB.Signatures.CrashInfo as Crash_Info
import lithium.interestingness.timed_run as timedrun
        import resource
    return res.lev >= gOptions.minimumInterestingLevel


# For direct, manual use
def main():  # pylint: disable=missing-docstring
    options = parseOptions(sys.argv[1:])
    cwd_prefix = Path.cwd() / "m"
    res = ShellResult(options, options.jsengineWithArgs, cwd_prefix, False)  # pylint: disable=no-member
    print(res.lev)
    if options.submit:  # pylint: disable=no-member
        if res.lev >= options.minimumInterestingLevel:  # pylint: disable=no-member
            testcase_filename = Path(options.jsengineWithArgs[-1])  # pylint: disable=no-member
            wrapper_file = Path(options.jsengineWithArgs[-2])  # pylint: disable=no-member
            if testcase_filename.suffix == ".wasm" and wrapper_file.suffix == ".wrapper":
                # binaryen integration, we do not yet have pinpoint nor autobisectjs support, so temporarily quality 10
                assert testcase_filename.is_file()
                assert wrapper_file.is_file()
                result_zip = Path.cwd() / "webassembly_files.zip"
                with zipfile.ZipFile(result_zip, "w") as f:
                    f.write(wrapper_file, wrapper_file.name, compress_type=zipfile.ZIP_DEFLATED)
                    f.write(testcase_filename, testcase_filename.name, compress_type=zipfile.ZIP_DEFLATED)

                # Quality is 10, meta_data {}
                print(f"Submitting {result_zip}")
                # pylint: disable=no-member
                create_collector.submit_collector(options.collector, res.crashInfo, str(result_zip), 10, meta_data={})
                print(f"Submitted {result_zip}")
            else:
                print(f"Submitting {testcase_filename}")
                # pylint: disable=no-member

# Path: src/funfuzz/util/create_collector.py
# def make_collector():
# def printCrashInfo(crashInfo):  # pylint: disable=invalid-name,missing-docstring
# def printMatchingSignature(match):  # pylint: disable=invalid-name,missing-docstring
# def submit_collector(collector, crash_info, testcase, quality, meta_data=None):
# 
# Path: src/funfuzz/util/os_ops.py
# NO_DUMP_MSG = r"""
# WARNING: Minidumps are not being generated, so all crashes will be uninteresting.
# WARNING: Make sure the following key value exists in this key:
# WARNING: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
# WARNING: Name: DumpType  Type: REG_DWORD
# WARNING: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787181%28v=vs.85%29.aspx
# """
# def make_cdb_cmd(prog_full_path, crashed_pid):
# def make_gdb_cmd(prog_full_path, crashed_pid):
# def disable_corefile():
# def get_core_limit():
# def make_dbg_cmd(prog_full_path, crashed_pid):
# def grab_crash_log(prog_full_path, crashed_pid, log_prefix, want_stack):
# def grab_mac_crash_log(crash_pid, log_prefix, use_log_files):
# def is_win_dumping_to_default():  # pylint: disable=too-complex
# def make_wtmp_dir(base_dir):


# Path: src/funfuzz/js/js_interesting.py
from copy import deepcopy
from optparse import OptionParser  # pylint: disable=deprecated-module
from pathlib import Path
from shlex import quote
from FTB.ProgramConfiguration import ProgramConfiguration
from . import inspect_shell
from ..util import create_collector
from ..util import file_manipulation
from ..util import os_ops
import io
import os
import platform
import shutil
import subprocess
import sys
import zipfile
import FTB.Signatures.CrashInfo as Crash_Info
import lithium.interestingness.timed_run as timedrun
        import resource

    return res.lev >= gOptions.minimumInterestingLevel


# For direct, manual use
def main():  # pylint: disable=missing-docstring
    options = parseOptions(sys.argv[1:])
    cwd_prefix = Path.cwd() / "m"
    res = ShellResult(options, options.jsengineWithArgs, cwd_prefix, False)  # pylint: disable=no-member
    print(res.lev)
    if options.submit:  # pylint: disable=no-member
        if res.lev >= options.minimumInterestingLevel:  # pylint: disable=no-member
            testcase_filename = Path(options.jsengineWithArgs[-1])  # pylint: disable=no-member
            wrapper_file = Path(options.jsengineWithArgs[-2])  # pylint: disable=no-member
            if testcase_filename.suffix == ".wasm" and wrapper_file.suffix == ".wrapper":
                # binaryen integration, we do not yet have pinpoint nor autobisectjs support, so temporarily quality 10
                assert testcase_filename.is_file()
                assert wrapper_file.is_file()
                result_zip = Path.cwd() / "webassembly_files.zip"
                with zipfile.ZipFile(result_zip, "w") as f:
                    f.write(wrapper_file, wrapper_file.name, compress_type=zipfile.ZIP_DEFLATED)
                    f.write(testcase_filename, testcase_filename.name, compress_type=zipfile.ZIP_DEFLATED)

                # Quality is 10, meta_data {}
                print(f"Submitting {result_zip}")
                # pylint: disable=no-member
                create_collector.submit_collector(options.collector, res.crashInfo, str(result_zip), 10, meta_data={})
                print(f"Submitted {result_zip}")
            else:
                print(f"Submitting {testcase_filename}")
                # pylint: disable=no-member

                create_collector.submit_collector(options.collector, res.crashInfo, str(testcase_filename), 0)