KR20120126920A - Method for Anti-Encoding Android by Using Java Native Interface - Google Patents

Method for Anti-Encoding Android by Using Java Native Interface Download PDF

Info

Publication number
KR20120126920A
KR20120126920A KR1020110045055A KR20110045055A KR20120126920A KR 20120126920 A KR20120126920 A KR 20120126920A KR 1020110045055 A KR1020110045055 A KR 1020110045055A KR 20110045055 A KR20110045055 A KR 20110045055A KR 20120126920 A KR20120126920 A KR 20120126920A
Authority
KR
South Korea
Prior art keywords
jni
android
java
class
obfuscation
Prior art date
Application number
KR1020110045055A
Other languages
Korean (ko)
Other versions
KR101234591B1 (en
Inventor
홍동철
홍민표
Original Assignee
(주)쉬프트웍스
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by (주)쉬프트웍스 filed Critical (주)쉬프트웍스
Priority to KR1020110045055A priority Critical patent/KR101234591B1/en
Publication of KR20120126920A publication Critical patent/KR20120126920A/en
Application granted granted Critical
Publication of KR101234591B1 publication Critical patent/KR101234591B1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/10Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
    • G06F21/12Protecting executable software
    • G06F21/14Protecting executable software against software analysis or reverse engineering, e.g. by obfuscation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)
  • Multimedia (AREA)
  • Technology Law (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)

Abstract

PURPOSE: An Android obfuscation method with a JNI(Java Native Interface) is provided to prevent the exposure of text string data by converting a text string into the JNI and implementing a class and method call part with a callback method of the JNI. CONSTITUTION: All of variables, methods, and classes are changed into a specific text format by changing classes and functions defined in an AndroidManfest.xml(S100). A declared text string of a byte code is changed into a JNI which is a binary code(S300). A part calling a class method in an object oriented program is removed from a Java source code and changed into a part calling the JNI(S400). [Reference numerals] (AA) Start; (BB) End; (S100) Changing all variables, methods, and classes in a java file into a, b, and c formats; (S200) Changing a text row in the java file into an SO library; (S300) Changing a byte code into a JNI, binary code; (S400) Removing a class method call part from a java source code and changing into a JNI call part; (S500) Calling a java function by the JNI

Description

JNI를 이용한 안드로이드 난독화 방법{Method for Anti-Encoding Android by Using Java Native Interface}Method for Anti-Encoding Android by Using Java Native Interface}

본 발명은 JNI를 이용한 안드로이드 난독화 방법에 관한 것으로, 보다 상세하게는 달빅(Dalvik) 언어를 사용하는 안드로이드의 역 컴파일을 방어하기 위해 문자열을 제이엔아이(Java Native Interface; 이하 'JNI')로 변경하고 호출된 함수가 JNI를 거쳐 호출되도록 하는 JNI를 이용한 안드로이드 난독화 방법에 관한 것이다.
The present invention relates to an Android obfuscation method using JNI, and more specifically, to protect against decompilation of Android using the Dalvik language, a string is converted into a Java Native Interface (“JNI”). It's about Android obfuscation using JNI to make changes and cause called functions to be called via JNI.

스마트폰의 대중화 가운데에서 안드로이드는 가장 인기를 끌고 있는 단말 플랫폼이다. Among the popularization of smartphones, Android is the most popular terminal platform.

하지만 안드로이드는 기존의 자바(JAVA)와 비슷한 언어인 Dalvik을 이용하여 사용되기 때문에 역 컴파일에 노출이 쉽다는 단점이 있다. However, Android uses Dalvik, a language similar to Java (JAVA), so it is easy to be exposed to reverse compilation.

이러한 단점을 파고들어서 최근에는 역 컴파일을 위해 덱스(dex) 등의 툴 들이 등장함에 따라 역 컴파일을 방어하기 위한 난독화 기술이 절실해 졌다.With these shortcomings, in recent years, tools such as dex have been introduced for decompiling, and obfuscation techniques for defending decompilation have been urgently needed.

한편, 자바를 컴파일하면 클래스(class) 파일로 생성되어 실행파일이 class 파일이 되지만 안드로이드는 에이피케이(apk)라는 확장자를 가진 실행 파일을 사용하고 있다. On the other hand, when Java is compiled, it is created as a class file and the executable file becomes a class file. However, Android uses an executable file with the extension of apk.

상기 apk 파일은 일반적인 짚(zip) 압축 파일과 같은 형태로 구현되어 있으며, 파일의 구조는 아래 표 1과 같다.The apk file is implemented in the form of a general zip compressed file, and the structure of the file is shown in Table 1 below.

파일명Filename 설명Explanation AndroidManifest.xml AndroidManifest.xml apk실행파일의 설정 파일
사용할 수 있는 권한이나 사용하는 Class 그리고 구조를 말한다
apk executable file
Permission to use, class to use, and structure
Classes.dexClasses.dex 실제로 java 소스파일이 컴파일 되어 생성Actually java source file is compiled META-INFMETA-INF 인증된 키값이 저장된 폴더Folder where authenticated key values are stored resres 그래픽과 관련된 이미지 및 레이아웃Images and layouts related to graphics liblib so라이브러리 so library

프로그램시 java 파일은 classes.dex. 파일로 변경되며 이 파일에는 모든 java 클래스의 값들이 Dalvik 가상머신에서 인식하기 쉽도록 묶여있다.When programming the java file is classes.dex. It is changed to a file that contains the values of all java classes tied together for easy recognition by the Dalvik virtual machine.

도 1은 종래의 역 컴파일 방법을 나타낸 도면이고, 도 2는 종래의 역 컴파일을 통해 class파일로 변경된 예를 나타낸 도면이고, 도 3은 종래의 역 컴파일을 통해 class파일로 변경된 파일 리스트를 나타낸 도면이고, 도 4는 종래의 JD 역 컴파일러를 통한 소스 보기 상태를 나타낸 도면이다.1 is a diagram illustrating a conventional reverse compilation method, FIG. 2 is a view showing an example of a class file changed through a conventional reverse compilation, and FIG. 3 is a view showing a file list changed to a class file through a conventional reverse compilation. 4 is a view showing a source view state through a conventional JD reverse compiler.

도 1 내지 도 4에 도시된 바와 같이, classes.dex.파일은 먼저 dex파일을 class로 만들고 그것을 다시 java파일로 역 컴파일하는 과정을 거치게 된다.As shown in Figs. 1 to 4, the classes.dex. File first undergoes a process of dex file generation into a class and then back-compiled into a java file.

이렇듯, 역 컴파일러를 통해 도 2와 같이 class 파일로 변경할 수 있다.As such, it can be changed into a class file as shown in FIG. 2 through a reverse compiler.

상기 classes.dex.파일이 역 컴파일 되어 도 3의 c$1.class의 이름을 갖는 class 파일로 표시된다.The classes.dex. File is decompiled and represented as a class file having the name c $ 1.class in FIG.

상기 class 파일을 일반적인 자바 역컴파일러인 JD를 통하여 역 컴파일하면 도 4에서와 같이 소스를 볼 수 있는 문제점이 있다.If the class file is decompiled through JD, which is a general Java decompiler, the source can be viewed as shown in FIG.

상기와 같은 문제점을 해결하기 위한 본 발명의 목적은 기존의 자바 난독화 기술의 연장선에서 벗어나 클래스와 메소드명을 안드로이드에 맞게 변경하고, JNI를 이용하여 난독화의 수준을 높이도록 하는 JNI를 이용한 안드로이드 난독화 방법을 제공함에 있다.An object of the present invention for solving the above problems is to extend the level of obfuscation using JNI to change the class and method names to Android, and to extend the level of obfuscation using JNI, which is an extension of the existing Java obfuscation technology. The present invention provides a method for obfuscation.

본 발명의 다른 목적은, 역 컴파일을 통한 코드를 통해서도 실제 코드가 어떠한 행위를 하는지 알 수 없도록 하는 JNI를 이용한 안드로이드 난독화 방법을 제공함에 있다.Another object of the present invention is to provide an Android obfuscation method using JNI, which makes it impossible to know what the actual code does even through code through decompilation.

본 발명의 또 다른 목적은, 함수가 호출되면 JNI를 거쳐 호출되도록 함으로써, 역공학으로 소스 추출이 불가능하도록 하는 JNI를 이용한 안드로이드 난독화 방법을 제공함에 있다.
Still another object of the present invention is to provide an Android obfuscation method using JNI, which makes it impossible to extract a source by reverse engineering when a function is called through JNI.

상기한 본 발명의 목적은, 안드로이드 소스의 역 컴파일을 방어하기 위한 난독화 방법에 있어서, 자바파일 내부의 모든 변수, 메소드 및 클래스를 특정 문자 형식으로 변경하는 제 1 단계; 및 상기 자바파일에서 문자열을 so라이브러리로 변경하는 제 2 단계를 포함하되, 상기 제 2 단계는, 바이트코드의 선언된 문자열을 바이너리 코드인 JNI로 변경하는 제 2-1 단계; 및 객체지향 프로그램에서 클래스 메소드를 호출하는 부분을 자바 소스코드에서 제거하고 JNI를 호출하는 부분으로 변경하는 제 2-2 단계를 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법에 의해 달성된다.An object of the present invention as described above, the obfuscation method for preventing the reverse compilation of the Android source, the first step of changing all variables, methods and classes in the Java file to a specific character format; And a second step of changing a string into a so library in the Java file, wherein the second step comprises: a second step of changing a declared string of bytecode into JNI, which is a binary code; And step 2-2 of removing the part of the class method call from the object-oriented program from the Java source code and changing the part of the JNI call to the part of calling the JNI.

또한 본 발명에 따르면, AndroidManfest.xml 내에 정의되어있는 클래스와 함수를 변경하는 단계를 더 포함하는 것을 특징으로 한다.In addition, according to the present invention, characterized in that it further comprises the step of changing the classes and functions defined in the AndroidManfest.xml.

또한 본 발명에 따르면, 상기 제 1 단계는, AndroidManfest.xml에서 패키지 경로를 mainfest 태그의 package에 선언하는 단계를 더 포함하는 것을 특징으로 한다.In addition, according to the present invention, the first step is characterized in that it further comprises the step of declaring the package path in the package of the mainfest tag in AndroidManfest.xml.

또한 본 발명에 따르면, 상기 제 1 단계는, 패키지 명칭과 클래스 명을 참조하여 소스파일에서 클래스의 위치를 찾아 변경하는 단계를 더 포함하는 것을 특징으로 한다.According to the present invention, the first step may further include finding and changing the location of the class in the source file with reference to the package name and the class name.

또한 본 발명에 따르면, 상기 제 1 단계는, 상기 특정 문자는 'a','b,'c' 형식으로서, 문자열의 첫 머리만으로 역공학이 편리해지지 않도록 사용되는 문자의 개수를 제한하며, 추가되는 문자는 'a1','b1','c1' 형식으로 숫자를 늘려 표시하는 것을 특징으로 한다.Further, according to the present invention, the first step, the specific character is a 'a', 'b,' c 'format, limiting the number of characters used so that reverse engineering is not convenient to only the first head of the string, Characters are characterized by increasing the number in the format 'a1', 'b1', 'c1'.

또한 본 발명에 따르면, 상기 제 2 단계는, 함수가 호출되면 JNI를 거쳐 호출되는 제 2-3 단계를 더 포함하는 것을 특징으로 한다.In addition, according to the present invention, the second step, characterized in that it further comprises a second to third step is called via a JNI when the function is called.

또한 본 발명에 따르면, 상기 제 2-3 단계는, 함수가 호출되면 타 클래스에서 호출하는 오리지널(original) 자바 코드를 확인하는 단계; 상기 호출된 함수에 해당하는 변경된 자바 파일의 문자열을 찾는 단계; 및 JNI로 상기 문자열에 해당하는 함수를 호출하는 단계를 포함하는 것을 특징으로 한다.In addition, according to the present invention, the step 2-3 may include: checking original Java code called by another class when a function is called; Finding a string of the changed Java file corresponding to the called function; And calling a function corresponding to the string with JNI.

또한 본 발명에 따르면, 상기 제 2 단계는, JNI 클래스에서 콜백 함수를 통하여 자바 메소드를 호출하는 경우, 메소드를 private로 선언하는 단계를 더 포함하는 것을 특징으로 한다.
Also, according to the present invention, the second step may further include the step of declaring a method private when calling a Java method through a callback function in a JNI class.

본 발명의 JNI를 이용한 안드로이드 난독화 방법에 의하면, 역 컴파일을 통한 코드를 통해서도 실제 코드가 어떠한 행위를 하는지 알 수 없는 효과가 있다.According to the Android obfuscation method using the JNI of the present invention, there is an effect that can not know what the actual code behaves even through the code through the reverse compilation.

본 발명의 JNI를 이용한 안드로이드 난독화 방법에 의하면, 문자열 데이터의 노출 방지를 위해 문자열을 JNI로 변경하고, 함수 사용을 위한 클래스와 메소드 호출 부분을 JNI의 콜백 메소드로 구현함으로써, 중간에 흐름을 끊도록 하는 효과가 있다.According to the Android obfuscation method using the JNI of the present invention, the flow is interrupted by changing the string to JNI to prevent the exposure of the string data, and implementing the class and method call parts for using the function as JNI callback methods. It is effective to make.

본 발명의 JNI를 이용한 안드로이드 난독화 방법에 의하면, 함수가 호출되면 JNI를 거쳐 호출되도록 함으로써, 역공학으로 소스 추출이 불가능하도록 하는 효과가 있다.
According to the Android obfuscation method using the JNI of the present invention, when the function is called through the JNI, the source extraction is impossible by reverse engineering.

도 1은 종래의 역 컴파일 방법을 나타낸 도면.
도 2는 종래의 역 컴파일을 통해 class파일로 변경된 예를 나타낸 도면.
도 3은 종래의 역 컴파일을 통해 class파일로 변경된 파일 리스트를 나타낸 도면.
도 4는 종래의 JD 역 컴파일러를 통한 소스 보기 상태를 나타낸 도면.
도 5는 본 발명의 실시예에 따른 JNI를 이용한 안드로이드 난독화 방법의 흐름도.
도 6은 본 발명의 실시예에 따른 AndroidManifest.xml에서 패키지 경로 선언문의 예를 나타낸 도면.
도 7은 본 발명의 실시예에 따른 호출 함수가 JNI를 거쳐 호출되는 과정을 나타낸 도면.
1 is a diagram illustrating a conventional inverse compilation method.
2 is a view showing an example changed to a class file through the conventional inverse compilation.
3 is a view showing a file list changed to a class file through a conventional reverse compilation.
4 illustrates a source view state through a conventional JD reverse compiler.
5 is a flowchart of an Android obfuscation method using JNI according to an embodiment of the present invention.
6 is a diagram showing an example of a package path declaration in AndroidManifest.xml according to an embodiment of the present invention.
7 is a diagram illustrating a process of calling a call function through JNI according to an embodiment of the present invention.

본 명세서 및 청구범위에 사용된 용어나 단어는 통상적이거나 사전적인 의미로 한정해서 해석되어서는 아니되며, 발명자는 그 자신의 발명을 가장 최선의 방법으로 설명하기 위해 용어의 개념을 적절하게 정의할 수 있다는 원칙에 입각하여 본 발명의 기술적 사상에 부합하는 의미와 개념으로 해석되어야만 한다.The terms and words used in the present specification and claims should not be construed as limited to ordinary or dictionary terms and the inventor may appropriately define the concept of the term in order to best describe its invention It should be construed as meaning and concept consistent with the technical idea of the present invention.

따라서, 본 명세서에 기재된 실시예와 도면에 도시된 구성은 본 발명의 가장 바람직한 일 실시예에 불과할 뿐이고 본 발명의 기술적 사상을 모두 대변하는 것은 아니므로, 본 출원시점에 있어서 이들을 대체할 수 있는 다양한 균등물과 변형 예들이 있을 수 있음을 이해하여야 한다.Therefore, the embodiments described in the specification and the drawings shown in the drawings are only the most preferred embodiment of the present invention and do not represent all of the technical idea of the present invention, various modifications that can be replaced at the time of the present application It should be understood that there may be equivalents and variations.

이하에서는 첨부된 도면을 참조하여 본 발명의 바람직한 실시예를 상세하게 설명하기로 한다.Hereinafter, preferred embodiments of the present invention will be described in detail with reference to the accompanying drawings.

일반적으로 Dex파일과 class파일은 바이트코드로 작성되어서 해석되며 이는 바이너리와 다르게 역 컴파일까지 가능하게 되어서 실제 소스까지 볼 수가 있다.In general, Dex file and class file are interpreted by writing byte code. Unlike binary, it is possible to decompile and see the actual source.

자바는 기본적으로 플랫폼 독립적인 장점을 유지하기 위해서 개발자들이 JNI를 널리 이용하지 않고 있지만 안드로이드 코드는 오로지 안드로이드에서만 작동하기 때문에 플랫폼 독립적일 필요가 없다. 따라서 JNI를 이용한 난독화를 하게되면 역공학을 막는데 탁월한 성능을 기대할 수 있다.Java does not use JNI widely to maintain platform-independent benefits by default, but Android code does not need to be platform-independent because it only works on Android. Therefore, if you use JNI obfuscation, you can expect excellent performance to prevent reverse engineering.

안드로이드는 리눅스 운영체제를 갖으며 라이브러리 파일은 so파일 확장자로 되어 JVM과 통신한다. JNI는 이러한 Dalvik과의 통신코드 때문에 일반적인 라이브러리보다 더욱 역공학이 어렵다.Android has a Linux operating system and library files have a so file extension to communicate with the JVM. JNI is more difficult to reverse engineer than a normal library because of this communication code with Dalvik.

최근 안드로이드에서는 기본적으로 JNI를 제공하며 Android NDK라는 빌드 툴을 제공해주고 있다. JNI는 기본적으로 클래스 내에 정적변수로 라이브러리 선언 함수를 넣는다. Recently, Android provides JNI by default and build tool called Android NDK. JNI basically puts the library declaration function as a static variable within the class.

먼저, JIN의 기본적인 소스 형태를 설명하도록 한다.First, let's explain the basic source form of JIN.

static {System.loadLibrary("android_security");}static {System.loadLibrary ("android_security");}

모듈명은 상기와 같이, 기본적으로 lib이 앞에 붙게 컴파일되며 모듈명이 libandroid_security.so 이라면 android_security가 실제 모듈에서 호출되어야 하는 부분이다.As above, the module name is basically compiled with lib in front of it. If the module name is libandroid_security.so, android_security should be called in the actual module.

public native void <메소드명>;public native void <method name>;

또한, native함수로 상기와 같이 선언을 하면 실제 함수에서 해당 메소드를 불러 사용한다.Also, if you declare as above with native function, the relevant method is called and used.

반환 데이터형 Java_<패키지명>_<클래스명>_<메소드명>Return data type Java_ <package name> _ <class name> _ <method name>

JNI를 작성할 때 C 코드에서는 메소드를 상기와 같은 규칙으로 생성하게 되면 해당 자바 파일과 통신을 하게 된다.When writing JNI, C code creates a method with the same rules as above to communicate with the corresponding Java file.

jbytejbyte

Java_kr_co_soongsil_VirusCheck_charJNI1( JNIEnv* env,Java_kr_co_soongsil_VirusCheck_charJNI1 (JNIEnv * env,

jobject thiz )                                                  jobject thiz)

{{

return 'e';return 'e';

}}

JNIEnv* env, jobject thiz 는 반드시 넣어야 하는 부분이며 해당 인자값 뒤로 받는 인자값을 넣게 된다. JNIEnv * env, jobject thiz is a part that must be entered, and the argument value received after the corresponding argument value is included.

아래와 같은 형식은 byte형을 리턴하는 kr.co.soongsil 패키지의 VirusCheck 클래스의 charJNI1이라는 메소드를 호출하는 부분이다.The format below is a part of calling method charJNI1 of VirusCheck class of kr.co.soongsil package that returns byte type.

도 5는 본 발명의 실시예에 따른 JNI를 이용한 안드로이드 난독화 방법의 흐름도이고, 도 6은 본 발명의 실시예에 따른 AndroidManifest.xml에서 패키지 경로 선언문의 예를 나타낸 도면이고, 도 7은 본 발명의 실시예에 따른 호출 함수가 JNI를 거쳐 호출되는 과정을 나타낸 도면이다.5 is a flowchart of an Android obfuscation method using JNI according to an embodiment of the present invention, FIG. 6 is a diagram illustrating an example of a package path declaration statement in AndroidManifest.xml according to an embodiment of the present invention, and FIG. 7 is an embodiment of the present invention. 2 is a diagram illustrating a process of calling a call function through JNI.

도 5를 참조하면, JNI를 이용한 안드로이드 난독화 방법은 자바파일 내부의 모든 변수와 메소드 그리고 클래스를 a,b,c와 같은 형식으로 변경한다(S100).Referring to FIG. 5, in the Android obfuscation method using JNI, all variables, methods, and classes in a Java file are changed to a, b, and c (S100).

이때, AndroidManfest.xml 내에 정의되어있는 클래스까지 같이 변경한다.At this time, change the class defined in AndroidManfest.xml as well.

안드로이드는 AndroidManifest.xml에 정의된 클래스가 존재하기 때문에 기존의 자바 Obfuscation방법으로는 정의된 클래스를 변경하기가 어렵기 때문에, 안드로이드 난독화를 위해서는 AndroidManifest.xml 의 정의된 클래스의 수정과 실제 소스에서의 대치되는 클래스의 명칭도 동시에 수정되어야 한다.Since Android has a class defined in AndroidManifest.xml, it is difficult to change the defined class by the existing Java Obfuscation method. For Android obfuscation, modify the defined class of AndroidManifest.xml and The name of the class being replaced must also be modified at the same time.

또한, AndroidManifest.xml에 안드로이드에서 사용하는 클래스가 정의되어 있다. 따라서 기존의 자바 난독화 기법만으로는 해당 클래스 명칭까지 변경이 불가능하다. Also, the class used in Android is defined in AndroidManifest.xml. Therefore, the existing class name cannot be changed only by the existing Java obfuscation technique.

안드로이드 2.3부터 제공되는 Proguard 난독화 툴은 해당 xml을 변경하지 못하고 있다. 하지만 완벽한 난독화를 위해서는 클래스 명으로 해당 내용을 알기 어렵게 AndroidManifest.xml에 정의되어 있는 함수도 변경하여야 한다.As of Android 2.3, the Proguard obfuscation tool has not been able to change the xml. However, for complete obfuscation, the function defined in AndroidManifest.xml must be changed so that its contents are difficult to understand by class name.

좀더 상세히 설명하면, 도 6에서와 같이, AndroidManifest.xml에서 패키지 경로는 manifest 태그의 package에 선언한다.More specifically, as shown in Figure 6, in AndroidManifest.xml, the package path is declared in the package of the manifest tag.

여기서 클래스로 정의되는 태그들은 아래의 표 2와 같다.The tags defined by class are shown in Table 2 below.

이벤트event 설명Explanation ActivityActivity 화면을 실행하는 ActivityActivity that launches the screen ReceiverReceiver 이벤트를 받는 ReceiverReceiver receiving an event ServiceService 백그라운드에서 돌아가는 ServiceService running in the background

패키지 명칭과 클래스 명을 참조하여 소스파일에서의 클래스의 위치를 알아내어 변경하고, 그 외의 모든 클래스의 명칭도 변경한다. Refer to the package name and the class name to find the location of the class in the source file, change it, and change the names of all other classes.

알파벳은 a~c까지의 5개만 이용한다. 이유는 a부터 z까지만을 보면 문자열의 첫머리 만으로 역공학이 좀더 편리해 지기 때문이다. Only five letters from a to c are used. This is because looking at a to z makes reverse engineering easier with just the beginning of the string.

A,b,c가 넘어가면 a1,b1,b1,a2,b2,b3 의 순으로 진행한다. When A, b, and c are crossed, it proceeds in the order of a1, b1, b1, a2, b2, b3.

클래스를 변경하고 나면 메소드를 변경해야 한다. 메소드도 마찬가지로 a1,b1과 같은 형식으로 변경하며 클래스 내부의 메소드를 선택하고 해당 메소드를 참조하여 변경한다.After changing the class, you need to change the method. Similarly, change the method in the form a1, b1. Select the method inside the class and refer to the method to change it.

다음으로는 자바파일에서 문자열을 so라이브러리로 변경하여 통신하게 한다(S200)고, 바이트코드의 String의 경우 예전부터 고질적인 취약점인 문자열 노출이 존재하기 때문에, 이를 회피하기 위하여 바이너리 코드인 JNI로 변경한다(S300).Next, change the string in the Java file to the so library to communicate (S200), and in the case of the byte code String, since the string exposure, which is a chronic weakness, exists, change to the binary code JNI to avoid this. (S300).

개인키 암호화를 사용할 때 특정 암호화 관련 키를 문자열에 넣을 경우 역공학을 통해 간단히 키를 추출해 낼 수 있다. 또한 특정 URL과 같은 정보가 누출되거나 꺼려지는 문자열의 경우 데이터를 JNI로 변경하면 역공학 시에도 해당 정보를 쉽게 알아내지 못하게 된다. When using private-key cryptography, if a particular encryption-related key is put into a string, reverse engineering simply extracts the key. In the case of strings that leak or reluctant information, such as specific URLs, changing the data to JNI makes it difficult to find the information even during reverse engineering.

따옴표 사이에 있는 문자열을 JNI에서 특정 문자열을 받아서 바로 결과값으로 돌려주는 코드를 작성하는 방법으로 구현한다. 중간에 native method의 명칭은 임의로 생성되므로 더욱 알아보기 어렵게 된다.You can implement this by writing code that takes a string between quotes and returns it as a result in JNI. In the meantime, the native method name is randomly generated, making it more difficult to recognize.

이 방법의 예를 들면 아래와 같다. An example of this method is shown below.

String st = “test_string”;String st = “test_string”;

test_string 이라는 문자열이 String으로 선언되어 있는데 아래와 같이 따옴표 사이가 getString이라는 JNI로 변경된다.The string test_string is declared as a String, and the quotes are changed to getString JNI as shown below.

String st = getString(test_string);String st = getString (test_string);

JNI통신을 위한 C코드 예제는 아래와 같게 된다.An example C code for JNI communication is shown below.

jstringjstring

Java_kr_co_testsungsil_TestJni_getString( JNIEnv* env,Java_kr_co_testsungsil_TestJni_getString (JNIEnv * env,

jobject this, jobject test_obj )                                                  jobject this, jobject test_obj)

{{

return (*env)->NewStringUTF(env, test_obj);    return (* env)-> NewStringUTF (env, test_obj);

}}

도 7에서와 같이, 객체지향 프로그램에서 클래스 메소드를 호출하는 부분을 JAVA 소스코드에서 제거하고 JNI를 호출하는 부분으로 변경하고(S400), JNI가 자바의 함수를 호출하게 됨으로써 사용자가 해당 메소드가 어떤 메소드를 호출했는지 알아볼 수가 없게 된다(S500).As shown in Figure 7, the object-oriented program calls the class method in the JAVA source code and removes the part to call the JNI (S400), JNI calls a function of the Java, so that the user can It cannot be determined whether the method is called (S500).

결정적으로 안드로이드 기본 클래스의 메소드도 전부 JNI를 이용한 콜백으로 변경이 가능하다. 때문에 역 컴파일 된 JAVA소스만을 가지고는 해당 클래스가 어떠한 기능을 하는지 유추하기는 극히 어렵다.In essence, all of the Android base class's methods can be changed with JNI callbacks. Therefore, it is extremely difficult to infer what the class does with only the decompiled JAVA source.

아래의 표 3은 JNI에서 클래스와 메소드를 알아내는 함수이다.Table 3 below shows functions and classes for JNI.

GetObjectClassGetObjectClass jclass class_Employee = (*env)->GetObjectClass(env,obj_this);jclass class_Employee = (* env)-> GetObjectClass (env, obj_this); FindClassFindClass jclass class_String
= (*env)->FindClass(env,”java/lang/String”)
jclass class_String
= (* env)-> FindClass (env, ”java / lang / String”)
GetFieldIDGetFieldID jfieldID id_salary
= (*env)->GetFieldID(env,class_Employee,”salary”,”D”);
jfieldID id_salary
= (* env)-> GetFieldID (env, class_Employee, ”salary”, ”D”);

아래의 표 4에서와 같이, JNI클래스에서 콜백 함수를 통하여 자바 메소드를 호출하는 경우에는 반드시 메소드가 private로 선언되어 있어야 한다. As shown in Table 4 below, when calling a Java method through a callback function in a JNI class, the method must be declared private.

클래스 메소드를 호출하는 JNIJNI to call class methods jint
Java_kr_co_testsungsil_TestJni_callMethod( JNIEnv* env, jobject obj )
{
jclass cls = (*env)->GetObjectClass(env,obj); //현재 클래스를 받아온다.
jmethodID aMethodID = (*env)->GetMethodID(env, cls, "callbackmethod", "(I)V");
int myvar=7;
(*env)->CallVoidMethod(env,obj,aMethodID, myvar);
}
jint
Java_kr_co_testsungsil_TestJni_callMethod (JNIEnv * env, jobject obj)
{
jclass cls = (* env)-> GetObjectClass (env, obj); // Get the current class.
jmethodID aMethodID = (* env)-> GetMethodID (env, cls, "callbackmethod", "(I) V");
int myvar = 7;
(* env)-> CallVoidMethod (env, obj, aMethodID, myvar);
}

또한, JNI로 자바함수를 호출할 때 아래의 표 5와 같이 자바에서 사용되는 함수도 인자값으로 전달할 수 있다.Also, when calling a Java function with JNI, the function used in Java can be passed as an argument value as shown in Table 5 below.

OBJECT인자값 전달Pass OBJECT argument Java_kr_co_testsungsil_TestJni_callMethod2( JNIEnv* env,jobject obj ,jobject test_obj)
{
jclass cls = (*env)->GetObjectClass(env,obj); //오브젝트 클래스를 받아온다.
jmethodID aMethodID = (*env)->GetMethodID(env, cls, "callbackmethod2", "(Ljava/util/ArrayList;)V"); //리턴값 void 인자값 int
(*env)->CallVoidMethod(env,obj,aMethodID, test_obj);
}
Java_kr_co_testsungsil_TestJni_callMethod2 (JNIEnv * env, jobject obj, jobject test_obj)
{
jclass cls = (* env)-> GetObjectClass (env, obj); // get the object class
jmethodID aMethodID = (* env)-> GetMethodID (env, cls, "callbackmethod2", "(Ljava / util / ArrayList;) V"); // return value void argument value int
(* env)-> CallVoidMethod (env, obj, aMethodID, test_obj);
}

그리고, 아래의 표 6과 같이 JNI를 호출하는 자바 외의 타 클래스를 호출할 때는 FindClass 함수를 이용하여 클래스의 정보를 알아낸다. CallObjectMethod를 이용하여 해당 메소드를 호출하고 호출된 메소드에서의 리턴값을 받아서 다시 JNI를 통하여 JAVA에 전달 할 수 있다. And, when calling other classes other than Java calling JNI as shown in Table 6 below, find class information by using FindClass function. CallObjectMethod can be used to call the method, get the return value from the called method, and pass it back to JAVA through JNI.

타 클래스의 정보 전달Passing Information of Other Classes jobject
Java_kr_co_testsungsil_TestJni_callClassMethodReturn( JNIEnv* env, jobject obj ,jobject test_obj)
{
jobject rtnobj;
jclass cls = (*env)->FindClass(env,"kr/co/testsungsil/TestClass"); //오브젝트 클래스를 받아온다.
jmethodID aMethodID = (*env)->GetMethodID(env, cls, "testMethodReturn", "(Ljava/util/ArrayList;)Ljava/util/ArrayList;"); //리턴값 ArrayList 인자값 ArrayList

if(aMethodID == 0){
}else{
rtnobj = (*env)->CallObjectMethod(env,obj,aMethodID, test_obj);
}
return rtnobj;
}
jobject
Java_kr_co_testsungsil_TestJni_callClassMethodReturn (JNIEnv * env, jobject obj, jobject test_obj)
{
jobject rtnobj;
jclass cls = (* env)-> FindClass (env, "kr / co / testsungsil / TestClass"); // get the object class
jmethodID aMethodID = (* env)-> GetMethodID (env, cls, "testMethodReturn", "(Ljava / util / ArrayList;) Ljava / util / ArrayList;"); // return value ArrayList argument value ArrayList

if (aMethodID == 0) {
} else {
rtnobj = (* env)-> CallObjectMethod (env, obj, aMethodID, test_obj);
}
return rtnobj;
}

표 6에서와 같이, 메소드를 변경한다면 메소드 호출 부분도 클래스 호출 부분도 역 컴파일된 상황이라도 알지 못하게 된다.
As shown in Table 6, if you change the method, you won't even know how to call the method or the class invocation.

안드로이드에서 사용하는 기본 함수도 변경이 가능하다. 기본 함수를 JNI를 통하여 변경하게 된다면 역 컴파일을 실제로 하게 된다 하여도 코드를 보고 실제 어떠한 행위를 하는지 알아내기는 거의 불가능 하게 된다.You can also change the default functions used by Android. If you change the default function through JNI, even if you actually decompile, it is almost impossible to look at the code and find out what it is actually doing.

예를 들어, ANDROID코드는 아래의 표7과 같다.For example, the ANDROID codes are shown in Table 7 below.

ANDROID CODEANDROID CODE static {System.loadLibrary("test_security");}

public native void contentView(int m);

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main); //실제 코드
contentView(R.layout.main); //호출하는 JNI코드
}
static {System.loadLibrary ("test_security");}

public native void contentView (int m);

public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
// setContentView (R.layout.main); // actual code
contentView (R.layout.main); // call JNI code
}

표 7에서 setContentView 함수는 안드로이드에서 제공하는 XML LAYOUT을 화면에 적용시키는 함수이다.In Table 7, the setContentView function applies the XML LAYOUT provided by Android to the screen.

하지만, 아래의 표 8에서와 같이, JNI를 통하여 해당 함수를 호출할 수가 있다.However, as shown in Table 8 below, the function can be called through JNI.

안드로이드 기본 함수를 호출하는 JNIJNI to call Android native functions Java_kr_co_testsungsil_TestJni_contentView( JNIEnv* env,jobject obj ,jint test_main)
{
jclass cls = (*env)->FindClass(env,"android/app/Activity");
jmethodID aMethodID = (*env)->GetMethodID(env, cls, "setContentView", "(I)V");
(*env)->CallObjectMethod(env,obj,aMethodID, test_main);
}
Java_kr_co_testsungsil_TestJni_contentView (JNIEnv * env, jobject obj, jint test_main)
{
jclass cls = (* env)-> FindClass (env, "android / app / Activity");
jmethodID aMethodID = (* env)-> GetMethodID (env, cls, "setContentView", "(I) V");
(* env)-> CallObjectMethod (env, obj, aMethodID, test_main);
}

이러한 식으로 안드로이드 프로그램의 클래스와 메소드 전체를 알기 어려운 문자로 변경하고 JNI로 변경하면 역공학이 거의 불가능 하게 된다.In this way, if you change the entire class and method of the Android program to characters that are difficult to understand and change to JNI, reverse engineering is almost impossible.

본 발명은 이상에서 살펴본 바와 같이 바람직한 실시예를 들어 도시하고 설명하였으나, 상기한 실시예에 한정되지 아니하며 본 발명의 정신을 벗어나지 않는 범위 내에서 당해 발명이 속하는 기술분야에서 통상의 지식을 가진 자에 의해 본 발명의 기술사상과 아래에 기재될 특허청구범위의 균등범위 내에서 다양한 수정 및 변형이 가능함은 물론이다.While the present invention has been particularly shown and described with reference to exemplary embodiments thereof, it is clearly understood that the same is by way of illustration and example only and is not to be taken by way of limitation, It will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the appended claims and their equivalents.

Claims (8)

안드로이드 소스의 역 컴파일을 방어하기 위한 난독화 방법에 있어서,
자바파일 내부의 모든 변수, 메소드 및 클래스를 특정 문자 형식으로 변경하는 제 1 단계; 및
상기 자바파일에서 문자열을 so라이브러리로 변경하는 제 2 단계를 포함하되,
상기 제 2 단계는,
바이트코드의 선언된 문자열을 바이너리 코드인 JNI로 변경하는 제 2-1 단계; 및
객체지향 프로그램에서 클래스 메소드를 호출하는 부분을 자바 소스코드에서 제거하고 JNI를 호출하는 부분으로 변경하는 제 2-2 단계를 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
In the obfuscation method to defend against decompilation of Android source,
A first step of changing all variables, methods, and classes in the Java file to a specific character format; And
Including the second step of changing the string into the so library in the Java file,
The second step,
Step 2-1 of changing the declared string of the byte code to JNI, which is a binary code; And
The method of Android obfuscation using JNI, comprising the step 2-2 of removing the part of calling the class method in the object-oriented program from the Java source code and the part of calling the JNI.
제 1항에 있어서,
상기 제 1 단계는,
AndroidManfest.xml 내에 정의되어있는 클래스와 함수를 변경하는 단계를 더 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The first step is,
Android obfuscation method using JNI, characterized in that it further comprises the step of changing the classes and functions defined in AndroidManfest.xml.
제 1항에 있어서,
상기 제 1 단계는,
AndroidManfest.xml에서 패키지 경로를 mainfest 태그의 package에 선언하는 단계를 더 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The first step is,
The Android obfuscation method using JNI further comprising the step of declaring the package path in the package of the mainfest tag in AndroidManfest.xml.
제 1항에 있어서,
상기 제 1 단계는,
패키지 명칭과 클래스 명을 참조하여 소스파일에서 클래스의 위치를 찾아 변경하는 단계를 더 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The first step is,
The Android obfuscation method using JNI further comprising the step of finding and changing the location of the class in the source file with reference to the package name and the class name.
제 1항에 있어서,
상기 제 1 단계는,
상기 특정 문자는 'a','b,'c' 형식으로서, 문자열의 첫 머리만으로 역공학이 편리해지지 않도록 사용되는 문자의 개수를 제한하며, 추가되는 문자는 'a1','b1','c1' 형식으로 숫자를 늘려 표시하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The first step is,
The specific characters are in the form of 'a', 'b,' c ', limiting the number of characters used so that reverse engineering is not convenient with the first head of the string, and the additional characters are' a1 ',' b1 ',' Android obfuscation method using JNI, characterized by increasing the number in c1 'format.
제 1항에 있어서,
상기 제 2 단계는,
함수가 호출되면 JNI를 거쳐 호출되는 제 2-3 단계를 더 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The second step,
Android obfuscation method using JNI, characterized in that it further comprises the second to third steps that are called via JNI when the function is called.
제 6항에 있어서,
상기 제 2-3 단계는,
함수가 호출되면 타 클래스에서 호출하는 오리지널(original) 자바 코드를 확인하는 단계;
상기 호출된 함수에 해당하는 변경된 자바 파일의 문자열을 찾는 단계; 및
JNI로 상기 문자열에 해당하는 함수를 호출하는 단계를 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method according to claim 6,
The second step is,
Checking the original Java code that is called by another class when the function is called;
Finding a string of the changed Java file corresponding to the called function; And
Android obfuscation method using JNI comprising the step of calling a function corresponding to the string with JNI.
제 1항에 있어서,
상기 제 2 단계는,
JNI 클래스에서 콜백 함수를 통하여 자바 메소드를 호출하는 경우, 메소드를 private로 선언하는 단계를 더 포함하는 것을 특징으로 하는 JNI를 이용한 안드로이드 난독화 방법.
The method of claim 1,
The second step,
In the case of calling a Java method through a callback function in a JNI class, the method further includes declaring the method as private.
KR1020110045055A 2011-05-13 2011-05-13 Method for Anti-Encoding Android by Using Java Native Interface KR101234591B1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
KR1020110045055A KR101234591B1 (en) 2011-05-13 2011-05-13 Method for Anti-Encoding Android by Using Java Native Interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
KR1020110045055A KR101234591B1 (en) 2011-05-13 2011-05-13 Method for Anti-Encoding Android by Using Java Native Interface

Publications (2)

Publication Number Publication Date
KR20120126920A true KR20120126920A (en) 2012-11-21
KR101234591B1 KR101234591B1 (en) 2013-02-19

Family

ID=47512169

Family Applications (1)

Application Number Title Priority Date Filing Date
KR1020110045055A KR101234591B1 (en) 2011-05-13 2011-05-13 Method for Anti-Encoding Android by Using Java Native Interface

Country Status (1)

Country Link
KR (1) KR101234591B1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101436741B1 (en) * 2013-05-27 2014-09-01 (주)스마일게이트엔터테인먼트 The method and system for applying security solution program
WO2014142430A1 (en) * 2013-03-15 2014-09-18 주식회사 에스이웍스 Dex file binary obfuscation method in android system
CN104156275A (en) * 2014-06-30 2014-11-19 青岛海信移动通信技术股份有限公司 Method and device for exception handling of Android platform
KR101885260B1 (en) * 2017-10-30 2018-08-03 주식회사 안랩 Obfuscated symbol recognition apparatus and method
CN109901826A (en) * 2019-03-01 2019-06-18 上海极威信息科技有限公司 For the data processing method of java applet, device and electronic equipment
CN115080006A (en) * 2021-03-15 2022-09-20 武汉斗鱼网络科技有限公司 Data calling method and related equipment

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101328012B1 (en) 2013-08-12 2013-11-13 숭실대학교산학협력단 Apparatus for tamper protection of application code and method thereof
KR101350390B1 (en) 2013-08-14 2014-01-16 숭실대학교산학협력단 A apparatus for code obfuscation and method thereof
KR101490047B1 (en) 2013-09-27 2015-02-04 숭실대학교산학협력단 Apparatus for tamper protection of application code based on self modification and method thereof

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100474894B1 (en) * 2002-03-18 2005-03-09 엘지전자 주식회사 Method for cooperating BSM with java application in mobile communication
KR20030085411A (en) * 2002-04-30 2003-11-05 주식회사 현대시스콤 Method for rate improvement of BSM GUI using java native interface

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2014142430A1 (en) * 2013-03-15 2014-09-18 주식회사 에스이웍스 Dex file binary obfuscation method in android system
KR101436741B1 (en) * 2013-05-27 2014-09-01 (주)스마일게이트엔터테인먼트 The method and system for applying security solution program
CN104156275A (en) * 2014-06-30 2014-11-19 青岛海信移动通信技术股份有限公司 Method and device for exception handling of Android platform
CN104156275B (en) * 2014-06-30 2017-10-17 青岛海信移动通信技术股份有限公司 A kind of method and apparatus of Android platform abnormality processing
KR101885260B1 (en) * 2017-10-30 2018-08-03 주식회사 안랩 Obfuscated symbol recognition apparatus and method
CN109901826A (en) * 2019-03-01 2019-06-18 上海极威信息科技有限公司 For the data processing method of java applet, device and electronic equipment
CN109901826B (en) * 2019-03-01 2022-06-10 上海极威信息科技有限公司 Data processing method and device for Java program and electronic equipment
CN115080006A (en) * 2021-03-15 2022-09-20 武汉斗鱼网络科技有限公司 Data calling method and related equipment

Also Published As

Publication number Publication date
KR101234591B1 (en) 2013-02-19

Similar Documents

Publication Publication Date Title
KR101234591B1 (en) Method for Anti-Encoding Android by Using Java Native Interface
CN108153518B (en) JAVA program anti-confusion method and terminal
CN108932406B (en) Virtualization software protection method and device
CN105068932B (en) A kind of detection method of Android application programs shell adding
CN105683990B (en) Method and apparatus for protecting dynamic base
US7937693B2 (en) System and method for obfuscation of reverse compiled computer code
US20160335431A1 (en) Method of Securing Non-Native Code
CN106326694A (en) Android application reinforcing method baed on C source code mixing
CN108733988A (en) The guard method of executable program on Android platform
CN103413073B (en) A kind of method and apparatus protecting JAVA executable program
KR101521765B1 (en) Apparatus For Code Obfuscation Using Indistinguishable Identifier Conversion and Method Thereof
CN103914637B (en) A kind of executable program encryption method of Android platform
CN106203006A (en) Android application reinforcement means based on dex Yu so file Dynamic Execution
EP2897074A1 (en) Application code obfuscation device based on self-conversion and method therefor
CN108363911B (en) Python script obfuscating and watermarking method and device
US20100058301A1 (en) System and method for branch extraction obfuscation
KR101861341B1 (en) Deobfuscation apparatus of application code and method of deobfuscating application code using the same
CN105046116A (en) Method for protecting dex file from being decompiled in Android system
CN102782693A (en) JCVM bytecode execution protection against fault attacks
CN103413075A (en) Method and device for protecting JAVA executable program through virtual machine
CN107632832B (en) Dalvik byte code oriented control flow confusion method
CN112052433B (en) Virtual protection method, terminal and storage medium for Jar file
CN107430650A (en) Computer program is protected to resist reverse-engineering
CN105404794A (en) Protection method and device of Java application software
CN103729579A (en) Function-level software protection method

Legal Events

Date Code Title Description
A201 Request for examination
E902 Notification of reason for refusal
E701 Decision to grant or registration of patent right
N231 Notification of change of applicant
GRNT Written decision to grant
FPAY Annual fee payment

Payment date: 20160204

Year of fee payment: 4

FPAY Annual fee payment

Payment date: 20170120

Year of fee payment: 5

FPAY Annual fee payment

Payment date: 20180206

Year of fee payment: 6

FPAY Annual fee payment

Payment date: 20190129

Year of fee payment: 7