int main(int argc, const char* argv[]) { if (argc != 2 ) { fprintf( stderr, "Usage: crc32 <filename>\n" ); return 1; } FILE *file = fopen(argv[1], "rb"); if (file) { uint32_t crc = encoding_crc32(0L, NULL, 0 ); for (;;) { uint8_t buffer[16384]; int numread = fread((void*)buffer, 1, sizeof(buffer), file); if (numread > 0) crc = encoding_crc32( crc, buffer, numread ); else break; } fclose(file); printf("%08x\n", crc); return 0; } fprintf(stderr, "Error opening input file: %s\n", strerror(errno)); return 1; }
static bool chd_get_crc(database_state_handle_t *db_state, const char *name, uint32_t *crc) { intfstream_t *fd = NULL; uint32_t acc = 0; uint8_t buffer[4096]; ssize_t size; fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA); if (!fd) { return 0; } while ((size = intfstream_read(fd, buffer, sizeof(buffer))) > 0) { acc = encoding_crc32(acc, buffer, size); } if (size < 0) { return 0; } RARCH_LOG("CHD '%s' crc: %x\n", name, acc); *crc = acc; return 1; }
/** * load_content_into_memory: * @path : buffer of the content file. * @buf : size of the content file. * @length : size of the content file that has been read from. * * Read the content file. If read into memory, also performs soft patching * (see patch_content function) in case soft patching has not been * blocked by the enduser. * * Returns: true if successful, false on error. **/ static bool load_content_into_memory(unsigned i, const char *path, void **buf, ssize_t *length) { uint32_t *content_crc_ptr = NULL; uint8_t *ret_buf = NULL; RARCH_LOG("%s: %s.\n", msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path); if (!content_file_read(path, (void**) &ret_buf, length)) return false; if (*length < 0) return false; if (i == 0) { /* First content file is significant, attempt to do patching, * CRC checking, etc. */ /* Attempt to apply a patch. */ if (!rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL)) patch_content(&ret_buf, length); content_get_crc(&content_crc_ptr); *content_crc_ptr = encoding_crc32(0, ret_buf, *length); RARCH_LOG("CRC32: 0x%x .\n", (unsigned)*content_crc_ptr); } *buf = ret_buf; return true; }
static bool file_get_crc(database_state_handle_t *db_state, const char *name, uint32_t *crc) { ssize_t ret; int read_from = filestream_read_file( name, (void**)&db_state->buf, &ret); if (read_from != 1 || ret <= 0) return 0; *crc = encoding_crc32(0, db_state->buf, ret); return 1; }
static int intfstream_get_crc(intfstream_t *fd, uint32_t *crc) { int64_t read = 0; uint32_t acc = 0; uint8_t buffer[4096]; while ((read = intfstream_read(fd, buffer, sizeof(buffer))) > 0) acc = encoding_crc32(acc, buffer, (size_t)read); if (read < 0) return 0; *crc = acc; return 1; }
static uint32_t zlib_stream_crc32_calculate(uint32_t crc, const uint8_t *data, size_t length) { return encoding_crc32(crc, data, length); }
uint32_t netplay_delta_frame_crc(netplay_t *netplay, struct delta_frame *delta) { if (!netplay->state_size) return 0; return encoding_crc32(0L, (const unsigned char*)delta->state, netplay->state_size); }