> For the complete documentation index, see [llms.txt](https://docs.cooku222.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cooku222.kr/security/mobile/frida-lab/frida-labs-0x4.md).

# Frida-Labs 0x4

출처: <https://github.com/DERE-ad2001/Frida-Labs/tree/main/Frida%200x4>

***

```
PS C:\Users\after\Downloads> adb install Challenge_0x4.apk
Performing Streamed Install
Success
```

<figure><img src="https://blog.kakaocdn.net/dna/da5lGO/dJMcaioL0Yn/AAAAAAAAAAAAAAAAAAAAADXsOTAmCdmR2FZzBWEv9aM0uQrFOENtual5EaRpGKF2/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=%2Bh7dV40atvFlry5AlaDjxrogF9Q%3D" alt="" height="508" width="1443"><figcaption></figcaption></figure>

adb 상에 설치하고 MainActivity부터 시작해보나 특이점은 없어보이니 com.ad2001.frida0x4 클래스중 Check 클래스를 확인해준다.

<figure><img src="https://blog.kakaocdn.net/dna/V1BUR/dJMb99SSF7h/AAAAAAAAAAAAAAAAAAAAAIrnbso3BWW10VfUDznwpsbiqEdyhkD5I98VasS1kgis/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=LjCPKg3z308yb6LkhBjhT1QtNFY%3D" alt="" height="460" width="1005"><figcaption></figcaption></figure>

위 함수를 보면 get\_flag() 메서드가 보인다. 중간에 보면 ^로 XOR 연산이 이루어지는 것을 볼 수 있다. 키 15를 이용해 I]FKNtW@]JKPFA\\\\\[NALJr 라는 문자열을 디코딩한다. 게다가 get\_flag() 메서드는 코드 전체에서 호출되는 구간이 없다\
(따라서 frida로 이 함수를 호출 해 a가 1337일 때 동작하는 것으로? 의도하고 호출해주면 될 거 같다.)\
앞 문제들과의 차이점인데, 디스어셈블한 java 코드에서 호출방식에 static와 instance 차이가 존재한다.

#### Frida에서 static vs instance 호출 차이

* static: ClassName.method(…)
* instance: var obj = ClassName.$new(); obj.method(…)

이런 차이점이 있다. \
static 메서드가 아닌 경우 frida에서 instance를 먼저 생성해준 후 메서드를 호출할 수 있다.&#x20;

```
Check ch = new Check();
String flag = ch.get_flag(1337);
```

이 함수는 문자열을 반환하므로 그 반환값을 변수에 저장해야 한다.

```
Java.perform(function() {

  var <class_reference> = Java.use("<package_name>.<class>");
  var <class_instance> = <class_reference>.$new(); // Class Object
  <class_instance>.<method>(); // Calling the method

})
```

&#x20;\
Frida에서 Java 클래스의 인스턴스를 생성하려면 $new() 메서드를 사용한다. 이 메서드는 Frida 전용 메서드로 특정 클래스의 객체를 생성할 수 있게 해준다. \
주어진 정보로는&#x20;

* 패키지 이름: com.ad2001.frida0x4
* 클래스 이름: Check
* 메서드 이름: get\_flag

와 같은 정보들이 있다.&#x20;

```
Java.perform(function(){
	var check=Java.use("com.ad2001.frida0x4.Check");
	var check_obj=check.$new();
	var res = check_obj.get_flag(1337);
	console.log("FLAG" + res);
})
```

위와 같이 코드를 짤 수 있다.&#x20;

```
PS C:\Users\after\Downloads> frida -U -f com.ad2001.frida0x4
     ____
    / _  |   Frida 17.5.1 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to Android Emulator 5554 (id=emulator-5554)
Spawning `com.ad2001.frida0x4`...                                      Spawned `com.ad2001.frida0x4`. Resuming main thread!
[Android Emulator 5554::com.ad2001.frida0x4 ]-> Java.perform(function(
){
var check=Java.use("com.ad2001.frida0x4.Check");
var check_obj=check.$new();
var res = check_obj.get_flag(1337);
console.log("FLAG" + res);
})
FLAGFRIDA{XORED_INSTANCE}
```

플래그가 출력되는 것을 확인할 수 있다!

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.cooku222.kr/security/mobile/frida-lab/frida-labs-0x4.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.
