[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

Török Edvin edwin at clamav.net
Sun Apr 4 01:19:10 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 9bdaf35dea6b29bd18dcbfe5c54a6758306c284a
Author: Török Edvin <edwin at clamav.net>
Date:   Sat Feb 6 17:53:17 2010 +0200

    print bytecode source code.

diff --git a/clambc/bcrun.c b/clambc/bcrun.c
index 320a355..e019d2a 100644
--- a/clambc/bcrun.c
+++ b/clambc/bcrun.c
@@ -120,6 +120,41 @@ static void tracehook_ptr(struct cli_bc_ctx *ctx, const void *ptr)
     fprintf(stderr, "[trace] %p\n", ptr);
 }
 
+static void print_src(const char *file)
+{
+  char buf[4096];
+  int nread, i, found = 0;
+  FILE *f = fopen(file, "r");
+  if (!f) {
+    fprintf(stderr,"Unable to reopen %s\n", file);
+    return;
+  }
+  do {
+    nread = fread(buf, 1, sizeof(buf), f);
+    for (i=0;i<nread-1;i++) {
+      if (buf[i] == '\n' && buf[i+1] == 'S') {
+        found = 1;
+        i++;
+        break;
+      }
+    }
+  } while (!found && (nread == sizeof(buf)));
+  printf("Source code:");
+  do {
+    for (;i+1<nread;i++) {
+      if (buf[i] == 'S' || buf[i] == '\n') {
+        putc('\n', stdout);
+        continue;
+      }
+      putc((buf[i]&0xf | ((buf[i+1]&0xf)<<4)), stdout);
+      i++;
+    }
+    i=0;
+    nread = fread(buf, 1, sizeof(buf), f);
+  } while (nread > 0);
+  fclose(f);
+}
+
 int main(int argc, char *argv[])
 {
     FILE *f;
@@ -210,6 +245,7 @@ int main(int argc, char *argv[])
     printf("Bytecode loaded\n");
     if (optget(opts, "describe")->enabled) {
 	cli_bytecode_describe(bc);
+        print_src(opts->filename[0]);
     } else {
 
 	ctx = cli_bytecode_context_alloc();
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 8f527cc..22d7522 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1229,7 +1229,7 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio, int tru
     unsigned linelength=0;
     char firstbuf[FILEBUFF];
     enum parse_state state;
-    int rc;
+    int rc, end=0;
 
     memset(bc, 0, sizeof(*bc));
     bc->trusted = trust;
@@ -1257,7 +1257,7 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio, int tru
 	return CL_EMEM;
     }
     state = PARSE_BC_LSIG;
-    while (cli_dbgets(buffer, linelength, f, dbio)) {
+    while (cli_dbgets(buffer, linelength, f, dbio) && !end) {
 	cli_chomp(buffer);
 	row++;
 	switch (state) {
@@ -1324,6 +1324,10 @@ int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio, int tru
 		}
 		/* fall-through */
 	    case PARSE_FUNC_HEADER:
+                if (*buffer == 'S') {
+		    end = 1;
+		    break;
+		}
 		rc = parseFunctionHeader(bc, current_func, (unsigned char*)buffer);
 		if (rc != CL_SUCCESS) {
 		    cli_errmsg("Error at bytecode line %u\n", row);

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list