Skip to main content

A malware classifier template with built-in logging.

Project description

MalwareClassifier

MalwareClassifier is a Python package that provides a template for building a malware classification system with a built-in logging system and configurable settings. It is designed to be modular, extensible, and easy to install using pip.


Table of Contents


Installation

Option A: Install using pip

pip install MalwareClassifier

Option B: Standard installation

# Clone the repository
git clone git@github.com:cchunhuang/MalwareClassifier.git
cd MalwareClassifier

# Install
pip install .

# Install additional dependencies if needed
pip install -r requirements.txt

Quick Start

from MalwareClassifier import MalwareClassifier, setup_logging, get_logger

class subMalwareClassifier(MalwareClassifier):
    def __init__(self, config_path="./config.json"):
        super().__init__()
        setup_logging(log_dir=self.config.folder.log)
        self.logger = get_logger(__name__)

    def getFeature(self):
        return 'This is the implementation of the getFeature function from the derived class.'
    
    def getVector(self):
        return 'This is the implementation of the getVector function from the derived class.'

    def getModel(self, action:str="train"):
        return 'This is the implementation of the getModel function from the derived class.'
    
    def getPrediction(self):
        return 'This is the implementation of the getPrediction function from the derived class.'
  • The MalwareClassifier class in MalwareClassifier.py defines the workflow skeleton. Subclass it to override getFeature(), getVector(), getModel(), and getPrediction().
  • You can specify your own config_path.

Configuration

The package includes a default config.json:

{
  "file": {
    "label": "./dataset/label.csv"
  },
  "folder": {
    "log": "./output/log/",
    "dataset": "./dataset/",
    "feature": "./output/feature/",
    "vectorize": "./output/vectorize/",
    "model": "./output/model/",
    "predict": "./output/predict/"
  },
  "parameter": {
    "general": {
        "detection": true
    },
    "feature": { 
        "save": true, 
        "load": false 
    },
    "vectorize": { 
        "save": true, 
        "load": false 
    },
    "model": { 
        "save": true, 
        "load": false 
    },
    "predict": { 
        "save": true, 
        "load": false 
    }
  }
}

After calling super().__init__()

  • You can directly access the data using dot notation, such as self.config.file.label or self.config.parameter.feature.save.
  • The contents of this config.json are fully customizable. For example, if you add "new_dic": { "new_val": 123 } under general, you can access it via self.config.parameter.general.new_dic.new_val.
  • Folders in folder will be created automatically (or using self.mkdir()).

Logging Usage

The logging system is defined in src/MalwareClassifier/Logging.py.

Available functions

  • setup_logging(config=None, reset_handlers=True, log_dir=None) Initialize logging with optional config overrides.
  • It is recommended to use setup_logging(log_dir=self.config.folder.log)
  • get_logger(name=None) Retrieve a logger for any module.

Default behavior

  • Logs are written both to console and file.
  • Log files are automatically named as: malware_classifier-YYYYMMDD-HHMMSS.log

Environment variables

Variable Description Example
MALCLASS_LOG_LEVEL Set log level DEBUG, INFO
MALCLASS_LOG_FILE Full path for the log file /tmp/log.txt
MALCLASS_LOG_DIR Directory for log files ./output/log
MALCLASS_LOG_FORMATTER Choose formatter: basic, verbose, json verbose

Note: JSON logging requires installing python-json-logger.

Example usage in modules

from MalwareClassifier import setup_logging, get_logger

setup_logging()
logger = get_logger(__name__)
logger.info("This is an info message")
logger.debug("This is a debug message")

Publishing

Publish to PyPI

pip install build twine
python -m build
twine upload dist/*

License

This project is licensed under the terms of the MIT License.


Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

malwareclassifier-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

malwareclassifier-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file malwareclassifier-0.1.1.tar.gz.

File metadata

  • Download URL: malwareclassifier-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for malwareclassifier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e324cf9270449bd8668d0552606c424c456040978dd32bd7c608006e15371455
MD5 cf65733a04c5bf6292e670ae4a151d4b
BLAKE2b-256 e1fae91b7d378c2b1eb82bc352a824eec1106facb99911db44a330972f14c8d9

See more details on using hashes here.

File details

Details for the file malwareclassifier-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for malwareclassifier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd70e0337024f29a226fa956f3474a2d2462b9eb539f25eb4edb6be7a12523b7
MD5 694d57d11cb7cec0437ead817925b0e7
BLAKE2b-256 9300dcd0651c9f9dc44102b126d34aa294155ace762e62c97edfa6de1084c24f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page