diff --git a/README.md b/README.md index a39ce00..b99e5ee 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Generator of static files for testing file upload functionality. Supported file types: +- EICAR test file + - For checking if the antivirus software works - csv - For checking if the worksheet function works - jpeg @@ -51,22 +53,29 @@ To specify bytes, you can use B, KB, MB, or GB as a unit. $ dummy -t abc -b 1MB test.png ``` +To generate an EICAR test file, include `eicar` as part of the file name. + +```bash +$ dummy eicar.com +``` + You can check your options at any time by checking help. ```bash $ dummy -h -usage: dummy [-h] [-t TEXT] [-b BYTES] file_path +usage: dummy [-h] [-t TEXT] [-b BYTES] [-v] file_path Create a dummy file for testing. positional arguments: - file_path Path to the generated file(.csv .jpeg, .png, .pdf) + file_path Path to the generated file(.csv .jpeg, .png, .pdf, EICAR) options: -h, --help show this help message and exit -t TEXT, --text TEXT Text to be written in the file(Disabled in csv) -b BYTES, --bytes BYTES Bytes of file(.png, .csv) + -v, --version Print version ``` ## License diff --git a/dummy/__init__.py b/dummy/__init__.py index e69de29..fb13a35 100644 --- a/dummy/__init__.py +++ b/dummy/__init__.py @@ -0,0 +1 @@ +__version__ = '0.2.1' \ No newline at end of file diff --git a/dummy/cli.py b/dummy/cli.py index 58ceca8..8fed365 100644 --- a/dummy/cli.py +++ b/dummy/cli.py @@ -3,11 +3,13 @@ import argparse import binascii +import codecs import colorama import io import os import platform +from dummy import __version__ from colorama import Fore from PIL import Image, ImageDraw, ImageFont from reportlab.pdfgen import canvas @@ -35,6 +37,14 @@ def make_csv(file_path, byte_size): f.write('0\n') return True +def make_eicar(file_path): + # Avoid scanners will detect the EICAR test file as a virus + rot13_eicar_bytes = 'K5B!C%@NC[4\\CMK54(C^)7PP)7}$RVPNE-FGNAQNEQ-NAGVIVEHF-GRFG-SVYR!$U+U*' + with open(file_path, 'w') as f: + f.write(codecs.encode(rot13_eicar_bytes, "rot_13")) + + return True + def make_jpeg(file_path, text): image = Image.new('RGB', (729, 516), (255, 255, 255)) # B5, White draw = ImageDraw.Draw(image) @@ -127,9 +137,10 @@ def parse_bytes(byte_str): def parse_args(): colorama.init(autoreset=True) parser = argparse.ArgumentParser(description='Create a dummy file for testing.') - parser.add_argument('file_path', help='Path to the generated file(.csv .jpeg, .png, .pdf)') + parser.add_argument('file_path', help='Path to the generated file(.csv .jpeg, .png, .pdf, EICAR)') parser.add_argument('-t', '--text', help='Text to be written in the file(Disabled in csv)', default='dummy file') parser.add_argument('-b', '--bytes', help='Bytes of file(.png, .csv)') + parser.add_argument('-v', '--version', help='Print version', action='version', version=__version__) args = parser.parse_args() if args.bytes is not None and not args.file_path.endswith('.png') and not args.file_path.endswith('.csv'): @@ -142,8 +153,12 @@ def parse_args(): if not os.path.exists(dir_path): print(Fore.RED + 'Error: The specified directory does not exist.') return - - if args.file_path.endswith('.csv'): + + if 'eicar' in args.file_path or 'EICAR' in args.file_path: + make_eicar(args.file_path) + print(Fore.GREEN + 'Successfully generated: ' + args.file_path) + + elif args.file_path.endswith('.csv'): make_csv(args.file_path, parse_bytes(args.bytes)) print(Fore.GREEN + 'Successfully generated: ' + args.file_path) diff --git a/setup.py b/setup.py index b2b6e28..adca7c1 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,11 @@ # coding: UTF-8 from setuptools import setup +from dummy import __version__ setup( name='dummy', - version='0.2.0', + version=__version__, description='Create a dummy file for testing.', author='Taichi Kotake', packages=['dummy'],