Index: tbl_change.php
===================================================================
--- tbl_change.php	(revision 10065)
+++ tbl_change.php	(working copy)
@@ -438,13 +438,19 @@
                 $special_chars = '';
                 $data          = $vrow[$field];
             } else {
-                // loic1: special binary "characters"
                 if ($is_binary || $is_blob) {
-                    $vrow[$field] = str_replace("\x00", '\0', $vrow[$field]);
-                    $vrow[$field] = str_replace("\x08", '\b', $vrow[$field]);
-                    $vrow[$field] = str_replace("\x0a", '\n', $vrow[$field]);
-                    $vrow[$field] = str_replace("\x0d", '\r', $vrow[$field]);
-                    $vrow[$field] = str_replace("\x1a", '\Z', $vrow[$field]);
+                    if ($cfg['ProtectBinary'] === 'hex') {
+                        if (!empty($vrow[$field])) {
+                            $vrow[$field] = '0x' . bin2hex($vrow[$field]);
+                        }
+                    } else {
+                        // loic1: special binary "characters"
+                        $vrow[$field] = str_replace("\x00", '\0', $vrow[$field]);
+                        $vrow[$field] = str_replace("\x08", '\b', $vrow[$field]);
+                        $vrow[$field] = str_replace("\x0a", '\n', $vrow[$field]);
+                        $vrow[$field] = str_replace("\x0d", '\r', $vrow[$field]);
+                        $vrow[$field] = str_replace("\x1a", '\Z', $vrow[$field]);
+                    }
                 } // end if
                 $special_chars   = htmlspecialchars($vrow[$field]);
                 $data            = $vrow[$field];
@@ -480,7 +486,7 @@
         //       stored or retrieved" so it does not mean that the contents is
         //       binary
         if ($cfg['ShowFunctionFields']) {
-            if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
+            if (($cfg['ProtectBinary'] && $cfg['ProtectBinary'] != 'hex' && $is_blob && !$is_upload)
                 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
                 echo '        <td align="center">' . $strBinary . '</td>' . "\n";
             } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
@@ -579,7 +585,7 @@
             }
             echo ' />' . "\n";
 
-            if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) ) {
+            if (!(($cfg['ProtectBinary'] && $cfg['ProtectBinary'] != 'hex' && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) ) {
 
                 echo '            <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
                      . ' name="fields_null' . $field_name_appendix . '"';
@@ -803,7 +809,7 @@
         // Change by Bernard M. Piller <bernard@bmpsystems.com>
         // We don't want binary data destroyed
         elseif ($is_binary || $is_blob) {
-            if (($cfg['ProtectBinary'] && $is_blob)
+            if (($cfg['ProtectBinary'] && $cfg['ProtectBinary'] != 'hex' && $is_blob)
                 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
                 echo "\n";
                 ?>
@@ -836,6 +842,9 @@
                 <?php
 
             } else {
+                if ($cfg['ProtectBinary'] === 'hex' && ($is_binary || $is_blob)) {
+                    $len = 2 + $len * 2;
+                }
                 if ($len < 4) {
                     $fieldsize = $maxlength = 4;
                 } else {
@@ -845,7 +854,14 @@
                 echo "\n";
                 ?>
             <td>
-                <?php echo $backup_field . "\n"; ?>
+                <?php
+                echo $backup_field . "\n";
+                if ($cfg['ProtectBinary'] === 'hex' && ($is_binary || $is_blob)) {
+                ?>
+                <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="hex" />
+                <?php
+                }
+                ?>
                 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
                     value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
                     maxlength="<?php echo $maxlength; ?>"
Index: tbl_replace.php
===================================================================
--- tbl_replace.php	(revision 10065)
+++ tbl_replace.php	(working copy)
@@ -233,7 +233,9 @@
             $query_values[] = PMA_backquote($key) . ' = ' . $cur_value;
         } elseif (empty($me_funcs[$key])
          && isset($me_fields_prev[$key])
-         && ("'" . PMA_sqlAddslashes($me_fields_prev[$key]) . "'" == $val)) {
+         && ("'" . PMA_sqlAddslashes($me_fields_prev[$key]) . "'" == $val
+         || ($cfg['ProtectBinary'] === 'hex' && isset($me_fields_type[$key]) &&
+         $me_fields_type[$key] == 'hex' && PMA_sqlAddslashes($me_fields_prev[$key]) == $val))) {
             // No change for this column and no MySQL function is used -> next column
             continue;
         } elseif (! empty($val)) {
Index: libraries/tbl_replace_fields.inc.php
===================================================================
--- libraries/tbl_replace_fields.inc.php	(revision 10065)
+++ libraries/tbl_replace_fields.inc.php	(working copy)
@@ -226,6 +226,9 @@
                 }
 
                 break;
+            case 'hex':
+                $val = "''";
+                break;
             default:
                 // best way to avoid problems in strict mode (works also in non-strict mode)
                 if (isset($me_auto_increment)  && isset($me_auto_increment[$key])) {
@@ -233,6 +236,10 @@
                 }
                 break;
         }
+    } elseif ($type == 'hex') {
+        // ignore leading white space and stop processing at the first
+        // illegal character just like MySQL does for numbers
+        $val = preg_match('@^\\s*(0x[0-9A-Fa-f]+)@', $val, $tmp) ? $tmp[0] : "''";
     } elseif (! ($type == 'timestamp' && $val == 'CURRENT_TIMESTAMP')) {
         $val = "'" . PMA_sqlAddslashes($val) . "'";
     }
@@ -250,5 +257,5 @@
         $val = "''";
     }
 }  // end else (field value in the form)
-unset($valid_file_was_uploaded, $me_fields_upload, $me_fields_uploadlocal, $type, $f);
+unset($valid_file_was_uploaded, $me_fields_upload, $me_fields_uploadlocal, $type, $f, $tmp);
 ?>
Index: libraries/display_tbl.lib.php
===================================================================
--- libraries/display_tbl.lib.php	(revision 10065)
+++ libraries/display_tbl.lib.php	(working copy)
@@ -1363,27 +1363,31 @@
                     // loic1: support blanks in the key
                     $relation_id = $row[$i];
 
+                    $field_flags = PMA_DBI_field_flags($dt_result, $i);
+                    if (stristr($field_flags, 'BINARY')) {
+                        if ($GLOBALS['cfg']['ProtectBinary'] === 'hex') {
+                            if (!empty($row[$i])) {
+                                $row[$i] = '0x' . bin2hex($row[$i]);
+                            }
+                        } else {
+                            // loic1: displays special characters from binaries
+                            $row[$i] = str_replace("\x00", '\0', $row[$i]);
+                            $row[$i] = str_replace("\x08", '\b', $row[$i]);
+                            $row[$i] = str_replace("\x0a", '\n', $row[$i]);
+                            $row[$i] = str_replace("\x0d", '\r', $row[$i]);
+                            $row[$i] = str_replace("\x1a", '\Z', $row[$i]);
+                        }
+                    }
+
                     // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
                     // lem9: (unless it's a link-type transformation)
                     if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1) && !strpos($transform_function, 'link') === true) {
                         $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
                     }
 
-                    // loic1: displays special characters from binaries
-                    $field_flags = PMA_DBI_field_flags($dt_result, $i);
-                    if (stristr($field_flags, 'BINARY')) {
-                        $row[$i]     = str_replace("\x00", '\0', $row[$i]);
-                        $row[$i]     = str_replace("\x08", '\b', $row[$i]);
-                        $row[$i]     = str_replace("\x0a", '\n', $row[$i]);
-                        $row[$i]     = str_replace("\x0d", '\r', $row[$i]);
-                        $row[$i]     = str_replace("\x1a", '\Z', $row[$i]);
-                        $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
-                    }
                     // loic1: displays all space characters, 4 space
                     // characters for tabulations and <cr>/<lf>
-                    else {
-                        $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
-                    }
+                    $row[$i]         = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
 
                     // garvin: transform functions may enable nowrapping:
                     $function_nowrap = $transform_function . '_nowrap';
Index: libraries/common.lib.php
===================================================================
--- libraries/common.lib.php	(revision 10065)
+++ libraries/common.lib.php	(working copy)
@@ -2367,7 +2367,8 @@
                 // the system character set (always utf8) since
                 // mysql4.1 can use different charset for fields.
                 if (PMA_MYSQL_INT_VERSION >= 40100
-                  && ($meta->type == 'string' || $meta->type == 'blob')) {
+                  && ($meta->type == 'string' || $meta->type == 'blob')
+                  && ($GLOBALS['cfg']['ProtectBinary'] != 'hex' || !stristr($field_flags, 'BINARY'))) {
                     $condition = ' CONVERT(' . PMA_backquote($meta->table) . '.'
                         . PMA_backquote($meta->orgname) . ' USING utf8) ';
                 } else {
@@ -2382,13 +2383,15 @@
                 // timestamp is numeric on some MySQL 4.1
                 if ($meta->numeric && $meta->type != 'timestamp') {
                     $condition .= '= ' . $row[$i] . ' AND';
-                } elseif ($meta->type == 'blob'
-                    // hexify only if this is a true not empty BLOB
+                } elseif (($meta->type == 'string' || $meta->type == 'blob')
+                    // hexify only if this is a true not empty BINARY or BLOB
                      && stristr($field_flags, 'BINARY')
                      && !empty($row[$i])) {
                         // do not waste memory building a too big condition
                         if (strlen($row[$i]) < 1000) {
-                            if (PMA_MYSQL_INT_VERSION < 40002) {
+                            if ($GLOBALS['cfg']['ProtectBinary'] === 'hex') {
+                                $condition .= '= 0x' . bin2hex($row[$i]) . ' AND';
+                            } elseif (PMA_MYSQL_INT_VERSION < 40002) {
                                 $condition .= 'LIKE 0x' . bin2hex($row[$i]) . ' AND';
                             } else {
                                 // use a CAST if possible, to avoid problems
