Changeset 12138 in vbox for trunk/src/VBox/Disassembler/testcase
- Timestamp:
- Sep 5, 2008 3:35:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Disassembler/testcase/tstDisasm-2.cpp
r9271 r12138 727 727 } 728 728 729 /** 730 * Converts a hex char to a number. 731 * 732 * @returns 0..15 on success, -1 on failure. 733 * @param ch The character. 734 */ 735 static int HexDigitToNum(char ch) 736 { 737 switch (ch) 738 { 739 case '0': return 0; 740 case '1': return 1; 741 case '2': return 2; 742 case '3': return 3; 743 case '4': return 4; 744 case '5': return 5; 745 case '6': return 6; 746 case '7': return 7; 747 case '8': return 8; 748 case '9': return 9; 749 case 'A': 750 case 'a': return 0xa; 751 case 'B': 752 case 'b': return 0xb; 753 case 'C': 754 case 'c': return 0xc; 755 case 'D': 756 case 'd': return 0xd; 757 case 'E': 758 case 'e': return 0xe; 759 case 'F': 760 case 'f': return 0xf; 761 default: 762 RTPrintf("error: Invalid hex digig '%c'\n", ch); 763 return -1; 764 } 765 } 729 766 730 767 /** … … 738 775 RTStrmPrintf(g_pStdErr, 739 776 "usage: %s [options] <file1> [file2..fileN]\n" 777 " or: %s [options] <-x|--hex-bytes> <hex byte> [more hex..]\n" 740 778 " or: %s <--help|-h>\n" 741 779 "\n" … … 773 811 RTFOFF off = 0; 774 812 RTFOFF cbMax = _1G; 813 bool fHexBytes = false; 775 814 776 815 /* … … 781 820 { "--address", 'a', RTGETOPT_REQ_UINT64 }, 782 821 { "--cpumode", 'c', RTGETOPT_REQ_UINT32 }, 783 { "--help", 'h', 0},822 { "--help", 'h', RTGETOPT_REQ_NOTHING }, 784 823 { "--bytes", 'b', RTGETOPT_REQ_INT64 }, 785 { "--listing", 'l', 0},786 { "--no-listing", 'L', 0},824 { "--listing", 'l', RTGETOPT_REQ_NOTHING }, 825 { "--no-listing", 'L', RTGETOPT_REQ_NOTHING }, 787 826 { "--offset", 'o', RTGETOPT_REQ_INT64 }, 788 827 { "--style", 's', RTGETOPT_REQ_STRING }, 789 828 { "--undef-op", 'u', RTGETOPT_REQ_STRING }, 829 { "--hex-bytes", 'x', RTGETOPT_REQ_NOTHING }, 790 830 }; 791 831 … … 866 906 break; 867 907 908 case 'x': 909 fHexBytes = true; 910 break; 911 868 912 default: 869 913 RTStrmPrintf(g_pStdErr, "%s: syntax error: %Rrc\n", argv0, ch); … … 874 918 return Usage(argv0); 875 919 876 /* 877 * Process the files. 878 */ 920 879 921 int rc = VINF_SUCCESS; 880 for ( ; iArg < argc; iArg++)922 if (fHexBytes) 881 923 { 882 924 /* 883 * Read the file into memory. 925 * Convert the remaining arguments from a hex byte string into 926 * a buffer that we disassemble. 884 927 */ 885 void *pvFile; 886 size_t cbFile; 887 rc = RTFileReadAllEx(argv[iArg], off, cbMax, 0, &pvFile, &cbFile); 888 if (RT_FAILURE(rc)) 889 { 890 RTStrmPrintf(g_pStdErr, "%s: %s: %Rrc\n", argv0, argv[iArg], rc); 891 break; 928 size_t cb = 0; 929 uint8_t *pb = NULL; 930 for ( ; iArg < argc; iArg++) 931 { 932 const char *psz = argv[iArg]; 933 while (*psz) 934 { 935 /** @todo this stuff belongs in IPRT, same stuff as mac address reading. Could be reused for IPv6 with a different item size.*/ 936 /* skip white space */ 937 while (isspace(*psz)) 938 psz++; 939 if (!*psz) 940 break; 941 942 /* one digit followed by a space or EOS, or two digits. */ 943 int iNum = HexDigitToNum(*psz++); 944 if (iNum == -1) 945 return 1; 946 if (!isspace(*psz) && *psz) 947 { 948 int iDigit = HexDigitToNum(*psz++); 949 if (iDigit == -1) 950 return 1; 951 iNum = iNum * 16 + iDigit; 952 } 953 954 /* add the byte */ 955 if (!(cb % 4 /*64*/)) 956 { 957 pb = (uint8_t *)RTMemRealloc(pb, cb + 64); 958 if (!pb) 959 { 960 RTPrintf("%s: error: RTMemRealloc failed\n", argv[0]); 961 return 1; 962 } 963 } 964 pb[cb++] = (uint8_t)iNum; 965 } 892 966 } 893 967 … … 895 969 * Disassemble it. 896 970 */ 897 rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, enmUndefOp); 898 if (RT_FAILURE(rc)) 899 break; 971 rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, pb, cb, enmStyle, fListing, enmUndefOp); 972 } 973 else 974 { 975 /* 976 * Process the files. 977 */ 978 for ( ; iArg < argc; iArg++) 979 { 980 /* 981 * Read the file into memory. 982 */ 983 void *pvFile; 984 size_t cbFile; 985 rc = RTFileReadAllEx(argv[iArg], off, cbMax, 0, &pvFile, &cbFile); 986 if (RT_FAILURE(rc)) 987 { 988 RTStrmPrintf(g_pStdErr, "%s: %s: %Rrc\n", argv0, argv[iArg], rc); 989 break; 990 } 991 992 /* 993 * Disassemble it. 994 */ 995 rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, enmUndefOp); 996 if (RT_FAILURE(rc)) 997 break; 998 } 900 999 } 901 1000
Note:
See TracChangeset
for help on using the changeset viewer.