/* BEGIN_LEGAL Copyright (c) 2021 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 */ // encoder patching example. (uses decoder too) #include "xed/xed-interface.h" #include "xed-examples-util.h" #include #include // malloc, etc. #include //strcmp #include xed_error_enum_t ex_make_patchable_instr(xed_encoder_instruction_t* to_enc, xed_decoded_inst_t* xedd, xed_uint8_t* itext, xed_uint_t ilen) { xed_encoder_request_t xede; xed_bool_t convert_ok; xed_error_enum_t xed_error; xed_uint_t olen = 0; xed_encoder_request_zero_set_mode(&xede, &(to_enc->mode)); convert_ok = xed_convert_to_encoder_request(&xede,to_enc); if (!convert_ok) { fprintf(stderr,"conversion to encode request failed\n"); return XED_ERROR_GENERAL_ERROR; } xed_error = xed_encode(&xede, itext, ilen, &olen); if (xed_error) return xed_error; // decode in to xedd xed_decoded_inst_zero_set_mode(xedd, &(to_enc->mode)); xed_error = xed_decode(xedd, itext, olen); return xed_error; } #define NINST 50 #define DBUFLEN 1000 int main(int argc, char** argv); int main(int argc, char** argv) { xed_error_enum_t xed_error; xed_state_t dstate32, dstate64; xed_uint8_t itext[NINST][XED_MAX_INSTRUCTION_BYTES]; unsigned int ilen[NINST]; xed_encoder_instruction_t to_enc[NINST]; xed_decoded_inst_t xedd[NINST]; unsigned int i, ninst=0; xed_bool_t ok; char buffer[DBUFLEN]; for(i=0;i decode) */ for(i=0;i