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

Sort files list in FileDirectory::loadAll() #3657

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

luk1337
Copy link
Contributor

@luk1337 luk1337 commented Aug 6, 2024

This lets us assemble classes.dex in a reproducible manner.

Test:
apktool d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
apktool -f d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex

This lets us assemble classes.dex in a reproducible manner.

Test:
  apktool d test.apk > /dev/null
  apktool b test > /dev/null
  sha1sum test/build/apk/classes.dex
  apktool -f d test.apk > /dev/null
  apktool b test > /dev/null
  sha1sum test/build/apk/classes.dex
@iBotPeaches
Copy link
Owner

Do you have a sample application that isn't the same?

3f6e2f8d35bf511b637a117341b4be776ad3b13f  test/build/apk/classes.dex
3f6e2f8d35bf511b637a117341b4be776ad3b13f  test/build/apk/classes.dex

Running a few of my samples through and its the same every time.

@luk1337
Copy link
Contributor Author

luk1337 commented Aug 7, 2024

Do you have a sample application that isn't the same?

3f6e2f8d35bf511b637a117341b4be776ad3b13f  test/build/apk/classes.dex
3f6e2f8d35bf511b637a117341b4be776ad3b13f  test/build/apk/classes.dex

Running a few of my samples through and its the same every time.

Here you go.
PowerOffAlarm.zip

@iBotPeaches
Copy link
Owner

What hash do you get with that sample?

➜  3657 apktool d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
apktool -f d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
19948740534f943722926f45812398fc0ddac344  test/build/apk/classes.dex
19948740534f943722926f45812398fc0ddac344  test/build/apk/classes.dex

@luk1337
Copy link
Contributor Author

luk1337 commented Aug 7, 2024

What hash do you get with that sample?

➜  3657 apktool d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
apktool -f d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
19948740534f943722926f45812398fc0ddac344  test/build/apk/classes.dex
19948740534f943722926f45812398fc0ddac344  test/build/apk/classes.dex
$ apktool d test.apk > /dev/null                 
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
apktool -f d test.apk > /dev/null
apktool b test > /dev/null
sha1sum test/build/apk/classes.dex
3558522cb49d4842b6bc682e6109861c35751871  test/build/apk/classes.dex
fd1f92a379ab8cf201056c8bce850f18fc34d6bf  test/build/apk/classes.dex

@iBotPeaches
Copy link
Owner

Thanks. I don't see anything dangerous with this merge, I'm just trying to understand how this is happening and I can't replicate.

@luk1337
Copy link
Contributor Author

luk1337 commented Aug 7, 2024

Thanks. I don't see anything dangerous with this merge, I'm just trying to understand how this is happening and I can't replicate.

Also, with the following diff applied:

diff --git a/brut.j.dir/src/main/java/brut/directory/FileDirectory.java b/brut.j.dir/src/main/java/brut/directory/FileDirectory.java
index fd6e88a5..0981693f 100644
--- a/brut.j.dir/src/main/java/brut/directory/FileDirectory.java
+++ b/brut.j.dir/src/main/java/brut/directory/FileDirectory.java
@@ -109,8 +109,21 @@ public class FileDirectory extends AbstractDirectory {
         mDirs = new LinkedHashMap<>();
 
         File[] files = getDir().listFiles();
+
+        for (File file : files) {
+            if (file.isFile()) {
+                System.out.println("[pre-sort] " + file.getName());
+            }
+        }
+
         Arrays.sort(files, Comparator.comparing(f -> f.getName()));
 
+        for (File file : files) {
+            if (file.isFile()) {
+                System.out.println("[post-sort] " + file.getName());
+            }
+        }
+
         for (File file : files) {
             if (file.isFile()) {
                 mFiles.add(file.getName());
$ apktool -f d test.apk>/dev/null ; apktool b test ; apktool -f d test.apk>/dev/null ; apktool b test
I: Using Apktool v2.9.2-58-7ad1c9f9-SNAPSHOT with 24 thread(s).
[pre-sort] AndroidManifest.xml
[pre-sort] apktool.yml
[post-sort] AndroidManifest.xml
[post-sort] apktool.yml
[pre-sort] AndroidManifest.xml
[pre-sort] apktool.yml
[post-sort] AndroidManifest.xml
[post-sort] apktool.yml
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
[pre-sort] IBase$Stub.smali
[pre-sort] IBase$Proxy.smali
[pre-sort] DebugInfo$Architecture.smali
[pre-sort] DebugInfo.smali
[pre-sort] IBase.smali
[post-sort] DebugInfo$Architecture.smali
[post-sort] DebugInfo.smali
[post-sort] IBase$Proxy.smali
[post-sort] IBase$Stub.smali
[post-sort] IBase.smali
[pre-sort] AlarmDatabase.smali
[pre-sort] AlarmDatabaseHelper.smali
[pre-sort] Manifest$permission.smali
[pre-sort] Manifest.smali
[pre-sort] PowerOffAlarmActivity$1.smali
[pre-sort] PowerOffAlarmActivity$2.smali
[pre-sort] PowerOffAlarmActivity$3.smali
[pre-sort] PowerOffAlarmActivity$TimeThread.smali
[pre-sort] PowerOffAlarmActivity.smali
[pre-sort] PowerOffAlarmBroadcastReceiver.smali
[pre-sort] PowerOffAlarmDialog$1.smali
[pre-sort] PowerOffAlarmDialog$2.smali
[pre-sort] PowerOffAlarmDialog$ShutDownReceiver.smali
[pre-sort] PowerOffAlarmDialog.smali
[pre-sort] PowerOffAlarmUtils.smali
[pre-sort] PowerOffAlarmPersistData.smali
[pre-sort] R$drawable.smali
[pre-sort] R$id.smali
[pre-sort] R$layout.smali
[pre-sort] R$string.smali
[pre-sort] R.smali
[post-sort] AlarmDatabase.smali
[post-sort] AlarmDatabaseHelper.smali
[post-sort] Manifest$permission.smali
[post-sort] Manifest.smali
[post-sort] PowerOffAlarmActivity$1.smali
[post-sort] PowerOffAlarmActivity$2.smali
[post-sort] PowerOffAlarmActivity$3.smali
[post-sort] PowerOffAlarmActivity$TimeThread.smali
[post-sort] PowerOffAlarmActivity.smali
[post-sort] PowerOffAlarmBroadcastReceiver.smali
[post-sort] PowerOffAlarmDialog$1.smali
[post-sort] PowerOffAlarmDialog$2.smali
[post-sort] PowerOffAlarmDialog$ShutDownReceiver.smali
[post-sort] PowerOffAlarmDialog.smali
[post-sort] PowerOffAlarmPersistData.smali
[post-sort] PowerOffAlarmUtils.smali
[post-sort] R$drawable.smali
[post-sort] R$id.smali
[post-sort] R$layout.smali
[post-sort] R$string.smali
[post-sort] R.smali
[pre-sort] IAlarm$Proxy.smali
[pre-sort] IAlarm.smali
[pre-sort] IAlarm$Stub.smali
[post-sort] IAlarm$Proxy.smali
[post-sort] IAlarm$Stub.smali
[post-sort] IAlarm.smali
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: test/dist/test.apk
I: Using Apktool v2.9.2-58-7ad1c9f9-SNAPSHOT with 24 thread(s).
[pre-sort] AndroidManifest.xml
[pre-sort] apktool.yml
[post-sort] AndroidManifest.xml
[post-sort] apktool.yml
[pre-sort] AndroidManifest.xml
[pre-sort] apktool.yml
[post-sort] AndroidManifest.xml
[post-sort] apktool.yml
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
[pre-sort] DebugInfo$Architecture.smali
[pre-sort] IBase$Proxy.smali
[pre-sort] IBase$Stub.smali
[pre-sort] DebugInfo.smali
[pre-sort] IBase.smali
[post-sort] DebugInfo$Architecture.smali
[post-sort] DebugInfo.smali
[post-sort] IBase$Proxy.smali
[post-sort] IBase$Stub.smali
[post-sort] IBase.smali
[pre-sort] AlarmDatabase.smali
[pre-sort] AlarmDatabaseHelper.smali
[pre-sort] Manifest$permission.smali
[pre-sort] Manifest.smali
[pre-sort] PowerOffAlarmActivity$1.smali
[pre-sort] PowerOffAlarmActivity$2.smali
[pre-sort] PowerOffAlarmActivity$3.smali
[pre-sort] PowerOffAlarmActivity$TimeThread.smali
[pre-sort] PowerOffAlarmActivity.smali
[pre-sort] PowerOffAlarmBroadcastReceiver.smali
[pre-sort] PowerOffAlarmDialog$1.smali
[pre-sort] PowerOffAlarmDialog$2.smali
[pre-sort] PowerOffAlarmDialog$ShutDownReceiver.smali
[pre-sort] PowerOffAlarmDialog.smali
[pre-sort] PowerOffAlarmPersistData.smali
[pre-sort] PowerOffAlarmUtils.smali
[pre-sort] R$drawable.smali
[pre-sort] R$id.smali
[pre-sort] R$layout.smali
[pre-sort] R$string.smali
[pre-sort] R.smali
[post-sort] AlarmDatabase.smali
[post-sort] AlarmDatabaseHelper.smali
[post-sort] Manifest$permission.smali
[post-sort] Manifest.smali
[post-sort] PowerOffAlarmActivity$1.smali
[post-sort] PowerOffAlarmActivity$2.smali
[post-sort] PowerOffAlarmActivity$3.smali
[post-sort] PowerOffAlarmActivity$TimeThread.smali
[post-sort] PowerOffAlarmActivity.smali
[post-sort] PowerOffAlarmBroadcastReceiver.smali
[post-sort] PowerOffAlarmDialog$1.smali
[post-sort] PowerOffAlarmDialog$2.smali
[post-sort] PowerOffAlarmDialog$ShutDownReceiver.smali
[post-sort] PowerOffAlarmDialog.smali
[post-sort] PowerOffAlarmPersistData.smali
[post-sort] PowerOffAlarmUtils.smali
[post-sort] R$drawable.smali
[post-sort] R$id.smali
[post-sort] R$layout.smali
[post-sort] R$string.smali
[post-sort] R.smali
[pre-sort] IAlarm$Proxy.smali
[pre-sort] IAlarm.smali
[pre-sort] IAlarm$Stub.smali
[post-sort] IAlarm$Proxy.smali
[post-sort] IAlarm$Stub.smali
[post-sort] IAlarm.smali
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: test/dist/test.apk

(diff between both executions)

--- a	2024-08-07 13:02:48.910824438 +0200
+++ b	2024-08-07 13:02:53.798824914 +0200
@@ -1,6 +1,6 @@
-[pre-sort] IBase$Stub.smali
-[pre-sort] IBase$Proxy.smali
 [pre-sort] DebugInfo$Architecture.smali
+[pre-sort] IBase$Proxy.smali
+[pre-sort] IBase$Stub.smali
 [pre-sort] DebugInfo.smali
 [pre-sort] IBase.smali
 [post-sort] DebugInfo$Architecture.smali
@@ -22,8 +22,8 @@
 [pre-sort] PowerOffAlarmDialog$2.smali
 [pre-sort] PowerOffAlarmDialog$ShutDownReceiver.smali
 [pre-sort] PowerOffAlarmDialog.smali
-[pre-sort] PowerOffAlarmUtils.smali
 [pre-sort] PowerOffAlarmPersistData.smali
+[pre-sort] PowerOffAlarmUtils.smali
 [pre-sort] R$drawable.smali
 [pre-sort] R$id.smali
 [pre-sort] R$layout.smali

Copy link
Owner

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

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

Thanks - don't see a downside.

@luk1337
Copy link
Contributor Author

luk1337 commented Aug 8, 2024

hmm, I noticed that this only appears to happen when I do it inside tmpfs. If I repeat the same steps inside my $HOME, the sha1sums are always identical.

@iBotPeaches
Copy link
Owner

Well thats odd. I sure don't have enough knowledge on filesystems to even begin to understand why that is.

@iBotPeaches iBotPeaches merged commit 9ebd579 into iBotPeaches:master Aug 12, 2024
25 checks passed
@iBotPeaches iBotPeaches added this to the v2.10.0 milestone Aug 12, 2024
@luk1337 luk1337 deleted the luk/sort branch August 12, 2024 23:19
iBotPeaches added a commit that referenced this pull request Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants