Title: Java Virtual Machine (Obfuscation and Java)
1Java Virtual Machine(Obfuscation and Java)
2What it is all about?
- ????????? Java
- Classfile
- ??????????? ???
- ????????? ? ????????? ??????
- ????????? ??????? ?????? ????-????
- ?????????? ? Java
- QA
3Java Technology(????????)
- Java ?????????? ?????? SUN Microsystems
- 1991 ?. James Gosling ???? Oak
- 1995 ?. ????????? ???????? ?? JAVA ? ??????
?????? ?????????? - JDK 1.0 - 1998 ?. ????????? Java 2 ( SE, EE, ME)
- Java ???
- ?????????
- ?????????
- ???????????
- ????????-??????????????
4What is this all for?
SMART HOUSE
EMBEDDED MEDICAL SYSTEM
WEB SERVER
VM
DESKTOP
CELLPHONE
H.JAR
PALM
SMARTPHONE
iPAQ
5???? ???? ? JAVA
Compiler (javac)
a.java
a.class
Obfuscator
JAR (jar) ZIP
b. class
b.java
External Verifier
b.java
b. class
H.JAR
Compiler (other)
e.other
e.class
Manifest.mf
f.png
g.txt
6OOP (JIC)
Moveable
2DPoint Pos
SetPosition()
ValidatePos()
Figure
Draw()
SetColor()
ValidatePos()
ValidatePos()
7CLASS FILE
8Classfile structure(?????????)
- ??????????? ?????????? Java ???????????????? ?
???? ?????? classfile-?? (??? ?? ??????? JAR) - ???????????? ????????? JAVA
- ????????????
- ?????? ??????????????????????
- ??????? ??????????
- ???????????? ???????? ??????????? ???????????
9Classfile structure(????????)
- ?????? classfile ???????????? ?????? ??????
?????? ??? ?????????? - ?? ?? ?????? ????????? ??????? ?????? ?
????????????? ????????????? ?????? ?????? ???
?????????? - Classfile ??? ????????? ???????????????????
????? ???? (big-endian) - ?? ???????????? ??????? classfile ??? ??????
??????
Classfile
JAVA
10Classfile structure(??? ????????)
- ??? ????????
- ??? ?????? (??????, ???????????? ???)
- ?????? ?? ?????-?????? (??????????)
- ????? ?????????????? ???????????
- ???????? ?????
- ???????? ?????
- ???????? ???????
- ???????? ???????
- ???????? ?????????
11Classfile structure(??????????? ???)
- ????? ??????? ??????????? ????????? ?????? ???
?????????? ? ???????? ???????? ?? ???? - ???????? ????? ????????? ?????????? ?????????
- ??????
- ????????? (int, float, long, double, ?????? UTF8)
- ?????? ?? ????????????? ???????? ??????? ????????
(???????, ???????, ???????) - ???????????? ?????? ????????? 216
- ??????????? ??? ????????? ? ???????? ??????????
12??????
CONSTANT_Methodref_info
CONSTANT_Class_info
COCONSTANT_NameAndType_info
CONSTANT_Utf8_info
13Attributes
- SourceFile - ???????? ?????????
- ConstantValue ???????? ?????????
- Code ???????? ????
- Exceptions ?????? ?????????? ???????? ???????
- InnerClasses ?????? ????????? ??????? ?? ??????
??????? - Synthetic ??????? ? ??? ??? ???? ??????
???????????? ? ????????? - LineNumberTable ?????? ?????? ?? ?????? ?????
- LocalVariableTable ?????? ???? ?????????
?????????? - Deprecated ??????? ? ??? ??? ???? ??? ?????
???????? (??????????)
14Methods and attributes
attribute_info u2 attribute_name_index
u4 attribute_length u1
infoattribute_length
Code_attribute u2 attribute_name_index
u4 attribute_length u2 max_stack
u2 max_locals u4 code_length
u1 codecode_length u2
exception_table_length u2 start_pc
u2 end_pc u2 handler_pc u2
catch_type exception_tableexception_tabl
e_length u2 attributes_count
attribute_info attributesattributes_count
method_info u2 access_flags u2
name_index u2 descriptor_index u2
attributes_count attribute_info
attributesattributes_count
15JVM
16???????????? JVM
- ? ???? ??????? ????????? ????
- ?? ????????? ????
17JVM Subsystems
?????????
???????? ?????
???? ????? ?????
????? ??????????? ????????????
18JVM (????????? JAVA ??????)
- ???????????????
- ????????? ??????????
- ?????? ??????????? ?????? ??????????? ?? ???????
?? ??????? - ?????????????? ?????? ??????
- ??????? ??????????????? ??????????????
19JVM (????????? JAVA ??????)
- JVM ?????????? ???????? ?????? ? ??????????
??????????? - ?????? ????? ? JVM ????? ???? ???? ?????
??????????? ???????? - JVM ????????? ?
- ?????? ????????? (??????? ????????)
- ?????????? ??????????? ???????????
- ???????????? ???????????
20JVM
Runtime constpool
Thread 1
Thread 2
JVM Op Stack
Local Variables
Parameters
Frame3
21JVM
FRAME STACK (call stack)
Thread 1
Thread 2
ALU
MEMORY
FRAME2
JVM Op Stack
HEAP
FRAME2
FRAME1
FRAME1
FRAME1
22BYTE code(?????????)
- ???????? ????? ????? ? 8 ??? ? ???????????
??????? - ???????? ????? ????????? ????????? ????????????
- ???? ????????? ????????
- ???? ??????? ? ??????? ???????? (IS ???????????)
- ?? ????? ???????????
- ?????? ???????? ? ??????? ???????? 8, 32, 64 ????
23BYTE code(???? ??????)
- byte - 8-bit ???????? ?????
- short - 16-bit ???????? ?????
- int - 32-bit ???????? ?????
- long - 64-bit ???????? ?????
- char - 16-bit ??? ???????? ??? ?????????????
UNICODE - float
- double
24BYTE code(????)
- ?????? ? ???????????
- Push ????-????
- ?????????? ? ???????? ????????? ??????????
- Pop ????-???? ? ?????? ?? ??????
- ?????????????? ????????
- ???????? ????????? ? ???????? ?????????, ????????
???????, ???????? ???????? ?? ??????? - ???????? ???????????? ????????
- ???????? ???????? ??????????? ? ????????????
????? - ???????? ????? ????????, ????????, ????????
?????????? ????? - ?????? ??????????
- ?????? ? ???????????? ?????????
- ??????? ???????? ?? ????
- ??????? ???????? ? ??????? ????????
25Size reduction
iconst_m1
push (byte)-1
n if (x lt 9 x gt 3) then x 3 else
OTHER_OPCODE push (byte)n
iconst_n
bipush
push x
sipush
push x
ldc
push CONST_POOLx
ldc_w
push CONST_POOLx
26Vierifier
- invoke virtual
- ????? ?????? ???? ????? ?????? ??? ?????? ??????.
- ? ??? ?????????
- verifier
- ? runtime
27JIT
- Pros vs Cons
- Time 2x-40x faster
- Memory Overhead 5x-10x
- Compilation
- JIT Just-In-Time
- AOT Ahead-Of-Time
- HI Hotspot Implementations
28Garbage collection(????? ?????)
- ????? ? ??????? ??????????? ?????????????
- ? ????????? ??????? ??? ??? ???????????
- ??? ????? ???? ??????????? ??????... ??????
??????? ??? ???? - ??????????? ???? ?????? ? ?????? ?????? ? ???...
- ???? ???????????? ?????????? ??? ?????????????,
???? ??? ????????????? ???????????? ? ??????
??????
29Obfuscation
30Obfuscation and Java
- Pros
- ??? ?? ????? ???? ??????????
- Java ?????? ????? ?????????????
- ?????????? ???????? ?????
- Cons
- Reflection ????? ???????? ???????
- ????????? Java ?????? ??????????
31Decompilers
- Goto
- ?????? ????? for ? synchronized ? ????-????
?? ?? ?????? ????? ??????? ? Java - ??? ???????? ????????, ???? ?? ?? ???????. ??????
????? ? ????? ?? ????????????, ???? ??? ??????????
32Decompilers
? ?????? ??? ???? ?????????????.
b a a b
int tmp tmp a a b b tmp
iload_0 iload_1 istore_0 istore_1
iload_0 istore_2 iload_1 istore_0 iload_2 istore_1
???????????
33Obfuscation - Names and profiles (Retroguard)
34Names and profiles (JODE)
- GNU GPL
- ?????????????? ???????, ??????? ? ?????
- ???????? ?????????? ??????????
- ???????? ???????? ???? (???????, ???????,
?????) - ??????????? ????????? ????????? ??????????
- ???? ????????????
35Names and profiles (SandMark)
- ?????? ??????????? ???????????? ?????????
watermarking, tamper-proofing ? code obfuscation - ??????? ?? ?????????? by Venkatesan, Collberg,
Stern, and others
36Names and profiles (DashO)
- Commercial
- Suns choice
- Features
- Package/Class/Method/Field renaming using our
patented Overload-Induction(tm) renaming system - Unused Class/Method/Field and constant pool entry
removal - Advanced Control Flow Obfuscation
- String Encryption
- Class and method level optimization to improve
JIT performance
37Names and profiles
???????? ???? (name mangling) ????????? ?????? ????????? (code mangling) ??????????? ????? (strings enscription)
Retroguard ?
SandMark ? ?
DashO
JODE ?
38Where is more information available?
- ????????????? ?????????? ? Java ?????? ??????????
? ???????????? SUN ? ?????? ???? ??? - http//sunsite.nstu.ru/java-stuff/vmspec/
- ?????????? ? ?????????? ? classfile
- ftp//ftp.cs.arizona.edu/reports/2004/TR04-11.pdf
- ????????? ???????????
- http//www.retrologic.com/retroguard-docs.html
- http//sandmark.cs.arizona.edu/publications.html
- http//www.preemptive.com/products/dasho/Features.
html
39THE END
40Q A