Skip to content

Commit 1253598

Browse files
committed
fix: match PoC BLOB encoding and symmetric key flags
Two remaining byte-level mismatches vs the HarpoS7 PoC template: 1. BLOB inside Struct has an extra 0x00 before the VLQ length 2. Symmetric key flags in the SetMulti struct use flags | 0x10000 (e.g. 0x10101 for S7-1200, not 0x101)
1 parent bbcaf6f commit 1253598

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

s7/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ def _ulint_val(v: int) -> bytes:
11721172
return bytes([0x00, DataType.ULINT]) + encode_uint64_vlq(v)
11731173

11741174
def _blob_val(data: bytes) -> bytes:
1175-
return bytes([0x00, DataType.BLOB]) + encode_uint32_vlq(len(data)) + data
1175+
return bytes([0x00, DataType.BLOB, 0x00]) + encode_uint32_vlq(len(data)) + data
11761176

11771177
def _struct_begin(struct_id: int) -> bytes:
11781178
return bytes([0x00, DataType.STRUCT]) + struct.pack(">I", struct_id)
@@ -1192,7 +1192,7 @@ def _key_descriptor(key_id: bytes, flags: int) -> bytes:
11921192
result += encode_uint32_vlq(1801) + _udint_val(0) # Version
11931193
result += encode_uint32_vlq(1802) + _usint_val(0) # SecurityLevel
11941194
result += encode_uint32_vlq(1803) + _key_descriptor(public_key_id, pub_flags) # PublicKey
1195-
result += encode_uint32_vlq(1804) + _key_descriptor(symmetric_key_id, sym_flags) # SymmetricKey
1195+
result += encode_uint32_vlq(1804) + _key_descriptor(symmetric_key_id, sym_flags | 0x10000) # SymmetricKey
11961196
result += encode_uint32_vlq(1805) + _blob_val(blob) # EncryptedKey
11971197
result += _STRUCT_END
11981198

0 commit comments

Comments
 (0)