You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.7 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <dlfcn.h>
  5. #include <string.h>
  6. /* function declaration */
  7. void print_str_bytes(const char []);
  8. int main() {
  9. void *lib;
  10. uint64_t (*get_ahash)(const char *);
  11. uint64_t (*get_dhash)(const char *);
  12. uint64_t (*get_phash)(const char *);
  13. static const char largePathStr[] = { 0x74,0x65,0x73,0x74,0x5F,0x69,0x6D,0x61,0x67,0x65,0x73,0x2F,0x73,0x61,0x6D,0x70,0x6C,0x65,0x5F,0x30,0x31,0x5F,0x6C,0x61,0x72,0x67,0x65,0x2E,0x6A,0x70,0x67,0x00 };
  14. //print_str_bytes(largePathStr);
  15. static const char mediumPathStr[] = { 0x74,0x65,0x73,0x74,0x5F,0x69,0x6D,0x61,0x67,0x65,0x73,0x2F,0x73,0x61,0x6D,0x70,0x6C,0x65,0x5F,0x30,0x31,0x5F,0x6D,0x65,0x64,0x69,0x75,0x6D,0x2E,0x6A,0x70,0x67,0x00 };
  16. //print_str_bytes(mediumPathStr);
  17. static const char smallPathStr[] = { 0x74,0x65,0x73,0x74,0x5F,0x69,0x6D,0x61,0x67,0x65,0x73,0x2F,0x73,0x61,0x6D,0x70,0x6C,0x65,0x5F,0x30,0x31,0x5F,0x73,0x6D,0x61,0x6C,0x6C,0x2E,0x6A,0x70,0x67,0x00 };
  18. //print_str_bytes(smallPathStr);
  19. const char *largePathPtr = &largePathStr[0];
  20. const char *mediumPathPtr = &mediumPathStr[0];
  21. const char *smallPathPtr = &smallPathStr[0];
  22. // Loading the external library
  23. lib = dlopen("./libpihash.so", RTLD_LAZY);
  24. //Registering the external functions
  25. *(void **)(&get_ahash) = dlsym(lib,"ext_get_ahash");
  26. *(void **)(&get_dhash) = dlsym(lib,"ext_get_dhash");
  27. *(void **)(&get_phash) = dlsym(lib,"ext_get_phash");
  28. uint64_t largeA = get_ahash(largePathPtr);
  29. uint64_t largeD = get_dhash(largePathPtr);
  30. uint64_t largeP = get_phash(largePathPtr);
  31. uint64_t mediumA = get_ahash(mediumPathPtr);
  32. uint64_t mediumD = get_dhash(mediumPathPtr);
  33. uint64_t mediumP = get_phash(mediumPathPtr);
  34. uint64_t smallA = get_ahash(smallPathPtr);
  35. uint64_t smallD = get_dhash(smallPathPtr);
  36. uint64_t smallP = get_phash(smallPathPtr);
  37. printf("Large_Test_AHash: %llu \n", largeA);
  38. printf("Large_Test_DHash: %llu \n", largeD);
  39. printf("Large_Test_PHash: %llu \n", largeP);
  40. printf("Medium_Test_AHash: %llu \n", mediumA);
  41. printf("Medium_Test_DHash: %llu \n", mediumD);
  42. printf("Medium_Test_PHash: %llu \n", mediumP);
  43. printf("Small_Test_AHash: %llu \n", smallA);
  44. printf("Small_Test_DHash: %llu \n", smallD);
  45. printf("Small_Test_PHash: %llu \n", smallP);
  46. if (lib != NULL ) dlclose(lib);
  47. return EXIT_SUCCESS;
  48. }
  49. void print_str_bytes(const char str[]) {
  50. int strLen = strlen(str);
  51. printf("Length: %u \n",strLen*2);
  52. char* strBuf = (char*) malloc(strLen);
  53. for(int i = 0; i <= strLen; i++) {
  54. int j = i * 2;
  55. printf("%c",str[i]);
  56. sprintf(&strBuf[j], "%02X", str[i]);
  57. }
  58. printf("\nBytes: %s \n" , strBuf);
  59. }