@arms__rum-electron@0.0.3.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. diff --git a/dist/index.mjs b/dist/index.mjs
  2. index d26925cd014c42b6c6d470f9d2d4d75196203339..ce203cba549db3b21cddf71bb7a2c74190319dde 100644
  3. --- a/dist/index.mjs
  4. +++ b/dist/index.mjs
  5. @@ -505,6 +505,48 @@ const p = /* @__PURE__ */ new WeakMap(), _ = class _ {
  6. /** 初始化窗口期时长(ms),用于合并框架路由重定向 */
  7. F(_, "INITIAL_LOAD_WINDOW_MS", 200);
  8. let kA = _;
  9. +// ZCode 修复:main logger 把公共前缀、业务消息和上下文作为多个 console.error 参数传入。
  10. +// SDK 原先只采第一个参数,导致 ARMS 里只剩 [timestamp] [pid] [source],完全丢失错误正文。
  11. +// 采集边界统一去前缀、安全序列化、脱敏和截断,避免为了监控改坏 console 的原生多参数语义。
  12. +const zcodeConsoleErrorMaxLength = 2e3;
  13. +const zcodeMainLogPrefixPattern = /^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\]\s+\[pid:\d+\]\s+\[[a-z][a-z0-9_-]*\]\s*$/;
  14. +const zcodeConsoleSensitiveKeyPattern = /(?:api[-_]?key|authorization|cookie|credential|password|secret|token)/i;
  15. +const zcodeConsoleSensitiveAssignmentPattern = /(["']?(?:api[-_]?key|authorization|cookie|credential|password|secret|token)["']?\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;}]+)/gi;
  16. +const zcodeConsoleAuthSchemePattern = /\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]+/gi;
  17. +const zcodeConsoleApiKeyPattern = /\b(sk-)[A-Za-z0-9_-]{16,}\b/gi;
  18. +function zcodeRedactConsoleErrorText(I) {
  19. + return I.replace(zcodeConsoleSensitiveAssignmentPattern, "$1<redacted>").replace(zcodeConsoleAuthSchemePattern, "$1 <redacted>").replace(zcodeConsoleApiKeyPattern, "$1<redacted>");
  20. +}
  21. +function zcodeFormatConsoleErrorValue(I) {
  22. + if (typeof I == "string") return zcodeRedactConsoleErrorText(I);
  23. + if (typeof I == "bigint" || typeof I == "number" || typeof I == "boolean" || typeof I == "symbol" || I == null)
  24. + return String(I);
  25. + if (typeof I == "undefined") return "undefined";
  26. + if (typeof I == "function") return `[Function${I.name ? ` ${I.name}` : ""}]`;
  27. + const A = new WeakSet();
  28. + try {
  29. + const Q = JSON.stringify(I, (g, C) => {
  30. + if (g && zcodeConsoleSensitiveKeyPattern.test(g)) return "<redacted>";
  31. + if (typeof C == "string") return zcodeRedactConsoleErrorText(C);
  32. + if (typeof C == "bigint") return String(C);
  33. + if (typeof C == "function") return `[Function${C.name ? ` ${C.name}` : ""}]`;
  34. + if (C && typeof C == "object") {
  35. + if (A.has(C)) return "[Circular]";
  36. + A.add(C);
  37. + }
  38. + return C;
  39. + });
  40. + return typeof Q == "string" ? Q : String(I);
  41. + } catch {
  42. + return "[Unserializable Object]";
  43. + }
  44. +}
  45. +function zcodeFormatConsoleErrorArgs(I) {
  46. + const A = Array.from(I || []);
  47. + typeof A[0] == "string" && zcodeMainLogPrefixPattern.test(A[0]) && A.shift();
  48. + const Q = zcodeRedactConsoleErrorText(A.map(zcodeFormatConsoleErrorValue).filter((g) => g.length > 0).join(" ").trim());
  49. + return Q.slice(0, zcodeConsoleErrorMaxLength);
  50. +}
  51. class sQ {
  52. constructor() {
  53. F(this, "name", "exception-collector");
  54. @@ -551,8 +593,13 @@ class sQ {
  55. hackOrigin() {
  56. const A = this, { collectors: Q = {} } = this.ctx.getConfig();
  57. Q.jsError !== !1 && (process.on("uncaughtException", this.uncaughtExceptionHandler), process.on("unhandledRejection", this.unhandledRejectionHandler)), Q.consoleError !== !1 && $A(console, "error", function(...g) {
  58. - const C = g.find((B) => B instanceof Error) || g[0];
  59. - A.errorHandle(C, "console.error");
  60. + const C = g.find((B) => B instanceof Error);
  61. + if (C) {
  62. + A.errorHandle(C, "console.error");
  63. + return;
  64. + }
  65. + const B = zcodeFormatConsoleErrorArgs(g);
  66. + B && A.errorHandle(B, "console.error");
  67. });
  68. }
  69. destroy() {
  70. @@ -794,6 +841,86 @@ async function xQ(I) {
  71. const A = await LQ(I, null);
  72. return JSON.parse(A);
  73. }
  74. +// ZCode 修复:旧版 WASM 没有透传 Crashpad 进程角色。minidump 还包含任意内存片段,
  75. +// 因此不能全文件搜索 process_type 字节;必须从 Crashpad info stream 沿 RVA 读取结构化
  76. +// annotation,避免 renderer 内存里的同名字节被误判成 browser 并污染 Native Crash 指标。
  77. +const zcodeCrashpadInfoStreamType = 1129316353;
  78. +function zcodeHasDumpRange(I, A, Q) {
  79. + return Number.isSafeInteger(A) && Number.isSafeInteger(Q) && A >= 0 && Q >= 0 && A <= I.length - Q;
  80. +}
  81. +function zcodeReadDumpLocation(I, A) {
  82. + if (!zcodeHasDumpRange(I, A, 8)) return;
  83. + const Q = I.readUInt32LE(A), g = I.readUInt32LE(A + 4);
  84. + if (Q === 0 || g === 0 || !zcodeHasDumpRange(I, g, Q)) return;
  85. + return { size: Q, rva: g };
  86. +}
  87. +function zcodeReadDumpString(I, A, Q, g) {
  88. + if (!zcodeHasDumpRange(I, A, 4)) return;
  89. + const C = I.readUInt32LE(A), B = A + 4;
  90. + if (C < 1 || C > Q || !zcodeHasDumpRange(I, B, C + (g ? 1 : 0))) return;
  91. + if (g && I[B + C] !== 0) return;
  92. + return I.subarray(B, B + C).toString("utf8");
  93. +}
  94. +function zcodeRememberProcessType(I, A, Q) {
  95. + if (A !== "process_type" && A !== "ptype") return;
  96. + const g = Q.trim().toLowerCase();
  97. + if (/^[a-z][a-z0-9_-]*$/.test(g)) I.add(g);
  98. +}
  99. +function zcodeReadSimpleAnnotations(I, A, Q) {
  100. + if (!A || A.size < 4) return;
  101. + const g = I.readUInt32LE(A.rva);
  102. + if (g > Math.floor((A.size - 4) / 8)) return;
  103. + for (let C = 0; C < g; C += 1) {
  104. + const B = A.rva + 4 + C * 8, E = zcodeReadDumpString(I, I.readUInt32LE(B), 64, !0);
  105. + if (E !== "process_type" && E !== "ptype") continue;
  106. + const D = zcodeReadDumpString(I, I.readUInt32LE(B + 4), 64, !0);
  107. + if (D) zcodeRememberProcessType(Q, E, D);
  108. + }
  109. +}
  110. +function zcodeReadAnnotationObjects(I, A, Q) {
  111. + if (!A || A.size < 4) return;
  112. + const g = I.readUInt32LE(A.rva);
  113. + if (g > Math.floor((A.size - 4) / 12)) return;
  114. + for (let C = 0; C < g; C += 1) {
  115. + const B = A.rva + 4 + C * 12;
  116. + if (I.readUInt16LE(B + 4) !== 1 || I.readUInt16LE(B + 6) !== 0) continue;
  117. + const E = zcodeReadDumpString(I, I.readUInt32LE(B), 64, !0);
  118. + if (E !== "process_type" && E !== "ptype") continue;
  119. + const D = zcodeReadDumpString(I, I.readUInt32LE(B + 8), 64, !1);
  120. + if (D) zcodeRememberProcessType(Q, E, D);
  121. + }
  122. +}
  123. +function zcodeReadModuleAnnotations(I, A, Q) {
  124. + if (!A || A.size < 20 || I.readUInt32LE(A.rva) < 1) return;
  125. + zcodeReadSimpleAnnotations(I, zcodeReadDumpLocation(I, A.rva + 12), Q);
  126. + if (A.size >= 28)
  127. + zcodeReadAnnotationObjects(I, zcodeReadDumpLocation(I, A.rva + 20), Q);
  128. +}
  129. +function zcodeReadCrashpadInfo(I, A, Q) {
  130. + if (!A || A.size < 52 || I.readUInt32LE(A.rva) < 1) return;
  131. + zcodeReadSimpleAnnotations(I, zcodeReadDumpLocation(I, A.rva + 36), Q);
  132. + const g = zcodeReadDumpLocation(I, A.rva + 44);
  133. + if (!g || g.size < 4) return;
  134. + const C = I.readUInt32LE(g.rva);
  135. + if (C > Math.floor((g.size - 4) / 12)) return;
  136. + for (let B = 0; B < C; B += 1) {
  137. + const E = g.rva + 4 + B * 12;
  138. + zcodeReadModuleAnnotations(I, zcodeReadDumpLocation(I, E + 4), Q);
  139. + }
  140. +}
  141. +function readCrashProcessType(I) {
  142. + const Q = Buffer.from(I.buffer, I.byteOffset, I.byteLength);
  143. + if (!zcodeHasDumpRange(Q, 0, 32) || Q.toString("ascii", 0, 4) !== "MDMP") return;
  144. + const A = Q.readUInt32LE(8), g = Q.readUInt32LE(12);
  145. + if (A < 1 || A > 4096 || !zcodeHasDumpRange(Q, g, A * 12)) return;
  146. + const C = new Set();
  147. + for (let B = 0; B < A; B += 1) {
  148. + const E = g + B * 12;
  149. + if (Q.readUInt32LE(E) === zcodeCrashpadInfoStreamType)
  150. + zcodeReadCrashpadInfo(Q, zcodeReadDumpLocation(Q, E + 4), C);
  151. + }
  152. + if (C.size === 1) return C.values().next().value;
  153. +}
  154. class mQ {
  155. constructor() {
  156. F(this, "name", "crash-collector");
  157. @@ -824,20 +951,22 @@ class mQ {
  158. try {
  159. const C = await m.stat(g), B = C.birthtimeMs || C.mtimeMs;
  160. let E = null;
  161. + let D = null;
  162. try {
  163. const U = new Uint8Array(await m.readFile(g));
  164. + D = readCrashProcessType(U);
  165. E = await xQ(U);
  166. } catch {
  167. }
  168. - const D = E ? bQ(E, B) : uQ(g, B);
  169. - this.sendEvent(D), await m.unlink(g);
  170. + const U = E ? bQ(E, B, D) : uQ(g, B);
  171. + this.sendEvent(U), await m.unlink(g);
  172. } catch {
  173. }
  174. }
  175. destroy() {
  176. }
  177. }
  178. -function bQ(I, A) {
  179. +function bQ(I, A, D) {
  180. const Q = jQ(I), g = Q.find((C) => C.crashed);
  181. return {
  182. event_type: T.EXCEPTION,
  183. @@ -853,7 +982,8 @@ function bQ(I, A) {
  184. meta: {
  185. code_type: I.system_info.cpu,
  186. process: i.getName(),
  187. - exception_type: I.crash_info.type
  188. + exception_type: I.crash_info.type,
  189. + ...(D ? { process_type: D } : {})
  190. },
  191. threads: Q,
  192. binary_images: _Q(I)