Enums

working with enums

**** NOTE: BLOG MOVED TO https://cmrodriguez.me/ ****

It is a bit complicated to work on Enums. There is a difference between Enums and common classes. The latter has multiple values but no status. So it is usually used to hold finite and semantically strong status, like in the following case months of a year (in Java code):

enum Month { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }

To set a value you have to define the value to set:

Month month = Month.APR;

In Frida we have the following possibilties:

1) Generate a Frida reference to the enum

Month =  Java.use("com.blog.testfrida.complexobjects.DateAbstraction$Month");

2) Get all the possible values (it returns an array, so it can be iterated as shown in the array part of this guide):

Month.values();

3) Print the value of a particular state. Note that we need a .value to get to the real value and not the wrapper of the status:

//Month has not redefined the toString so it calls the Object one
console.log(Month.APR.value);

4) The toString method does not work in this case, as it will print the generic "[object Object]" string.

5) Instantiate a Month value based on a String, and send it as a parameter (there are two ways to send it as a parameter to the Java method):

console.log(DateAbstraction.getMonthName(Month.valueOf(String.$new("APR"))));
console.log(DateAbstraction.getMonthName(Month.APR.value));

While writing this guide I had issues finding a way to get the value from a method (when it returns an Enum) and get the value when You want to override a method. The following example does not work as expected. We have the following code in Java:

public static Month getMay() {
    return Month.MAY;
}

When we get the result from Frida:

May = DateAbstraction.getMay();

the object returned seems to be the Month enum itself and not the particular value (so as an example the *.value does not work with the May object). I'll post a bug in the Frida repo and will update the result.

Last updated