Browse code

ooxml: added process of locating property files ooxml: added property file specific callbacks

Kevin Lin authored on 2014/05/01 06:36:11
Showing 1 changed files
... ...
@@ -666,12 +666,24 @@ static int unzip_search(cli_ctx *ctx, const char *name, size_t nlen, uint32_t *l
666 666
     return ret;
667 667
 }
668 668
 
669
+static int ooxml_core_cb(int fd, cli_ctx *ctx)
670
+{
671
+    cli_dbgmsg("in ooxml_core_cb\n");
672
+}
673
+
674
+static int ooxml_extn_cb(int fd, cli_ctx *ctx)
675
+{
676
+    cli_dbgmsg("in ooxml_extn_cb\n");
677
+}
678
+
669 679
 static int ooxml_content_cb(int fd, cli_ctx *ctx)
670 680
 {
671 681
 #if HAVE_LIBXML2
672
-    int tmp, i, ret = CL_SUCCESS;
673
-    const xmlChar *name, *value;
682
+    int ret = CL_SUCCESS;
683
+    int core=0, extn=0, cust=0;
684
+    const xmlChar *name, *value, *CT, *PN;
674 685
     xmlTextReaderPtr reader = NULL;
686
+    uint32_t loff;
675 687
 
676 688
     cli_dbgmsg("in ooxml_content_cb\n");
677 689
 
... ...
@@ -690,16 +702,73 @@ static int ooxml_content_cb(int fd, cli_ctx *ctx)
690 690
 
691 691
         if (!xmlTextReaderHasAttributes(reader)) continue;
692 692
 
693
+        CT = NULL; PN = NULL;
693 694
         while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
694 695
             name = xmlTextReaderConstLocalName(reader);
695 696
             value = xmlTextReaderConstValue(reader);
696 697
             if (name == NULL || value == NULL) continue;
697 698
 
699
+            if (!xmlStrcmp(name, "ContentType")) {
700
+                CT = value;
701
+            }
702
+            else if (!xmlStrcmp(name, "PartName")) {
703
+                PN = value;
704
+            }
705
+
698 706
             cli_dbgmsg("%s: %s\n", name, value);
699 707
         }
708
+
709
+        if (!CT && !PN) continue;
710
+
711
+        if (!core && !xmlStrcmp(CT, "application/vnd.openxmlformats-package.core-properties+xml")) {
712
+            /* default: /docProps/core.xml*/
713
+            if (unzip_search(ctx, PN+1, xmlStrlen(PN)-1, &loff) != CL_VIRUS) {
714
+                cli_dbgmsg("cli_process_ooxml: failed to find core properties file \"%s\"!\n", PN);
715
+            }
716
+            else {
717
+                cli_dbgmsg("ooxml_content_cb: found core properties file \"%s\" @ %x\n", PN, loff);
718
+                ret = unzip_single_internal(ctx, loff, ooxml_core_cb);
719
+            }
720
+            core = 1;
721
+        }
722
+        else if (!extn && !xmlStrcmp(CT, "application/vnd.openxmlformats-officedocument.extended-properties+xml")) {
723
+            /* default: /docProps/app.xml */
724
+            if (unzip_search(ctx, PN+1, xmlStrlen(PN)-1, &loff) != CL_VIRUS) {
725
+                cli_dbgmsg("cli_process_ooxml: failed to find extended properties file \"%s\"!\n", PN);
726
+            }
727
+            else {
728
+                cli_dbgmsg("ooxml_content_cb: found extended properties file \"%s\" @ %x\n", PN, loff);
729
+                ret = unzip_single_internal(ctx, loff, ooxml_extn_cb);
730
+            }
731
+            extn = 1;
732
+        }
733
+        else if (!cust && !xmlStrcmp(CT, "application/vnd.openxmlformats-officedocument.custom-properties+xml")) {
734
+            /* default: /docProps/custom.xml */
735
+            if (unzip_search(ctx, PN+1, xmlStrlen(PN)-1, &loff) != CL_VIRUS) {
736
+                cli_dbgmsg("cli_process_ooxml: failed to find custom properties file \"%s\"!\n", PN);
737
+            }
738
+            else {
739
+                cli_dbgmsg("ooxml_content_cb: found custom properties file \"%s\" @ %x\n", PN, loff);
740
+                /* custom properties ignored for now */
741
+            }
742
+            cust = 1;
743
+        }
744
+
745
+        if (ret != CL_SUCCESS)
746
+            goto ooxml_content_exit;
747
+    }
748
+
749
+    if (!core) {
750
+        cli_dbgmsg("cli_process_ooxml: file does not contain core properties file\n");
751
+    }
752
+    if (!extn) {
753
+        cli_dbgmsg("cli_process_ooxml: file does not contain extended properties file\n");
754
+    }
755
+    if (!cust) {
756
+        cli_dbgmsg("cli_process_ooxml: file does not contain custom properties file\n");
700 757
     }
701 758
 
702
- oocml_content_exit:
759
+ ooxml_content_exit:
703 760
     xmlTextReaderClose(reader);
704 761
     xmlFreeTextReader(reader);
705 762
     return ret;