updater.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2017-2018 Hugh Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #define WINVER 0x0600
  18. #define _WIN32_WINDOWS 0x0600
  19. #define _WIN32_WINNT 0x0600
  20. #define WIN32_LEAN_AND_MEAN
  21. #define ZLIB_CONST
  22. #include <windows.h>
  23. #include <winhttp.h>
  24. #include <commctrl.h>
  25. #include <Wincrypt.h>
  26. #include <shlobj.h>
  27. #include <shellapi.h>
  28. #include <malloc.h>
  29. #include <stdlib.h>
  30. #include <tchar.h>
  31. #include <strsafe.h>
  32. #include <zlib.h>
  33. #include <ctype.h>
  34. #include <blake2.h>
  35. #include <string>
  36. #include "../win-update-helpers.hpp"
  37. #define BLAKE2_HASH_LENGTH 20
  38. #define BLAKE2_HASH_STR_LENGTH ((BLAKE2_HASH_LENGTH * 2) + 1)
  39. #if defined _M_IX86
  40. #pragma comment(linker, \
  41. "/manifestdependency:\"type='win32' " \
  42. "name='Microsoft.Windows.Common-Controls' " \
  43. "version='6.0.0.0' " \
  44. "processorArchitecture='x86' " \
  45. "publicKeyToken='6595b64144ccf1df' " \
  46. "language='*'\"")
  47. #elif defined _M_IA64
  48. #pragma comment(linker, \
  49. "/manifestdependency:\"type='win32' " \
  50. "name='Microsoft.Windows.Common-Controls' " \
  51. "version='6.0.0.0' " \
  52. "processorArchitecture='ia64' " \
  53. "publicKeyToken='6595b64144ccf1df' " \
  54. "language='*'\"")
  55. #elif defined _M_X64
  56. #pragma comment(linker, \
  57. "/manifestdependency:\"type='win32' " \
  58. "name='Microsoft.Windows.Common-Controls' " \
  59. "version='6.0.0.0' " \
  60. "processorArchitecture='amd64' " \
  61. "publicKeyToken='6595b64144ccf1df' " \
  62. "language='*'\"")
  63. #else
  64. #pragma comment(linker, \
  65. "/manifestdependency:\"type='win32' " \
  66. "name='Microsoft.Windows.Common-Controls' " \
  67. "version='6.0.0.0' processorArchitecture='*' " \
  68. "publicKeyToken='6595b64144ccf1df' " \
  69. "language='*'\"")
  70. #endif
  71. #include <util/windows/WinHandle.hpp>
  72. #include <jansson.h>
  73. #include "resource.h"
  74. bool HTTPGetFile(HINTERNET hConnect,
  75. const wchar_t *url,
  76. const wchar_t *outputPath,
  77. const wchar_t *extraHeaders,
  78. int * responseCode);
  79. bool HTTPPostData(const wchar_t *url,
  80. const BYTE * data,
  81. int dataLen,
  82. const wchar_t *extraHeaders,
  83. int * responseCode,
  84. std::string & response);
  85. void HashToString(const BYTE *in, wchar_t *out);
  86. void StringToHash(const wchar_t *in, BYTE *out);
  87. bool CalculateFileHash(const wchar_t *path, BYTE *hash);
  88. int ApplyPatch(LPCTSTR patchFile, LPCTSTR targetFile);
  89. extern HWND hwndMain;
  90. extern HCRYPTPROV hProvider;
  91. extern int totalFileSize;
  92. extern int completedFileSize;
  93. extern HANDLE cancelRequested;
  94. #pragma pack(push, r1, 1)
  95. typedef struct {
  96. BLOBHEADER blobheader;
  97. RSAPUBKEY rsapubkey;
  98. } PUBLICKEYHEADER;
  99. #pragma pack(pop, r1)
  100. void FreeWinHttpHandle(HINTERNET handle);
  101. using HttpHandle = CustomHandle<HINTERNET, FreeWinHttpHandle>;