main.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "ApplyPatch.h"
  11. #include "CreatePatch.h"
  12. #include <stdio.h>
  13. #include <string.h>
  14. /*
  15. // Test from memory
  16. void main(void)
  17. {
  18. char source[256], destination[256];
  19. strcpy(source, "The quick red fox jumped over the lazy brown dog.");
  20. strcpy(destination, "A story: The quick red fox jumped over the lazy brown dog. The dog then ripped the fox's freaking head off.");
  21. char *patch;
  22. unsigned patchSize;
  23. if (CreatePatch(source, (unsigned int)strlen(source), destination, (unsigned int)strlen(destination), &patch, &patchSize)==false)
  24. {
  25. printf("CreatePatch failed!\n");
  26. }
  27. char *patchedSource;
  28. unsigned patchedSourceSize;
  29. if (ApplyPatch(source, (unsigned int)strlen(source), &patchedSource, &patchedSourceSize, patch, patchSize)==false)
  30. {
  31. printf("ApplyPatch failed!\n");
  32. }
  33. if (patchedSourceSize!=(unsigned int)strlen(destination))
  34. printf("Patched source file does not match length of destination\n");
  35. else if (memcmp(patchedSource, destination, patchedSourceSize)!=0)
  36. printf("Patched source does not match destination\n");
  37. else
  38. printf("Success!\n");
  39. }
  40. */
  41. // Test from files
  42. extern int TestPatchInMemory(int argc,char *argv[]);
  43. extern int TestDiffInMemory(int argc,char *argv[]);
  44. extern int DIFF_main(int argc,char *argv[]);
  45. extern int PATCH_main(int argc,char * argv[]);
  46. #include <conio.h>
  47. void main(void)
  48. {
  49. printf("(M)ine or (T)heirs?\n");
  50. if (getch()=='m')
  51. {
  52. char *argv[4];
  53. argv[1]="Descent1.dll.bak";
  54. argv[2]="Descent2.dll.bak";
  55. argv[3]="my_patch";
  56. if (TestDiffInMemory(4,argv)==0)
  57. {
  58. printf("TestDiffInMemory Failed.\n");
  59. return;
  60. }
  61. argv[1]="Descent1.dll.bak";
  62. argv[2]="Descent2_patched_my.dll.bak";
  63. argv[3]="my_patch";
  64. if (TestPatchInMemory(4, argv)==0)
  65. {
  66. printf("TestPatchInMemory Failed.\n");
  67. return;
  68. }
  69. printf("Success.\n");
  70. }
  71. else
  72. {
  73. char *argv[4];
  74. argv[1]="Descent1.dll.bak";
  75. argv[2]="Descent2.dll.bak";
  76. argv[3]="their_patch";
  77. DIFF_main(4,argv);
  78. argv[1]="Descent1.dll.bak";
  79. argv[2]="Descent2_patched.dll.bak";
  80. argv[3]="their_patch";
  81. PATCH_main(4, argv);
  82. printf("Success.\n");
  83. }
  84. }
粤ICP备19079148号