void test_diff_binary__delta_append(void) { git_index *index; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/untimely.txt b/untimely.txt\n" \ "index 9a69d960ae94b060f56c2a8702545e2bb1abb935..1111d4f11f4b35bf6759e0fb714fe09731ef0840 100644\n" \ "GIT binary patch\n" \ "delta 32\n" \ "nc%1vf+QYWt3zLL@hC)e3Vu?a>QDRl4f_G*?PG(-ZA}<#J$+QbW\n" \ "\n" \ "delta 7\n" \ "Oc%18D`@*{63ljhg(E~C7\n" \ "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; opts.id_abbrev = GIT_OID_HEXSZ; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); cl_git_append2file("renames/untimely.txt", "Oh that crazy Kipling!\r\n"); cl_git_pass(git_index_add_bypath(index, "untimely.txt")); cl_git_pass(git_index_write(index)); test_patch( "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13", NULL, &opts, expected); git_index_free(index); }
void test_diff_binary__add(void) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/binary.bin b/binary.bin\n" \ "new file mode 100644\n" \ "index 0000000000000000000000000000000000000000..bd474b2519cc15eab801ff851cc7d50f0dee49a1\n" \ "GIT binary patch\n" \ "literal 3\n" \ "Kc${Nk-~s>u4FC%O\n" "\n" \ "literal 0\n" \ "Hc$@<O00001\n" \ "\n"; opts.flags = GIT_DIFF_SHOW_BINARY; opts.id_abbrev = GIT_OID_HEXSZ; repo = cl_git_sandbox_init("diff_format_email"); test_patch( "873806f6f27e631eb0b23e4b56bea2bfac14a373", "897d3af16ca9e420cd071b1c4541bd2b91d04c8c", &opts, expected); }
void test_diff_binary__modify_normal(void) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/binary.bin b/binary.bin\n" \ "index bd474b2..9ac35ff 100644\n" \ "Binary files a/binary.bin and b/binary.bin differ\n"; repo = cl_git_sandbox_init("diff_format_email"); test_patch( "897d3af16ca9e420cd071b1c4541bd2b91d04c8c", "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts, expected); }
void test_diff_binary__add_normal(void) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/binary.bin b/binary.bin\n" \ "new file mode 100644\n" \ "index 0000000..bd474b2\n" \ "Binary files /dev/null and b/binary.bin differ\n"; repo = cl_git_sandbox_init("diff_format_email"); test_patch( "873806f6f27e631eb0b23e4b56bea2bfac14a373", "897d3af16ca9e420cd071b1c4541bd2b91d04c8c", &opts, expected); }
void test_diff_binary__delta(void) { git_index *index; git_buf contents = GIT_BUF_INIT; size_t i; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/songof7cities.txt b/songof7cities.txt\n" \ "index 4210ffd5c390b21dd5483375e75288dea9ede512..cc84ec183351c9944ed90a619ca08911924055b5 100644\n" \ "GIT binary patch\n" \ "delta 198\n" \ "zc$}LmI8{(0BqLQJI6p64AwNwaIJGP_Pa)Ye#M3o+qJ$<Jl;sX*mF<MGCYv&*L7AHu\n" \ "zGA1*^gt?gYVN82wTbPO_W)+x<&1+cP;HrPHR>PQ;Y(X&QMK*C5^Br3bjG4d=XI^5@\n" \ "JfH567LIG)KJdFSV\n" \ "\n" \ "delta 198\n" \ "zc$}LmI8{(0BqLQJI6p64AwNwaIJGP_Pr*5}Br~;mqJ$<Jl;sX*mF<MGCYv&*L7AHu\n" \ "zGA1*^gt?gYVN82wTbPO_W)+x<&1+cP;HrPHR>PQ;Y(X&QMK*C5^Br3bjG4d=XI^5@\n" \ "JfH567LIF3FM2!Fd\n" \ "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; opts.id_abbrev = GIT_OID_HEXSZ; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_futils_readbuffer(&contents, "renames/songof7cities.txt")); for (i = 0; i < contents.size - 6; i++) { if (strncmp(&contents.ptr[i], "Cities", 6) == 0) memcpy(&contents.ptr[i], "cITIES", 6); } cl_git_rewritefile("renames/songof7cities.txt", contents.ptr); cl_git_pass(git_index_add_bypath(index, "songof7cities.txt")); cl_git_pass(git_index_write(index)); test_patch( "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13", NULL, &opts, expected); git_index_free(index); git_buf_dispose(&contents); }
void test_diff_binary__modify(void) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; const char *expected = "diff --git a/binary.bin b/binary.bin\n" \ "index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \ "GIT binary patch\n" \ "literal 5\n" \ "Mc${NkU}WL~000&M4gdfE\n" \ "\n" \ "literal 3\n" \ "Kc${Nk-~s>u4FC%O\n" \ "\n"; opts.flags = GIT_DIFF_SHOW_BINARY; repo = cl_git_sandbox_init("diff_format_email"); test_patch( "897d3af16ca9e420cd071b1c4541bd2b91d04c8c", "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts, expected); }
int wiz_mmuhack(int mem_fd) { FILE *kallsyms_file; int uname_offset; unsigned int pagetable_offset; char kallsyms_line[128]; char uname_backup[16]; int *uname_backup_int = (int *)uname_backup; int test_value; int failure = 0; kallsyms_file = fopen("/proc/kallsyms", "rb"); if(kallsyms_file == NULL) { printf("Could not find /proc/kallsyms, trying /proc/ksyms.\n"); kallsyms_file = fopen("/proc/ksyms", "rb"); if(kallsyms_file == NULL) { printf("Could not find /proc/ksyms, exiting.\n"); return -1; } } while(1) { if(fgets(kallsyms_line, 128, kallsyms_file)) { if(!strncmp(kallsyms_line + 11, "sys_newuname", 12)) { uname_offset = strtoul(kallsyms_line, NULL, 16); break; } } else { fclose(kallsyms_file); printf("Could not find sys_newuname offset.\n"); return -1; } } fclose(kallsyms_file); uname_offset -= 0xC0000000; printf("got uname location %x\n", uname_offset); backup_uname(mem_fd, uname_offset, uname_backup); printf("uname backup: %x %x %x %x\n", uname_backup_int[0], uname_backup_int[1], uname_backup_int[2], uname_backup_int[3]); test_value = test_patch(mem_fd, uname_offset, 0xA3); printf("test 1: expected 0xA3, got %x\n", test_value); test_value = test_patch(mem_fd, uname_offset, 0xE9); printf("test 2: expected 0xE9, got %x\n", test_value); if(test_value == 0xE9) { pagetable_offset = get_pagetable_offset(mem_fd, uname_offset); printf("modifying pagetable at %x\n", pagetable_offset); if((pagetable_offset >= (1024 * 1024 * 64)) || (pagetable_offset == 0xE9)) { printf("Error: pagetable offset out of range.\n"); failure = -1; } else { hack_pagetable(mem_fd, pagetable_offset); drain_wb_flush_tlb(mem_fd, uname_offset); } } else { failure = -1; } restore_uname(mem_fd, uname_offset, uname_backup); return failure; }