Cobra icon indicating copy to clipboard operation
Cobra copied to clipboard

改进windows下的兼容性

Open Pryriat opened this issue 6 years ago • 2 comments

win10 1809,python 3.7.2 x86

upgrade cloghandler to concurrent_log_handler

在运行cobra.py时报以下错误:

PS F:\git\cobra> python cobra.py --help
Traceback (most recent call last):
  File "cobra.py", line 18, in <module>
    from cobra import main
  File "F:\git\cobra\cobra\__init__.py", line 21, in <module>
    from .log import logger
  File "F:\git\cobra\cobra\log.py", line 19, in <module>
    import cloghandler
ModuleNotFoundError: No module named 'cloghandler'

PS F:\git\cobra> pip install cloghandler
Collecting cloghandler
  Could not find a version that satisfies the requirement cloghandler (from versions: )
No matching distribution found for cloghandler

参考pypi说明,concurrent_log_handlercloghandler的新实现。

concurrent-log-handler 0.9.12

This is a fork from Lowell Alleman's version with updates for Windows and recent versions of Python. It should be a drop-in replacement for users of the old version, except for changing the package name from cloghandler to concurrent_log_handler.

cloghandler替换为concurrent_log_handler,问题解决。

文件目录问题

解决上一问题后,报出以下错误

PS F:\git\cobra> python cobra.py --help
Traceback (most recent call last):
  File "cobra.py", line 18, in <module>
    from cobra import main
  File "F:\git\cobra\cobra\__init__.py", line 22, in <module>
    from . import cli, api, config
  File "F:\git\cobra\cobra\cli.py", line 17, in <module>
    from .detection import Detection
  File "F:\git\cobra\cobra\detection.py", line 20, in <module>
    from .config import rules_path
  File "F:\git\cobra\cobra\config.py", line 27, in <module>
    os.mkdir(code_path)
FileNotFoundError: [WinError 3] 系统找不到指定的路径。: '/tmp/cobra'

在windows下/tmp/cobra路径非法,修改为:在初始化code_path前对系统环境进行判断,如果为windows,目录变更为cobra项目目录/tmp

关于fcntl的建议

在windows下没有fcntl的实现,建议将实现内置于源码中,或者将fcntl置于项目目录下。

Pryriat avatar Feb 12 '19 09:02 Pryriat

fcntl.txt Change to suffix .py put into a C:\Python version\Lib It can be run in 改为后缀.py 放在C:\Python版本\Lib 就能运行了

towy avatar Mar 05 '19 13:03 towy

windows下的问题不止这些,还有grep之类的,比较麻烦吧...以前提过一个issue,如果感兴趣可以自己改改看

https://github.com/WhaleShark-Team/cobra/pull/539

LoRexxar avatar Aug 24 '20 08:08 LoRexxar