Skip to content

Commit 9a6d66a

Browse files
committed
首次上传
1 parent 54a21ff commit 9a6d66a

File tree

3 files changed

+240
-0
lines changed

3 files changed

+240
-0
lines changed

3gppDecoder.cfg

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"wireshark-dir": "D:/Program Files/Wireshark",
3+
"notepadpp-dir": "D:/Program Files/Notepad++",
4+
"NAT": [
5+
{
6+
"NR": [
7+
"nr-rrc.dl.ccch",
8+
"nr-rrc.dl.dcch",
9+
"nr-rrc.ul.ccch",
10+
"nr-rrc.ul.dcch",
11+
"xnap"
12+
]
13+
},
14+
{
15+
"LTE": [
16+
"lte-rrc.dl.ccch",
17+
"lte-rrc.dl.dcch",
18+
"lte-rrc.ul.ccch",
19+
"lte-rrc.ul.dcch",
20+
"s1ap",
21+
"x2ap"
22+
]
23+
},
24+
{
25+
"LTE-NB": [
26+
"nr-rrc.dl.ccch.nb",
27+
"nr-rrc.dl.dcch.nb",
28+
"nr-rrc.ul.ccch.nb",
29+
"nr-rrc.ul.dcch.nb",
30+
"s1ap",
31+
"x2ap"
32+
]
33+
}
34+
]
35+
}

3gppDecoder.red

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
Red [
2+
Title: "3GPP DECODER"
3+
Author: "KONGLONG"
4+
Date: 2019-10-01
5+
Version: 1.0.0
6+
purpose: "解码wireshark能支持的所有协议"
7+
Needs: 'View
8+
]
9+
10+
default_config: make map! [
11+
wireshark-dir: "C:/Program Files/Wireshark"
12+
notepadpp-dir: "C:/Program Files/Notepad++"
13+
NAT: [
14+
#(LTE: [
15+
"lte-rrc.dl.ccch" "lte-rrc.dl.dcch" "lte-rrc.ul.ccch" "lte-rrc.ul.dcch" "s1ap" "x2ap"
16+
])
17+
#(NR: [
18+
"nr-rrc.dl.ccch" "nr-rrc.dl.dcch" "nr-rrc.ul.ccch" "nr-rrc.ul.dcch" "xnap"
19+
])
20+
]
21+
]
22+
23+
if error? try [
24+
config: load-json read %3gppDecoder.cfg
25+
][
26+
config: default_config
27+
]
28+
print config
29+
; print ? config/NAT/1/LTE
30+
if error? try [
31+
ws_path: config/wireshark-dir
32+
text2pcap: rejoin[config/wireshark-dir "/text2pcap.exe"]
33+
tshark: rejoin[config/wireshark-dir "/tshark.exe"]
34+
notepad: rejoin[config/notepadpp-dir "/notepad++.exe"]
35+
][
36+
quit
37+
]
38+
; print ws_path
39+
; print text2pcap
40+
; print tshark
41+
; print length? tshark
42+
43+
nats: make block! []
44+
foreach p config/NAT [
45+
foreach [k v] p [
46+
append nats to-string k
47+
]
48+
]
49+
50+
default_nat: nats/2
51+
52+
if empty? nats [
53+
quit
54+
]
55+
56+
selected-proto: ""
57+
58+
proc-hex-str: function [
59+
src-str [string!]
60+
] [
61+
whitespace: charset reduce [space tab cr lf]
62+
hex-digits: charset ["0123456789" #"a" - #"f" #"A" - #"F"]
63+
64+
replace/all src-str "," " "
65+
replace/all src-str "0x" " "
66+
replace/all src-str "0X" " "
67+
68+
dst-str: ""
69+
hex-ind: 0
70+
str-len: 0
71+
clear dst-str
72+
73+
parse src-str [some[
74+
some[whitespace] (hex-ind: 0)
75+
| [pos: hex-digits] (either hex-ind == 0 [
76+
append dst-str " 0"
77+
append dst-str pos/1
78+
str-len: str-len + 3
79+
hex-ind: 1
80+
] [
81+
dst-str/(:str-len - 1): dst-str/:str-len
82+
dst-str/:str-len: pos/1
83+
hex-ind: 0
84+
])
85+
]]
86+
87+
trim/head dst-str
88+
trim/tail dst-str
89+
dst-str
90+
]
91+
92+
pre-proc-data: function [
93+
data [string!]
94+
] [
95+
data: proc-hex-str data
96+
prep-area/text: data
97+
rejoin["0000 " data " 0000"]
98+
]
99+
100+
decode-handler: function [
101+
proto [string!]
102+
data [string!]
103+
] [
104+
data-temp: copy data
105+
data-temp: pre-proc-data data-temp
106+
write %textdata.txt data-temp
107+
text2pcap_cmd: rejoin[text2pcap " -l 147 textdata.txt decode_temp.pcap"]
108+
; print text2pcap_cmd
109+
call/wait text2pcap_cmd
110+
111+
;^(22)是"的转义,^(5c)是\的转义
112+
tshark_cmd: rejoin[tshark " -V -o ^(22)uat:user_dlts:^(5c)^(22)User 0 (DLT=147)^(5c)^(22),^(5c)^(22)"
113+
proto
114+
"^(5c)^(22),^(5c)^(22)0^(5c)^(22),^(5c)^(22)^(5c)^(22),^(5c)^(22)0^(5c)^(22),^(5c)^(22)^(5c)^(22)^(22) -r decode_temp.pcap"]
115+
; print tshark_cmd
116+
write %decode_result.txt ""
117+
call/wait/output tshark_cmd %decode_result.txt
118+
119+
call/wait "del textdata.txt"
120+
call/wait "del decode_temp.pcap"
121+
122+
output-area/text: read %decode_result.txt
123+
]
124+
125+
update-nat-proto: function [
126+
nat-str [string!]
127+
] [
128+
foreach p config/NAT [
129+
foreach [k v] p [
130+
if nat-str = to-string k [
131+
proto-drop-down/text: v/1
132+
proto-drop-down/data: v
133+
]
134+
]
135+
]
136+
]
137+
138+
about-txt: {
139+
版本: v1.0.0
140+
通过修改配置文件,理论上可以解码wireshark支持的所有协议。
141+
By: KONGLONG
142+
}
143+
144+
main-window: layout [
145+
title "3GPP解码器"
146+
text "网络:" 40x25
147+
nat-drop-down: drop-down 100x25 data nats
148+
on-select [
149+
update-nat-proto face/text
150+
selected-proto: proto-drop-down/text
151+
]
152+
text "协议:" 40x25
153+
proto-drop-down: drop-down 125x25 data []
154+
on-select [
155+
selected-proto: face/text
156+
]
157+
button "解码" [
158+
if selected-proto <> "" [
159+
decode-handler selected-proto input-area/text
160+
]
161+
]
162+
button "用NPP打开" [
163+
call rejoin[notepad " decode_result.txt"]
164+
]
165+
return
166+
text "输入码流:"
167+
return
168+
input-area: area focus "" 800x60
169+
return
170+
text "码流预处理:"
171+
return
172+
prep-area: area "" 800x60
173+
return
174+
text "解码结果:"
175+
return
176+
output-area: area "" 800x400
177+
178+
do [
179+
nat-drop-down/text: nats/1
180+
update-nat-proto nat-drop-down/text
181+
selected-proto: proto-drop-down/text
182+
]
183+
]
184+
185+
main-window/menu: [
186+
"文件" [ "退出" qt ]
187+
"帮助" [ "关于" ab ]
188+
]
189+
main-window/actors: make object! [
190+
on-menu: func [face [object!] event [event!]][
191+
switch event/picked [
192+
qt [quit]
193+
ab [
194+
view/flags [
195+
title "关于"
196+
text 180x100 about-txt
197+
return
198+
OK-btn: button "OK" [unview]
199+
] [modal popup]
200+
]
201+
] ] ]
202+
203+
view main-window
204+

textdata1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000 20 0b 3c f4 fd 76 10 30 04 2b fe 63 47 fb 80 02 10 04 04 13 00 08 04 01 90 e2 fd 55 ae a5 df 83 5b 01 3f ba 00 30 76 38 13 fb a0 03 17 60 1a 22 80 ec 3a 88 66 26 26 62 1d e5 a8 ac c8 60 e6 54 34 00 08 c2 44 00 0000

0 commit comments

Comments
 (0)