From 913b3f22e3c5fc7e1c3c46d8c5982b14e0e9bf82 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sat, 2 May 2015 20:21:36 +0200 Subject: [PATCH 1/6] show error message when offset is too large --- .../decompiler/flash/SWFOutputStream.java | 39 ++++++++++-- .../flash/action/ActionListReader.java | 6 +- .../flash/action/parser/pcode/ASMParser.java | 59 ++++++++++++++++--- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java index e739f8361..eb82cc566 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -153,11 +153,15 @@ public class SWFOutputStream extends OutputStream { /** * Writes UI8 (Unsigned 8bit integer) value to the stream * - * @param val UI8 value to write + * @param value UI8 value to write * @throws IOException */ - public void writeUI8(int val) throws IOException { - write(val); + public void writeUI8(int value) throws IOException { + if (value > 0xff) { + throw new Error("Value is too large for UI8: " + value); + } + + write(value); } /** @@ -167,7 +171,14 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeString(String value) throws IOException { - write(Utf8Helper.getBytes(value)); + byte[] data = Utf8Helper.getBytes(value); + for (int i = 0; i < data.length; i++) { + if (data[i] == 0) { + throw new IOException("String should not contain null character."); + } + } + + write(data); write(0); } @@ -178,6 +189,10 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeUI32(long value) throws IOException { + if (value > 0xffffffffL) { + throw new Error("Value is too large for UI32: " + value); + } + write((int) (value & 0xff)); write((int) ((value >> 8) & 0xff)); write((int) ((value >> 16) & 0xff)); @@ -191,6 +206,10 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeUI16(int value) throws IOException { + if (value > 0xffff) { + throw new Error("Value is too large for UI16: " + value); + } + write((int) (value & 0xff)); write((int) ((value >> 8) & 0xff)); } @@ -202,6 +221,10 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeSI32(long value) throws IOException { + if (value > 0x7fffffffL) { + throw new Error("Value is too large for SI32: " + value); + } + writeUI32(value); } @@ -212,6 +235,10 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeSI16(int value) throws IOException { + if (value > 0x7fff) { + throw new Error("Value is too large for SI16: " + value); + } + writeUI16(value); } @@ -222,6 +249,10 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeSI8(int value) throws IOException { + if (value > 0x7ff) { + throw new Error("Value is too large for SI8: " + value); + } + writeUI8(value); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index 78a09459e..ef9290aac 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * 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 3.0 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. */ diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java index 569ce320a..6beabfc79 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * 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 3.0 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. */ package com.jpexs.decompiler.flash.action.parser.pcode; @@ -128,14 +128,16 @@ import com.jpexs.helpers.Helper; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; public class ASMParser { - public static ActionList parse(boolean ignoreNops, List