Created
March 3, 2017 16:33
-
-
Save gbossert/74ed94ba6f606446e3c4cf9ca8c41711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
from netzob.all import * | |
data = ["hello bernard !", "hello albert !", "hello netzob !"] | |
messages = [RawMessage(d) for d in data] | |
f0 = Field(ASCII("hello ")) | |
f1 = Field(ASCII(nbChars=(1,20))) | |
f2 = Field(ASCII(" !")) | |
s = Symbol(fields = [f0, f1, f2]) | |
s.messages = messages | |
print(s) | |
# Field | Field | Field | |
# -------- | --------- | ----- | |
# 'hello ' | 'bernard' | ' !' | |
# 'hello ' | 'albert' | ' !' | |
# 'hello ' | 'netzob' | ' !' | |
# -------- | --------- | ----- | |
sorted_x = sorted(f1.getMessageValues().items(), key=operator.itemgetter(1)) | |
for message, field_value in sorted_x: | |
print(field_value, " | ", message.data) | |
# b'albert' | hello albert ! | |
# b'bernard' | hello bernard ! | |
# b'netzob' | hello netzob ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For nicer output on binary protocols: