flash.swf.DebugDecoder Maven / Gradle / Ivy
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package flash.swf;
import flash.swf.debug.DebugModule;
import flash.swf.debug.LineRecord;
import flash.swf.debug.RegisterRecord;
import flash.swf.types.FlashUUID;
import flash.util.FileUtils;
import flash.util.IntMap;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.util.ArrayList;
import java.net.MalformedURLException;
import java.net.URL;
/**
* The swd file format is as follows
*
* swd(header) (tag)*
*/
public class DebugDecoder
{
public static final int
kDebugScript=0,
kDebugOffset=1,
kDebugBreakpoint=2,
kDebugID=3,
kDebugRegisters=5
;
/**
* table of line numbers, indexed by offset in the SWF file
*/
private SwfDecoder in;
private IntMap modules = new IntMap();
public DebugDecoder(byte[] b)
{
this(new ByteArrayInputStream(b));
}
public DebugDecoder(InputStream in)
{
this.in = new SwfDecoder(in, 0);
}
public void readSwd(DebugHandler h) throws IOException
{
readHeader(h);
readTags(h);
}
void readHeader(DebugHandler handler) throws IOException
{
byte[] sig = new byte[4];
in.readFully(sig);
if (sig[0] != 'F' || sig[1] != 'W' || sig[2] != 'D' || sig[3] < 6)
{
throw new SwfFormatException("not a Flash 6 or later SWD file");
}
in.swfVersion = sig[3];
handler.header(in.swfVersion);
}
public void setTagData(byte[] b) throws IOException
{
in = new SwfDecoder(b, 0);
}
public void readTags(DebugHandler handler) throws IOException
{
//