binary file search fix

This commit is contained in:
Honfika
2014-01-22 00:17:03 +01:00
parent 043b4c12da
commit e2a42471de
3 changed files with 17 additions and 19 deletions

View File

@@ -46,8 +46,8 @@ public class BinarySWFBundle implements SWFBundle {
@Override
public Set<String> getKeys() {
Set<String> 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;
}
}

View File

@@ -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<ProgressListener> listeners = new HashSet<>();
private final List<MemoryInputStream> swfStreams = new ArrayList<>();
private final Map<Long, MemoryInputStream> 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<Long> getAddresses() {
return swfStreams.keySet();
}
public int length() {
if (!processed) {
return 0;

View File

@@ -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;
}
}