본문 바로가기

안드로이드

[JNI] C++코드로 JAVA 의 Priavate를 접근할 수 있는가?

[JNI] C++코드로 JAVA 의 Priavate를 접근할 수 있는가?

 대답은  YES이다.

 

C++의 JNI 는  JAVA IllegalAccessException 이 날수 있는 상황에서도 접근에 성공한다. JAVA차원에서 접근 제어자를 걸어두어도, C++는 상관하지 않고  JAVA의 메모리에 있는 모든 변수 , 함수 들을 가져올 수 있다.

 

아래는 관련된 공식 문서의 일부를 발췌한 것이다.

The JNI Programmer's Guide and Specification says this in "10.9 Violating Access Control Rules":

"The JNI does not enforce class, field, and method access control restrictions that can be expressed at the Java programming language level through the use of modifiers such as private and final. It is possible to write native code to access or modify fields of an object even though doing so at the Java programming language level would lead to an IllegalAccessException. JNI's permissiveness was a conscious design decision, given that native code can access and modify any memory location in the heap anyway."