# Enums

\*\*\*\* **NOTE: BLOG MOVED TO** [**https://cmrodriguez.me/**](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):

```java
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:

```java
Month month = Month.APR;
```

In Frida we have the following possibilties:

1\) Generate a Frida reference to the enum

```javascript
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):

```javascript
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:

```javascript
//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):

```javascript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://neo-geo2.gitbook.io/adventures-on-security/frida-scripting-guide/enums.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
