forked from warthog618/sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smsdeliver.go
76 lines (71 loc) · 1.5 KB
/
smsdeliver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: MIT
//
// Copyright © 2019 Kent Gibson <[email protected]>.
// smsdeliver provides an example of extracting a message from a set of
// SMS-DELIVER TPDUs.
package main
import (
"encoding/hex"
"flag"
"fmt"
"log"
"os"
"github.com/warthog618/sms"
"github.com/warthog618/sms/encoding/pdumode"
)
func main() {
var pm bool
flag.BoolVar(&pm, "p", false, "PDU is prefixed with SCA (PDU mode)")
flag.Usage = usage
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
os.Exit(1)
}
c := sms.NewCollector()
defer c.Close()
for _, a := range flag.Args() {
b, err := hex.DecodeString(a)
if err != nil {
log.Fatal(err)
}
tb := b
if pm {
pdu, err := pdumode.UnmarshalBinary(b)
if err != nil {
log.Fatal(err)
}
tb = pdu.TPDU
}
t, err := sms.Unmarshal(tb)
if err != nil {
log.Printf("unmarshal error: %v", err)
continue
}
pdus, err := c.Collect(*t)
if err != nil {
log.Printf("collect error: %v", err)
}
if pdus == nil {
continue
}
msg, err := sms.Decode(pdus)
if err != nil {
log.Printf("decode error: %v", err)
}
if msg != nil {
fmt.Printf("%s: %s\n", pdus[0].OA.Number(), msg)
}
}
// report active collect pipes
pipes := c.Pipes()
for k, v := range pipes {
fmt.Println("incomplete reassembly: ", k)
fmt.Println(v)
}
}
func usage() {
fmt.Fprintf(os.Stderr, "smsdeliver decodes and displays the message from one or more SMS Deliver TPDUs.\n"+
"Usage: smsdeliver [-p] <pdu> [pdu...]\n")
flag.PrintDefaults()
}