Fixed handling of dynamic fetch field name

This commit is contained in:
kitbyte
2024-12-22 11:39:43 +02:00
parent c6ca06e6dd
commit 34894d4589
2 changed files with 18 additions and 5 deletions
+2 -2
View File
@@ -4,7 +4,7 @@
---
<h4>WeMod patcher allows you to get some WeMod features absolutely free. This script patches WeMod, thereby removing the daily usage limit (2h), etc.</h4>
<h4>WeMod patcher allows you to get some WeMod Pro features absolutely free. This script patches WeMod, thereby removing the daily usage limit (2h), etc.</h4>
## 👾 No malware? Is it safe for me?
@@ -40,7 +40,7 @@ With this patch you will be able to use the latest version together with Pro.
2. **Run the script**
``` bash
bun install/npm install/yarn install/whatever you use
npm ./unlocker.js
node ./unlocker.js
```
3. **Follow the instructions**
+16 -3
View File
@@ -6,7 +6,7 @@ const patchBySignature = require("./memoryScanner");
const regex = /getUserAccount\(\)\{.*?return\s+this\.#\w+\.fetch\(\{.*?\}\).*?\}/g;
const asarPatch = "getUserAccount(){return this.#v.fetch({endpoint:\"/v3/account\",method:\"GET\",name:\"/v3/account\",collectMetrics:0}).then(response=>{response.subscription={period:\"yearly\",state:\"active\"};response.flags=78;return response;})}"
const asarPatch = "getUserAccount(){return this.#<fetch_field_name>.fetch({endpoint:\"/v3/account\",method:\"GET\",name:\"/v3/account\",collectMetrics:0}).then(response=>{response.subscription={period:\"yearly\",state:\"active\"};response.flags=78;return response;})}"
const signature = "E8 ?? ?? ?? ?? 85 C0 75 ?? F6 C3 01 74 ?? 48 89 F9 E8 ?? ?? ?? ??"
const patchBytes = [0x31]
const patchOffset = 0x5
@@ -40,6 +40,11 @@ const checkWeModPaths = (dir) => {
return fs.existsSync(dir) && fs.existsSync(path.join(dir, 'WeMod.exe')) && fs.existsSync(path.join(dir, 'resources'))
}
function getFetchFieldName(code) {
const match = code.match(/this\.#([a-zA-Z_$][0-9a-zA-Z_$]*)\.fetch/);
return match ? match[1] : null;
}
const patchAsar = unpackedPath => {
let items = fs.readdirSync(unpackedPath,{ withFileTypes: true })
items = items.filter(item => !item.isDirectory() && /^app-\w+/.test(item.name));
@@ -60,9 +65,18 @@ const patchAsar = unpackedPath => {
console.error(" - Multiple target functions found. Looks like the version is not supported")
throw new Error("Multiple target functions found");
}
const fetchFieldName = getFetchFieldName(matches[0]);
if(!fetchFieldName) {
console.error(" - Fetch field name not found")
throw new Error("Fetch field name not found");
}
const patch = asarPatch.replace(/<fetch_field_name>/g, fetchFieldName)
console.log(" - Found target function in: ", item.name)
console.log(" - Patching asar...")
fs.writeFileSync(path.join(unpackedPath, item.name), data.replace(regex, asarPatch), {encoding: 'utf8'})
fs.writeFileSync(path.join(unpackedPath, item.name), data.replace(regex, patch), {encoding: 'utf8'})
console.log(" - Patch applied")
asarPatchApplied = true;
break;
@@ -153,7 +167,6 @@ if(fs.existsSync(defaultDir)) {
}
}
(async () => {
await prepare();
})();