diff --git a/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java b/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java index 68d63bab0..abd904590 100644 --- a/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java +++ b/trunk/src/com/jpexs/decompiler/flash/BinarySWFBundle.java @@ -46,8 +46,8 @@ public class BinarySWFBundle implements SWFBundle { @Override public Set getKeys() { Set ret = new HashSet<>(); - for(int i = 0; i < length(); i++){ - ret.add("[" + i + "]"); + for (Long address : search.getAddresses()) { + ret.add("[" + address + "]"); } return ret; } @@ -60,16 +60,11 @@ public class BinarySWFBundle implements SWFBundle { if(!key.endsWith("]")){ return null; } - key = key.substring(1,key.length()-1); - try{ - int index = Integer.parseInt(key); - if(index<0 || index>=length()){ - return null; - } - return search.get(null, index); - }catch(IOException iex){ - return null; - }catch(NumberFormatException nfe){ + key = key.substring(1, key.length() - 1); + try { + int address = Integer.parseInt(key); + return search.get(null, address); + } catch(IOException | NumberFormatException iex){ return null; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java b/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java index f1df4b655..b1d94d3a8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFSearch.java @@ -19,7 +19,6 @@ package com.jpexs.decompiler.flash; import com.jpexs.helpers.MemoryInputStream; import com.jpexs.helpers.PosMarkedInputStream; import com.jpexs.helpers.ProgressListener; -import com.jpexs.helpers.ReReadableInputStream; import com.jpexs.helpers.Searchable; import java.io.IOException; import java.io.InputStream; @@ -39,7 +38,7 @@ public class SWFSearch { protected Searchable s; private boolean processed = false; private final Set listeners = new HashSet<>(); - private final List swfStreams = new ArrayList<>(); + private final Map swfStreams = new HashMap<>(); public SWFSearch(Searchable s) { this.s = s; @@ -84,7 +83,7 @@ public class SWFSearch { long limit = pmi.getPos(); MemoryInputStream is = new MemoryInputStream(mis.getAllRead(), (int) (long) addr, (int) limit); if (swf.fileSize > 0 && swf.version > 0 && !swf.tags.isEmpty() && swf.version < 25/*Needs to be fixed when SWF versions reaches this value*/) { - swfStreams.add(is); + swfStreams.put(addr, is); } } catch (OutOfMemoryError ome) { @@ -97,16 +96,20 @@ public class SWFSearch { processed = true; } - public MemoryInputStream get(ProgressListener listener, int index) throws IOException { + public MemoryInputStream get(ProgressListener listener, long address) throws IOException { if(!processed){ return null; } - if(index < 0 || index >= swfStreams.size()){ + if (!swfStreams.containsKey(address)) { return null; } - return swfStreams.get(index); + return swfStreams.get(address); } + public Set getAddresses() { + return swfStreams.keySet(); + } + public int length() { if (!processed) { return 0; diff --git a/trunk/src/com/jpexs/helpers/MemoryInputStream.java b/trunk/src/com/jpexs/helpers/MemoryInputStream.java index 9f1f74c06..abb4c7877 100644 --- a/trunk/src/com/jpexs/helpers/MemoryInputStream.java +++ b/trunk/src/com/jpexs/helpers/MemoryInputStream.java @@ -51,7 +51,7 @@ public class MemoryInputStream extends SeekableInputStream { } this.maxLength = maxLength; if (startPos + maxLength >= buffer.length) { - throw new IOException("Invalid maxLength"); + this.maxLength = buffer.length - startPos - 1; } }