Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deobfuscated crashes #618

Merged
merged 5 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/kotlin/io/github/mojira/arisa/domain/Issue.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.mojira.arisa.domain

import java.io.File
import java.time.Instant

data class Issue(
Expand Down Expand Up @@ -45,5 +46,6 @@ data class Issue(
val addNotEnglishComment: (language: String) -> Unit,
val addRawRestrictedComment: (body: String, restriction: String) -> Unit,
val markAsFixedWithSpecificVersion: (fixVersion: String) -> Unit,
val changeReporter: (reporter: String) -> Unit
val changeReporter: (reporter: String) -> Unit,
val addAttachment: (file: File) -> Unit
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class AttachmentUtils(
) {
data class TextDocument(
val getContent: () -> String,
val created: Instant
val created: Instant,
val name: String
)

fun extractCrashesFromAttachments(issue: Issue): List<Pair<TextDocument, Crash>> = with(issue) {
Expand All @@ -23,7 +24,7 @@ class AttachmentUtils(
.map(::fetchAttachment)
.toMutableList()
// also add description, so it's searched for crash reports
textDocuments.add(TextDocument({ description ?: "" }, created))
textDocuments.add(TextDocument({ description ?: "" }, created, "description"))

textDocuments
.asSequence()
Expand All @@ -43,7 +44,7 @@ class AttachmentUtils(
String(data)
}

return TextDocument(getText, attachment.created)
return TextDocument(getText, attachment.created, attachment.name)
}

private fun processCrash(it: TextDocument) = it to crashReader.processCrash(it.getContent().lines())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.rcarz.jiraclient.User
import net.rcarz.jiraclient.Version
import net.sf.json.JSONObject
import org.apache.http.HttpStatus
import java.io.File
import java.net.URI
import java.time.Instant
import java.time.temporal.ChronoField
Expand Down Expand Up @@ -248,6 +249,32 @@ fun deleteAttachment(context: Lazy<IssueUpdateContext>, attachment: Attachment)
}
}

fun addAttachmentFile(context: Lazy<IssueUpdateContext>, file: File) {
context.value.otherOperations.add {
runBlocking {
Either.catch {
withContext(Dispatchers.IO) {
try {
context.value.jiraIssue.addAttachment(file)
} catch (e: RestException) {
if (e.httpStatusCode == HttpStatus.SC_NOT_FOUND ||
e.httpStatusCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR
) {
log.warn("Couldn't upload ${file.name}")
} else {
throw e
}
} finally {
if (file.exists()) {
file.delete()
}
}
}
}
}
}
}

fun createComment(
context: Lazy<IssueUpdateContext>,
comment: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ fun JiraIssue.toDomain(
},
addRawRestrictedComment = ::addRestrictedComment.partially1(context),
::markAsFixedWithSpecificVersion.partially1(context),
::changeReporter.partially1(context)
::changeReporter.partially1(context),
::addAttachmentFile.partially1(context)
)
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/io/github/mojira/arisa/modules/CrashModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.github.mojira.arisa.infrastructure.AttachmentUtils
import io.github.mojira.arisa.infrastructure.config.CrashDupeConfig
import me.urielsalis.mccrashlib.Crash
import me.urielsalis.mccrashlib.CrashReader
import java.io.File
import java.time.Instant

class CrashModule(
urielsalis marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -29,6 +30,7 @@ class CrashModule(
val crashes = AttachmentUtils(crashReportExtensions, crashReader).extractCrashesFromAttachments(issue)

assertContainsNewCrash(crashes, lastRun).bind()
uploadDeobfuscatedCrashes(issue, crashes)
urielsalis marked this conversation as resolved.
Show resolved Hide resolved
assertNoValidCrash(crashes).bind()

val key = crashes
Expand All @@ -47,6 +49,20 @@ class CrashModule(
}
}

private fun uploadDeobfuscatedCrashes(issue: Issue, crashes: List<Pair<AttachmentUtils.TextDocument, Crash>>) {
val minecraftCrashesWithDeobf = crashes
.map { it.first.name to it.second }
.filter { it.second is Crash.Minecraft }
.map { it.first to (it.second as Crash.Minecraft).deobf }
.filter { it.second != null }
.filterNot { issue.attachments.any { attachment -> attachment.name == getDeobfName(it.first) } }
minecraftCrashesWithDeobf.forEach {
issue.addAttachment(File(getDeobfName(it.first)))
urielsalis marked this conversation as resolved.
Show resolved Hide resolved
}
}

private fun getDeobfName(name: String): String = "${name.substringAfterLast(".")}-deobfuscated.log"
urielsalis marked this conversation as resolved.
Show resolved Hide resolved

/**
* Checks whether an analyzed crash report matches any of the specified known crash issues.
* Returns the key of the parent bug report if one is found, and null otherwise.
Expand Down
Loading