Skip to content

Commit 962c90a

Browse files
committed
review: address PR feedback
1 parent aed0eb0 commit 962c90a

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ android {
8181
filters {
8282
engines {
8383
include 'spek2'
84+
include 'junit-jupiter'
8485
}
8586
}
8687
jacocoOptions {

app/src/main/java/com/kyhsgeekcode/disassembler/ui/components/HexView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ data class HexRow(
3838

3939
fun buildHexRows(bytes: ByteArray): List<HexRow> {
4040
return bytes.toList().chunked(BYTES_PER_ROW).mapIndexed { index, chunk ->
41-
val paddedHex = chunk.map { "%02X".format(it) } + List(BYTES_PER_ROW - chunk.size) { "" }
41+
val paddedHex = chunk.map { "%02X".format(it.toInt() and 0xFF) } +
42+
List(BYTES_PER_ROW - chunk.size) { "" }
4243
val ascii = chunk.map { byte ->
4344
val charValue = byte.toInt().toChar()
4445
if (isPrintableChar(charValue)) charValue.toString() else "."
45-
}
46+
} + List(BYTES_PER_ROW - chunk.size) { "" }
4647
HexRow(
4748
offset = index * BYTES_PER_ROW,
4849
bytes = chunk,

app/src/main/java/com/kyhsgeekcode/disassembler/ui/tabs/BinaryDisasmTab.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fun BinaryDisasmTabContent(
209209
InfiniteList(onLoadMore = { firstVisibleItemIndex, lastVisibleItemIndex ->
210210
disasmData.setCurrentAddressByFirstItemIndex(firstVisibleItemIndex)
211211
disasmData.loadMore(lastVisibleItemIndex)
212-
}, modifier = Modifier.fillMaxWidth(), listState = listState) {
212+
}, modifier = Modifier.wrapContentWidth(), listState = listState) {
213213

214214
stickyHeader {
215215
BinaryDisasmHeader(disasmData)

app/src/main/java/com/kyhsgeekcode/disassembler/viewmodel/MainViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
145145
try {
146146
val app = getApplication<Application>()
147147
app.contentResolver.openInputStream(uri).use { inStream ->
148+
requireNotNull(inStream) { "Failed to open content URI: $uri" }
148149
val fileName = resolveImportedFileName(app, uri, displayName)
149150
val file = app.filesDir.resolve("imports").resolve(fileName)
150151
file.parentFile?.mkdirs()
151152
file.outputStream().use { fileOut ->
152-
inStream?.copyTo(fileOut)
153+
inStream.copyTo(fileOut)
153154
}
154155
val project = ProjectManager.newProject(
155156
file,

app/src/test/java/com/kyhsgeekcode/disassembler/ui/components/HexViewLayoutTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ class HexViewLayoutTest {
2525

2626
assertEquals(1, rows.size)
2727
assertEquals(16, rows[0].paddedHexValues.size)
28+
assertEquals(16, rows[0].asciiValues.size)
2829
assertEquals(listOf("41", "42", "43"), rows[0].paddedHexValues.take(3))
2930
assertTrue(rows[0].paddedHexValues.drop(3).all { it == "" })
31+
assertEquals(listOf("A", "B", "C"), rows[0].asciiValues.take(3))
32+
assertTrue(rows[0].asciiValues.drop(3).all { it == "" })
3033
}
3134

3235
@Test
3336
fun `ascii cells convert printable bytes and replace control bytes`() {
3437
val rows = buildHexRows(byteArrayOf(0x41, 0x20, 0x0A, 0x7F))
3538

36-
assertEquals(listOf("A", " ", ".", "."), rows.single().asciiValues)
39+
assertEquals(listOf("A", " ", ".", "."), rows.single().asciiValues.take(4))
40+
}
41+
42+
@Test
43+
fun `buildHexRows formats high-bit bytes as two-digit hex`() {
44+
val rows = buildHexRows(byteArrayOf(0xEE.toByte(), 0xFF.toByte(), 0x80.toByte()))
45+
46+
assertEquals(listOf("EE", "FF", "80"), rows.single().paddedHexValues.take(3))
3747
}
3848

3949
@Test

0 commit comments

Comments
 (0)