updated for gwasm minimal 1.0.1

This commit is contained in:
sirjonasxx 2021-11-26 00:51:46 +01:00
parent c2fcee21b9
commit d9d1785a33
5 changed files with 44 additions and 54 deletions

View File

@ -232,7 +232,7 @@
<dependency> <dependency>
<groupId>G-Earth</groupId> <groupId>G-Earth</groupId>
<artifactId>G-Wasm</artifactId> <artifactId>G-Wasm</artifactId>
<version>1.0</version> <version>1.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -7,7 +7,6 @@ import wasm.disassembly.modules.sections.code.Locals;
import wasm.disassembly.types.FuncType; import wasm.disassembly.types.FuncType;
import wasm.disassembly.types.ResultType; import wasm.disassembly.types.ResultType;
import wasm.disassembly.types.ValType; import wasm.disassembly.types.ValType;
import wasm.misc.CodeCompare;
import wasm.misc.StreamReplacement; import wasm.misc.StreamReplacement;
import java.util.Arrays; import java.util.Arrays;
@ -38,23 +37,23 @@ public class IncomingPacketPatcher implements StreamReplacement {
} }
@Override @Override
public CodeCompare getCodeCompare() { public boolean codeMatches(Func code) {
return code -> { if (!(code.getLocalss().equals(Collections.singletonList(new Locals(1, ValType.I32)))))
if (!(code.getLocalss().equals(Collections.singletonList(new Locals(1, ValType.I32))))) return false;
return false;
List<InstrType> expectedExpr = Arrays.asList(InstrType.I32_CONST, InstrType.I32_LOAD8_S, List<InstrType> expectedExpr = Arrays.asList(InstrType.I32_CONST, InstrType.I32_LOAD8_S,
InstrType.I32_EQZ, InstrType.IF, InstrType.LOCAL_GET, InstrType.I32_LOAD, InstrType.LOCAL_TEE, InstrType.I32_EQZ, InstrType.IF, InstrType.LOCAL_GET, InstrType.I32_LOAD, InstrType.LOCAL_TEE,
InstrType.IF); InstrType.IF);
if (code.getExpression().getInstructions().size() != expectedExpr.size()) return false; if (code.getExpression().getInstructions().size() != expectedExpr.size()) return false;
for (int j = 0; j < code.getExpression().getInstructions().size(); j++) { for (int j = 0; j < code.getExpression().getInstructions().size(); j++) {
Instr instr = code.getExpression().getInstructions().get(j); Instr instr = code.getExpression().getInstructions().get(j);
if (instr.getInstrType() != expectedExpr.get(j)) return false; if (instr.getInstrType() != expectedExpr.get(j)) return false;
} }
return true; return true;
};
} }
} }

View File

@ -6,7 +6,6 @@ import wasm.disassembly.modules.sections.code.Func;
import wasm.disassembly.types.FuncType; import wasm.disassembly.types.FuncType;
import wasm.disassembly.types.ResultType; import wasm.disassembly.types.ResultType;
import wasm.disassembly.types.ValType; import wasm.disassembly.types.ValType;
import wasm.misc.CodeCompare;
import wasm.misc.StreamReplacement; import wasm.misc.StreamReplacement;
import java.util.Arrays; import java.util.Arrays;
@ -36,18 +35,16 @@ public class OutgoingPacketPatcher implements StreamReplacement {
} }
@Override @Override
public CodeCompare getCodeCompare() { public boolean codeMatches(Func code) {
return code -> { if (code.getLocalss().size() != 0) return false;
if (code.getLocalss().size() != 0) return false; List<Instr> expression = code.getExpression().getInstructions();
List<Instr> expression = code.getExpression().getInstructions(); if (expression.get(0).getInstrType() != InstrType.LOCAL_GET) return false;
if (expression.get(0).getInstrType() != InstrType.LOCAL_GET) return false; if (expression.get(1).getInstrType() != InstrType.LOCAL_GET) return false;
if (expression.get(1).getInstrType() != InstrType.LOCAL_GET) return false; if (expression.get(2).getInstrType() != InstrType.LOCAL_GET) return false;
if (expression.get(2).getInstrType() != InstrType.LOCAL_GET) return false; if (expression.get(3).getInstrType() != InstrType.I32_LOAD) return false;
if (expression.get(3).getInstrType() != InstrType.I32_LOAD) return false; if (expression.get(4).getInstrType() != InstrType.I32_CONST) return false;
if (expression.get(4).getInstrType() != InstrType.I32_CONST) return false; if (expression.get(5).getInstrType() != InstrType.CALL) return false;
if (expression.get(5).getInstrType() != InstrType.CALL) return false;
return true; return true;
};
} }
} }

View File

@ -6,7 +6,6 @@ import wasm.disassembly.modules.sections.code.Func;
import wasm.disassembly.types.FuncType; import wasm.disassembly.types.FuncType;
import wasm.disassembly.types.ResultType; import wasm.disassembly.types.ResultType;
import wasm.disassembly.types.ValType; import wasm.disassembly.types.ValType;
import wasm.misc.CodeCompare;
import wasm.misc.StreamReplacement; import wasm.misc.StreamReplacement;
import java.util.Arrays; import java.util.Arrays;
@ -36,13 +35,11 @@ public class ReturnBytePatcher implements StreamReplacement {
} }
@Override @Override
public CodeCompare getCodeCompare() { public boolean codeMatches(Func code) {
return code -> { if (code.getLocalss().size() != 0) return false;
if (code.getLocalss().size() != 0) return false; if (code.getExpression().getInstructions().size() != 30) return false;
if (code.getExpression().getInstructions().size() != 30) return false; List<Instr> expr = code.getExpression().getInstructions();
List<Instr> expr = code.getExpression().getInstructions(); if (expr.get(expr.size() - 1).getInstrType() != InstrType.I32_XOR) return false;
if (expr.get(expr.size() - 1).getInstrType() != InstrType.I32_XOR) return false; return true;
return true;
};
} }
} }

View File

@ -7,7 +7,6 @@ import wasm.disassembly.modules.sections.code.Locals;
import wasm.disassembly.types.FuncType; import wasm.disassembly.types.FuncType;
import wasm.disassembly.types.ResultType; import wasm.disassembly.types.ResultType;
import wasm.disassembly.types.ValType; import wasm.disassembly.types.ValType;
import wasm.misc.CodeCompare;
import wasm.misc.StreamReplacement; import wasm.misc.StreamReplacement;
import java.util.Arrays; import java.util.Arrays;
@ -38,23 +37,21 @@ public class SetKeyPatcher implements StreamReplacement {
} }
@Override @Override
public CodeCompare getCodeCompare() { public boolean codeMatches(Func code) {
return code -> { if (!(code.getLocalss().equals(Collections.singletonList(new Locals(1, ValType.I32)))))
if (!(code.getLocalss().equals(Collections.singletonList(new Locals(1, ValType.I32))))) return false;
return false; List<InstrType> expectedExpr = Arrays.asList(InstrType.I32_CONST, InstrType.I32_LOAD8_S,
List<InstrType> expectedExpr = Arrays.asList(InstrType.I32_CONST, InstrType.I32_LOAD8_S, InstrType.I32_EQZ, InstrType.IF, InstrType.BLOCK, InstrType.LOCAL_GET, InstrType.I32_CONST,
InstrType.I32_EQZ, InstrType.IF, InstrType.BLOCK, InstrType.LOCAL_GET, InstrType.I32_CONST, InstrType.LOCAL_GET, InstrType.I32_LOAD, InstrType.I32_CONST, InstrType.I32_CONST, InstrType.I32_CONST,
InstrType.LOCAL_GET, InstrType.I32_LOAD, InstrType.I32_CONST, InstrType.I32_CONST, InstrType.I32_CONST, InstrType.CALL);
InstrType.CALL);
if (code.getExpression().getInstructions().size() != expectedExpr.size()) return false; if (code.getExpression().getInstructions().size() != expectedExpr.size()) return false;
for (int j = 0; j < code.getExpression().getInstructions().size(); j++) { for (int j = 0; j < code.getExpression().getInstructions().size(); j++) {
Instr instr = code.getExpression().getInstructions().get(j); Instr instr = code.getExpression().getInstructions().get(j);
if (instr.getInstrType() != expectedExpr.get(j)) return false; if (instr.getInstrType() != expectedExpr.get(j)) return false;
} }
return true; return true;
};
} }
} }