| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  | #ifndef RC_HASH_H
 | 
					
						
							|  |  |  | #define RC_HASH_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "rc_consoles.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* generates a hash from a block of memory.
 | 
					
						
							|  |  |  |    * returns non-zero on success, or zero on failure. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2022-01-07 15:21:37 +00:00
										 |  |  |   int rc_hash_generate_from_buffer(char hash[33], int console_id, const uint8_t* buffer, size_t buffer_size); | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* generates a hash from a file.
 | 
					
						
							|  |  |  |    * returns non-zero on success, or zero on failure. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   int rc_hash_generate_from_file(char hash[33], int console_id, const char* path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* data for rc_hash_iterate
 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   struct rc_hash_iterator | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     uint8_t* buffer; | 
					
						
							|  |  |  |     size_t buffer_size; | 
					
						
							|  |  |  |     uint8_t consoles[12]; | 
					
						
							|  |  |  |     int index; | 
					
						
							|  |  |  |     const char* path; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* initializes a rc_hash_iterator
 | 
					
						
							|  |  |  |    * - path must be provided | 
					
						
							|  |  |  |    * - if buffer and buffer_size are provided, path may be a filename (i.e. for something extracted from a zip file) | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void rc_hash_initialize_iterator(struct rc_hash_iterator* iterator, const char* path, uint8_t* buffer, size_t buffer_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* releases resources associated to a rc_hash_iterator
 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void rc_hash_destroy_iterator(struct rc_hash_iterator* iterator); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* generates the next hash for the data in the rc_hash_iterator.
 | 
					
						
							|  |  |  |    * returns non-zero if a hash was generated, or zero if no more hashes can be generated for the data. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   int rc_hash_iterate(char hash[33], struct rc_hash_iterator* iterator); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* specifies a function to call when an error occurs to display the error message */ | 
					
						
							|  |  |  |   typedef void (*rc_hash_message_callback)(const char*); | 
					
						
							|  |  |  |   void rc_hash_init_error_message_callback(rc_hash_message_callback callback); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* specifies a function to call for verbose logging */ | 
					
						
							|  |  |  |   void rc_hash_init_verbose_message_callback(rc_hash_message_callback callback); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* opens a file */ | 
					
						
							|  |  |  |   typedef void* (*rc_hash_filereader_open_file_handler)(const char* path_utf8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* moves the file pointer - standard fseek parameters */ | 
					
						
							| 
									
										
										
										
											2021-06-21 17:00:14 +00:00
										 |  |  |   typedef void (*rc_hash_filereader_seek_handler)(void* file_handle, int64_t offset, int origin); | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* locates the file pointer */ | 
					
						
							| 
									
										
										
										
											2021-06-21 17:00:14 +00:00
										 |  |  |   typedef int64_t (*rc_hash_filereader_tell_handler)(void* file_handle); | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* reads the specified number of bytes from the file starting at the read pointer.
 | 
					
						
							|  |  |  |    * returns the number of bytes actually read. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   typedef size_t (*rc_hash_filereader_read_handler)(void* file_handle, void* buffer, size_t requested_bytes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* closes the file */ | 
					
						
							|  |  |  |   typedef void (*rc_hash_filereader_close_file_handler)(void* file_handle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   struct rc_hash_filereader | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     rc_hash_filereader_open_file_handler      open; | 
					
						
							|  |  |  |     rc_hash_filereader_seek_handler           seek; | 
					
						
							|  |  |  |     rc_hash_filereader_tell_handler           tell; | 
					
						
							|  |  |  |     rc_hash_filereader_read_handler           read; | 
					
						
							|  |  |  |     rc_hash_filereader_close_file_handler     close; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void rc_hash_init_custom_filereader(struct rc_hash_filereader* reader); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   #define RC_HASH_CDTRACK_FIRST_DATA ((uint32_t)-1)
 | 
					
						
							|  |  |  |   #define RC_HASH_CDTRACK_LAST ((uint32_t)-2)
 | 
					
						
							|  |  |  |   #define RC_HASH_CDTRACK_LARGEST ((uint32_t)-3)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* opens a track from the specified file. track 0 indicates the largest data track should be opened.
 | 
					
						
							|  |  |  |    * returns a handle to be passed to the other functions, or NULL if the track could not be opened. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   typedef void* (*rc_hash_cdreader_open_track_handler)(const char* path, uint32_t track); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-26 15:01:32 +00:00
										 |  |  |   /* attempts to read the specified number of bytes from the file starting at the specified absolute sector.
 | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  |    * returns the number of bytes actually read. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   typedef size_t (*rc_hash_cdreader_read_sector_handler)(void* track_handle, uint32_t sector, void* buffer, size_t requested_bytes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* closes the track handle */ | 
					
						
							|  |  |  |   typedef void (*rc_hash_cdreader_close_track_handler)(void* track_handle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-26 15:01:32 +00:00
										 |  |  |   /* gets the absolute sector index for the first sector of a track */ | 
					
						
							|  |  |  |   typedef uint32_t(*rc_hash_cdreader_first_track_sector_handler)(void* track_handle); | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   struct rc_hash_cdreader | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     rc_hash_cdreader_open_track_handler              open_track; | 
					
						
							|  |  |  |     rc_hash_cdreader_read_sector_handler             read_sector; | 
					
						
							|  |  |  |     rc_hash_cdreader_close_track_handler             close_track; | 
					
						
							| 
									
										
										
										
											2022-03-26 15:01:32 +00:00
										 |  |  |     rc_hash_cdreader_first_track_sector_handler      first_track_sector; | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-26 15:01:32 +00:00
										 |  |  |   void rc_hash_get_default_cdreader(struct rc_hash_cdreader* cdreader); | 
					
						
							| 
									
										
										
										
											2022-01-07 15:21:37 +00:00
										 |  |  |   void rc_hash_init_default_cdreader(void); | 
					
						
							| 
									
										
										
										
											2021-02-21 06:58:40 +00:00
										 |  |  |   void rc_hash_init_custom_cdreader(struct rc_hash_cdreader* reader); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ===================================================== */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* RC_HASH_H */
 |