Guest User

Untitled

a guest
Jan 30th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. diff --git a/sha1_file.c b/sha1_file.c
  2. index e13bd2c..adc4018 100644
  3. --- a/sha1_file.c
  4. +++ b/sha1_file.c
  5. @@ -2744,20 +2744,75 @@ void *read_object_with_reference(const unsigned char *sha1,
  6. }
  7. }
  8.  
  9. +static int inc_ascii_buf(unsigned char * buf, unsigned long len);
  10. static void write_sha1_file_prepare(const void *buf, unsigned long len,
  11. const char *type, unsigned char *sha1,
  12. char *hdr, int *hdrlen)
  13. {
  14. git_SHA_CTX c;
  15. + git_SHA_CTX t;
  16.  
  17. /* Generate the header */
  18. *hdrlen = sprintf(hdr, "%s %lu", type, len)+1;
  19.  
  20. +
  21. + /* CHANGES
  22. + len - 11 to len -1 is the scratch zone.
  23. + this is where the desired hash is found.
  24. + */
  25. + /* first diff_len bytes of sha1sum must be 0.*/
  26. + unsigned long diff_len = 4;
  27. + unsigned long i = 0;
  28. + unsigned char* b2 = (char*) buf;
  29. +
  30. +
  31. /* Sha1.. */
  32. git_SHA1_Init(&c);
  33. git_SHA1_Update(&c, hdr, *hdrlen);
  34. - git_SHA1_Update(&c, buf, len);
  35. - git_SHA1_Final(sha1, &c);
  36. + git_SHA1_Update(&c, buf, len - 11);
  37. + t = c;
  38. + while (1) {
  39. + if (0==i%100) {
  40. + //printf("iter %d %s" , i, (char*) (buf + len - 11));
  41. + }
  42. + int j = 0;
  43. + unsigned char x = 0;
  44. + git_SHA1_Update(&c, buf + len - 11, 11);
  45. + git_SHA1_Final(sha1, &c);
  46. + for (; j < diff_len; j++) {
  47. + x = x | sha1[j];
  48. + }
  49. + if (0 == x) {
  50. + FILE *f = fopen("body_fixed.txt", "w");
  51. + fputs(buf, f);
  52. + fclose(f);
  53. + break;}
  54. + else {
  55. + // reset.
  56. + c = t;
  57. + // increment scratch buf.
  58. + if (1==inc_ascii_buf(b2 + len - 11, 10)) {
  59. + break; // failure.
  60. + }
  61. + }
  62. + i++;
  63. + }
  64. +}
  65. +
  66. +static int inc_ascii_buf(unsigned char * buf, unsigned long len) {
  67. + /* returns 1 = maxed out. */
  68. + unsigned char min = 48;
  69. + unsigned char max = 122;
  70. + int x;
  71. + for (x = 0; x < len; x++) {
  72. + if (buf[x] == max) {
  73. + buf[x] = min;
  74. + } else {
  75. + buf[x]++;
  76. + return 0;
  77. + }
  78. + }
  79. + return 1;
  80. }
  81.  
  82. /*
Advertisement
Add Comment
Please, Sign In to add comment