├── sample.file ├── docs ├── requirements.txt ├── docutils.conf ├── modules │ ├── time.rst │ ├── string.rst │ ├── console.rst │ ├── magic.rst │ └── hash.rst ├── modules.rst └── index.rst ├── bootstrap.sh ├── tests ├── oss-fuzz │ ├── rules_fuzzer_corpus │ │ ├── 1 │ │ ├── 2 │ │ ├── 3 │ │ ├── 4 │ │ ├── 5 │ │ ├── 6 │ │ ├── 7 │ │ └── 8 │ ├── rules_fuzzer.options │ ├── elf_fuzzer_corpus │ │ ├── crash-03bca75466ee42801a8bff280de04afc3d1a3637 │ │ ├── crash-086300bbce1c6537573057336a343a82d483e2c0 │ │ ├── crash-2cafe4de66d87a83d83aaf65d8e4cea48f2c1144 │ │ ├── crash-370485c5b087f780a2447a03d775f7188e323d31 │ │ ├── crash-49bb55d669fda0683f945b89396a6bd458caf2d8 │ │ ├── crash-49d00b6b033eaeb07cd39809dbc1d7ba2df196ec │ │ ├── crash-723296cdc1c0dba83ea767d69286429e608c46c3 │ │ ├── crash-7dc27920ae1cb85333e7f2735a45014488134673 │ │ ├── crash-7e945ce5f43f515ea078c558a2e3205089d414e5 │ │ ├── crash-a809561e75b94bd5d4d8cf7488d9e2663fc1ccdc │ │ ├── crash-a8715a38a94161c9509309f5dbb5a7936aba8376 │ │ ├── crash-aee928239444a7b039500d4499035e6d30cb89da │ │ ├── crash-c4002396c52065d21fe1c1f05f8937aab8d59c18 │ │ ├── crash-c610b3036f195ad7fb05248a530278aad37b438d │ │ ├── crash-c6569e6e28f0a18bb2f3bf49c982333a359bed67 │ │ ├── crash-cc6844f44825a785de1b079c88f728e1c0f779fb │ │ ├── poc-6bf54fca69bb5029676d747b12c74b597dd8c5939343ea8f2cbfea9e666dd6b1 │ │ ├── poc-789fc6da83de39c3ff394a950b0831f6fe5b63a85a46aaa236048b5c1dcf0e59 │ │ ├── poc-939e9cd87b0d80834210fbf54edc66341aebf416d7509f6633f1d49766978b22 │ │ ├── poc-93a9fd1909dd49fc2a9b654333504f249cdac58126d3cfc4728577e78cb3eb89 │ │ ├── poc-b5b03a1f305b2cc1c158e01fee6c08c65145325d4e073f04d969329577077862 │ │ ├── poc-fa8bbacb5a12f057a0ed3999c37d78b4991e6b201bda4dc9a75a7c7970c7690d │ │ └── crash-f1fd008da535b110853885221ebfaac3f262a1c1e280f10929f7b353c44996c8 │ ├── dex_fuzzer_corpus │ │ ├── crash.poc │ │ ├── 1cf540db2f048bb21bd89379a57279b9ff4c308558715a3baee666a47393d86e │ │ ├── 25ef27f9543444652f0c68fe412d3da627a1d2a590b0a2b30e47466c1e962136 │ │ ├── 27fb31059503773723597edb875c937af971a6c15f91aac8c03c1fbdfa9e918c │ │ ├── 3ba9c082050f62e725c87ce4cf9f592fe9f177faf3a0c879f8fbe87312ca4b2c │ │ ├── b1203d95c56f02e7e6dbea714275cc05b47ac2510958b85f436571b801af44e7 │ │ └── b343d1058063e6e4b652ccf0589f93d0dbb6b092960e4aebc3c3c58894831359 │ ├── dotnet_fuzzer_corpus │ │ ├── obfuscated │ │ ├── buggy_stream_names │ │ ├── clusterfuzz-testcase-minimized-dotnet_fuzzer-5105966966636544 │ │ ├── clusterfuzz-testcase-minimized-dotnet_fuzzer-5195285818507264 │ │ ├── clusterfuzz-testcase-minimized-dotnet_fuzzer-5636481138556928 │ │ ├── clusterfuzz-testcase-minimized-dotnet_fuzzer-5725060321509376 │ │ └── clusterfuzz-testcase-minimized-dotnet_fuzzer-5880393521430528 │ ├── pe_fuzzer_corpus │ │ ├── clusterfuzz-testcase-minimized-5211130361282560 │ │ ├── clusterfuzz-testcase-minimized-5839717883969536 │ │ ├── clusterfuzz-testcase-minimized-pe_fuzzer-5671228022718464 │ │ ├── clusterfuzz-testcase-minimized-pe_fuzzer-5741846293643264 │ │ ├── 00388b550a2603a9e219bcb48acaf8cc115653cb1ea84cb4bccceb1aabe755b6 │ │ ├── 12f50a7dbf0c42f61ae1c351b2a9f75e8edb3bb55e582619edc7ece4eb0a3094 │ │ ├── 967af267b4124bada8f507cebf25f2192d146a4d63be71b45bfc03c5da7f21a7 │ │ ├── 99e98cb7096dee974e28fea0f76f1c30bc44fd5762cb12b2702910a28b28f95f │ │ └── e5af0352010b1879ac1c63a69d3d9a02d577fa834165f855bd5ebee0f1105de1 │ ├── macho_fuzzer_corpus │ │ ├── 1443c3cfb47c5eb41022a7063c24ab1bc9e45bfc31e98d5e6d3aa8377599b983 │ │ ├── 589f7b0e30d885ed91229646e58ccc7615007d2fab06451fef8785c6126adba7 │ │ ├── 5eefacbe52990526e4953802249447dd8c0a4b537459ca41e005a7173ca46138 │ │ ├── 6164a837fd33574f37464a765ab461fff94b52e659b114fb6109f2635678c564 │ │ ├── 66528aeb35dd705cc26a7daf4b8eda684f620efebfa0740fab84043e371ed566 │ │ ├── 678d89b32eecd7d01390aaaf3507935b27854f4f3a7055e3f6b1b0ccf0ca5072 │ │ ├── 6af5d157184d9144f86668f83e81760898df5db3c9e209596eb5fd9a91a7eeba │ │ ├── 797d1d450421b771482c0cc03f472e4eccbc9e4f544b6c12c1d4f070dec3c381 │ │ ├── 85494d8cb5753f1ad09be39428135feb35eb4ef44f39d6e1e75e2ad30d93e158 │ │ ├── b225048e85b14f08a43dd4752b9bb4b20840f5a8726eac0ff765d45c9e619828 │ │ └── fda81421d7403180923717a94e77aade8c9286d5b8de3ae0e2812343b666c6a7 │ ├── dex_fuzzer.cc │ ├── rules_fuzzer.cc │ ├── elf_fuzzer.cc │ ├── dotnet_fuzzer.cc │ ├── macho_fuzzer.cc │ └── pe_fuzzer.cc ├── data │ ├── tiny │ ├── foo.yar │ ├── include │ │ └── bar.yar │ ├── xor.out │ ├── mtxex.dll │ ├── pe_imports │ ├── pe_mingw │ ├── tiny-macho │ ├── weird_rich │ ├── ChipTune.efi │ ├── tiny-overlay │ ├── xorwide.out │ ├── bad_dotnet_pe │ ├── tiny-idata-51ff │ ├── tiny-idata-5200 │ ├── tiny-universal │ ├── elf_with_imports │ ├── test-pb.data.bin │ ├── xorwideandascii.out │ ├── tiny_empty_import_name │ ├── mtxex_modified_rsrc_rva.dll │ ├── 05cd06e6a202e12be22a02700ed6f1604e803ca8867277d852e8971efded0650 │ ├── 079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885 │ ├── 0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171 │ ├── 33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b │ ├── 3b8b90159fa9b6048cc5410c5d53f116943564e4d05b04a843f9b3d0540d0c1c │ ├── 6c2abf4b80a87e63eee2996e5cea8f004d49ec0c1806080fa72e960529cba14c │ ├── 756684f4017ba7e931a26724ae61606b16b5f8cc84ed38a260a34e50c5016f59 │ ├── ca21e1c32065352d352be6cde97f89c141d7737ea92434831f998080783d5386 │ ├── e3d45a2865818756068757d7e319258fef40dad54532ee4355b86bc129f27345 │ ├── 079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx │ ├── c6f9709feccf42f2d9e22057182fe185f177fb9daaa2649b4669a24f2ee7e3ba_0h_410h │ ├── test-pb.data │ ├── tiny.notes │ ├── baz.yar │ └── base64 ├── convention-portable-modifiers ├── gcov-summary ├── test-magic.c ├── test-version.c ├── test-pb.c ├── test-stack.c ├── mapper.c └── test-re-split.c ├── extra ├── logo.ai ├── old-logo.png ├── old-logo.psd ├── UltraEdit-wordfile.txt └── codemirror │ ├── index.html │ └── yara.js ├── libyara ├── stino.settings ├── modules │ ├── pb_tests │ │ ├── yara.pb-c.h │ │ └── pb_tests.proto │ ├── module_list │ ├── pb_to_module.rst │ ├── pe │ │ └── authenticode-parser │ │ │ ├── certificate.h │ │ │ ├── countersignature.h │ │ │ ├── helper.h │ │ │ ├── helper.c │ │ │ └── structs.c │ ├── demo │ │ └── demo.c │ └── time │ │ └── time.c ├── yara.pc ├── include │ ├── yara │ │ ├── notebook.h │ │ ├── simple_str.h │ │ ├── elf_utils.h │ │ ├── exefiles.h │ │ ├── base64.h │ │ ├── scan.h │ │ ├── mem.h │ │ ├── stream.h │ │ ├── proc.h │ │ ├── stack.h │ │ ├── pe_utils.h │ │ ├── threading.h │ │ ├── stopwatch.h │ │ ├── filemap.h │ │ ├── ahocorasick.h │ │ ├── sizedstr.h │ │ ├── endian.h │ │ ├── unaligned.h │ │ ├── strutils.h │ │ └── dex.h │ ├── yara.h │ └── tlshc │ │ └── tlsh.h ├── tlshc │ ├── tlsh_util.h │ └── tlsh.c ├── pb │ └── yara.proto ├── stream.c ├── endian.c ├── proc │ └── none.c └── hex_grammar.h ├── .gitattributes ├── windows ├── vs2017 │ ├── yara │ │ └── yara.vcxproj.user │ ├── yarac │ │ └── yarac.vcxproj.user │ ├── libyara │ │ ├── libyara.vcxproj.user │ │ └── packages.config │ └── NuGet.Config ├── vs2019 │ ├── yara │ │ └── yara.vcxproj.user │ ├── yarac │ │ └── yarac.vcxproj.user │ ├── libyara │ │ ├── libyara.vcxproj.user │ │ └── packages.config │ └── NuGet.Config └── vs2015 │ ├── NuGet.Config │ └── libyara │ └── packages.config ├── sample.rules ├── yara.pc.in ├── AUTHORS ├── SECURITY.md ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── oss-fuzz.yml │ └── coverity.yml ├── .readthedocs.yaml ├── dist ├── yara-python.spec └── yara.spec ├── .gitignore ├── COPYING ├── CONTRIBUTORS ├── yarac.man ├── sandbox ├── collect_matches.h ├── yara_matches.proto └── collect_matches.cc ├── cli ├── common.h ├── unicode.h └── threading.h └── appveyor.yml /sample.file: -------------------------------------------------------------------------------- 1 | abbbb 2 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx-rtd-theme==2.0.0 -------------------------------------------------------------------------------- /docs/docutils.conf: -------------------------------------------------------------------------------- 1 | [parsers] 2 | smart_quotes: false 3 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | autoreconf --force --install 3 | -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/1: -------------------------------------------------------------------------------- 1 | rule test { condition: false } -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/8: -------------------------------------------------------------------------------- 1 | rule N{condition:for 1r in r(r -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | max_len = 50000 3 | -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/6: -------------------------------------------------------------------------------- 1 | rule r{condition:r(for 7e in(6):(1) -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/7: -------------------------------------------------------------------------------- 1 | rule N{condition:for 1r in r(2,3,r -------------------------------------------------------------------------------- /extra/logo.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/extra/logo.ai -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/5: -------------------------------------------------------------------------------- 1 | rule r{condition:for all e in r(for all n -------------------------------------------------------------------------------- /tests/data/tiny: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny -------------------------------------------------------------------------------- /extra/old-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/extra/old-logo.png -------------------------------------------------------------------------------- /extra/old-logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/extra/old-logo.psd -------------------------------------------------------------------------------- /tests/data/foo.yar: -------------------------------------------------------------------------------- 1 | include "include/bar.yar" 2 | 3 | rule foo { condition: bar } 4 | -------------------------------------------------------------------------------- /tests/data/include/bar.yar: -------------------------------------------------------------------------------- 1 | include "../baz.yar" 2 | 3 | rule bar { condition: baz } 4 | -------------------------------------------------------------------------------- /tests/data/xor.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/xor.out -------------------------------------------------------------------------------- /tests/data/mtxex.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/mtxex.dll -------------------------------------------------------------------------------- /tests/data/pe_imports: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/pe_imports -------------------------------------------------------------------------------- /tests/data/pe_mingw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/pe_mingw -------------------------------------------------------------------------------- /tests/data/tiny-macho: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny-macho -------------------------------------------------------------------------------- /tests/data/weird_rich: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/weird_rich -------------------------------------------------------------------------------- /tests/data/ChipTune.efi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/ChipTune.efi -------------------------------------------------------------------------------- /tests/data/tiny-overlay: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny-overlay -------------------------------------------------------------------------------- /tests/data/xorwide.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/xorwide.out -------------------------------------------------------------------------------- /tests/data/bad_dotnet_pe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/bad_dotnet_pe -------------------------------------------------------------------------------- /tests/data/tiny-idata-51ff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny-idata-51ff -------------------------------------------------------------------------------- /tests/data/tiny-idata-5200: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny-idata-5200 -------------------------------------------------------------------------------- /tests/data/tiny-universal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny-universal -------------------------------------------------------------------------------- /libyara/stino.settings: -------------------------------------------------------------------------------- 1 | { 2 | "baudrate": 4, 3 | "line_ending": 1, 4 | "serial_port": 1 5 | } -------------------------------------------------------------------------------- /tests/data/elf_with_imports: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/elf_with_imports -------------------------------------------------------------------------------- /tests/data/test-pb.data.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/test-pb.data.bin -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-03bca75466ee42801a8bff280de04afc3d1a3637: -------------------------------------------------------------------------------- 1 | ELFELF -------------------------------------------------------------------------------- /tests/data/xorwideandascii.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/xorwideandascii.out -------------------------------------------------------------------------------- /tests/data/tiny_empty_import_name: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/tiny_empty_import_name -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/rules_fuzzer_corpus/3 -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/4: -------------------------------------------------------------------------------- 1 | rule r{condition:for 1e in(1):(for 6f in(3):(for all c in(6):(for c cc in(6):(for c c -------------------------------------------------------------------------------- /tests/data/mtxex_modified_rsrc_rva.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/mtxex_modified_rsrc_rva.dll -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/crash.poc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/crash.poc -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/obfuscated: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/obfuscated -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://pete.akeo.ie/2010/12/that-darn-libtoolize-acconfigmacrodirm4.html 2 | *.sh text eol=lf 3 | *.ac text eol=lf 4 | *.am text eol=lf -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/buggy_stream_names: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/buggy_stream_names -------------------------------------------------------------------------------- /libyara/modules/pb_tests/yara.pb-c.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Empty header file generated by protoc-gen-yara because it is included from 4 | * .pb-c.h files generated by protoc-gen-c. 5 | */ 6 | -------------------------------------------------------------------------------- /tests/data/05cd06e6a202e12be22a02700ed6f1604e803ca8867277d852e8971efded0650: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/05cd06e6a202e12be22a02700ed6f1604e803ca8867277d852e8971efded0650 -------------------------------------------------------------------------------- /tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885 -------------------------------------------------------------------------------- /tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171 -------------------------------------------------------------------------------- /tests/data/33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b -------------------------------------------------------------------------------- /tests/data/3b8b90159fa9b6048cc5410c5d53f116943564e4d05b04a843f9b3d0540d0c1c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/3b8b90159fa9b6048cc5410c5d53f116943564e4d05b04a843f9b3d0540d0c1c -------------------------------------------------------------------------------- /tests/data/6c2abf4b80a87e63eee2996e5cea8f004d49ec0c1806080fa72e960529cba14c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/6c2abf4b80a87e63eee2996e5cea8f004d49ec0c1806080fa72e960529cba14c -------------------------------------------------------------------------------- /tests/data/756684f4017ba7e931a26724ae61606b16b5f8cc84ed38a260a34e50c5016f59: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/756684f4017ba7e931a26724ae61606b16b5f8cc84ed38a260a34e50c5016f59 -------------------------------------------------------------------------------- /tests/data/ca21e1c32065352d352be6cde97f89c141d7737ea92434831f998080783d5386: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/ca21e1c32065352d352be6cde97f89c141d7737ea92434831f998080783d5386 -------------------------------------------------------------------------------- /tests/data/e3d45a2865818756068757d7e319258fef40dad54532ee4355b86bc129f27345: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/e3d45a2865818756068757d7e319258fef40dad54532ee4355b86bc129f27345 -------------------------------------------------------------------------------- /tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-086300bbce1c6537573057336a343a82d483e2c0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-086300bbce1c6537573057336a343a82d483e2c0 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-2cafe4de66d87a83d83aaf65d8e4cea48f2c1144: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-2cafe4de66d87a83d83aaf65d8e4cea48f2c1144 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-370485c5b087f780a2447a03d775f7188e323d31: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-370485c5b087f780a2447a03d775f7188e323d31 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-49bb55d669fda0683f945b89396a6bd458caf2d8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-49bb55d669fda0683f945b89396a6bd458caf2d8 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-49d00b6b033eaeb07cd39809dbc1d7ba2df196ec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-49d00b6b033eaeb07cd39809dbc1d7ba2df196ec -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-723296cdc1c0dba83ea767d69286429e608c46c3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-723296cdc1c0dba83ea767d69286429e608c46c3 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-7dc27920ae1cb85333e7f2735a45014488134673: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-7dc27920ae1cb85333e7f2735a45014488134673 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-7e945ce5f43f515ea078c558a2e3205089d414e5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-7e945ce5f43f515ea078c558a2e3205089d414e5 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-a809561e75b94bd5d4d8cf7488d9e2663fc1ccdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-a809561e75b94bd5d4d8cf7488d9e2663fc1ccdc -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-a8715a38a94161c9509309f5dbb5a7936aba8376: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-a8715a38a94161c9509309f5dbb5a7936aba8376 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-aee928239444a7b039500d4499035e6d30cb89da: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-aee928239444a7b039500d4499035e6d30cb89da -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-c4002396c52065d21fe1c1f05f8937aab8d59c18: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-c4002396c52065d21fe1c1f05f8937aab8d59c18 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-c610b3036f195ad7fb05248a530278aad37b438d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-c610b3036f195ad7fb05248a530278aad37b438d -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-c6569e6e28f0a18bb2f3bf49c982333a359bed67: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-c6569e6e28f0a18bb2f3bf49c982333a359bed67 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-cc6844f44825a785de1b079c88f728e1c0f779fb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-cc6844f44825a785de1b079c88f728e1c0f779fb -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-5211130361282560: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-5211130361282560 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-5839717883969536: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-5839717883969536 -------------------------------------------------------------------------------- /windows/vs2017/yara/yara.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /windows/vs2017/yarac/yarac.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /windows/vs2019/yara/yara.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /windows/vs2019/yarac/yarac.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/data/c6f9709feccf42f2d9e22057182fe185f177fb9daaa2649b4669a24f2ee7e3ba_0h_410h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/data/c6f9709feccf42f2d9e22057182fe185f177fb9daaa2649b4669a24f2ee7e3ba_0h_410h -------------------------------------------------------------------------------- /windows/vs2017/libyara/libyara.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /windows/vs2019/libyara/libyara.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-pe_fuzzer-5671228022718464: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-pe_fuzzer-5671228022718464 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-pe_fuzzer-5741846293643264: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/clusterfuzz-testcase-minimized-pe_fuzzer-5741846293643264 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/00388b550a2603a9e219bcb48acaf8cc115653cb1ea84cb4bccceb1aabe755b6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/00388b550a2603a9e219bcb48acaf8cc115653cb1ea84cb4bccceb1aabe755b6 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/12f50a7dbf0c42f61ae1c351b2a9f75e8edb3bb55e582619edc7ece4eb0a3094: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/12f50a7dbf0c42f61ae1c351b2a9f75e8edb3bb55e582619edc7ece4eb0a3094 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/967af267b4124bada8f507cebf25f2192d146a4d63be71b45bfc03c5da7f21a7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/967af267b4124bada8f507cebf25f2192d146a4d63be71b45bfc03c5da7f21a7 -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/99e98cb7096dee974e28fea0f76f1c30bc44fd5762cb12b2702910a28b28f95f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/99e98cb7096dee974e28fea0f76f1c30bc44fd5762cb12b2702910a28b28f95f -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer_corpus/e5af0352010b1879ac1c63a69d3d9a02d577fa834165f855bd5ebee0f1105de1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/pe_fuzzer_corpus/e5af0352010b1879ac1c63a69d3d9a02d577fa834165f855bd5ebee0f1105de1 -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/1cf540db2f048bb21bd89379a57279b9ff4c308558715a3baee666a47393d86e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/1cf540db2f048bb21bd89379a57279b9ff4c308558715a3baee666a47393d86e -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/25ef27f9543444652f0c68fe412d3da627a1d2a590b0a2b30e47466c1e962136: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/25ef27f9543444652f0c68fe412d3da627a1d2a590b0a2b30e47466c1e962136 -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/27fb31059503773723597edb875c937af971a6c15f91aac8c03c1fbdfa9e918c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/27fb31059503773723597edb875c937af971a6c15f91aac8c03c1fbdfa9e918c -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/3ba9c082050f62e725c87ce4cf9f592fe9f177faf3a0c879f8fbe87312ca4b2c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/3ba9c082050f62e725c87ce4cf9f592fe9f177faf3a0c879f8fbe87312ca4b2c -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/b1203d95c56f02e7e6dbea714275cc05b47ac2510958b85f436571b801af44e7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/b1203d95c56f02e7e6dbea714275cc05b47ac2510958b85f436571b801af44e7 -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer_corpus/b343d1058063e6e4b652ccf0589f93d0dbb6b092960e4aebc3c3c58894831359: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dex_fuzzer_corpus/b343d1058063e6e4b652ccf0589f93d0dbb6b092960e4aebc3c3c58894831359 -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5105966966636544: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5105966966636544 -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5195285818507264: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5195285818507264 -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5636481138556928: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5636481138556928 -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5725060321509376: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5725060321509376 -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5880393521430528: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/dotnet_fuzzer_corpus/clusterfuzz-testcase-minimized-dotnet_fuzzer-5880393521430528 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-6bf54fca69bb5029676d747b12c74b597dd8c5939343ea8f2cbfea9e666dd6b1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-6bf54fca69bb5029676d747b12c74b597dd8c5939343ea8f2cbfea9e666dd6b1 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-789fc6da83de39c3ff394a950b0831f6fe5b63a85a46aaa236048b5c1dcf0e59: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-789fc6da83de39c3ff394a950b0831f6fe5b63a85a46aaa236048b5c1dcf0e59 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-939e9cd87b0d80834210fbf54edc66341aebf416d7509f6633f1d49766978b22: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-939e9cd87b0d80834210fbf54edc66341aebf416d7509f6633f1d49766978b22 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-93a9fd1909dd49fc2a9b654333504f249cdac58126d3cfc4728577e78cb3eb89: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-93a9fd1909dd49fc2a9b654333504f249cdac58126d3cfc4728577e78cb3eb89 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-b5b03a1f305b2cc1c158e01fee6c08c65145325d4e073f04d969329577077862: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-b5b03a1f305b2cc1c158e01fee6c08c65145325d4e073f04d969329577077862 -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/poc-fa8bbacb5a12f057a0ed3999c37d78b4991e6b201bda4dc9a75a7c7970c7690d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/poc-fa8bbacb5a12f057a0ed3999c37d78b4991e6b201bda4dc9a75a7c7970c7690d -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/1443c3cfb47c5eb41022a7063c24ab1bc9e45bfc31e98d5e6d3aa8377599b983: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/1443c3cfb47c5eb41022a7063c24ab1bc9e45bfc31e98d5e6d3aa8377599b983 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/589f7b0e30d885ed91229646e58ccc7615007d2fab06451fef8785c6126adba7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/589f7b0e30d885ed91229646e58ccc7615007d2fab06451fef8785c6126adba7 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/5eefacbe52990526e4953802249447dd8c0a4b537459ca41e005a7173ca46138: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/5eefacbe52990526e4953802249447dd8c0a4b537459ca41e005a7173ca46138 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/6164a837fd33574f37464a765ab461fff94b52e659b114fb6109f2635678c564: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/6164a837fd33574f37464a765ab461fff94b52e659b114fb6109f2635678c564 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/66528aeb35dd705cc26a7daf4b8eda684f620efebfa0740fab84043e371ed566: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/66528aeb35dd705cc26a7daf4b8eda684f620efebfa0740fab84043e371ed566 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/678d89b32eecd7d01390aaaf3507935b27854f4f3a7055e3f6b1b0ccf0ca5072: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/678d89b32eecd7d01390aaaf3507935b27854f4f3a7055e3f6b1b0ccf0ca5072 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/6af5d157184d9144f86668f83e81760898df5db3c9e209596eb5fd9a91a7eeba: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/6af5d157184d9144f86668f83e81760898df5db3c9e209596eb5fd9a91a7eeba -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/797d1d450421b771482c0cc03f472e4eccbc9e4f544b6c12c1d4f070dec3c381: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/797d1d450421b771482c0cc03f472e4eccbc9e4f544b6c12c1d4f070dec3c381 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/85494d8cb5753f1ad09be39428135feb35eb4ef44f39d6e1e75e2ad30d93e158: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/85494d8cb5753f1ad09be39428135feb35eb4ef44f39d6e1e75e2ad30d93e158 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/b225048e85b14f08a43dd4752b9bb4b20840f5a8726eac0ff765d45c9e619828: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/b225048e85b14f08a43dd4752b9bb4b20840f5a8726eac0ff765d45c9e619828 -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer_corpus/fda81421d7403180923717a94e77aade8c9286d5b8de3ae0e2812343b666c6a7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/macho_fuzzer_corpus/fda81421d7403180923717a94e77aade8c9286d5b8de3ae0e2812343b666c6a7 -------------------------------------------------------------------------------- /sample.rules: -------------------------------------------------------------------------------- 1 | import "pe" 2 | 3 | rule UPX : Packer 4 | { 5 | strings: 6 | $a = {60 E8 00 00 00 00 58 83 E8 3D 50 8D B8} 7 | 8 | condition: 9 | $a at pe.entry_point 10 | } 11 | 12 | 13 | rule test {condition: false} 14 | -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer_corpus/crash-f1fd008da535b110853885221ebfaac3f262a1c1e280f10929f7b353c44996c8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VirusTotal/yara/HEAD/tests/oss-fuzz/elf_fuzzer_corpus/crash-f1fd008da535b110853885221ebfaac3f262a1c1e280f10929f7b353c44996c8 -------------------------------------------------------------------------------- /libyara/yara.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr/local 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/include 4 | libdir=${exec_prefix}/lib 5 | 6 | Name: yara 7 | Description: YARA library 8 | URL: https://virustotal.github.io/yara/ 9 | Version: 4.2.2 10 | Requires.private: libcrypto 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -lyara 13 | Libs.private: -lm 14 | -------------------------------------------------------------------------------- /windows/vs2015/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /windows/vs2017/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /windows/vs2019/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /yara.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | 6 | Name: yara 7 | Description: YARA library 8 | URL: https://virustotal.github.io/yara/ 9 | Version: @PACKAGE_VERSION@ 10 | Requires.private: @PC_REQUIRES_PRIVATE@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -lyara 13 | Libs.private: @PC_LIBS_PRIVATE@ @PTHREAD_LIBS@ 14 | -------------------------------------------------------------------------------- /docs/modules/time.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _time-module: 3 | 4 | ############ 5 | Time module 6 | ############ 7 | 8 | .. versionadded:: 3.7.0 9 | 10 | The Time module allows you to use temporal conditions in your YARA rules. 11 | 12 | .. c:function:: now() 13 | 14 | Function returning an integer which is the number of seconds since January 15 | 1, 1970. 16 | 17 | *Example: pe.timestamp > time.now()* 18 | -------------------------------------------------------------------------------- /windows/vs2015/libyara/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /windows/vs2017/libyara/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /windows/vs2019/libyara/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /libyara/include/yara/notebook.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Victor Manuel Alvarez on 3/4/20. 3 | // 4 | 5 | #ifndef YR_NOTEBOOK_H 6 | #define YR_NOTEBOOK_H 7 | 8 | #include 9 | 10 | typedef struct YR_NOTEBOOK YR_NOTEBOOK; 11 | 12 | int yr_notebook_create(size_t page_size, YR_NOTEBOOK** pool); 13 | 14 | int yr_notebook_destroy(YR_NOTEBOOK* pool); 15 | 16 | void* yr_notebook_alloc(YR_NOTEBOOK* notebook, size_t size); 17 | 18 | #endif // YR_NOTEBOOK_H 19 | -------------------------------------------------------------------------------- /libyara/modules/module_list: -------------------------------------------------------------------------------- 1 | MODULE(tests) 2 | MODULE(pe) 3 | MODULE(elf) 4 | MODULE(math) 5 | MODULE(time) 6 | MODULE(console) 7 | MODULE(string) 8 | 9 | #ifdef DOTNET_MODULE 10 | MODULE(dotnet) 11 | #endif 12 | 13 | #ifdef CUCKOO_MODULE 14 | MODULE(cuckoo) 15 | #endif 16 | 17 | #ifdef MAGIC_MODULE 18 | MODULE(magic) 19 | #endif 20 | 21 | #ifdef HASH_MODULE 22 | MODULE(hash) 23 | #endif 24 | 25 | #ifdef MACHO_MODULE 26 | MODULE(macho) 27 | #endif 28 | 29 | #ifdef DEX_MODULE 30 | MODULE(dex) 31 | #endif 32 | 33 | #ifdef PB_TESTS_MODULE 34 | MODULE(pb_tests) 35 | #endif 36 | -------------------------------------------------------------------------------- /libyara/include/yara/simple_str.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIMPLESTR_H 2 | #define _SIMPLESTR_H 3 | 4 | #include 5 | 6 | /* Simple dynamic string implementation for more readable/maintainable code 7 | Can be further optimized */ 8 | typedef struct _SIMPLE_STR 9 | { 10 | uint32_t len; 11 | uint32_t cap; 12 | char* str; 13 | } SIMPLE_STR, *PSIMPLE_STR; 14 | 15 | SIMPLE_STR* sstr_new(const char* s); 16 | SIMPLE_STR* sstr_newf(const char* fmt, ...); 17 | void sstr_free(SIMPLE_STR* ss); 18 | bool sstr_appendf(SIMPLE_STR* ss, const char* fmt, ...); 19 | char* sstr_move(SIMPLE_STR* ss); 20 | 21 | #endif -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of YARA authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | # Please keep the list sorted. 10 | 11 | Avast 12 | Google Inc. 13 | Hilko Bengen 14 | Joachim Metz 15 | Stefan Buehlmann 16 | Victor M. Alvarez ; 17 | Wesley Shields 18 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | Reporting security issues 2 | ========================= 3 | 4 | The YARA authors try their best to keep this software free of security issues, 5 | but 100% secure software does not exist. We appreciate all kinds of bug reports, 6 | but those that constitute a security vulnerability are specially welcomed and 7 | they will be prioritized and publicly acknowledged. 8 | 9 | Please do not open a GitHub issue to report a security vulnerability. If you 10 | believe you have found a security vulnerability, please submit your report to 11 | 12 | ``` 13 | vmalvarez@virustotal.com 14 | ``` 15 | 16 | We'll get back to you as soon as possible (usually in 1-2 days). 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Please complete the following information:** 23 | - OS: [e.g. iOS] 24 | - YARA version: [e.g. 4.3.0] 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /libyara/include/yara/elf_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef YR_ELF_UTILS_H 2 | #define YR_ELF_UTILS_H 3 | 4 | #include 5 | 6 | typedef struct _ELF_SYMBOL 7 | { 8 | char *name; 9 | int value; 10 | int size; 11 | int type; 12 | int bind; 13 | int shndx; 14 | int visibility; 15 | 16 | struct _ELF_SYMBOL *next; // Next symbol in the list 17 | } ELF_SYMBOL; 18 | 19 | // Linked list of symbols 20 | typedef struct _ELF_SYMBOL_LIST 21 | { 22 | int count; 23 | ELF_SYMBOL *symbols; 24 | } ELF_SYMBOL_LIST; 25 | 26 | typedef struct _ELF 27 | { 28 | ELF_SYMBOL_LIST *symtab; 29 | ELF_SYMBOL_LIST *dynsym; 30 | char *telfhash; 31 | char *import_hash; 32 | } ELF; 33 | 34 | #endif //YR_ELF_UTILS_H 35 | -------------------------------------------------------------------------------- /tests/data/test-pb.data: -------------------------------------------------------------------------------- 1 | # 2 | # Data used by test-pb.c. 3 | # 4 | # The structure for this data is defined in: 5 | # libyara/modules/pb_tests/pb_tests.proto 6 | # 7 | # Use the command below for encoding the data in binary form: 8 | # protoc -I./libyara/pb -I./libyara/modules/pb_tests --encode=test.RootMessage \ 9 | # libyara/modules/pb_tests/pb_tests.proto < tests/data/test-pb.data > tests/data/test-pb.data.bin 10 | # 11 | 12 | f_int32: 1111 13 | f_int64: 2222 14 | f_string: "foo" 15 | f_struct_array: [ 16 | { 17 | f_string: "bar" 18 | f_enum: 1 19 | }, 20 | { 21 | f_string: "baz" 22 | f_nested_struct: { 23 | f_int32: 3333 24 | } 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest a new feature for this project 4 | title: '' 5 | labels: feature-request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/oss-fuzz.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | Fuzzing: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Build Fuzzers 10 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 11 | with: 12 | oss-fuzz-project-name: 'yara' 13 | dry-run: false 14 | - name: Run Fuzzers 15 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 16 | with: 17 | oss-fuzz-project-name: 'yara' 18 | fuzz-seconds: 600 19 | dry-run: false 20 | - name: Upload Crash 21 | uses: actions/upload-artifact@v4 22 | if: failure() 23 | with: 24 | name: artifacts 25 | path: ./out/artifacts 26 | -------------------------------------------------------------------------------- /libyara/tlshc/tlsh_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLSH_TLSH_UTIL_H__ 2 | #define __TLSH_TLSH_UTIL_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | // unsigned char b_mapping(unsigned char salt, unsigned char i, unsigned char 10 | // j, unsigned char k); 11 | unsigned char l_capturing(unsigned int len); 12 | int mod_diff(unsigned int x, unsigned int y, unsigned int R); 13 | int h_distance(int len, const unsigned char x[], const unsigned char y[]); 14 | void to_hex(unsigned char* psrc, int len, char* pdest); 15 | void from_hex(const char* psrc, int len, unsigned char* pdest); 16 | unsigned char swap_byte(const unsigned char in); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // __TLSH_TLSH_UTIL_H__ -------------------------------------------------------------------------------- /docs/modules.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | Modules 3 | ******* 4 | 5 | Modules are the method YARA provides for extending its features. They allow you 6 | to define data structures and functions which can be used in your rules to 7 | express more complex conditions. Here you'll find described some modules 8 | officially distributed with YARA, but you can also learn how to write your own 9 | modules in the :ref:`writing-modules` section. 10 | 11 | 12 | .. toctree:: 13 | :maxdepth: 3 14 | 15 | PE 16 | ELF 17 | Cuckoo 18 | Magic 19 | Hash 20 | Math 21 | Dotnet 22 | Time 23 | Console 24 | String 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/convention-portable-modifiers: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # pseudo code: 4 | # - find all .[ch] files in libyara/ 5 | # - grep for non-portable modifiers 6 | 7 | set -e 8 | find . -type f | egrep "\.[ch]$" | xargs egrep --line-number "\%\'{0,1}l[dux]" | perl -lane ' 9 | printf qq[- convention: non-portable modifier: %s\n], $_; 10 | $single_quote = chr(0x27); 11 | s~\%$single_quote{0,1}l([dux])~\%" PRI${1}64 "~g; 12 | printf qq[- convention: portable modifier: %s\n], $_; 13 | $violation_count ++; 14 | sub END { 15 | if ($violation_count > 0) { 16 | printf qq[- convention: non-portable modifier: %u instances found above; please fix\n], $violation_count; 17 | exit(1); 18 | } 19 | printf qq[- convention: non-portable modifier: none found\n]; 20 | }' 21 | 22 | exit 0 23 | -------------------------------------------------------------------------------- /libyara/pb/yara.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package yara; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message ModuleOptions { 8 | string name = 1; 9 | string root_message = 2; 10 | } 11 | 12 | message FieldOptions { 13 | string name = 1; 14 | bool ignore = 2; 15 | } 16 | 17 | message MessageOptions { 18 | string name = 1; 19 | } 20 | 21 | message EnumOptions { 22 | string name = 1; 23 | } 24 | 25 | extend google.protobuf.FileOptions { 26 | ModuleOptions module_options = 51503; 27 | } 28 | 29 | extend google.protobuf.FieldOptions { 30 | FieldOptions field_options = 51504; 31 | } 32 | 33 | extend google.protobuf.MessageOptions { 34 | MessageOptions message_options = 51505; 35 | } 36 | 37 | extend google.protobuf.EnumOptions { 38 | EnumOptions enum_options = 51506; 39 | } 40 | -------------------------------------------------------------------------------- /extra/UltraEdit-wordfile.txt: -------------------------------------------------------------------------------- 1 | /L20"YARA rules" YARA_LANG Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = " File Extensions = YAR 2 | /Marker Characters = "//" 3 | /Delimiters = ~!@%^&*()-+=|\/{}[]<>:;"' , .? 4 | /Function String = "rule [a-zA-Z0-9_]*" 5 | /Indent Strings = "{" 6 | /Unindent Strings = "}" 7 | /Open Brace Strings = "{" "(" "[" 8 | /Close Brace Strings = "}" ")" "]" 9 | 10 | /C1"YARA Keywords" 11 | and at any all ascii 12 | condition contains 13 | endswith entrypoint 14 | for false filesize fullword 15 | global 16 | icontains iendswith is istartswith in include int8 int16 int32 17 | meta matches 18 | nocase not 19 | or of 20 | private 21 | rule rva 22 | section startswith strings 23 | them true 24 | uint8 uint16 uint32 25 | wide 26 | 27 | /C4"YARA Strings" 28 | " 29 | // / 30 | -------------------------------------------------------------------------------- /.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | name: Coverity 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | 7 | jobs: 8 | coverity: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Install dependencies 13 | run: | 14 | sudo apt-get update 15 | sudo apt-get install -y \ 16 | autoconf \ 17 | automake \ 18 | gcc-multilib \ 19 | libtool \ 20 | libjansson-dev \ 21 | libmagic-dev \ 22 | libssl-dev 23 | - name: Prepare for building 24 | run: | 25 | ./bootstrap.sh 26 | ./configure 27 | - uses: vapier/coverity-scan-action@v1 28 | with: 29 | project: 'plusvic/yara' 30 | email: ${{ secrets.COVERITY_SCAN_EMAIL }} 31 | token: ${{ secrets.COVERITY_SCAN_TOKEN }} 32 | -------------------------------------------------------------------------------- /tests/data/tiny.notes: -------------------------------------------------------------------------------- 1 | tiny.exe was compiled from a simple oneliner, 2 | 3 | int main() { return 42; } 4 | 5 | $ i686-w64-mingw32-gcc -s -Wl,--file-alignment=4096 -o tiny.exe tiny.c 6 | 7 | To demonstrate issue #429, two patched executables have been generated 8 | where the PointerToRawData for the .idata section (offset 0x22c) was 9 | changed from 0x5000 to 0x51ff (tiny-idata-51ff.exe) and 0x5200 10 | (tiny-idata-5200.exe), respectively. While tiny-idata-51ff.exe can be 11 | executed in Windows XP, tiny-idata-5200.exe can not. 12 | 13 | 14 | 15 | Compiler version used to produce tiny.exe: 16 | 17 | $ i686-w64-mingw32-gcc --version 18 | i686-w64-mingw32-gcc (GCC) 5.3.1 20160205 19 | Copyright (C) 2015 Free Software Foundation, Inc. 20 | This is free software; see the source for copying conditions. There is NO 21 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | 23 | -------------------------------------------------------------------------------- /tests/oss-fuzz/dex_fuzzer.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | YR_RULES* rules = NULL; 7 | 8 | 9 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 10 | { 11 | YR_COMPILER* compiler; 12 | 13 | if (yr_initialize() != ERROR_SUCCESS) 14 | return 0; 15 | 16 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 17 | return 0; 18 | 19 | if (yr_compiler_add_string(compiler, "import \"dex\"", NULL) == 0) 20 | yr_compiler_get_rules(compiler, &rules); 21 | 22 | yr_compiler_destroy(compiler); 23 | 24 | return 0; 25 | } 26 | 27 | 28 | int callback( 29 | YR_SCAN_CONTEXT* context, 30 | int message, 31 | void* message_data, 32 | void* user_data) 33 | { 34 | return CALLBACK_CONTINUE; 35 | } 36 | 37 | 38 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 39 | { 40 | if (rules == NULL) 41 | return 0; 42 | 43 | yr_rules_scan_mem( 44 | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /libyara/modules/pb_to_module.rst: -------------------------------------------------------------------------------- 1 | Generating a module from a Protocol Buffer 2 | 3 | 4 | [Protocol Buffers](https://developers.google.com/protocol-buffers) (protobufs) 5 | are Google's language-neutral, platform-idependent mechanism for serializing 6 | structured data. The first thing you need to do for using protobuf is defining 7 | your data structures, for example: 8 | 9 | message Employee { 10 | int32 id = 1; 11 | string name = 2; 12 | int32 age = 3 13 | string email = 4; 14 | } 15 | 16 | Once you have defined your data structure, you use a protobuf compiler to 17 | automatically generate the code that will marshal/unmarshall the data structure 18 | into/from a bytes sequence. The protobuf compiler is able to generate code in 19 | multiple languages, including C/C++, Python, Java and Go. 20 | 21 | Now imagine that you can pass the marshalled data structure to YARA, and create 22 | rules based in that data. Like for example: 23 | 24 | import "vt_employee" 25 | 26 | rule virustotal_employee_under_25 27 | { 28 | condition: 29 | vt_employee.age < 25 and 30 | vt_employee.email matches /*.@virustotal\.com/ 31 | } 32 | 33 | Neat, right? 34 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.12" 12 | # You can also specify other tool versions: 13 | # nodejs: "20" 14 | # rust: "1.70" 15 | # golang: "1.20" 16 | 17 | # Build documentation in the "docs/" directory with Sphinx 18 | sphinx: 19 | configuration: docs/conf.py 20 | # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs 21 | # builder: "dirhtml" 22 | # Fail on all warnings to avoid broken references 23 | # fail_on_warning: true 24 | 25 | # Optionally build your docs in additional formats such as PDF and ePub 26 | # formats: 27 | # - pdf 28 | # - epub 29 | 30 | # Optional but recommended, declare the Python requirements required 31 | # to build your documentation 32 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 33 | python: 34 | install: 35 | - requirements: docs/requirements.txt 36 | -------------------------------------------------------------------------------- /dist/yara-python.spec: -------------------------------------------------------------------------------- 1 | %define name yara-python 2 | %define version 3.2.0 3 | %define unmangled_version 3.2.0 4 | %define release 1 5 | 6 | Summary: Python bindings for YARA malware research tool 7 | Name: %{name} 8 | Version: %{version} 9 | Release: %{release} 10 | Source0: %{name}-%{unmangled_version}.tar.gz 11 | License: Apache License 2.0 12 | Group: Development/Libraries 13 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot 14 | Prefix: %{_prefix} 15 | Vendor: Victor M. Alvarez 16 | BuildRequires: gcc python-devel 17 | BuildRequires: libyara-devel 18 | 19 | %description 20 | YARA is a tool aimed at (but not limited to) helping malware researchers to identify and classify malware samples. With YARA you can create descriptions of malware families (or whatever you want to describe) based on textual or binary patterns. 21 | 22 | %prep 23 | %setup -n %{name}-%{unmangled_version} 24 | 25 | %build 26 | env CFLAGS="$RPM_OPT_FLAGS" python setup.py build 27 | 28 | %install 29 | python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES 30 | 31 | %clean 32 | rm -rf $RPM_BUILD_ROOT 33 | 34 | %files -f INSTALLED_FILES 35 | %defattr(-,root,root) 36 | -------------------------------------------------------------------------------- /tests/gcov-summary: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # pseudo code: 4 | # - find all .c files in libyara/ 5 | # - run gcov --preserve-paths 6 | # - fold gcov output into single summary line output 7 | # - remember files not executed, and percentages 8 | # - at end: output grand total percentage 9 | # - at end: output files not executed 10 | 11 | cd libyara/ 12 | find . -type f | egrep "\.c$" | perl -lane ' 13 | if (-e $_) { 14 | $cmd = qq[gcov --preserve-paths $_]; 15 | $out = `$cmd 2>&1`; 16 | $out =~ s~(Creating|[^\n]+cannot open notes) [^\n]+\s+~~gs; 17 | @out = split(m~\n~, $out); 18 | foreach(reverse @out) { 19 | if (m~assuming not executed~) { 20 | push @assume, $_; 21 | next; 22 | } 23 | if (m~Lines executed:([\d\.]+). of (\d+)~) { 24 | $loc_tot += $2; 25 | $loc_exe += ($2 * $1 / 100); 26 | } 27 | printf qq[%-32s%s], $_, m~^Lines~ ? q[] : qq[\n]; 28 | } 29 | } 30 | sub END { 31 | if ($loc_tot) { 32 | printf qq[Lines executed:%.2f%% of %u total lines in all executed code\n\n], $loc_exe / $loc_tot * 100, $loc_tot; 33 | } 34 | foreach(@assume) { 35 | printf qq[%s\n], $_; 36 | } 37 | }' 38 | 39 | exit 0 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generic auto-generated build files 2 | *~ 3 | *.a 4 | *.gcda 5 | *.gcno 6 | *.gcov 7 | *.la 8 | *.lai 9 | *.lo 10 | *.Plo 11 | *.Po 12 | *.o 13 | *.so 14 | *.so.[0-9][0-9]* 15 | *.so.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]* 16 | *.Tpo 17 | *.m4 18 | *.dSYM 19 | .deps 20 | .libs 21 | INSTALL 22 | Makefile 23 | Makefile.in 24 | stamp-h1 25 | 26 | # Specific auto-generated build files 27 | /ABOUT-NLS 28 | /aclocal.m4 29 | /ar-lib 30 | /autom4te.cache/ 31 | /build-aux 32 | /compile 33 | /config.guess 34 | /config.h 35 | /config.h.in 36 | /config.log 37 | /config.rpath 38 | /config.status 39 | /config.sub 40 | /configure 41 | /depcomp 42 | /install-sh 43 | /libtool 44 | /ltmain.sh 45 | /missing 46 | /test-driver 47 | /ylwrap 48 | /m4 49 | !/m4/acx_pthread.m4 50 | 51 | # Project specific files 52 | /yara 53 | /yarac 54 | /libyara/modules/.dirstamp 55 | libyara/proc/.dirstamp 56 | /yara.pc 57 | /tests/.dirstamp 58 | 59 | # Linux and Mac files 60 | *.swp 61 | .DS_Store 62 | 63 | # Files generated by tests 64 | test-*[^.c] 65 | test-async 66 | test-magic 67 | test-rules.yarc 68 | 69 | # Bazel 70 | bazel-* 71 | 72 | # Visual Studio files 73 | Release/ 74 | Debug/ 75 | windows/*/.vs 76 | x64/ 77 | *.obj 78 | *.suo 79 | *.sdf 80 | *.opendb 81 | *.opensdf 82 | *.VC.db 83 | 84 | # NuGet 85 | windows/*/packages/ 86 | *.trs 87 | *.log 88 | .dirstamp 89 | 90 | .idea/ 91 | .vscode/ 92 | 93 | tests/mapper 94 | -------------------------------------------------------------------------------- /tests/data/baz.yar: -------------------------------------------------------------------------------- 1 | /* 2 | Add padding for making the file large enough to trigger issue #884 3 | 4 | pading pading pading pading pading pading pading pading pading pading 5 | pading pading pading pading pading pading pading pading pading pading 6 | pading pading pading pading pading pading pading pading pading pading 7 | pading pading pading pading pading pading pading pading pading pading 8 | pading pading pading pading pading pading pading pading pading pading 9 | pading pading pading pading pading pading pading pading pading pading 10 | pading pading pading pading pading pading pading pading pading pading 11 | pading pading pading pading pading pading pading pading pading pading 12 | pading pading pading pading pading pading pading pading pading pading 13 | pading pading pading pading pading pading pading pading pading pading 14 | pading pading pading pading pading pading pading pading pading pading 15 | pading pading pading pading pading pading pading pading pading pading 16 | pading pading pading pading pading pading pading pading pading pading 17 | pading pading pading pading pading pading pading pading pading pading 18 | pading pading pading pading pading pading pading pading pading pading 19 | pading pading pading pading pading pading pading pading pading pading 20 | pading pading pading pading pading pading pading pading pading pading 21 | pading pading pading pading pading pading pading pading pading pading 22 | */ 23 | 24 | rule baz { condition: true } 25 | -------------------------------------------------------------------------------- /docs/modules/string.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _string-module: 3 | 4 | ########### 5 | String module 6 | ########### 7 | 8 | .. versionadded:: 4.3.0 9 | 10 | The String module provides functions for manipulating strings as returned by 11 | modules. The strings referenced here are not YARA strings as defined in the 12 | strings section of your rule. 13 | 14 | .. c:function:: to_int(string) 15 | 16 | .. versionadded:: 4.3.0 17 | 18 | Convert the given string to a signed integer. If the string starts with "0x" 19 | it is treated as base 16. If the string starts with "0" it is treated base 20 | 8. Leading '+' or '-' is also supported. 21 | 22 | *Example: string.to_int("1234") == 1234* 23 | *Example: string.to_int("-10") == -10* 24 | *Example: string.to_int("-010") == -8* 25 | 26 | .. c:function:: to_int(string, base) 27 | 28 | .. versionadded:: 4.3.0 29 | 30 | Convert the given string, interpreted with the given base, to a signed 31 | integer. Base must be 0 or between 2 and 36 inclusive. If it is zero then 32 | the string will be intrepreted as base 16 if it starts with "0x" or as base 33 | 8 if it starts with "0". Leading '+' or '-' is also supported. 34 | 35 | *Example: string.to_int("011", 8) == 9* 36 | *Example: string.to_int("-011", 0) == -9* 37 | 38 | .. c:function:: length(string) 39 | 40 | .. versionadded:: 4.3.0 41 | 42 | Return the length of the string, which can be any sequence of bytes. NULL 43 | bytes included. 44 | 45 | *Example: string.length("AXS\x00ERS") == 7* 46 | 47 | -------------------------------------------------------------------------------- /tests/test-magic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "blob.h" 6 | #include "util.h" 7 | 8 | int main(int argc, char** argv) 9 | { 10 | int result = 0; 11 | 12 | YR_DEBUG_INITIALIZE(); 13 | YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]); 14 | 15 | init_top_srcdir(); 16 | 17 | yr_initialize(); 18 | 19 | assert_true_rule_blob( 20 | "import \"magic\" rule test { condition: \ 21 | magic.type() contains \"ELF\" }", 22 | ELF32_FILE); 23 | 24 | assert_true_rule_blob( 25 | "import \"magic\" rule test { condition: \ 26 | ( magic.type() contains \"MS-DOS executable\" or \ 27 | magic.type() contains \"PE32+ executable\" or \ 28 | magic.type() contains \"PE32 executable\") and \ 29 | ( magic.mime_type() == \"application/x-dosexec\" or \ 30 | magic.mime_type() == \"application/vnd.microsoft.portable-executable\" ) }", 31 | PE32_FILE); 32 | 33 | // Test case for https://github.com/VirusTotal/yara/issues/1663 34 | assert_true_rule_blob( 35 | "import \"magic\" rule test { condition: \ 36 | magic.type() contains \"Mach-O\" and \ 37 | (magic.mime_type() == \"application/x-mach-binary\" or magic.mime_type() == \"application/octet-stream\") and \ 38 | magic.type() contains \"Mach-O\"}", 39 | MACHO_X86_FILE); 40 | 41 | yr_finalize(); 42 | 43 | YR_DEBUG_FPRINTF( 44 | 1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]); 45 | 46 | return result; 47 | } 48 | -------------------------------------------------------------------------------- /libyara/tlshc/tlsh.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "tlsh_impl.h" 4 | 5 | Tlsh* tlsh_new() 6 | { 7 | Tlsh* tlsh = malloc(sizeof(Tlsh)); 8 | if (!tlsh) 9 | return NULL; 10 | 11 | tlsh->impl = tlsh_impl_new(); 12 | if (!tlsh->impl) 13 | { 14 | free(tlsh); 15 | return NULL; 16 | } 17 | 18 | return tlsh; 19 | } 20 | 21 | void tlsh_free(Tlsh* tlsh) 22 | { 23 | if (tlsh) 24 | { 25 | tlsh_impl_free(tlsh->impl); 26 | free(tlsh); 27 | } 28 | } 29 | 30 | int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len) 31 | { 32 | int tlsh_option = 0; 33 | if (tlsh->impl) 34 | { 35 | int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option); 36 | if (res) 37 | { 38 | return 1; 39 | } 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | void tlsh_reset(Tlsh* tlsh) 46 | { 47 | if (tlsh->impl) 48 | tlsh_impl_reset(tlsh->impl); 49 | } 50 | 51 | int tlsh_final( 52 | Tlsh* tlsh, 53 | const unsigned char* data, 54 | unsigned int len, 55 | int tlsh_option) 56 | { 57 | if (tlsh->impl) 58 | { 59 | if ((data != NULL) && (len > 0)) 60 | { 61 | int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option); 62 | if (res) 63 | { 64 | return 1; 65 | } 66 | } 67 | 68 | tlsh_impl_final(tlsh->impl, tlsh_option); 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | const char* tlsh_get_hash(Tlsh* tlsh, bool showvers) 75 | { 76 | if (tlsh->impl) 77 | return tlsh_impl_hash(tlsh->impl, showvers); 78 | else 79 | return ""; 80 | } -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2016. The YARA Authors. All Rights Reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation and/or 11 | other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /extra/codemirror/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CodeMirror: YARA mode 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 26 | 27 |
28 |

YARA mode

29 |
30 | 42 |
43 | 53 |

MIME type: text/x-yara

54 |
55 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. yara documentation master file, created by 2 | sphinx-quickstart on Tue Jul 8 11:04:03 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to YARA's documentation! 7 | ================================ 8 | 9 | YARA is a tool aimed at (but not limited to) helping malware researchers to 10 | identify and classify malware samples. With YARA you can create descriptions of malware families (or whatever you want to describe) based on textual or binary patterns. Each description, a.k.a. rule, consists of a set of strings and a 11 | boolean expression which determine its logic. Let's see an example: 12 | 13 | .. code-block:: yara 14 | 15 | rule silent_banker : banker 16 | { 17 | meta: 18 | description = "This is just an example" 19 | threat_level = 3 20 | in_the_wild = true 21 | strings: 22 | $a = {6A 40 68 00 30 00 00 6A 14 8D 91} 23 | $b = {8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9} 24 | $c = "UVODFRYSIHLNWPEJXQZAKCBGMT" 25 | condition: 26 | $a or $b or $c 27 | } 28 | 29 | The above rule is telling YARA that any file containing one of the three strings 30 | must be reported as silent_banker. This is just a simple example, more complex 31 | and powerful rules can be created by using wild-cards, case-insensitive strings, regular expressions, special operators and many other features that you'll find explained in this documentation. 32 | 33 | Contents: 34 | 35 | .. toctree:: 36 | :maxdepth: 3 37 | 38 | gettingstarted 39 | writingrules 40 | modules 41 | writingmodules 42 | commandline 43 | yarapython 44 | capi 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This is the official list of people who can contribute 2 | # (and typically have contributed) code to the YARA repository. 3 | # The AUTHORS file lists the copyright holders; this file 4 | # lists people. For example, Google employees are listed here 5 | # but not in AUTHORS, because Google holds the copyright. 6 | # 7 | # The submission process automatically checks to make sure 8 | # that people submitting code are listed in this file (by email address). 9 | # 10 | # Names should be added to this file only after verifying that 11 | # the individual or the individual's organization has agreed to 12 | # the appropriate Contributor License Agreement, found here: 13 | # 14 | # http://code.google.com/legal/individual-cla-v1.0.html 15 | # http://code.google.com/legal/corporate-cla-v1.0.html 16 | # 17 | # The agreement for individuals can be filled out on the web. 18 | # 19 | # When adding J Random Contributor's name to this file, 20 | # either J's name or J's organization's name should be 21 | # added to the AUTHORS file, depending on whether the 22 | # individual or corporate CLA was used. 23 | 24 | # Names should be added to this file like so: 25 | # Name 26 | 27 | # Please keep the list sorted. 28 | 29 | Anthony Desnos 30 | Antonio Vargas Gonzalez 31 | Christian Blichmann 32 | Hilko Bengen 33 | Joachim Metz 34 | Karel Hajek 35 | Karl Hiramoto 36 | Mike Wiacek 37 | Shane Huntley 38 | Stefan Buehlmann 39 | Victor M. Alvarez ; 40 | Wesley Shields 41 | -------------------------------------------------------------------------------- /yarac.man: -------------------------------------------------------------------------------- 1 | .\"Text automatically generated by txt2man 2 | .TH YARAC "1" "Jan 2014" "YARAC 2.0" "compile rules to yara" 3 | .SH NAME 4 | \fByarac \fP- compile rules to yara 5 | .SH SYNOPSIS 6 | .nf 7 | .fam C 8 | \fByarac\fP [OPTION]\.\.\. [RULE_FILE]\.\.\. \fIOUTPUT_FILE\fP 9 | .fam T 10 | .fi 11 | .fam T 12 | .fi 13 | .SH DESCRIPTION 14 | To invoke YARA you will need two things: a file with the rules you want to 15 | use (either in source code or compiled form) and the target to be scanned. 16 | The target can be a file, a folder, or a process. 17 | .PP 18 | Rule files can be passed directly in source code form, or can be previously 19 | compiled with the \fByarac\fP tool. You may prefer to use your rules in compiled 20 | form if you are going to invoke YARA multiple times with the same rules. 21 | This way you’ll save time, because for YARA is faster to load compiled rules 22 | than compiling the same rules over and over again. 23 | .PP 24 | The rules will be applied to the target specified as the last argument to YARA, 25 | if it’s a path to a directory all the files contained in it will be scanned. 26 | .SH OPTIONS 27 | .TP 28 | .B 29 | \fB-d\fP = 30 | define external variable. 31 | .TP 32 | .B \-w " --no-warnings" 33 | Disable warnings. 34 | .TP 35 | .B " --fail-on-warnings" 36 | Treat warnings as errors. Has no effect if used with 37 | .B --no-warnings. 38 | .TP 39 | .B \-v " --version" 40 | Show version information. 41 | .SH EXAMPLE 42 | The \fB-d\fP is used to define external variables. For example: 43 | .PP 44 | \fB-d\fP flag=true 45 | .PP 46 | \fB-d\fP beast=666 47 | .PP 48 | \fB-d\fP name="James Bond" 49 | .SH SEE ALSO 50 | \fByara\fP(1) 51 | .SH AUTHOR 52 | \fByarac\fP was written by Victor M. Alvarez . 53 | This manual page was written by Joao Eriberto Mota Filho for the Debian project (but may be used by others). 54 | -------------------------------------------------------------------------------- /libyara/include/yara/exefiles.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_EXEFILES_H 31 | #define YR_EXEFILES_H 32 | 33 | uint64_t yr_get_entry_point_offset(const uint8_t* buffer, size_t buffer_length); 34 | 35 | uint64_t yr_get_entry_point_address( 36 | const uint8_t* buffer, 37 | size_t buffer_length, 38 | uint64_t base_address); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libyara/modules/pb_tests/pb_tests.proto: -------------------------------------------------------------------------------- 1 | 2 | syntax = "proto2"; 3 | 4 | package test; 5 | import "yara.proto"; 6 | 7 | option (yara.module_options) = { 8 | name : "pb_tests" 9 | root_message: "RootMessage"; 10 | }; 11 | 12 | 13 | message Struct { 14 | option (yara.message_options).name = "struct"; 15 | required string f_string = 1; 16 | enum Enum { 17 | option (yara.enum_options).name = "enum"; 18 | FIRST = 0; 19 | SECOND = 1; 20 | } 21 | optional Enum f_enum = 2; 22 | message NestedStruct { 23 | optional int32 f_int32 = 1; 24 | optional string f_string = 2; 25 | } 26 | optional NestedStruct f_nested_struct = 3; 27 | repeated NestedStruct f_nested_struct_array = 4; 28 | } 29 | 30 | message MapStruct { 31 | optional int32 f_int32 = 1; 32 | optional int64 f_int64 = 2; 33 | } 34 | 35 | message RootMessage { 36 | optional int32 f_int32 = 1; 37 | optional int64 f_int64 = 2; 38 | //optional uint32 f_uint32 = 3; // not supported 39 | //optional uint64 f_uint64 = 4; // not supported 40 | optional sint32 f_sint32 = 5; 41 | optional sint64 f_sint64 = 6; 42 | //optional fixed32 f_fixed32 = 7; // not supported 43 | //optional fixed64 f_fixed64 = 8; // not supported 44 | optional sfixed32 f_sfixed32 = 9; 45 | optional sfixed64 f_sfixed64 = 10; 46 | optional bool f_bool = 11; 47 | optional string f_string = 12; 48 | optional bytes f_bytes = 13; 49 | repeated Struct f_struct_array = 14; 50 | map f_map_int32 = 15; 51 | map f_map_bool = 16; 52 | map f_map_string = 17; 53 | map f_map_float = 18; 54 | map f_map_struct = 19; 55 | oneof f_oneof { 56 | string f_oneof_string = 20; 57 | MapStruct f_oneof_struct = 21; 58 | } 59 | optional string f_ignored = 22 [(yara.field_options).ignore = true]; 60 | optional string f_renamed = 23 [(yara.field_options).name = "f_yara_name"]; 61 | } 62 | -------------------------------------------------------------------------------- /tests/data/base64: -------------------------------------------------------------------------------- 1 | Plaintext Encoded Substring 2 | This program cannot VGhpcyBwcm9ncmFtIGNhbm5vdA== VGhpcyBwcm9ncmFtIGNhbm5vd 3 | AThis program cannot QVRoaXMgcHJvZ3JhbSBjYW5ub3Q= RoaXMgcHJvZ3JhbSBjYW5ub3 4 | AAThis program cannot QUFUaGlzIHByb2dyYW0gY2Fubm90 UaGlzIHByb2dyYW0gY2Fubm90 5 | 6 | These are the wide versions of the string. To make it easier I'm splitting 7 | them each onto their own line. 8 | This program cannot 9 | VABoAGkAcwAgAHAAcgBvAGcAcgBhAG0AIABjAGEAbgBuAG8AdAA= 10 | VABoAGkAcwAgAHAAcgBvAGcAcgBhAG0AIABjAGEAbgBuAG8AdA 11 | 12 | AThis program cannot 13 | QVQAaABpAHMAIABwAHIAbwBnAHIAYQBtACAAYwBhAG4AbgBvAHQA 14 | QAaABpAHMAIABwAHIAbwBnAHIAYQBtACAAYwBhAG4AbgBvAHQA 15 | 16 | AAThis program cannot 17 | QUFUAGgAaQBzACAAcAByAG8AZwByAGEAbQAgAGMAYQBuAG4AbwB0AA== 18 | UAGgAaQBzACAAcAByAG8AZwByAGEAbQAgAGMAYQBuAG4AbwB0A 19 | 20 | These are the ascii strings converted to base64wide 21 | VGhpcyBwcm9ncmFtIGNhbm5vdA== 22 | QVRoaXMgcHJvZ3JhbSBjYW5ub3Q= 23 | QUFUaGlzIHByb2dyYW0gY2Fubm90 24 | 25 | These are the wide strings converted to base64wide 26 | VABoAGkAcwAgAHAAcgBvAGcAcgBhAG0AIABjAGEAbgBuAG8AdAA= 27 | QVQAaABpAHMAIABwAHIAbwBnAHIAYQBtACAAYwBhAG4AbgBvAHQA 28 | QUFUAGgAaQBzACAAcAByAG8AZwByAGEAbQAgAGMAYQBuAG4AbwB0AA== 29 | 30 | Encoded with a custom alphabet (still using = for padding): 31 | !@#$%^&*(){}[].,|ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu 32 | E&QYLh@fLVsWLV^c(&]QKVoeM!== 33 | |EAXJG[PL*)eIm)QKB@SHFodKm|= 34 | |D^DJ&Ui(*@hKlMhHFjPHl^dKVsj 35 | 36 | Encoded single byte (a) base64, second encoding is skipped 37 | YQ== 38 | AGE= 39 | AABh 40 | Encoded single byte (a) base64, second encoding is skipped 41 | YQ== 42 | AGE= 43 | AABh 44 | -------------------------------------------------------------------------------- /libyara/include/yara.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007-2013. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_YARA_H 31 | #define YR_YARA_H 32 | 33 | #include "yara/compiler.h" 34 | #include "yara/error.h" 35 | #include "yara/filemap.h" 36 | #include "yara/hash.h" 37 | #include "yara/libyara.h" 38 | #include "yara/mem.h" 39 | #include "yara/modules.h" 40 | #include "yara/object.h" 41 | #include "yara/scanner.h" 42 | #include "yara/stream.h" 43 | #include "yara/strutils.h" 44 | #include "yara/utils.h" 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /sandbox/collect_matches.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef SANDBOX_COLLECT_MATCHES_H_ 31 | #define SANDBOX_COLLECT_MATCHES_H_ 32 | 33 | struct YR_SCAN_CONTEXT; 34 | 35 | namespace yara { 36 | 37 | // Callback function for yr_scan_mem() that collects YARA matches in a 38 | // YaraMatches proto given in user_data. 39 | int CollectMatches(YR_SCAN_CONTEXT*, int message, void* message_data, 40 | void* user_data); 41 | 42 | } // namespace yara 43 | 44 | #endif // SANDBOX_COLLECT_MATCHES_H_ 45 | -------------------------------------------------------------------------------- /libyara/include/yara/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2020. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_BASE64_H 31 | #define YR_BASE64_H 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | typedef struct BASE64_NODE BASE64_NODE; 38 | 39 | struct BASE64_NODE 40 | { 41 | SIZED_STRING* str; 42 | int escaped; 43 | BASE64_NODE* next; 44 | }; 45 | 46 | int yr_base64_ast_from_string( 47 | SIZED_STRING* in_str, 48 | YR_MODIFIER modifier, 49 | RE_AST** re_ast, 50 | RE_ERROR* error); 51 | #endif 52 | -------------------------------------------------------------------------------- /libyara/modules/pe/authenticode-parser/certificate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Avast Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | */ 21 | 22 | #ifndef AUTHENTICODE_PARSER_CERTIFICATE_H 23 | #define AUTHENTICODE_PARSER_CERTIFICATE_H 24 | 25 | #include 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | Certificate* certificate_new(X509* x509); 34 | Certificate* certificate_copy(Certificate* cert); 35 | void certificate_free(Certificate* cert); 36 | 37 | void parse_x509_certificates(const STACK_OF(X509) * certs, CertificateArray* result); 38 | 39 | CertificateArray* parse_signer_chain(X509* signer_cert, STACK_OF(X509) * certs); 40 | int certificate_array_move(CertificateArray* dst, CertificateArray* src); 41 | int certificate_array_append(CertificateArray* dst, CertificateArray* src); 42 | CertificateArray* certificate_array_new(int certCount); 43 | void certificate_array_free(CertificateArray* arr); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /cli/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017-2021. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | 31 | #ifndef COMMON_H 32 | #define COMMON_H 33 | 34 | #include 35 | 36 | #include "unicode.h" 37 | 38 | 39 | #ifdef _UNICODE 40 | char* unicode_to_ansi(const char_t* str); 41 | #endif 42 | 43 | bool compile_files( 44 | YR_COMPILER* compiler, 45 | int argc, 46 | const char_t** argv); 47 | 48 | int define_external_variables( 49 | char** ext_vars, 50 | YR_RULES* rules, 51 | YR_COMPILER* compiler); 52 | 53 | bool is_integer(const char *str); 54 | 55 | bool is_float(const char *str); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /libyara/stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | 34 | size_t yr_stream_read(void* ptr, size_t size, size_t count, YR_STREAM* stream) 35 | { 36 | if (stream->read == NULL) 37 | return 0; 38 | 39 | return stream->read(ptr, size, count, stream->user_data); 40 | } 41 | 42 | 43 | size_t yr_stream_write( 44 | const void* ptr, 45 | size_t size, 46 | size_t count, 47 | YR_STREAM* stream) 48 | { 49 | if (stream->write == NULL) 50 | return 0; 51 | 52 | return stream->write(ptr, size, count, stream->user_data); 53 | } 54 | -------------------------------------------------------------------------------- /tests/test-version.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "util.h" 34 | 35 | int main(int argc, char **argv) 36 | { 37 | YR_DEBUG_INITIALIZE(); 38 | YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]); 39 | 40 | // make sure that versions defined in configure.ac and in 41 | // libyara/include/yara/libyara.h are in sync. 42 | 43 | int result = strcmp(PACKAGE_VERSION, YR_VERSION); 44 | 45 | YR_DEBUG_FPRINTF( 46 | 1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]); 47 | 48 | return result; 49 | } 50 | -------------------------------------------------------------------------------- /libyara/include/tlshc/tlsh.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLSH_TLSH_H__ 2 | #define __TLSH_TLSH_H__ 3 | 4 | #include 5 | 6 | #define TLSH_OPTION_CONSERVATIVE 2 7 | #define TLSH_OPTION_KEEP_BUCKET 4 8 | #define TLSH_OPTION_PRIVATE 8 9 | #define TLSH_OPTION_THREADED 16 10 | 11 | // Define TLSH_STRING_LEN_REQ, which is the string length of "T1" + the hex 12 | // value of the Tlsh hash. BUCKETS_256 & CHECKSUM_3B are compiler switches 13 | // defined in CMakeLists.txt 14 | #if defined BUCKETS_256 15 | #define TLSH_STRING_LEN_REQ 136 16 | // changed the minimum data length to 256 for version 3.3 17 | #define MIN_DATA_LENGTH 50 18 | // added the -force option for version 3.5 19 | // added the -conservatibe option for version 3.17 20 | #define MIN_CONSERVATIVE_DATA_LENGTH 256 21 | #endif 22 | 23 | #if defined BUCKETS_128 24 | #define TLSH_STRING_LEN_REQ 72 25 | // changed the minimum data length to 256 for version 3.3 26 | #define MIN_DATA_LENGTH 50 27 | // added the -force option for version 3.5 28 | // added the -conservatibe option for version 3.17 29 | #define MIN_CONSERVATIVE_DATA_LENGTH 256 30 | #endif 31 | 32 | #if defined BUCKETS_48 33 | // No 3 Byte checksum option for 48 Bucket min hash 34 | #define TLSH_STRING_LEN 30 35 | // changed the minimum data length to 256 for version 3.3 36 | #define MIN_DATA_LENGTH 10 37 | // added the -force option for version 3.5 38 | #define MIN_CONSERVATIVE_DATA_LENGTH 10 39 | #endif 40 | 41 | #define TLSH_STRING_BUFFER_LEN (TLSH_STRING_LEN_REQ + 1) 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | typedef struct TlshImpl TlshImpl; 48 | 49 | typedef struct { 50 | TlshImpl* impl; 51 | } Tlsh; 52 | 53 | Tlsh* tlsh_new(); 54 | void tlsh_free(Tlsh* tlsh); 55 | void tlsh_reset(Tlsh* tlsh); 56 | int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len); 57 | int tlsh_final(Tlsh* tlsh, const unsigned char* data, unsigned int len, int tlsh_option); 58 | const char* tlsh_get_hash(Tlsh* tlsh, bool showvers); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif // __TLSH_TLSH_H__ -------------------------------------------------------------------------------- /libyara/modules/pe/authenticode-parser/countersignature.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Avast Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | */ 21 | 22 | #ifndef AUTHENTICODE_PARSER_COUNTERSIGNATURE_H 23 | #define AUTHENTICODE_PARSER_COUNTERSIGNATURE_H 24 | 25 | #include "certificate.h" 26 | #include "helper.h" 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | Countersignature* pkcs9_countersig_new( 39 | const uint8_t* data, long size, STACK_OF(X509) * certs, ASN1_STRING* enc_digest); 40 | Countersignature* ms_countersig_new(const uint8_t* data, long size, ASN1_STRING* enc_digest); 41 | 42 | int countersignature_array_insert(CountersignatureArray* arr, Countersignature* sig); 43 | /* Moves all countersignatures of src and inserts them into dst */ 44 | int countersignature_array_move(CountersignatureArray* dst, CountersignatureArray* src); 45 | 46 | void countersignature_free(Countersignature* sig); 47 | void countersignature_array_free(CountersignatureArray* arr); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /docs/modules/console.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _console-module: 3 | 4 | ############## 5 | Console module 6 | ############## 7 | 8 | .. versionadded:: 4.2.0 9 | 10 | The Console module allows you to log information during condition execution. By 11 | default, the log messages are sent to stdout but can be handled differently by 12 | using the C api (:ref:`scanning-data`). 13 | 14 | Every function in the console module returns true for the purposes of condition 15 | evaluation. This means you must logically and your statements together to get 16 | the proper output. For example: 17 | 18 | .. code-block:: yara 19 | 20 | import "console" 21 | 22 | rule example 23 | { 24 | condition: 25 | console.log("Hello") and console.log("World!") 26 | } 27 | 28 | .. c:function:: log(string) 29 | 30 | Function which sends the string to the main callback. 31 | 32 | *Example: console.log(pe.imphash())* 33 | 34 | .. c:function:: log(message, string) 35 | 36 | Function which sends the message and string to the main callback. 37 | 38 | *Example: console.log("The imphash is: ", pe.imphash())* 39 | 40 | .. c:function:: log(integer) 41 | 42 | Function which sends the integer to the main callback. 43 | 44 | *Example: console.log(uint32(0))* 45 | 46 | .. c:function:: log(message, integer) 47 | 48 | Function which sends the message and integer to the main callback. 49 | 50 | *Example: console.log("32bits at 0: ", uint32(0))* 51 | 52 | .. c:function:: log(float) 53 | 54 | Function which sends the floating point value to the main callback. 55 | 56 | *Example: console.log(math.entropy(0, filesize))* 57 | 58 | .. c:function:: log(message, float) 59 | 60 | Function which sends the message and the floating point value to the main 61 | callback. 62 | 63 | *Example: console.log("Entropy: ", math.entropy(0, filesize))* 64 | 65 | .. c:function:: hex(integer) 66 | 67 | Function which sends the integer to the main callback, formatted as a hex 68 | string. 69 | 70 | *Example: console.hex(uint32(0))* 71 | 72 | .. c:function:: hex(message, integer) 73 | 74 | Function which sends the integer to the main callback, formatted as a hex 75 | string. 76 | 77 | *Example: console.hex("Hex at 0: ", uint32(0))* 78 | -------------------------------------------------------------------------------- /libyara/include/yara/scan.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_SCAN_H 31 | #define YR_SCAN_H 32 | 33 | #include 34 | 35 | // 36 | // Flags used with yr_scanner_set_flags and yr_rules_scan_xxx functions. 37 | // 38 | #define SCAN_FLAGS_FAST_MODE 1 39 | #define SCAN_FLAGS_PROCESS_MEMORY 2 40 | #define SCAN_FLAGS_NO_TRYCATCH 4 41 | #define SCAN_FLAGS_REPORT_RULES_MATCHING 8 42 | #define SCAN_FLAGS_REPORT_RULES_NOT_MATCHING 16 43 | 44 | int yr_scan_verify_match( 45 | YR_SCAN_CONTEXT* context, 46 | YR_AC_MATCH* ac_match, 47 | const uint8_t* data, 48 | size_t data_size, 49 | uint64_t data_base, 50 | size_t offset); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /docs/modules/magic.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _magic-module: 3 | 4 | ############ 5 | Magic module 6 | ############ 7 | 8 | .. versionadded:: 3.1.0 9 | 10 | The Magic module allows you to identify the type of the file based on the 11 | output of `file `_, the standard 12 | Unix command. 13 | 14 | .. important:: 15 | This module is not built into YARA by default, to learn how to include it 16 | refer to :ref:`compiling-yara`. Bad news for Windows users: **this module is 17 | not supported on Windows**. 18 | 19 | There are two functions in this module: :c:func:`type` and :c:func:`mime_type`. 20 | The first one returns the descriptive string returned by *file*, for example, 21 | if you run *file* against some PDF document you'll get something like this:: 22 | 23 | $file some.pdf 24 | some.pdf: PDF document, version 1.5 25 | 26 | The :c:func:`type` function would return *"PDF document, version 1.5"* in this 27 | case. Using the :c:func:`mime_type` function is similar to passing the 28 | ``--mime`` argument to *file*.:: 29 | 30 | $file --mime some.pdf 31 | some.pdf: application/pdf; charset=binary 32 | 33 | 34 | :c:func:`mime_type` would return *"application/pdf"*, without the charset part. 35 | 36 | By experimenting a little with the *file* command you can learn which output to 37 | expect for different file types. These are a few examples: 38 | 39 | * JPEG image data, JFIF standard 1.01 40 | * PE32 executable for MS Windows (GUI) Intel 80386 32-bit 41 | * PNG image data, 1240 x 1753, 8-bit/color RGBA, non-interlaced 42 | * ASCII text, with no line terminators 43 | * Zip archive data, at least v2.0 to extract 44 | 45 | libmagic will try and read its compiled file type database from /etc/magic.mgc 46 | by default. If this file doesn't exist, you can set the environment variable 47 | MAGIC to point to a magic.mgc file and libmagic will attempt to load from there 48 | as an alternative. 49 | 50 | .. c:function:: type() 51 | 52 | Function returning a string with the type of the file. 53 | 54 | *Example: magic.type() contains "PDF"* 55 | 56 | 57 | .. c:function:: mime_type() 58 | 59 | Function returning a string with the MIME type of the file. 60 | 61 | *Example: magic.mime_type() == "application/pdf"* 62 | -------------------------------------------------------------------------------- /libyara/modules/demo/demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #define MODULE_NAME demo 33 | 34 | begin_declarations 35 | declare_string("greeting"); 36 | end_declarations 37 | 38 | 39 | int module_initialize(YR_MODULE* module) 40 | { 41 | return ERROR_SUCCESS; 42 | } 43 | 44 | 45 | int module_finalize(YR_MODULE* module) 46 | { 47 | return ERROR_SUCCESS; 48 | } 49 | 50 | 51 | int module_load( 52 | YR_SCAN_CONTEXT* context, 53 | YR_OBJECT* module_object, 54 | void* module_data, 55 | size_t module_data_size) 56 | { 57 | yr_set_string("Hello World!", module_object, "greeting"); 58 | 59 | return ERROR_SUCCESS; 60 | } 61 | 62 | 63 | int module_unload(YR_OBJECT* module_object) 64 | { 65 | return ERROR_SUCCESS; 66 | } 67 | -------------------------------------------------------------------------------- /libyara/include/yara/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_MEM_H 31 | #define YR_MEM_H 32 | 33 | #include 34 | #include 35 | 36 | #ifdef DMALLOC 37 | 38 | #define yr_malloc malloc 39 | #define yr_calloc calloc 40 | #define yr_realloc realloc 41 | #define yr_free free 42 | #define yr_strdup strdup 43 | #define yr_strndup strndup 44 | 45 | #include 46 | 47 | #else 48 | 49 | void* yr_calloc(size_t count, size_t size); 50 | 51 | void* yr_malloc(size_t size); 52 | 53 | void* yr_realloc(void* ptr, size_t size); 54 | 55 | char* yr_strdup(const char* str); 56 | 57 | char* yr_strndup(const char* str, size_t n); 58 | 59 | YR_API void yr_free(void* ptr); 60 | 61 | #endif 62 | 63 | int yr_heap_alloc(void); 64 | 65 | int yr_heap_free(void); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /libyara/include/yara/stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_STREAM_H 31 | #define YR_STREAM_H 32 | 33 | #include 34 | 35 | typedef size_t (*YR_STREAM_READ_FUNC)( 36 | void* ptr, 37 | size_t size, 38 | size_t count, 39 | void* user_data); 40 | 41 | typedef size_t (*YR_STREAM_WRITE_FUNC)( 42 | const void* ptr, 43 | size_t size, 44 | size_t count, 45 | void* user_data); 46 | 47 | typedef struct _YR_STREAM 48 | { 49 | void* user_data; 50 | 51 | YR_STREAM_READ_FUNC read; 52 | YR_STREAM_WRITE_FUNC write; 53 | 54 | } YR_STREAM; 55 | 56 | size_t yr_stream_read(void* ptr, size_t size, size_t count, YR_STREAM* stream); 57 | 58 | size_t yr_stream_write( 59 | const void* ptr, 60 | size_t size, 61 | size_t count, 62 | YR_STREAM* stream); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libyara/endian.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | uint16_t _yr_bswap16(uint16_t x) 33 | { 34 | return (x >> 8 | x << 8); 35 | } 36 | 37 | uint32_t _yr_bswap32(uint32_t x) 38 | { 39 | return ( 40 | (((x) &0xff000000) >> 24) | (((x) &0x00ff0000) >> 8) | 41 | (((x) &0x0000ff00) << 8) | (((x) &0x000000ff) << 24)); 42 | } 43 | 44 | uint64_t _yr_bswap64(uint64_t x) 45 | { 46 | return ( 47 | (((x) &0xff00000000000000ull) >> 56) | 48 | (((x) &0x00ff000000000000ull) >> 40) | 49 | (((x) &0x0000ff0000000000ull) >> 24) | 50 | (((x) &0x000000ff00000000ull) >> 8) | 51 | (((x) &0x00000000ff000000ull) << 8) | 52 | (((x) &0x0000000000ff0000ull) << 24) | 53 | (((x) &0x000000000000ff00ull) << 40) | 54 | (((x) &0x00000000000000ffull) << 56)); 55 | } 56 | -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer_corpus/2: -------------------------------------------------------------------------------- 1 | rule r1 { condition: true or false } 2 | 3 | rule r2 { condition: 0x1 and 0x2} 4 | 5 | rule r3 { condition: 2 > 1 } 6 | 7 | rule r4 { condition: 1.5 >= 1.0} 8 | 9 | rule r5 { condition: 0.5 <= 1} 10 | 11 | rule r6 { condition: "abc" == "abc"} 12 | 13 | rule r7 { condition: "ab" < "abc"} 14 | 15 | rule r8 { condition: (1 + 1) * 2 == (9 - 1) \ 2 } 16 | 17 | rule r9 { condition: 1.5 + 1.5 == 3} 18 | 19 | rule r10 { condition: -2.0-3.0 == -5} 20 | 21 | rule r11 { condition: ~0xAA ^ 0x5A & 0xFF == (~0xAA) ^ (0x5A & 0xFF) } 22 | 23 | rule r12 { strings: $a = "abc" wide nocase fullword condition: $a } 24 | 25 | rule r13 { 26 | strings: 27 | $a = "abcdef" 28 | $b = "cdef" 29 | $c = "ef" 30 | condition: 31 | all of them 32 | } 33 | 34 | rule r14 { 35 | strings: 36 | $a = "abcdef" 37 | $b = "cdef" 38 | $c = "ef" 39 | condition: 40 | for all of ($*) : ($) 41 | } 42 | 43 | rule r15 { 44 | strings: 45 | $a = { 64 01 00 00 60 01 } 46 | condition: 47 | $a 48 | } 49 | 50 | rule r16 { 51 | strings: 52 | $a = { 64 01 [1-3] (60|61) 01 } 53 | condition: 54 | $a 55 | } 56 | 57 | rule r17 { 58 | strings: 59 | $a = { 4D 5A [-] 6A 2A [-] 58 C3 } 60 | condition: 61 | $a 62 | } 63 | 64 | rule r18 { 65 | strings: 66 | $a = { 4D 5A [300-] 6A 2A [-] 58 C3} 67 | condition: 68 | $a 69 | } 70 | 71 | rule r19 { 72 | strings: 73 | $a = { 2e 7? (65 | ?? ) 78 } 74 | condition: 75 | $a 76 | } 77 | 78 | rule r21 { 79 | strings: 80 | $a = /a.*efg/ 81 | condition: 82 | $a 83 | } 84 | 85 | rule r22 { 86 | strings: 87 | $a = /abc[^D]/ nocase 88 | condition: 89 | $a 90 | } 91 | 92 | rule r23 { 93 | strings: 94 | $a = /a[-]?c/ 95 | condition: 96 | $a 97 | } 98 | 99 | rule r24 { 100 | strings: 101 | $a = /[0-9a-f]+/ 102 | condition: 103 | $a 104 | } 105 | 106 | rule r25 { 107 | strings: 108 | $a = /[\\da-fA-F]+/ 109 | condition: 110 | $a 111 | } 112 | 113 | rule r26 { 114 | strings: 115 | $a = /(bc+d$|ef*g.|h?i(j|k))/ 116 | condition: 117 | $a 118 | } 119 | 120 | rule r27 { 121 | condition: 122 | "xxFoOxx" matches /fOo/i 123 | } 124 | 125 | rule r28 { 126 | condition: 127 | uint32be(0) == 0xAABBCCDD 128 | } 129 | -------------------------------------------------------------------------------- /libyara/proc/none.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007-2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #if defined(USE_NO_PROC) 31 | 32 | #include 33 | #include 34 | 35 | int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) 36 | { 37 | return ERROR_COULD_NOT_ATTACH_TO_PROCESS; 38 | } 39 | 40 | int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) 41 | { 42 | return ERROR_INVALID_ARGUMENT; 43 | } 44 | 45 | YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) 46 | { 47 | return NULL; 48 | } 49 | 50 | YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( 51 | YR_MEMORY_BLOCK_ITERATOR* iterator) 52 | { 53 | iterator->last_error = ERROR_SUCCESS; 54 | return NULL; 55 | } 56 | 57 | YR_API YR_MEMORY_BLOCK* yr_process_get_first_memory_block( 58 | YR_MEMORY_BLOCK_ITERATOR* iterator) 59 | { 60 | return NULL; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /libyara/include/yara/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_PROC_H 31 | #define YR_PROC_H 32 | 33 | #include 34 | 35 | typedef struct _YR_PROC_ITERATOR_CTX 36 | { 37 | const uint8_t* buffer; 38 | size_t buffer_size; 39 | YR_MEMORY_BLOCK current_block; 40 | void* proc_info; 41 | } YR_PROC_ITERATOR_CTX; 42 | 43 | YR_API int yr_process_open_iterator( 44 | int pid, 45 | YR_MEMORY_BLOCK_ITERATOR* iterator); 46 | 47 | YR_API int yr_process_close_iterator(YR_MEMORY_BLOCK_ITERATOR* iterator); 48 | 49 | YR_API YR_MEMORY_BLOCK* yr_process_get_first_memory_block( 50 | YR_MEMORY_BLOCK_ITERATOR* iterator); 51 | 52 | YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( 53 | YR_MEMORY_BLOCK_ITERATOR* iterator); 54 | 55 | YR_API const uint8_t* yr_process_fetch_memory_block_data( 56 | YR_MEMORY_BLOCK* block); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /sandbox/yara_matches.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | syntax = "proto3"; 31 | 32 | package yara; 33 | 34 | // Identifies a single rule inside a namespace 35 | message YaraRuleId { 36 | string rule_namespace = 1; // Currently unused by yara_entrypoints.cc 37 | string rule_name = 2; 38 | } 39 | 40 | // Holds N mappings for the matches. 41 | message YaraMatches { 42 | // Holds one mapping from (namespace, name) --> N key-value entries. 43 | message Match { 44 | message Meta { 45 | string identifier = 1; 46 | oneof value { 47 | bytes bytes_value = 2; 48 | int64 int_value = 3; 49 | } 50 | } 51 | 52 | YaraRuleId id = 1; 53 | repeated Meta meta = 2; 54 | } 55 | 56 | repeated Match match = 1; 57 | } 58 | 59 | message YaraStatus { 60 | int64 code = 1; 61 | int64 line_number = 2; 62 | string message = 3; 63 | } 64 | -------------------------------------------------------------------------------- /libyara/modules/time/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014-2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #define MODULE_NAME time 34 | 35 | 36 | define_function(now) 37 | { 38 | time_t now = time(NULL); 39 | if (now == -1) 40 | return_integer(YR_UNDEFINED); 41 | return_integer((long) now); 42 | } 43 | 44 | 45 | begin_declarations 46 | declare_function("now", "", "i", now); 47 | end_declarations; 48 | 49 | 50 | int module_initialize(YR_MODULE* module) 51 | { 52 | return ERROR_SUCCESS; 53 | } 54 | 55 | 56 | int module_finalize(YR_MODULE* module) 57 | { 58 | return ERROR_SUCCESS; 59 | } 60 | 61 | 62 | int module_load( 63 | YR_SCAN_CONTEXT* context, 64 | YR_OBJECT* module_object, 65 | void* module_data, 66 | size_t module_data_size) 67 | { 68 | return ERROR_SUCCESS; 69 | } 70 | 71 | 72 | int module_unload(YR_OBJECT* module_object) 73 | { 74 | return ERROR_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /libyara/include/yara/stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_STACK_H 31 | #define YR_STACK_H 32 | 33 | typedef struct YR_STACK YR_STACK; 34 | 35 | struct YR_STACK 36 | { 37 | // Pointer to a heap-allocated array containing the void* values put in 38 | // in the stack. This array starts with a fixed size and it's grown as 39 | // required when new items are pushed into the stack. 40 | void* items; 41 | 42 | // Current capacity (i.e: the number of items that fit into the array) 43 | int capacity; 44 | 45 | // Size of each individual item in the stack. 46 | int item_size; 47 | 48 | // Index of the stack's top in the items array. 49 | int top; 50 | }; 51 | 52 | int yr_stack_create(int initial_capacity, int item_size, YR_STACK** stack); 53 | 54 | void yr_stack_destroy(YR_STACK* stack); 55 | 56 | int yr_stack_push(YR_STACK* stack, void* item); 57 | 58 | int yr_stack_pop(YR_STACK* stack, void* item); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cli/unicode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_UNICODE_H 31 | #define YR_UNICODE_H 32 | 33 | #ifdef _MSC_VER 34 | #include 35 | #define char_t TCHAR 36 | #define PF_S "hs" 37 | #define PF_C "hc" 38 | 39 | #else 40 | #define char_t char 41 | #define _T(x) x 42 | #define PF_S "s" 43 | #define PF_C "c" 44 | 45 | #ifdef __CYGWIN__ 46 | #define _tcstok_s strtok_r 47 | #else 48 | #define _tcstok_s strtok_s 49 | #endif 50 | 51 | #define _tcscmp strcmp 52 | #define _tcsdup strdup 53 | #define _tcschr strchr 54 | #define _tcslen strlen 55 | #define _tcsstr strstr 56 | #define _tcstol strtol 57 | #define _tcstoll strtoll 58 | #define _tstoi atoi 59 | #define _tstof atof 60 | #define _tisdigit isdigit 61 | #define _tfopen fopen 62 | #define _ftprintf fprintf 63 | #define _stprintf sprintf 64 | #define _tprintf printf 65 | #define _tmain main 66 | #define _sntprintf snprintf 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libyara/modules/pe/authenticode-parser/helper.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Avast Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | */ 21 | 22 | #ifndef AUTHENTICODE_PARSER_HELPER_H 23 | #define AUTHENTICODE_PARSER_HELPER_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #ifdef _WIN32 33 | #define timegm _mkgmtime 34 | #endif 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /* Endianity related functions for PE reading */ 41 | uint16_t bswap16(uint16_t d); 42 | uint32_t bswap32(uint32_t d); 43 | 44 | #if defined(WORDS_BIGENDIAN) 45 | #define letoh16(x) bswap16(x) 46 | #define letoh32(x) bswap32(x) 47 | #define betoh16(x) (x) 48 | #define betoh32(x) (x) 49 | #else 50 | #define letoh16(x) (x) 51 | #define letoh32(x) (x) 52 | #define betoh16(x) bswap16(x) 53 | #define betoh32(x) bswap32(x) 54 | #endif 55 | 56 | /* Calculates digest md of data, return bytes written to digest or 0 on error 57 | * Maximum of EVP_MAX_MD_SIZE will be written to digest */ 58 | int calculate_digest(const EVP_MD* md, const uint8_t* data, size_t len, uint8_t* digest); 59 | /* Copies data of length len into already existing arr */ 60 | int byte_array_init(ByteArray* arr, const uint8_t* data, int len); 61 | /* Converts ASN1_TIME string time into a unix timestamp */ 62 | int64_t ASN1_TIME_to_int64_t(const ASN1_TIME* time); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /libyara/include/yara/pe_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef YR_PE_UTILS_H 2 | #define YR_PE_UTILS_H 3 | 4 | #include 5 | 6 | #define MAX_PE_SECTIONS 96 7 | 8 | #define IS_64BITS_PE(pe) \ 9 | (yr_le16toh(pe->header64->OptionalHeader.Magic) == \ 10 | IMAGE_NT_OPTIONAL_HDR64_MAGIC) 11 | 12 | #define OptionalHeader(pe, field) \ 13 | (IS_64BITS_PE(pe) ? pe->header64->OptionalHeader.field \ 14 | : pe->header->OptionalHeader.field) 15 | 16 | // 17 | // Imports are stored in a linked list. Each node (IMPORTED_DLL) contains the 18 | // name of the DLL and a pointer to another linked list of 19 | // IMPORT_EXPORT_FUNCTION structures containing the details of imported 20 | // functions. 21 | // 22 | 23 | typedef struct _IMPORTED_DLL 24 | { 25 | char* name; 26 | 27 | struct _IMPORT_FUNCTION* functions; 28 | struct _IMPORTED_DLL* next; 29 | 30 | } IMPORTED_DLL, *PIMPORTED_DLL; 31 | 32 | // 33 | // This is used to track imported and exported functions. The "has_ordinal" 34 | // field is only used in the case of imports as those are optional. Every export 35 | // has an ordinal so we don't need the field there, but in the interest of 36 | // keeping duplicate code to a minimum we use this function for both imports and 37 | // exports. 38 | // 39 | 40 | typedef struct _IMPORT_FUNCTION 41 | { 42 | char* name; 43 | uint8_t has_ordinal; 44 | uint16_t ordinal; 45 | uint64_t rva; 46 | 47 | struct _IMPORT_FUNCTION* next; 48 | 49 | } IMPORT_FUNCTION, *PIMPORT_FUNCTION; 50 | 51 | typedef struct _PE 52 | { 53 | const uint8_t* data; 54 | size_t data_size; 55 | 56 | union 57 | { 58 | PIMAGE_NT_HEADERS32 header; 59 | PIMAGE_NT_HEADERS64 header64; 60 | }; 61 | 62 | YR_HASH_TABLE* hash_table; 63 | YR_OBJECT* object; 64 | IMPORTED_DLL* imported_dlls; 65 | IMPORTED_DLL* delay_imported_dlls; 66 | 67 | uint32_t resources; 68 | uint32_t version_infos; 69 | 70 | } PE; 71 | 72 | #define fits_in_pe(pe, pointer, size) \ 73 | ((size_t)(size) <= pe->data_size && (uint8_t*) (pointer) >= pe->data && \ 74 | (uint8_t*) (pointer) <= pe->data + pe->data_size - (size)) 75 | 76 | #define struct_fits_in_pe(pe, pointer, struct_type) \ 77 | fits_in_pe(pe, pointer, sizeof(struct_type)) 78 | 79 | PIMAGE_NT_HEADERS32 pe_get_header(const uint8_t* data, size_t data_size); 80 | 81 | PIMAGE_DATA_DIRECTORY pe_get_directory_entry(PE* pe, int entry); 82 | 83 | int64_t pe_rva_to_offset(PE* pe, uint64_t rva); 84 | 85 | char* ord_lookup(char* dll, uint16_t ord); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /tests/oss-fuzz/rules_fuzzer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 37 | { 38 | yr_initialize(); 39 | return 0; 40 | } 41 | 42 | 43 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 44 | { 45 | YR_RULES* rules; 46 | YR_COMPILER* compiler; 47 | 48 | char* buffer = (char*) malloc(size + 1); 49 | 50 | if (!buffer) 51 | return 0; 52 | 53 | strncpy(buffer, (const char*) data, size); 54 | buffer[size] = 0; 55 | 56 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 57 | { 58 | free(buffer); 59 | return 0; 60 | } 61 | 62 | if (yr_compiler_add_string(compiler, (const char*) buffer, NULL) == 0) 63 | { 64 | if (yr_compiler_get_rules(compiler, &rules) == ERROR_SUCCESS) 65 | yr_rules_destroy(rules); 66 | } 67 | 68 | yr_compiler_destroy(compiler); 69 | free(buffer); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /libyara/include/yara/threading.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_MUTEX_H 31 | #define YR_MUTEX_H 32 | 33 | #if defined(_WIN32) || defined(__CYGWIN__) 34 | 35 | #include 36 | 37 | typedef DWORD YR_THREAD_ID; 38 | typedef DWORD YR_THREAD_STORAGE_KEY; 39 | typedef HANDLE YR_MUTEX; 40 | 41 | #define YR_TLS __declspec(thread) 42 | 43 | #else 44 | 45 | #include 46 | 47 | typedef pthread_t YR_THREAD_ID; 48 | typedef pthread_key_t YR_THREAD_STORAGE_KEY; 49 | typedef pthread_mutex_t YR_MUTEX; 50 | 51 | #define YR_TLS __thread 52 | 53 | #endif 54 | 55 | YR_THREAD_ID yr_current_thread_id(void); 56 | 57 | int yr_mutex_create(YR_MUTEX*); 58 | int yr_mutex_destroy(YR_MUTEX*); 59 | int yr_mutex_lock(YR_MUTEX*); 60 | int yr_mutex_unlock(YR_MUTEX*); 61 | 62 | int yr_thread_storage_create(YR_THREAD_STORAGE_KEY*); 63 | int yr_thread_storage_destroy(YR_THREAD_STORAGE_KEY*); 64 | int yr_thread_storage_set_value(YR_THREAD_STORAGE_KEY*, void*); 65 | void* yr_thread_storage_get_value(YR_THREAD_STORAGE_KEY*); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /tests/oss-fuzz/elf_fuzzer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | YR_RULES* rules = NULL; 36 | 37 | 38 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 39 | { 40 | YR_COMPILER* compiler; 41 | 42 | if (yr_initialize() != ERROR_SUCCESS) 43 | return 0; 44 | 45 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 46 | return 0; 47 | 48 | if (yr_compiler_add_string(compiler, "import \"elf\"", NULL) == 0) 49 | yr_compiler_get_rules(compiler, &rules); 50 | 51 | yr_compiler_destroy(compiler); 52 | 53 | return 0; 54 | } 55 | 56 | 57 | int callback( 58 | YR_SCAN_CONTEXT* context, 59 | int message, 60 | void* message_data, 61 | void* user_data) 62 | { 63 | return CALLBACK_CONTINUE; 64 | } 65 | 66 | 67 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 68 | { 69 | if (rules == NULL) 70 | return 0; 71 | 72 | yr_rules_scan_mem( 73 | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /libyara/include/yara/stopwatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_STOPWATCH_H 31 | #define YR_STOPWATCH_H 32 | 33 | #include 34 | #include 35 | 36 | #if defined(_WIN32) 37 | 38 | #include 39 | 40 | typedef struct _YR_STOPWATCH 41 | { 42 | LARGE_INTEGER frequency; 43 | LARGE_INTEGER start; 44 | 45 | } YR_STOPWATCH; 46 | 47 | #elif defined(__APPLE__) && defined(__MACH__) 48 | 49 | #include 50 | 51 | typedef struct _YR_STOPWATCH 52 | { 53 | mach_timebase_info_data_t timebase; 54 | uint64_t start; 55 | 56 | } YR_STOPWATCH; 57 | 58 | #else 59 | 60 | #include 61 | 62 | typedef struct _YR_STOPWATCH 63 | { 64 | union 65 | { 66 | struct timeval tv_start; 67 | struct timespec ts_start; 68 | }; 69 | 70 | } YR_STOPWATCH; 71 | 72 | #endif 73 | 74 | // yr_stopwatch_start starts measuring time. 75 | void yr_stopwatch_start(YR_STOPWATCH* stopwatch); 76 | 77 | // yr_stopwatch_elapsed_ns returns the number of nanoseconds elapsed 78 | // since the last call to yr_stopwatch_start. 79 | uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* stopwatch); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /libyara/modules/pe/authenticode-parser/helper.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Avast Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | */ 21 | 22 | #include "helper.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | uint16_t bswap16(uint16_t d) 32 | { 33 | return (d << 8) | (d >> 8); 34 | } 35 | 36 | uint32_t bswap32(uint32_t d) 37 | { 38 | return (((d)&0xff000000) >> 24) | (((d)&0x00ff0000) >> 8) | (((d)&0x0000ff00) << 8) | 39 | (((d)&0x000000ff) << 24); 40 | } 41 | 42 | int calculate_digest(const EVP_MD* md, const uint8_t* data, size_t len, uint8_t* digest) 43 | { 44 | unsigned int outLen = 0; 45 | 46 | EVP_MD_CTX* mdCtx = EVP_MD_CTX_new(); 47 | if (!mdCtx) 48 | goto end; 49 | 50 | if (!EVP_DigestInit_ex(mdCtx, md, NULL) || !EVP_DigestUpdate(mdCtx, data, len) || 51 | !EVP_DigestFinal_ex(mdCtx, digest, &outLen)) 52 | goto end; 53 | 54 | end: 55 | EVP_MD_CTX_free(mdCtx); 56 | return (int)outLen; 57 | } 58 | 59 | int byte_array_init(ByteArray* arr, const uint8_t* data, int len) 60 | { 61 | if (len == 0) { 62 | arr->data = NULL; 63 | arr->len = 0; 64 | return 0; 65 | } 66 | 67 | arr->data = (uint8_t*)malloc(len); 68 | if (!arr->data) 69 | return -1; 70 | 71 | arr->len = len; 72 | memcpy(arr->data, data, len); 73 | return 0; 74 | } 75 | 76 | int64_t ASN1_TIME_to_int64_t(const ASN1_TIME* time) 77 | { 78 | struct tm t = {0}; 79 | if (!time) 80 | return timegm(&t); 81 | 82 | ASN1_TIME_to_tm(time, &t); 83 | return timegm(&t); 84 | } 85 | -------------------------------------------------------------------------------- /tests/test-pb.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #include "util.h" 33 | 34 | int main(int argc, char** argv) 35 | { 36 | int result = 0; 37 | 38 | YR_DEBUG_INITIALIZE(); 39 | YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, __FILE__); 40 | 41 | init_top_srcdir(); 42 | yr_initialize(); 43 | 44 | assert_true_rule_module_data_file( 45 | "import \"pb_tests\" \ 46 | rule test { \ 47 | condition: \ 48 | pb_tests.f_int32 == 1111 and \ 49 | pb_tests.f_int64 == 2222 and \ 50 | pb_tests.f_string == \"foo\" and \ 51 | pb_tests.f_struct_array[0].f_enum == pb_tests.struct.enum.SECOND \ 52 | }", 53 | "tests/data/test-pb.data.bin"); 54 | 55 | assert_true_rule_module_data_file( 56 | "import \"pb_tests\" \ 57 | rule test { \ 58 | condition: \ 59 | for any s in pb_tests.f_struct_array : ( \ 60 | s.f_nested_struct.f_int32 == 3333 \ 61 | ) \ 62 | }", 63 | "tests/data/test-pb.data.bin"); 64 | 65 | yr_finalize(); 66 | 67 | YR_DEBUG_FPRINTF( 68 | 1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, __FILE__); 69 | 70 | return result; 71 | } 72 | -------------------------------------------------------------------------------- /libyara/include/yara/filemap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007-2015. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_FILEMAP_H 31 | #define YR_FILEMAP_H 32 | 33 | #include 34 | 35 | #if defined(_WIN32) || defined(__CYGWIN__) 36 | #include 37 | #define YR_FILE_DESCRIPTOR HANDLE 38 | #else 39 | #define YR_FILE_DESCRIPTOR int 40 | #endif 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | 47 | typedef struct _YR_MAPPED_FILE 48 | { 49 | YR_FILE_DESCRIPTOR file; 50 | size_t size; 51 | const uint8_t* data; 52 | #if defined(_WIN32) || defined(__CYGWIN__) 53 | HANDLE mapping; 54 | #endif 55 | 56 | } YR_MAPPED_FILE; 57 | 58 | 59 | YR_API int yr_filemap_map(const char* file_path, YR_MAPPED_FILE* pmapped_file); 60 | 61 | 62 | YR_API int yr_filemap_map_fd( 63 | YR_FILE_DESCRIPTOR file, 64 | uint64_t offset, 65 | size_t size, 66 | YR_MAPPED_FILE* pmapped_file); 67 | 68 | 69 | YR_API int yr_filemap_map_ex( 70 | const char* file_path, 71 | uint64_t offset, 72 | size_t size, 73 | YR_MAPPED_FILE* pmapped_file); 74 | 75 | 76 | YR_API void yr_filemap_unmap(YR_MAPPED_FILE* pmapped_file); 77 | 78 | 79 | YR_API void yr_filemap_unmap_fd(YR_MAPPED_FILE* pmapped_file); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /tests/oss-fuzz/dotnet_fuzzer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | const char* RULES = "import \"dotnet\"" 35 | "rule test {" 36 | " condition:" 37 | " dotnet.module_name == \"foo.exe\"" 38 | "}"; 39 | 40 | YR_RULES* rules = NULL; 41 | 42 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 43 | { 44 | YR_COMPILER* compiler; 45 | 46 | if (yr_initialize() != ERROR_SUCCESS) 47 | return 0; 48 | 49 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 50 | return 0; 51 | 52 | if (yr_compiler_add_string(compiler, RULES, NULL) == 0) 53 | yr_compiler_get_rules(compiler, &rules); 54 | 55 | yr_compiler_destroy(compiler); 56 | 57 | return 0; 58 | } 59 | 60 | 61 | int callback( 62 | YR_SCAN_CONTEXT* context, 63 | int message, 64 | void* message_data, 65 | void* user_data) 66 | { 67 | return CALLBACK_CONTINUE; 68 | } 69 | 70 | 71 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 72 | { 73 | if (rules == NULL) 74 | return 0; 75 | 76 | yr_rules_scan_mem( 77 | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /tests/oss-fuzz/macho_fuzzer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | const char* RULES = "import \"macho\"" 35 | "rule test {" 36 | " condition:" 37 | " macho.segments[1].sections[0].segname == \"__TEXT\"" 38 | "}"; 39 | 40 | YR_RULES* rules = NULL; 41 | 42 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 43 | { 44 | YR_COMPILER* compiler; 45 | 46 | if (yr_initialize() != ERROR_SUCCESS) 47 | return 0; 48 | 49 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 50 | return 0; 51 | 52 | if (yr_compiler_add_string(compiler, RULES, NULL) == 0) 53 | yr_compiler_get_rules(compiler, &rules); 54 | 55 | yr_compiler_destroy(compiler); 56 | 57 | return 0; 58 | } 59 | 60 | 61 | int callback( 62 | YR_SCAN_CONTEXT* context, 63 | int message, 64 | void* message_data, 65 | void* user_data) 66 | { 67 | return CALLBACK_CONTINUE; 68 | } 69 | 70 | 71 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 72 | { 73 | if (rules == NULL) 74 | return 0; 75 | 76 | yr_rules_scan_mem( 77 | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /tests/oss-fuzz/pe_fuzzer.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | const char* RULES = "import \"pe\"" 35 | "rule test {" 36 | " condition:" 37 | " pe.rva_to_offset(pe.sections[0].virtual_address) == " 38 | "pe.sections[0].raw_data_offset" 39 | "}"; 40 | 41 | YR_RULES* rules = NULL; 42 | 43 | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) 44 | { 45 | YR_COMPILER* compiler; 46 | 47 | if (yr_initialize() != ERROR_SUCCESS) 48 | return 0; 49 | 50 | if (yr_compiler_create(&compiler) != ERROR_SUCCESS) 51 | return 0; 52 | 53 | if (yr_compiler_add_string(compiler, RULES, NULL) == 0) 54 | yr_compiler_get_rules(compiler, &rules); 55 | 56 | yr_compiler_destroy(compiler); 57 | 58 | return 0; 59 | } 60 | 61 | 62 | int callback( 63 | YR_SCAN_CONTEXT* context, 64 | int message, 65 | void* message_data, 66 | void* user_data) 67 | { 68 | return CALLBACK_CONTINUE; 69 | } 70 | 71 | 72 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 73 | { 74 | if (rules == NULL) 75 | return 0; 76 | 77 | yr_rules_scan_mem( 78 | rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /docs/modules/hash.rst: -------------------------------------------------------------------------------- 1 | 2 | .. _hash-module: 3 | 4 | ########### 5 | Hash module 6 | ########### 7 | 8 | .. versionadded:: 3.2.0 9 | 10 | The Hash module allows you to calculate hashes (MD5, SHA1, SHA256) from portions 11 | of your file and create signatures based on those hashes. 12 | 13 | .. important:: 14 | This module depends on the OpenSSL library. Please refer to 15 | :ref:`compiling-yara` for information about how to build OpenSSL-dependant 16 | features into YARA. 17 | 18 | Good news for Windows users: this module is already included in the official 19 | Windows binaries. 20 | 21 | .. warning:: 22 | The returned hash string is always in lowercase. This means that rule condition matching on hashes 23 | ``hash.md5(0, filesize) == "feba6c919e3797e7778e8f2e85fa033d"`` 24 | requires the hash string to be given in lowercase, otherwise the match condition 25 | will not work. (see https://github.com/VirusTotal/yara/issues/1004) 26 | 27 | .. c:function:: md5(offset, size) 28 | 29 | Returns the MD5 hash for *size* bytes starting at *offset*. When scanning a 30 | running process the *offset* argument should be a virtual address within 31 | the process address space. The returned string is always in lowercase. 32 | 33 | *Example: hash.md5(0, filesize) == "feba6c919e3797e7778e8f2e85fa033d"* 34 | 35 | .. c:function:: md5(string) 36 | 37 | Returns the MD5 hash for the given string. 38 | 39 | *Example: hash.md5("dummy") == "275876e34cf609db118f3d84b799a790"* 40 | 41 | .. c:function:: sha1(offset, size) 42 | 43 | Returns the SHA1 hash for the *size* bytes starting at *offset*. When 44 | scanning a running process the *offset* argument should be a virtual address 45 | within the process address space. The returned string is always in 46 | lowercase. 47 | 48 | .. c:function:: sha1(string) 49 | 50 | Returns the SHA1 hash for the given string. 51 | 52 | .. c:function:: sha256(offset, size) 53 | 54 | Returns the SHA256 hash for the *size* bytes starting at *offset*. When 55 | scanning a running process the *offset* argument should be a virtual address 56 | within the process address space. The returned string is always in 57 | lowercase. 58 | 59 | .. c:function:: sha256(string) 60 | 61 | Returns the SHA256 hash for the given string. 62 | 63 | .. c:function:: checksum32(offset, size) 64 | 65 | Returns a 32-bit checksum for the *size* bytes starting at *offset*. The 66 | checksum is just the sum of all the bytes (unsigned). 67 | 68 | .. c:function:: checksum32(string) 69 | 70 | Returns a 32-bit checksum for the given string. The checksum is just the 71 | sum of all the bytes in the string (unsigned). 72 | 73 | .. c:function:: crc32(offset, size) 74 | 75 | Returns a crc32 checksum for the *size* bytes starting at *offset*. 76 | 77 | .. c:function:: crc32(string) 78 | 79 | Returns a crc32 checksum for the given string. 80 | 81 | -------------------------------------------------------------------------------- /libyara/include/yara/ahocorasick.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _AHOCORASICK_H 31 | #define _AHOCORASICK_H 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | // Number of bits dedicated to store the offset of the slot relative to its 38 | // own state. 39 | #define YR_AC_SLOT_OFFSET_BITS 9 40 | 41 | // Max number of slots in the transition table. This is the maximum number of 42 | // slots that can be addressed with 23-bit indexes. 43 | #define YR_AC_MAX_TRANSITION_TABLE_SIZE 0x800000 44 | 45 | #define YR_AC_ROOT_STATE 0 46 | #define YR_AC_NEXT_STATE(t) (t >> YR_AC_SLOT_OFFSET_BITS) 47 | #define YR_AC_INVALID_TRANSITION(t, c) (((t) &0x1FF) != c) 48 | 49 | #define YR_AC_MAKE_TRANSITION(state, code) \ 50 | ((YR_AC_TRANSITION)( \ 51 | (((YR_AC_TRANSITION) state) << YR_AC_SLOT_OFFSET_BITS) | (code))) 52 | 53 | int yr_ac_automaton_create(YR_ARENA* arena, YR_AC_AUTOMATON** automaton); 54 | 55 | int yr_ac_automaton_destroy(YR_AC_AUTOMATON* automaton); 56 | 57 | int yr_ac_add_string( 58 | YR_AC_AUTOMATON* automaton, 59 | YR_STRING* string, 60 | uint32_t string_idx, 61 | YR_ATOM_LIST_ITEM* atom, 62 | YR_ARENA* arena); 63 | 64 | int yr_ac_compile(YR_AC_AUTOMATON* automaton, YR_ARENA* arena); 65 | 66 | void yr_ac_print_automaton(YR_AC_AUTOMATON* automaton); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sandbox/collect_matches.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "sandbox/collect_matches.h" 31 | 32 | #include "libyara/include/yara.h" 33 | #include "sandbox/yara_matches.pb.h" 34 | 35 | namespace yara 36 | { 37 | int CollectMatches( 38 | YR_SCAN_CONTEXT*, 39 | int message, 40 | void* message_data, 41 | void* user_data) 42 | { 43 | if (message != CALLBACK_MSG_RULE_MATCHING) 44 | { 45 | return ERROR_SUCCESS; // There are no matching rules, simply return 46 | } 47 | 48 | auto* rule = static_cast(message_data); 49 | YR_META* rule_meta = rule->metas; 50 | 51 | auto* match = reinterpret_cast(user_data)->add_match(); 52 | 53 | if (rule->ns != nullptr && rule->ns->name != nullptr) 54 | { 55 | match->mutable_id()->set_rule_namespace(rule->ns->name); 56 | } 57 | 58 | match->mutable_id()->set_rule_name(rule->identifier); 59 | 60 | yr_rule_metas_foreach(rule, rule_meta) 61 | { 62 | auto* meta = match->add_meta(); 63 | meta->set_identifier(rule_meta->identifier); 64 | switch (rule_meta->type) 65 | { 66 | case META_TYPE_BOOLEAN: 67 | case META_TYPE_INTEGER: 68 | meta->set_int_value(rule_meta->integer); 69 | break; 70 | case META_TYPE_STRING: 71 | meta->set_bytes_value(rule_meta->string); 72 | break; 73 | } 74 | } 75 | 76 | return ERROR_SUCCESS; 77 | } 78 | 79 | } // namespace yara 80 | -------------------------------------------------------------------------------- /cli/threading.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef THREADING_H 31 | #define THREADING_H 32 | 33 | #if defined(_WIN32) || defined(__CYGWIN__) 34 | #include 35 | #else 36 | #include 37 | #include 38 | #if defined(__APPLE__) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | #endif 44 | 45 | #if defined(_WIN32) || defined(__CYGWIN__) 46 | 47 | typedef HANDLE SEMAPHORE; 48 | typedef CRITICAL_SECTION MUTEX; 49 | typedef HANDLE THREAD; 50 | 51 | typedef LPTHREAD_START_ROUTINE THREAD_START_ROUTINE; 52 | 53 | #else 54 | 55 | typedef pthread_mutex_t MUTEX; 56 | typedef pthread_t THREAD; 57 | typedef void* (*THREAD_START_ROUTINE)(void*); 58 | 59 | #if defined(__APPLE__) 60 | typedef semaphore_t SEMAPHORE; 61 | #else 62 | typedef sem_t* SEMAPHORE; 63 | #endif 64 | 65 | #endif 66 | 67 | int cli_mutex_init(MUTEX* mutex); 68 | 69 | void cli_mutex_destroy(MUTEX* mutex); 70 | 71 | void cli_mutex_lock(MUTEX* mutex); 72 | 73 | void cli_mutex_unlock(MUTEX* mutex); 74 | 75 | int cli_semaphore_init(SEMAPHORE* semaphore, int value); 76 | 77 | void cli_semaphore_destroy(SEMAPHORE* semaphore); 78 | 79 | int cli_semaphore_wait(SEMAPHORE* semaphore, time_t abs_timeout); 80 | 81 | void cli_semaphore_release(SEMAPHORE* semaphore); 82 | 83 | int cli_create_thread( 84 | THREAD* thread, 85 | THREAD_START_ROUTINE start_routine, 86 | void* param); 87 | 88 | void cli_thread_join(THREAD* thread); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /tests/test-stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "util.h" 34 | 35 | int main(int argc, char** argv) 36 | { 37 | int result = 0; 38 | 39 | YR_DEBUG_INITIALIZE(); 40 | YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]); 41 | 42 | YR_STACK* stack; 43 | 44 | int item; 45 | 46 | yr_initialize(); 47 | yr_stack_create(1, sizeof(item), &stack); 48 | 49 | item = 1; 50 | 51 | if (yr_stack_push(stack, &item) != ERROR_SUCCESS) 52 | exit(EXIT_FAILURE); 53 | 54 | item = 2; 55 | 56 | if (yr_stack_push(stack, &item) != ERROR_SUCCESS) 57 | exit(EXIT_FAILURE); 58 | 59 | item = 3; 60 | 61 | if (yr_stack_push(stack, &item) != ERROR_SUCCESS) 62 | exit(EXIT_FAILURE); 63 | 64 | item = 4; 65 | 66 | if (yr_stack_push(stack, &item) != ERROR_SUCCESS) 67 | exit(EXIT_FAILURE); 68 | 69 | if (!yr_stack_pop(stack, &item) || item != 4) 70 | exit(EXIT_FAILURE); 71 | 72 | if (!yr_stack_pop(stack, &item) || item != 3) 73 | exit(EXIT_FAILURE); 74 | 75 | if (!yr_stack_pop(stack, &item) || item != 2) 76 | exit(EXIT_FAILURE); 77 | 78 | if (!yr_stack_pop(stack, &item) || item != 1) 79 | exit(EXIT_FAILURE); 80 | 81 | if (yr_stack_pop(stack, &item) || item != 1) 82 | exit(EXIT_FAILURE); 83 | 84 | yr_stack_destroy(stack); 85 | yr_finalize(); 86 | 87 | YR_DEBUG_FPRINTF( 88 | 1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]); 89 | 90 | return result; 91 | } 92 | -------------------------------------------------------------------------------- /dist/yara.spec: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2007-2015. The YARA Authors. All Rights Reserved. 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## Unless required by applicable law or agreed to in writing, software 8 | ## distributed under the License is distributed on an "AS IS" BASIS, 9 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | ## See the License for the specific language governing permissions and 11 | ## limitations under the License. 12 | ## 13 | 14 | Name: yara 15 | Version: 3.2.0 16 | Release: 1 17 | License: Apache License 2.0 18 | Summary: A malware identification and classification tool 19 | Url: http://plusvic.github.io/yara/ 20 | Group: System/Filesystems 21 | Source: yara-%{version}.tar.gz 22 | BuildRoot: %{_tmppath}/%{name}-%{version}-build 23 | BuildRequires: autoconf automake libtool 24 | 25 | %description 26 | YARA is a tool aimed at helping malware researchers to identify and classify 27 | malware samples. With YARA you can create descriptions of malware families 28 | based on textual or binary patterns contained on samples of those families. 29 | 30 | %package -n libyara 31 | Summary: Library to support the yara malware identification tool 32 | Group: System/Libraries 33 | 34 | %description -n libyara 35 | YARA is a tool aimed at helping malware researchers to identify and classify 36 | malware samples. With YARA you can create descriptions of malware families 37 | based on textual or binary patterns contained on samples of those families. 38 | 39 | %package -n yara-devel 40 | Summary: Development files to support the yara malware identification tool 41 | Group: Development/Libraries/C and C++ 42 | Requires: libyara = %{version}-%{release} 43 | 44 | %description -n yara-devel 45 | YARA is a tool aimed at helping malware researchers to identify and classify 46 | malware samples. With YARA you can create descriptions of malware families 47 | based on textual or binary patterns contained on samples of those families. 48 | 49 | %prep 50 | %setup -q 51 | 52 | %build 53 | ./bootstrap.sh 54 | ./configure 55 | make 56 | 57 | %install 58 | make install DESTDIR=%{buildroot} bindir=%{_bindir} libdir=%{_libdir} includedir=%{_includedir} mandir=%{_mandir} INSTALL="install -p" 59 | 60 | %post -n libyara -p /sbin/ldconfig 61 | 62 | %postun -n libyara -p /sbin/ldconfig 63 | 64 | %files 65 | %defattr(-,root,root) 66 | %{_bindir}/yara 67 | %{_bindir}/yarac 68 | %{_mandir}/man1/* 69 | 70 | %files -n libyara 71 | %defattr(-,root,root) 72 | %{_libdir}/libyara.so* 73 | %{_libdir}/pkgconfig/yara.pc 74 | 75 | %files -n yara-devel 76 | %defattr(-,root,root) 77 | %{_includedir}/yara.h 78 | %{_includedir}/yara/* 79 | %{_libdir}/libyara.a 80 | %{_libdir}/libyara.la 81 | 82 | 83 | %changelog 84 | * Sat Jan 25 2015 Domingo Kiser 3.2.0-1 85 | Initial Creation. 86 | -------------------------------------------------------------------------------- /tests/mapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | char str[] = "!dlrow ,olleH"; 41 | int fd; 42 | 43 | char* map_file(char* path) 44 | { 45 | if ((fd = open(path, O_RDONLY)) < 0) 46 | { 47 | fprintf(stderr, "open: %s: %s\n", path, strerror(errno)); 48 | exit(1); 49 | } 50 | char* rv = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 51 | if (rv == NULL) 52 | { 53 | fprintf(stderr, "mmap: %s: failed: %s\n", path, strerror(errno)); 54 | exit(1); 55 | } 56 | close(fd); 57 | return rv; 58 | } 59 | 60 | int main(int argc, char** argv) 61 | { 62 | char* buf; 63 | 64 | if (argc < 2) 65 | { 66 | fprintf(stderr, "no argument\n"); 67 | exit(1); 68 | } 69 | else if (strcmp(argv[1], "open") == 0) 70 | { 71 | if (argc < 3) 72 | exit(1); 73 | 74 | printf("%s: %s %s\n", argv[0], argv[1], argv[2]); 75 | buf = map_file(argv[2]); 76 | } 77 | else if (strcmp(argv[1], "patch") == 0) 78 | { 79 | if (argc < 3) 80 | exit(1); 81 | 82 | printf("%s: %s %s\n", argv[0], argv[1], argv[2]); 83 | buf = map_file(argv[2]); 84 | 85 | for (int i = 0; i < sizeof(str) - 1; i++) 86 | { 87 | buf[i] = str[sizeof(str) - i - 2]; 88 | } 89 | } 90 | else 91 | { 92 | fprintf(stderr, "unknown argument <%s>\n", argv[1]); 93 | exit(1); 94 | } 95 | sleep(3600); 96 | } 97 | -------------------------------------------------------------------------------- /tests/test-re-split.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | 33 | #include "util.h" 34 | 35 | int main(int argc, char** argv) 36 | { 37 | int result = 0; 38 | 39 | YR_DEBUG_INITIALIZE(); 40 | YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]); 41 | 42 | RE_AST* re_ast; 43 | RE_AST* re_ast_remain; 44 | 45 | RE_ERROR re_error; 46 | 47 | int32_t min_gap; 48 | int32_t max_gap; 49 | 50 | yr_initialize(); 51 | yr_re_parse_hex( 52 | "{ 01 02 03 04 [0-300] 05 06 07 08 [1-400] 09 0A 0B 0C }", 53 | &re_ast, 54 | &re_error); 55 | 56 | assert(re_ast != NULL); 57 | 58 | yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); 59 | 60 | assert(re_ast != NULL); 61 | assert(re_ast_remain != NULL); 62 | assert(min_gap == 0); 63 | assert(max_gap == 300); 64 | 65 | yr_re_ast_destroy(re_ast); 66 | re_ast = re_ast_remain; 67 | 68 | yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); 69 | 70 | assert(re_ast != NULL); 71 | assert(re_ast_remain != NULL); 72 | assert(min_gap == 1); 73 | assert(max_gap == 400); 74 | 75 | yr_re_ast_destroy(re_ast); 76 | re_ast = re_ast_remain; 77 | 78 | yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); 79 | 80 | assert(re_ast != NULL); 81 | assert(re_ast_remain == NULL); 82 | 83 | yr_re_ast_destroy(re_ast); 84 | yr_finalize(); 85 | 86 | YR_DEBUG_FPRINTF( 87 | 1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]); 88 | 89 | return result; 90 | } 91 | -------------------------------------------------------------------------------- /libyara/include/yara/sizedstr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007-2014. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _SIZEDSTR_H 31 | #define _SIZEDSTR_H 32 | 33 | #include 34 | #include 35 | 36 | // SIZED_STRING_FLAGS_NO_CASE indicates that the has been decorated with 37 | // the "nocase" modifier or with the /i modifier in the case of regular 38 | // expressions. 39 | #define SIZED_STRING_FLAGS_NO_CASE 1 40 | 41 | // SIZED_STRING_FLAGS_DOT_ALL is used for strings that contain a regular 42 | // expression that had the /s modifier. 43 | #define SIZED_STRING_FLAGS_DOT_ALL 2 44 | 45 | 46 | #pragma pack(push) 47 | #pragma pack(1) 48 | 49 | // 50 | // This struct is used to support strings containing null chars. The length of 51 | // the string is stored along the string data. However the string data is also 52 | // terminated with a null char. 53 | // 54 | typedef struct _SIZED_STRING 55 | { 56 | uint32_t length; 57 | uint32_t flags; 58 | 59 | char c_string[1]; 60 | 61 | } SIZED_STRING; 62 | 63 | #pragma pack(pop) 64 | 65 | int ss_compare(SIZED_STRING* s1, SIZED_STRING* s2); 66 | 67 | int ss_icompare(SIZED_STRING* s1, SIZED_STRING* s2); 68 | 69 | bool ss_contains(SIZED_STRING* s1, SIZED_STRING* s2); 70 | 71 | bool ss_icontains(SIZED_STRING* s1, SIZED_STRING* s2); 72 | 73 | bool ss_startswith(SIZED_STRING* s1, SIZED_STRING* s2); 74 | 75 | bool ss_istartswith(SIZED_STRING* s1, SIZED_STRING* s2); 76 | 77 | bool ss_endswith(SIZED_STRING* s1, SIZED_STRING* s2); 78 | 79 | bool ss_iendswith(SIZED_STRING* s1, SIZED_STRING* s2); 80 | 81 | SIZED_STRING* ss_dup(SIZED_STRING* s); 82 | 83 | SIZED_STRING* ss_new(const char* s); 84 | 85 | SIZED_STRING* ss_convert_to_wide(SIZED_STRING* s); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /libyara/include/yara/endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_ENDIAN_H 31 | #define YR_ENDIAN_H 32 | 33 | #include 34 | 35 | #if defined(__has_builtin) 36 | #if __has_builtin(__builtin_bswap16) 37 | #define yr_bswap16(x) __builtin_bswap16(x) 38 | #endif 39 | #endif 40 | 41 | #if !defined(yr_bswap16) && defined(_MSC_VER) 42 | #define yr_bswap16(x) _byteswap_ushort(x) 43 | #endif 44 | 45 | #if !defined(yr_bswap16) 46 | uint16_t _yr_bswap16(uint16_t x); 47 | #define yr_bswap16(x) _yr_bswap16(x) 48 | #endif 49 | 50 | #if defined(__has_builtin) 51 | #if __has_builtin(__builtin_bswap32) 52 | #define yr_bswap32(x) __builtin_bswap32(x) 53 | #endif 54 | #endif 55 | 56 | #if !defined(yr_bswap32) && defined(_MSC_VER) 57 | #define yr_bswap32(x) _byteswap_ulong(x) 58 | #endif 59 | 60 | #if !defined(yr_bswap32) 61 | uint32_t _yr_bswap32(uint32_t x); 62 | #define yr_bswap32(x) _yr_bswap32(x) 63 | #endif 64 | 65 | #if defined(__has_builtin) 66 | #if __has_builtin(__builtin_bswap64) 67 | #define yr_bswap64(x) __builtin_bswap64(x) 68 | #endif 69 | #endif 70 | 71 | #if !defined(yr_bswap64) && defined(_MSC_VER) 72 | #define yr_bswap64(x) _byteswap_uint64(x) 73 | #endif 74 | 75 | #if !defined(yr_bswap64) 76 | uint64_t _yr_bswap64(uint64_t x); 77 | #define yr_bswap64(x) _yr_bswap64(x) 78 | #endif 79 | 80 | #if defined(WORDS_BIGENDIAN) 81 | #define yr_le16toh(x) yr_bswap16(x) 82 | #define yr_le32toh(x) yr_bswap32(x) 83 | #define yr_le64toh(x) yr_bswap64(x) 84 | #define yr_be16toh(x) (x) 85 | #define yr_be32toh(x) (x) 86 | #define yr_be64toh(x) (x) 87 | #else 88 | #define yr_le16toh(x) (x) 89 | #define yr_le32toh(x) (x) 90 | #define yr_le64toh(x) (x) 91 | #define yr_be16toh(x) yr_bswap16(x) 92 | #define yr_be32toh(x) yr_bswap32(x) 93 | #define yr_be64toh(x) yr_bswap64(x) 94 | #endif 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /extra/codemirror/yara.js: -------------------------------------------------------------------------------- 1 | /* 2 | Language mode for CodeMirror (https://codemirror.net/) 3 | */ 4 | 5 | CodeMirror.defineMode("yara", function(config) { 6 | function words(str) { 7 | var obj = {}, words = str.split(" "); 8 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 9 | return obj; 10 | } 11 | var keywords = words("all and any ascii at base64 base64wide condition contains endswith entrypoint filesize for " + 12 | "fullword global icontains iendswith import in include int16 int32 int8 istartswith matches meta " + 13 | "nocase not of or private rule startswith strings them uint16 uint32 " + 14 | "uint8 wide xor"); 15 | 16 | var atoms = {"true": true, "false": true}; 17 | 18 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; 19 | 20 | function tokenBase(stream, state) { 21 | var ch = stream.next(); 22 | if (ch == "#" && state.startOfLine) { 23 | stream.skipToEnd(); 24 | return "meta"; 25 | } 26 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { 27 | return null 28 | } 29 | if (/\d/.test(ch)) { 30 | stream.eatWhile(/[\w\.]/); 31 | return "number"; 32 | } 33 | if (ch == "/") { 34 | if (stream.eat("/")) { 35 | stream.skipToEnd(); 36 | return "comment"; 37 | } 38 | if (stream.eat("*")) { 39 | state.tokenize = tokenComment; 40 | return tokenComment(stream, state); 41 | } 42 | } 43 | if (ch == '"' || ch == '/') { 44 | state.tokenize = tokenString(ch); 45 | return state.tokenize(stream, state); 46 | } 47 | if (isOperatorChar.test(ch)) { 48 | stream.eatWhile(isOperatorChar); 49 | return "operator"; 50 | } 51 | stream.eatWhile(/[\w\$_]/); 52 | var cur = stream.current(); 53 | if (keywords.propertyIsEnumerable(cur)) return "keyword"; 54 | if (atoms.propertyIsEnumerable(cur)) return "atom"; 55 | return "word"; 56 | } 57 | 58 | function tokenString(quote) { 59 | return function(stream, state) { 60 | var escaped = false, next, end = false; 61 | while ((next = stream.next()) != null) { 62 | if (next == quote && !escaped) {end = true; break;} 63 | escaped = !escaped && next == "\\"; 64 | } 65 | if (end || !escaped) state.tokenize = null; 66 | return "string"; 67 | }; 68 | } 69 | 70 | function tokenComment(stream, state) { 71 | var maybeEnd = false, ch; 72 | while (ch = stream.next()) { 73 | if (ch == "/" && maybeEnd) { 74 | state.tokenize = null; 75 | break; 76 | } 77 | maybeEnd = (ch == "*"); 78 | } 79 | return "comment"; 80 | } 81 | 82 | // Interface 83 | 84 | return { 85 | startState: function(basecolumn) { 86 | return {tokenize: null}; 87 | }, 88 | 89 | token: function(stream, state) { 90 | if (stream.eatSpace()) return null; 91 | var style = (state.tokenize || tokenBase)(stream, state); 92 | return style; 93 | }, 94 | 95 | electricChars: "{}" 96 | }; 97 | }); 98 | 99 | CodeMirror.defineMIME("text/yara", "yara"); 100 | CodeMirror.defineMIME("text/x-yara", "yara"); 101 | -------------------------------------------------------------------------------- /libyara/include/yara/unaligned.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_UNALIGNED_H 31 | #define YR_UNALIGNED_H 32 | 33 | #include 34 | 35 | #pragma pack(push) 36 | #pragma pack(1) 37 | 38 | typedef struct 39 | { 40 | uint16_t val; 41 | } uint16_una_t; 42 | 43 | typedef struct 44 | { 45 | uint32_t val; 46 | } uint32_una_t; 47 | 48 | typedef struct 49 | { 50 | uint64_t val; 51 | } uint64_una_t; 52 | 53 | typedef struct 54 | { 55 | int16_t val; 56 | } int16_una_t; 57 | 58 | typedef struct 59 | { 60 | int32_t val; 61 | } int32_una_t; 62 | 63 | typedef struct 64 | { 65 | int64_t val; 66 | } int64_una_t; 67 | 68 | typedef struct 69 | { 70 | char *val; 71 | } charp_una_t; 72 | 73 | #pragma pack(pop) 74 | 75 | static inline uint16_t yr_unaligned_u16(const void *ptr) 76 | { 77 | const uint16_una_t *tmp = (const uint16_una_t *) ptr; 78 | return tmp->val; 79 | } 80 | 81 | static inline uint32_t yr_unaligned_u32(const void *ptr) 82 | { 83 | const uint32_una_t *tmp = (const uint32_una_t *) ptr; 84 | return tmp->val; 85 | } 86 | 87 | static inline uint64_t yr_unaligned_u64(const void *ptr) 88 | { 89 | const uint64_una_t *tmp = (const uint64_una_t *) ptr; 90 | return tmp->val; 91 | } 92 | 93 | static inline uint16_t yr_unaligned_i16(const void *ptr) 94 | { 95 | const int16_una_t *tmp = (const int16_una_t *) ptr; 96 | return tmp->val; 97 | } 98 | 99 | static inline uint32_t yr_unaligned_i32(const void *ptr) 100 | { 101 | const int32_una_t *tmp = (const int32_una_t *) ptr; 102 | return tmp->val; 103 | } 104 | 105 | static inline uint64_t yr_unaligned_i64(const void *ptr) 106 | { 107 | const int64_una_t *tmp = (const int64_una_t *) ptr; 108 | return tmp->val; 109 | } 110 | 111 | static inline char *yr_unaligned_char_ptr(const void *ptr) 112 | { 113 | const charp_una_t *tmp = (const charp_una_t *) ptr; 114 | return tmp->val; 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # AppVeyor CI for Windows 2 | 3 | version: '{branch}-{build}' 4 | 5 | pull_requests: 6 | do_not_increment_build_number: true 7 | 8 | environment: 9 | matrix: 10 | - TARGET: vs2015 11 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 12 | VisualStudioVersion: 14.0 13 | platform: x86 14 | configuration: Release 15 | artifact_postfix: win32 16 | - TARGET: vs2015 17 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 18 | VisualStudioVersion: 14.0 19 | platform: x86 20 | configuration: Debug 21 | - TARGET: vs2015 22 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 23 | VisualStudioVersion: 14.0 24 | platform: x64 25 | configuration: Release 26 | artifact_postfix: win64 27 | - TARGET: vs2015 28 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 29 | VisualStudioVersion: 14.0 30 | platform: x64 31 | configuration: Debug 32 | - TARGET: cygwin 33 | 34 | for: 35 | - 36 | matrix: 37 | only: 38 | - TARGET: cygwin 39 | 40 | # Disable the installation of flex and bison packages. For some reason this 41 | # now (2021-04-19) upgrades the perl_base package to version 5.32.1-1 which 42 | # later fails with error: 43 | # Can't locate threads.pm in @INC (you may need to install the threads module) 44 | # 45 | # before_build: 46 | # - cmd: C:\cygwin64\setup-x86_64.exe --quiet-mode --no-desktop --no-shortcuts --no-startmenu --no-admin --packages flex,bison 47 | 48 | build_script: 49 | - cmd: C:\cygwin64\bin\bash -e -l -c "cd c:/projects/yara && ./build.sh" 50 | 51 | test_script: 52 | - cmd: C:\cygwin64\bin\bash -e -l -c "cd c:/projects/yara && make check" 53 | 54 | - 55 | matrix: 56 | only: 57 | - TARGET: vs2015 58 | - configuration: Release 59 | 60 | before_build: 61 | - ps: nuget restore windows/vs2015/yara.sln 62 | 63 | build: 64 | project: windows/vs2015/yara.sln 65 | verbosity: minimal 66 | 67 | after_build: 68 | - cmd: 7z a yara-%APPVEYOR_BUILD_VERSION%-%ARTIFACT_POSTFIX%.zip %APPVEYOR_BUILD_FOLDER%\windows\%TARGET%\%CONFIGURATION%\yara*.exe 69 | 70 | artifacts: 71 | - path: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX).zip 72 | name: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX) 73 | type: zip 74 | 75 | deploy: 76 | tag: $(APPVEYOR_REPO_TAG_NAME) 77 | release: YARA $(APPVEYOR_REPO_TAG_NAME) 78 | provider: GitHub 79 | auth_token: 80 | secure: k+4xp4M/IEqXhKKYwo3DY2ko6VenOfSBEij3AasSiz1i8vsCwfcGxhuae0kj7Gj2 81 | artifact: yara-$(APPVEYOR_BUILD_VERSION)-$(ARTIFACT_POSTFIX) 82 | draft: true 83 | on: 84 | APPVEYOR_REPO_TAG: true # deploy on tag push only 85 | 86 | test_script: 87 | - cmd: c:/projects/yara/windows/vs2015/%CONFIGURATION%/test-alignment.exe 88 | 89 | - 90 | matrix: 91 | only: 92 | - TARGET: vs2015 93 | - configuration: Debug 94 | 95 | before_build: 96 | - ps: nuget restore windows/vs2015/yara.sln 97 | 98 | build: 99 | project: windows/vs2015/yara.sln 100 | verbosity: minimal 101 | 102 | test_script: 103 | - cmd: c:/projects/yara/windows/vs2015/%CONFIGURATION%/test-alignment.exe 104 | 105 | 106 | # Uncomment the lines below for enabling Remote Desktop in the Appveyor. This 107 | # allows connecting to the remote machine and debug issues. 108 | # on_finish: 109 | # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) 110 | -------------------------------------------------------------------------------- /libyara/modules/pe/authenticode-parser/structs.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021 Avast Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | */ 21 | 22 | #include "structs.h" 23 | 24 | ASN1_CHOICE(SpcString) = { 25 | ASN1_IMP_OPT(SpcString, value.unicode, ASN1_BMPSTRING, 0), 26 | ASN1_IMP_OPT(SpcString, value.ascii, ASN1_IA5STRING, 1) 27 | } ASN1_CHOICE_END(SpcString) 28 | 29 | ASN1_SEQUENCE(SpcSerializedObject) = { 30 | ASN1_SIMPLE(SpcSerializedObject, classId, ASN1_OCTET_STRING), 31 | ASN1_SIMPLE(SpcSerializedObject, serializedData, ASN1_OCTET_STRING) 32 | } ASN1_SEQUENCE_END(SpcSerializedObject) 33 | 34 | ASN1_CHOICE(SpcLink) = { 35 | ASN1_IMP_OPT(SpcLink, value.url, ASN1_IA5STRING, 0), 36 | ASN1_IMP_OPT(SpcLink, value.moniker, SpcSerializedObject, 1), 37 | ASN1_EXP_OPT(SpcLink, value.file, SpcString, 2) 38 | } ASN1_CHOICE_END(SpcLink) 39 | 40 | ASN1_SEQUENCE(SpcAttributeTypeAndOptionalValue) = { 41 | ASN1_SIMPLE(SpcAttributeTypeAndOptionalValue, type, ASN1_OBJECT), 42 | ASN1_OPT(SpcAttributeTypeAndOptionalValue, value, ASN1_ANY) 43 | } ASN1_SEQUENCE_END(SpcAttributeTypeAndOptionalValue) 44 | 45 | ASN1_SEQUENCE(SpcPeImageData) = { 46 | ASN1_SIMPLE(SpcPeImageData, flags, ASN1_BIT_STRING), 47 | ASN1_EXP_OPT(SpcPeImageData, file, SpcLink, 0) 48 | } ASN1_SEQUENCE_END(SpcPeImageData) 49 | 50 | ASN1_SEQUENCE(AlgorithmIdentifier) = { 51 | ASN1_SIMPLE(AlgorithmIdentifier, algorithm, ASN1_OBJECT), 52 | ASN1_OPT(AlgorithmIdentifier, parameters, ASN1_ANY) 53 | } ASN1_SEQUENCE_END(AlgorithmIdentifier) 54 | 55 | ASN1_SEQUENCE(DigestInfo) = { 56 | ASN1_SIMPLE(DigestInfo, digestAlgorithm, AlgorithmIdentifier), 57 | ASN1_SIMPLE(DigestInfo, digest, ASN1_OCTET_STRING) 58 | } ASN1_SEQUENCE_END(DigestInfo) 59 | 60 | ASN1_SEQUENCE(SpcIndirectDataContent) = { 61 | ASN1_SIMPLE(SpcIndirectDataContent, data, SpcAttributeTypeAndOptionalValue), 62 | ASN1_SIMPLE(SpcIndirectDataContent, messageDigest, DigestInfo) 63 | } ASN1_SEQUENCE_END(SpcIndirectDataContent) 64 | 65 | ASN1_SEQUENCE(SpcSpOpusInfo) = { 66 | ASN1_EXP_OPT(SpcSpOpusInfo, programName, SpcString, 0), 67 | ASN1_EXP_OPT(SpcSpOpusInfo, moreInfo, SpcLink, 1) 68 | } ASN1_SEQUENCE_END(SpcSpOpusInfo) 69 | 70 | IMPLEMENT_ASN1_FUNCTIONS(SpcString) 71 | IMPLEMENT_ASN1_FUNCTIONS(SpcSerializedObject) 72 | IMPLEMENT_ASN1_FUNCTIONS(SpcLink) 73 | IMPLEMENT_ASN1_FUNCTIONS(SpcAttributeTypeAndOptionalValue) 74 | IMPLEMENT_ASN1_FUNCTIONS(SpcPeImageData) 75 | IMPLEMENT_ASN1_FUNCTIONS(AlgorithmIdentifier) 76 | IMPLEMENT_ASN1_FUNCTIONS(DigestInfo) 77 | IMPLEMENT_ASN1_FUNCTIONS(SpcIndirectDataContent) 78 | IMPLEMENT_ASN1_FUNCTIONS(SpcSpOpusInfo) 79 | -------------------------------------------------------------------------------- /libyara/hex_grammar.h: -------------------------------------------------------------------------------- 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ 2 | 3 | /* Bison interface for Yacc-like parsers in C 4 | 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 | Inc. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | /* As a special exception, you may create a larger work that contains 22 | part or all of the Bison parser skeleton and distribute that work 23 | under terms of your choice, so long as that work isn't itself a 24 | parser generator using the skeleton or a modified version thereof 25 | as a parser skeleton. Alternatively, if you modify or redistribute 26 | the parser skeleton itself, you may (at your option) remove this 27 | special exception, which will cause the skeleton and the resulting 28 | Bison output files to be licensed under the GNU General Public 29 | License without this special exception. 30 | 31 | This special exception was added by the Free Software Foundation in 32 | version 2.2 of Bison. */ 33 | 34 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 35 | especially those whose name start with YY_ or yy_. They are 36 | private implementation details that can be changed or removed. */ 37 | 38 | #ifndef YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED 39 | # define YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED 40 | /* Debug traces. */ 41 | #ifndef YYDEBUG 42 | # define YYDEBUG 0 43 | #endif 44 | #if YYDEBUG 45 | extern int hex_yydebug; 46 | #endif 47 | 48 | /* Token kinds. */ 49 | #ifndef YYTOKENTYPE 50 | # define YYTOKENTYPE 51 | enum yytokentype 52 | { 53 | YYEMPTY = -2, 54 | YYEOF = 0, /* "end of file" */ 55 | YYerror = 256, /* error */ 56 | YYUNDEF = 257, /* "invalid token" */ 57 | _BYTE_ = 258, /* _BYTE_ */ 58 | _MASKED_BYTE_ = 259, /* _MASKED_BYTE_ */ 59 | _NOT_BYTE_ = 260, /* _NOT_BYTE_ */ 60 | _MASKED_NOT_BYTE_ = 261, /* _MASKED_NOT_BYTE_ */ 61 | _NUMBER_ = 262 /* _NUMBER_ */ 62 | }; 63 | typedef enum yytokentype yytoken_kind_t; 64 | #endif 65 | /* Token kinds. */ 66 | #define YYEMPTY -2 67 | #define YYEOF 0 68 | #define YYerror 256 69 | #define YYUNDEF 257 70 | #define _BYTE_ 258 71 | #define _MASKED_BYTE_ 259 72 | #define _NOT_BYTE_ 260 73 | #define _MASKED_NOT_BYTE_ 261 74 | #define _NUMBER_ 262 75 | 76 | /* Value type. */ 77 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 78 | union YYSTYPE 79 | { 80 | #line 78 "hex_grammar.y" 81 | 82 | int64_t integer; 83 | RE_NODE *re_node; 84 | 85 | #line 86 "hex_grammar.h" 86 | 87 | }; 88 | typedef union YYSTYPE YYSTYPE; 89 | # define YYSTYPE_IS_TRIVIAL 1 90 | # define YYSTYPE_IS_DECLARED 1 91 | #endif 92 | 93 | 94 | 95 | 96 | int hex_yyparse (void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); 97 | 98 | 99 | #endif /* !YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED */ 100 | -------------------------------------------------------------------------------- /libyara/include/yara/strutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007-2014. The YARA Authors. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef YR_STRUTILS_H 31 | #define YR_STRUTILS_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #if defined(_WIN32) 40 | 41 | #if !defined(PRIu64) 42 | #define PRIu64 "I64u" 43 | #endif 44 | 45 | #if !defined(PRIu32) 46 | #define PRIu32 "I32u" 47 | #endif 48 | 49 | #if !defined(PRIx64) 50 | #define PRIx64 "I64x" 51 | #endif 52 | 53 | #if !defined(PRId64) 54 | #define PRId64 "I64d" 55 | #endif 56 | 57 | #if !defined(PRIi32) 58 | #define PRIi32 "I32i" 59 | #endif 60 | 61 | #if !defined(PRIi64) 62 | #define PRIi64 "I64i" 63 | #endif 64 | 65 | #if !defined(PRIo64) 66 | #define PRIo64 "I64o" 67 | #endif 68 | 69 | #else 70 | #include 71 | #endif 72 | 73 | // Cygwin already has these functions. 74 | #if defined(_WIN32) && !defined(__CYGWIN__) 75 | #if defined(_MSC_VER) && _MSC_VER < 1900 76 | 77 | #if !defined(snprintf) 78 | #define snprintf _snprintf 79 | #endif 80 | 81 | #endif 82 | #define strcasecmp _stricmp 83 | #define strncasecmp _strnicmp 84 | #endif 85 | 86 | uint64_t xtoi(const char* hexstr); 87 | 88 | #if !HAVE_STRLCPY && !defined(strlcpy) 89 | size_t strlcpy(char* dst, const char* src, size_t size); 90 | #endif 91 | 92 | #if !HAVE_STRLCAT && !defined(strlcat) 93 | size_t strlcat(char* dst, const char* src, size_t size); 94 | #endif 95 | 96 | #if !HAVE_MEMMEM && !defined(memmem) 97 | void* memmem( 98 | const void* haystack, 99 | size_t haystack_size, 100 | const void* needle, 101 | size_t needle_size); 102 | #endif 103 | 104 | int strnlen_w(const char* w_str); 105 | 106 | int strcmp_w(const char* w_str, const char* str); 107 | 108 | size_t strlcpy_w(char* dst, const char* w_src, size_t n); 109 | 110 | #endif 111 | 112 | int yr_isalnum(const uint8_t* s); 113 | 114 | void yr_vasprintf(char** strp, const char* fmt, va_list ap); 115 | 116 | void yr_asprintf(char** strp, const char* fmt, ...); 117 | -------------------------------------------------------------------------------- /libyara/include/yara/dex.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEX_H 2 | #define _DEX_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define DEX_FILE_MAGIC_035 "dex\n035\x00" 9 | #define DEX_FILE_MAGIC_036 "dex\n036\x00" 10 | #define DEX_FILE_MAGIC_037 "dex\n037\x00" 11 | #define DEX_FILE_MAGIC_038 "dex\n038\x00" 12 | #define DEX_FILE_MAGIC_039 "dex\n039\x00" 13 | 14 | #pragma pack(push, 1) 15 | 16 | typedef struct 17 | { 18 | uint8_t magic[8]; 19 | uint32_t checksum; 20 | uint8_t signature[20]; 21 | uint32_t file_size; 22 | uint32_t header_size; 23 | uint32_t endian_tag; 24 | uint32_t link_size; 25 | uint32_t link_offset; 26 | uint32_t map_offset; 27 | uint32_t string_ids_size; 28 | uint32_t string_ids_offset; 29 | uint32_t type_ids_size; 30 | uint32_t type_ids_offset; 31 | uint32_t proto_ids_size; 32 | uint32_t proto_ids_offset; 33 | uint32_t field_ids_size; 34 | uint32_t field_ids_offset; 35 | uint32_t method_ids_size; 36 | uint32_t method_ids_offset; 37 | uint32_t class_defs_size; 38 | uint32_t class_defs_offset; 39 | uint32_t data_size; 40 | uint32_t data_offset; 41 | } dex_header_t; 42 | 43 | typedef struct 44 | { 45 | uint32_t string_data_offset; 46 | } string_id_item_t; 47 | 48 | typedef struct 49 | { 50 | uint32_t utf16_size; 51 | } string_data_item_t; 52 | 53 | typedef struct 54 | { 55 | uint32_t descriptor_idx; 56 | } type_id_item_t; 57 | 58 | typedef struct 59 | { 60 | uint32_t shorty_idx; 61 | uint32_t return_type_idx; 62 | uint32_t parameters_offset; 63 | } proto_id_item_t; 64 | 65 | typedef struct 66 | { 67 | uint16_t class_idx; 68 | uint16_t type_idx; 69 | uint32_t name_idx; 70 | } field_id_item_t; 71 | 72 | typedef struct 73 | { 74 | uint16_t class_idx; 75 | uint16_t proto_idx; 76 | uint32_t name_idx; 77 | } method_id_item_t; 78 | 79 | typedef struct 80 | { 81 | uint32_t class_idx; 82 | uint32_t access_flags; 83 | uint32_t super_class_idx; 84 | uint32_t interfaces_offset; 85 | uint32_t source_file_idx; 86 | uint32_t annotations_offset; 87 | uint32_t class_data_offset; 88 | uint32_t static_values_offset; 89 | } class_id_item_t; 90 | 91 | typedef struct 92 | { 93 | uint32_t static_fields_size; 94 | uint32_t instance_fields_size; 95 | uint32_t direct_methods_size; 96 | uint32_t virtual_methods_size; 97 | } class_data_item_t; 98 | 99 | typedef struct 100 | { 101 | uint32_t field_idx_diff; 102 | uint32_t access_flags; 103 | } encoded_field_t; 104 | 105 | typedef struct 106 | { 107 | uint32_t method_idx_diff; 108 | uint32_t access_flags; 109 | uint32_t code_off; 110 | } encoded_method_t; 111 | 112 | typedef struct 113 | { 114 | uint16_t registers_size; 115 | uint16_t ins_size; 116 | uint16_t outs_size; 117 | uint16_t tries_size; 118 | uint32_t debug_info_off; 119 | uint32_t insns_size; 120 | } code_item_t; 121 | 122 | typedef struct 123 | { 124 | uint16_t type; 125 | uint16_t unused; 126 | uint32_t size; 127 | uint32_t offset; 128 | } map_item_t; 129 | 130 | typedef struct _DEX 131 | { 132 | const uint8_t* data; 133 | size_t data_size; 134 | dex_header_t* header; 135 | YR_OBJECT* object; 136 | } DEX; 137 | 138 | #define fits_in_dex(dex, pointer, size) \ 139 | ((size_t) size <= dex->data_size && (uint8_t*) (pointer) >= dex->data && \ 140 | (uint8_t*) (pointer) <= dex->data + dex->data_size - size) 141 | 142 | #define struct_fits_in_dex(dex, pointer, struct_type) \ 143 | fits_in_dex(dex, pointer, sizeof(struct_type)) 144 | 145 | #pragma pack(pop) 146 | 147 | #endif 148 | --------------------------------------------------------------------------------