Skip to content
Open
Changes from all 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
1 change: 1 addition & 0 deletions src/commonMain/kotlin/app/revanced/library/ApkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object ApkUtils {
ZFile.openReadWrite(apkFile, zFileOptions).use { targetApkZFile ->
dexFiles.forEach { dexFile ->
targetApkZFile.add(dexFile.name, dexFile.stream)
dexFile.stream.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, however now you can't call this function twice. I remember functions should "always be callable multiple times"

Copy link
Member

@oSumAtrIX oSumAtrIX Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it maybe possible to pass a handle to manually open and close a stream in patcher? Not a file handle though as we'd need to expose the "File" API when patcher should just contract with a generic handle instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge, a File object is the lowest/generic way to construct a stream from a local file. Once a stream is closed, the data stream no longer exists and you can't re-open or close it at will.

This is pretty much why I advocated to pass around a file descriptor instead of a potentially closed stream.

Copy link
Member

@oSumAtrIX oSumAtrIX Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most abstract is a Handle interface with a method to open a stream to be implemented by patcher. Not a File object

interface Handle {
 fun inputStream()
}

Copy link
Member

@oSumAtrIX oSumAtrIX Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already explained why File won't work. The fact that patcher is using a File under the hood is private and scoped to patchers internals. I may very much swap it with an in memory implementation. The second i expose the File API, it is part of the public API and I can't do that no more. Right now patcher provides a dexFile.stream directly, but instead it can provide a handle to open a stream.

e.g:

h = result.dexHandle
stream = openStream(h)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the maintainer, so up to you. Feel free the close the PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To pass a handle, patcher API needs to change to return an interface where you can call inputStream(). Patcher then can handle the implementation for it respectively for the internal implementation. For File ill open a file inputstream, for byte[] it'll wrap to a bytearray input stream. Any amount of streams can be opened and closed solving the issue in this comment. Could you PR that? Since the API changes, you may need to deprecate the old API

}

resources?.let { resources ->
Expand Down
Loading