- 24 Dec 2024
- 2 Minutes à lire
- SombreLumière
- PDF
Java code examples
- Mis à jour le 24 Dec 2024
- 2 Minutes à lire
- SombreLumière
- PDF
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.