Skip to content

Commit e13727f

Browse files
authored
Fix tcgapi.py _debugPackets property API. (#36)
* Fix tcgapi.py _debugPackets property API. Fix Session::dump bug causing failure when non-UTF8 bytes are encountered. Signed-off-by: wyllys <wyllys.ingersoll@keepertech.com> * Fix final dumpPacket log message format. Signed-off-by: wyllys <wyllys.ingersoll@keepertech.com> * Fixed packet dump index number Signed-off-by: wyllys <wyllys.ingersoll@keepertech.com> --------- Signed-off-by: wyllys <wyllys.ingersoll@keepertech.com>
1 parent e1f1fe4 commit e13727f

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

TCGstorageAPI/tcgapi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,17 @@ def maxLba(self):
311311
@property
312312
def _debugPackets(self):
313313
'''
314-
Dump TCG packets in debug log
314+
Retrieve flag for dumping TCG packets in debug log.
315315
'''
316316

317-
self.__pysed._debugPackets
317+
return self.__pysed._debugPackets
318+
319+
@_debugPackets.setter
320+
def _debugPackets(self, value):
321+
'''
322+
Toggle flag to enable dumping TCG packets in debug log.
323+
'''
324+
self.__pysed._debugPackets = value
318325

319326
@property
320327
def fipsApprovedMode(self):

pysed/TcgDrive.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,24 @@ void Session::dumpPacket(const char * desc, void * buf, size_t size) {
441441
if (dumpPackets == false)
442442
return;
443443

444-
LoggerBase & logger = drive->getLogger();
445-
std::string dump = drive->getLogger().dump(buf, size).c_str();
446-
dump = std::string(desc) + std::string(":") + dump;
447-
logger.write(LoggerBase::Debug, dump.c_str());
444+
unsigned char *bytes = (unsigned char *)buf;
445+
int maxbytes = size * 5 + 1;
446+
int lastprint = 0;
447+
char bytestr[maxbytes];
448+
bzero(bytestr, sizeof(bytestr));
449+
for (int i = 0; i < size; i++) {
450+
int currlen = strlen(bytestr);
451+
sprintf(bytestr + currlen, "0x%02x ", bytes[i]);
452+
if (strlen(bytestr) > 76) {
453+
getLogger().debug("%s [%d]: %s", desc, lastprint, bytestr);
454+
bzero(bytestr, sizeof(bytestr));
455+
lastprint = i + 1;
456+
}
457+
}
458+
if (strlen(bytestr)) {
459+
// dump whatever remains in the string buffer
460+
getLogger().debug("%s [%d]: %s", desc, lastprint, bytestr);
461+
}
448462
}
449463

450464
void PacketHeaders::fill(Drive * const drive, Session * const session,

0 commit comments

Comments
 (0)