Java code examples
  • 22 Jan 2025
  • 2 Minutes à lire
  • Sombre
    Lumière
  • PDF

Java code examples

  • Sombre
    Lumière
  • PDF

The content is currently unavailable in French. You are viewing the default English version.
Résumé de l’article

The binding mechanisms are performed on smali code, which is Apktool’s internal code format. Smali is a text representation of the Dalvik byte code instructions which may be compared to how assembler code represents machine code in readable text. However, for clarity, the following examples are using Java code equivalents of the smali code transformations performed.

Original code:

public class A {
    private static final String message = "Hello!";

    public void print() {
        for (int i = 0; i < 5; i++) {
            System.out.println(message + " " + i);
        }
    }
}

After push bindings:

import no.promon.shield.Binding;
import no.promon.shield.LibShieldStarter;

public class A {
    private static final String message = null;  // "Hello!"

    public void print() {
        for (int i = fsh_1; i < fsh_2; i++) {
            System.out.println(message + fsh_3 + i);
        }
    }

    public static final int fsh_1 = 0;           // 0
    public static final int fsh_2 = 0;           // 5
    public static final String fsh_3 = null;     // " "

    static {
        LibStarter.startLibFromClinit();
        Binding.pushToClass(A.class, 42);
    }
}
  • The two constants used in the for-loop have been replaced with two class field references: fsh_1 and fsh_2.

  • The original message field has been modified to use a null value rather than the original message.

  • The constant containing one space has been moved to a class field fsh_3 of type String, also with the incorrect null value.

  • Lastly, the class now contains a static initializer that will ensure App Shielding is loaded before the class can be used at all, and a call to push the bindings into the class that is identified by a random identifier (in this case 42).

After pull bindings:

import no.promon.shield.Binding;
import no.promon.shield.LibShieldStarter;

public class A {
    private static final String message = Binding.getStr(0);

    public void print() {
        for (int i = Binding.getInt(1); i < Binding.getInt(2); i++) {
            System.out.println(message + Binding.getStr(3) + i);
        }
    }

    static {
        LibStarter.startLibFromClinit();
    }
}

All constants were removed from the code and replaced by calls to fetch these constants from App Shielding on demand. App Shielding will need a constant handle, in order to know the value to return which has been placed in the code by the Shielding Tool instead. The static initializer is created and will ensure that App Shielding is loaded.

After pull and push bindings:

import no.promon.shield.Binding;
import no.promon.shield.LibShieldStarter;

public class A {
    private static final String message = null;

    public void print() {
        for (int i = fsh_1; i < fsh_2; i++) {
            System.out.println(message + Binding.getStr(0) + i);
        }
    }

    public static final int fsh_1 = 0;
    public static final int fsh_2 = 0;

    static {
        LibStarter.startLibFromClinit();
        Binding.pushToClass(A.class, 42);
    }
}

In this class both pull and push bindings are used in a combination.


Cet article vous a-t-il été utile ?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Ozzy, facilitant la découverte de connaissances grâce à l’intelligence conversationnelle