⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbindiff.cpp

📁 vbindiff-3.0_beta4.tar.gz是一个linux下二进制比较工具
💻 CPP
📖 第 1 页 / 共 4 页
字号:
     case ' ':                  // Space      cmd = cmNextDiff;      break;     case 0x05:                 // Ctrl+E     case 'E':      if (e.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))        cmd = cmEditBottom;      else        cmd = cmEditTop;      break;     case 'F':      if (e.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))        cmd = cmFind|cmgGotoBottom;      else        cmd = cmFind|cmgGotoBoth;      break;     case 0x06:               // Ctrl+F      cmd = cmFind|cmgGotoTop;      break;     case 'G':      if (e.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))        cmd = cmgGoto|cmgGotoBottom;      else        cmd = cmgGoto|cmgGotoBoth;      break;     case 0x07:               // Ctrl+G      cmd = cmgGoto|cmgGotoTop;      break;     case KEY_ESCAPE:         // Esc     case 0x03:               // Ctrl+C     case 'Q':      cmd = cmQuit;      break;     case 'C':  cmd = cmToggleASCII;  break;     default:                 // Try extended codes      switch (e.wVirtualKeyCode) {       case VK_DOWN:   cmd = cmmMove|cmmMoveLine|cmmMoveForward;  break;       case VK_RIGHT:  cmd = cmmMove|cmmMoveByte|cmmMoveForward;  break;       case VK_NEXT:   cmd = cmmMove|cmmMovePage|cmmMoveForward;  break;       case VK_END:    cmd = cmmMove|cmmMoveAll|cmmMoveForward;   break;       case VK_LEFT:   cmd = cmmMove|cmmMoveByte;                 break;       case VK_UP:     cmd = cmmMove|cmmMoveLine;                 break;       case VK_PRIOR:  cmd = cmmMove|cmmMovePage;                 break;       case VK_HOME:   cmd = cmmMove|cmmMoveAll;                  break;      } // end switch virtual key code      break;    } // end switch ASCII code  } // end while no command  if (cmd & cmmMove) {    if ((e.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) == 0)      cmd |= cmmMoveTop;    if ((e.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) == 0)      cmd |= cmmMoveBottom;  } // end if move command  return cmd;} // end getCommand#else // using curses interfaceCommand getCommand(){  Command  cmd = cmNothing;  while (cmd == cmNothing) {    int e = promptWin.readKey();    switch (safeUC(e)) {     case KEY_RETURN:           // Enter     case ' ':                  // Space      cmd = cmNextDiff;      break;     case 'E':      if (lockState == lockTop)        cmd = cmEditBottom;      else        cmd = cmEditTop;      break;     case 'F':      cmd = cmFind;      if (lockState != lockTop)    cmd |= cmgGotoTop;      if (lockState != lockBottom) cmd |= cmgGotoBottom;      break;     case 'G':      cmd = cmgGoto;      if (lockState != lockTop)    cmd |= cmgGotoTop;      if (lockState != lockBottom) cmd |= cmgGotoBottom;      break;     case KEY_ESCAPE:     case 0x03:               // Ctrl+C     case 'Q':      cmd = cmQuit;      break;     case 'C':  cmd = cmToggleASCII;  break;     case 'B':  if (!singleFile) cmd = cmUseBottom;              break;     case 'T':  if (!singleFile) cmd = cmUseTop;                 break;     case KEY_DOWN:   cmd = cmmMove|cmmMoveLine|cmmMoveForward;  break;     case KEY_RIGHT:  cmd = cmmMove|cmmMoveByte|cmmMoveForward;  break;     case KEY_NPAGE:  cmd = cmmMove|cmmMovePage|cmmMoveForward;  break;     case KEY_END:    cmd = cmmMove|cmmMoveAll|cmmMoveForward;   break;     case KEY_LEFT:   cmd = cmmMove|cmmMoveByte;                 break;     case KEY_UP:     cmd = cmmMove|cmmMoveLine;                 break;     case KEY_PPAGE:  cmd = cmmMove|cmmMovePage;                 break;     case KEY_HOME:   cmd = cmmMove|cmmMoveAll;                  break;    } // end switch ASCII code  } // end while no command  if (cmd & cmmMove) {    if (lockState != lockTop)    cmd |= cmmMoveTop;    if (lockState != lockBottom) cmd |= cmmMoveBottom;  } // end if move command  return cmd;} // end getCommand#endif  // end else curses interface//--------------------------------------------------------------------// Get a file position and move there:void gotoPosition(Command cmd){  positionInWin(cmd, inWidth+2, " Goto ");  const int  maxLen = inWidth-2;  char  buf[maxLen+1];  getString(buf, maxLen, positionHistory, hexDigits, true);  if (!buf[0])    return;  FPos  pos = strtoul(buf, NULL, 16);  if (cmd & cmgGotoTop)    file1.moveTo(pos);  if (cmd & cmgGotoBottom)    file2.moveTo(pos);} // end gotoPosition//--------------------------------------------------------------------// Search for text or bytes in the files:void searchFiles(Command cmd){  const bool havePrev = !lastSearch.empty();  positionInWin(cmd, (havePrev ? 47 : 32), " Find ");  inWin.put(2, 1,"H Hex search   T Text search");  inWin.putAttribs( 2,1, cPromptKey, 1);  inWin.putAttribs(17,1, cPromptKey, 1);  if (havePrev) {    inWin.put(33, 1,"N Next match");    inWin.putAttribs(33,1, cPromptKey, 1);  }  inWin.update();  int key = safeUC(inWin.readKey());  bool hex = false;  if (key == KEY_ESCAPE) {    inWin.hide();    return;  } else if (key == 'H')    hex = true;  if (key == 'N' && havePrev) {    inWin.hide();  } else {    positionInWin(cmd, screenWidth, (hex ? " Find Hex Bytes" : " Find Text "));    const int  maxLen = screenWidth-4;    Byte  buf[maxLen+1];    int   searchLen;    if (hex) {      getString(reinterpret_cast<char*>(buf), maxLen, hexSearchHistory, hexDigits, true, true);      searchLen = packHex(buf);    } else {      getString(reinterpret_cast<char*>(buf), maxLen, textSearchHistory);      searchLen = strlen(reinterpret_cast<char*>(buf));      if (displayTable == ebcdicDisplayTable) {        for (int i = 0; i < searchLen; ++i)          buf[i] = ascii2ebcdicTable[buf[i]];      } // end if in EBCDIC mode    } // end else text search    if (!searchLen) return;    lastSearch.assign(reinterpret_cast<char*>(buf), searchLen);  } // end else need to read search string  bool problem = false;  const Byte *const  searchPattern =    reinterpret_cast<const Byte*>(lastSearch.c_str());  if ((cmd & cmgGotoTop) &&      !file1.moveTo(searchPattern, lastSearch.length()))    problem = true;  if ((cmd & cmgGotoBottom) &&      !file2.moveTo(searchPattern, lastSearch.length()))    problem = true;  if (problem) beep();} // end searchFiles//--------------------------------------------------------------------// Handle a command://// Input://   cmd:  The command to be handledvoid handleCmd(Command cmd){  if (cmd & cmmMove) {    int  step = steps[cmd & cmmMoveSize];    if ((cmd & cmmMoveForward) == 0)      step *= -1;               // We're moving backward    if ((cmd & cmmMoveForward) && !step) {      if (cmd & cmmMoveTop)        file1.moveToEnd((!singleFile && (cmd & cmmMoveBottom)) ? &file2 : NULL);      else        file2.moveToEnd(NULL);    } else {      if (cmd & cmmMoveTop) {        if (step)          file1.move(step);        else          file1.moveTo(0);      } // end if moving top file      if (cmd & cmmMoveBottom) {        if (step)          file2.move(step);        else          file2.moveTo(0);      } // end if moving bottom file    } // end else not moving to end  } // end if move  else if ((cmd & cmgGotoMask) == cmgGoto)    gotoPosition(cmd);  else if ((cmd & cmgGotoMask) == cmFind)    searchFiles(cmd);  else if (cmd == cmNextDiff) {    if (lockState) {      lockState = lockNeither;      displayLockState();    }    do {      file1.move(bufSize);      file2.move(bufSize);    } while (!diffs.compute());  } // end else if cmNextDiff  else if (cmd == cmUseTop) {    if (lockState == lockBottom)      lockState = lockNeither;    else      lockState = lockBottom;    displayLockState();  }  else if (cmd == cmUseBottom) {    if (lockState == lockTop)      lockState = lockNeither;    else      lockState = lockTop;    displayLockState();  }  else if (cmd == cmToggleASCII) {    displayTable = ((displayTable == asciiDisplayTable)                    ? ebcdicDisplayTable                    : asciiDisplayTable );    displayCharacterSet();  }  else if (cmd == cmEditTop)    file1.edit(singleFile ? NULL : &file2);  else if (cmd == cmEditBottom)    file2.edit(&file1);  // Make sure we haven't gone past the end of both files:  while (diffs.compute() < 0) {    file1.move(-steps[cmmMovePage]);    file2.move(-steps[cmmMovePage]);  }  file1.display();  file2.display();} // end handleCmd//====================================================================// Initialization and option processing://====================================================================// Display license information and exit:bool license(GetOpt*, const GetOpt::Option*, const char*,             GetOpt::Connection, const char*, int*){  puts(titleString);  puts("\n""This program is free software; you can redistribute it and/or\n""modify it under the terms of the GNU General Public License as\n""published by the Free Software Foundation; either version 2 of\n""the License, or (at your option) any later version.\n""\n""This program is distributed in the hope that it will be useful,\n""but WITHOUT ANY WARRANTY; without even the implied warranty of\n""MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n""GNU General Public License for more details.\n""\n""You should have received a copy of the GNU General Public License\n""along with this program; if not, see <http://www.gnu.org/licenses/>."  );  exit(0);  return false;                 // Never happens} // end license//--------------------------------------------------------------------// Display version & usage information and exit://// Input://   showHelp:    True means display usage information//   exitStatus:  Status code to pass to exit()void usage(bool showHelp, int exitStatus){  if (exitStatus > 1)    cerr << "Try `" << program_name << " --help' for more information.\n";  else {    cout << titleString << endl;    if (showHelp)      cout << "Usage: " << program_name << " FILE1 [FILE2]\n\Compare FILE1 and FILE2 byte by byte.\n\If FILE2 is omitted, just display FILE1.\n\\n\Options:\n\      --help               display this help information and exit\n\      -L, --license        display license & warranty information and exit\n\      -V, --version        display version information and exit\n";  }  exit(exitStatus);} // end usagebool usage(GetOpt* getopt, const GetOpt::Option* option,           const char*, GetOpt::Connection, const char*, int*){  usage(option->shortName == '?');  return false;                 // Never happens} // end usage//--------------------------------------------------------------------// Handle options://// Input://   argc, argv:  The parameters passed to main//// Output://   argc, argv://     Modified to list only the non-option arguments//     Note: argv[0] may not be the executable namevoid processOptions(int& argc, char**& argv){  static const GetOpt::Option options[] =  {    { '?', "help",       NULL, 0, &usage },    { 'L', "license",    NULL, 0, &license },    { 'V', "version",    NULL, 0, &usage },    { 0 }  };  GetOpt getopt(options);  int argi = getopt.process(argc, const_cast<const char**>(argv));  if (getopt.error)    usage(true, 1);  if (argi >= argc)    argc = 1;           // No arguments  else {    argc -= --argi;     // Reduce argc by number of arguments used    argv += argi;       // And adjust argv[1] to the next argument  }} // end processOptions//====================================================================// Main Program://====================================================================int main(int argc, char* argv[]){  if ((program_name = strrchr(argv[0], '\\')))    // Isolate the filename:    ++program_name;  else    program_name = argv[0];  processOptions(argc, argv);  if (argc < 2 || argc > 3)    usage(1);  cout << "\VBinDiff " PACKAGE_VERSION ", Copyright 1995-2008 Christopher J. Madsen\n\VBinDiff comes with ABSOLUTELY NO WARRANTY; for details type `vbindiff -L'.\n";  singleFile = (argc == 2);  if (!initialize()) {    cerr << '\n' << program_name << ": Unable to initialize windows\n";    return 1;  }  {    ostringstream errMsg;    if (!file1.setFile(argv[1])) {      const char* errStr = ErrorMsg();      errMsg << "Unable to open " << argv[1] << ": " << errStr;    }    else if (!singleFile && !file2.setFile(argv[2])) {      const char* errStr = ErrorMsg();      errMsg << "Unable to open " << argv[2] << ": " << errStr;    }    string error(errMsg.str());    if (error.length())      exitMsg(1, error.c_str());  } // end block around errMsg  diffs.compute();  file1.display();  file2.display();  Command  cmd;  while ((cmd = getCommand()) != cmQuit)    handleCmd(cmd);  file1.shutDown();  file2.shutDown();  inWin.close();  promptWin.close();  ConWindow::shutdown();  return 0;} // end main//--------------------------------------------------------------------// Local Variables://     c-file-style: "cjm"// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -