2222import com .fox2code .mmm .compat .CompatActivity ;
2323import com .fox2code .mmm .utils .FastException ;
2424import com .fox2code .mmm .utils .Files ;
25+ import com .fox2code .mmm .utils .Hashes ;
2526import com .fox2code .mmm .utils .Http ;
2627import com .fox2code .mmm .utils .IntentHelper ;
2728import com .google .android .material .progressindicator .LinearProgressIndicator ;
@@ -54,6 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
5455 final Intent intent = this .getIntent ();
5556 final String target ;
5657 final String name ;
58+ final String checksum ;
5759 final boolean noPatch ;
5860 final boolean noExtensions ;
5961 final boolean rootless ;
@@ -66,6 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
6668 }
6769 target = intent .getStringExtra (Constants .EXTRA_INSTALL_PATH );
6870 name = intent .getStringExtra (Constants .EXTRA_INSTALL_NAME );
71+ checksum = intent .getStringExtra (Constants .EXTRA_INSTALL_CHECKSUM );
6972 noPatch = intent .getBooleanExtra (Constants .EXTRA_INSTALL_NO_PATCH , false );
7073 noExtensions = intent .getBooleanExtra (// Allow intent to disable extensions
7174 Constants .EXTRA_INSTALL_NO_EXTENSIONS , false );
@@ -122,6 +125,15 @@ protected void onCreate(Bundle savedInstanceState) {
122125 this .progressIndicator .setProgressCompat (progress , true );
123126 });
124127 });
128+ if (checksum != null && !checksum .isEmpty ()) {
129+ Log .d (TAG , "Checking for checksum: " + checksum );
130+ this .installerTerminal .addLine ("- Checking file integrity" );
131+ if (!Hashes .checkSumMatch (rawModule , checksum )) {
132+ this .setInstallStateFinished (false ,
133+ "! File integrity check failed" , "" );
134+ return ;
135+ }
136+ }
125137 if (noPatch ) {
126138 try (OutputStream outputStream = new FileOutputStream (moduleCache )) {
127139 outputStream .write (rawModule );
@@ -152,13 +164,31 @@ protected void onCreate(Bundle savedInstanceState) {
152164 }
153165 }, "Module download Thread" ).start ();
154166 } else {
167+ final File moduleFile = new File (target );
168+ if (checksum != null && !checksum .isEmpty ()) {
169+ Log .d (TAG , "Checking for checksum: " + checksum );
170+ this .installerTerminal .addLine ("- Checking file integrity" );
171+ try {
172+ if (!Hashes .checkSumMatch (Files .readSU (moduleFile ), checksum )) {
173+ this .setInstallStateFinished (false ,
174+ "! File integrity check failed" , "" );
175+ return ;
176+ }
177+ } catch (IOException e ) {
178+ Log .e (TAG , "Failed to read file for checksum check" , e );
179+ this .setInstallStateFinished (false ,
180+ "! File integrity check failed" , "" );
181+ return ;
182+ }
183+ }
155184 this .installerTerminal .addLine ("- Installing " + name );
156185 new Thread (() -> this .doInstall (
157- this .toDelete = new File ( target ) , noExtensions , rootless ),
186+ this .toDelete = moduleFile , noExtensions , rootless ),
158187 "Install Thread" ).start ();
159188 }
160189 }
161190
191+
162192 private void doInstall (File file ,boolean noExtensions ,boolean rootless ) {
163193 Log .i (TAG , "Installing: " + moduleCache .getName ());
164194 InstallerController installerController = new InstallerController (
0 commit comments