/* BEGIN_LEGAL Copyright (c) 2023 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. END_LEGAL */ #include #include #include #include #include "xed/xed-interface.h" #define HEX_BUFLEN 200 #define MAX_INPUT_NIBBLES (XED_MAX_INSTRUCTION_BYTES*2) static xed_uint8_t letter_cvt(char a, char base) { return (a-base); } xed_uint8_t convert_ascii_nibble(char c) { if (c >= '0' && c <= '9') { return letter_cvt(c,'0'); } else if (c >= 'a' && c <= 'f') { return (xed_uint8_t)(letter_cvt(c,'a') + 10U); } else if (c >= 'A' && c <= 'F') { return (xed_uint8_t)(letter_cvt(c,'A') + 10U); } else { printf("[XED CLIENT ERROR] Invalid character in hex string: %c\n", c); exit(1); } } xed_uint8_t convert_ascii_nibbles(char c1, char c2) { xed_uint8_t a = (xed_uint8_t)(convert_ascii_nibble(c1) * 16 + convert_ascii_nibble(c2)); return a; } unsigned int convert_ascii_to_hex(const char* src, xed_uint8_t* dst, unsigned int max_bytes) { unsigned int j; unsigned int p = 0; unsigned int i = 0; const unsigned int len = XED_STATIC_CAST(unsigned int,strlen(src)); if ((len & 1) != 0) { printf("test string was not an even number of nibbles"); exit(1); } if (len > (max_bytes * 2) ) { printf("test string was too long"); exit(1); } for(j=0; j= uargc) { printf("Need some hex instruction nibbles"); exit(1); } for(i=first_argv;i