package home.smart.fly.animations.ui.activity;

import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import home.smart.fly.animations.R;
import home.smart.fly.animations.utils.Tools;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class ReadJarActivity extends AppCompatActivity {
    private static final String FILE_NAME = "hack.jar";
    private static final String TAG = "ReadJarActivity";
    private static final String target = "com/bumptech/glide/RequestManager.class";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read_jar);
        findViewById(R.id.read_file).setOnClickListener(view -> readJarFromFile());
    }

    private void readJarFromFile() {

        String path = getFilesDir() + File.separator + FILE_NAME;
        File file = new File(path);
        if (file.exists()) {
            try {
                JarFile jarFile = new JarFile(file);
                Enumeration<JarEntry> entries = jarFile.entries();
                while (entries.hasMoreElements()) {
                    JarEntry entry = entries.nextElement();
                    Log.e(TAG, "readJarFromFile: " + entry.getName());
                    if (target.equals(entry.getName())) {
                        break;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else {
            if (Tools.copyFileFromAssetsToBox(FILE_NAME, this)) {
                Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
                readJarFromFile();
            }
        }
    }
}

@@ -41,16 +41,45 @@
 ivity;%0A%0A
+import android.os.FileUtils;%0A
 import a
@@ -195,24 +195,73 @@
 .os.Bundle;%0A
+import com.facebook.common.internal.ByteStreams;%0A
 import home.
@@ -334,56 +334,160 @@
 ls;%0A
-%0Aimport java.io.File;%0Aimport java.io.IOException
+import kotlin.jvm.internal.ClassReference;%0A%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream
 ;%0Aim
@@ -574,16 +574,85 @@
 JarFile;
+%0Aimport java.util.jar.JarOutputStream;%0Aimport java.util.zip.ZipEntry;
 %0A%0Apublic
@@ -758,16 +758,82 @@
 k.jar%22;%0A
+    private static final String FILE_NAME_COPY = %22hack_copy.jar%22;%0A
     priv
@@ -1368,445 +1368,1203 @@
 h);%0A
-        if (file.exists()) %7B%0A            try %7B%0A                JarFile jarFile = new JarFile(file);%0A                Enumeration%3CJarEntry%3E entries = jarFile.entries();%0A                while (entries.hasMoreElements()) %7B%0A                    JarEntry entry = entries.nextElement();%0A                    Log.e(TAG, %22readJarFromFile: %22 + entry.getName());%0A                    if (target.equals(entry.getName())) %7B%0A                        break
+%0A        String copy = getFilesDir() + File.separator + FILE_NAME_COPY;%0A        JarOutputStream jarOutputStream;%0A%0A%0A        if (file.exists()) %7B%0A            try %7B%0A                File outJarFile = new File(copy);%0A                if (outJarFile.exists()) %7B%0A                    outJarFile.delete();%0A                %7D%0A                jarOutputStream = new JarOutputStream(new FileOutputStream(outJarFile));%0A%0A                JarFile jarFile = new JarFile(file);%0A                Enumeration%3CJarEntry%3E entries = jarFile.entries();%0A                while (entries.hasMoreElements()) %7B%0A                    JarEntry entry = entries.nextElement();%0A                    Log.e(TAG, %22readJarFromFile: %22 + entry.getName());%0A                    String entryName = entry.getName();%0A%0A                    ZipEntry zipEntry = new ZipEntry(entryName);%0A                    InputStream inputStream = jarFile.getInputStream(entry);%0A                    jarOutputStream.putNextEntry(zipEntry);%0A%0A                    if (target.equals(entryName)) %7B%0A                        Log.e(TAG, %22readJarFromFile: ignored %22 + entryName);%0A                    %7D else %7B%0A                        ByteStreams.copy(inputStream, jarOutputStream)
 ;%0A  
@@ -2591,33 +2591,198 @@
                 
-%7D
+    inputStream.close();%0A                    jarOutputStream.closeEntry();%0A                %7D%0A                jarOutputStream.close();%0A                jarFile.close();
 %0A            %7D c
@@ -2837,24 +2837,97 @@
 ackTrace();%0A
+                Log.e(TAG, %22readJarFromFile fail :%5Cn%22 + e.getMessage());%0A
             
@@ -2937,16 +2937,17 @@
        %7D
+ 
 else %7B%0A 

read and copy jar