Initialize local project and fix ranch growth synchronization
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
/** Read-only loader audit. Writes only stdout; never saves a SWF. */
|
||||
public final class LoaderAudit_20261107_01 {
|
||||
static final Set<String> DUMP = Set.of("fixComplete", "mainByteLoadComplete", "mainComplete", "loaderStart",
|
||||
"startVersionCheck", "fixVersionFileAutoLoadComplete", "fixVersionComplete", "addToStageHandler",
|
||||
"getStorageSrcIfExist", "getStorageFileIfExist");
|
||||
static String sha(byte[] b) throws Exception {
|
||||
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(b));
|
||||
}
|
||||
static byte[] uncompressed(byte[] b) throws Exception {
|
||||
if (b[0] == 'F') return b;
|
||||
if (b[0] != 'C') throw new IOException("Unsupported SWF compression");
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
out.write(b, 0, 8);
|
||||
try (var in = new InflaterInputStream(new ByteArrayInputStream(b, 8, b.length - 8))) { in.transferTo(out); }
|
||||
return out.toByteArray();
|
||||
}
|
||||
static int[] find(byte[] hay, byte[] needle) {
|
||||
if (needle.length < 8) return new int[0];
|
||||
ArrayList<Integer> found = new ArrayList<>();
|
||||
outer: for (int i = 0; i <= hay.length - needle.length; i++) {
|
||||
if (hay[i] != needle[0]) continue;
|
||||
for (int j = 1; j < needle.length; j++) if (hay[i+j] != needle[j]) continue outer;
|
||||
found.add(i);
|
||||
}
|
||||
return found.stream().mapToInt(Integer::intValue).toArray();
|
||||
}
|
||||
static List<String> offsets(MethodBody body) {
|
||||
AVM2Code code = body.getCode();
|
||||
Set<Long> boundaries = new HashSet<>();
|
||||
for (var ins : code.code) boundaries.add(ins.getAddress());
|
||||
List<String> problems = new ArrayList<>();
|
||||
for (var ins : code.code) for (long target : ins.getOffsets()) {
|
||||
if (!boundaries.contains(target)) problems.add("BRANCH @" + ins.getAddress() + " -> " + target);
|
||||
}
|
||||
for (var ex : body.exceptions) {
|
||||
if (!boundaries.contains((long)ex.start) || (ex.end != body.getCodeBytes().length && !boundaries.contains((long)ex.end))
|
||||
|| !boundaries.contains((long)ex.target) || ex.start >= ex.end || ex.end > body.getCodeBytes().length)
|
||||
problems.add("EXCEPTION " + ex.start + ":" + ex.end + ":" + ex.target);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
static void dump(ABC abc, MethodBody body, byte[] rawSwf) throws Exception {
|
||||
byte[] bytes = body.getCodeBytes().clone();
|
||||
AVM2Code code = body.getCode();
|
||||
System.out.println("RAW_CODE " + HexFormat.of().formatHex(bytes));
|
||||
System.out.println("RAW_CODE_SWF_OFFSETS " + Arrays.toString(find(rawSwf, bytes)));
|
||||
System.out.println("SERIALIZATION_IDENTICAL " + Arrays.equals(bytes, code.getBytes()));
|
||||
Map<Long, Integer> heights = new HashMap<>();
|
||||
Map<Long, Integer> scopes = new HashMap<>();
|
||||
Map<Long, AVM2Instruction> instructions = new HashMap<>();
|
||||
for (var ins : code.code) instructions.put(ins.getAddress(), ins);
|
||||
ArrayDeque<Long> work = new ArrayDeque<>();
|
||||
heights.put(0L, 0); scopes.put(0L, body.init_scope_depth); work.add(0L);
|
||||
int maximum = 0, maximumScope = body.init_scope_depth;
|
||||
List<String> problems = new ArrayList<>();
|
||||
while (!work.isEmpty()) {
|
||||
long at = work.removeFirst();
|
||||
var ins = instructions.get(at);
|
||||
if (ins == null) { problems.add("MISSING_INSTRUCTION " + at); continue; }
|
||||
int before = heights.get(at), scope = scopes.get(at);
|
||||
int pops = ins.definition.getStackPopCount(ins, abc), pushes = ins.definition.getStackPushCount(ins, abc);
|
||||
if (before < pops) problems.add("UNDERFLOW @" + at + " " + before + "<" + pops);
|
||||
int after = before - pops + pushes;
|
||||
int scopeAfter = scope + ins.definition.getScopeStackDelta(ins, abc);
|
||||
maximum = Math.max(maximum, Math.max(before, after)); maximumScope = Math.max(maximumScope, scopeAfter);
|
||||
List<Long> successors = new ArrayList<>(ins.getOffsets());
|
||||
if (!ins.isExit() && !ins.isJump() && !ins.definition.instructionName.equals("lookupswitch"))
|
||||
successors.add(at + ins.getBytesLength());
|
||||
for (long to : successors) {
|
||||
Integer prev = heights.putIfAbsent(to, after);
|
||||
scopes.putIfAbsent(to, scopeAfter);
|
||||
if (prev == null) work.add(to);
|
||||
else if (prev != after) problems.add("STACK_MERGE @" + to + " " + prev + " vs " + after);
|
||||
}
|
||||
}
|
||||
System.out.println("STACK_ANALYSIS computed_max=" + maximum + " declared_max=" + body.max_stack
|
||||
+ " computed_scope=" + maximumScope + " declared_scope=" + body.max_scope_depth + " problems=" + problems);
|
||||
for (int i = 0; i < code.code.size(); i++) {
|
||||
var ins = code.code.get(i);
|
||||
int pop = ins.definition.getStackPopCount(ins, abc), push = ins.definition.getStackPushCount(ins, abc);
|
||||
Integer h = heights.get(ins.getAddress());
|
||||
System.out.printf("%03d @%04x (%3d) %-22s stack=%s pop=%d push=%d %-85s %s%n", i,
|
||||
ins.getAddress(), ins.getAddress(), HexFormat.of().formatHex(ins.getBytes()),
|
||||
h == null ? "?" : h + "->" + (h-pop+push), pop, push,
|
||||
ins.toStringNoAddress(abc.constants, new ArrayList<>()),
|
||||
ins.getOffsets().isEmpty() ? "" : "TARGETS=" + ins.getOffsets());
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (String arg : args) {
|
||||
byte[] file = Files.readAllBytes(Path.of(arg));
|
||||
byte[] rawSwf = uncompressed(file);
|
||||
System.out.println("FILE " + arg + " bytes=" + file.length + " sha256=" + sha(file)
|
||||
+ " signature=" + new String(file, 0, 3, java.nio.charset.StandardCharsets.US_ASCII));
|
||||
try (var in = new BufferedInputStream(new ByteArrayInputStream(file))) {
|
||||
SWF swf = new SWF(in, false);
|
||||
Map<ABC, List<String>> packs = new LinkedHashMap<>();
|
||||
for (ScriptPack pack : swf.getAS3Packs()) {
|
||||
String name = pack.getClassPath().toString();
|
||||
packs.computeIfAbsent(pack.abc, k -> new ArrayList<>()).add(name);
|
||||
if (name.startsWith("net.pixvi.myrloader.")) System.out.println("LOADER_CLASS " + name);
|
||||
}
|
||||
// Main logic artifacts are inspected only for loader definitions, never battle bodies.
|
||||
if (arg.endsWith(".app") || arg.contains("_ui_inventory_")) {
|
||||
System.out.println("MAIN_LOADER_CLASS_INVENTORY_COMPLETE packs=" + packs.values().stream().mapToInt(List::size).sum());
|
||||
continue;
|
||||
}
|
||||
int totalBodies = 0, branches = 0, exceptions = 0, bad = 0;
|
||||
for (var entry : packs.entrySet()) {
|
||||
ABC abc = entry.getKey(); Tag tag = (Tag)abc.parentTag;
|
||||
System.out.println("ABC tagPos=" + tag.getPos() + " rawBytes=" + tag.getOriginalDataLength()
|
||||
+ " rawSha256=" + sha(tag.getOriginalData()) + " packs=" + entry.getValue());
|
||||
for (int bi = 0; bi < abc.bodies.size(); bi++) {
|
||||
var body = abc.bodies.get(bi);
|
||||
String name = abc.constants.getString(abc.method_info.get(body.method_info).name_index);
|
||||
byte[] originalCode = body.getCodeBytes().clone();
|
||||
List<String> errors = offsets(body);
|
||||
totalBodies++; exceptions += body.exceptions.length; bad += errors.size();
|
||||
for (var ins : body.getCode().code) branches += ins.getOffsets().size();
|
||||
System.out.println("BODY tagPos=" + tag.getPos() + " body=" + bi + " method=" + body.method_info
|
||||
+ " name=" + name + " bytes=" + originalCode.length + " sha256=" + sha(originalCode)
|
||||
+ " maxStack=" + body.max_stack + " regs=" + body.max_regs
|
||||
+ " scope=" + body.init_scope_depth + ":" + body.max_scope_depth
|
||||
+ " exceptions=" + Arrays.toString(body.exceptions) + " offsetErrors=" + errors);
|
||||
boolean targeted = entry.getValue().stream().anyMatch(n -> n.equals("net.pixvi.myrloader.MYRLoaderStarter")
|
||||
|| n.equals("net.pixvi.myrloader.MYRLoader_dyd") || n.equals("net.pixvi.myrloader.center.MyrUpdateCenter"));
|
||||
if (targeted && name != null && DUMP.contains(name)) dump(abc, body, rawSwf);
|
||||
}
|
||||
if (entry.getValue().contains("net.pixvi.myrloader.MYRLoaderStarter")) {
|
||||
int lookup = abc.findMethodBodyByName("net.pixvi.myrloader.MYRLoaderStarter", "fixComplete");
|
||||
System.out.println("FIX_COMPLETE_NAME_LOOKUP body=" + lookup);
|
||||
for (var inst : abc.instance_info) for (var trait : inst.instance_traits.traits)
|
||||
if (trait instanceof TraitMethodGetterSetter tm && abc.constants.getString(abc.method_info.get(tm.method_info).name_index).equals("fixComplete"))
|
||||
System.out.println("FIX_COMPLETE_ACTUAL_TRAIT method=" + tm.method_info + " body=" + abc.findBodyIndex(tm.method_info));
|
||||
}
|
||||
}
|
||||
System.out.println("OFFSET_SUMMARY bodies=" + totalBodies + " branchTargets=" + branches
|
||||
+ " exceptionEntries=" + exceptions + " invalidOffsets=" + bad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,34 @@
|
||||
"""Read only loader entrypoints and loader bytes from the named local APKs."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import zipfile
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
files = sorted(root.glob("*.apk")) + [
|
||||
root / "analysis/device_current.apk",
|
||||
root / "analysis/device_after_two_mods.apk",
|
||||
]
|
||||
rows = []
|
||||
for path in files:
|
||||
if not path.is_file():
|
||||
continue
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
names = archive.namelist()
|
||||
row = {"apk": str(path.relative_to(root)), "loaders": [], "air_descriptors": []}
|
||||
for name in names:
|
||||
if name == "assets/MYRDyd.swf":
|
||||
data = archive.read(name)
|
||||
row["loaders"].append({"name": name, "size": len(data), "sha256": hashlib.sha256(data).hexdigest()})
|
||||
if name.endswith("META-INF/AIR/application.xml"):
|
||||
data = archive.read(name)
|
||||
xml = ET.fromstring(data)
|
||||
row["air_descriptors"].append({"name": name, "entrypoints": [element.text for element in xml.iter() if element.tag.endswith("}content")], "text": data.decode("utf-8")})
|
||||
row["swf_candidates"] = [n for n in names if n.lower().endswith(".swf") and ("myrdyd" in n.lower() or "myrloader" in n.lower())]
|
||||
rows.append(row)
|
||||
destination = Path(__file__).with_name("apk_entrypoints_20261107_01.json")
|
||||
with destination.open("x", encoding="utf-8") as out:
|
||||
json.dump(rows, out, indent=2, ensure_ascii=False)
|
||||
for row in rows:
|
||||
print(json.dumps({**row, "air_descriptors": [{k:v for k,v in d.items() if k != "text"} for d in row["air_descriptors"]]}, ensure_ascii=True))
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"file": "analysis\\loader_audit\\MYRDyd_explicit_package_diagnostic_20261107_01.swf",
|
||||
"original_sha256": "4728d0e23bdf0d6b1468e8cd39f97535e65a09bfa40044e7c73af7e1655af741",
|
||||
"candidate_sha256": "50aa4369787dc8f2a240a52c6969eae84f220a96c1cf18a9e5e85f2a4a2ee90f",
|
||||
"file_size": 367556,
|
||||
"method_code_start_hex": "0x289f4",
|
||||
"method_offset_hex": "0x13",
|
||||
"file_offset_hex": "0x28a07",
|
||||
"before": "60 05 46 0f 00 66 2f 80 14 d5 60 05 2c 80 02 46 2b 01 85 d6",
|
||||
"after": "60 3d 66 43 2c 80 02 46 3f 01 66 41 85 d6 02 02 02 02 02 02",
|
||||
"changed_byte_count": 18,
|
||||
"identical_outside_block": true
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Create a separate equal-length diagnostic loader; existing files stay untouched."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
outdir = Path(__file__).parent
|
||||
original = (root / "analysis/MYRDyd.swf").read_bytes()
|
||||
assert hashlib.sha256(original).hexdigest() == "4728d0e23bdf0d6b1468e8cd39f97535e65a09bfa40044e7c73af7e1655af741"
|
||||
code_start = 0x289f4
|
||||
patch_start = code_start + 0x13
|
||||
before = bytes.fromhex("60 05 46 0f 00 66 2f 80 14 d5 60 05 2c 80 02 46 2b 01 85 d6")
|
||||
# File.applicationDirectory.resolvePath("MYRMain.app").url -> local2, followed by six real nop opcodes.
|
||||
after = bytes.fromhex("60 3d 66 43 2c 80 02 46 3f 01 66 41 85 d6 02 02 02 02 02 02")
|
||||
assert len(before) == len(after) == 20
|
||||
assert original[patch_start:patch_start + 20] == before
|
||||
candidate = bytearray(original)
|
||||
candidate[patch_start:patch_start + 20] = after
|
||||
assert len(original) == len(candidate)
|
||||
assert candidate[:patch_start] == original[:patch_start]
|
||||
assert candidate[patch_start + 20:] == original[patch_start + 20:]
|
||||
path = outdir / "MYRDyd_explicit_package_diagnostic_20261107_01.swf"
|
||||
with path.open("xb") as stream:
|
||||
stream.write(candidate)
|
||||
result = {"file": str(path.relative_to(root)), "original_sha256": hashlib.sha256(original).hexdigest(),
|
||||
"candidate_sha256": hashlib.sha256(candidate).hexdigest(), "file_size": len(candidate),
|
||||
"method_code_start_hex": hex(code_start), "method_offset_hex": "0x13", "file_offset_hex": hex(patch_start),
|
||||
"before": before.hex(" "), "after": after.hex(" "),
|
||||
"changed_byte_count": sum(a != b for a, b in zip(before, after)), "identical_outside_block": True}
|
||||
with (outdir / "explicit_package_candidate_20261107_01.json").open("x", encoding="utf-8") as stream:
|
||||
json.dump(result, stream, indent=2)
|
||||
print(json.dumps(result, indent=2))
|
||||
@@ -0,0 +1,307 @@
|
||||
{
|
||||
"changed_method_bodies": [
|
||||
{
|
||||
"tag_pos": 413,
|
||||
"body": 43,
|
||||
"original": [
|
||||
"44",
|
||||
"fixComplete",
|
||||
"104",
|
||||
"e36b100598f599e3aa7fd7c5d68faeacb339074d526d86ff4947e099e9518cf1",
|
||||
"4",
|
||||
"3",
|
||||
"0:1",
|
||||
"[]"
|
||||
],
|
||||
"modified": [
|
||||
"44",
|
||||
"fixComplete",
|
||||
"101",
|
||||
"00e37cab2a6ea0e8685aece0b798ea3d1bb10f222736f85d3b3bf0412bed0a49",
|
||||
"4",
|
||||
"3",
|
||||
"0:1",
|
||||
"[]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"code_start": 166388,
|
||||
"code_start_hex": "0x289f4",
|
||||
"method_header_offset": 166382,
|
||||
"max_stack_offset": 166383,
|
||||
"method_header_original": "2c 04 03 00 01 68",
|
||||
"method_header_modified": "2c 04 03 00 01 65",
|
||||
"original_size": 367556,
|
||||
"modified_size": 367553,
|
||||
"original_sha256": "4728d0e23bdf0d6b1468e8cd39f97535e65a09bfa40044e7c73af7e1655af741",
|
||||
"modified_sha256": "4abd57617346228c5b6e9b60f363c130e94d820d32a30848559555caaada0f4d",
|
||||
"method_region_original": "80 14 d5 60 05 2c 80 02 46 2b 01 85 d6",
|
||||
"method_region_modified": "80 14 2c 80 02 02 02 02 02 d6",
|
||||
"prefix_identical_except_header_and_lengths": [
|
||||
[
|
||||
4,
|
||||
196,
|
||||
193
|
||||
],
|
||||
[
|
||||
415,
|
||||
245,
|
||||
242
|
||||
],
|
||||
[
|
||||
166387,
|
||||
104,
|
||||
101
|
||||
]
|
||||
],
|
||||
"suffix_identical_after_method": true,
|
||||
"candidate": {
|
||||
"path": "analysis\\loader_audit\\MYRDyd_resolver_bypass_diagnostic_20261107_01.swf",
|
||||
"sha256": "4acad192e4eba7aca0d740cbfab09662753d03091ae25640a7f216822ae913f7",
|
||||
"size": 367556,
|
||||
"changed_offsets": [
|
||||
166422,
|
||||
166423,
|
||||
166424
|
||||
],
|
||||
"changed_offsets_hex": [
|
||||
"0x28a16",
|
||||
"0x28a17",
|
||||
"0x28a18"
|
||||
],
|
||||
"before": "46 2b 01",
|
||||
"after": "2b 29 02"
|
||||
},
|
||||
"tags": {
|
||||
"original": [
|
||||
{
|
||||
"kind": 69,
|
||||
"tag_offset": 21,
|
||||
"payload_offset": 23,
|
||||
"length": 4,
|
||||
"sha256": "0623ccb9b1619bd388284a438034d8cb6431964ba727d8b1c450303105735488"
|
||||
},
|
||||
{
|
||||
"kind": 77,
|
||||
"tag_offset": 27,
|
||||
"payload_offset": 33,
|
||||
"length": 369,
|
||||
"sha256": "72592809abc213253f20ac9373cb86790c78194ff314d05b051b345fe7449798"
|
||||
},
|
||||
{
|
||||
"kind": 9,
|
||||
"tag_offset": 402,
|
||||
"payload_offset": 404,
|
||||
"length": 3,
|
||||
"sha256": "709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c"
|
||||
},
|
||||
{
|
||||
"kind": 65,
|
||||
"tag_offset": 407,
|
||||
"payload_offset": 409,
|
||||
"length": 4,
|
||||
"sha256": "1fd6f3f462ab087f59033a9831ed96c8cae01b3b3f83959f81578f0e2ae4514b"
|
||||
},
|
||||
{
|
||||
"kind": 82,
|
||||
"tag_offset": 413,
|
||||
"payload_offset": 419,
|
||||
"length": 367093,
|
||||
"sha256": "b8e45b1a12925d07be9592fc4f8424b11c4b4f183ccbcbf28d3d63aeee75cdb5",
|
||||
"abc_name": "merged",
|
||||
"abc_start": 430
|
||||
},
|
||||
{
|
||||
"kind": 76,
|
||||
"tag_offset": 367512,
|
||||
"payload_offset": 367514,
|
||||
"length": 38,
|
||||
"sha256": "1fb8d55a7e2c454ecf32a91c8a8d48cc36e4811330f463a6ed209c02f13a9bf9",
|
||||
"symbols": [
|
||||
{
|
||||
"symbol_id": 0,
|
||||
"name": "net.pixvi.myrloader.MYRLoader_dyd"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": 1,
|
||||
"tag_offset": 367552,
|
||||
"payload_offset": 367554,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
},
|
||||
{
|
||||
"kind": 0,
|
||||
"tag_offset": 367554,
|
||||
"payload_offset": 367556,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
}
|
||||
],
|
||||
"modified": [
|
||||
{
|
||||
"kind": 69,
|
||||
"tag_offset": 21,
|
||||
"payload_offset": 23,
|
||||
"length": 4,
|
||||
"sha256": "0623ccb9b1619bd388284a438034d8cb6431964ba727d8b1c450303105735488"
|
||||
},
|
||||
{
|
||||
"kind": 77,
|
||||
"tag_offset": 27,
|
||||
"payload_offset": 33,
|
||||
"length": 369,
|
||||
"sha256": "72592809abc213253f20ac9373cb86790c78194ff314d05b051b345fe7449798"
|
||||
},
|
||||
{
|
||||
"kind": 9,
|
||||
"tag_offset": 402,
|
||||
"payload_offset": 404,
|
||||
"length": 3,
|
||||
"sha256": "709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c"
|
||||
},
|
||||
{
|
||||
"kind": 65,
|
||||
"tag_offset": 407,
|
||||
"payload_offset": 409,
|
||||
"length": 4,
|
||||
"sha256": "1fd6f3f462ab087f59033a9831ed96c8cae01b3b3f83959f81578f0e2ae4514b"
|
||||
},
|
||||
{
|
||||
"kind": 82,
|
||||
"tag_offset": 413,
|
||||
"payload_offset": 419,
|
||||
"length": 367090,
|
||||
"sha256": "a52752b9b4785c89941c70e9b347e28f655f4c8f9044116a4512f7dd17797426",
|
||||
"abc_name": "merged",
|
||||
"abc_start": 430
|
||||
},
|
||||
{
|
||||
"kind": 76,
|
||||
"tag_offset": 367509,
|
||||
"payload_offset": 367511,
|
||||
"length": 38,
|
||||
"sha256": "1fb8d55a7e2c454ecf32a91c8a8d48cc36e4811330f463a6ed209c02f13a9bf9",
|
||||
"symbols": [
|
||||
{
|
||||
"symbol_id": 0,
|
||||
"name": "net.pixvi.myrloader.MYRLoader_dyd"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": 1,
|
||||
"tag_offset": 367549,
|
||||
"payload_offset": 367551,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
},
|
||||
{
|
||||
"kind": 0,
|
||||
"tag_offset": 367551,
|
||||
"payload_offset": 367553,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
}
|
||||
],
|
||||
"candidate": [
|
||||
{
|
||||
"kind": 69,
|
||||
"tag_offset": 21,
|
||||
"payload_offset": 23,
|
||||
"length": 4,
|
||||
"sha256": "0623ccb9b1619bd388284a438034d8cb6431964ba727d8b1c450303105735488"
|
||||
},
|
||||
{
|
||||
"kind": 77,
|
||||
"tag_offset": 27,
|
||||
"payload_offset": 33,
|
||||
"length": 369,
|
||||
"sha256": "72592809abc213253f20ac9373cb86790c78194ff314d05b051b345fe7449798"
|
||||
},
|
||||
{
|
||||
"kind": 9,
|
||||
"tag_offset": 402,
|
||||
"payload_offset": 404,
|
||||
"length": 3,
|
||||
"sha256": "709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c"
|
||||
},
|
||||
{
|
||||
"kind": 65,
|
||||
"tag_offset": 407,
|
||||
"payload_offset": 409,
|
||||
"length": 4,
|
||||
"sha256": "1fd6f3f462ab087f59033a9831ed96c8cae01b3b3f83959f81578f0e2ae4514b"
|
||||
},
|
||||
{
|
||||
"kind": 82,
|
||||
"tag_offset": 413,
|
||||
"payload_offset": 419,
|
||||
"length": 367093,
|
||||
"sha256": "b321fb54bdc910efb25b393601e8da732265669010ef766cb93844fbdf80f12d",
|
||||
"abc_name": "merged",
|
||||
"abc_start": 430
|
||||
},
|
||||
{
|
||||
"kind": 76,
|
||||
"tag_offset": 367512,
|
||||
"payload_offset": 367514,
|
||||
"length": 38,
|
||||
"sha256": "1fb8d55a7e2c454ecf32a91c8a8d48cc36e4811330f463a6ed209c02f13a9bf9",
|
||||
"symbols": [
|
||||
{
|
||||
"symbol_id": 0,
|
||||
"name": "net.pixvi.myrloader.MYRLoader_dyd"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": 1,
|
||||
"tag_offset": 367552,
|
||||
"payload_offset": 367554,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
},
|
||||
{
|
||||
"kind": 0,
|
||||
"tag_offset": 367554,
|
||||
"payload_offset": 367556,
|
||||
"length": 0,
|
||||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ui_comparison": [
|
||||
{
|
||||
"apk": "\u7267\u7f8a\u4eba\u4e4b\u5fc3_1.9.68.apk",
|
||||
"size": 9379890,
|
||||
"sha256": "2fdf91d2106a274d236b006db55b6aa84b68d1477dae6ee35f9a9028076ed3b9",
|
||||
"matches_original": true
|
||||
},
|
||||
{
|
||||
"apk": "\u7267\u7f8a\u4eba\u4e4b\u5fc3_1.9.68_\u4f24\u5bb310\u500d_\u4e0a\u96505\u4e07.apk",
|
||||
"size": 9379890,
|
||||
"sha256": "2fdf91d2106a274d236b006db55b6aa84b68d1477dae6ee35f9a9028076ed3b9",
|
||||
"matches_original": true
|
||||
},
|
||||
{
|
||||
"apk": "\u7267\u7f8a\u4eba\u4e4b\u5fc3_1.9.68_\u4f24\u5bb310\u500d_\u4e0a\u96505\u4e07_\u4fee\u6b63\u7248.apk",
|
||||
"size": 9379890,
|
||||
"sha256": "2fdf91d2106a274d236b006db55b6aa84b68d1477dae6ee35f9a9028076ed3b9",
|
||||
"matches_original": true
|
||||
},
|
||||
{
|
||||
"apk": "\u7267\u7f8a\u4eba\u4e4b\u5fc3_1.9.68_\u73a9\u5bb6\u5c5e\u60272\u500d.apk",
|
||||
"size": 9379890,
|
||||
"sha256": "2fdf91d2106a274d236b006db55b6aa84b68d1477dae6ee35f9a9028076ed3b9",
|
||||
"matches_original": true
|
||||
},
|
||||
{
|
||||
"apk": "analysis\\device_after_two_mods.apk",
|
||||
"size": 9379890,
|
||||
"sha256": "2fdf91d2106a274d236b006db55b6aa84b68d1477dae6ee35f9a9028076ed3b9",
|
||||
"matches_original": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
"""Compare immutable loader inputs and write a separate three-byte diagnostic candidate."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import struct
|
||||
import zipfile
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
outdir = Path(__file__).parent
|
||||
audit_text = (outdir / "bytecode_20261107_01.txt").read_text(encoding="utf-8-sig")
|
||||
sections = re.split(r"(?m)^FILE ", audit_text)[1:]
|
||||
sections = {section.split(" bytes=", 1)[0]: section for section in sections}
|
||||
sha = lambda data: hashlib.sha256(data).hexdigest()
|
||||
original = (root / "analysis/MYRDyd.swf").read_bytes()
|
||||
modified = (root / "analysis/MYRDyd_packaged_main.swf").read_bytes()
|
||||
assert original[:3] == modified[:3] == b"FWS"
|
||||
|
||||
def body_rows(section):
|
||||
return {(int(tag), int(body)): (method, name, size, digest, stack, regs, scope, exceptions)
|
||||
for tag, body, method, name, size, digest, stack, regs, scope, exceptions in re.findall(
|
||||
r"(?m)^BODY tagPos=(\d+) body=(\d+) method=(\d+) name=(.*?) bytes=(\d+) sha256=(\w+) maxStack=(\d+) regs=(\d+) scope=(\S+) exceptions=(.*?) offsetErrors=", section)}
|
||||
|
||||
left = body_rows(sections["analysis/MYRDyd.swf"])
|
||||
right = body_rows(sections["analysis/MYRDyd_packaged_main.swf"])
|
||||
changed = [{"tag_pos": key[0], "body": key[1], "original": left[key], "modified": right[key]}
|
||||
for key in left.keys() | right.keys() if left.get(key) != right.get(key)]
|
||||
assert len(changed) == 1 and changed[0]["body"] == 43
|
||||
|
||||
def fix_bytes(section):
|
||||
return bytes.fromhex(re.search(r"(?m)^BODY .*name=fixComplete .*\nRAW_CODE ([0-9a-f]+)", section)[1])
|
||||
|
||||
oldcode = fix_bytes(sections["analysis/MYRDyd.swf"])
|
||||
badcode = fix_bytes(sections["analysis/MYRDyd_packaged_main.swf"])
|
||||
start = original.index(oldcode)
|
||||
assert original.find(oldcode, start + 1) == -1 and modified.index(badcode) == start
|
||||
assert original[start - 6:start] == bytes([44, 4, 3, 0, 1, 104])
|
||||
assert modified[start - 6:start] == bytes([44, 4, 3, 0, 1, 101])
|
||||
assert original[start + 0x22:start + 0x25] == bytes.fromhex("46 2b 01")
|
||||
candidate = bytearray(original)
|
||||
candidate[start + 0x22:start + 0x25] = bytes.fromhex("2b 29 02")
|
||||
changed_offsets = [i for i, (before, after) in enumerate(zip(original, candidate)) if before != after]
|
||||
assert changed_offsets == list(range(start + 0x22, start + 0x25))
|
||||
destination = outdir / "MYRDyd_resolver_bypass_diagnostic_20261107_01.swf"
|
||||
with destination.open("xb") as stream:
|
||||
stream.write(candidate)
|
||||
|
||||
def tags(data):
|
||||
nbits = data[8] >> 3
|
||||
pos = 8 + (5 + 4 * nbits + 7) // 8 + 4
|
||||
result = []
|
||||
while pos < len(data):
|
||||
tag_offset = pos
|
||||
rec, = struct.unpack_from("<H", data, pos)
|
||||
pos += 2
|
||||
kind, size = rec >> 6, rec & 63
|
||||
if size == 63:
|
||||
size, = struct.unpack_from("<I", data, pos)
|
||||
pos += 4
|
||||
payload = data[pos:pos + size]
|
||||
item = {"kind": kind, "tag_offset": tag_offset, "payload_offset": pos, "length": size, "sha256": sha(payload)}
|
||||
if kind == 82:
|
||||
zero = payload.index(0, 4)
|
||||
item.update(abc_name=payload[4:zero].decode("utf-8"), abc_start=pos + zero + 1)
|
||||
if kind == 76:
|
||||
count, = struct.unpack_from("<H", payload)
|
||||
at = 2
|
||||
symbols = []
|
||||
for _ in range(count):
|
||||
symbol, = struct.unpack_from("<H", payload, at)
|
||||
at += 2
|
||||
end = payload.index(0, at)
|
||||
symbols.append({"symbol_id": symbol, "name": payload[at:end].decode("utf-8")})
|
||||
at = end + 1
|
||||
item["symbols"] = symbols
|
||||
result.append(item)
|
||||
pos += size
|
||||
if kind == 0:
|
||||
break
|
||||
assert pos == len(data)
|
||||
return result
|
||||
|
||||
tag_rows = {"original": tags(original), "modified": tags(modified), "candidate": tags(candidate)}
|
||||
original_apk = next(p for p in sorted(root.glob("*.apk")) if p.name == "牧羊人之心_1.9.68.apk")
|
||||
with zipfile.ZipFile(original_apk) as archive:
|
||||
ui_name = "assets/ui/myrLoader.swf"
|
||||
ui = archive.read(ui_name)
|
||||
ui_path = outdir / "myrLoader_ui_inventory_20261107_01.swf"
|
||||
with ui_path.open("xb") as stream:
|
||||
stream.write(ui)
|
||||
ui_members = []
|
||||
for path in [*sorted(root.glob("*.apk")), root / "analysis/device_after_two_mods.apk"]:
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
data = archive.read(ui_name)
|
||||
ui_members.append({"apk": str(path.relative_to(root)), "size": len(data), "sha256": sha(data), "matches_original": data == ui})
|
||||
|
||||
result = {
|
||||
"changed_method_bodies": changed,
|
||||
"code_start": start, "code_start_hex": hex(start),
|
||||
"method_header_offset": start - 6, "max_stack_offset": start - 5,
|
||||
"method_header_original": original[start - 6:start].hex(" "),
|
||||
"method_header_modified": modified[start - 6:start].hex(" "),
|
||||
"original_size": len(original), "modified_size": len(modified),
|
||||
"original_sha256": sha(original), "modified_sha256": sha(modified),
|
||||
"method_region_original": oldcode[0x1a:0x27].hex(" "),
|
||||
"method_region_modified": badcode[0x1a:0x24].hex(" "),
|
||||
"prefix_identical_except_header_and_lengths": [(i, a, b) for i, (a, b) in enumerate(zip(original[:start], modified[:start])) if a != b],
|
||||
"suffix_identical_after_method": original[start + len(oldcode):] == modified[start + len(badcode):],
|
||||
"candidate": {"path": str(destination.relative_to(root)), "sha256": sha(candidate), "size": len(candidate),
|
||||
"changed_offsets": changed_offsets, "changed_offsets_hex": [hex(i) for i in changed_offsets],
|
||||
"before": original[start + 0x22:start + 0x25].hex(" "), "after": candidate[start + 0x22:start + 0x25].hex(" ")},
|
||||
"tags": tag_rows,
|
||||
"ui_comparison": ui_members,
|
||||
}
|
||||
with (outdir / "raw_compare_20261107_01.json").open("x", encoding="utf-8") as stream:
|
||||
json.dump(result, stream, indent=2)
|
||||
print(json.dumps({key: value for key, value in result.items() if key not in ("tags", "ui_comparison")}, indent=2))
|
||||
print("UI_COMPARISON " + json.dumps(ui_members, ensure_ascii=True))
|
||||
@@ -0,0 +1,10 @@
|
||||
CHECK analysis/MYRDyd.swf net.pixvi.myrloader.MYRLoaderStarter.fixComplete method=44 bytes=104
|
||||
PASS control-flow/stack errors=0
|
||||
CHECK analysis/MYRDyd_packaged_main.swf net.pixvi.myrloader.MYRLoaderStarter.fixComplete method=44 bytes=101
|
||||
STACK LIMIT at 43 stack=5/4 scope=1/1
|
||||
STACK LIMIT at 50 stack=5/4 scope=1/1
|
||||
FAIL control-flow/stack errors=2
|
||||
CHECK analysis/loader_audit/MYRDyd_resolver_bypass_diagnostic_20261107_01.swf net.pixvi.myrloader.MYRLoaderStarter.fixComplete method=44 bytes=104
|
||||
PASS control-flow/stack errors=0
|
||||
CHECK analysis/loader_audit/MYRDyd_explicit_package_diagnostic_20261107_01.swf net.pixvi.myrloader.MYRLoaderStarter.fixComplete method=44 bytes=104
|
||||
PASS control-flow/stack errors=0
|
||||
Reference in New Issue
Block a user