diff --git a/include/syscap_tool.h b/include/syscap_tool.h index 2d129877a8ee2528cdc66af4a9bdca51bd8b712b..8ec1899ac0d42cb2acda526296f77a29f3e0d683 100644 --- a/include/syscap_tool.h +++ b/include/syscap_tool.h @@ -18,6 +18,9 @@ #include "stdint.h" +#define TYPE_FILE (0U) +#define TYPE_STRING (1U) + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -35,7 +38,7 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.json */ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath); /* in: pcidFile, rpcidFile */ -int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile); +int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t type); int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uint32_t osArraySize, char **priSyscap, uint32_t *priSyscapLen); diff --git a/src/main.c b/src/main.c index 3b3c9d1b0f6d00c7612e4af58c28eccb322632c0..9cdd88bc8f172e91c1e143e6723ed95baa2094d8 100644 --- a/src/main.c +++ b/src/main.c @@ -29,7 +29,7 @@ printf("ERROR: [%s: %d] -> ", __FILE__, __LINE__); \ printf(__VA_ARGS__); \ } while (0) -#define SYSCAP_VERSION "1.0.1" +#define SYSCAP_VERSION "1.1.1" #define OUTPUT_VERSION_LEN 200 #define ENCODE 0 #define DECODE 1 @@ -130,7 +130,9 @@ int main(int argc, char **argv) case 0x115: // 0x115, -Pesi inputfile ret = EncodePcidscToString(inputfile, outputpath); break; case 0x60: // 0x60, -C PCID.txt RPCID.txt - ret = ComparePcidWithRpcidString(pcidfile, rpcidfile); break; + ret = ComparePcidWithRpcidString(pcidfile, rpcidfile, TYPE_FILE); break; + case 0x64: // 0x64, -sC "pcidstring" "rpcidstring" + ret = ComparePcidWithRpcidString(pcidfile, rpcidfile, TYPE_STRING); break; case 0x111: // 0x111, -Pei inputfile ret = CreatePCID(inputfile, outputpath); break; case 0x112: // 0x112, -Pdi inputfile @@ -168,7 +170,8 @@ void PrintHelp(void) printf("-h, --help\t: how to use\n"); printf("-R, --RPCID\t: encode or decode RPCID\n"); printf("-P, --PCID\t: encode or decode PCID\n"); - printf("-C, --compare\t: compare pcid with rpcid string format.\n"); + printf("-C, --compare\t: compare pcid with rpcid string format.\n\t" + "-s, --string : input string.\n"); printf("-e, --encode\t: encode to sc format.\n\t-s, --string : encode to string format.\n"); printf("-d, --decode\t: decode to json format.\n\t-s, --string : decode string format.\n"); printf("-i filepath, --input filepath\t: input file\n"); diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 54c7063bb7309cc9f4c1b922dffb137917dd89a8..fdfceb22d8799485d53eeca84bcd5981e0f501d9 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -647,7 +647,7 @@ SKIP_PRI_SYSCAP: return 0; } -int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile) +int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t type) { int32_t ret; int32_t versionFlag = 0; @@ -663,14 +663,21 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile) uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; - if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { - PRINT_ERR("Get pcid file context failed, input file : %s\n", pcidFile); - return -1; - } - - if (GetFileContext(rpcidFile, &rpcidContent, &rpcidContentLen)) { - PRINT_ERR("Get rpcid file context failed, input file : %s\n", rpcidFile); - free(pcidContent); + if (type == TYPE_FILE) { + if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { + PRINT_ERR("Get pcid file context failed, input file : %s\n", pcidFile); + return -1; + } + if (GetFileContext(rpcidFile, &rpcidContent, &rpcidContentLen)) { + PRINT_ERR("Get rpcid file context failed, input file : %s\n", rpcidFile); + free(pcidContent); + return -1; + } + } else if (type == TYPE_STRING) { + pcidContent = pcidFile; + rpcidContent = rpcidFile; + } else { + PRINT_ERR("Input file type error, type=%d\n", type); return -1; }