File: test-magic.c

package info (click to toggle)
yara 4.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,884 kB
  • sloc: ansic: 52,295; yacc: 2,895; lex: 2,019; cpp: 863; makefile: 479; javascript: 85; sh: 47; python: 35
file content (47 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <unistd.h>
#include <yara.h>

#include "blob.h"
#include "util.h"

int main(int argc, char** argv)
{
  int result = 0;

  YR_DEBUG_INITIALIZE();
  YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]);

  init_top_srcdir();

  yr_initialize();

  assert_true_rule_blob(
      "import \"magic\" rule test { condition: \
      magic.type() contains \"ELF\" }",
      ELF32_FILE);

  assert_true_rule_blob(
      "import \"magic\" rule test { condition: \
      ( magic.type() contains \"MS-DOS executable\" or \
        magic.type() contains \"PE32+ executable\" or \
        magic.type() contains \"PE32 executable\") and \
      ( magic.mime_type() == \"application/x-dosexec\" or \
        magic.mime_type() == \"application/vnd.microsoft.portable-executable\" ) }",
      PE32_FILE);

  // Test case for https://github.com/VirusTotal/yara/issues/1663
  assert_true_rule_blob(
      "import \"magic\" rule test { condition: \
      magic.type() contains \"Mach-O\" and \
      (magic.mime_type() == \"application/x-mach-binary\" or magic.mime_type() == \"application/octet-stream\") and \
      magic.type() contains \"Mach-O\"}",
      MACHO_X86_FILE);

  yr_finalize();

  YR_DEBUG_FPRINTF(
      1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]);

  return result;
}