Skip to content

Commit 016f569

Browse files
committed
Change file format and move the hash out of non-Windows platforms.
1 parent 57f2062 commit 016f569

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

analytics/generate_windows_stubs.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,15 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
152152
f.write("\n\n")
153153
f.write("\n".join(macro_definitions))
154154
f.write("\n// clang-format on\n")
155+
f.write(f'\n// Number of Google Analytics functions expected to be loaded from the DLL.')
156+
f.write('\nextern const int FirebaseAnalytics_DynamicFunctionCount;\n');
155157
f.write("\n// --- Dynamic Loader Declaration for Windows ---\n")
156-
f.write("#if defined(_WIN32)\n")
158+
f.write("#if defined(_WIN32)\n\n")
157159
f.write('#include <windows.h>\n')
158-
f.write(f'\n// Google Analytics Windows DLL SHA256 hash, to be verified on load.')
159-
f.write(f'\nextern const unsigned char FirebaseAnalytics_WindowsDllHash[{len(dll_hash)}];\n');
160-
161-
f.write(f'\n// Number of Google Analytics functions expected to be loaded from the DLL.')
162-
f.write(f'\n#define FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT {len(function_details_for_loader)}\n\n')
160+
f.write(f'\n// Google Analytics Windows DLL SHA256 hash, to be verified before loading.')
161+
f.write(f'\nextern const unsigned char FirebaseAnalytics_WindowsDllHash[{len(dll_hash)}];\n\n');
163162
f.write('// Load Analytics functions from the given DLL handle into function pointers.\n')
164-
f.write(f'// Returns the number of functions successfully loaded (out of\n// FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT).\n')
163+
f.write(f'// Returns the number of functions successfully loaded.\n')
165164
f.write("int FirebaseAnalytics_LoadDynamicFunctions(HMODULE dll_handle);\n\n")
166165
f.write('// Reset all function pointers back to stubs.\n')
167166
f.write("void FirebaseAnalytics_UnloadDynamicFunctions(void);\n\n")
@@ -180,12 +179,16 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
180179
f.write(f'#include "{INCLUDE_PREFIX}{os.path.basename(output_h_path)}"\n\n')
181180
f.write('#include <stddef.h>\n\n')
182181
f.write("static void* g_stub_memory = NULL;\n\n")
183-
f.write("// clang-format off\n\n")
184-
f.write('// Google Analytics Windows DLL SHA256 hash, to be verified on load.\n')
182+
f.write("// clang-format off\n")
183+
f.write(f'\n// Number of Google Analytics functions expected to be loaded from the DLL.')
184+
f.write(f'\nconst int FirebaseAnalytics_DynamicFunctionCount = {len(function_details_for_loader)};\n\n');
185+
f.write("#if defined(_WIN32)\n")
186+
f.write('// Google Analytics Windows DLL SHA256 hash, to be verified before loading.\n')
185187
f.write('const unsigned char FirebaseAnalytics_WindowsDllHash[] = {\n ')
186188
f.write(', '.join(["0x%02x" % s for s in dll_hash]))
187-
f.write('\n};\n\n')
188-
f.write("// --- Stub Function Definitions ---\n")
189+
f.write('\n};\n')
190+
f.write("#endif // defined(_WIN32)\n")
191+
f.write("\n// --- Stub Function Definitions ---\n")
189192
f.write("\n\n".join(stub_functions))
190193
f.write("\n\n\n// --- Function Pointer Initializations ---\n")
191194
f.write("\n".join(pointer_initializations))

analytics/src/analytics_desktop.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ void Initialize(const App& app) {
6969
if (g_analytics_module) {
7070
int num_loaded = FirebaseAnalytics_LoadDynamicFunctions(
7171
g_analytics_module); // Ensure g_analytics_module is used
72-
if (num_loaded < FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT) {
72+
if (num_loaded < FirebaseAnalytics_DynamicFunctionCount) {
7373
LogWarning(
7474
"Analytics: Failed to load functions from Google Analytics "
7575
"module (%d out of %d loaded), reverting to stubs.",
76-
num_loaded, FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT);
76+
num_loaded, FirebaseAnalytics_DynamicFunctionCount);
7777
FirebaseAnalytics_UnloadDynamicFunctions();
7878
FreeLibrary(g_analytics_module);
7979
g_analytics_module = 0;

analytics/src/analytics_desktop_dynamic.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ static void* g_stub_memory = NULL;
2222

2323
// clang-format off
2424

25+
// Number of Google Analytics functions expected to be loaded from the DLL.
26+
const int FirebaseAnalytics_DynamicFunctionCount = 19;
27+
28+
#if defined(_WIN32)
2529
// Google Analytics Windows DLL SHA256 hash, to be verified on load.
2630
const unsigned char FirebaseAnalytics_WindowsDllHash[] = {
2731
0xc1, 0xb9, 0xff, 0x6e, 0x91, 0x19, 0xc3, 0x0b, 0xbe, 0xb7, 0x47, 0x23, 0x26, 0xdc, 0xde, 0x41, 0x8f, 0x45, 0x68, 0x2e, 0x6b, 0x82, 0x2e, 0x25, 0xee, 0xd9, 0x22, 0xfe, 0x6e, 0x3c, 0xc6, 0x98
2832
};
33+
#endif // defined(_WIN32)
2934

3035
// --- Stub Function Definitions ---
3136
// Stub for GoogleAnalytics_Item_Create

analytics/src/analytics_desktop_dynamic.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,19 @@ extern void (*ptr_GoogleAnalytics_SetAnalyticsCollectionEnabled)(bool enabled);
112112
#define GoogleAnalytics_SetAnalyticsCollectionEnabled ptr_GoogleAnalytics_SetAnalyticsCollectionEnabled
113113
// clang-format on
114114

115+
// Number of Google Analytics functions expected to be loaded from the DLL.
116+
extern const int FirebaseAnalytics_DynamicFunctionCount;
117+
115118
// --- Dynamic Loader Declaration for Windows ---
116119
#if defined(_WIN32)
120+
117121
#include <windows.h>
118122

119-
// Google Analytics Windows DLL SHA256 hash, to be verified on load.
123+
// Google Analytics Windows DLL SHA256 hash, to be verified before loading.
120124
extern const unsigned char FirebaseAnalytics_WindowsDllHash[32];
121125

122-
// Number of Google Analytics functions expected to be loaded from the DLL.
123-
#define FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT 19
124-
125126
// Load Analytics functions from the given DLL handle into function pointers.
126-
// Returns the number of functions successfully loaded (out of
127-
// FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT).
127+
// Returns the number of functions successfully loaded.
128128
int FirebaseAnalytics_LoadDynamicFunctions(HMODULE dll_handle);
129129

130130
// Reset all function pointers back to stubs.

0 commit comments

Comments
 (0)