Skip to content

Commit

Permalink
Reformat with ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Dec 27, 2023
1 parent e788e00 commit 8d6f989
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 259 deletions.
24 changes: 13 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ repositories {
mavenCentral()
}

val ghidraDir = (project.findProperty("ghidra.dir") as? String)
?: System.getenv("GHIDRA_INSTALL_DIR")
?: throw IllegalStateException("Can't find Ghidra installation")
val ghidraDir =
(project.findProperty("ghidra.dir") as? String)
?: System.getenv("GHIDRA_INSTALL_DIR")
?: throw IllegalStateException("Can't find Ghidra installation")

val ghidraProps = Properties().apply { file("$ghidraDir/Ghidra/application.properties").inputStream().use { load(it) } }
val ghidraVersion = ghidraProps.getProperty("application.version")!!
Expand Down Expand Up @@ -65,19 +66,20 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

val generateExtensionProps by tasks.registering() {
val generateExtensionProps by tasks.registering {
val output = layout.buildDirectory.file("generated/extension.properties")
outputs.file(output)
doLast {
file(output).outputStream().use {
val props = Properties()
props += mapOf(
("name" to "GhidraBoy"),
("description" to "Support for Sharp SM83 / Game Boy"),
("author" to "Gekkio"),
("createdOn" to LocalDate.now().toString()),
("version" to ghidraVersion)
)
props +=
mapOf(
("name" to "GhidraBoy"),
("description" to "Support for Sharp SM83 / Game Boy"),
("author" to "Gekkio"),
("createdOn" to LocalDate.now().toString()),
("version" to ghidraVersion),
)
props.store(it, null)
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/test/kotlin/fi/gekkio/ghidraboy/DisassemblyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,14 @@ class DisassemblyTest : IntegrationTest() {
fun `can disassemble XOR n`() = test(0xee, "XOR 0x55", 0x55)

@Test
fun `can disassemble RST 0x28`() = test(0xef, "RST 0x0028") {
val helper = EmulatorHelper(it.program)
helper.writeRegister("SP", 0xffff)
helper.step(TaskMonitor.DUMMY)
println(helper.readRegister("SP"))
println(helper.readRegister("PC"))
}
fun `can disassemble RST 0x28`() =
test(0xef, "RST 0x0028") {
val helper = EmulatorHelper(it.program)
helper.writeRegister("SP", 0xffff)
helper.step(TaskMonitor.DUMMY)
println(helper.readRegister("SP"))
println(helper.readRegister("PC"))
}

@Test
fun `can disassemble LDH A, (n)`() = test(0xf0, "LDH A,(0x55)", 0x55)
Expand Down Expand Up @@ -816,7 +817,12 @@ class DisassemblyTest : IntegrationTest() {
@Test
fun `can disassemble RST 0x38`() = test(0xff, "RST 0x0038")

private fun test(opcode: Int, expected: String, vararg args: Int, assertions: (codeUnit: CodeUnit) -> Unit = {}) {
private fun test(
opcode: Int,
expected: String,
vararg args: Int,
assertions: (codeUnit: CodeUnit) -> Unit = {},
) {
val codeUnit = disassemble(byteArrayOf(opcode.toByte(), *(args.map { it.toByte() }).toByteArray()))
assertEquals(expected, codeUnit.toString())
assertions(codeUnit)
Expand Down
29 changes: 16 additions & 13 deletions src/test/kotlin/fi/gekkio/ghidraboy/GhidraApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ class GhidraApplication : Extension {
companion object {
private var initialized = false

fun initialize() = synchronized(this) {
if (initialized) return
val layout = object : GhidraApplicationLayout() {
override fun findGhidraModules(): MutableMap<String, GModule> = mutableMapOf(
"GhidraBoy" to
GModule(applicationRootDirs, ResourceFile("./"))
).apply {
putAll(super.findGhidraModules())
}
fun initialize() =
synchronized(this) {
if (initialized) return
val layout =
object : GhidraApplicationLayout() {
override fun findGhidraModules(): MutableMap<String, GModule> =
mutableMapOf(
"GhidraBoy" to
GModule(applicationRootDirs, ResourceFile("./")),
).apply {
putAll(super.findGhidraModules())
}
}
val configuration = HeadlessGhidraApplicationConfiguration()
Application.initializeApplication(layout, configuration)
initialized = true
}
val configuration = HeadlessGhidraApplicationConfiguration()
Application.initializeApplication(layout, configuration)
initialized = true
}
}
}
7 changes: 4 additions & 3 deletions src/test/kotlin/fi/gekkio/ghidraboy/IntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ open class IntegrationTest {
open fun beforeAll() {
val provider = SleighLanguageProvider.getSleighLanguageProvider()
Assertions.assertFalse(provider.hadLoadFailure())
val languageDescription = provider.languageDescriptions.filter {
it.description == "Sharp SM83" && it.processor.toString() == "SM83"
}.single()
val languageDescription =
provider.languageDescriptions.filter {
it.description == "Sharp SM83" && it.processor.toString() == "SM83"
}.single()
language = provider.getLanguage(languageDescription.languageID)
}

Expand Down
8 changes: 6 additions & 2 deletions src/test/kotlin/fi/gekkio/ghidraboy/MemoryExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ import ghidra.program.model.mem.Memory
import ghidra.program.model.mem.MemoryBlock
import ghidra.util.task.TaskMonitor

fun Memory.loadBytes(name: String, start: Address, bytes: ByteArray, overlay: Boolean = false): MemoryBlock =
createInitializedBlock(name, start, bytes.inputStream(), bytes.size.toLong(), TaskMonitor.DUMMY, overlay)
fun Memory.loadBytes(
name: String,
start: Address,
bytes: ByteArray,
overlay: Boolean = false,
): MemoryBlock = createInitializedBlock(name, start, bytes.inputStream(), bytes.size.toLong(), TaskMonitor.DUMMY, overlay)
5 changes: 4 additions & 1 deletion src/test/kotlin/fi/gekkio/ghidraboy/ProgramExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ package fi.gekkio.ghidraboy

import ghidra.program.model.listing.Program

inline fun <T> Program.withTransaction(description: String = "", crossinline f: () -> T): T {
inline fun <T> Program.withTransaction(
description: String = "",
crossinline f: () -> T,
): T {
var success = false
val id = startTransaction(description)
try {
Expand Down
Loading

0 comments on commit 8d6f989

Please sign in to comment.