-
Notifications
You must be signed in to change notification settings - Fork 1
/
pull-tombstone.ps1
52 lines (42 loc) · 1.7 KB
/
pull-tombstone.ps1
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
Param(
[Parameter(Mandatory=$false)]
[String] $fileName = "RecentCrash.log",
[Parameter(Mandatory=$false)]
[Switch] $analyze,
[Parameter(Mandatory=$false)]
[Switch] $help
)
if ($help -eq $true) {
Write-Output "`"Pull-Tombstone`" - Finds and pulls the most recent tombstone from your quest, optionally analyzing it with ndk-stack"
Write-Output "`n-- Arguments --`n"
Write-Output "-FileName `t The name for the output file, defaulting to RecentCrash.log"
Write-Output "-Analyze `t Runs ndk-stack on the file after pulling"
exit
}
$global:currentDate = get-date
$global:recentDate = $Null
$global:recentTombstone = $Null
for ($i = 0; $i -lt 3; $i++) {
$stats = & adb shell stat /sdcard/Android/data/com.beatgames.beatsaber/files/tombstone_0$i
$date = (Select-String -Input $stats -Pattern "(?<=Modify: )\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?=.\d{9})").Matches.Value
if([string]::IsNullOrEmpty($date)) {
Write-Output "Failed to pull tombstone, exiting..."
exit 1;
}
$dateObj = [datetime]::ParseExact($date, "yyyy-MM-dd HH:mm:ss", $Null)
$difference = [math]::Round(($currentDate - $dateObj).TotalMinutes)
if ($difference -eq 1) {
Write-Output "Found tombstone_0$i $difference minute ago"
} else {
Write-Output "Found tombstone_0$i $difference minutes ago"
}
if (-not $recentDate -or $recentDate -lt $dateObj) {
$recentDate = $dateObj
$recentTombstone = $i
}
}
Write-Output "Latest tombstone was tombstone_0$recentTombstone"
& adb pull /sdcard/Android/data/com.beatgames.beatsaber/files/tombstone_0$recentTombstone $fileName
if ($analyze) {
& $PSScriptRoot/ndk-stack.ps1 -logName:$fileName
}