|
| 1 | +#!/usr/local/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
1 | 3 | #
|
2 | 4 | # Copyright (c) 2007-2014. The YARA Authors. All Rights Reserved.
|
3 | 5 | #
|
@@ -692,24 +694,58 @@ def testEntrypoint(self):
|
692 | 694 | 'rule test { condition: entrypoint >= 0 }',
|
693 | 695 | ])
|
694 | 696 |
|
695 |
| - def testMeta(self): |
696 |
| - |
697 |
| - r = yara.compile(source=r'rule test { meta: a = "foo\x80bar" condition: true }') |
698 |
| - self.assertTrue((list(r)[0].meta['a']) == 'foobar') |
699 |
| - |
700 |
| - # This test ensures that anything after the NULL character is stripped. |
| 697 | + # This test ensures that anything after the NULL character is stripped. |
701 | 698 | def testMetaNull(self):
|
702 | 699 |
|
703 | 700 | r = yara.compile(source=r'rule test { meta: a = "foo\x00bar\x80" condition: true }')
|
704 | 701 | self.assertTrue((list(r)[0].meta['a']) == 'foo')
|
705 | 702 |
|
| 703 | + def testMeta(self): |
| 704 | + |
| 705 | + r = yara.compile(source=r""" |
| 706 | + rule test { |
| 707 | + meta: |
| 708 | + a = "foo\x80bar" |
| 709 | + b = "ñ" |
| 710 | + c = "\xc3\xb1" |
| 711 | + condition: |
| 712 | + true } |
| 713 | + """) |
| 714 | + |
| 715 | + meta = list(r)[0].meta |
| 716 | + |
| 717 | + if sys.version_info > (3, 0): |
| 718 | + self.assertTrue(meta['a'] == 'foobar') |
| 719 | + else: |
| 720 | + self.assertTrue(meta['a'] == 'foo\x80bar') |
| 721 | + |
| 722 | + self.assertTrue(meta['b'] == 'ñ') |
| 723 | + self.assertTrue(meta['c'] == 'ñ') |
| 724 | + |
706 | 725 | # This test is similar to testMeta but it tests the meta data generated
|
707 | 726 | # when a Match object is created.
|
708 | 727 | def testScanMeta(self):
|
709 | 728 |
|
710 |
| - r = yara.compile(source=r'rule test { meta: a = "foo\x80bar" condition: true }') |
| 729 | + r = yara.compile(source=r""" |
| 730 | + rule test { |
| 731 | + meta: |
| 732 | + a = "foo\x80bar" |
| 733 | + b = "ñ" |
| 734 | + c = "\xc3\xb1" |
| 735 | + condition: |
| 736 | + true } |
| 737 | + """) |
| 738 | + |
711 | 739 | m = r.match(data='dummy')
|
712 |
| - self.assertTrue((list(m)[0].meta['a']) == 'foobar') |
| 740 | + meta = list(m)[0].meta |
| 741 | + |
| 742 | + if sys.version_info > (3, 0): |
| 743 | + self.assertTrue(meta['a'] == 'foobar') |
| 744 | + else: |
| 745 | + self.assertTrue(meta['a'] == 'foo\x80bar') |
| 746 | + |
| 747 | + self.assertTrue(meta['b'] == 'ñ') |
| 748 | + self.assertTrue(meta['c'] == 'ñ') |
713 | 749 |
|
714 | 750 | def testFilesize(self):
|
715 | 751 |
|
|
0 commit comments