Changeset - b1ac644087e5
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-10-10 14:48:42
hy@ozderya.net
when switching from hex to ascii, patch hex string in case of missing nibble
1 file changed with 12 insertions and 1 deletions:
0 comments (0 inline, 0 general)
commandedit.cpp
Show inline comments
 
@@ -19,6 +19,8 @@
 

	
 
#include <QKeyEvent>
 

	
 
#include <QtDebug>
 

	
 
#include "commandedit.h"
 

	
 
class HexCommandValidator : public QRegExpValidator
 
@@ -76,7 +78,16 @@ void CommandEdit::setMode(bool ascii)
 
    if (ascii)
 
    {
 
        setValidator(asciiValidator);
 
        setText(QByteArray::fromHex(text().remove(" ").toLatin1()));
 

	
 
        auto hexText = text().remove(" ");
 
        // try patching HEX string in case of missing nibble so that
 
        // input doesn't turn into gibberish
 
        if (hexText.size() % 2 == 1)
 
        {
 
            hexText.replace(hexText.size()-1, 1, "3F"); // 0x3F = '?'
 
            qWarning() << "Broken byte in hex command is replaced. Check your command!";
 
        }
 
        setText(QByteArray::fromHex(hexText.toLatin1()));
 
    }
 
    else
 
    {
0 comments (0 inline, 0 general)