-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructured-parser.js
More file actions
947 lines (757 loc) · 34.7 KB
/
structured-parser.js
File metadata and controls
947 lines (757 loc) · 34.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
"use strict";
// IPS Crash Report Structured Parser
class StructuredIPSParser {
constructor(ipsContent) {
this.ipsContent = ipsContent;
this.metadata = null;
this.report = null;
}
parse() {
try {
const lines = this.ipsContent.trim().split('\n');
if (lines.length < 2) {
throw new Error('Invalid IPS file format. Expected at least 2 lines (metadata + report).');
}
// thanks to example in
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter
const bigIntJsonReviver = (key, value, context) => {
// convert all numbers for consistency
if (typeof value === 'number') {
// Ignore the value because it has already lost precision
return BigInt(context.source);
}
return value;
}
// Parse metadata (first line)
this.metadata = JSON.parse(lines[0], bigIntJsonReviver);
// Parse crash report (remaining lines)
const reportLines = lines.slice(1).join('\n');
this.report = JSON.parse(reportLines, bigIntJsonReviver);
// Verify it's a crash report
if (this.metadata.bug_type !== "309") {
throw new Error(`Not a crash report (bug_type: ${this.metadata.bug_type}). Expected bug_type "309".`);
}
return true;
} catch (error) {
throw new Error(`Failed to parse IPS file: ${error.message}`);
}
}
// Helper methods for creating DOM elements
createElement(tag, className, textContent) {
const el = document.createElement(tag);
if (className) el.className = className;
if (textContent !== undefined) el.textContent = textContent;
return el;
}
createSpan(className, textContent) {
return this.createElement('span', className, textContent);
}
createDiv(className, textContent) {
return this.createElement('div', className, textContent);
}
createAddress(addr) {
return this.createSpan('addr', `0x${addr.toString(16).padStart(16, '0')}`);
}
createNumber(num) {
return this.createSpan('number', String(num));
}
createSymbol(sym) {
return this.createSpan('symbol', sym);
}
formatReport() {
if (!this.metadata || !this.report) {
throw new Error('Report not parsed. Call parse() first.');
}
const container = document.createDocumentFragment();
// Process Information
container.appendChild(this.formatProcessInfo());
// Exception Information
container.appendChild(this.formatException());
// Application Specific Information
if (this.report.asi) {
container.appendChild(this.formatASI());
}
// Application Specific Backtraces
if (this.report.asiBacktraces && this.report.asiBacktraces.length > 0) {
this.report.asiBacktraces.forEach((backtrace, index) => {
container.appendChild(this.formatASIBacktrace(backtrace, index));
});
}
// Last Exception Backtrace
if (this.report.lastExceptionBacktrace) {
container.appendChild(this.formatLastExceptionBacktrace());
}
// Threads
container.appendChild(this.formatThreads());
// Binary Images
container.appendChild(this.formatBinaryImages());
// External Modification Summary
const extModsSection = this.formatExtMods();
if (extModsSection) {
container.appendChild(extModsSection);
}
// VM Summary
if (this.report.vmSummary) {
container.appendChild(this.formatVMSummary());
}
// Filtered Log
if (this.report.filteredLog && this.report.filteredLog.length > 0) {
container.appendChild(this.formatFilteredLog());
}
return container;
}
formatProcessInfo() {
const bundleInfo = this.report.bundleInfo || {};
const buildInfo = this.report.buildInfo || {};
const storeInfo = this.report.storeInfo || {};
const osVersion = this.report.osVersion || {};
const section = this.createDiv('crash-section');
const details = this.createElement('details');
details.open = true;
const summary = this.createElement('summary', null, 'Process Information');
details.appendChild(summary);
const grid = this.createDiv('info-grid');
const addRow = (label, value) => {
grid.appendChild(this.createDiv('info-label', label + ':'));
const valueDiv = this.createDiv('info-value');
if (typeof value === 'string') {
valueDiv.textContent = value;
} else {
valueDiv.appendChild(value);
}
grid.appendChild(valueDiv);
};
const procValue = document.createDocumentFragment();
procValue.append(this.report.procName || 'Unknown', ' [', this.createNumber(this.report.pid || 0), ']');
addRow('Process', procValue);
addRow('Path', this.report.procPath || 'Unknown');
addRow('Identifier', bundleInfo.CFBundleIdentifier || this.report.procName || 'Unknown');
// Version formatting
const hasVersion = bundleInfo.CFBundleShortVersionString || bundleInfo.CFBundleVersion;
if (hasVersion) {
addRow('Version', `${bundleInfo.CFBundleShortVersionString || '?'} (${bundleInfo.CFBundleVersion || '?'})`);
} else {
addRow('Version', '???');
}
if (bundleInfo.DTAppStoreToolsBuild) {
addRow('AppStoreTools', bundleInfo.DTAppStoreToolsBuild);
}
if (storeInfo.applicationVariant) {
addRow('AppVariant', storeInfo.applicationVariant);
}
if (this.report.isBeta !== undefined) {
addRow('Beta', this.report.isBeta ? 'YES' : 'NO');
}
// Build Info
if (buildInfo.ProjectName && buildInfo.SourceVersion && buildInfo.BuildVersion) {
addRow('Build Info', `${buildInfo.ProjectName}-${buildInfo.SourceVersion}~${buildInfo.BuildVersion}`);
}
const translatedLabel = this.report.translated ? 'Translated' : 'Native';
addRow('Code Type', `${this.report.cpuType || 'Unknown'} (${translatedLabel})`);
if (this.report.procRole) {
addRow('Role', this.report.procRole);
}
const parentValue = document.createDocumentFragment();
parentValue.append(this.report.parentProc || 'Unknown');
if (this.report.parentPid !== undefined) {
parentValue.append(' [', this.createNumber(this.report.parentPid), ']');
}
addRow('Parent Process', parentValue);
if (this.report.coalitionName) {
const coalValue = document.createDocumentFragment();
coalValue.append(this.report.coalitionName);
if (this.report.coalitionID !== undefined) {
coalValue.append(' [', this.createNumber(this.report.coalitionID), ']');
}
addRow('Coalition', coalValue);
}
if (this.report.responsibleProc) {
const respValue = document.createDocumentFragment();
respValue.append(this.report.responsibleProc);
if (this.report.responsiblePid !== undefined) {
respValue.append(' [', this.createNumber(this.report.responsiblePid), ']');
}
addRow('Responsible Process', respValue);
}
if (this.report.userID !== undefined) {
addRow('User ID', String(this.report.userID));
}
addRow('Date/Time', this.report.captureTime || 'Unknown');
if (this.report.procLaunch) {
addRow('Launch Time', this.report.procLaunch);
}
if (this.report.procStartAbsTime !== undefined) {
addRow('Process Start (Absolute)', String(this.report.procStartAbsTime));
}
if (this.report.procExitAbsTime !== undefined) {
addRow('Process Exit (Absolute)', String(this.report.procExitAbsTime));
}
if (this.report.modelCode) {
addRow('Hardware Model', this.report.modelCode);
}
if (this.report.codeName) {
addRow('Device Model', this.report.codeName);
}
addRow('OS Version', `${osVersion.train || 'Unknown'} (${osVersion.build || 'Unknown'})`);
if (osVersion.releaseType) {
addRow('Release Type', osVersion.releaseType);
}
if (this.report.basebandVersion) {
addRow('Baseband Version', this.report.basebandVersion);
}
if (this.report.bootSessionUUID) {
addRow('Boot Session UUID', this.report.bootSessionUUID);
}
if (this.report.sleepWakeUUID) {
addRow('Sleep/Wake UUID', this.report.sleepWakeUUID);
}
if (storeInfo.deviceIdentifierForVendor && storeInfo.entitledBeta) {
addRow('Beta Identifier', storeInfo.deviceIdentifierForVendor);
}
if (this.report.crashReporterKey) {
addRow('Crash Reporter Key', this.report.crashReporterKey);
}
if (this.report.systemID) {
addRow('UDID', this.report.systemID);
}
if (this.report.incident) {
addRow('Incident ID', this.report.incident);
}
if (this.report.uptime !== undefined) {
const uptimeValue = document.createDocumentFragment();
uptimeValue.append(this.createNumber(this.report.uptime), ' seconds');
addRow('Uptime', uptimeValue);
}
if (this.report.wakeTime !== undefined) {
const wakeValue = document.createDocumentFragment();
wakeValue.append(this.createNumber(this.report.wakeTime), ' seconds');
addRow('Time Since Wake', wakeValue);
}
if (this.report.sip !== undefined) {
addRow('System Integrity Protection', this.report.sip);
}
if (this.report.developerMode !== undefined) {
addRow('Developer Mode', this.report.developerMode ? 'enabled' : 'disabled');
}
if (this.report.appleIntelligenceStatus) {
const aiStatus = this.report.appleIntelligenceStatus;
const statusText = `${aiStatus.state || 'unknown'}${aiStatus.reasons ? ' (' + aiStatus.reasons.join(', ') + ')' : ''}`;
addRow('Apple Intelligence', statusText);
}
if (this.report.deployVersion !== undefined) {
addRow('Deploy Version', String(this.report.deployVersion));
}
if (this.report.throttleTimeout !== undefined) {
addRow('Throttle Timeout', String(this.report.throttleTimeout));
}
if (this.report.codeSigningMonitor !== undefined) {
addRow('Code Signing Monitor', String(this.report.codeSigningMonitor));
}
if (this.report.codeSigningID !== undefined) {
addRow('Code Signing ID', this.report.codeSigningID || '(none)');
}
if (this.report.codeSigningTeamID !== undefined) {
addRow('Code Signing Team ID', this.report.codeSigningTeamID || '(none)');
}
if (this.report.codeSigningFlags !== undefined) {
addRow('Code Signing Flags', `0x${this.report.codeSigningFlags.toString(16)}`);
}
if (this.report.codeSigningValidationCategory !== undefined) {
addRow('Code Signing Validation', String(this.report.codeSigningValidationCategory));
}
if (this.report.codeSigningTrustLevel !== undefined) {
addRow('Code Signing Trust Level', String(this.report.codeSigningTrustLevel));
}
if (this.report.codeSigningAuxiliaryInfo !== undefined) {
addRow('Code Signing Auxiliary', `0x${this.report.codeSigningAuxiliaryInfo.toString(16)}`);
}
if (this.report.bootProgressRegister !== undefined) {
addRow('Boot Progress Register', this.report.bootProgressRegister);
}
if (this.report.wasUnlockedSinceBoot !== undefined) {
addRow('Unlocked Since Boot', this.report.wasUnlockedSinceBoot ? 'YES' : 'NO');
}
if (this.report.isLocked !== undefined) {
addRow('Currently Locked', this.report.isLocked ? 'YES' : 'NO');
}
details.appendChild(grid);
section.appendChild(details);
return section;
}
formatException() {
const ex = this.report.exception || {};
const term = this.report.termination;
const section = this.createDiv('crash-section');
const details = this.createElement('details');
details.open = true;
const summary = this.createElement('summary', null, 'Exception Information');
details.appendChild(summary);
const exceptionInfo = this.createDiv('exception-info');
const exType = this.createDiv('exception-type');
exType.textContent = ex.type || 'Unknown';
if (ex.signal) {
exType.textContent += ` (${ex.signal})`;
}
exceptionInfo.appendChild(exType);
if (ex.subtype !== undefined) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Subtype: ${ex.subtype}`));
}
if (ex.codes !== undefined) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Codes: ${ex.codes}`));
}
if (ex.message) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Message: ${ex.message}`));
}
if (this.report.isSimulated) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Note: SIMULATED (this is NOT a crash)`));
}
if (this.report.isCorpse) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Note: EXC_CORPSE_NOTIFY`));
}
if (this.report.exceptionReason && this.report.exceptionReason.composed_message) {
exceptionInfo.appendChild(this.createDiv('exception-detail', `Reason: ${this.report.exceptionReason.composed_message}`));
}
if (term) {
const termDetail = this.createDiv('exception-detail spaced');
const termFrag = document.createDocumentFragment();
termFrag.append(
'Termination: Namespace ',
term.namespace || 'Unknown',
', Code ',
this.createNumber(term.code || 0)
);
if (term.indicator) {
termFrag.append(', ', term.indicator);
}
termDetail.appendChild(termFrag);
exceptionInfo.appendChild(termDetail);
// Termination reasons (detailed error messages)
if (term.reasons && term.reasons.length > 0) {
term.reasons.forEach(reason => {
exceptionInfo.appendChild(this.createDiv('exception-detail', reason));
});
}
// Termination details (e.g., "terminated at launch; ignore backtrace")
if (term.details && term.details.length > 0) {
term.details.forEach(detail => {
exceptionInfo.appendChild(this.createDiv('exception-detail', detail));
});
}
if (term.byProc) {
const procFrag = document.createDocumentFragment();
procFrag.append('Terminating Process: ', term.byProc, ' [', this.createNumber(term.byPid || 0), ']');
const procDetail = this.createDiv('exception-detail');
procDetail.appendChild(procFrag);
exceptionInfo.appendChild(procDetail);
}
}
if (this.report.vmRegionInfo) {
const vmDetail = this.createDiv('exception-detail spaced');
vmDetail.style.whiteSpace = 'pre-wrap';
vmDetail.textContent = `VM Region Info: ${this.report.vmRegionInfo}`;
exceptionInfo.appendChild(vmDetail);
}
if (this.report.instructionByteStream) {
const instDetail = this.createDiv('exception-detail spaced');
const inst = this.report.instructionByteStream;
const instFrag = document.createDocumentFragment();
instFrag.append('Instruction Bytes:');
if (inst.beforePC) {
instFrag.append('\n Before PC: ', inst.beforePC);
}
if (inst.atPC) {
instFrag.append('\n At PC: ', inst.atPC);
}
instDetail.appendChild(instFrag);
exceptionInfo.appendChild(instDetail);
}
if (this.report.faultingThread !== undefined) {
const threads = this.report.threads || [];
const faultingThread = threads.find(t => t.triggered);
const dispatchQueue = faultingThread?.queue;
const faultDetail = this.createDiv('exception-detail spaced');
const faultFrag = document.createDocumentFragment();
faultFrag.append('Faulting Thread: ', this.createNumber(this.report.faultingThread));
if (dispatchQueue) {
faultFrag.append(', Dispatch Queue: ', dispatchQueue);
}
faultDetail.appendChild(faultFrag);
exceptionInfo.appendChild(faultDetail);
}
details.appendChild(exceptionInfo);
section.appendChild(details);
return section;
}
formatASI() {
const section = this.createDiv('crash-section');
const details = this.createElement('details');
details.open = true;
const summary = this.createElement('summary', null, 'Application Specific Information');
details.appendChild(summary);
const grid = this.createDiv('info-grid');
for (const [key, value] of Object.entries(this.report.asi)) {
if (Array.isArray(value)) {
value.forEach(v => {
grid.appendChild(this.createDiv('info-label', key + ':'));
grid.appendChild(this.createDiv('info-value', v));
});
} else {
grid.appendChild(this.createDiv('info-label', key + ':'));
grid.appendChild(this.createDiv('info-value', String(value)));
}
}
details.appendChild(grid);
section.appendChild(details);
return section;
}
formatASIBacktrace(backtrace, index) {
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, `Application Specific Backtrace ${index}`);
details.appendChild(summary);
const pre = this.createElement('pre', 'asi-backtrace');
pre.textContent = backtrace;
details.appendChild(pre);
section.appendChild(details);
return section;
}
formatLastExceptionBacktrace() {
const backtrace = this.report.lastExceptionBacktrace;
if (!backtrace || backtrace.length === 0) return null;
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, 'Last Exception Backtrace');
details.appendChild(summary);
const container = this.createDiv('section-container');
backtrace.forEach((frame, index) => {
const imageInfo = this.report.usedImages[frame.imageIndex];
const imageName = imageInfo ? imageInfo.name : 'Unknown';
const address = (imageInfo?.base || 0n) + frame.imageOffset;
const stackFrame = this.createDiv('stack-frame');
stackFrame.appendChild(this.createDiv('frame-index', String(index)));
stackFrame.appendChild(this.createDiv('frame-image', imageName));
const frameDetails = this.createDiv('frame-details');
frameDetails.appendChild(this.createAddress(address));
if (frame.symbol) {
frameDetails.append(' ', this.createSymbol(frame.symbol));
if (frame.symbolLocation !== undefined) {
const offset = this.createSpan('offset');
offset.append('+ ', this.createNumber(frame.symbolLocation));
frameDetails.append(' ', offset);
}
}
stackFrame.appendChild(frameDetails);
container.appendChild(stackFrame);
});
details.appendChild(container);
section.appendChild(details);
return section;
}
formatThreads() {
const threads = this.report.threads || [];
const section = this.createDiv('crash-section');
const details = this.createElement('details');
details.open = true;
const summary = this.createElement('summary', null, 'Threads');
details.appendChild(summary);
const threadList = this.createDiv('thread-list');
threads.forEach((thread) => {
const isCrashed = thread.triggered;
const threadItem = this.createDiv(isCrashed ? 'thread-item crashed' : 'thread-item');
const threadDetails = this.createElement('details');
if (isCrashed) {
threadDetails.open = true;
}
const threadSummary = this.createElement('summary', 'thread-header');
const summaryFrag = document.createDocumentFragment();
summaryFrag.append('Thread ', this.createNumber(thread.id));
if (thread.name) {
summaryFrag.append(' - ', thread.name);
}
if (thread.queue) {
summaryFrag.append(' (', thread.queue, ')');
}
if (isCrashed) {
summaryFrag.append(' ⚠️ CRASHED');
}
threadSummary.appendChild(summaryFrag);
threadDetails.appendChild(threadSummary);
// Stack frames
if (thread.frames && thread.frames.length > 0) {
const framesContainer = this.createDiv('frames-container');
thread.frames.forEach((frame, index) => {
const imageInfo = this.report.usedImages[frame.imageIndex];
const imageName = imageInfo ? imageInfo.name : 'Unknown';
const address = (imageInfo?.base || 0n) + frame.imageOffset;
const stackFrame = this.createDiv('stack-frame');
stackFrame.appendChild(this.createDiv('frame-index', String(index)));
stackFrame.appendChild(this.createDiv('frame-image', imageName));
const frameDetails = this.createDiv('frame-details');
frameDetails.appendChild(this.createAddress(address));
if (frame.symbol) {
frameDetails.append(' ', this.createSymbol(frame.symbol));
if (frame.symbolLocation !== undefined) {
const offset = this.createSpan('offset');
offset.append('+ ', this.createNumber(frame.symbolLocation));
frameDetails.append(' ', offset);
}
}
stackFrame.appendChild(frameDetails);
framesContainer.appendChild(stackFrame);
});
threadDetails.appendChild(framesContainer);
}
// Thread state for crashed thread
if (isCrashed && thread.threadState) {
threadDetails.appendChild(this.formatThreadState(thread.threadState));
}
threadItem.appendChild(threadDetails);
threadList.appendChild(threadItem);
});
details.appendChild(threadList);
section.appendChild(details);
return section;
}
formatThreadState(state) {
if (!state) return null;
const container = this.createDiv('thread-state-container');
const header = this.createElement('h4', 'thread-state-header');
let registers = [];
switch (state.flavor) {
case 'ARM_THREAD_STATE64':
header.textContent = 'ARM Thread State (64-bit)';
if (state.x) {
for (let i = 0; i < state.x.length; i++) {
registers.push({ name: 'x' + i, object: state.x[i] });
}
}
const namedRegs = [
'fp', 'lr', 'sp', 'pc', 'cpsr',
'far', 'esr'
];
namedRegs.forEach(regName => {
if (state[regName]) {
registers.push({ name: regName, object: state[regName] });
}
});
break;
case 'x86_THREAD_STATE':
header.textContent = 'X86 Thread State (64-bit)';
const x86Regs = [
'rax', 'rbx', 'rcx', 'rdx', 'rdi', 'rsi', 'rbp', 'rsp',
'r8', 'r9', 'r10', 'r11', 'r12', 'r13', 'r14', 'r15',
'rip', 'rflags', 'cr2'
];
x86Regs.forEach(regName => {
if (state[regName]) {
const displayName = regName === 'rflags' ? 'rfl' : regName;
registers.push({ name: displayName, object: state[regName] });
}
});
// Rosetta registers (tmp0, tmp1, tmp2)
if (state.rosetta) {
['tmp0', 'tmp1', 'tmp2'].forEach(tmpReg => {
if (state.rosetta[tmpReg]) {
registers.push({ name: tmpReg, object: state.rosetta[tmpReg] });
}
});
}
break;
default:
header.textContent = 'Register State';
}
container.appendChild(header);
const registersGrid = this.createDiv('registers');
registers.forEach(reg => {
const value = reg.object.value || 0;
const registerDiv = this.createDiv('register');
registerDiv.appendChild(this.createDiv('register-name', reg.name + ':'));
registerDiv.appendChild(this.createDiv('register-value', `0x${value.toString(16).padStart(16, '0')}`));
if (reg.object.description) {
registerDiv.appendChild(this.createDiv('register-desc', reg.object.description));
}
registersGrid.appendChild(registerDiv);
});
container.appendChild(registersGrid);
return container;
}
formatBinaryImages() {
const images = this.report.usedImages || [];
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, 'Binary Images');
details.appendChild(summary);
const container = this.createDiv('section-container');
images.forEach((image) => {
const base = image.base || 0n;
let end = base + (image.size || 0n) - 1n;
// simulate underflow (matches Apple behavior)
if (end < 0n) {
const uint64Max = 18446744073709551616n;
end += uint64Max;
}
const binaryImage = this.createDiv('binary-image');
const rangeDiv = this.createDiv('image-range');
rangeDiv.appendChild(this.createAddress(base));
rangeDiv.append(' - ');
rangeDiv.appendChild(this.createAddress(end));
binaryImage.appendChild(rangeDiv);
binaryImage.appendChild(this.createDiv('image-name', image.name || '???'));
const detailsDiv = this.createDiv('image-details');
detailsDiv.appendChild(this.createSpan('image-arch', image.arch || 'unknown'));
detailsDiv.append(' ');
detailsDiv.appendChild(this.createSpan('image-uuid', `<${image.uuid || ''}>`));
detailsDiv.append(' ');
detailsDiv.appendChild(this.createSpan('image-path', image.path || '???'));
binaryImage.appendChild(detailsDiv);
container.appendChild(binaryImage);
});
details.appendChild(container);
section.appendChild(details);
return section;
}
formatExtMods() {
const extMods = this.report.extMods;
if (!extMods) return null;
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, 'External Modification Summary');
details.appendChild(summary);
const grid = this.createDiv('info-grid');
const addRow = (label, value) => {
grid.appendChild(this.createDiv('info-label', label + ':'));
const valueDiv = this.createDiv('info-value');
if (typeof value === 'string') {
valueDiv.textContent = value;
} else {
valueDiv.appendChild(value);
}
grid.appendChild(valueDiv);
};
// Calls made by other processes targeting this process
if (extMods.targeted) {
const targetedFrag = document.createDocumentFragment();
targetedFrag.appendChild(this.createDiv(null, 'Calls made by other processes targeting this process:'));
if (extMods.targeted.task_for_pid !== undefined) {
targetedFrag.appendChild(this.createDiv(null, ` task_for_pid: ${extMods.targeted.task_for_pid}`));
}
if (extMods.targeted.thread_create !== undefined) {
targetedFrag.appendChild(this.createDiv(null, ` thread_create: ${extMods.targeted.thread_create}`));
}
if (extMods.targeted.thread_set_state !== undefined) {
targetedFrag.appendChild(this.createDiv(null, ` thread_set_state: ${extMods.targeted.thread_set_state}`));
}
addRow('Targeted', targetedFrag);
}
// Calls made by this process
if (extMods.caller) {
const callerFrag = document.createDocumentFragment();
callerFrag.appendChild(this.createDiv(null, 'Calls made by this process:'));
if (extMods.caller.task_for_pid !== undefined) {
callerFrag.appendChild(this.createDiv(null, ` task_for_pid: ${extMods.caller.task_for_pid}`));
}
if (extMods.caller.thread_create !== undefined) {
callerFrag.appendChild(this.createDiv(null, ` thread_create: ${extMods.caller.thread_create}`));
}
if (extMods.caller.thread_set_state !== undefined) {
callerFrag.appendChild(this.createDiv(null, ` thread_set_state: ${extMods.caller.thread_set_state}`));
}
addRow('Caller', callerFrag);
}
// Calls made by all processes on this machine
if (extMods.system) {
const systemFrag = document.createDocumentFragment();
systemFrag.appendChild(this.createDiv(null, 'Calls made by all processes on this machine:'));
if (extMods.system.task_for_pid !== undefined) {
systemFrag.appendChild(this.createDiv(null, ` task_for_pid: ${extMods.system.task_for_pid}`));
}
if (extMods.system.thread_create !== undefined) {
systemFrag.appendChild(this.createDiv(null, ` thread_create: ${extMods.system.thread_create}`));
}
if (extMods.system.thread_set_state !== undefined) {
systemFrag.appendChild(this.createDiv(null, ` thread_set_state: ${extMods.system.thread_set_state}`));
}
addRow('System', systemFrag);
}
details.appendChild(grid);
section.appendChild(details);
return section;
}
formatVMSummary() {
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, 'VM Region Summary');
details.appendChild(summary);
const vmDiv = this.createDiv('vm-summary', this.report.vmSummary);
details.appendChild(vmDiv);
section.appendChild(details);
return section;
}
formatFilteredLog() {
const section = this.createDiv('crash-section');
const details = this.createElement('details');
const summary = this.createElement('summary', null, 'Filtered log messages');
details.appendChild(summary);
const logDiv = this.createDiv('filtered-log');
logDiv.textContent = this.report.filteredLog.join('\n');
details.appendChild(logDiv);
section.appendChild(details);
return section;
}
}
// UI Controller
document.addEventListener('DOMContentLoaded', () => {
const ipsInput = document.getElementById('ipsInput');
const parseBtn = document.getElementById('parseBtn');
const clearBtn = document.getElementById('clearBtn');
const expandAllBtn = document.getElementById('expandAllBtn');
const collapseAllBtn = document.getElementById('collapseAllBtn');
const errorMessage = document.getElementById('errorMessage');
const outputSection = document.getElementById('output');
const reportOutput = document.getElementById('reportOutput');
parseBtn.addEventListener('click', () => {
const content = ipsInput.value.trim();
if (!content) {
showError('Please paste IPS file contents first.');
return;
}
try {
const parser = new StructuredIPSParser(content);
parser.parse();
const formatted = parser.formatReport();
reportOutput.textContent = '';
reportOutput.appendChild(formatted);
outputSection.style.display = 'block';
errorMessage.style.display = 'none';
} catch (error) {
showError(error.message);
outputSection.style.display = 'none';
}
});
clearBtn.addEventListener('click', () => {
ipsInput.value = '';
outputSection.style.display = 'none';
errorMessage.style.display = 'none';
ipsInput.focus();
});
expandAllBtn.addEventListener('click', () => {
reportOutput.querySelectorAll('details').forEach(detail => {
detail.open = true;
});
});
collapseAllBtn.addEventListener('click', () => {
reportOutput.querySelectorAll('details').forEach(detail => {
detail.open = false;
});
});
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
}
// Allow parsing with Enter key (Ctrl/Cmd + Enter)
ipsInput.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
parseBtn.click();
}
});
});