Rename bin_offset to payload_offset

This commit is contained in:
QuantumEntangledAndy authored and Andrew committed 2020-10-15 11:02:32 +07:00
1 parent 4ff53b73af
commit 31aefdbc74
4 files changed
+26 -26

No files matched your search

+12 -12
View File
@@ -10,7 +10,7 @@ message_len = ProtoField.int32("baichuan.msg_len", "messageLen", base.DEC)
xml_enc_offset = ProtoField.int32("baichuan.xml_encryption_offset", "xmlEncryptionOffset", base.DEC)
xml_enc_used = ProtoField.bool("baichuan.xml_encryption_used", "encrypted", base.NONE)
message_class = ProtoField.int32("baichuan.msg_class", "messageClass", base.DEC)
f_bin_offset = ProtoField.int32("baichuan.bin_offset", "binOffset", base.DEC)
f_payload_offset = ProtoField.int32("baichuan.payload_offset", "binOffset", base.DEC)
username = ProtoField.string("baichuan.username", "username", base.ASCII)
password = ProtoField.string("baichuan.password", "password", base.ASCII)
@@ -21,7 +21,7 @@ bc_protocol.fields = {
xml_enc_offset,
xml_enc_used,
message_class,
f_bin_offset,
f_payload_offset,
username,
password,
}
@@ -101,12 +101,12 @@ function bc_protocol.dissector(buffer, pinfo, tree)
return buffer:len()
end
-- bin_offset is either nil (no binary data) or nonzero
-- TODO: bin_offset is actually stateful!
local bin_offset = nil
-- payload_offset is either nil (no binary data) or nonzero
-- TODO: payload_offset is actually stateful!
local payload_offset = nil
if header_len == 24 then
bin_offset = buffer(20, 4):le_uint()
if bin_offset == 0 then bin_offset = nil end
payload_offset = buffer(20, 4):le_uint()
if payload_offset == 0 then payload_offset = nil end
end
local bc_subtree = tree:add(bc_protocol, buffer(),
@@ -125,7 +125,7 @@ function bc_protocol.dissector(buffer, pinfo, tree)
header:add_le(xml_enc_used, buffer(16, 1))
header:add_le(message_class, buffer(18, 2))
:append_text(" (" .. class .. ")")
header:add_le(f_bin_offset, buffer(20, 4))
header:add_le(f_payload_offset, buffer(20, 4))
if msg_len == 0 then
return
@@ -140,11 +140,11 @@ function bc_protocol.dissector(buffer, pinfo, tree)
body:add_le(password, buffer(header_len + 32, 32))
end
else
local body_tvb = buffer(header_len, bin_offset):tvb()
local body_tvb = buffer(header_len, payload_offset):tvb()
body:add(body_tvb(), "XML Payload")
if encrypted then
local ba = buffer(header_len, bin_offset):bytes()
local ba = buffer(header_len, payload_offset):bytes()
local decrypted = xml_encrypt(ba, enc_offset)
body_tvb = decrypted:tvb("Decrypted XML")
-- Create a tree item that, when clicked, automatically shows the tab we just created
@@ -152,8 +152,8 @@ function bc_protocol.dissector(buffer, pinfo, tree)
end
Dissector.get("xml"):call(body_tvb, pinfo, body)
if bin_offset ~= nil then
local binary_tvb = buffer(header_len + bin_offset, nil):tvb()
if payload_offset ~= nil then
local binary_tvb = buffer(header_len + payload_offset, nil):tvb()
body:add(binary_tvb(), "Binary Payload")
if msg_type == 0x03 then -- video
Dissector.get("h265"):call(binary_tvb, pinfo, tree)
+4 -4
View File
@@ -116,7 +116,7 @@ fn bc_modern_msg<'a, 'b>(
Err,
};
let xml_len = match header.bin_offset {
let xml_len = match header.payload_offset {
Some(off) => off,
_ => header.body_len,
};
@@ -183,7 +183,7 @@ fn bc_header(buf: &[u8]) -> IResult<&[u8], BcHeader> {
// A copy of the source code for the camera would be very useful.
let encrypted = response_code != 0;
let (buf, bin_offset) = cond(has_bin_offset(class), le_u32)(buf)?;
let (buf, payload_offset) = cond(has_payload_offset(class), le_u32)(buf)?;
Ok((
buf,
@@ -193,7 +193,7 @@ fn bc_header(buf: &[u8]) -> IResult<&[u8], BcHeader> {
enc_offset,
encrypted,
class,
bin_offset,
payload_offset,
},
))
}
@@ -280,7 +280,7 @@ fn test_bc_modern_login_success() {
assert_eq!(header.encrypted, true);
assert_eq!(header.class, 0x0000);
// Previously, we were not handling bin_offset == 0 (no bin offset) correctly.
// Previously, we were not handling payload_offset == 0 (no bin offset) correctly.
// Test that we decoded XML and no binary.
match body {
BcBody::ModernMsg(ModernMsg {
+5 -5
View File
@@ -44,7 +44,7 @@ pub(super) struct BcHeader {
pub enc_offset: u32,
pub encrypted: bool,
pub class: u16,
pub bin_offset: Option<u32>,
pub payload_offset: Option<u32>,
}
/// The components of the Baichuan TLV header that are not
@@ -62,7 +62,7 @@ pub struct BcMeta {
#[derive(Debug, PartialEq, Eq)]
pub(super) struct BcSendInfo {
pub body_len: u32,
pub bin_offset: Option<u32>,
pub payload_offset: Option<u32>,
}
#[derive(Debug)]
@@ -146,9 +146,9 @@ impl BcHeader {
}
}
pub fn from_meta(meta: &BcMeta, body_len: u32, bin_offset: Option<u32>) -> BcHeader {
pub fn from_meta(meta: &BcMeta, body_len: u32, payload_offset: Option<u32>) -> BcHeader {
BcHeader {
bin_offset,
payload_offset,
body_len,
msg_id: meta.msg_id,
enc_offset: meta.client_idx,
@@ -158,7 +158,7 @@ impl BcHeader {
}
}
pub(super) fn has_bin_offset(class: u16) -> bool {
pub(super) fn has_payload_offset(class: u16) -> bool {
// See BcHeader::is_modern() for a description of which packets have the bin offset
class == 0x6414 || class == 0x0000
}
+5 -5
View File
@@ -14,7 +14,7 @@ impl Bc {
// Ideally this would be a combinator, but that would be hairy because we have to
// serialize the XML to have the metadata to build the header
let body_buf;
let bin_offset;
let payload_offset;
match &self.body {
BcBody::ModernMsg(ref modern) => {
let (buf, xml_len) = gen(
@@ -22,7 +22,7 @@ impl Bc {
vec![],
)?;
body_buf = buf;
bin_offset = if has_bin_offset(self.meta.class) {
payload_offset = if has_payload_offset(self.meta.class) {
// If we're required to put binary length, put 0 if we have no binary
Some(if modern.payload.is_some() {
xml_len as u32
@@ -36,12 +36,12 @@ impl Bc {
BcBody::LegacyMsg(ref legacy) => {
let (buf, _) = gen(bc_legacy(legacy), vec![])?;
body_buf = buf;
bin_offset = None;
payload_offset = None;
}
}
// Now have enough info to create the header
let header = BcHeader::from_meta(&self.meta, body_buf.len() as u32, bin_offset);
let header = BcHeader::from_meta(&self.meta, body_buf.len() as u32, payload_offset);
let (mut buf, _n) = gen(tuple((bc_header(&header), slice(body_buf))), buf)?;
@@ -94,7 +94,7 @@ fn bc_header<W: Write>(header: &BcHeader) -> impl SerializeFn<W> {
le_u8(signaled_encryption),
le_u8(spare), // skipped byte
le_u16(header.class),
opt(header.bin_offset, le_u32),
opt(header.payload_offset, le_u32),
))
}