Jump to content

Obfuscating your local scripts


Recommended Posts

Posted (edited)

As some people do not know how to do this, and it is useful to prevent people stealing your code, here is how to obfuscate (https://en.wikipedia.org/wiki/Obfuscation) using ProGuard.

 

If you don't know what Obfuscation looks like, here is an example of one of my classes, post obfuscation:

 

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.osbot.rs07.api.Bank;
import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.utility.ConditionalSleep;

public final class a
extends g {
    private final List b;
    private final ConditionalSleep c;

    public a(Combiner combiner, List list) {
        super(combiner);
        this.c = new b(this, 5000);
        this.b = list;
    }

    @Override
    public final boolean a() {
        for (c c2 : this.b) {
            if (!c2.d()) continue;
            return false;
        }
        return true;
    }

    @Override
    public final void b() {
        if (this.a.getBank() != null) {
            if (!this.a.getBank().isOpen()) {
                a a2 = this;
                try {
                    a2.a.getBank().open();
                    a2.c.sleep();
                }
                catch (InterruptedException var4_3) {
                    a2.a.log((Object)var4_3);
                    return;
                }
            }
            Object object = this.b.iterator();
            while (object.hasNext()) {
                a a3;
                f[] arrf;
                f[] arrf2;
                boolean bl;
                block12 : {
                    boolean bl2;
                    block11 : {
                        arrf2 = arrf = (f[])object.next();
                        a3 = this;
                        for (f f2 : arrf2.c()) {
                            if (a3.a.getBank().contains(new String[]{f2.a})) continue;
                            bl2 = false;
                            break block11;
                        }
                        bl2 = true;
                    }
                    if (!bl2) continue;
                    arrf2 = arrf;
                    a3 = this;
                    arrf = arrf2;
                    object = a3;
                    arrf = a.a((c)arrf);
                    Filter[] arrfilter = new Filter[1];
                    arrfilter[0] = arg_0 -> a.b((List)arrf, arg_0);
                    if (object.a.getInventory().contains(arrfilter)) {
                        arrf = arrf2;
                        object = a3;
                        arrf = a.a((c)arrf);
                        Filter[] arrfilter2 = new Filter[1];
                        arrfilter2[0] = arg_0 -> a.a((List)arrf, arg_0);
                        object.a.getBank().depositAllExcept(arrfilter2);
                        return;
                    }
                    arrf = arrf2;
                    object = a3;
                    for (f f2 : arrf.c()) {
                        if (object.a.getInventory().getAmount(new String[]{f2.a}) <= (long)f2.b) continue;
                        bl = true;
                        break block12;
                    }
                    bl = false;
                }
                if (bl) {
                    arrf = arrf2;
                    object = a3;
                    for (f f2 : arrf.c()) {
                        if (object.a.getInventory().getAmount(new String[]{f2.a}) <= (long)f2.b) continue;
                        object.a.getBank().deposit(f2.a, (int)object.a.getInventory().getAmount(new String[]{f2.a}) - f2.b);
                    }
                    return;
                }
                for (f f2 : arrf2.c()) {
                    if (a3.a.getInventory().contains(new String[]{f2.a})) continue;
                    a3.a.getBank().withdraw(f2.a, f2.b);
                }
                return;
            }
            this.a.log("Ran out of ingredients, stopping script.");
            this.a.stop(true);
        }
    }

    private static List a(c c2) {
        return Arrays.stream(c2.c()).map(f2 -> f2.a).collect(Collectors.toList());
    }

    private static /* synthetic */ boolean a(List list, Item item) {
        return list.contains(item.getName());
    }

    private static /* synthetic */ boolean b(List list, Item item) {
        if (!list.contains(item.getName())) {
            return true;
        }
        return false;
    }
} 

 

1. Download and extract proguard http://sourceforge.net/projects/proguard/files/

 

2. Create a folder anywhere called "proguard_configs", this is where you will store your configuration files to be used with ProGuard.

 

3. In the proguard_configs folder, create a new empty proguard config file (.pro) in notepad.

 

4. Define your configuration, here is the configuration I use for my scripts:

-injars       C:\Users\Username\OSBot\Scripts\script.jar 
-outjars      C:\Users\Username\Obfuscated\script_obf.jar 
-libraryjars  C:\Users\USername\Downloads\OSBot 2.4.29.jar 
-libraryjars  C:\Program Files\Java\jre1.8.0_66\lib\rt.jar

-keepattributes *Annotation*

-keep public class package.Main
  • -injars is file path to the script .jar to be obfuscated

  • -outjars is the file path to the obfuscated script .jar

  • -libraryjars are the OSBot.jar and the Java runtime rt.jar

  • -keepattributes *Annotation* ensures that we keep the @ScriptManifest annotation

  • Finally we specifiy that we want to keep the main Script class, as we need this as the entry point to our script.

  • You should replace "package.Main" with the package that your script is in, and the name of your main script file

 

5. Finally run the following command in cmd / terminal, replacing path_to_proguard with the path to proguard.jar, which is found in the proguard\lib folder, and path_to_config with the path to the .pro file you previously made:

java -jar path_to_proguard.jar @path_to_config.pro

6. Note if you get warnings about missing classes, that are not classes you have defined, add to you config the line, replacing javafx with the package name:

-dontwarn javafx.**
Edited by Explv
  • Like 12
Posted

Nice tut,. I tried it and got the "Processing completed successfully" message but my script wont show up in the client..Any ideas?

 

Missed a line out:

 

-keepattributes *Annotation*

 

Which is essential, because you need to keep the @ScriptManifest annotation.

 

I have edited the config.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...