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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- livebook:{"app_settings":{"access_type":"public","output_type":"rich","slug":"ngap-tree"}} -->
|
| 2 |
+
|
| 3 |
+
# NGAP Parser
|
| 4 |
+
|
| 5 |
+
```elixir
|
| 6 |
+
token = System.get_env("LB_MIX_GITHUB_ACCESS_TOKEN")
|
| 7 |
+
|
| 8 |
+
Mix.install(
|
| 9 |
+
[
|
| 10 |
+
{:kino, github: "devmuroid/kino"},
|
| 11 |
+
{:jason, "~> 1.4"},
|
| 12 |
+
# {:ngapv1710, github: "devmuroid/ngapv1710"},
|
| 13 |
+
{:ngapv1710, git: "https://#{token}@github.com/devmuroid/ngapv1710"},
|
| 14 |
+
{:lemon_ex, "~> 0.2.4"}
|
| 15 |
+
],
|
| 16 |
+
config: [
|
| 17 |
+
lemon_ex: [
|
| 18 |
+
api_key: System.get_env("LB_LEMONSQUEEZY_API_KEY"),
|
| 19 |
+
# webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET"),
|
| 20 |
+
# (Optional) You can provide HTTPoison options which are added to every request.
|
| 21 |
+
# See all options here: https://hexdocs.pm/httpoison/HTTPoison.Request.html#content
|
| 22 |
+
request_options: [timeout: 10_000]
|
| 23 |
+
]
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Parse 3GPP ASN.1 Protocols
|
| 29 |
+
|
| 30 |
+
```elixir
|
| 31 |
+
defmodule Parser do
|
| 32 |
+
|
| 33 |
+
def parse_packet(:ngap,packet) do
|
| 34 |
+
parsed = packet |> Base.decode16!(case: :lower) |> :ngap."dec_NGAP-PDU"()
|
| 35 |
+
{{message_type, message_map}, _new_bytes} = parsed
|
| 36 |
+
%{:procedureCode => pc, :value => %{:protocolIEs => protocolIEs}} = message_map
|
| 37 |
+
procedure_code = :ngap_general.pc(pc)
|
| 38 |
+
infoelements = :ngap_general.change_protocol_ies(protocolIEs)
|
| 39 |
+
|
| 40 |
+
message_map =
|
| 41 |
+
message_map
|
| 42 |
+
|> Map.replace!(:value, %{:protocolIEs => infoelements})
|
| 43 |
+
|> Map.replace!(:procedureCode, procedure_code)
|
| 44 |
+
|
| 45 |
+
{message_type, message_map}
|
| 46 |
+
# |> Kino.Tree.new()
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
def parse_packet(_,_) do
|
| 50 |
+
"unsupported_protocol"
|
| 51 |
+
end
|
| 52 |
+
|
| 53 |
+
def parser_frame(frame_controls, frame_result) do
|
| 54 |
+
# label =
|
| 55 |
+
# Kino.Markdown.new("""
|
| 56 |
+
# ### Enter the protocol and hex packet
|
| 57 |
+
# """)
|
| 58 |
+
|
| 59 |
+
form =
|
| 60 |
+
Kino.Control.form(
|
| 61 |
+
[
|
| 62 |
+
p: Kino.Input.textarea("Packet", default: "000e008081000007000a000560fc8b21dc00550005c035c143d4001c00070002f83900004000000002000100770009000004000000010000005e0020ee791b7dd5bbf424ab0af061c5920726c124dd3d17659fb8ed284fee4a6fd7de00264026257e026d8c8a0e017e0042010177000bf202f839000040fc8b21dc54062202f83900015e0148"),
|
| 63 |
+
pr: Kino.Input.select("Protocol", [{:ngap, "NGAP"}, {:rrc, "RRC"}])
|
| 64 |
+
],
|
| 65 |
+
submit: "Parse",
|
| 66 |
+
reset_on_submit: [:p]
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Kino.Frame.render(frame_controls, label)
|
| 70 |
+
Kino.Frame.clear(frame_controls)
|
| 71 |
+
Kino.Frame.append(frame_controls, form)
|
| 72 |
+
|
| 73 |
+
Kino.listen(form, fn %{data: %{p: packet, pr: protocol}, origin: _origin} ->
|
| 74 |
+
# IO.inspect(event)
|
| 75 |
+
frame_result |> Kino.Frame.clear()
|
| 76 |
+
tree = parse_packet(protocol,packet) |> Kino.Tree.new()
|
| 77 |
+
frame_result |> Kino.Frame.render(tree)
|
| 78 |
+
end)
|
| 79 |
+
|
| 80 |
+
end
|
| 81 |
+
end
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
```elixir
|
| 85 |
+
# Kino.Markdown.new("""
|
| 86 |
+
|
| 87 |
+
# <!-- Features Section -->
|
| 88 |
+
# <div class="bg-gray-100 py-4 px-4">
|
| 89 |
+
# <div class="container mx-auto text-center">
|
| 90 |
+
# <h2 class="text-3xl font-bold mb-8">Why Use Packet Parser?</h2>
|
| 91 |
+
# <div class="grid grid-cols-1 md:grid-cols-3 gap-8 max-w-5xl mx-auto">
|
| 92 |
+
|
| 93 |
+
# <!-- Feature 1 -->
|
| 94 |
+
# <div class="bg-white p-6 rounded-lg shadow-md">
|
| 95 |
+
# <div class="text-indigo-600">
|
| 96 |
+
# <!-- Icon -->
|
| 97 |
+
# <svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 mx-auto mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 98 |
+
# <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 99 |
+
# </svg>
|
| 100 |
+
# </div>
|
| 101 |
+
# <h3 class="text-xl font-semibold mb-2">Instant Packet Parsing</h3>
|
| 102 |
+
# <p class="text-gray-600">
|
| 103 |
+
# Quickly convert hexadecimal packet contents into readable packet information without complex setup or tools.
|
| 104 |
+
# </p>
|
| 105 |
+
# </div>
|
| 106 |
+
|
| 107 |
+
# <!-- Feature 2 -->
|
| 108 |
+
# <div class="bg-white p-6 rounded-lg shadow-md">
|
| 109 |
+
# <div class="text-indigo-600">
|
| 110 |
+
# <!-- Icon -->
|
| 111 |
+
# <svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 mx-auto mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 112 |
+
# <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m-6-3l3-3V4m-6 3a9 9 0 100 18A9 9 0 003 7z" />
|
| 113 |
+
# </svg>
|
| 114 |
+
# </div>
|
| 115 |
+
# <h3 class="text-xl font-semibold mb-2">Multiple Protocols</h3>
|
| 116 |
+
# <p class="text-gray-600">
|
| 117 |
+
# Parse packets across multiple protocols like <b>NGAP</b>, <b>RRC</b>, <b>S1AP</b> using <b>ASN.1</b> encoding format for 5G protocols as defined by the <b>3GPP</b> standards.
|
| 118 |
+
# </p>
|
| 119 |
+
# </div>
|
| 120 |
+
|
| 121 |
+
# <!-- Feature 3 -->
|
| 122 |
+
# <div class="bg-white p-6 rounded-lg shadow-md">
|
| 123 |
+
# <div class="text-indigo-600">
|
| 124 |
+
# <!-- Icon -->
|
| 125 |
+
# <svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 mx-auto mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 126 |
+
# <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3l4 4-4 4V7H7v2a9 9 0 11-9 0 9 9 0 019 0v-2h6z" />
|
| 127 |
+
# </svg>
|
| 128 |
+
# </div>
|
| 129 |
+
# <h3 class="text-xl font-semibold mb-2">Tailored for 5G</h3>
|
| 130 |
+
# <p class="text-gray-600">
|
| 131 |
+
# Seamlessly decode ASN.1-based packets in 5G networks, giving you a powerful tool for analyzing modern protocols.
|
| 132 |
+
# </p>
|
| 133 |
+
# </div>
|
| 134 |
+
|
| 135 |
+
# </div>
|
| 136 |
+
# </div>
|
| 137 |
+
# </div>
|
| 138 |
+
|
| 139 |
+
# """)
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
## Parser
|
| 143 |
+
|
| 144 |
+
```elixir
|
| 145 |
+
# Kino.Markdown.new("""
|
| 146 |
+
# ### Enter your e-mail address
|
| 147 |
+
# """)
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
```elixir
|
| 151 |
+
form_mail =
|
| 152 |
+
Kino.Control.form(
|
| 153 |
+
[
|
| 154 |
+
mail: Kino.Input.text("E-Mail Address",default: "devmuroid@gmail.com"),
|
| 155 |
+
licence_key: Kino.Input.password("Licence Key")
|
| 156 |
+
],
|
| 157 |
+
submit: "Sign-in"
|
| 158 |
+
)
|
| 159 |
+
# Kino.nothing()
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
```elixir
|
| 163 |
+
frame_controls = Kino.Frame.new(placeholder: false)
|
| 164 |
+
# Kino.nothing()
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
```elixir
|
| 168 |
+
frame_result = Kino.Frame.new(placeholder: false)
|
| 169 |
+
# Kino.nothing()
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
```elixir
|
| 173 |
+
# Kino.Layout.grid([form_mail, frame_controls], columns: {1,2}, boxed: true, gap: 8)
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
```elixir
|
| 177 |
+
# frame_result
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
```elixir
|
| 181 |
+
# LemonEx.Subscriptions.list(filter: [user_email: "mail@mail.com"])
|
| 182 |
+
# hd([])
|
| 183 |
+
# Kino.nothing()
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
```elixir
|
| 187 |
+
Kino.listen(form_mail, fn %{data: %{mail: mail, licence_key: _licence_key}, origin: _origin} ->
|
| 188 |
+
# IO.inspect(event)
|
| 189 |
+
frame_controls |> Kino.Frame.clear()
|
| 190 |
+
frame_result |> Kino.Frame.clear()
|
| 191 |
+
{:ok, %LemonEx.PaginatedResponse{:data => subscriptions}} =
|
| 192 |
+
LemonEx.Subscriptions.list(filter: [user_email: mail])
|
| 193 |
+
|
| 194 |
+
if subscriptions != [] && hd(subscriptions).status == "active" do
|
| 195 |
+
# Kino.Tree.new(%{user_name: hd(subscriptions).user_name})
|
| 196 |
+
Parser.parser_frame(frame_controls,frame_result)
|
| 197 |
+
else
|
| 198 |
+
frame_controls |> Kino.Frame.render("User not found")
|
| 199 |
+
end
|
| 200 |
+
end)
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
<!-- livebook:{"offset":6140,"stamp":{"token":"XCP.8bGC-qD-WmgAjvxxmy3X7TljVwFvk-TQK3aQoCk8qqXco4lZYkATe3Kw3wf3F0TFLYdsesodX7vnQ8zRf8P7mRgTh2ciuc4l_eLWUas5d7lLgNfbmXpnPh5TPEqCLjULX_kAafm9VCpMi__PXJ9UU6Gguf2NP78_ic9a","version":2}} -->
|