... | ... |
@@ -46,6 +46,15 @@ |
46 | 46 |
#include <bzlib.h> |
47 | 47 |
#endif |
48 | 48 |
|
49 |
+#if HAVE_LIBXML2 |
|
50 |
+#ifdef _WIN32 |
|
51 |
+#ifndef LIBXML_WRITER_ENABLED |
|
52 |
+#define LIBXML_WRITER_ENABLED 1 |
|
53 |
+#endif |
|
54 |
+#endif |
|
55 |
+#include <libxml/xmlreader.h> |
|
56 |
+#endif |
|
57 |
+ |
|
49 | 58 |
#include "explode.h" |
50 | 59 |
#include "others.h" |
51 | 60 |
#include "clamav.h" |
... | ... |
@@ -659,22 +668,50 @@ static int unzip_search(cli_ctx *ctx, const char *name, size_t nlen, uint32_t *l |
659 | 659 |
|
660 | 660 |
static int ooxml_content_cb(int fd, cli_ctx *ctx) |
661 | 661 |
{ |
662 |
+#if HAVE_LIBXML2 |
|
663 |
+ int tmp, i, ret = CL_SUCCESS; |
|
664 |
+ const xmlChar *name, *value; |
|
665 |
+ xmlTextReaderPtr reader = NULL; |
|
666 |
+ |
|
662 | 667 |
cli_dbgmsg("in ooxml_content_cb\n"); |
663 |
- cli_errmsg("HI MOM! IT FUCKING WORKS!\n"); |
|
664 |
- /* locate core-properties */ |
|
665 |
- /* extract core-properties and process */ |
|
666 |
- /* locate extended-properties */ |
|
667 |
- /* extract extended-properties and process */ |
|
668 |
- /* locate custom-properties (optional) */ |
|
669 |
- /* extract custom-properties and process */ |
|
670 |
- /* return ret */ |
|
671 | 668 |
|
669 |
+ reader = xmlReaderForFd(fd, "[Content_Types].xml", NULL, 0); |
|
670 |
+ if (reader == NULL) { |
|
671 |
+ cli_dbgmsg("ooxml_content_cb: xmlReaderForFd error for ""[Content_Types].xml""\n"); |
|
672 |
+ return CL_SUCCESS; // libxml2 failed! |
|
673 |
+ } |
|
674 |
+ |
|
675 |
+ /* locate core-properties, extended-properties, and custom-properties (optional) */ |
|
676 |
+ while (xmlTextReaderRead(reader) == 1) { |
|
677 |
+ name = xmlTextReaderConstLocalName(reader); |
|
678 |
+ if (name == NULL) continue; |
|
679 |
+ |
|
680 |
+ if (strcmp(name, "Override")) continue; |
|
681 |
+ |
|
682 |
+ if (!xmlTextReaderHasAttributes(reader)) continue; |
|
683 |
+ |
|
684 |
+ while (xmlTextReaderMoveToNextAttribute(reader) == 1) { |
|
685 |
+ name = xmlTextReaderConstLocalName(reader); |
|
686 |
+ value = xmlTextReaderConstValue(reader); |
|
687 |
+ if (name == NULL || value == NULL) continue; |
|
688 |
+ |
|
689 |
+ cli_dbgmsg("%s: %s\n", name, value); |
|
690 |
+ } |
|
691 |
+ } |
|
692 |
+ |
|
693 |
+ oocml_content_exit: |
|
694 |
+ xmlTextReaderClose(reader); |
|
695 |
+ xmlFreeTextReader(reader); |
|
696 |
+ return ret; |
|
697 |
+#else |
|
698 |
+ cli_dbgmsg("ooxml_content_cb: libxml2 needs to enabled!"); |
|
672 | 699 |
return CL_SUCCESS; |
700 |
+#endif |
|
673 | 701 |
} |
674 | 702 |
|
675 | 703 |
int cli_process_ooxml(cli_ctx *ctx) |
676 | 704 |
{ |
677 |
- int ret = CL_SUCCESS; |
|
705 |
+#if HAVE_LIBXML2 |
|
678 | 706 |
uint32_t loff = 0; |
679 | 707 |
|
680 | 708 |
cli_dbgmsg("in cli_processooxml\n"); |
... | ... |
@@ -687,10 +724,12 @@ int cli_process_ooxml(cli_ctx *ctx) |
687 | 687 |
cli_dbgmsg("cli_process_ooxml: failed to find ""[Content_Types].xml""!\n"); |
688 | 688 |
return CL_EFORMAT; |
689 | 689 |
} |
690 |
- |
|
691 |
- /* loff conatins the location of the [Content Type].xml ZIP entry */ |
|
692 | 690 |
cli_dbgmsg("cli_process_ooxml: found ""[Content_Types].xml"" @ %x\n", loff); |
693 | 691 |
|
694 |
- ret = unzip_single_internal(ctx, loff, ooxml_content_cb); |
|
692 |
+ return unzip_single_internal(ctx, loff, ooxml_content_cb); |
|
693 |
+#else |
|
694 |
+ cli_dbgmsg("in cli_processooxml\n"); |
|
695 |
+ cli_dbgmsg("cli_process_ooxml: libxml2 needs to enabled!"); |
|
695 | 696 |
return CL_SUCCESS; |
697 |
+#endif |
|
696 | 698 |
} |