{"record":{"id":"f3cc52a7d1b3ddaf","repo":"huiyadanli/RevokeMsgPatcher","slug":"error","errorCode":null,"errorMessage":"查询串与替换串长度不同!","messagePattern":"查询串与替换串长度不同!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"RevokeMsgPatcher.Assistant/FormAssisant.cs","lineNumber":58,"sourceCode":"            byte[] replaceBytes = ByteUtil.HexStringToByteArray(\"1C E9 9D 00 00 00 8B 45 E8 8D 55 EC 52 89 5D EC EB 09 90 90 90 8B 08 50 FF 51 78 85 C0 79 2D 8D 45 0C C7 45 0C\");\n            //int[] indexs = FuzzyMatcher.MatchAll(fileByteArray, searchBytes);\n            int[] indexs = FuzzyMatcher.MatchNotReplaced(fileByteArray, searchBytes, replaceBytes);\n            txtInfo.AppendText(\"查找结果位置:\" + string.Join(\",\", indexs) + Environment.NewLine);\n            // 371130\n\n            List<Change> changes = ComputChanges(indexs, searchBytes, replaceBytes);\n            foreach (Change c in changes)\n            {\n                txtInfo.AppendText(\"替换位置:\" + Convert.ToString(c.Position, 16) + \" 替换内容:\" + ByteUtil.ByteArrayToHexString(c.Content) + Environment.NewLine);\n            }\n\n        }\n\n        public static List<Change> ComputChanges(int[] indexs, byte[] searchBytes, byte[] replaceBytes)\n        {\n            if (searchBytes.Length != replaceBytes.Length)\n            {\n                throw new Exception(\"查询串与替换串长度不同!\");\n            }\n            // 一个替换串存在多个替换点的情况\n            List<Change> changeOffsets = new List<Change>(); // 查询串与替换串变化偏移\n            List<byte> diff = null;\n            for (int i = 0; i < searchBytes.Length; i++)\n            {\n                if (searchBytes[i] != replaceBytes[i])\n                {\n                    if (diff == null)\n                    {\n                        diff = new List<byte>();\n                        Change offset = new Change\n                        {\n                            Position = i\n                        };\n                        changeOffsets.Add(offset);\n                    }\n                    diff.Add(replaceBytes[i]);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/huiyadanli/RevokeMsgPatcher/blob/89cbbb3f0cc896d5d092de0199a635c5c39944b6/RevokeMsgPatcher.Assistant/FormAssisant.cs#L40-L76","documentation":"ComputChanges (in the RevokeMsgPatcher.Assistant authoring tool) diffs a search byte array against a replace byte array to produce per-match Change records. Because it patches bytes in place over an identical byte range, it requires searchBytes and replaceBytes to be the same length; it throws a plain Exception if their Length properties differ. This is an authoring/data error, not an end-user runtime condition.","triggerScenarios":"Calling FormAssisant.ComputChanges(indexs, searchBytes, replaceBytes) where the two byte arrays differ in length. Concretely: hand-editing the hex strings in btnSearch_Click so the search and replace strings are out of sync, or one having a stray space / odd character count after ByteUtil.HexStringToByteArray.","commonSituations":"Authoring a new patch in the Assistant tool; pasting a 32-byte search pattern but a 31- or 33-byte replacement; hex strings with inconsistent whitespace or an odd number of nibbles.","solutions":["Make searchBytes and replaceBytes the same length (in-place hex edit requires matching length).","Re-derive both arrays from equal-length hex strings, stripping spaces, and confirm both have an even nibble count.","Add a length guard before calling ComputChanges and log both lengths to pinpoint the mismatch."],"exampleFix":"// before\nbyte[] searchBytes  = ByteUtil.HexStringToByteArray(\"AA BB CC\");      // 3 bytes\nbyte[] replaceBytes = ByteUtil.HexStringToByteArray(\"AA BB CC DD\");   // 4 bytes -> throws\nList<Change> changes = ComputChanges(indexs, searchBytes, replaceBytes);\n\n// after\nbyte[] searchBytes  = ByteUtil.HexStringToByteArray(\"AA BB CC DD\"); // 4\nbyte[] replaceBytes = ByteUtil.HexStringToByteArray(\"AA BB CC DD\"); // 4\nif (searchBytes.Length != replaceBytes.Length)\n    throw new ArgumentException($\"len mismatch {searchBytes.Length} vs {replaceBytes.Length}\");\nList<Change> changes = ComputChanges(indexs, searchBytes, replaceBytes);","handlingStrategy":"validation","validationCode":"byte[] searchBytes = ByteUtil.HexStringToByteArray(searchHex);\nbyte[] replaceBytes = ByteUtil.HexStringToByteArray(replaceHex);\nif (searchBytes.Length != replaceBytes.Length)\n{\n    txtInfo.AppendText($\"长度不同: search={searchBytes.Length} replace={replaceBytes.Length}{Environment.NewLine}\");\n    return;\n}\nList<Change> changes = ComputChanges(indexs, searchBytes, replaceBytes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive both byte arrays from equal-length hex strings in the authoring tool.","Assert searchBytes.Length == replaceBytes.Length immediately after conversion.","Treat any length mismatch as a patch-data bug, never auto-pad."],"tags":["authoring","data-validation","assistant"],"backgroundTag":null,"analyzedSha":"89cbbb3f0cc896d5d092de0199a635c5c39944b6","analyzedAt":"2026-08-13T10:37:37.073Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}