-
Notifications
You must be signed in to change notification settings - Fork 110
Reduce retained binary memory with range-reader groundwork #742
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
Open
yhs0602
wants to merge
5
commits into
master
Choose a base branch
from
codex/binary-range-reader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e058e18
refactor: add file channel range reader bridge
yhs0602 bdf19b8
stability: lazy-load raw binaries after header sniffing
yhs0602 b4c5d72
stability: lazy-load elf binaries on demand
yhs0602 658b1ba
stability: defer retained pe binary contents
yhs0602 9dcda8b
test: expand instrumentation flow coverage
yhs0602 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ndroidTest/java/com/kyhsgeekcode/disassembler/MainActivityAdvancedImportCancelFlowTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.kyhsgeekcode.disassembler | ||
|
|
||
| import android.content.ComponentName | ||
| import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.espresso.intent.Intents.intending | ||
| import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.kyhsgeekcode.disassembler.ui.MainTestTags | ||
| import com.kyhsgeekcode.filechooser.NewFileChooserActivity | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.rules.RuleChain | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class MainActivityAdvancedImportCancelFlowTest { | ||
| private val projectCleanupRule = ProjectStateCleanupRule() | ||
| private val preferenceRule = PowerUserModePreferenceRule(powerUserModeEnabled = true) | ||
| private val intentsRule = InstrumentationIntentsRule() | ||
| private val composeRule = createAndroidComposeRule<MainActivity>() | ||
|
|
||
| @get:Rule | ||
| val rules: RuleChain = RuleChain.outerRule(projectCleanupRule) | ||
| .around(preferenceRule) | ||
| .around(intentsRule) | ||
| .around(composeRule) | ||
|
|
||
| @Test | ||
| fun advancedImportCancel_keepsPowerUserEntryPointsVisible() { | ||
| intending( | ||
| hasComponent( | ||
| ComponentName( | ||
| composeRule.activity, | ||
| NewFileChooserActivity::class.java | ||
| ) | ||
| ) | ||
| ).respondWith(createCanceledActivityResult()) | ||
|
|
||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_ADVANCED_BUTTON).performClick() | ||
| composeRule.waitForIdle() | ||
|
|
||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_SAF_BUTTON).assertExists() | ||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_ADVANCED_BUTTON).assertExists() | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
.../androidTest/java/com/kyhsgeekcode/disassembler/MainActivityBinaryDetailExportFlowTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package com.kyhsgeekcode.disassembler | ||
|
|
||
| import android.content.Intent | ||
| import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
| import androidx.compose.ui.test.onAllNodesWithTag | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.espresso.intent.Intents.intending | ||
| import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.kyhsgeekcode.disassembler.ui.MainTestTags | ||
| import org.hamcrest.CoreMatchers.allOf | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.rules.RuleChain | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class MainActivityBinaryDetailExportFlowTest { | ||
| private val projectCleanupRule = ProjectStateCleanupRule() | ||
| private val preferenceRule = PowerUserModePreferenceRule(powerUserModeEnabled = false) | ||
| private val intentsRule = InstrumentationIntentsRule() | ||
| private val composeRule = createAndroidComposeRule<MainActivity>() | ||
|
|
||
| @get:Rule | ||
| val rules: RuleChain = RuleChain.outerRule(projectCleanupRule) | ||
| .around(preferenceRule) | ||
| .around(intentsRule) | ||
| .around(composeRule) | ||
|
|
||
| @Test | ||
| fun saveDetailsResult_writesTextDocument() { | ||
| stubSafImport("detail-export-source.apk") | ||
| val (outputFile, createDocumentResult) = createCreateDocumentResult("binary-details.txt") | ||
| intending(allOf(hasAction(Intent.ACTION_CREATE_DOCUMENT))).respondWith(createDocumentResult) | ||
|
|
||
| openProjectAndDetailTab() | ||
| composeRule.onNodeWithTag(MainTestTags.SAVE_DETAILS_BUTTON).performClick() | ||
|
|
||
| composeRule.waitUntil(timeoutMillis = 5_000) { | ||
| outputFile.length() > 0L | ||
| } | ||
|
|
||
| assertTrue(outputFile.readText().contains("File Size:")) | ||
| } | ||
|
|
||
| @Test | ||
| fun saveDetailsCancel_keepsProjectOpen() { | ||
| stubSafImport("detail-export-cancel-source.apk") | ||
| intending(allOf(hasAction(Intent.ACTION_CREATE_DOCUMENT))).respondWith(createCanceledActivityResult()) | ||
|
|
||
| openProjectAndDetailTab() | ||
| composeRule.onNodeWithTag(MainTestTags.SAVE_DETAILS_BUTTON).performClick() | ||
| composeRule.waitForIdle() | ||
|
|
||
| composeRule.onNodeWithTag(MainTestTags.SAVE_DETAILS_BUTTON).assertExists() | ||
| composeRule.onNodeWithTag(MainTestTags.EXPORT_PROJECT_BUTTON).assertExists() | ||
| } | ||
|
|
||
| private fun stubSafImport(displayName: String) { | ||
| intending( | ||
| allOf( | ||
| hasAction(Intent.ACTION_OPEN_DOCUMENT) | ||
| ) | ||
| ).respondWith( | ||
| createOpenDocumentResult( | ||
| displayName = displayName, | ||
| content = "apk-content".encodeToByteArray() | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| private fun openProjectAndDetailTab() { | ||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_SAF_BUTTON).performClick() | ||
| composeRule.waitUntil(timeoutMillis = 5_000) { | ||
| composeRule.onAllNodesWithTag(MainTestTags.EXPORT_PROJECT_BUTTON) | ||
| .fetchSemanticsNodes().isNotEmpty() | ||
| } | ||
| composeRule.onNodeWithTag(MainTestTags.BINARY_TAB_DETAIL).performClick() | ||
| composeRule.onNodeWithTag(MainTestTags.SAVE_DETAILS_BUTTON).assertExists() | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...src/androidTest/java/com/kyhsgeekcode/disassembler/MainActivitySafImportCancelFlowTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.kyhsgeekcode.disassembler | ||
|
|
||
| import android.content.Intent | ||
| import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.espresso.intent.Intents.intending | ||
| import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.kyhsgeekcode.disassembler.ui.MainTestTags | ||
| import org.hamcrest.CoreMatchers.allOf | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.rules.RuleChain | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class MainActivitySafImportCancelFlowTest { | ||
| private val projectCleanupRule = ProjectStateCleanupRule() | ||
| private val preferenceRule = PowerUserModePreferenceRule(powerUserModeEnabled = false) | ||
| private val intentsRule = InstrumentationIntentsRule() | ||
| private val composeRule = createAndroidComposeRule<MainActivity>() | ||
|
|
||
| @get:Rule | ||
| val rules: RuleChain = RuleChain.outerRule(projectCleanupRule) | ||
| .around(preferenceRule) | ||
| .around(intentsRule) | ||
| .around(composeRule) | ||
|
|
||
| @Test | ||
| fun safImportCancel_keepsStandardEntryPointVisible() { | ||
| intending( | ||
| allOf( | ||
| hasAction(Intent.ACTION_OPEN_DOCUMENT) | ||
| ) | ||
| ).respondWith(createCanceledActivityResult()) | ||
|
|
||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_SAF_BUTTON).performClick() | ||
| composeRule.waitForIdle() | ||
|
|
||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_SAF_BUTTON).assertExists() | ||
| composeRule.onNodeWithTag(MainTestTags.IMPORT_ADVANCED_BUTTON).assertDoesNotExist() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/kyhsgeekcode/disassembler/files/BinaryContainerFormat.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.kyhsgeekcode.disassembler.files | ||
|
|
||
| enum class BinaryContainerFormat { | ||
| ELF, | ||
| PE, | ||
| RAW, | ||
| } |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/kyhsgeekcode/disassembler/files/BinaryContentLoader.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.kyhsgeekcode.disassembler.files | ||
|
|
||
| fun interface BinaryContentLoader { | ||
| fun load(): ByteArray | ||
| } |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/kyhsgeekcode/disassembler/files/BinaryRangeReader.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.kyhsgeekcode.disassembler.files | ||
|
|
||
| import java.io.Closeable | ||
|
|
||
| interface BinaryRangeReader : Closeable { | ||
| val size: Long | ||
|
|
||
| fun read(offset: Long, length: Int): ByteArray | ||
|
|
||
| fun readFully(): ByteArray | ||
| } |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/kyhsgeekcode/disassembler/files/DeferredFileBackedBinaryContent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.kyhsgeekcode.disassembler.files | ||
|
|
||
| import java.io.File | ||
|
|
||
| class DeferredFileBackedBinaryContent( | ||
| private val file: File, | ||
| initialContent: ByteArray? = null, | ||
| private val loader: BinaryContentLoader? = null, | ||
| ) { | ||
| private var loadedContent: ByteArray? = initialContent | ||
|
|
||
| fun contents(): ByteArray { | ||
| val existing = loadedContent | ||
| if (existing != null) { | ||
| return existing | ||
| } | ||
| val loaded = loader?.load() ?: file.readBytes() | ||
| loadedContent = loaded | ||
| return loaded | ||
| } | ||
|
|
||
| fun length(): Long { | ||
| return loadedContent?.size?.toLong() ?: file.length() | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't treat deferred bytes as "not configured".
Line 24 now returns the placeholder string whenever
fileContentsis still lazy. After this PR,RawFile,ElfFile, andPEFileintentionally leavefileContentsuninitialized until bytes are requested, sotoString()skips the size/address metadata even thoughgetBinaryLength()and the parsed fields are already available.🩹 Proposed fix
override fun toString(): String { - if (!::fileContents.isInitialized) { - return "The file has not been configured. You should setup manually in the first page before you can see the details." - } val builder = StringBuilder( if (this is RawFile) "The file has not been configured. You should setup manually in the first page before you can see the details." + System.lineSeparator() else "" )🤖 Prompt for AI Agents