เครื่องมือนี้ยังอยู่ในช่วงเริ่มต้นของการพัฒนา เป็นที่รู้จักกันว่าไม่สมบูรณ์และ Incorrekt
new หรือ deleteclang-format ที่มีไฟล์ .clang-format ก่อนที่จะส่งไปยังที่เก็บ Jitana ใช้ CMAKE ซึ่งรองรับการสร้างนอกแหล่ง ในเอกสารนี้จะสันนิษฐานว่าโครงสร้างไดเรกทอรีต่อไปนี้:
.
├── jitana (source code downloaded)
├── dex (DEX files)
└── build (build directory you make)
ติดตั้งการพึ่งพาทั้งหมดก่อน แล้ว
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../jitana
make -j8
โปรดดูที่การรวบรวม Jitana บน Linux
โปรดดูการรวบรวม Jitana บน Windows
Jitana ถูกนำไปใช้โดยใช้เทคนิคการเขียนโปรแกรมทั่วไปมากกว่าเทคนิคเชิงวัตถุแบบดั้งเดิมเนื่องจากแนวคิดต่อไปนี้:
jitana::virtual_machinejitana::loader_graph loaders()jitana::loader_graph_propertyjitana::loader_edge_property = jitana::any_edge_propertyjitana::loader_vertex_propertyjitana::class_loader loaderjitana::dex_filejitana::class_graph classes()jitana::class_graph_propertystd::unordered_map<jitana::jvm_type_hdl, jitana::class_vertex_descriptor> jvm_hdl_to_vertexstd::unordered_map<jitana::dex_type_hdl, jitana::class_vertex_descriptor> hdl_to_vertexjitana::class_edge_property = jitana::any_edge_propertyjitana::class_vertex_propertyjitana::dex_type_hdl hdljitana::jvm_type_hdl jvm_hdljitana::dex_access_flags access_flagsstd::vector<jitana::dex_field_hdl> static_fieldsstd::vector<jitana::dex_field_hdl> instance_fieldsstd::vector<jitana::dex_method_hdl> dtablestd::vector<jitana::dex_method_hdl> vtableuint16_t static_sizeuint16_t instance_sizejitana::method_graph methods()jitana::method_graph_propertystd::unordered_map<jitana::jvm_method_hdl, jitana::method_vertex_descriptor> jvm_hdl_to_vertexstd::unordered_map<jitana::dex_method_hdl, jitana::method_vertex_descriptor> hdl_to_vertexjitana::method_edge_property = jitana::any_edge_propertyjitana::method_vertex_propertyjitana::dex_method_hdl hdljitana::jvm_method_hdl jvm_hdljitana::dex_type_hdl class_hdljitana::dex_access_flags access_flagsstd::vector<jitana::method_param> paramsjitana::insn_graph insnsjitana::insn_graph_propertystd::unordered_map<uint16_t, jitana::insn_vertex_descriptor> offset_to_vertexjitana::dex_method_hdl hdljitana::jvm_method_hdl jvm_hdlstd::vector<jitana::try_catch_block> try_catchessize_t registers_sizesize_t ins_sizesize_t outs_sizeuint32_t insns_offjitana::insn_edge_property = jitana::any_edge_propertyjitana::insn_vertex_propertyjitana::dex_insn_hdl hdljitana::insn insnlong long counter = 0uint32_t offint line_num = 0ที่จับใช้เพื่อระบุวัตถุเครื่องเสมือน (คลาส, วิธี, คำสั่ง ฯลฯ ) ใน Jitana มีที่จับสองประเภท:
ดูรวม/jitana/hdl.hpp สำหรับรายละเอียดการใช้งาน
+--------------------------------+---------------------------------+
| DEX Handle | JVM Handle |
| (Android specific: int based) | (General Java: string based) |
+----------+--------------------------------+---------------------------------+
| Class | struct class_loader_hdl { |
| Loader | uint8_t idx; |
| | } |
+----------+--------------------------------+---------------------------------+
| DEX | struct dex_file_hdl { | N/A |
| File | class_loader_hdl loader_hdl; | (No concept of DEX file in JVM) |
| | uint8_t idx; | |
| | }; | |
+----------+--------------------------------+---------------------------------+
| Type | struct dex_type_hdl { | struct jvm_type_hdl { |
| | dex_file_hdl file_hdl; | class_loader_hdl loader_hdl; |
| | uint16_t idx; | std::string descriptor; |
| | }; | }; |
+----------+--------------------------------+---------------------------------+
| Method | struct dex_method_hdl { | struct jvm_method_hdl { |
| | dex_file_hdl file_hdl; | jvm_type_hdl type_hdl; |
| | uint16_t idx; | std::string unique_name; |
| | }; | }; |
+----------+--------------------------------+---------------------------------+
| Field | struct dex_field_hdl { | struct jvm_field_hdl { |
| | dex_file_hdl file; | jvm_type_hdl type_hdl; |
| | uint16_t idx; | std::string unique_name; |
| | }; | }; |
+----------+--------------------------------+---------------------------------+
| Instruc- | struct dex_insn_hdl { | N/A |
| tion | dex_method_hdl method_hdl; | |
| | uint16_t idx; | |
| | }; | |
+----------+--------------------------------+---------------------------------+
| Register | struct dex_reg_hdl { | N/A |
| | dex_insn_hdl insn_hdl; | |
| | uint16_t idx; | |
| | }; | |
+----------+--------------------------------+---------------------------------+เรามี ที่จับที่เริ่มต้น อย่างน้อยหนึ่งรายการและ ที่จับที่เป็น เอกลักษณ์สำหรับแต่ละวัตถุ VM:
virtual_machine::find_*()แนวคิดเหล่านี้สะท้อนให้เห็นถึง ตัวตักที่กำหนด และ ตัวตักเริ่มต้น ที่อธิบายไว้ในข้อกำหนด JVM
เพื่อความสะดวกคุณควรสร้างเครื่องมือของคุณเองภายใต้ tools/ เพื่อให้ระบบบิลด์สามารถอ่าน CMakeLists.txt ของคุณโดยอัตโนมัติ คุณสามารถใช้ tools/jitana-graph/ เป็นตัวอย่าง
# include < jitana/jitana.hpp >
int main ()
{
// 1. Create a virtual machine.
jitana::virtual_machine vm;
// 2a. Create and add a system class loader.
{
const auto & filenames = { " dex/system/framework/core.dex " ,
" dex/system/framework/framework.dex " ,
" dex/system/framework/framework2.dex " ,
" dex/system/framework/ext.dex " ,
" dex/system/framework/conscrypt.dex " ,
" dex/system/framework/okhttp.dex " };
jitana::class_loader loader ( 11 , " SystemLoader " , begin (filenames),
end (filenames));
vm. add_loader (loader);
}
// 2b. Create and add an application class loader.
{
const auto & filenames = { " dex/app/instagram_classes.dex " };
jitana::loader loader ( 22 , " Instagram " , begin (filenames),
end (filenames));
vm. add_loader (loader, 11 );
}
// 3a. Load a specific class.
// You need to specify fully qualified Java binary name.
{
bool try_to_load = true ;
vm. find_class ({ 22 , " Ljava/lang/BootClassLoader; " }, try_to_load);
}
// 3b. Or, load everything from a class loader.
vm. load_all_classes ( 22 );
}