MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / decodeFindStruct

Method decodeFindStruct

pager_lib/smb/base.py:2209–2246  ·  view source on GitHub ↗
(data_bytes)

Source from the content-addressed store, hash-verified

2207 self._pushToArray(messages_history, m)
2208
2209 def decodeFindStruct(data_bytes):
2210 # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1
2211 info_format = '<IIQQQQQQIIIBB24s'
2212 info_size = struct.calcsize(info_format)
2213
2214 data_length = len(data_bytes)
2215 offset = 0
2216 while offset < data_length:
2217 if offset + info_size > data_length:
2218 return data_bytes[offset:]
2219
2220 next_offset, _, \
2221 create_time, last_access_time, last_write_time, last_attr_change_time, \
2222 file_size, alloc_size, file_attributes, filename_length, ea_size, \
2223 short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size])
2224
2225 offset2 = offset + info_size
2226 if offset2 + filename_length > data_length:
2227 return data_bytes[offset:]
2228
2229 filename = DataFaultToleranceStrategy.data_bytes_decode(data_bytes[offset2:offset2+filename_length])
2230 short_name = DataFaultToleranceStrategy.data_bytes_decode(short_name)
2231
2232 accept_result = False
2233 if (file_attributes & 0xff) in ( 0x00, ATTR_NORMAL ): # Only the first 8-bits are compared. We ignore other bits like temp, compressed, encryption, sparse, indexed, etc
2234 accept_result = (search == SMB_FILE_ATTRIBUTE_NORMAL) or (search & SMB_FILE_ATTRIBUTE_INCL_NORMAL)
2235 else:
2236 accept_result = (file_attributes & search) > 0
2237 if accept_result:
2238 results.append(SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time),
2239 convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
2240 file_size, alloc_size, file_attributes, short_name, filename))
2241
2242 if next_offset:
2243 offset += next_offset
2244 else:
2245 break
2246 return b''
2247
2248 def findFirstCB(find_message, **kwargs):
2249 self._pushToArray(messages_history, find_message)

Callers

nothing calls this directly

Calls 4

SharedFileClass · 0.85
convertFILETIMEtoEpochFunction · 0.85
appendMethod · 0.80
data_bytes_decodeMethod · 0.45

Tested by

no test coverage detected