import_text: Add ASCII identification checkbox

Add a checkbox for the extra detection for ASCII in a hex+ASCII
hexdump even when the text looks like hexbytes to Import from Hex
Dump. Save and restore it from the settings. Work towards #16724.
This commit is contained in:
John Thacker 2021-12-26 17:40:59 -05:00
parent 0dfc6414e0
commit 23355cddf6
6 changed files with 48 additions and 9 deletions

View File

@ -150,9 +150,6 @@ static guint32 hdr_data_chunk_ppid = 0;
/* Export PDU */
static gboolean hdr_export_pdu = FALSE;
/* ASCII text dump identification */
static gboolean identify_ascii = FALSE;
static gboolean has_direction = FALSE;
/*--- Local data -----------------------------------------------------------------*/
@ -579,7 +576,7 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump
break;
case 'a':
identify_ascii = TRUE;
info->hexdump.identify_ascii = TRUE;
break;
case 'v':
@ -805,7 +802,6 @@ parse_options(int argc, char *argv[], text_import_info_t * const info, wtap_dump
info->ppi = hdr_data_chunk_ppid;
info->max_frame_length = max_offset;
info->identify_ascii = identify_ascii;
/* Display summary of our state */
if (!quiet) {

View File

@ -216,6 +216,7 @@ void ImportTextDialog::applyDialogSettings()
ti_ui_->noOffsetButton->setChecked(true);
}
ti_ui_->directionIndicationCheckBox->setChecked(settings["hexdump.hasDirection"].toBool());
ti_ui_->asciiIdentificationCheckBox->setChecked(settings["hexdump.identifyAscii"].toBool());
// Regular Expression
ti_ui_->regexTextEdit->setText(settings["regex.format"].toString());
@ -300,6 +301,7 @@ void ImportTextDialog::storeDialogSettings()
settings["hexdump.offsets"] = "none";
}
settings["hexdump.hasDirection"] = ti_ui_->directionIndicationCheckBox->isChecked();
settings["hexdump.identifyAscii"] = ti_ui_->asciiIdentificationCheckBox->isChecked();
// Regular Expression
settings["regex.format"] = ti_ui_->regexTextEdit->toPlainText();
@ -654,6 +656,7 @@ void ImportTextDialog::on_modeTabWidget_currentChanged(int index) {
import_info_.mode = TEXT_IMPORT_HEXDUMP;
memset(&import_info_.hexdump, 0, sizeof(import_info_.hexdump));
on_directionIndicationCheckBox_toggled(ti_ui_->directionIndicationCheckBox->isChecked());
on_asciiIdentificationCheckBox_toggled(ti_ui_->asciiIdentificationCheckBox->isChecked());
enableFieldWidgets(false, true);
break;
case 1:
@ -684,6 +687,11 @@ void ImportTextDialog::on_directionIndicationCheckBox_toggled(bool checked)
import_info_.hexdump.has_direction = checked;
}
void ImportTextDialog::on_asciiIdentificationCheckBox_toggled(bool checked)
{
import_info_.hexdump.identify_ascii = checked;
}
/*******************************************************************************
* Regex Tab
*/

View File

@ -91,6 +91,7 @@ private slots:
/* Hex Dump input */
void on_noOffsetButton_toggled(bool checked);
void on_directionIndicationCheckBox_toggled(bool checked);
void on_asciiIdentificationCheckBox_toggled(bool checked);
/* Regex input */
void on_regexTextEdit_textChanged();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>673</height>
<width>562</width>
<height>832</height>
</rect>
</property>
<property name="maximumSize">
@ -194,6 +194,40 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="asciiLayout" stretch="0,0,0">
<item>
<widget class="QLabel" name="asciiIdentificationLabel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether to do extra processing detecting the start of the ASCII representation at the end of a hex+ASCII line even if it looks like hex bytes.&lt;/p&gt;&lt;p&gt;Do not enable if the hex dump does not contain ASCII.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>ASCII identification:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="asciiIdentificationCheckBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether to do extra processing detecting the start of the ASCII representation at the end of a hex+ASCII line even if it looks like hex bytes.&lt;/p&gt;&lt;p&gt;Do not enable if the hex dump does not contain ASCII.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="asciiSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -1451,7 +1451,7 @@ parse_token(token_t token, char *str)
by_eol = 1;
state = START_OF_LINE;
}
if (info_p->identify_ascii) {
if (info_p->hexdump.identify_ascii) {
/* Here a line of pkt bytes reading is finished
compare the ascii and hex to avoid such situation:
"61 62 20 ab ", when ab is ascii dump then it should

View File

@ -76,6 +76,7 @@ typedef struct
FILE *import_text_FILE;
enum offset_type offset_type;
gboolean has_direction;
gboolean identify_ascii;
} hexdump;
struct {
GMappedFile* import_text_GMappedFile;
@ -111,7 +112,6 @@ typedef struct
/* const */ gchar* payload;
guint max_frame_length;
gboolean identify_ascii;
/* Output info */
guint num_packets_read;