Saving only modified ABC body code

Reading ABC code outside bounds fix
This commit is contained in:
Jindra Petřík
2014-09-24 17:42:44 +02:00
parent 92162124f5
commit f202a81ddc
5 changed files with 27 additions and 10 deletions

View File

@@ -545,7 +545,7 @@ public class ABC {
mb.init_scope_depth = ais.readU30("init_scope_depth");
mb.max_scope_depth = ais.readU30("max_scope_depth");
int code_length = ais.readU30("code_length");
mb.codeBytes = ais.readBytes(code_length, "code");
mb.setCodeBytes(ais.readBytes(code_length, "code"));
int ex_count = ais.readU30("ex_count");
mb.exceptions = new ABCException[ex_count];
for (int j = 0; j < ex_count; j++) {
@@ -668,7 +668,7 @@ public class ABC {
aos.writeU30(mb.max_regs);
aos.writeU30(mb.init_scope_depth);
aos.writeU30(mb.max_scope_depth);
byte[] codeBytes = mb.getCode().getBytes();
byte[] codeBytes = mb.getCodeBytes();
aos.writeU30(codeBytes.length);
aos.write(codeBytes);
aos.writeU30(mb.exceptions.length);

View File

@@ -788,12 +788,18 @@ public class AVM2Code implements Cloneable {
Map<Long, AVM2Instruction> codeMap = new TreeMap<>();
DumpInfo diParent = ais.dumpInfo;
List<Long> addresses = new ArrayList<>();
addresses.add(ais.getPosition());
long startPos = ais.getPosition();
addresses.add(startPos);
while (!addresses.isEmpty()) {
long address = addresses.remove(0);
if (codeMap.containsKey(address)) {
continue;
}
if(address<startPos) //no jump outside block
{
continue;
}
try {
ais.seek(address);
while (ais.available() > 0) {

View File

@@ -54,13 +54,26 @@ public class MethodBody implements Cloneable {
public int max_regs;
public int init_scope_depth;
public int max_scope_depth;
public byte[] codeBytes;
private byte[] codeBytes = new byte[0];
private AVM2Code code;
public ABCException[] exceptions = new ABCException[0];
public Traits traits = new Traits();
public transient List<GraphTargetItem> convertedItems;
public transient Throwable convertException;
public synchronized void setCodeBytes(byte codeBytes[]){
this.codeBytes = codeBytes;
this.code = null;
}
public synchronized byte[] getCodeBytes() {
if(code == null){
return codeBytes;
}else{
return code.getBytes();
}
}
public synchronized AVM2Code getCode() {
if (code == null) {
AVM2Code avm2Code;

View File

@@ -1458,8 +1458,7 @@ public class CommandLineArgumentParser {
if (text.trim().startsWith("#hexdata")) {
byte[] data = Helper.getBytesFromHexaText(text);
MethodBody mb = abc.bodies.get(bodyIndex);
mb.codeBytes = data;
mb.setCode(null);
mb.setCodeBytes(data);
} else {
try {
AVM2Code acode = ASM3Parser.parse(new StringReader(text), abc.constants, trait, new MissingSymbolHandler() {
@@ -1484,7 +1483,7 @@ public class CommandLineArgumentParser {
return true;
}
}, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info));
acode.getBytes(abc.bodies.get(bodyIndex).codeBytes);
//acode.getBytes(abc.bodies.get(bodyIndex).getCodeBytes());
abc.bodies.get(bodyIndex).setCode(acode);
} catch (AVM2ParseException ex) {
System.err.println("%error% on line %line%".replace("%error%", ex.text).replace("%line%", "" + ex.line));

View File

@@ -189,8 +189,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi
if (text.trim().startsWith("#hexdata")) {
byte[] data = Helper.getBytesFromHexaText(text);
MethodBody mb = abc.bodies.get(bodyIndex);
mb.codeBytes = data;
mb.setCode(null);
mb.setCodeBytes(data);
} else {
AVM2Code acode = ASM3Parser.parse(new StringReader(text), abc.constants, trait, new MissingSymbolHandler() {
//no longer ask for adding new constants
@@ -214,7 +213,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi
return true;
}
}, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info));
acode.getBytes(abc.bodies.get(bodyIndex).codeBytes);
//acode.getBytes(abc.bodies.get(bodyIndex).getCodeBytes());
abc.bodies.get(bodyIndex).setCode(acode);
}
((Tag) abc.parentTag).setModified(true);