|
| 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 | + |
0 commit comments