-
Notifications
You must be signed in to change notification settings - Fork 124
Updated Analytics Windows to allow multiple DLL hashes, and add usage of Options struct. #1744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonsimantov
merged 22 commits into
analytics-dll-secure
from
analytics_windows_dll_updated
Jun 25, 2025
Merged
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
81045a0
Update script and code to handle known hashes for multiple DLLs.
jonsimantov 2a2bc2b
Fixed issues on Windows with multi-dll-hash code.
jonsimantov 9171093
Fix: Link Crypt32.lib for firebase_analytics on Windows
google-labs-jules[bot] e75fb8c
Fix: Link Crypt32.lib for firebase_analytics_test on Windows
google-labs-jules[bot] d806c1f
Update DLL.
jonsimantov 0911aec
Merge branch 'analytics-dll-secure-multihash' into fix/analytics-dll-…
jonsimantov 867937e
Merge branch 'fix/analytics-dll-hash-sizeof' of https://github.com/fi…
jonsimantov 60199f3
Remove unused file.
jonsimantov 7936e99
Remove extra file.
jonsimantov fc5aa8e
Initialize Analytics C SDK with AppOptions on desktop
google-labs-jules[bot] cfa4385
Update stub generation.
jonsimantov ab86de9
Merge branch 'analytics_windows_dll_updated' into feat/desktop-analyt…
jonsimantov e3e8a08
Format code.
jonsimantov 9a65e98
Fix build issues.
jonsimantov fcd9aaa
Update Analytics to use new options struct. (#1745)
jonsimantov 421ce66
Format code.
jonsimantov 764619b
Only display Analytics warnings if we are not in stub mode.
jonsimantov 72affd7
Merge branch 'feat/desktop-analytics-init-options' into analytics_win…
jonsimantov 1e23573
Format code.
jonsimantov 377a83c
Address review comments and add missing copyright notices.
jonsimantov 44816bb
Remove extraneous commented out code.
jonsimantov f5fb8d2
Add another known hash to the list.
jonsimantov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,36 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
initialized pointers, and a dynamic loading function for Windows. | ||
|
||
Args: | ||
header_file_path (str): The path to the DLL file. | ||
dll_file_path (str): The path to the DLL file. | ||
header_file_path (str): The path to the input C header file. | ||
output_h_path (str): The path for the generated C header output file. | ||
output_c_path (str): The path for the generated C source output file. | ||
""" | ||
print(f"Reading DLL file: {dll_file_path}") | ||
dll_hash = hash_file(dll_file_path) | ||
dll_hash = hash_file(dll_file_path) # This is binary | ||
|
||
# --- Manage known hashes --- | ||
hash_file_path = os.path.join(os.path.dirname(dll_file_path), "known_dll_hashes.txt") | ||
known_hex_hashes = [] | ||
try: | ||
with open(hash_file_path, 'r') as f: | ||
for line in f: | ||
known_hex_hashes.append(line.strip()) | ||
except FileNotFoundError: | ||
print(f"Info: '{hash_file_path}' not found, will be created.") | ||
pass # File doesn't exist, list remains empty | ||
|
||
current_dll_hex_hash = dll_hash.hex() | ||
if current_dll_hex_hash not in known_hex_hashes: | ||
known_hex_hashes.append(current_dll_hex_hash) | ||
# Sort for consistency, although not strictly required by the prompt | ||
jonsimantov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# known_hex_hashes.sort() # Decided against sorting to maintain order of addition for now | ||
|
||
with open(hash_file_path, 'w') as f: | ||
for hex_hash in known_hex_hashes: | ||
f.write(hex_hash + '\n') | ||
print(f"Updated known hashes in: {hash_file_path}") | ||
# --- End of manage known hashes --- | ||
|
||
print(f"Reading header file: {header_file_path}") | ||
try: | ||
|
@@ -77,7 +100,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
includes = re.findall(r"#include\s+<.*?>", header_content) | ||
|
||
# Find all typedefs, including their documentation comments | ||
typedefs = re.findall(r"/\*\*(?:[\s\S]*?)\*/\s*typedef[\s\S]*?;\s*", header_content) | ||
typedefs = re.findall(r"(?:/\*\*(?:[\s\S]*?)\*/\s*)?typedef[\s\S]*?;\s*", header_content) | ||
|
||
# --- Extract function prototypes --- | ||
function_pattern = re.compile( | ||
|
@@ -104,7 +127,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
if "void" in return_type: | ||
return_statement = " // No return value." | ||
elif "*" in return_type: | ||
return_statement = f' return ({return_type})(&g_stub_memory);' | ||
return_statement = f' return ({return_type})(&g_stub_memory[0]);' | ||
else: # bool, int64_t, etc. | ||
return_statement = " return 1;" | ||
|
||
|
@@ -136,6 +159,7 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
f.write(f"// Generated from {os.path.basename(header_file_path)} by {os.path.basename(sys.argv[0])}\n\n") | ||
f.write(f"#ifndef {header_guard}\n") | ||
f.write(f"#define {header_guard}\n\n") | ||
f.write(f"#define ANALYTICS_API // filter out from header copy\n\n") | ||
f.write("#include <stdbool.h> // needed for bool type in pure C\n\n") | ||
|
||
f.write("// --- Copied from original header ---\n") | ||
|
@@ -157,8 +181,10 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
f.write("\n// --- Dynamic Loader Declaration for Windows ---\n") | ||
f.write("#if defined(_WIN32)\n\n") | ||
f.write('#include <windows.h>\n') | ||
f.write(f'\n// Google Analytics Windows DLL SHA256 hash, to be verified before loading.') | ||
f.write(f'\nextern const unsigned char FirebaseAnalytics_WindowsDllHash[{len(dll_hash)}];\n\n'); | ||
f.write('\n// Array of known Google Analytics Windows DLL SHA256 hashes (hex strings).\n') | ||
f.write('extern const char* FirebaseAnalytics_KnownWindowsDllHashes[];\n') | ||
f.write('// Count of known Google Analytics Windows DLL SHA256 hashes.\n') | ||
f.write('extern const int FirebaseAnalytics_KnownWindowsDllHashCount;\n\n') | ||
f.write('// Load Analytics functions from the given DLL handle into function pointers.\n') | ||
f.write(f'// Returns the number of functions successfully loaded.\n') | ||
f.write("int FirebaseAnalytics_LoadDynamicFunctions(HMODULE dll_handle);\n\n") | ||
|
@@ -178,15 +204,30 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
f.write(f"// Generated from {os.path.basename(header_file_path)} by {os.path.basename(sys.argv[0])}\n\n") | ||
f.write(f'#include "{INCLUDE_PREFIX}{os.path.basename(output_h_path)}"\n\n') | ||
f.write('#include <stddef.h>\n\n') | ||
f.write("static void* g_stub_memory = NULL;\n\n") | ||
f.write("// A nice big chunk of stub memory that can be returned by stubbed Create methods.\n") | ||
f.write("static char g_stub_memory[256] = {0};\n\n") | ||
f.write("// clang-format off\n") | ||
f.write(f'\n// Number of Google Analytics functions expected to be loaded from the DLL.') | ||
f.write(f'\nconst int FirebaseAnalytics_DynamicFunctionCount = {len(function_details_for_loader)};\n\n'); | ||
# f.write("#if defined(_WIN32)\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
# f.write('// Google Analytics Windows DLL SHA256 hash, to be verified before loading.\n') | ||
# f.write('const unsigned char FirebaseAnalytics_WindowsDllHash[] = {\n ') | ||
# f.write(', '.join(["0x%02x" % s for s in dll_hash])) | ||
# f.write('\n};\n') | ||
# f.write("#endif // defined(_WIN32)\n") | ||
|
||
f.write("#if defined(_WIN32)\n") | ||
f.write('// Google Analytics Windows DLL SHA256 hash, to be verified before loading.\n') | ||
f.write('const unsigned char FirebaseAnalytics_WindowsDllHash[] = {\n ') | ||
f.write(', '.join(["0x%02x" % s for s in dll_hash])) | ||
f.write('\n};\n') | ||
f.write('// Array of known Google Analytics Windows DLL SHA256 hashes (hex strings).\n') | ||
f.write('const char* FirebaseAnalytics_KnownWindowsDllHashes[] = {\n') | ||
if known_hex_hashes: | ||
for i, hex_hash in enumerate(known_hex_hashes): | ||
f.write(f' "{hex_hash}"') | ||
if i < len(known_hex_hashes) - 1: | ||
f.write(',') | ||
f.write('\n') | ||
f.write('};\n\n') | ||
f.write('// Count of known Google Analytics Windows DLL SHA256 hashes.\n') | ||
f.write(f'const int FirebaseAnalytics_KnownWindowsDllHashCount = {len(known_hex_hashes)};\n') | ||
f.write("#endif // defined(_WIN32)\n") | ||
f.write("\n// --- Stub Function Definitions ---\n") | ||
f.write("\n\n".join(stub_functions)) | ||
|
@@ -231,25 +272,21 @@ def generate_function_pointers(dll_file_path, header_file_path, output_h_path, o | |
parser.add_argument( | ||
"--windows_dll", | ||
default = os.path.join(os.path.dirname(sys.argv[0]), "windows/analytics_win.dll"), | ||
#required=True, | ||
help="Path to the DLL file to calculate a hash." | ||
) | ||
parser.add_argument( | ||
"--windows_header", | ||
default = os.path.join(os.path.dirname(sys.argv[0]), "windows/include/public/c/analytics.h"), | ||
#required=True, | ||
help="Path to the input C header file." | ||
) | ||
parser.add_argument( | ||
"--output_header", | ||
default = os.path.join(os.path.dirname(sys.argv[0]), INCLUDE_PATH, "analytics_desktop_dynamic.h"), | ||
#required=True, | ||
help="Path for the generated output header file." | ||
) | ||
parser.add_argument( | ||
"--output_source", | ||
default = os.path.join(os.path.dirname(sys.argv[0]), INCLUDE_PATH, "analytics_desktop_dynamic.c"), | ||
#required=True, | ||
help="Path for the generated output source file." | ||
) | ||
args = parser.parse_args() | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be PUBLIC? Looking over other cases, we usually try to make these private, though there might be a reason this one needs to be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try it and see what happens!