/* * Copyright (C) 2010-2013 JPEXS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.jpexs.decompiler.flash.action.swf7; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.parser.*; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; import com.jpexs.decompiler.flash.helpers.Helper; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ActionTry extends Action { public boolean catchInRegisterFlag; public boolean finallyBlockFlag; public boolean catchBlockFlag; public String catchName; public int catchRegister; public List tryBody; public List catchBody; public List finallyBody; public ActionTry(int actionLength, SWFInputStream sis, int version) throws IOException { super(0x8F, actionLength); sis.readUB(5); catchInRegisterFlag = sis.readUB(1) == 1; finallyBlockFlag = sis.readUB(1) == 1; catchBlockFlag = sis.readUB(1) == 1; int trySize = sis.readUI16(); int catchSize = sis.readUI16(); int finallySize = sis.readUI16(); if (catchInRegisterFlag) { catchRegister = sis.readUI8(); } else { catchName = sis.readString(); } byte tryBodyBytes[] = sis.readBytes(trySize); byte catchBodyBytes[] = sis.readBytes(catchSize); byte finallyBodyBytes[] = sis.readBytes(finallySize); tryBody = (new SWFInputStream(new ByteArrayInputStream(tryBodyBytes), version)).readActionList(); catchBody = (new SWFInputStream(new ByteArrayInputStream(catchBodyBytes), version)).readActionList(); finallyBody = (new SWFInputStream(new ByteArrayInputStream(finallyBodyBytes), version)).readActionList(); } @Override public void setAddress(long address, int version) { super.setAddress(address, version); ByteArrayOutputStream baos = new ByteArrayOutputStream(); SWFOutputStream sos = new SWFOutputStream(baos, version); try { sos.writeUB(5, 0); sos.writeUB(1, catchInRegisterFlag ? 1 : 0); sos.writeUB(1, finallyBlockFlag ? 1 : 0); sos.writeUB(1, catchBlockFlag ? 1 : 0); byte tryBodyBytes[] = Action.actionsToBytes(tryBody, false, version); byte catchBodyBytes[] = Action.actionsToBytes(catchBody, false, version); byte finallyBodyBytes[] = Action.actionsToBytes(finallyBody, false, version); sos.writeUI16(tryBodyBytes.length); sos.writeUI16(catchBodyBytes.length); sos.writeUI16(finallyBodyBytes.length); if (catchInRegisterFlag) { sos.writeUI8(catchRegister); } else { sos.writeString(catchName); } Action.setActionsAddresses(tryBody, address + baos.toByteArray().length, version); sos.write(tryBodyBytes); Action.setActionsAddresses(catchBody, address + baos.toByteArray().length, version); sos.write(catchBodyBytes); Action.setActionsAddresses(finallyBody, address + baos.toByteArray().length, version); sos.close(); } catch (IOException e) { } } @Override public byte[] getBytes(int version) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); SWFOutputStream sos = new SWFOutputStream(baos, version); try { sos.writeUB(5, 0); sos.writeUB(1, catchInRegisterFlag ? 1 : 0); sos.writeUB(1, finallyBlockFlag ? 1 : 0); sos.writeUB(1, catchBlockFlag ? 1 : 0); byte tryBodyBytes[] = Action.actionsToBytes(tryBody, false, version); byte catchBodyBytes[] = Action.actionsToBytes(catchBody, false, version); byte finallyBodyBytes[] = Action.actionsToBytes(finallyBody, false, version); sos.writeUI16(tryBodyBytes.length); sos.writeUI16(catchBodyBytes.length); sos.writeUI16(finallyBodyBytes.length); if (catchInRegisterFlag) { sos.writeUI8(catchRegister); } else { sos.writeString(catchName); } sos.write(tryBodyBytes); sos.write(catchBodyBytes); sos.write(finallyBodyBytes); sos.close(); } catch (IOException e) { } return surroundWithAction(baos.toByteArray(), version); } public ActionTry(boolean ignoreNops, List