libgsf r996 - in trunk: . gsf tools
- From: jody svn gnome org
- To: svn-commits-list gnome org
- Subject: libgsf r996 - in trunk: . gsf tools
- Date: Mon, 25 Aug 2008 01:00:13 +0000 (UTC)
Author: jody
Date: Mon Aug 25 01:00:13 2008
New Revision: 996
URL: http://svn.gnome.org/viewvc/libgsf?rev=996&view=rev
Log:
2008-08-24 Jody Goldberg <jody gnome org>
* gsf/gsf-infile-msvba.c (gsf_input_find_vba) : move this here from
tools/gsf-vba-dump.
(gsf_infile_msvba_get_modules) : new.
(vba_extract_module_source) : store the code rather than dumping it to stdout.
* tools/gsf-vba-dump.c (test) : use the new utilities.
(cb_dump_vba) : do the dumping here.
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/gsf/gsf-infile-ar.c
trunk/gsf/gsf-infile-msole.c
trunk/gsf/gsf-infile-msvba.c
trunk/gsf/gsf-infile-msvba.h
trunk/gsf/gsf-infile-zip.c
trunk/gsf/gsf-libxml.c
trunk/gsf/gsf-open-pkg-utils.c
trunk/gsf/gsf-structured-blob.c
trunk/gsf/gsf-zip-utils.c
trunk/tools/gsf-vba-dump.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Mon Aug 25 01:00:13 2008
@@ -9,6 +9,7 @@
* Be more forgiving of corrupt ole2.
* Add additional MS OpenPkg support to facilitate pivots.
* gtk-doc improvements.
+ * Make the VBA extractor more accessible.
Morten:
* Use g_base64_-routines from glib when available.
Modified: trunk/gsf/gsf-infile-ar.c
==============================================================================
--- trunk/gsf/gsf-infile-ar.c (original)
+++ trunk/gsf/gsf-infile-ar.c Mon Aug 25 01:00:13 2008
@@ -450,8 +450,8 @@
/**
* gsf_infile_ar_new :
- * @source:
- * @err:
+ * @source: #GsfInput
+ * @err: #Gerror
*
* Opens the root directory of a Ar file.
* <note>This adds a reference to @source.</note>
Modified: trunk/gsf/gsf-infile-msole.c
==============================================================================
--- trunk/gsf/gsf-infile-msole.c (original)
+++ trunk/gsf/gsf-infile-msole.c Mon Aug 25 01:00:13 2008
@@ -425,15 +425,8 @@
return info;
}
-/**
- * ole_dup:
- * @src:
- *
- * Utility routine to _partially_ replicate a file. It does NOT copy the bat
- * blocks, or init the dirent.
- *
- * Returns: the partial duplicate.
- **/
+/* Utility routine to _partially_ replicate a file. It does NOT copy the bat
+ * blocks, or init the dirent. */
static GsfInfileMSOle *
ole_dup (GsfInfileMSOle const *src, GError **err)
{
Modified: trunk/gsf/gsf-infile-msvba.c
==============================================================================
--- trunk/gsf/gsf-infile-msvba.c (original)
+++ trunk/gsf/gsf-infile-msvba.c Mon Aug 25 01:00:13 2008
@@ -33,6 +33,9 @@
#include <gsf/gsf-input-memory.h>
#include <gsf/gsf-impl-utils.h>
#include <gsf/gsf-msole-utils.h>
+#include <gsf/gsf-infile-msole.h>
+#include <gsf/gsf-infile-zip.h>
+#include <gsf/gsf-open-pkg-utils.h>
#include <gsf/gsf-utils.h>
#include <stdio.h>
@@ -45,6 +48,8 @@
GsfInfile *source;
GList *children;
+
+ GHashTable *modules;
};
typedef GsfInfileClass GsfInfileMSVBAClass;
@@ -67,7 +72,7 @@
vba_extract_module_source (GsfInfileMSVBA *vba, char const *name, guint32 src_offset)
{
GsfInput *module;
- guint8 *src_code;
+ guint8 *code;
int inflated_size;
g_return_if_fail (name != NULL);
@@ -76,15 +81,16 @@
if (module == NULL)
return;
- src_code = gsf_vba_inflate (module, (gsf_off_t) src_offset, &inflated_size, TRUE);
- if (src_code != NULL) {
- printf ("<module name=\"%s\">\n<![CDATA[%s]]>\n</module>\n", name, src_code);
- g_free (src_code);
+ code = gsf_vba_inflate (module, (gsf_off_t) src_offset, &inflated_size, TRUE);
+ if (code != NULL) {
+ if (NULL == vba->modules)
+ vba->modules = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free, (GDestroyNotify)g_free);
+ g_hash_table_insert (vba->modules, g_strdup (name), code);
} else
g_warning ("Problems extracting the source for %s @ %u", name, src_offset);
g_object_unref (module);
- module = NULL;
}
/**
@@ -391,6 +397,10 @@
{
GsfInfileMSVBA *vba = GSF_INFILE_MSVBA (obj);
+ if (NULL != vba->modules) {
+ g_hash_table_destroy (vba->modules);
+ vba->modules = NULL;
+ }
if (vba->source != NULL) {
g_object_unref (G_OBJECT (vba->source));
vba->source = NULL;
@@ -404,6 +414,7 @@
GsfInfileMSVBA *vba = GSF_INFILE_MSVBA (obj);
vba->source = NULL;
+ vba->modules = NULL;
vba->children = NULL;
}
@@ -444,3 +455,87 @@
g_object_unref (G_OBJECT (vba));
return NULL;
}
+
+/**
+ * gsf_infile_msvba_get_modules :
+ * @vba_stream : #GsfInfile
+ *
+ * a collection of names and source code.
+ *
+ * Returns: %NULL, or a hashtable of names and source code (unknown encoding).
+ **/
+GHashTable *
+gsf_infile_msvba_get_modules (GsfInfileMSVBA const *vba_stream)
+{
+ g_return_val_if_fail (GSF_IS_INFILE_MSVBA (vba_stream), NULL);
+ return vba_stream->modules;
+}
+
+/**
+ * gsf_infile_msvba_steal_modules :
+ * @vba_stream : #GsfInfile
+ *
+ * A collection of names and source code which the caller is responsible for destroying.
+ *
+ * Returns: %NULL, or a hashtable of names and source code (unknown encoding).
+ **/
+GHashTable *
+gsf_infile_msvba_steal_modules (GsfInfileMSVBA *vba_stream)
+{
+ GHashTable *res;
+ g_return_val_if_fail (GSF_IS_INFILE_MSVBA (vba_stream), NULL);
+ res = vba_stream->modules;
+ vba_stream->modules = NULL;
+ return res;
+}
+
+/**
+ * gsf_input_find_vba :
+ * @input : #GsfInput
+ * @err : #GError, optionally %NULL.
+ *
+ * A utility routine that attempts to find the VBA file withint a stream.
+ *
+ * Returns: a GsfInfileMSVBA *gsf_input_find_vba (GsfInput *input, GError *err);
+ **/
+GsfInfileMSVBA *
+gsf_input_find_vba (GsfInput *input, GError **err)
+{
+ GsfInput *vba = NULL;
+ GsfInfile *infile;
+
+ if (NULL != (infile = gsf_infile_msole_new (input, NULL))) {
+ /* 1) Try XLS */
+ vba = gsf_infile_child_by_vname (infile, "_VBA_PROJECT_CUR", "VBA", NULL);
+ /* 2) DOC */
+ if (NULL == vba)
+ vba = gsf_infile_child_by_vname (infile, "Macros", "VBA", NULL);
+
+ /* TODO : PPT is more complex */
+
+ g_object_unref (G_OBJECT (infile));
+ } else if (NULL != (infile = gsf_infile_zip_new (input, NULL))) {
+ GsfInput *main_part = gsf_open_pkg_get_rel_by_type (GSF_INPUT (infile),
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
+
+ if (NULL != main_part) {
+ GsfInput *vba_stream = gsf_open_pkg_get_rel_by_type (main_part,
+ "http://schemas.microsoft.com/office/2006/relationships/vbaProject");
+ if (NULL != vba_stream) {
+ GsfInfile *ole = gsf_infile_msole_new (vba_stream, err);
+ if (NULL != ole) {
+ vba = gsf_infile_child_by_vname (ole, "VBA", NULL);
+ g_object_unref (G_OBJECT (ole));
+ }
+ g_object_unref (G_OBJECT (vba_stream));
+ }
+ g_object_unref (G_OBJECT (main_part));
+ }
+ g_object_unref (G_OBJECT (infile));
+ }
+
+ if (NULL != vba)
+ return (GsfInfileMSVBA *)
+ gsf_infile_msvba_new (GSF_INFILE (vba), err);
+ return NULL;
+}
Modified: trunk/gsf/gsf-infile-msvba.h
==============================================================================
--- trunk/gsf/gsf-infile-msvba.h (original)
+++ trunk/gsf/gsf-infile-msvba.h Mon Aug 25 01:00:13 2008
@@ -36,7 +36,12 @@
GType gsf_infile_msvba_get_type (void) G_GNUC_CONST;
/* void gsf_infile_msvba_register_type (GTypeModule *module); glib dynamic types are not thread safe */
-GsfInfile *gsf_infile_msvba_new (GsfInfile *source, GError **err);
+GsfInfile *gsf_infile_msvba_new (GsfInfile *source, GError **err);
+GHashTable *gsf_infile_msvba_get_modules (GsfInfileMSVBA const *vba_stream);
+GHashTable *gsf_infile_msvba_steal_modules (GsfInfileMSVBA *vba_stream);
+
+/* Utility */
+GsfInfileMSVBA *gsf_input_find_vba (GsfInput *input, GError **err);
G_END_DECLS
Modified: trunk/gsf/gsf-infile-zip.c
==============================================================================
--- trunk/gsf/gsf-infile-zip.c (original)
+++ trunk/gsf/gsf-infile-zip.c Mon Aug 25 01:00:13 2008
@@ -261,12 +261,7 @@
g_free (info);
}
-/**
- * zip_dup :
- * @src :
- *
- * Return value: the partial duplicate.
- **/
+/* Returns a partial duplicate. */
static GsfInfileZip *
zip_dup (GsfInfileZip const *src, GError **err)
{
Modified: trunk/gsf/gsf-libxml.c
==============================================================================
--- trunk/gsf/gsf-libxml.c (original)
+++ trunk/gsf/gsf-libxml.c Mon Aug 25 01:00:13 2008
@@ -371,6 +371,17 @@
return res;
}
+/**
+ * gsf_xmlDocFormatDump :
+ * @output : #GsfOutput
+ * @cur : #xmlDocPtr
+ * @encoding : The encoding to use.
+ * @format : %TRUE to reformat the output.
+ *
+ * Dumps the document @cur into @output.
+ *
+ * Returns: status from xmlSaveFormatFileTo.
+ **/
int
gsf_xmlDocFormatDump (GsfOutput *output, xmlDocPtr cur, char const *encoding,
gboolean format)
@@ -1108,6 +1119,9 @@
* @ns_id : The name space id to check
* @name : The target node name
*
+ * Checks to see if @str is the same as @ns_id::@name with either an explicit
+ * namespace or the current default namespace.
+ *
* Returns: %TRUE if @str == @ns_id:@name according to @state.
**/
gboolean
@@ -1758,6 +1772,14 @@
g_free (tmp);
}
+/**
+ * gsf_xml_out_get_output :
+ * @xout : #GsfXMLOut
+ *
+ * Get the #GsfInput we are parsing from.
+ *
+ * Returns: #GsfInput or %NULL.
+ **/
GsfOutput *
gsf_xml_out_get_output (GsfXMLOut const *xout)
{
Modified: trunk/gsf/gsf-open-pkg-utils.c
==============================================================================
--- trunk/gsf/gsf-open-pkg-utils.c (original)
+++ trunk/gsf/gsf-open-pkg-utils.c Mon Aug 25 01:00:13 2008
@@ -843,7 +843,7 @@
* gsf_outfile_open_pkg_add_rel:
* @dir : #GsfOutfile
* @name : target name
- * @content_type :
+ * @content_type : non-%NULL content type
* @parent : #GsfOutfile
* @type : target type
*
Modified: trunk/gsf/gsf-structured-blob.c
==============================================================================
--- trunk/gsf/gsf-structured-blob.c (original)
+++ trunk/gsf/gsf-structured-blob.c Mon Aug 25 01:00:13 2008
@@ -196,7 +196,10 @@
* gsf_structured_blob_read :
* @input: An input (potentially a GsfInfile) holding the blob
*
- * Returns: a freshly created tree of blobs
+ * Create a tree of binary blobs with unknown content from a #GsfInput or
+ * #GsfInfile and store it in a newly created #GsfStructuredBlob.
+ *
+ * Returns: a new #GsfStructuredBlob object which the caller is responsible for.
**/
GsfStructuredBlob *
gsf_structured_blob_read (GsfInput *input)
Modified: trunk/gsf/gsf-zip-utils.c
==============================================================================
--- trunk/gsf/gsf-zip-utils.c (original)
+++ trunk/gsf/gsf-zip-utils.c Mon Aug 25 01:00:13 2008
@@ -25,6 +25,14 @@
#include <string.h>
#include "gsf-zip-impl.h"
+/**
+ * SECTION:zip
+ * @Short_description: Utilities for reading and writing ZIP/JAR files
+ * @Title: Zip files
+ *
+ * #GsfInfile and #GsfOutfile support for zip files.
+ **/
+
/* Doesn't do much, but include for symmetry */
GsfZipDirent*
gsf_zip_dirent_new (void)
Modified: trunk/tools/gsf-vba-dump.c
==============================================================================
--- trunk/tools/gsf-vba-dump.c (original)
+++ trunk/tools/gsf-vba-dump.c Mon Aug 25 01:00:13 2008
@@ -31,22 +31,15 @@
#include <stdio.h>
static void
-dump_vba (GsfInput *vba, char const *filename, GError **err)
+cb_dump_vba (char const *name, guint8 const *src_code)
{
- GsfInfile *vba_wrapper;
-
- fprintf (stderr, "%s\n", filename);
-
- vba_wrapper = gsf_infile_msvba_new (GSF_INFILE (vba), err);
- if (vba_wrapper != NULL)
- g_object_unref (G_OBJECT (vba_wrapper));
+ printf ("<module name=\"%s\">\n<![CDATA[%s]]>\n</module>\n", name, src_code);
}
static int
test (int argc, char *argv[])
{
- GsfInput *input, *vba;
- GsfInfile *infile;
+ GsfInput *input;
GError *err = NULL;
int i;
@@ -54,50 +47,16 @@
input = gsf_input_mmap_new (argv[i], NULL);
if (input == NULL) /* Only report error if stdio fails too */
input = gsf_input_stdio_new (argv[i], &err);
+
if (input != NULL) {
- if (NULL != (infile = gsf_infile_msole_new (input, &err))) {
- // Try XLS first
- vba = gsf_infile_child_by_vname (infile, "_VBA_PROJECT_CUR", "VBA", NULL);
-
- // Try DOC next
- if (NULL == vba)
- vba = gsf_infile_child_by_vname (infile, "Macros", "VBA", NULL);
-
- // TODO : PPT is more complex
-
- if (vba != NULL) {
- dump_vba (vba, argv[1], &err);
- g_object_unref (G_OBJECT (vba));
- }
- g_object_unref (G_OBJECT (infile));
- } else if (NULL != (infile = gsf_infile_zip_new (input, NULL))) {
- GsfInput *main_part = gsf_open_pkg_get_rel_by_type (GSF_INPUT (infile),
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
- if (NULL != err) {
- g_error_free (err);
- err = NULL;
- }
-
- if (NULL != main_part) {
- GsfInput *vba_stream = gsf_open_pkg_get_rel_by_type (main_part,
- "http://schemas.microsoft.com/office/2006/relationships/vbaProject");
- if (NULL != vba_stream) {
- GsfInfile *ole = gsf_infile_msole_new (vba_stream, &err);
- if (NULL != ole) {
- vba = gsf_infile_child_by_vname (ole, "VBA", NULL);
- if (NULL != vba) {
- dump_vba (vba, argv[1], &err);
- g_object_unref (G_OBJECT (vba));
- }
- g_object_unref (G_OBJECT (ole));
- }
- g_object_unref (G_OBJECT (vba_stream));
- }
- g_object_unref (G_OBJECT (main_part));
- }
- g_object_unref (G_OBJECT (infile));
+ GsfInfileMSVBA *vba = gsf_input_find_vba (input, &err);
+ if (NULL != vba) {
+ GHashTable *modules = gsf_infile_msvba_get_modules (vba);
+ if (NULL != modules)
+ g_hash_table_foreach (modules,
+ (GHFunc) cb_dump_vba, NULL);
+ g_object_unref (G_OBJECT (vba));
}
-
g_object_unref (G_OBJECT (input));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]