Skip to content

Commit d4106fb

Browse files
committed
update README.md
1 parent cc7d344 commit d4106fb

File tree

4 files changed

+123
-5
lines changed

4 files changed

+123
-5
lines changed

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ FetchContent_MakeAvailable(googletest)
1515

1616
# libimobiledevice
1717
if (NOT DEFINED ENV{IMB_PKG_CONFIG_PATH})
18-
message(FATAL_ERROR "not defined env var: IMB_PKG_CONFIG_PATH for imobiledevice") # "../perfcat_build_scripts/built/darwin-arm64/lib/pkgconfig"
18+
message(FATAL_ERROR "not defined env var: IMB_PKG_CONFIG_PATH for imobiledevice") # "../libimobiledevice/built/darwin-arm64/lib/pkgconfig"
1919
endif()
2020
set(ENV{PKG_CONFIG_PATH} $ENV{IMB_PKG_CONFIG_PATH})
2121
find_package(PkgConfig)
@@ -87,13 +87,22 @@ add_definitions(-DENABLE_NSKEYEDARCHIVE_TEST)
8787
include(GoogleTest)
8888
gtest_discover_tests(${PROJECT_NAME}_test)
8989

90+
# fuzzer
91+
#add_executable(
92+
# ${PROJECT_NAME}_fuzzer
93+
# test/dtxmessageparser_fuzzer.cpp
94+
#)
95+
#target_compile_options(${PROJECT_NAME}_fuzzer PUBLIC -g -O1 -fsanitize=fuzzer)
96+
#set_target_properties(${PROJECT_NAME}_fuzzer PROPERTIES LINK_FLAGS -fsanitize=fuzzer)
97+
#target_link_libraries(${PROJECT_NAME}_fuzzer ${PROJECT_NAME})
98+
9099
# tools
91100
add_executable(
92-
${PROJECT_NAME}_decoder
101+
idevice_decoder
93102
tools/decoder.cpp
94103
)
95104
target_link_libraries(
96-
${PROJECT_NAME}_decoder
105+
idevice_decoder
97106
${PROJECT_NAME}
98107
)
99108

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,103 @@
33
A library to communicate with services on iOS devices using native protocols.
44

55
Based on [libimobiledevice](https://github.com/libimobiledevice/libimobiledevice), additionally implemented **instrument_service**.
6+
7+
8+
## Build
9+
10+
1. Compile the [libimobiledevice](https://github.com/libimobiledevice/libimobiledevice) project first, and then set its pkgconfig output directory to the `IMB_PKG_CONFIG_PATH` environment variable.
11+
12+
e.g.:
13+
```
14+
$ export IMB_PKG_CONFIG_PATH="../libimobiledevice/built/darwin-arm64/lib/pkgconfig"
15+
```
16+
17+
2. Compile with CMake.
18+
19+
```
20+
$ mkdir build && cd build
21+
$ cmake ..
22+
// or cmake -G "Xcode" ..
23+
```
24+
25+
## Usage
26+
27+
### library: libidevice
28+
29+
```c++
30+
idevice_t device = ...;
31+
32+
DTXTransport* transport = new DTXTransport(device);
33+
DTXConnection* connection = new DTXConnection(transport);
34+
connection->Connect();
35+
36+
std::shared_ptr<DTXChannel> channel = connection->MakeChannelWithIdentifier(
37+
"com.apple.instruments.server.services.deviceinfo");
38+
std::shared_ptr<DTXMessage> message = DTXMessage::Create("runningProcesses");
39+
channel->SendMessageAsync(message, [&](auto msg) {
40+
printf("reply handler\n");
41+
msg->Dump();
42+
});
43+
```
44+
45+
46+
47+
### tool: idevice_decoder
48+
49+
This tool is used to decode the binary records of communication messages with Xcode.
50+
51+
```
52+
$ idevice_decoder --hex received_outfile.bin transmit_outfile.bin
53+
```
54+
55+
output:
56+
```
57+
==== DTXMessage ====
58+
message_type: 2
59+
identifier: 5100
60+
conversation_index: 0
61+
channel_code: 0
62+
expects_reply: 1
63+
auxiliary:
64+
DTXPrimitiveArray, size=2:
65+
item #0: [type=kSignedInt32, size=4, value=18]
66+
item #1: [type=kBuffer, size=184, value="com.apple.instruments.server.services.assets"]
67+
00000000h: 62 70 6C 69 73 74 30 30 D4 01 02 03 04 05 06 07 bplist00........
68+
00000010h: 0A 58 24 76 65 72 73 69 6F 6E 59 24 61 72 63 68 .X$versionY$arch
69+
00000020h: 69 76 65 72 54 24 74 6F 70 58 24 6F 62 6A 65 63 iverT$topX$objec
70+
00000030h: 74 73 12 00 01 86 A0 5F 10 0F 4E 53 4B 65 79 65 ts....._..NSKeye
71+
00000040h: 64 41 72 63 68 69 76 65 72 D1 08 09 54 72 6F 6F dArchiver...Troo
72+
00000050h: 74 80 01 A2 0B 0C 55 24 6E 75 6C 6C 5F 10 2C 63 t.....U$null_.,c
73+
00000060h: 6F 6D 2E 61 70 70 6C 65 2E 69 6E 73 74 72 75 6D om.apple.instrum
74+
00000070h: 65 6E 74 73 2E 73 65 72 76 65 72 2E 73 65 72 76 ents.server.serv
75+
00000080h: 69 63 65 73 2E 61 73 73 65 74 73 08 11 1A 24 29 ices.assets...$)
76+
00000090h: 32 37 49 4C 51 53 56 5C 00 00 00 00 00 00 01 01 27ILQSV\........
77+
000000a0h: 00 00 00 00 00 00 00 0D 00 00 00 00 00 00 00 00 ................
78+
000000b0h: 00 00 00 00 00 00 00 8B ........
79+
payload(size=175):
80+
00000000h: 62 70 6C 69 73 74 30 30 D4 01 02 03 04 05 06 07 bplist00........
81+
00000010h: 0A 58 24 76 65 72 73 69 6F 6E 59 24 61 72 63 68 .X$versionY$arch
82+
00000020h: 69 76 65 72 54 24 74 6F 70 58 24 6F 62 6A 65 63 iverT$topX$objec
83+
00000030h: 74 73 12 00 01 86 A0 5F 10 0F 4E 53 4B 65 79 65 ts....._..NSKeye
84+
00000040h: 64 41 72 63 68 69 76 65 72 D1 08 09 54 72 6F 6F dArchiver...Troo
85+
00000050h: 74 80 01 A2 0B 0C 55 24 6E 75 6C 6C 5F 10 23 5F t.....U$null_.#_
86+
00000060h: 72 65 71 75 65 73 74 43 68 61 6E 6E 65 6C 57 69 requestChannelWi
87+
00000070h: 74 68 43 6F 64 65 3A 69 64 65 6E 74 69 66 69 65 thCode:identifie
88+
00000080h: 72 3A 08 11 1A 24 29 32 37 49 4C 51 53 56 5C 00 r:...$)27ILQSV\.
89+
00000090h: 00 00 00 00 00 01 01 00 00 00 00 00 00 00 0D 00 ................
90+
000000a0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 ...............
91+
"_requestChannelWithCode:identifier:"
92+
==== /DTXMessage ====
93+
94+
==== DTXMessage ====
95+
message_type: 0
96+
identifier: 5100
97+
conversation_index: 1
98+
channel_code: 0
99+
expects_reply: 0
100+
auxiliary:
101+
none
102+
payload(size=0):
103+
==== /DTXMessage ====
104+
```
105+

include/idevice/dtxprimitivearray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ class DTXPrimitiveValue {
152152
break;
153153
}
154154
case kBuffer: {
155+
nskeyedarchiver::KAValue value = nskeyedarchiver::NSKeyedUnarchiver::UnarchiveTopLevelObjectWithData(d_.b, Size());
156+
printf("[type=kBuffer, size=%zu, value=%s]\n", Size(), value.ToJson().c_str());
155157
if (dumphex) {
156158
hexdump(d_.b, Size(), 0);
157159
}
158-
nskeyedarchiver::KAValue value = nskeyedarchiver::NSKeyedUnarchiver::UnarchiveTopLevelObjectWithData(d_.b, Size());
159-
printf("[type=kBuffer, size=%zu, value=%s]\n", Size(), value.ToJson().c_str());
160160
break;
161161
}
162162
case kSignedInt32:

test/dtxmessageparser_fuzzer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "idevice/dtxmessageparser.h"
2+
3+
using namespace idevice;
4+
5+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
6+
DTXMessageParser parser;
7+
bool ret = parser.ParseIncomingBytes(reinterpret_cast<const char*>(data), size);
8+
return 0;
9+
}

0 commit comments

Comments
 (0)