Added command line argument to extract payload
This commit is contained in:
parent
0cb656e659
commit
fe886ef655
133
cmd/sdb/main.go
133
cmd/sdb/main.go
@ -5,69 +5,94 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"flag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"required argument missing\n")
|
||||
flags := flag.NewFlagSet("sdb", flag.ExitOnError)
|
||||
flags.SetOutput(os.Stdout)
|
||||
flags.Usage = func() {
|
||||
fmt.Fprintf(flags.Output(),
|
||||
"Usage: %s [OPTION] <files> ...\nOptions:\n",
|
||||
os.Args[0])
|
||||
flags.PrintDefaults()
|
||||
}
|
||||
|
||||
plonly := flags.Bool("payload", false, "only return the payload")
|
||||
|
||||
flags.Parse(os.Args[1:])
|
||||
|
||||
if flags.NArg() < 1 {
|
||||
fmt.Fprintf(os.Stderr, "files parameter cannot be empty\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"error reading \"%s\": %s\n",
|
||||
os.Args[1], err.Error())
|
||||
}
|
||||
|
||||
data, err := sdb.ParseSDB(raw)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"%s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Protocol Revision: %d\n",
|
||||
data.ProtocolRevision)
|
||||
fmt.Printf("Message Length: %d\n",
|
||||
data.Length)
|
||||
for c, i := range data.Elements {
|
||||
if c > 0 {
|
||||
fmt.Println()
|
||||
for _, fn := range flags.Args() {
|
||||
raw, err := ioutil.ReadFile(fn)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"error reading \"%s\": %s\n",
|
||||
fn, err.Error())
|
||||
continue
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case sdb.MOHeader:
|
||||
fmt.Printf("\tMO Header IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Header Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Header CDR Reference: %d\n",
|
||||
v.CDRReference)
|
||||
fmt.Printf("\tMO Header IMEI: %s\n",
|
||||
v.IMEI)
|
||||
fmt.Printf("\tMO Header Status: %s (%d)\n",
|
||||
v.StatusString(), v.Status)
|
||||
fmt.Printf("\tMO Header MOMSN: %d\n",
|
||||
v.MOMSN)
|
||||
fmt.Printf("\tMO Header MTMSN: %d\n",
|
||||
v.MTMSN)
|
||||
fmt.Printf("\tMO Header Session Time: %s\n",
|
||||
v.SessionTime().String())
|
||||
|
||||
case sdb.MOPayload:
|
||||
fmt.Printf("\tMO Payload IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Payload Length: %d\n",
|
||||
v.Length)
|
||||
data, err := sdb.ParseSDB(raw)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"%s\n", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
case sdb.MOConfirmation:
|
||||
fmt.Printf("\tMO Confirmation IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Confirmation Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Confirmation Status: %d\n",
|
||||
v.Status)
|
||||
if *plonly {
|
||||
for _, i := range data.Elements {
|
||||
switch v := i.(type) {
|
||||
case sdb.MOPayload:
|
||||
os.Stdout.Write(v.Payload)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Protocol Revision: %d\n",
|
||||
data.ProtocolRevision)
|
||||
fmt.Printf("Message Length: %d\n",
|
||||
data.Length)
|
||||
for c, i := range data.Elements {
|
||||
if c > 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case sdb.MOHeader:
|
||||
fmt.Printf("\tMO Header IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Header Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Header CDR Reference: %d\n",
|
||||
v.CDRReference)
|
||||
fmt.Printf("\tMO Header IMEI: %s\n",
|
||||
v.IMEI)
|
||||
fmt.Printf("\tMO Header Status: %s (%d)\n",
|
||||
v.StatusString(), v.Status)
|
||||
fmt.Printf("\tMO Header MOMSN: %d\n",
|
||||
v.MOMSN)
|
||||
fmt.Printf("\tMO Header MTMSN: %d\n",
|
||||
v.MTMSN)
|
||||
fmt.Printf("\tMO Header Session Time: %s\n",
|
||||
v.SessionTime().String())
|
||||
|
||||
case sdb.MOPayload:
|
||||
fmt.Printf("\tMO Payload IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Payload Length: %d\n",
|
||||
v.Length)
|
||||
|
||||
case sdb.MOConfirmation:
|
||||
fmt.Printf("\tMO Confirmation IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Confirmation Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Confirmation Status: %d\n",
|
||||
v.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user