From 15bbe349f854f56e5847189f3428eff4e296dffc Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 29 Dec 2020 00:25:12 +0100 Subject: [PATCH] potential fixes --- .../unity_tools/UnityWebModifyer.java | 3 +- .../services/unity_tools/WasmCodePatcher.java | 34 +++++++++--------- .../resources/build/windows/32bit/G-Earth.exe | Bin 46592 -> 46592 bytes .../resources/build/windows/64bit/G-Earth.exe | Bin 46592 -> 46592 bytes 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/G-Earth/src/main/java/gearth/services/unity_tools/UnityWebModifyer.java b/G-Earth/src/main/java/gearth/services/unity_tools/UnityWebModifyer.java index a950657..1571860 100644 --- a/G-Earth/src/main/java/gearth/services/unity_tools/UnityWebModifyer.java +++ b/G-Earth/src/main/java/gearth/services/unity_tools/UnityWebModifyer.java @@ -96,8 +96,7 @@ public class UnityWebModifyer { URL codeUrl = new URL(currentUrl + UNITY_CODE); downloadToFile(codeUrl, codeFile); - WasmCodePatcher patcher = new WasmCodePatcher(codeFile.getAbsolutePath()); - patcher.patch(); + new WasmCodePatcher(codeFile.getAbsolutePath()).patch(); } diff --git a/G-Earth/src/main/java/gearth/services/unity_tools/WasmCodePatcher.java b/G-Earth/src/main/java/gearth/services/unity_tools/WasmCodePatcher.java index 07477a6..4977c10 100644 --- a/G-Earth/src/main/java/gearth/services/unity_tools/WasmCodePatcher.java +++ b/G-Earth/src/main/java/gearth/services/unity_tools/WasmCodePatcher.java @@ -25,30 +25,30 @@ import java.util.*; public class WasmCodePatcher { - private final Module module; private String file; - public WasmCodePatcher(String file) throws IOException, InvalidOpCodeException { - module = new Module(file); + public WasmCodePatcher(String file) { this.file = file; } public void patch() throws IOException, InvalidOpCodeException { - FuncIdx returnByteId = findReturnByteFunc(); - FuncIdx setkey = findSetKeyFunc(); - FuncIdx outgoingIdx = findOutFunc(); - FuncIdx incomingIdx = findInFunc(); + Module module = new Module(file); - hook(setkey, "g_chacha_setkey"); - copyEmptyHook(returnByteId, "_gearth_returnbyte_copy", "g_chacha_returnbyte"); - copyEmptyHook(outgoingIdx, "_gearth_outgoing_copy", "g_outgoing_packet"); - copyEmptyHook(incomingIdx, "_gearth_incoming_copy", "g_incoming_packet"); + FuncIdx returnByteId = findReturnByteFunc(module); + FuncIdx setkey = findSetKeyFunc(module); + FuncIdx outgoingIdx = findOutFunc(module); + 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); } - private FuncIdx findOutFunc() { + private FuncIdx findOutFunc(Module module) { TypeIdx expectedTypeIdx = module.getTypeSection().getTypeIdxForFuncType(new FuncType( new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)), new ResultType(Collections.emptyList()) @@ -78,7 +78,7 @@ public class WasmCodePatcher { return null; } - private FuncIdx findSetKeyFunc() { + private FuncIdx findSetKeyFunc(Module module) { FuncType expectedType = new FuncType( new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32)), new ResultType(Collections.emptyList()) @@ -108,7 +108,7 @@ public class WasmCodePatcher { return null; } - private FuncIdx findReturnByteFunc() { + private FuncIdx findReturnByteFunc(Module module) { FuncType expectedType = new FuncType( new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32)), new ResultType(Collections.singletonList(ValType.I32)) @@ -131,7 +131,7 @@ public class WasmCodePatcher { return null; } - private FuncIdx findInFunc() { + private FuncIdx findInFunc(Module module) { FuncType expectedType = new FuncType( new ResultType(Arrays.asList(ValType.I32, ValType.I32, ValType.I32, ValType.I32, ValType.I32)), new ResultType(Collections.emptyList()) @@ -161,7 +161,7 @@ public class WasmCodePatcher { 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 // export the copy // 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); Import imp = new Import( diff --git a/G-Earth/src/main/resources/build/windows/32bit/G-Earth.exe b/G-Earth/src/main/resources/build/windows/32bit/G-Earth.exe index 7a025e62810b4a783832113dd23a36841eb86723..c1c3d5cea125e2b1f0e6b6f1c20da9dfe50c414d 100644 GIT binary patch delta 901 zcmZ{iKTE?v7{=ebMyyb!NDCE<2rd}}Td8~LRIwkRf?$`li7pi#Ita;_!J#FKTRV1f z>Qe9vICdylaOvPsq@ZpN4nCJZ?WxH@_}%m5xqIJS&YE*;&fB(fV7#4o?kX|8%Q`Q4 zKB+iY{KPqB?`$$S=8u{iaN>G4o8e?7iKq-_z!nIQ*ug34DN{^@LBxm@qCWT3(qAWG zO^K`+_yxwnBqM7BRKZQK2&TX)ms*{+~`+3V3^Yy;UQ8J;HB=_}GbZ(jh>a zc)S93#Dd!I1&jQBM7|x7?;}6lW2Ba_g+Hd6$;6ddj8~13`1iq>L;Gj$S|8Af;3fF| z=RMUK`F*)51$s-$??SIgS~X$F1@@s2r9ch(TGC_aBS|M3jNH5BdpFSHk_N+u9!mwz ZE*RZPdSGAbrL}w^mlG=rgU^TO)gS7BeHj1% delta 817 zcmZ{iu}eZx6vofJ3OPtfyud&zsKK@p0*3~1iyT}6TcYLZlL(52+PtGfgLW5(hQ?Y# z&>^V7t%imMDWRo5KRE&s{l2jZlfB=~ZI^$Rs^I{rAf+$Q>mA)GH zqhwk=A{7E%Faky}cotj+=fE^*fq8HqbihSWfi~Cxi(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