duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

rc_hash.h (5360B)


      1 #ifndef RC_HASH_H
      2 #define RC_HASH_H
      3 
      4 #include <stddef.h>
      5 #include <stdio.h>
      6 #include <stdint.h>
      7 
      8 #include "rc_consoles.h"
      9 
     10 RC_BEGIN_C_DECLS
     11 
     12   /* ===================================================== */
     13 
     14   /* generates a hash from a block of memory.
     15    * returns non-zero on success, or zero on failure.
     16    */
     17   RC_EXPORT int RC_CCONV rc_hash_generate_from_buffer(char hash[33], uint32_t console_id, const uint8_t* buffer, size_t buffer_size);
     18 
     19   /* generates a hash from a file.
     20    * returns non-zero on success, or zero on failure.
     21    */
     22   RC_EXPORT int RC_CCONV rc_hash_generate_from_file(char hash[33], uint32_t console_id, const char* path);
     23 
     24   /* ===================================================== */
     25 
     26   /* data for rc_hash_iterate
     27    */
     28   typedef struct rc_hash_iterator
     29   {
     30     const uint8_t* buffer;
     31     size_t buffer_size;
     32     uint8_t consoles[12];
     33     int index;
     34     const char* path;
     35   } rc_hash_iterator_t;
     36 
     37   /* initializes a rc_hash_iterator
     38    * - path must be provided
     39    * - if buffer and buffer_size are provided, path may be a filename (i.e. for something extracted from a zip file)
     40    */
     41   RC_EXPORT void RC_CCONV rc_hash_initialize_iterator(struct rc_hash_iterator* iterator, const char* path, const uint8_t* buffer, size_t buffer_size);
     42 
     43   /* releases resources associated to a rc_hash_iterator
     44    */
     45   RC_EXPORT void RC_CCONV rc_hash_destroy_iterator(struct rc_hash_iterator* iterator);
     46 
     47   /* generates the next hash for the data in the rc_hash_iterator.
     48    * returns non-zero if a hash was generated, or zero if no more hashes can be generated for the data.
     49    */
     50   RC_EXPORT int RC_CCONV rc_hash_iterate(char hash[33], struct rc_hash_iterator* iterator);
     51 
     52   /* ===================================================== */
     53 
     54   /* specifies a function to call when an error occurs to display the error message */
     55   typedef void (RC_CCONV *rc_hash_message_callback)(const char*);
     56   RC_EXPORT void RC_CCONV rc_hash_init_error_message_callback(rc_hash_message_callback callback);
     57 
     58   /* specifies a function to call for verbose logging */
     59   RC_EXPORT void rc_hash_init_verbose_message_callback(rc_hash_message_callback callback);
     60 
     61   /* ===================================================== */
     62 
     63   /* opens a file */
     64   typedef void* (RC_CCONV *rc_hash_filereader_open_file_handler)(const char* path_utf8);
     65 
     66   /* moves the file pointer - standard fseek parameters */
     67   typedef void (RC_CCONV *rc_hash_filereader_seek_handler)(void* file_handle, int64_t offset, int origin);
     68 
     69   /* locates the file pointer */
     70   typedef int64_t (RC_CCONV *rc_hash_filereader_tell_handler)(void* file_handle);
     71 
     72   /* reads the specified number of bytes from the file starting at the read pointer.
     73    * returns the number of bytes actually read.
     74    */
     75   typedef size_t (RC_CCONV *rc_hash_filereader_read_handler)(void* file_handle, void* buffer, size_t requested_bytes);
     76 
     77   /* closes the file */
     78   typedef void (RC_CCONV *rc_hash_filereader_close_file_handler)(void* file_handle);
     79 
     80   struct rc_hash_filereader
     81   {
     82     rc_hash_filereader_open_file_handler      open;
     83     rc_hash_filereader_seek_handler           seek;
     84     rc_hash_filereader_tell_handler           tell;
     85     rc_hash_filereader_read_handler           read;
     86     rc_hash_filereader_close_file_handler     close;
     87   };
     88 
     89   RC_EXPORT void RC_CCONV rc_hash_init_custom_filereader(struct rc_hash_filereader* reader);
     90 
     91   /* ===================================================== */
     92 
     93   #define RC_HASH_CDTRACK_FIRST_DATA ((uint32_t)-1) /* the first data track (skip audio tracks) */
     94   #define RC_HASH_CDTRACK_LAST ((uint32_t)-2) /* the last data/audio track */
     95   #define RC_HASH_CDTRACK_LARGEST ((uint32_t)-3) /* the largest data/audio track */
     96   #define RC_HASH_CDTRACK_FIRST_OF_SECOND_SESSION ((uint32_t)-4) /* the first data/audio track of the second session */
     97 
     98   /* opens a track from the specified file. see the RC_HASH_CDTRACK_ defines for special tracks.
     99    * returns a handle to be passed to the other functions, or NULL if the track could not be opened.
    100    */
    101   typedef void* (RC_CCONV *rc_hash_cdreader_open_track_handler)(const char* path, uint32_t track);
    102 
    103   /* attempts to read the specified number of bytes from the file starting at the specified absolute sector.
    104    * returns the number of bytes actually read.
    105    */
    106   typedef size_t (RC_CCONV *rc_hash_cdreader_read_sector_handler)(void* track_handle, uint32_t sector, void* buffer, size_t requested_bytes);
    107 
    108   /* closes the track handle */
    109   typedef void (RC_CCONV *rc_hash_cdreader_close_track_handler)(void* track_handle);
    110 
    111   /* gets the absolute sector index for the first sector of a track */
    112   typedef uint32_t(RC_CCONV *rc_hash_cdreader_first_track_sector_handler)(void* track_handle);
    113 
    114   struct rc_hash_cdreader
    115   {
    116     rc_hash_cdreader_open_track_handler              open_track;
    117     rc_hash_cdreader_read_sector_handler             read_sector;
    118     rc_hash_cdreader_close_track_handler             close_track;
    119     rc_hash_cdreader_first_track_sector_handler      first_track_sector;
    120   };
    121 
    122   RC_EXPORT void RC_CCONV rc_hash_get_default_cdreader(struct rc_hash_cdreader* cdreader);
    123   RC_EXPORT void RC_CCONV rc_hash_init_default_cdreader(void);
    124   RC_EXPORT void RC_CCONV rc_hash_init_custom_cdreader(struct rc_hash_cdreader* reader);
    125 
    126   /* ===================================================== */
    127 
    128 RC_END_C_DECLS
    129 
    130 #endif /* RC_HASH_H */