updater.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, "/manifestdependency:\"type='win32' " \
  41. "name='Microsoft.Windows.Common-Controls' " \
  42. "version='6.0.0.0' " \
  43. "processorArchitecture='x86' " \
  44. "publicKeyToken='6595b64144ccf1df' " \
  45. "language='*'\"")
  46. #elif defined _M_IA64
  47. #pragma comment(linker, "/manifestdependency:\"type='win32' " \
  48. "name='Microsoft.Windows.Common-Controls' " \
  49. "version='6.0.0.0' " \
  50. "processorArchitecture='ia64' " \
  51. "publicKeyToken='6595b64144ccf1df' " \
  52. "language='*'\"")
  53. #elif defined _M_X64
  54. #pragma comment(linker, "/manifestdependency:\"type='win32' " \
  55. "name='Microsoft.Windows.Common-Controls' " \
  56. "version='6.0.0.0' " \
  57. "processorArchitecture='amd64' " \
  58. "publicKeyToken='6595b64144ccf1df' " \
  59. "language='*'\"")
  60. #else
  61. #pragma comment(linker, "/manifestdependency:\"type='win32' " \
  62. "name='Microsoft.Windows.Common-Controls' " \
  63. "version='6.0.0.0' processorArchitecture='*' " \
  64. "publicKeyToken='6595b64144ccf1df' " \
  65. "language='*'\"")
  66. #endif
  67. #include <util/windows/WinHandle.hpp>
  68. #include <jansson.h>
  69. #include "resource.h"
  70. bool HTTPGetFile(HINTERNET hConnect, const wchar_t *url,
  71. const wchar_t *outputPath, const wchar_t *extraHeaders,
  72. int *responseCode);
  73. bool HTTPPostData(const wchar_t *url, const BYTE *data, int dataLen,
  74. const wchar_t *extraHeaders, int *responseCode,
  75. std::string &response);
  76. void HashToString(const BYTE *in, wchar_t *out);
  77. void StringToHash(const wchar_t *in, BYTE *out);
  78. bool CalculateFileHash(const wchar_t *path, BYTE *hash);
  79. int ApplyPatch(LPCTSTR patchFile, LPCTSTR targetFile);
  80. extern HWND hwndMain;
  81. extern HCRYPTPROV hProvider;
  82. extern int totalFileSize;
  83. extern int completedFileSize;
  84. extern HANDLE cancelRequested;
  85. #pragma pack(push, r1, 1)
  86. typedef struct {
  87. BLOBHEADER blobheader;
  88. RSAPUBKEY rsapubkey;
  89. } PUBLICKEYHEADER;
  90. #pragma pack(pop, r1)
  91. void FreeWinHttpHandle(HINTERNET handle);
  92. using HttpHandle = CustomHandle<HINTERNET, FreeWinHttpHandle>;