Skip to content

Commit

Permalink
Fix tcgapi.py _debugPackets property API. (#36)
Browse files Browse the repository at this point in the history
* Fix tcgapi.py _debugPackets property API.
Fix Session::dump bug causing failure when non-UTF8 bytes are encountered.

Signed-off-by: wyllys <[email protected]>

* Fix final dumpPacket log message format.

Signed-off-by: wyllys <[email protected]>

* Fixed packet dump index number

Signed-off-by: wyllys <[email protected]>

---------

Signed-off-by: wyllys <[email protected]>
  • Loading branch information
wyllys66 authored Aug 22, 2024
1 parent e1f1fe4 commit e13727f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
11 changes: 9 additions & 2 deletions TCGstorageAPI/tcgapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,17 @@ def maxLba(self):
@property
def _debugPackets(self):
'''
Dump TCG packets in debug log
Retrieve flag for dumping TCG packets in debug log.
'''

self.__pysed._debugPackets
return self.__pysed._debugPackets

@_debugPackets.setter
def _debugPackets(self, value):
'''
Toggle flag to enable dumping TCG packets in debug log.
'''
self.__pysed._debugPackets = value

@property
def fipsApprovedMode(self):
Expand Down
22 changes: 18 additions & 4 deletions pysed/TcgDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,24 @@ void Session::dumpPacket(const char * desc, void * buf, size_t size) {
if (dumpPackets == false)
return;

LoggerBase & logger = drive->getLogger();
std::string dump = drive->getLogger().dump(buf, size).c_str();
dump = std::string(desc) + std::string(":") + dump;
logger.write(LoggerBase::Debug, dump.c_str());
unsigned char *bytes = (unsigned char *)buf;
int maxbytes = size * 5 + 1;
int lastprint = 0;
char bytestr[maxbytes];
bzero(bytestr, sizeof(bytestr));
for (int i = 0; i < size; i++) {
int currlen = strlen(bytestr);
sprintf(bytestr + currlen, "0x%02x ", bytes[i]);
if (strlen(bytestr) > 76) {
getLogger().debug("%s [%d]: %s", desc, lastprint, bytestr);
bzero(bytestr, sizeof(bytestr));
lastprint = i + 1;
}
}
if (strlen(bytestr)) {
// dump whatever remains in the string buffer
getLogger().debug("%s [%d]: %s", desc, lastprint, bytestr);
}
}

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

0 comments on commit e13727f

Please sign in to comment.