forked from Cisco-Talos/clamav-bytecode-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: add test for COPYRIGHT() function
Adds a test to verify that use of the COPYRIGHT() function in bytecode source correctly excludes the bytecode source from the compiled bytecode signature. I also tidied up the basic runtime tests to: - put test files in the test temp directory rather than the current directory. - make the variable names more Pythonic. - use pathlib.Path features rather than os.path.join().
- Loading branch information
Showing
5 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (C) 2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
|
||
""" | ||
The tests in this file are to verify behavior for assorted signature features. | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
import platform | ||
import shutil | ||
import subprocess | ||
import sys | ||
import time | ||
import unittest | ||
|
||
import testcase | ||
|
||
|
||
os_platform = platform.platform() | ||
operating_system = os_platform.split('-')[0].lower() | ||
|
||
|
||
class TC(testcase.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TC, cls).setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
super(TC, cls).tearDownClass() | ||
|
||
def setUp(self): | ||
super(TC, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TC, self).tearDown() | ||
self.verify_valgrind_log() | ||
|
||
def test_00_no_copyright(self): | ||
self.step_name('Test that without COPYRIGHT() function, source is included with compiled sig.') | ||
|
||
testsig_src_file = self.path_source / 'test' / 'examples' / 'in' / 'lsig_simple2.c' | ||
testsig_out_file = self.path_tmp / 'sigs' / 'lsig_simple2.cbc' | ||
os.makedirs(testsig_out_file.parent, exist_ok=True) | ||
|
||
self.execute_command(f'{self.clambcc} {testsig_src_file} -o {testsig_out_file} {self.headers}') | ||
|
||
command = f'{self.clambc} --printsrc {testsig_out_file}' | ||
output = self.execute_command(command) | ||
|
||
self.verify_output( | ||
output.out, | ||
expected=r'VIRUSNAME_PREFIX\("Clamav-Unit-Test-Signature.02"\)', | ||
unexpected='Cisco 2022' | ||
) | ||
|
||
def test_01_has_copyright(self): | ||
self.step_name('Test that with COPYRIGHT() function, source is excluded from compiled sig.') | ||
|
||
testsig_src_file = self.path_source / 'test' / 'examples' / 'in' / 'lsig_copyright.c' | ||
testsig_out_file = self.path_tmp / 'sigs' / 'lsig_copyright.cbc' | ||
os.makedirs(testsig_out_file.parent, exist_ok=True) | ||
|
||
self.execute_command(f'{self.clambcc} {testsig_src_file} -o {testsig_out_file} {self.headers}') | ||
|
||
command = f'{self.clambc} --printsrc {testsig_out_file}' | ||
output = self.execute_command(command) | ||
|
||
self.verify_output( | ||
output.out, | ||
expected='Cisco 2022', | ||
unexpected=r'VIRUSNAME_PREFIX\("Clamav-Unit-Test-Signature.02"\)' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
COPYRIGHT("Cisco 2022") | ||
|
||
VIRUSNAME_PREFIX("Clamav-Unit-Test-Signature.02") | ||
VIRUSNAMES("") | ||
TARGET(0) | ||
|
||
FUNCTIONALITY_LEVEL_MIN(FUNC_LEVEL_096_4) | ||
|
||
SIGNATURES_DECL_BEGIN | ||
DECLARE_SIGNATURE(test_string) | ||
SIGNATURES_DECL_END | ||
|
||
SIGNATURES_DEF_BEGIN | ||
/* matches "CLAMAV-TEST-STRING-NOT-EICAR" */ | ||
DEFINE_SIGNATURE(test_string, "0:434c414d41562d544553542d535452494e472d4e4f542d4549434152") | ||
SIGNATURES_DEF_END | ||
|
||
bool logical_trigger() | ||
{ | ||
/***Will return true if signature matches ***/ | ||
return matches(Signatures.test_string); | ||
} | ||
|
||
/***bytecode function that executes if the logical signature matched ***/ | ||
int entrypoint(void) | ||
{ | ||
foundVirus(""); | ||
return 0; | ||
} |
File renamed without changes.