@@ -82,6 +82,95 @@ int s2binlib_pattern_scan(const char* binary_name, const char* pattern, void** r
8282 */
8383int s2binlib_pattern_scan_va (const char * binary_name , const char * pattern , void * * result );
8484
85+ /**
86+ * Callback function type for pattern_scan_all functions
87+ *
88+ * @param index The index of the current match (0-based)
89+ * @param address The found address (VA or memory address depending on the function)
90+ * @param user_data User-provided data pointer
91+ * @return true to stop searching (found what you need), false to continue searching
92+ */
93+ typedef bool (* s2binlib_pattern_scan_callback )(size_t index , void * address , void * user_data );
94+
95+ /**
96+ * Find all occurrences of a pattern in a binary and return their virtual addresses
97+ *
98+ * Scans the binary for all occurrences of the specified byte pattern and calls
99+ * the callback function for each match found. The callback receives virtual addresses (VA).
100+ *
101+ * If the binary is not yet loaded, it will be loaded automatically.
102+ *
103+ * @param binary_name Name of the binary to scan
104+ * @param pattern Byte pattern with wildcards (e.g., "48 89 5C 24 ? 48 89 74")
105+ * @param callback Function pointer that will be called for each match
106+ * @param user_data User-provided pointer passed to each callback invocation
107+ *
108+ * @return 0 on success (at least one match found)
109+ * -1 if S2BinLib not initialized
110+ * -2 if invalid parameters
111+ * -3 if failed to load binary
112+ * -4 if pattern not found
113+ * -5 if internal error
114+ *
115+ * @note The callback should return true to stop searching, false to continue
116+ *
117+ * @example
118+ * bool my_callback(size_t index, void* address, void* user_data) {
119+ * printf("Match #%zu found at VA: %p\n", index, address);
120+ * int* count = (int*)user_data;
121+ * (*count)++;
122+ * return false; // Continue searching
123+ * }
124+ *
125+ * int count = 0;
126+ * int result = s2binlib_pattern_scan_all_va("server", "48 89 5C 24 ?", my_callback, &count);
127+ * if (result == 0) {
128+ * printf("Found %d matches\n", count);
129+ * }
130+ */
131+ int s2binlib_pattern_scan_all_va (const char * binary_name , const char * pattern ,
132+ s2binlib_pattern_scan_callback callback , void * user_data );
133+
134+ /**
135+ * Find all occurrences of a pattern in a binary and return their memory addresses
136+ *
137+ * Scans the binary for all occurrences of the specified byte pattern and calls
138+ * the callback function for each match found. The callback receives memory addresses
139+ * (adjusted with module base address).
140+ *
141+ * If the binary is not yet loaded, it will be loaded automatically.
142+ *
143+ * @param binary_name Name of the binary to scan
144+ * @param pattern Byte pattern with wildcards (e.g., "48 89 5C 24 ? 48 89 74")
145+ * @param callback Function pointer that will be called for each match
146+ * @param user_data User-provided pointer passed to each callback invocation
147+ *
148+ * @return 0 on success (at least one match found)
149+ * -1 if S2BinLib not initialized
150+ * -2 if invalid parameters
151+ * -3 if failed to load binary
152+ * -4 if pattern not found
153+ * -5 if internal error
154+ *
155+ * @note The callback should return true to stop searching, false to continue
156+ *
157+ * @example
158+ * bool my_callback(size_t index, void* address, void* user_data) {
159+ * printf("Match #%zu found at memory address: %p\n", index, address);
160+ * int* count = (int*)user_data;
161+ * (*count)++;
162+ * return false; // Continue searching
163+ * }
164+ *
165+ * int count = 0;
166+ * int result = s2binlib_pattern_scan_all("server", "48 89 5C 24 ?", my_callback, &count);
167+ * if (result == 0) {
168+ * printf("Found %d matches\n", count);
169+ * }
170+ */
171+ int s2binlib_pattern_scan_all (const char * binary_name , const char * pattern ,
172+ s2binlib_pattern_scan_callback callback , void * user_data );
173+
85174/**
86175 * Find a vtable by class name in the specified binary
87176 *
0 commit comments