[Swfdec-commits] 2 commits - test/trace vivified/code
Benjamin Otte
company at kemper.freedesktop.org
Mon Apr 21 08:34:23 PDT 2008
test/trace/Makefile.am | 9
test/trace/same-argument-name-5.swf |binary
test/trace/same-argument-name-5.swf.trace | 1
test/trace/same-argument-name-6.swf |binary
test/trace/same-argument-name-6.swf.trace | 1
test/trace/same-argument-name-7.swf |binary
test/trace/same-argument-name-7.swf.trace | 1
test/trace/same-argument-name-8.swf |binary
test/trace/same-argument-name-8.swf.trace | 1
test/trace/same-argument-name.as | 8
vivified/code/Makefile.am | 2
vivified/code/vivi_code_asm_function2.c | 291 ++++++++++++++++++++++++++++++
vivified/code/vivi_code_asm_function2.h | 81 ++++++++
vivified/code/vivi_disassembler.c | 32 +++
14 files changed, 426 insertions(+), 1 deletion(-)
New commits:
commit ee3b593c3b43e66048771483283f2d45b6a54b56
Author: Benjamin Otte <otte at gnome.org>
Date: Mon Apr 21 17:30:22 2008 +0200
disassemble DefineFunction2
diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index a04e1f3..a54e680 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -21,6 +21,7 @@ libvivified_compiler_la_SOURCES = \
vivi_code_asm_code.c \
vivi_code_asm_code_default.c \
vivi_code_asm_function.c \
+ vivi_code_asm_function2.c \
vivi_code_asm_if.c \
vivi_code_asm_jump.c \
vivi_code_asm_pool.c \
@@ -91,6 +92,7 @@ noinst_HEADERS = \
vivi_code_asm_code.h \
vivi_code_asm_code_default.h \
vivi_code_asm_function.h \
+ vivi_code_asm_function2.h \
vivi_code_asm_if.h \
vivi_code_asm_jump.h \
vivi_code_asm_pool.h \
diff --git a/vivified/code/vivi_code_asm_function2.c b/vivified/code/vivi_code_asm_function2.c
new file mode 100644
index 0000000..142f512
--- /dev/null
+++ b/vivified/code/vivi_code_asm_function2.c
@@ -0,0 +1,291 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <swfdec/swfdec_as_interpret.h>
+#include <swfdec/swfdec_bits.h>
+#include <swfdec/swfdec_script_internal.h>
+
+#include "vivi_code_asm_function2.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_emitter.h"
+#include "vivi_code_error.h"
+#include "vivi_code_printer.h"
+
+static gboolean
+vivi_code_asm_function2_resolve (ViviCodeEmitter *emitter, SwfdecBuffer *buffer,
+ gpointer data, GError **error)
+{
+ /* FIXME: write */
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+vivi_code_asm_function2_emit (ViviCodeAsm *code, ViviCodeEmitter *emitter, GError **error)
+{
+ ViviCodeAsmFunction2 *fun = VIVI_CODE_ASM_FUNCTION2 (code);
+ SwfdecBots *emit = vivi_code_emitter_get_bots (emitter);
+ SwfdecBots *bots;
+ guint i, len;
+
+ bots = swfdec_bots_open ();
+ swfdec_bots_put_string (bots, fun->name ? fun->name : "");
+ swfdec_bots_put_u16 (bots, fun->args->len);
+ swfdec_bots_put_u8 (bots, fun->n_registers);
+ swfdec_bots_put_u16 (bots, fun->flags);
+ for (i = 0; i < fun->args->len; i++) {
+ SwfdecScriptArgument *arg = &g_array_index (fun->args, SwfdecScriptArgument, i);
+ swfdec_bots_put_u8 (bots, arg->preload);
+ swfdec_bots_put_string (bots, arg->name);
+ }
+ swfdec_bots_put_u16 (bots, 0); /* length of body, to be resolved later */
+
+ len = swfdec_bots_get_bytes (bots);
+ if (len > G_MAXUINT16) {
+ g_set_error (error, VIVI_CODE_ERROR, VIVI_CODE_ERROR_SIZE,
+ "DeclareFunction2 action too big");
+ swfdec_bots_free (bots);
+ return FALSE;
+ }
+
+ swfdec_bots_put_u8 (emit, SWFDEC_AS_ACTION_DEFINE_FUNCTION2);
+ swfdec_bots_put_u16 (emit, len);
+ swfdec_bots_put_bots (emit, bots);
+ vivi_code_emitter_add_later (emitter, vivi_code_asm_function2_resolve, fun);
+ swfdec_bots_free (bots);
+
+ return TRUE;
+}
+
+static void
+vivi_code_asm_function2_asm_init (ViviCodeAsmInterface *iface)
+{
+ iface->emit = vivi_code_asm_function2_emit;
+}
+
+G_DEFINE_TYPE_WITH_CODE (ViviCodeAsmFunction2, vivi_code_asm_function2, VIVI_TYPE_CODE_ASM_CODE,
+ G_IMPLEMENT_INTERFACE (VIVI_TYPE_CODE_ASM, vivi_code_asm_function2_asm_init))
+
+/* FIXME: export for compiler */
+static const char *flag_names[16] = {
+ "preload_this",
+ "suppress_this",
+ "preload_args",
+ "suppress_args",
+ "preload_super",
+ "suppress_super",
+ "preload_root",
+ "preload_parent",
+ "preload_global",
+ "reserved1",
+ "reserved2",
+ "reserved3",
+ "reserved4",
+ "reserved5",
+ "reserved6",
+ "reserved7"
+};
+
+static void
+vivi_code_asm_function2_print (ViviCodeToken *token, ViviCodePrinter*printer)
+{
+ ViviCodeAsmFunction2 *fun = VIVI_CODE_ASM_FUNCTION2 (token);
+ guint i;
+
+ vivi_code_printer_print (printer, "function2 ");
+ if (fun->name) {
+ char *s = vivi_code_escape_string (fun->name);
+ vivi_code_printer_print (printer, s);
+ vivi_code_printer_print (printer, " ");
+ g_free (s);
+ }
+ if (fun->n_registers) {
+ char *s = g_strdup_printf ("%u", fun->n_registers);
+ vivi_code_printer_print (printer, s);
+ vivi_code_printer_print (printer, " ");
+ g_free (s);
+ }
+ for (i = 0; i < G_N_ELEMENTS (flag_names); i++) {
+ if (fun->flags & (1 << i)) {
+ vivi_code_printer_print (printer, flag_names[i]);
+ vivi_code_printer_print (printer, " ");
+ }
+ }
+ for (i = 0; i < fun->args->len; i++) {
+ SwfdecScriptArgument *arg = &g_array_index (fun->args, SwfdecScriptArgument, i);
+ if (i == 0)
+ vivi_code_printer_print (printer, "(");
+ else
+ vivi_code_printer_print (printer, ", ");
+ /* FIXME: escape this? */
+ vivi_code_printer_print (printer, arg->name);
+ if (arg->preload) {
+ char *s = g_strdup_printf ("%u", arg->preload);
+ vivi_code_printer_print (printer, " ");
+ vivi_code_printer_print (printer, s);
+ g_free (s);
+ }
+ }
+ if (i > 0)
+ vivi_code_printer_print (printer, ") ");
+ vivi_code_printer_print (printer, vivi_code_label_get_name (fun->label));
+ vivi_code_printer_new_line (printer, FALSE);
+}
+
+static void
+vivi_code_asm_function2_dispose (GObject *object)
+{
+ ViviCodeAsmFunction2 *fun = VIVI_CODE_ASM_FUNCTION2 (object);
+ guint i;
+
+ for (i = 0; i < fun->args->len; i++) {
+ g_free (g_array_index (fun->args, SwfdecScriptArgument, i).name);
+ }
+ g_array_free (fun->args, TRUE);
+ g_free (fun->name);
+ g_object_unref (fun->label);
+
+ G_OBJECT_CLASS (vivi_code_asm_function2_parent_class)->dispose (object);
+}
+
+static void
+vivi_code_asm_function2_class_init (ViviCodeAsmFunction2Class *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ ViviCodeTokenClass *token_class = VIVI_CODE_TOKEN_CLASS (klass);
+ ViviCodeAsmCodeClass *code_class = VIVI_CODE_ASM_CODE_CLASS (klass);
+
+ object_class->dispose = vivi_code_asm_function2_dispose;
+
+ token_class->print = vivi_code_asm_function2_print;
+
+ code_class->bytecode = SWFDEC_AS_ACTION_DEFINE_FUNCTION2;
+}
+
+static void
+vivi_code_asm_function2_init (ViviCodeAsmFunction2 *fun)
+{
+ fun->args = g_array_new (FALSE, FALSE, sizeof (SwfdecScriptArgument));
+}
+
+ViviCodeAsm *
+vivi_code_asm_function2_new (ViviCodeLabel *label, const char *name,
+ guint n_registers, guint flags)
+{
+ ViviCodeAsmFunction2 *fun;
+
+ g_return_val_if_fail (VIVI_IS_CODE_LABEL (label), NULL);
+ g_return_val_if_fail (n_registers < 256, NULL);
+ g_return_val_if_fail (flags <= G_MAXUINT16, NULL);
+
+ fun= g_object_new (VIVI_TYPE_CODE_ASM_FUNCTION2, NULL);
+ fun->label = g_object_ref (label);
+ fun->name = g_strdup (name);
+ fun->n_registers = n_registers;
+ fun->flags = flags;
+
+ return VIVI_CODE_ASM (fun);
+}
+
+ViviCodeLabel *
+vivi_code_asm_function2_get_label (ViviCodeAsmFunction2 *fun)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), NULL);
+
+ return fun->label;
+}
+
+void
+vivi_code_asm_function2_set_label (ViviCodeAsmFunction2 *fun, ViviCodeLabel *label)
+{
+ g_return_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun));
+ g_return_if_fail (VIVI_IS_CODE_LABEL (label));
+
+ g_object_ref (label);
+ g_object_unref (fun->label);
+ fun->label = label;
+}
+
+const char *
+vivi_code_asm_function2_get_name (ViviCodeAsmFunction2 *fun)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), NULL);
+
+ return fun->name;
+}
+
+guint
+vivi_code_asm_function2_get_flags (ViviCodeAsmFunction2 *fun)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), 0);
+
+ return fun->flags;
+}
+
+guint
+vivi_code_asm_function2_get_n_registers (ViviCodeAsmFunction2 *fun)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), 0);
+
+ return fun->n_registers;
+}
+
+guint
+vivi_code_asm_function2_get_n_arguments (ViviCodeAsmFunction2 *fun)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), 0);
+
+ return fun->args->len;
+}
+
+const char *
+vivi_code_asm_function2_get_argument_name (ViviCodeAsmFunction2 *fun, guint i)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), NULL);
+ g_return_val_if_fail (i < fun->args->len, NULL);
+
+ return g_array_index (fun->args, SwfdecScriptArgument, i).name;
+}
+
+guint
+vivi_code_asm_function2_get_argument_preload (ViviCodeAsmFunction2 *fun, guint i)
+{
+ g_return_val_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun), 0);
+ g_return_val_if_fail (i < fun->args->len, 0);
+
+ return g_array_index (fun->args, SwfdecScriptArgument, i).preload;
+}
+
+void
+vivi_code_asm_function2_add_argument (ViviCodeAsmFunction2 *fun,
+ const char *name, guint preload)
+{
+ SwfdecScriptArgument arg;
+
+ g_return_if_fail (VIVI_IS_CODE_ASM_FUNCTION2 (fun));
+ g_return_if_fail (fun->args->len < G_MAXUINT16);
+ g_return_if_fail (name != NULL);
+
+ arg.preload = preload;
+ arg.name = g_strdup (name);
+ g_array_append_val (fun->args, arg);
+}
diff --git a/vivified/code/vivi_code_asm_function2.h b/vivified/code/vivi_code_asm_function2.h
new file mode 100644
index 0000000..2c921f8
--- /dev/null
+++ b/vivified/code/vivi_code_asm_function2.h
@@ -0,0 +1,81 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef _VIVI_CODE_ASM_FUNCTION2_H_
+#define _VIVI_CODE_ASM_FUNCTION2_H_
+
+#include <vivified/code/vivi_code_asm.h>
+#include <vivified/code/vivi_code_asm_code.h>
+#include <vivified/code/vivi_code_label.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ViviCodeAsmFunction2 ViviCodeAsmFunction2;
+typedef struct _ViviCodeAsmFunction2Class ViviCodeAsmFunction2Class;
+
+#define VIVI_TYPE_CODE_ASM_FUNCTION2 (vivi_code_asm_function2_get_type())
+#define VIVI_IS_CODE_ASM_FUNCTION2(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_ASM_FUNCTION2))
+#define VIVI_IS_CODE_ASM_FUNCTION2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_ASM_FUNCTION2))
+#define VIVI_CODE_ASM_FUNCTION2(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_ASM_FUNCTION2, ViviCodeAsmFunction2))
+#define VIVI_CODE_ASM_FUNCTION2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_ASM_FUNCTION2, ViviCodeAsmFunction2Class))
+#define VIVI_CODE_ASM_FUNCTION2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_ASM_FUNCTION2, ViviCodeAsmFunction2Class))
+
+struct _ViviCodeAsmFunction2
+{
+ ViviCodeAsmCode code;
+
+ char * name;
+ guint flags;
+ guint n_registers;
+ GArray * args;
+ ViviCodeLabel * label;
+};
+
+struct _ViviCodeAsmFunction2Class
+{
+ ViviCodeAsmCodeClass code_class;
+};
+
+GType vivi_code_asm_function2_get_type (void);
+
+ViviCodeAsm * vivi_code_asm_function2_new (ViviCodeLabel * label,
+ const char * name,
+ guint n_registers,
+ guint flags);
+
+ViviCodeLabel * vivi_code_asm_function2_get_label (ViviCodeAsmFunction2 * fun);
+void vivi_code_asm_function2_set_label (ViviCodeAsmFunction2 * fun,
+ ViviCodeLabel * label);
+const char * vivi_code_asm_function2_get_name (ViviCodeAsmFunction2 * fun);
+guint vivi_code_asm_function2_get_flags (ViviCodeAsmFunction2 * fun);
+guint vivi_code_asm_function2_get_n_registers (ViviCodeAsmFunction2 * fun);
+guint vivi_code_asm_function2_get_n_arguments (ViviCodeAsmFunction2 * fun);
+const char * vivi_code_asm_function2_get_argument_name
+ (ViviCodeAsmFunction2 * fun,
+ guint i);
+guint vivi_code_asm_function2_get_argument_preload
+ (ViviCodeAsmFunction2 * fun,
+ guint i);
+void vivi_code_asm_function2_add_argument (ViviCodeAsmFunction2 * fun,
+ const char * name,
+ guint preload);
+
+
+G_END_DECLS
+#endif
diff --git a/vivified/code/vivi_disassembler.c b/vivified/code/vivi_disassembler.c
index a8e5ef9..afeebe0 100644
--- a/vivified/code/vivi_disassembler.c
+++ b/vivified/code/vivi_disassembler.c
@@ -28,6 +28,7 @@
#include "vivi_decompiler.h"
#include "vivi_code_asm_code_default.h"
#include "vivi_code_asm_function.h"
+#include "vivi_code_asm_function2.h"
#include "vivi_code_asm_if.h"
#include "vivi_code_asm_jump.h"
#include "vivi_code_asm_pool.h"
@@ -321,6 +322,36 @@ vivi_disassemble_script (SwfdecScript *script)
g_object_unref (fun);
}
break;
+ case SWFDEC_AS_ACTION_DEFINE_FUNCTION2:
+ {
+ char *name, *s;
+ ViviCodeLabel *label;
+ ViviCodeAsm *fun;
+ guint i, n_args, n_regs, flags;
+
+ name = swfdec_bits_get_string (&bits, script->version);
+ n_args = swfdec_bits_get_u16 (&bits);
+ n_regs = swfdec_bits_get_u8 (&bits);
+ flags = swfdec_bits_get_u16 (&bits);
+ /* FIXME: need a temporary label until we lookup the real one */
+ label = VIVI_CODE_LABEL (vivi_code_label_new ("whoops"));
+ fun = vivi_code_asm_function2_new (label, name && *name ? name : NULL, n_regs, flags);
+ g_object_unref (label);
+ g_free (name);
+ for (i = 0; i < n_args; i++) {
+ flags = swfdec_bits_get_u8 (&bits);
+ s = swfdec_bits_get_string (&bits, script->version);
+ vivi_code_asm_function2_add_argument (VIVI_CODE_ASM_FUNCTION2 (fun),
+ s, flags);
+ g_free (s);
+ }
+ label = vivi_disassemble_labels_get_label (labels,
+ pc + swfdec_bits_get_u16 (&bits));
+ vivi_code_asm_function2_set_label (VIVI_CODE_ASM_FUNCTION2 (fun), label);
+ vivi_code_assembler_add_code (assembler, fun);
+ g_object_unref (fun);
+ }
+ break;
case SWFDEC_AS_ACTION_GOTO_FRAME:
case SWFDEC_AS_ACTION_GET_URL:
case SWFDEC_AS_ACTION_STRICT_MODE:
@@ -328,7 +359,6 @@ vivi_disassemble_script (SwfdecScript *script)
case SWFDEC_AS_ACTION_SET_TARGET:
case SWFDEC_AS_ACTION_GOTO_LABEL:
case SWFDEC_AS_ACTION_WAIT_FOR_FRAME2:
- case SWFDEC_AS_ACTION_DEFINE_FUNCTION2:
case SWFDEC_AS_ACTION_TRY:
case SWFDEC_AS_ACTION_WITH:
case SWFDEC_AS_ACTION_GET_URL2:
commit 7e3700527deeb0c894706bce9178ad94d3960d49
Author: Benjamin Otte <otte at gnome.org>
Date: Mon Apr 21 15:46:31 2008 +0200
add a test for how 2 arguments with the same name are treated
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 0b8b0d7..2628d50 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -2534,6 +2534,15 @@ EXTRA_DIST = \
round-direction-7.swf.trace \
round-direction-8.swf \
round-direction-8.swf.trace \
+ same-argument-name-5.swf \
+ same-argument-name-5.swf.trace \
+ same-argument-name-6.swf \
+ same-argument-name-6.swf.trace \
+ same-argument-name-7.swf \
+ same-argument-name-7.swf.trace \
+ same-argument-name-8.swf \
+ same-argument-name-8.swf.trace \
+ same-argument-name.as \
scalemode.as \
scalemode-5.swf \
scalemode-5.swf.trace \
diff --git a/test/trace/same-argument-name-5.swf b/test/trace/same-argument-name-5.swf
new file mode 100644
index 0000000..7fc486e
Binary files /dev/null and b/test/trace/same-argument-name-5.swf differ
diff --git a/test/trace/same-argument-name-5.swf.trace b/test/trace/same-argument-name-5.swf.trace
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/trace/same-argument-name-5.swf.trace
@@ -0,0 +1 @@
+2
diff --git a/test/trace/same-argument-name-6.swf b/test/trace/same-argument-name-6.swf
new file mode 100644
index 0000000..bab96c4
Binary files /dev/null and b/test/trace/same-argument-name-6.swf differ
diff --git a/test/trace/same-argument-name-6.swf.trace b/test/trace/same-argument-name-6.swf.trace
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/trace/same-argument-name-6.swf.trace
@@ -0,0 +1 @@
+2
diff --git a/test/trace/same-argument-name-7.swf b/test/trace/same-argument-name-7.swf
new file mode 100644
index 0000000..80f3174
Binary files /dev/null and b/test/trace/same-argument-name-7.swf differ
diff --git a/test/trace/same-argument-name-7.swf.trace b/test/trace/same-argument-name-7.swf.trace
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/trace/same-argument-name-7.swf.trace
@@ -0,0 +1 @@
+2
diff --git a/test/trace/same-argument-name-8.swf b/test/trace/same-argument-name-8.swf
new file mode 100644
index 0000000..2218294
Binary files /dev/null and b/test/trace/same-argument-name-8.swf differ
diff --git a/test/trace/same-argument-name-8.swf.trace b/test/trace/same-argument-name-8.swf.trace
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/test/trace/same-argument-name-8.swf.trace
@@ -0,0 +1 @@
+2
diff --git a/test/trace/same-argument-name.as b/test/trace/same-argument-name.as
new file mode 100644
index 0000000..93ac771
--- /dev/null
+++ b/test/trace/same-argument-name.as
@@ -0,0 +1,8 @@
+// makeswf -v 7 -s 200x150 -r 1 -o same-argument-name.swf same-argument-name.as
+
+function foo (x, x) {
+ trace (x);
+};
+foo (1, 2);
+
+getURL ("fscommand:quit", "");
More information about the Swfdec-commits
mailing list