mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
potential fixes
This commit is contained in:
parent
065aebeb76
commit
15bbe349f8
@ -96,8 +96,7 @@ public class UnityWebModifyer {
|
|||||||
URL codeUrl = new URL(currentUrl + UNITY_CODE);
|
URL codeUrl = new URL(currentUrl + UNITY_CODE);
|
||||||
downloadToFile(codeUrl, codeFile);
|
downloadToFile(codeUrl, codeFile);
|
||||||
|
|
||||||
WasmCodePatcher patcher = new WasmCodePatcher(codeFile.getAbsolutePath());
|
new WasmCodePatcher(codeFile.getAbsolutePath()).patch();
|
||||||
patcher.patch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,30 +25,30 @@ import java.util.*;
|
|||||||
|
|
||||||
public class WasmCodePatcher {
|
public class WasmCodePatcher {
|
||||||
|
|
||||||
private final Module module;
|
|
||||||
private String file;
|
private String file;
|
||||||
|
|
||||||
public WasmCodePatcher(String file) throws IOException, InvalidOpCodeException {
|
public WasmCodePatcher(String file) {
|
||||||
module = new Module(file);
|
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void patch() throws IOException, InvalidOpCodeException {
|
public void patch() throws IOException, InvalidOpCodeException {
|
||||||
FuncIdx returnByteId = findReturnByteFunc();
|
Module module = new Module(file);
|
||||||
FuncIdx setkey = findSetKeyFunc();
|
|
||||||
FuncIdx outgoingIdx = findOutFunc();
|
|
||||||
FuncIdx incomingIdx = findInFunc();
|
|
||||||
|
|
||||||
hook(setkey, "g_chacha_setkey");
|
FuncIdx returnByteId = findReturnByteFunc(module);
|
||||||
copyEmptyHook(returnByteId, "_gearth_returnbyte_copy", "g_chacha_returnbyte");
|
FuncIdx setkey = findSetKeyFunc(module);
|
||||||
copyEmptyHook(outgoingIdx, "_gearth_outgoing_copy", "g_outgoing_packet");
|
FuncIdx outgoingIdx = findOutFunc(module);
|
||||||
copyEmptyHook(incomingIdx, "_gearth_incoming_copy", "g_incoming_packet");
|
FuncIdx incomingIdx = findInFunc(module);
|
||||||
|
|
||||||
|
hook(module, setkey, "g_chacha_setkey");
|
||||||
|
copyEmptyHook(module, returnByteId, "_gearth_returnbyte_copy", "g_chacha_returnbyte");
|
||||||
|
copyEmptyHook(module, outgoingIdx, "_gearth_outgoing_copy", "g_outgoing_packet");
|
||||||
|
copyEmptyHook(module, incomingIdx, "_gearth_incoming_copy", "g_incoming_packet");
|
||||||
|
|
||||||
module.assembleToFile(file);
|
module.assembleToFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private FuncIdx findOutFunc() {
|
private FuncIdx findOutFunc(Module module) {
|
||||||
TypeIdx expectedTypeIdx = module.getTypeSection().getTypeIdxForFuncType(new FuncType(
|
TypeIdx expectedTypeIdx = module.getTypeSection().getTypeIdxForFuncType(new FuncType(
|
||||||
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)),
|
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)),
|
||||||
new ResultType(Collections.emptyList())
|
new ResultType(Collections.emptyList())
|
||||||
@ -78,7 +78,7 @@ public class WasmCodePatcher {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private FuncIdx findSetKeyFunc() {
|
private FuncIdx findSetKeyFunc(Module module) {
|
||||||
FuncType expectedType = new FuncType(
|
FuncType expectedType = new FuncType(
|
||||||
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32)),
|
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32)),
|
||||||
new ResultType(Collections.emptyList())
|
new ResultType(Collections.emptyList())
|
||||||
@ -108,7 +108,7 @@ public class WasmCodePatcher {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private FuncIdx findReturnByteFunc() {
|
private FuncIdx findReturnByteFunc(Module module) {
|
||||||
FuncType expectedType = new FuncType(
|
FuncType expectedType = new FuncType(
|
||||||
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)),
|
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)),
|
||||||
new ResultType(Collections.singletonList(ValType.I32))
|
new ResultType(Collections.singletonList(ValType.I32))
|
||||||
@ -131,7 +131,7 @@ public class WasmCodePatcher {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private FuncIdx findInFunc() {
|
private FuncIdx findInFunc(Module module) {
|
||||||
FuncType expectedType = new FuncType(
|
FuncType expectedType = new FuncType(
|
||||||
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32, ValType.I32)),
|
new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32, ValType.I32)),
|
||||||
new ResultType(Collections.emptyList())
|
new ResultType(Collections.emptyList())
|
||||||
@ -161,7 +161,7 @@ public class WasmCodePatcher {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyEmptyHook(FuncIdx orgFuncIdx, String exportName, String hookname) throws InvalidOpCodeException, IOException {
|
private void copyEmptyHook(Module module, FuncIdx orgFuncIdx, String exportName, String hookname) throws InvalidOpCodeException, IOException {
|
||||||
// copies the method, empties the first one
|
// copies the method, empties the first one
|
||||||
// export the copy
|
// export the copy
|
||||||
// hooks to the emptied one
|
// hooks to the emptied one
|
||||||
@ -197,7 +197,7 @@ public class WasmCodePatcher {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hook(FuncIdx funcIdx, String jsFunctionName) throws InvalidOpCodeException, IOException {
|
private void hook(Module module, FuncIdx funcIdx, String jsFunctionName) throws InvalidOpCodeException, IOException {
|
||||||
FuncType funcType = module.getTypeSection().getByFuncIdx(funcIdx);
|
FuncType funcType = module.getTypeSection().getByFuncIdx(funcIdx);
|
||||||
|
|
||||||
Import imp = new Import(
|
Import imp = new Import(
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user