Browse code

Add hidden ctx param to APIcalls.

Török Edvin authored on 2009/09/04 18:09:17
Showing 9 changed files
... ...
@@ -60,14 +60,14 @@ int main(int argc, char *argv[])
60 60
 	fprintf(stderr, "ERROR: Can't parse command line options\n");
61 61
 	exit(1);
62 62
     }
63
-    if(optget(opts, "help")->enabled || !opts->filename) {
63
+    if(optget(opts, "version")->enabled) {
64
+	printf("Clam AntiVirus Bytecode Testing Tool %s\n", get_version());
64 65
 	optfree(opts);
65
-	help();
66 66
 	exit(0);
67 67
     }
68
-    if(optget(opts, "version")->enabled) {
69
-	printf("Clam AntiVirus Bytecode Testing Tool %s\n", get_version());
68
+    if(optget(opts, "help")->enabled || !opts->filename) {
70 69
 	optfree(opts);
70
+	help();
71 71
 	exit(0);
72 72
     }
73 73
     f = fopen(opts->filename[0], "r");
... ...
@@ -97,11 +97,16 @@ int main(int argc, char *argv[])
97 97
 
98 98
     if (dbgargc > 1)
99 99
 	cli_bytecode_debug(dbgargc, opts->filename);
100
-    rc = cli_bytecode_init(&bcs);
101
-    if (rc != CL_SUCCESS) {
102
-	fprintf(stderr,"Unable to init bytecode engine: %s\n", cl_strerror(rc));
103
-	optfree(opts);
104
-	exit(4);
100
+
101
+    if (optget(opts, "force-interpreter")->enabled) {
102
+	bcs.engine = NULL;
103
+    } else {
104
+	rc = cli_bytecode_init(&bcs);
105
+	if (rc != CL_SUCCESS) {
106
+	    fprintf(stderr,"Unable to init bytecode engine: %s\n", cl_strerror(rc));
107
+	    optfree(opts);
108
+	    exit(4);
109
+	}
105 110
     }
106 111
 
107 112
     bcs.all_bcs = bc;
... ...
@@ -75,4 +75,5 @@ int cli_bytecode_run(const struct cli_all_bc *bcs, const struct cli_bc *bc, stru
75 75
 void cli_bytecode_destroy(struct cli_bc *bc);
76 76
 int cli_bytecode_done(struct cli_all_bc *allbc);
77 77
 
78
+
78 79
 #endif
... ...
@@ -1,6 +1,34 @@
1
+/*
2
+ *  ClamAV bytecode API.
3
+ *
4
+ *  Copyright (C) 2009 Sourcefire, Inc.
5
+ *
6
+ *  Authors: Török Edvin
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 version 2 as
10
+ *  published by the Free Software Foundation.
11
+ *
12
+ *  This program is distributed in the hope that it will be useful,
13
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ *  GNU General Public License for more details.
16
+ *
17
+ *  You should have received a copy of the GNU General Public License
18
+ *  along with this program; if not, write to the Free Software
19
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
+ *  MA 02110-1301, USA.
21
+ */
22
+
23
+struct lsig_match {
24
+    uint32_t evalcnt;
25
+    uint64_t evalids;
26
+    uint16_t filetype;
27
+};
28
+
1 29
 struct foo {
2 30
     struct foo *nxt;
3 31
 };
4 32
 
5
-int32_t cli_bcapi_test0(struct foo*, uint32_t);
6
-int32_t cli_bcapi_test1(int32_t, int32_t);
33
+int32_t test0(struct foo*, uint32_t);
34
+int32_t test1(int32_t, int32_t);
... ...
@@ -23,6 +23,9 @@
23 23
 #include "type_desc.h"
24 24
 #include "bytecode_api.h"
25 25
 
26
+uint32_t cli_bcapi_test0(struct cli_bc_ctx *ctx, struct foo*, uint32_t);
27
+uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t, uint32_t);
28
+
26 29
 static uint16_t cli_tmp0[]={32, 70, 32};
27 30
 static uint16_t cli_tmp1[]={71};
28 31
 static uint16_t cli_tmp2[]={70};
... ...
@@ -38,8 +41,8 @@ const struct cli_bc_type cli_apicall_types[]={
38 38
 const unsigned cli_apicall_maxtypes=sizeof(cli_apicall_types)/sizeof(cli_apicall_types[0]);
39 39
 const struct cli_apicall cli_apicalls[]={
40 40
 /* Bytecode APIcalls BEGIN */
41
-	{"cli_bcapi_test0", 0, 0, 1},
42
-	{"cli_bcapi_test1", 3, 0, 0}
41
+	{"test0", 0, 0, 1},
42
+	{"test1", 3, 0, 0}
43 43
 /* Bytecode APIcalls END */
44 44
 };
45 45
 const cli_apicall_int2 cli_apicalls0[] = {
... ...
@@ -576,7 +576,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
576 576
 			int32_t a, b, r;
577 577
 			READ32(a, inst->u.ops.ops[0]);
578 578
 			READ32(b, inst->u.ops.ops[1]);
579
-			res = cli_apicalls0[api->idx](a, b);
579
+			res = cli_apicalls0[api->idx](ctx, a, b);
580 580
 			break;
581 581
 		    }
582 582
 		    case 1: {
... ...
@@ -22,6 +22,8 @@
22 22
 #ifndef TYPE_DESC_H
23 23
 #define TYPE_DESC_H
24 24
 
25
+struct cli_bc_ctx;
26
+
25 27
 enum derived_t {
26 28
   DFunctionType,
27 29
   DPointerType,
... ...
@@ -38,8 +40,8 @@ struct cli_bc_type {
38 38
     unsigned align;
39 39
 };
40 40
 
41
-typedef int32_t (*cli_apicall_int2)(int32_t, int32_t);
42
-typedef int32_t (*cli_apicall_pointer)(void*, uint32_t);
41
+typedef int32_t (*cli_apicall_int2)(struct cli_bc_ctx *, int32_t, int32_t);
42
+typedef int32_t (*cli_apicall_pointer)(struct cli_bc_ctx *, void*, uint32_t);
43 43
 
44 44
 struct cli_apicall {
45 45
     const char *name;
... ...
@@ -118,6 +118,8 @@ const struct clam_option clam_options[] = {
118 118
     { NULL, "non-default", 'n', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMCONF, "", "" },
119 119
     { NULL, "generate-config", 'g', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMCONF, "", "" },
120 120
 
121
+    { NULL, "force-interpreter", 'f', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMBC, "", "" },
122
+
121 123
     /* cmdline only - deprecated */
122 124
     { NULL, "http-proxy", 0, TYPE_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
123 125
     { NULL, "proxy-user", 0, TYPE_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
... ...
@@ -1,6 +1,6 @@
1 1
 ClamBCaa`|`````|`afafp`clamcoincidencejb
2 2
 Tedacb`bb`bb`b
3
-Eabaaabbed|b`acflfifoebfcfaf`gifoedgefcgdgac``
3
+Eabaaabbed|afdgefcgdgac``
4 4
 A`b`bLacb`baab`bFadaa
5 5
 Bb`b``bbabHonnkm``odHm``oonnkdaaaadab`b`Hhgfedcbadb`babnaaaDm``odDmjnmdTcab`babE
6 6
 Aab`bLabahaab`bFacaa
... ...
@@ -1,6 +1,6 @@
1 1
 ClamBCaa`|`````|`ajafp`clamcoincidencejb
2 2
 Tedcabidebidacb`bb`bb`bacb`bbidb`bebed
3
-Eabababbgd|b`acflfifoebfcfaf`gifoedgefcgdgac``aabhd|b`acflfifoebfcfaf`gifoedgefcgdg`c``
3
+Eabababbgd|afdgefcgdgac``aabhd|afdgefcgdg`c``
4 4
 A`b`bLahbedbfd`b`baab`baab`bFajac
5 5
 Bbfdaacb`@d@d``eb`aab`bac`bbabHonnkm``odHm``oonnkdaaaddab`bacHhgfedcbadTaaadaaab
6 6
 Bb`bae`bbaa`Honnkmjnmdaaafdab`baeHhgfedcbadb`bagnaafDm``odDmjnmdTcab`bag