@@ -46,7 +46,7 @@ def hash_file(filename):
46
46
with open (filename , "rb" ) as file :
47
47
while chunk := file .read (4096 ):
48
48
sha256_hash .update (chunk )
49
- return sha256_hash .hexdigest ()
49
+ return sha256_hash .digest ()
50
50
51
51
def generate_function_pointers (dll_file_path , header_file_path , output_h_path , output_c_path ):
52
52
"""
@@ -62,7 +62,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
62
62
"""
63
63
print (f"Reading DLL file: { dll_file_path } " )
64
64
dll_hash = hash_file (dll_file_path )
65
-
65
+
66
66
print (f"Reading header file: { header_file_path } " )
67
67
try :
68
68
with open (header_file_path , 'r' , encoding = 'utf-8' ) as f :
@@ -96,7 +96,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
96
96
return_type = match .group (1 ).strip ()
97
97
function_name = match .group (2 ).strip ()
98
98
params_str = match .group (3 ).strip ()
99
-
99
+
100
100
cleaned_params_for_decl = re .sub (r'\s+' , ' ' , params_str ) if params_str else ""
101
101
stub_name = f"Stub_{ function_name } "
102
102
@@ -107,7 +107,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
107
107
return_statement = f' return ({ return_type } )(&g_stub_memory);'
108
108
else : # bool, int64_t, etc.
109
109
return_statement = " return 1;"
110
-
110
+
111
111
stub_function = (
112
112
f"// Stub for { function_name } \n "
113
113
f"static { return_type } { stub_name } ({ params_str } ) {{\n "
@@ -124,7 +124,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
124
124
125
125
pointer_init = f"{ return_type } (*ptr_{ function_name } )({ cleaned_params_for_decl } ) = &{ stub_name } ;"
126
126
pointer_initializations .append (pointer_init )
127
-
127
+
128
128
function_details_for_loader .append ((function_name , return_type , cleaned_params_for_decl ))
129
129
130
130
print (f"Found { len (pointer_initializations )} functions. Generating output files..." )
@@ -137,12 +137,12 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
137
137
f .write (f"#ifndef { header_guard } \n " )
138
138
f .write (f"#define { header_guard } \n \n " )
139
139
f .write ("#include <stdbool.h> // needed for bool type in pure C\n \n " )
140
-
140
+
141
141
f .write ("// --- Copied from original header ---\n " )
142
142
f .write ("\n " .join (includes ) + "\n \n " )
143
143
f .write ("" .join (typedefs ))
144
144
f .write ("// --- End of copied section ---\n \n " )
145
-
145
+
146
146
f .write ("#ifdef __cplusplus\n " )
147
147
f .write ('extern "C" {\n ' )
148
148
f .write ("#endif\n \n " )
@@ -156,7 +156,8 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
156
156
f .write ("#if defined(_WIN32)\n " )
157
157
f .write ('#include <windows.h> // For HMODULE\n ' )
158
158
f .write (f'\n // Google Analytics Windows DLL SHA256 hash, to be verified on load.' )
159
- f .write (f'\n #define FIREBASE_ANALYTICS_DYNAMIC_LIBRARY_HASH "{ dll_hash } "\n ' )
159
+ f .write (f'\n extern const unsigned char FirebaseAnalytics_WindowsDllHash[{ len (dll_hash )} ];\n ' );
160
+
160
161
f .write (f'\n // Number of Google Analytics functions expected to be loaded from the DLL.' )
161
162
f .write (f'\n #define FIREBASE_ANALYTICS_DYNAMIC_FUNCTION_COUNT { len (function_details_for_loader )} \n \n ' )
162
163
f .write ('// Load Google Analytics functions from the given DLL handle into function pointers.\n ' )
@@ -178,6 +179,10 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
178
179
f .write (f"// Generated from { os .path .basename (header_file_path )} by { os .path .basename (sys .argv [0 ])} \n \n " )
179
180
f .write (f'#include "{ INCLUDE_PREFIX } { os .path .basename (output_h_path )} "\n ' )
180
181
f .write ('#include <stddef.h>\n \n ' )
182
+ f .write ('// Google Analytics Windows DLL SHA256 hash, to be verified on load.\n ' )
183
+ f .write ('const unsigned char FirebaseAnalytics_WindowsDllHash[] = {' )
184
+ f .write (',' .join (["0x%02x" % s for s in dll_hash ]))
185
+ f .write ('};\n \n ' )
181
186
f .write ("// clang-format off\n \n " )
182
187
f .write ("static void* g_stub_memory = NULL;\n \n " )
183
188
f .write ("// --- Stub Function Definitions ---\n " )
@@ -245,10 +250,10 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o
245
250
help = "Path for the generated output source file."
246
251
)
247
252
args = parser .parse_args ()
248
-
253
+
249
254
generate_function_pointers (
250
255
args .windows_dll ,
251
- args .windows_header ,
252
- args .output_header ,
256
+ args .windows_header ,
257
+ args .output_header ,
253
258
args .output_source
254
259
)
0 commit comments