diff --git a/Source/build.cpp b/Source/build.cpp index 0490e0d0..cc15e245 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -8,6 +8,7 @@ #include "util.h" #include "fileform.h" #include "writer.h" +#include "crc32.h" #include @@ -2274,7 +2275,7 @@ int CEXEBuild::write_output(void) RET_UNLESS_OK( uninstall_generate() ); - int crc=0; + crc32_t crc=0; { string full_path = get_full_path(build_output_filename); @@ -2349,7 +2350,7 @@ int CEXEBuild::write_output(void) } if (!build_compress_whole) - fh.length_of_all_following_data=ihd.getlen()+build_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(int):0); + fh.length_of_all_following_data=ihd.getlen()+build_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(crc32_t):0); else fd_start=ftell(fp); @@ -2384,7 +2385,7 @@ int CEXEBuild::write_output(void) return PS_ERROR; } #ifdef NSIS_CONFIG_CRC_SUPPORT - crc_writer_sink crc_sink((unsigned long *) &crc); + crc_writer_sink crc_sink((crc32_t *) &crc); firstheader_writer w(&crc_sink); w.write(&fh); @@ -2455,7 +2456,7 @@ int CEXEBuild::write_output(void) if (db_opt_save) { int total_out_size_estimate= - m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(int):0); + m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(crc32_t):0); #ifdef _WIN32 int pc=MulDiv(db_opt_save,1000,db_opt_save+total_out_size_estimate); #else @@ -2564,7 +2565,7 @@ int CEXEBuild::write_output(void) unsigned fend = ftell(fp); - fh.length_of_all_following_data=ftell(fp)-fd_start+(build_crcchk?sizeof(int):0); + fh.length_of_all_following_data=ftell(fp)-fd_start+(build_crcchk?sizeof(crc32_t):0); INFO_MSG( "%10d / %d bytes\n", ftell(fp) - fd_start, @@ -2608,9 +2609,9 @@ int CEXEBuild::write_output(void) { total_usize+=sizeof(int); int rcrc = FIX_ENDIAN_INT32(crc); - if (fwrite(&rcrc,1,sizeof(int),fp) != sizeof(int)) + if (fwrite(&rcrc,1,sizeof(crc32_t),fp) != sizeof(crc32_t)) { - ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(int)); + ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(crc32_t)); fclose(fp); return PS_ERROR; } @@ -2693,7 +2694,7 @@ int CEXEBuild::uninstall_generate() if (err < 0) return PS_ERROR; } - int crc=0; + crc32_t crc=0; // Get offsets of icons to replace for uninstall // Also makes sure that the icons are there and in the right size. @@ -2763,7 +2764,7 @@ int CEXEBuild::uninstall_generate() #endif fh.siginfo=FH_SIG; fh.length_of_all_following_data= - uhd.getlen()+ubuild_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(int):0); + uhd.getlen()+ubuild_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(crc32_t):0); MMapBuf udata; @@ -2832,7 +2833,7 @@ int CEXEBuild::uninstall_generate() } firstheader *_fh=(firstheader *)udata.get(0, sizeof(firstheader)); - _fh->length_of_all_following_data=FIX_ENDIAN_INT32(udata.getlen()+(build_crcchk?sizeof(int):0)); + _fh->length_of_all_following_data=FIX_ENDIAN_INT32(udata.getlen()+(build_crcchk?sizeof(crc32_t):0)); udata.release(); } else diff --git a/Source/build.h b/Source/build.h index 2307ce57..5434935a 100644 --- a/Source/build.h +++ b/Source/build.h @@ -35,13 +35,6 @@ # include "Plugins.h" #endif //NSIS_CONFIG_PLUGIN_SUPPORT -#ifdef NSIS_CONFIG_CRC_SUPPORT -extern "C" -{ - unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len); -}; -#endif - #define PS_OK 0 #define PS_EOF 1 #define PS_ERROR 50 diff --git a/Source/crc32.c b/Source/crc32.c index 781c127e..eed0c883 100644 --- a/Source/crc32.c +++ b/Source/crc32.c @@ -1,20 +1,21 @@ #include "Platform.h" +#include "crc32.h" #include "exehead/config.h" #ifdef NSIS_CONFIG_CRC_SUPPORT // this is based on the (slow,small) CRC32 implementation from zlib. -unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len) +crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len) { - static unsigned long crc_table[256]; + static crc32_t crc_table[256]; if (!crc_table[1]) { - unsigned long c; + crc32_t c; int n, k; for (n = 0; n < 256; n++) { - c = (unsigned long)n; + c = (crc32_t)n; for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0); crc_table[n] = c; } diff --git a/Source/crc32.h b/Source/crc32.h new file mode 100644 index 00000000..d40a132a --- /dev/null +++ b/Source/crc32.h @@ -0,0 +1,13 @@ +#include "Platform.h" + +#ifndef ___CRC32__H___ +#define ___CRC32__H___ + +typedef UINT32 crc32_t; + +#ifdef __cplusplus +extern "C" +#endif +crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len); + +#endif//!___CRC32__H___ diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c index 739a636b..fd833ffb 100644 --- a/Source/exehead/fileform.c +++ b/Source/exehead/fileform.c @@ -6,6 +6,7 @@ #include "lang.h" #include "ui.h" #include "exec.h" +#include "../crc32.h" #ifdef NSIS_CONFIG_COMPRESSION_SUPPORT #ifdef NSIS_COMPRESS_USE_ZLIB @@ -95,8 +96,6 @@ BOOL CALLBACK verProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) static z_stream g_inflate_stream; #endif -extern unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len); - const char * NSISCALL loadHeaders(int cl_flags) { #ifdef NSIS_CONFIG_CRC_SUPPORT @@ -104,7 +103,7 @@ const char * NSISCALL loadHeaders(int cl_flags) HWND hwnd = 0; unsigned int verify_time = GetTickCount() + 1000; #endif - int crc = 0; + crc32_t crc = 0; int do_crc = 0; #endif//NSIS_CONFIG_CRC_SUPPORT int left; @@ -230,9 +229,9 @@ const char * NSISCALL loadHeaders(int cl_flags) #ifdef NSIS_CONFIG_CRC_SUPPORT if (do_crc) { - int fcrc; + crc32_t fcrc; SetSelfFilePointer(m_pos); - if (!ReadSelfFile(&fcrc, sizeof(int)) || crc != fcrc) + if (!ReadSelfFile(&fcrc, sizeof(crc32_t)) || crc != fcrc) return _LANG_INVALIDCRC; } #endif//NSIS_CONFIG_CRC_SUPPORT @@ -251,7 +250,7 @@ const char * NSISCALL loadHeaders(int cl_flags) } dbd_srcpos = SetSelfFilePointer(g_filehdrsize + sizeof(firstheader)); #ifdef NSIS_CONFIG_CRC_SUPPORT - dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data - ((h.flags & FH_FLAGS_NO_CRC) ? 0 : sizeof(int)); + dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data - ((h.flags & FH_FLAGS_NO_CRC) ? 0 : sizeof(crc32_t)); #else dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data; #endif//NSIS_CONFIG_CRC_SUPPORT diff --git a/Source/writer.cpp b/Source/writer.cpp index 491885ee..1ef240e9 100644 --- a/Source/writer.cpp +++ b/Source/writer.cpp @@ -64,7 +64,7 @@ void file_writer_sink::write_data(const void *data, const size_t size) } #ifdef NSIS_CONFIG_CRC_SUPPORT -extern "C" unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len); +#include "crc32.h" void crc_writer_sink::write_data(const void *data, const size_t size) { diff --git a/Source/writer.h b/Source/writer.h index 56ab7adc..f7caf8db 100644 --- a/Source/writer.h +++ b/Source/writer.h @@ -3,6 +3,7 @@ #include "exehead/config.h" #include "growbuf.h" +#include "crc32.h" #include class writer_sink { @@ -57,12 +58,12 @@ private: #ifdef NSIS_CONFIG_CRC_SUPPORT class crc_writer_sink : public writer_sink { public: - crc_writer_sink(unsigned long *crc) : m_crc(crc) {} + crc_writer_sink(crc32_t *crc) : m_crc(crc) {} virtual void write_data(const void *data, const size_t size); private: - unsigned long *m_crc; + crc32_t *m_crc; }; #endif