Path: blob/main/misc/bdelta/files/patch-bpatch.cpp
18160 views
--- bpatch.cpp.orig 2013-01-30 20:16:01 UTC1+++ bpatch.cpp2@@ -7,6 +7,8 @@3#include "file.h"4#include "compatibility.h"56+#define FEFE7+8bool copy_bytes_to_file(FILE *infile, FILE *outfile, unsigned numleft) {9size_t numread;10do {11@@ -42,10 +44,17 @@ int main(int argc, char **argv) {12return 1;13}14unsigned short version = read_word(patchfile);15+#ifdef FEFE16+ if (version != 1 && version != 2) {17+ printf("unsupported patch version\n");18+ return 1;19+ }20+#else21if (version != 1) {22printf("unsupported patch version\n");23return 1;24}25+#endif26char intsize;27fread_fixed(patchfile, &intsize, 1);28if (intsize != 4) {29@@ -57,14 +66,32 @@ int main(int argc, char **argv) {3031unsigned nummatches = read_dword(patchfile);3233+#ifdef FEFE34+ long long * copyloc1 = new long long[nummatches + 1];35+ long long * copyloc2 = new long long[nummatches + 1];36+ unsigned * copynum = new unsigned[nummatches + 1];37+#else38unsigned * copyloc1 = new unsigned[nummatches + 1];39unsigned * copyloc2 = new unsigned[nummatches + 1];40unsigned * copynum = new unsigned[nummatches + 1];41+#endif4243for (unsigned i = 0; i < nummatches; ++i) {44+#ifdef FEFE45+ if (version==2) {46+ copyloc1[i] = read_varint(patchfile);47+ copyloc2[i] = read_varint(patchfile);48+ copynum[i] = read_varint(patchfile);49+ } else {50copyloc1[i] = read_dword(patchfile);51copyloc2[i] = read_dword(patchfile);52copynum[i] = read_dword(patchfile);53+ }54+#else55+ copyloc1[i] = read_dword(patchfile);56+ copyloc2[i] = read_dword(patchfile);57+ copynum[i] = read_dword(patchfile);58+#endif59size2 -= copyloc2[i] + copynum[i];60}61if (size2) {62@@ -77,16 +104,22 @@ int main(int argc, char **argv) {63FILE *outfile = fopen(argv[2], "wb");6465for (unsigned i = 0; i < nummatches; ++i) {66+// printf("%u/%u: copy %u bytes from patch file ofs %ld (dest ofs %u)\n",i,nummatches,copyloc2[i],ftell(patchfile),ftell(outfile));67if (!copy_bytes_to_file(patchfile, outfile, copyloc2[i])) {68printf("Error. patchfile is truncated\n");69return -1;70}7172- int copyloc = copyloc1[i];73+ long long copyloc = copyloc1[i];74fseek(ref, copyloc, SEEK_CUR);7576+ long curofs=ftell(ref);77+78+#ifdef FEFE79+// printf("%u/%u: (%d -> %u,%d -> %u,%u)\n",i,nummatches-1,copyloc,ftell(ref),copyloc2[i],ftell(outfile),copynum[i]);80+#endif81if (!copy_bytes_to_file(ref, outfile, copynum[i])) {82- printf("Error while copying from reference file\n");83+ printf("Error while copying from reference file (ofs %ld, %u bytes)\n", curofs, copynum[i]);84return -1;85}86}878889