CalebFenton / simplify

Android virtual machine and deobfuscator
Other
4.41k stars 438 forks source link

Improve Dead Code Removal Method #159

Open apkunpacker opened 3 years ago

apkunpacker commented 3 years ago

Obfuscator Used :

5742964208d197f408c982e6424902154505e2f1c4a0ee5d645d42d6a20f346c

MProtector_2.0.apk.zip created by https://github.com/KingMahmud

Sample Obfuscated : Sample.apk.zip

Simplify Command Used :

java -jar simplify.jar --max-call-depth 999999 --max-address-visits 999999 --max-method-visits 999999 --ignore-error -it 'Lcom/tilks/arsc/main/MainActivity;->e\(' Sample.apk

logs :

11:19:21.704 INFO  Main         - Options:
Input file: Sample.apk.zip
Output file: Sample.apk_simple.zip
Include filter: Lcom/tilks/arsc/main/MainActivity;->e\(
Exclude filter: null
Max execution time: 300
Max address visits: 999999
Max call depth: 999999
Max method visits: 999999
Max optimization passes: 100
Output API level: 20
Include support library: false
11:19:24.053 INFO  Main         - Filtered 0 support library classes
[1 / 1] Processing top level class Lcom/tilks/arsc/main/MainActivity;
(1 / 1) Executing top level method: Lcom/tilks/arsc/main/MainActivity;->e()Ljava/lang/String;
11:19:40.461 INFO  NonInteractiveMethodExecutor - Executing Landroid/app/Activity;-><clinit>()V, depth=0
11:19:40.537 INFO  NonInteractiveMethodExecutor - Executing Lcom/tilks/arsc/main/MainActivity;-><clinit>()V, depth=0
11:19:40.613 INFO  NonInteractiveMethodExecutor - Executing Lcom/tilks/arsc/main/MainActivity;->e()Ljava/lang/String;, depth=0
11:19:40.634 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:40.664 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:40.717 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:40.758 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:40.821 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:40.882 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:40.918 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:40.949 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:40.969 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:40.989 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.010 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.031 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.052 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.073 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.093 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.153 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.214 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.266 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.286 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.308 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.328 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.349 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.370 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.391 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.412 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.433 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.455 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.477 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.498 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.520 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.541 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.562 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.584 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.605 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.627 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.657 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.675 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:41.905 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:41.955 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:42.036 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:42.075 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:42.118 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:42.163 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_(Ljava/lang/String;)V, depth=1
11:19:42.239 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:42.256 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
Simplifying: Lcom/tilks/arsc/main/MainActivity;->e()Ljava/lang/String;
11:19:42.374 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
11:19:42.388 INFO  NonInteractiveMethodExecutor - Executing L€/£/¥/₩;->_()V, depth=1
Optimizations:
    constantized ifs = 0
    constantized ops = 0
    dead assignments removed = 24
    dead ops removed = 0
    dead results removed = 0
    nops removed = 0
    peephole optmizations = 0
    unreflected fields = 0
    unreflected methods = 0
    useless gotos removed = 0
Simplification complete:
    total classes = 1
    total methods = 1
    optimized methods = 1
    failed methods = 0
    run time = 20713 ms
Total optimizations:
    constantized ifs = 0
    constantized ops = 0
    dead assignments removed = 24
    dead ops removed = 0
    dead results removed = 0
    nops removed = 0
    peephole optmizations = 0
    unreflected fields = 0
    unreflected methods = 0
    useless gotos removed = 0
Writing output to Sample.apk_simple.zip

That method after simplified : simplified.txt

Expected : expected.txt

Reason :

invoke-static/range {v1 .. v1}, L€/£/¥/₩;->_(Ljava/lang/String;)V

and

invoke-static {}, L€/£/¥/₩;->_()V

are empty method , anything pass through them have no effect on code so they should be considered as dead and removed . continuous use of same register again and again also should be treated as dead as next assignment of same register overwrite previous value like

    invoke-static {}, L€/£/¥/₩;->_()V

    invoke-static {p0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    invoke-static {}, L€/£/¥/₩;->_()V

    const-string v1, "saallnnsls"

    invoke-static/range {v1 .. v1}, L€/£/¥/₩;->_(Ljava/lang/String;)V

    const-string v1, "ELBANENGIS"

    invoke-static/range {v1 .. v1}, L€/£/¥/₩;->_(Ljava/lang/String;)V

    const-string v1, "signenable"

    invoke-static/range {v1 .. v1}, L€/£/¥/₩;->_(Ljava/lang/String;)V

could be simplified to

     invoke-static {p0}, Landroid/preference/PreferenceManager;->getDefaultSharedPreferences(Landroid/content/Context;)Landroid/content/SharedPreferences;

    move-result-object v0

    const-string v1, "signEnable"

as v1 keep overwritten and only last assignment of register is used

Thanks

CalebFenton commented 3 years ago

Thanks for the error report. I can't get to it now because all my spare time is focused on simplify 2.x rewrite, but I'll get to this eventually :D

Luffitys commented 2 years ago

Thanks for the error report. I can't get to it now because all my spare time is focused on simplify 2.x rewrite, but I'll get to this eventually :D

Since it has been a while, will simplify 2.x ever get to see the sunlight? Haha

CalebFenton commented 2 years ago

@Luffitys I got a new car, house, child, and position at work. I'd love to work on 2.x but I'm doing 50 other things every day from dawn 'til dusk. Maybe this year once things calm down and I'm not worried about this baby dying all the time. Thanks for your interest!