Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/sha1_file.c b/sha1_file.c
- index e13bd2c..adc4018 100644
- --- a/sha1_file.c
- +++ b/sha1_file.c
- @@ -2744,20 +2744,75 @@ void *read_object_with_reference(const unsigned char *sha1,
- }
- }
- +static int inc_ascii_buf(unsigned char * buf, unsigned long len);
- static void write_sha1_file_prepare(const void *buf, unsigned long len,
- const char *type, unsigned char *sha1,
- char *hdr, int *hdrlen)
- {
- git_SHA_CTX c;
- + git_SHA_CTX t;
- /* Generate the header */
- *hdrlen = sprintf(hdr, "%s %lu", type, len)+1;
- +
- + /* CHANGES
- + len - 11 to len -1 is the scratch zone.
- + this is where the desired hash is found.
- + */
- + /* first diff_len bytes of sha1sum must be 0.*/
- + unsigned long diff_len = 4;
- + unsigned long i = 0;
- + unsigned char* b2 = (char*) buf;
- +
- +
- /* Sha1.. */
- git_SHA1_Init(&c);
- git_SHA1_Update(&c, hdr, *hdrlen);
- - git_SHA1_Update(&c, buf, len);
- - git_SHA1_Final(sha1, &c);
- + git_SHA1_Update(&c, buf, len - 11);
- + t = c;
- + while (1) {
- + if (0==i%100) {
- + //printf("iter %d %s" , i, (char*) (buf + len - 11));
- + }
- + int j = 0;
- + unsigned char x = 0;
- + git_SHA1_Update(&c, buf + len - 11, 11);
- + git_SHA1_Final(sha1, &c);
- + for (; j < diff_len; j++) {
- + x = x | sha1[j];
- + }
- + if (0 == x) {
- + FILE *f = fopen("body_fixed.txt", "w");
- + fputs(buf, f);
- + fclose(f);
- + break;}
- + else {
- + // reset.
- + c = t;
- + // increment scratch buf.
- + if (1==inc_ascii_buf(b2 + len - 11, 10)) {
- + break; // failure.
- + }
- + }
- + i++;
- + }
- +}
- +
- +static int inc_ascii_buf(unsigned char * buf, unsigned long len) {
- + /* returns 1 = maxed out. */
- + unsigned char min = 48;
- + unsigned char max = 122;
- + int x;
- + for (x = 0; x < len; x++) {
- + if (buf[x] == max) {
- + buf[x] = min;
- + } else {
- + buf[x]++;
- + return 0;
- + }
- + }
- + return 1;
- }
- /*
Advertisement
Add Comment
Please, Sign In to add comment