|
|
@@ -74,13 +74,14 @@ def show_help(ofp):
|
|
|
ofp.write("usage:");
|
|
|
ofp.write("\n");
|
|
|
ofp.write("\n");
|
|
|
- ofp.write(" format_debug_msg.py [-h] [-F] <MAILBOX> [--asciihex] <PAYLOAD>\n");
|
|
|
+ ofp.write(" format_debug_msg.py [-h] [-F] <MAILBOX> [--asciihex] [-i] <PAYLOAD>\n");
|
|
|
ofp.write("\n");
|
|
|
ofp.write(" <MAILBOX> destination mailbox\n")
|
|
|
ofp.write(" <PAYLOAD> payload to convert\n")
|
|
|
ofp.write(" [--show-mailbox] print out all valid mailboxes\n")
|
|
|
ofp.write(" [-F|-force-mailbox] do not check to see if MAILBOX is in list of valid mailboxes\n")
|
|
|
ofp.write(" [--asciihex] payload in ASCII hex format (with spaces) (example: ' 23 74 65 73 74')\n")
|
|
|
+ ofp.write(" [-i] Read from file instead ('-' for stdin)\n")
|
|
|
ofp.write(" [-h|-help] help (this screen)\n")
|
|
|
ofp.write("\n");
|
|
|
|
|
|
@@ -94,8 +95,10 @@ payload_converted = ""
|
|
|
asciihex_flag = False
|
|
|
force_mailbox = False
|
|
|
|
|
|
+ifn = ''
|
|
|
+
|
|
|
argv = sys.argv[1:]
|
|
|
-options, rem = getopt.gnu_getopt(sys.argv[1:], "hF", ["asciihex", "help", "version", "show-mailbox", "force-mailbox"])
|
|
|
+options, rem = getopt.gnu_getopt(sys.argv[1:], "hFi:", ["asciihex", "help", "version", "show-mailbox", "force-mailbox", "input="])
|
|
|
for opt, arg in options:
|
|
|
if opt in ('-v', '--version'):
|
|
|
show_version(sys.stdout)
|
|
|
@@ -110,11 +113,13 @@ for opt, arg in options:
|
|
|
elif opt in ('--show-mailbox'):
|
|
|
show_mailboxes()
|
|
|
sys.exit(0)
|
|
|
+ elif opt in ('-i', '--input'):
|
|
|
+ ifn = arg
|
|
|
else:
|
|
|
show_help(sys.sdterr)
|
|
|
sys.exit(-1)
|
|
|
|
|
|
-if len(rem) < 2:
|
|
|
+if (len(rem) < 2) and ((len(rem) != 1) or (len(ifn)==0)):
|
|
|
sys.stderr.write("must provide MAILBOX and PAYLOAD\n")
|
|
|
show_help(sys.stderr)
|
|
|
sys.exit(-1)
|
|
|
@@ -128,15 +133,17 @@ if not force_mailbox:
|
|
|
sys.stderr.write("Use the --show-mailbox option to see a list of vlaid options\n\n")
|
|
|
sys.exit(-1)
|
|
|
|
|
|
-payload_text = rem[1]
|
|
|
+if len(ifn)==0:
|
|
|
+ payload_text = rem[1]
|
|
|
+else:
|
|
|
+ with open(ifn) as fp:
|
|
|
+ payload_text = fp.read()
|
|
|
|
|
|
if asciihex_flag:
|
|
|
payload_converted = payload_text
|
|
|
else:
|
|
|
for ch in payload_text:
|
|
|
- payload_converted += format(ord(ch), ' 02x')
|
|
|
-
|
|
|
-
|
|
|
+ payload_converted += " " + format(ord(ch), '02x').zfill(2)
|
|
|
|
|
|
print mailbox + ":" + payload_converted
|
|
|
|