关于#c语言#的问题:复杂的反汇编程序的一些请教

最近在学习初步的反汇编程序
我写了一个大致框架
#include 
#include 
#include 

int convertStrToByteCode(const char *str, unsigned char inst[], int size);

int main(int argc, char **argv)
{
  FILE *pFile = NULL;

  char buffer[15];

  if (argc < 2)
  {
    pFile = fopen("./test1.txt", "r");
  }
  else
  {
    pFile = fopen(argv[1], "r");
  }

  if (pFile == NULL)
  {
    printf("Error open test file, please make sure they exist.\n");

    return 0;
  }

  while (fgets(buffer, 15, pFile) && strlen(buffer) > 1)
  {
    //This unsigned char array stores an instruction read from the file
    //As the largest y86 instruction is 6 bytes, there are 6 unsigned char in the array where
    //each represents a byte.
    unsigned char instruction[6] = {0, 0, 0, 0, 0, 0};
    convertStrToByteCode(buffer, instruction, 6);

    //TODO: From here, your task is to complete the implementation so that all y86 opcodes can be disassembled.
    //Any undisassembled opcode should display as "TODO: undisassembled opcode"
    printf("TODO: undisassembled opcode. The first byte of the instruction is 0x%X\n", instruction[0]);
  }

  fclose(pFile);

  return 0;
}

/****************************************************************************
N.B. You do not need to modify or work in this function.
Description:
This function converts a line of machine code read from the text file
into machine byte code.
The machine code is stored in an unsigned char array.
******************************************************************************/
int convertStrToByteCode(const char *str, unsigned char inst[], int size)
{
  int numHexDigits = 0;
  char *endstr;
  //Each instruction should consist of at most 12 hex digits
  numHexDigits = strlen(str) - 1;
  //Convert the string to integer, N.B. this integer is in decimal
  long long value = strtol(str, &endstr, 16);

  int numBytes = numHexDigits >> 1;
  int byteCount = numHexDigits >> 1;

  while (byteCount > 0)
  {
    unsigned long long mask = 0xFF;
    unsigned long shift = (numBytes - byteCount) << 3;

    inst[byteCount - 1] = (value & (mask << shift)) >> shift;
    byteCount--;
  }

  //Return the size of the instruction in bytes
  return numHexDigits >> 1;
}

这个是我设置的测试程序,我试很多次但是最后都是报错,无奈我只好把我写的删掉了

img

没明白,到底要问啥?

This unsigned char array stores an instruction read from the file 这个无符号的字符数组存储从文件中读取的指令
As the largest y86 instruction is 6 bytes, there are 6 unsigned char in the array where each represents a byte.
由于最大的 y86 指令是 6 个字节,因此数组中有 6 个无符号字符,每个字符代表一个字节。
From here, your task is to complete the implementation so that all y86 opcodes can be disassembled.
从这里开始,您的任务是完成实现,以便可以反汇编所有 y86 操作码。
Any undisassembled opcode should display as "TODO: undisassembled opcode"
任何未反汇编的操作码都应显示为“TODO:未反汇编的操作码”
You do not need to modify or work in this function.
Description:
This function converts a line of machine code read from the text file
into machine byte code.
The machine code is stored in an unsigned char array.
您无需修改或使用此功能。
描述:
此函数转换从文本文件中读取的一行机器代码
转换为机器字节码。
机器代码存储在无符号字符数组中。
Each instruction should consist of at most 12 hex digits
每条指令最多应包含12个十六进制数字

Convert the string to integer, N.B. this integer is in decimal

将字符串转换为整数,注意此整数是十进制
Return the size of the instruction in bytes
返回指令的大小(以字节为单位)