Moved src/emu/hash.[cpp|h] into src/lib/util, and namespaced that code (and hashing.[cpp|h]) into util::

This commit is contained in:
Nathan Woods 2016-07-23 12:49:33 -04:00
parent 4423c242a6
commit 4aa0ab1724
27 changed files with 181 additions and 170 deletions

View File

@ -118,8 +118,6 @@ files {
MAME_DIR .. "src/emu/emupal.h", MAME_DIR .. "src/emu/emupal.h",
MAME_DIR .. "src/emu/fileio.cpp", MAME_DIR .. "src/emu/fileio.cpp",
MAME_DIR .. "src/emu/fileio.h", MAME_DIR .. "src/emu/fileio.h",
MAME_DIR .. "src/emu/hash.cpp",
MAME_DIR .. "src/emu/hash.h",
MAME_DIR .. "src/emu/image.cpp", MAME_DIR .. "src/emu/image.cpp",
MAME_DIR .. "src/emu/image.h", MAME_DIR .. "src/emu/image.h",
MAME_DIR .. "src/emu/input.cpp", MAME_DIR .. "src/emu/input.cpp",

View File

@ -56,6 +56,8 @@ project "utils"
MAME_DIR .. "src/lib/util/flac.h", MAME_DIR .. "src/lib/util/flac.h",
MAME_DIR .. "src/lib/util/harddisk.cpp", MAME_DIR .. "src/lib/util/harddisk.cpp",
MAME_DIR .. "src/lib/util/harddisk.h", MAME_DIR .. "src/lib/util/harddisk.h",
MAME_DIR .. "src/lib/util/hash.cpp",
MAME_DIR .. "src/lib/util/hash.h",
MAME_DIR .. "src/lib/util/hashing.cpp", MAME_DIR .. "src/lib/util/hashing.cpp",
MAME_DIR .. "src/lib/util/hashing.h", MAME_DIR .. "src/lib/util/hashing.h",
MAME_DIR .. "src/lib/util/huffman.cpp", MAME_DIR .. "src/lib/util/huffman.cpp",

View File

@ -22,7 +22,7 @@
even if not all carts use all of them (in particular no cart type even if not all carts use all of them (in particular no cart type
seems to use access to the ranges $0500 to $0fff and $2800 to $2fff) seems to use access to the ranges $0500 to $0fff and $2800 to $2fff)
***********************************************************************************************************/ ***********************************************************************************************************/
@ -473,7 +473,7 @@ bool a78_cart_slot_device::call_load()
} }
void a78_partialhash(hash_collection &dest, const unsigned char *data, void a78_partialhash(util::hash_collection &dest, const unsigned char *data,
unsigned long length, const char *functions) unsigned long length, const char *functions)
{ {
if (length <= 128) if (length <= 128)

View File

@ -75,7 +75,7 @@ protected:
}; };
void a78_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions); void a78_partialhash(util::hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
// ======================> a78_cart_slot_device // ======================> a78_cart_slot_device

View File

@ -1034,7 +1034,7 @@ WRITE8_MEMBER(nes_cart_slot_device::write_ex)
// device_image_partialhash_func // device_image_partialhash_func
//------------------------------------------------- //-------------------------------------------------
void nes_partialhash(hash_collection &dest, const unsigned char *data, void nes_partialhash(util::hash_collection &dest, const unsigned char *data,
unsigned long length, const char *functions) unsigned long length, const char *functions)
{ {
if (length <= 16) if (length <= 16)

View File

@ -326,7 +326,7 @@ protected:
std::vector<UINT16> m_prg_bank_map; std::vector<UINT16> m_prg_bank_map;
}; };
void nes_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions); void nes_partialhash(util::hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
// ======================> nes_cart_slot_device // ======================> nes_cart_slot_device

View File

@ -2599,11 +2599,11 @@ std::unique_ptr<rpk_socket> rpk_reader::load_rom_resource(util::archive_file &zi
sha1 = xml_get_attribute_string(rom_resource_node, "sha1", nullptr); sha1 = xml_get_attribute_string(rom_resource_node, "sha1", nullptr);
if (sha1 != nullptr) if (sha1 != nullptr)
{ {
hash_collection actual_hashes; util::hash_collection actual_hashes;
actual_hashes.compute((const UINT8 *)contents, length, hash_collection::HASH_TYPES_CRC_SHA1); actual_hashes.compute((const UINT8 *)contents, length, util::hash_collection::HASH_TYPES_CRC_SHA1);
hash_collection expected_hashes; util::hash_collection expected_hashes;
expected_hashes.add_from_string(hash_collection::HASH_SHA1, sha1, strlen(sha1)); expected_hashes.add_from_string(util::hash_collection::HASH_SHA1, sha1, strlen(sha1));
if (actual_hashes != expected_hashes) throw rpk_exception(RPK_INVALID_FILE_REF, "SHA1 check failed"); if (actual_hashes != expected_hashes) throw rpk_exception(RPK_INVALID_FILE_REF, "SHA1 check failed");
} }

View File

@ -168,7 +168,7 @@ iodevice_t device_image_interface::device_typeid(const char *name)
using this device's partial hash if appropriate using this device's partial hash if appropriate
-------------------------------------------------*/ -------------------------------------------------*/
void device_image_interface::device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const void device_image_interface::device_compute_hash(util::hash_collection &hashes, const void *data, size_t length, const char *types) const
{ {
/* retrieve the partial hash func */ /* retrieve the partial hash func */
device_image_partialhash_func partialhash = get_partial_hash(); device_image_partialhash_func partialhash = get_partial_hash();
@ -464,8 +464,8 @@ bool device_image_interface::load_software_region(const char *tag, optional_shar
// to be loaded // to be loaded
// **************************************************************************** // ****************************************************************************
void device_image_interface::run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), void device_image_interface::run_hash(void (*partialhash)(util::hash_collection &, const unsigned char *, unsigned long, const char *),
hash_collection &hashes, const char *types) util::hash_collection &hashes, const char *types)
{ {
UINT32 size; UINT32 size;
dynamic_buffer buf; dynamic_buffer buf;
@ -511,7 +511,7 @@ void device_image_interface::image_checkhash()
// retrieve the partial hash func // retrieve the partial hash func
partialhash = get_partial_hash(); partialhash = get_partial_hash();
run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL); run_hash(partialhash, m_hash, util::hash_collection::HASH_TYPES_ALL);
} }
return; return;
} }
@ -778,7 +778,7 @@ void device_image_interface::determine_open_plan(int is_create, UINT32 *open_pla
// correct checksums for a given software item // correct checksums for a given software item
//------------------------------------------------- //-------------------------------------------------
static void dump_wrong_and_correct_checksums(const hash_collection &hashes, const hash_collection &acthashes) static void dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes)
{ {
osd_printf_error(" EXPECTED: %s\n", hashes.macro_string().c_str()); osd_printf_error(" EXPECTED: %s\n", hashes.macro_string().c_str());
osd_printf_error(" FOUND: %s\n", acthashes.macro_string().c_str()); osd_printf_error(" FOUND: %s\n", acthashes.macro_string().c_str());
@ -790,7 +790,7 @@ static void dump_wrong_and_correct_checksums(const hash_collection &hashes, cons
// and hash signatures of a file // and hash signatures of a file
//------------------------------------------------- //-------------------------------------------------
static int verify_length_and_hash(emu_file *file, const char *name, UINT32 explength, const hash_collection &hashes) static int verify_length_and_hash(emu_file *file, const char *name, UINT32 explength, const util::hash_collection &hashes)
{ {
int retVal = 0; int retVal = 0;
if (file==nullptr) return 0; if (file==nullptr) return 0;
@ -804,8 +804,8 @@ static int verify_length_and_hash(emu_file *file, const char *name, UINT32 exple
} }
// If there is no good dump known, write it // If there is no good dump known, write it
hash_collection &acthashes = file->hashes(hashes.hash_types().c_str()); util::hash_collection &acthashes = file->hashes(hashes.hash_types().c_str());
if (hashes.flag(hash_collection::FLAG_NO_DUMP)) if (hashes.flag(util::hash_collection::FLAG_NO_DUMP))
{ {
osd_printf_error("%s NO GOOD DUMP KNOWN\n", name); osd_printf_error("%s NO GOOD DUMP KNOWN\n", name);
} }
@ -818,7 +818,7 @@ static int verify_length_and_hash(emu_file *file, const char *name, UINT32 exple
retVal++; retVal++;
} }
// If it matches, but it is actually a bad dump, write it // If it matches, but it is actually a bad dump, write it
else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) else if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP))
{ {
osd_printf_error("%s NEEDS REDUMP\n",name); osd_printf_error("%s NEEDS REDUMP\n",name);
} }
@ -848,7 +848,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
osd_file::error filerr = osd_file::error::NOT_FOUND; osd_file::error filerr = osd_file::error::NOT_FOUND;
UINT32 crc = 0; UINT32 crc = 0;
bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc); bool has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
const software_info *swinfo = swlist.find(swname); const software_info *swinfo = swlist.find(swname);
if (swinfo == nullptr) if (swinfo == nullptr)
@ -911,7 +911,7 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
if ((m_mame_file == nullptr) && (tag5.c_str() != nullptr)) if ((m_mame_file == nullptr) && (tag5.c_str() != nullptr))
m_mame_file = common_process_file(device().machine().options(), tag5.c_str(), has_crc, crc, romp, filerr); m_mame_file = common_process_file(device().machine().options(), tag5.c_str(), has_crc, crc, romp, filerr);
warningcount += verify_length_and_hash(m_mame_file.get(),ROM_GETNAME(romp),ROM_GETLENGTH(romp),hash_collection(ROM_GETHASHDATA(romp))); warningcount += verify_length_and_hash(m_mame_file.get(),ROM_GETNAME(romp),ROM_GETLENGTH(romp), util::hash_collection(ROM_GETHASHDATA(romp)));
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
filerr = util::core_file::open_proxy(*m_mame_file, m_file); filerr = util::core_file::open_proxy(*m_mame_file, m_file);

View File

@ -104,7 +104,7 @@ class software_info;
typedef delegate<int (device_image_interface &)> device_image_load_delegate; typedef delegate<int (device_image_interface &)> device_image_load_delegate;
typedef delegate<void (device_image_interface &)> device_image_func_delegate; typedef delegate<void (device_image_interface &)> device_image_func_delegate;
// legacy // legacy
typedef void (*device_image_partialhash_func)(hash_collection &, const unsigned char *, unsigned long, const char *); typedef void (*device_image_partialhash_func)(util::hash_collection &, const unsigned char *, unsigned long, const char *);
//************************************************************************** //**************************************************************************
// MACROS // MACROS
@ -147,7 +147,7 @@ public:
static const char *device_brieftypename(iodevice_t type); static const char *device_brieftypename(iodevice_t type);
static iodevice_t device_typeid(const char *name); static iodevice_t device_typeid(const char *name);
virtual void device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const; virtual void device_compute_hash(util::hash_collection &hashes, const void *data, size_t length, const char *types) const;
virtual bool call_load() { return FALSE; } virtual bool call_load() { return FALSE; }
virtual bool call_create(int format_type, util::option_resolution *format_options) { return FALSE; } virtual bool call_create(int format_type, util::option_resolution *format_options) { return FALSE; }
@ -215,7 +215,7 @@ public:
bool load_software_region(const char *tag, optional_shared_ptr<UINT8> &ptr); bool load_software_region(const char *tag, optional_shared_ptr<UINT8> &ptr);
UINT32 crc(); UINT32 crc();
hash_collection& hash() { return m_hash; } util::hash_collection& hash() { return m_hash; }
void battery_load(void *buffer, int length, int fill); void battery_load(void *buffer, int length, int fill);
void battery_load(void *buffer, int length, void *def_buffer); void battery_load(void *buffer, int length, void *def_buffer);
@ -266,7 +266,7 @@ protected:
void setup_working_directory(); void setup_working_directory();
bool try_change_working_directory(const char *subdir); bool try_change_working_directory(const char *subdir);
void run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), hash_collection &hashes, const char *types); void run_hash(void (*partialhash)(util::hash_collection &, const unsigned char *, unsigned long, const char *), util::hash_collection &hashes, const char *types);
void image_checkhash(); void image_checkhash();
void update_names(const device_type device_type = nullptr, const char *inst = nullptr, const char *brief = nullptr); void update_names(const device_type device_type = nullptr, const char *inst = nullptr, const char *brief = nullptr);
@ -317,7 +317,7 @@ protected:
int m_create_format; int m_create_format;
util::option_resolution *m_create_args; util::option_resolution *m_create_args;
hash_collection m_hash; util::hash_collection m_hash;
std::string m_brief_instance_name; std::string m_brief_instance_name;
std::string m_instance_name; std::string m_instance_name;

View File

@ -197,7 +197,7 @@ emu_file::operator util::core_file &()
// hash - returns the hash for a file // hash - returns the hash for a file
//------------------------------------------------- //-------------------------------------------------
hash_collection &emu_file::hashes(const char *types) util::hash_collection &emu_file::hashes(const char *types)
{ {
// determine the hashes we already have // determine the hashes we already have
std::string already_have = m_hashes.hash_types(); std::string already_have = m_hashes.hash_types();

View File

@ -91,7 +91,7 @@ public:
const char *filename() const { return m_filename.c_str(); } const char *filename() const { return m_filename.c_str(); }
const char *fullpath() const { return m_fullpath.c_str(); } const char *fullpath() const { return m_fullpath.c_str(); }
UINT32 openflags() const { return m_openflags; } UINT32 openflags() const { return m_openflags; }
hash_collection &hashes(const char *types); util::hash_collection &hashes(const char *types);
bool restrict_to_mediapath() const { return m_restrict_to_mediapath; } bool restrict_to_mediapath() const { return m_restrict_to_mediapath; }
bool part_of_mediapath(std::string path); bool part_of_mediapath(std::string path);
@ -155,7 +155,7 @@ private:
path_iterator m_mediapaths; // media-path iterator path_iterator m_mediapaths; // media-path iterator
UINT32 m_crc; // file's CRC UINT32 m_crc; // file's CRC
UINT32 m_openflags; // flags we used for the open UINT32 m_openflags; // flags we used for the open
hash_collection m_hashes; // collection of hashes util::hash_collection m_hashes; // collection of hashes
std::unique_ptr<util::archive_file> m_zipfile; // ZIP file pointer std::unique_ptr<util::archive_file> m_zipfile; // ZIP file pointer
dynamic_buffer m_zipdata; // ZIP file data dynamic_buffer m_zipdata; // ZIP file data

View File

@ -380,7 +380,7 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, std::string tr
} }
/* no good dumps are okay */ /* no good dumps are okay */
else if (hash_collection(ROM_GETHASHDATA(romp)).flag(hash_collection::FLAG_NO_DUMP)) else if (util::hash_collection(ROM_GETHASHDATA(romp)).flag(util::hash_collection::FLAG_NO_DUMP))
{ {
if (!is_chd_error) if (!is_chd_error)
m_errorstring.append(string_format("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name, tried_file_names)); m_errorstring.append(string_format("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name, tried_file_names));
@ -403,7 +403,7 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, std::string tr
correct checksums for a given ROM correct checksums for a given ROM
-------------------------------------------------*/ -------------------------------------------------*/
void rom_load_manager::dump_wrong_and_correct_checksums(const hash_collection &hashes, const hash_collection &acthashes) void rom_load_manager::dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes)
{ {
m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string().c_str())); m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string().c_str()));
m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string().c_str())); m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string().c_str()));
@ -415,7 +415,7 @@ void rom_load_manager::dump_wrong_and_correct_checksums(const hash_collection &h
and hash signatures of a file and hash signatures of a file
-------------------------------------------------*/ -------------------------------------------------*/
void rom_load_manager::verify_length_and_hash(const char *name, UINT32 explength, const hash_collection &hashes) void rom_load_manager::verify_length_and_hash(const char *name, UINT32 explength, const util::hash_collection &hashes)
{ {
/* we've already complained if there is no file */ /* we've already complained if there is no file */
if (m_file == nullptr) if (m_file == nullptr)
@ -430,8 +430,8 @@ void rom_load_manager::verify_length_and_hash(const char *name, UINT32 explength
} }
/* If there is no good dump known, write it */ /* If there is no good dump known, write it */
hash_collection &acthashes = m_file->hashes(hashes.hash_types().c_str()); util::hash_collection &acthashes = m_file->hashes(hashes.hash_types().c_str());
if (hashes.flag(hash_collection::FLAG_NO_DUMP)) if (hashes.flag(util::hash_collection::FLAG_NO_DUMP))
{ {
m_errorstring.append(string_format("%s NO GOOD DUMP KNOWN\n", name)); m_errorstring.append(string_format("%s NO GOOD DUMP KNOWN\n", name));
m_knownbad++; m_knownbad++;
@ -445,7 +445,7 @@ void rom_load_manager::verify_length_and_hash(const char *name, UINT32 explength
m_warnings++; m_warnings++;
} }
/* If it matches, but it is actually a bad dump, write it */ /* If it matches, but it is actually a bad dump, write it */
else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) else if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP))
{ {
m_errorstring.append(string_format("%s ROM NEEDS REDUMP\n", name)); m_errorstring.append(string_format("%s ROM NEEDS REDUMP\n", name));
m_knownbad++; m_knownbad++;
@ -557,7 +557,7 @@ int rom_load_manager::open_rom_file(const char *regiontag, const rom_entry *romp
/* extract CRC to use for searching */ /* extract CRC to use for searching */
UINT32 crc = 0; UINT32 crc = 0;
bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc); bool has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
/* attempt reading up the chain through the parents. It automatically also /* attempt reading up the chain through the parents. It automatically also
attempts any kind of load by checksum supported by the archives. */ attempts any kind of load by checksum supported by the archives. */
@ -928,7 +928,7 @@ void rom_load_manager::process_rom_entries(const char *regiontag, const rom_entr
if (baserom) if (baserom)
{ {
LOG(("Verifying length (%X) and checksums\n", explength)); LOG(("Verifying length (%X) and checksums\n", explength));
verify_length_and_hash(ROM_GETNAME(baserom), explength, hash_collection(ROM_GETHASHDATA(baserom))); verify_length_and_hash(ROM_GETNAME(baserom), explength, util::hash_collection(ROM_GETHASHDATA(baserom)));
LOG(("Verify finished\n")); LOG(("Verify finished\n"));
} }
@ -1064,7 +1064,7 @@ int open_disk_image(emu_options &options, const game_driver *gamedrv, const rom_
/* otherwise, look at our parents for a CHD with an identical checksum */ /* otherwise, look at our parents for a CHD with an identical checksum */
/* and try to open that */ /* and try to open that */
hash_collection romphashes(ROM_GETHASHDATA(romp)); util::hash_collection romphashes(ROM_GETHASHDATA(romp));
for (int drv = driver_list::find(*gamedrv); drv != -1; drv = driver_list::clone(drv)) for (int drv = driver_list::find(*gamedrv); drv != -1; drv = driver_list::clone(drv))
{ {
machine_config config(driver_list::driver(drv), options); machine_config config(driver_list::driver(drv), options);
@ -1075,7 +1075,7 @@ int open_disk_image(emu_options &options, const game_driver *gamedrv, const rom_
/* look for a differing name but with the same hash data */ /* look for a differing name but with the same hash data */
if (strcmp(ROM_GETNAME(romp), ROM_GETNAME(rom)) != 0 && if (strcmp(ROM_GETNAME(romp), ROM_GETNAME(rom)) != 0 &&
romphashes == hash_collection(ROM_GETHASHDATA(rom))) romphashes == util::hash_collection(ROM_GETHASHDATA(rom)))
{ {
/* attempt to open the properly named file, scanning up through parent directories */ /* attempt to open the properly named file, scanning up through parent directories */
filerr = osd_file::error::NOT_FOUND; filerr = osd_file::error::NOT_FOUND;
@ -1161,7 +1161,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
{ {
auto chd = std::make_unique<open_chd>(regiontag); auto chd = std::make_unique<open_chd>(regiontag);
hash_collection hashes(ROM_GETHASHDATA(romp)); util::hash_collection hashes(ROM_GETHASHDATA(romp));
chd_error err; chd_error err;
/* make the filename of the source */ /* make the filename of the source */
@ -1178,7 +1178,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
} }
/* get the header and extract the SHA1 */ /* get the header and extract the SHA1 */
hash_collection acthashes; util::hash_collection acthashes;
acthashes.add_sha1(chd->orig_chd().sha1()); acthashes.add_sha1(chd->orig_chd().sha1());
/* verify the hash */ /* verify the hash */
@ -1188,7 +1188,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent
dump_wrong_and_correct_checksums(hashes, acthashes); dump_wrong_and_correct_checksums(hashes, acthashes);
m_warnings++; m_warnings++;
} }
else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) else if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP))
{ {
m_errorstring.append(string_format("%s CHD NEEDS REDUMP\n", filename)); m_errorstring.append(string_format("%s CHD NEEDS REDUMP\n", filename));
m_knownbad++; m_knownbad++;

View File

@ -310,8 +310,8 @@ private:
void count_roms(); void count_roms();
void fill_random(UINT8 *base, UINT32 length); void fill_random(UINT8 *base, UINT32 length);
void handle_missing_file(const rom_entry *romp, std::string tried_file_names, chd_error chderr); void handle_missing_file(const rom_entry *romp, std::string tried_file_names, chd_error chderr);
void dump_wrong_and_correct_checksums(const hash_collection &hashes, const hash_collection &acthashes); void dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes);
void verify_length_and_hash(const char *name, UINT32 explength, const hash_collection &hashes); void verify_length_and_hash(const char *name, UINT32 explength, const util::hash_collection &hashes);
void display_loading_rom_message(const char *name, bool from_list); void display_loading_rom_message(const char *name, bool from_list);
void display_rom_load_results(bool from_list); void display_rom_load_results(bool from_list);
void region_post_process(const char *rgntag, bool invert); void region_post_process(const char *rgntag, bool invert);

View File

@ -738,7 +738,7 @@ void software_list_device::internal_validity_check(validity_checker &valid)
if (data->_hashdata != nullptr) if (data->_hashdata != nullptr)
{ {
// make sure the hash is valid // make sure the hash is valid
hash_collection hashes; util::hash_collection hashes;
if (!hashes.from_internal_string(data->_hashdata)) if (!hashes.from_internal_string(data->_hashdata))
osd_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", filename(), swinfo.shortname().c_str(), data->_name, data->_hashdata); osd_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", filename(), swinfo.shortname().c_str(), data->_name, data->_hashdata);
} }
@ -1272,7 +1272,7 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu
else else
{ {
if (!crc.empty() && !sha1.empty()) if (!crc.empty() && !sha1.empty())
hashdata = string_format("%c%s%c%s%s", hash_collection::HASH_CRC, crc, hash_collection::HASH_SHA1, sha1, (baddump ? BAD_DUMP : "")); hashdata = string_format("%c%s%c%s%s", util::hash_collection::HASH_CRC, crc, util::hash_collection::HASH_SHA1, sha1, (baddump ? BAD_DUMP : ""));
else else
parse_error("Incomplete rom hash definition"); parse_error("Incomplete rom hash definition");
} }
@ -1319,7 +1319,7 @@ void softlist_parser::parse_data_start(const char *tagname, const char **attribu
const bool baddump = (status == "baddump"); const bool baddump = (status == "baddump");
const bool nodump = (status == "nodump" ); const bool nodump = (status == "nodump" );
const bool writeable = (writeablestr == "yes"); const bool writeable = (writeablestr == "yes");
std::string hashdata = string_format("%c%s%s", hash_collection::HASH_SHA1, sha1, (nodump ? NO_DUMP : (baddump ? BAD_DUMP : ""))); std::string hashdata = string_format("%c%s%s", util::hash_collection::HASH_SHA1, sha1, (nodump ? NO_DUMP : (baddump ? BAD_DUMP : "")));
add_rom_entry(name.c_str(), hashdata.c_str(), 0, 0, ROMENTRYTYPE_ROM | (writeable ? DISK_READWRITE : DISK_READONLY)); add_rom_entry(name.c_str(), hashdata.c_str(), 0, 0, ROMENTRYTYPE_ROM | (writeable ? DISK_READWRITE : DISK_READONLY));
} }

View File

@ -1477,7 +1477,7 @@ void validity_checker::validate_roms()
total_files++; total_files++;
// make sure the hash is valid // make sure the hash is valid
hash_collection hashes; util::hash_collection hashes;
if (!hashes.from_internal_string(ROM_GETHASHDATA(romp))) if (!hashes.from_internal_string(ROM_GETHASHDATA(romp)))
osd_printf_error("ROM '%s' has an invalid hash string '%s'\n", last_name, ROM_GETHASHDATA(romp)); osd_printf_error("ROM '%s' has an invalid hash string '%s'\n", last_name, ROM_GETHASHDATA(romp));
} }

View File

@ -72,11 +72,11 @@ m_searchpath = combinedpath.c_str();
for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
{ {
char const *const name(ROM_GETNAME(rom)); char const *const name(ROM_GETNAME(rom));
hash_collection const hashes(ROM_GETHASHDATA(rom)); util::hash_collection const hashes(ROM_GETHASHDATA(rom));
device_t *const shared_device(find_shared_device(device, name, hashes, ROM_GETLENGTH(rom))); device_t *const shared_device(find_shared_device(device, name, hashes, ROM_GETLENGTH(rom)));
// count the number of files with hashes // count the number of files with hashes
if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom))
{ {
required++; required++;
if (shared_device) if (shared_device)
@ -349,10 +349,10 @@ void media_auditor::audit_regions(const rom_entry *region, const char *locationt
// now iterate over rom definitions // now iterate over rom definitions
for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
{ {
hash_collection const hashes(ROM_GETHASHDATA(rom)); util::hash_collection const hashes(ROM_GETHASHDATA(rom));
// count the number of files with hashes // count the number of files with hashes
if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom))
required++; required++;
audit_record const *record = nullptr; audit_record const *record = nullptr;
@ -426,10 +426,10 @@ media_auditor::audit_record &media_auditor::audit_one_disk(const rom_entry *rom,
// if we succeeded, get the hashes // if we succeeded, get the hashes
if (err == CHDERR_NONE) if (err == CHDERR_NONE)
{ {
hash_collection hashes; util::hash_collection hashes;
// if there's a SHA1 hash, add them to the output hash // if there's a SHA1 hash, add them to the output hash
if (source.sha1() != sha1_t::null) if (source.sha1() != util::sha1_t::null)
hashes.add_sha1(source.sha1()); hashes.add_sha1(source.sha1());
// update the actual values // update the actual values
@ -452,7 +452,7 @@ void media_auditor::compute_status(audit_record &record, const rom_entry *rom, b
// if not found, provide more details // if not found, provide more details
if (!found) if (!found)
{ {
if (record.expected_hashes().flag(hash_collection::FLAG_NO_DUMP)) if (record.expected_hashes().flag(util::hash_collection::FLAG_NO_DUMP))
record.set_status(audit_status::NOT_FOUND, audit_substatus::NOT_FOUND_NODUMP); record.set_status(audit_status::NOT_FOUND, audit_substatus::NOT_FOUND_NODUMP);
else if (ROM_ISOPTIONAL(rom)) else if (ROM_ISOPTIONAL(rom))
record.set_status(audit_status::NOT_FOUND, audit_substatus::NOT_FOUND_OPTIONAL); record.set_status(audit_status::NOT_FOUND, audit_substatus::NOT_FOUND_OPTIONAL);
@ -463,11 +463,11 @@ void media_auditor::compute_status(audit_record &record, const rom_entry *rom, b
{ {
if (record.expected_length() != record.actual_length()) if (record.expected_length() != record.actual_length())
record.set_status(audit_status::FOUND_INVALID, audit_substatus::FOUND_WRONG_LENGTH); record.set_status(audit_status::FOUND_INVALID, audit_substatus::FOUND_WRONG_LENGTH);
else if (record.expected_hashes().flag(hash_collection::FLAG_NO_DUMP)) else if (record.expected_hashes().flag(util::hash_collection::FLAG_NO_DUMP))
record.set_status(audit_status::GOOD, audit_substatus::FOUND_NODUMP); record.set_status(audit_status::GOOD, audit_substatus::FOUND_NODUMP);
else if (record.expected_hashes() != record.actual_hashes()) else if (record.expected_hashes() != record.actual_hashes())
record.set_status(audit_status::FOUND_INVALID, audit_substatus::FOUND_BAD_CHECKSUM); record.set_status(audit_status::FOUND_INVALID, audit_substatus::FOUND_BAD_CHECKSUM);
else if (record.expected_hashes().flag(hash_collection::FLAG_BAD_DUMP)) else if (record.expected_hashes().flag(util::hash_collection::FLAG_BAD_DUMP))
record.set_status(audit_status::GOOD, audit_substatus::GOOD_NEEDS_REDUMP); record.set_status(audit_status::GOOD, audit_substatus::GOOD_NEEDS_REDUMP);
else else
record.set_status(audit_status::GOOD, audit_substatus::GOOD); record.set_status(audit_status::GOOD, audit_substatus::GOOD);
@ -480,9 +480,9 @@ void media_auditor::compute_status(audit_record &record, const rom_entry *rom, b
// shares a media entry with the same hashes // shares a media entry with the same hashes
//------------------------------------------------- //-------------------------------------------------
device_t *media_auditor::find_shared_device(device_t &device, const char *name, const hash_collection &romhashes, UINT64 romlength) device_t *media_auditor::find_shared_device(device_t &device, const char *name, const util::hash_collection &romhashes, UINT64 romlength)
{ {
bool const dumped = !romhashes.flag(hash_collection::FLAG_NO_DUMP); bool const dumped = !romhashes.flag(util::hash_collection::FLAG_NO_DUMP);
// special case for non-root devices // special case for non-root devices
device_t *highest_device = nullptr; device_t *highest_device = nullptr;
@ -494,7 +494,7 @@ device_t *media_auditor::find_shared_device(device_t &device, const char *name,
{ {
if (ROM_GETLENGTH(rom) == romlength) if (ROM_GETLENGTH(rom) == romlength)
{ {
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if ((dumped && hashes == romhashes) || (!dumped && ROM_GETNAME(rom) == name)) if ((dumped && hashes == romhashes) || (!dumped && ROM_GETNAME(rom) == name))
highest_device = &device; highest_device = &device;
} }
@ -514,7 +514,7 @@ device_t *media_auditor::find_shared_device(device_t &device, const char *name,
{ {
if (ROM_GETLENGTH(rom) == romlength) if (ROM_GETLENGTH(rom) == romlength)
{ {
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if ((dumped && hashes == romhashes) || (!dumped && ROM_GETNAME(rom) == name)) if ((dumped && hashes == romhashes) || (!dumped && ROM_GETNAME(rom) == name))
highest_device = &scandevice; highest_device = &scandevice;
} }

View File

@ -107,8 +107,8 @@ public:
const char *name() const { return m_name; } const char *name() const { return m_name; }
UINT64 expected_length() const { return m_explength; } UINT64 expected_length() const { return m_explength; }
UINT64 actual_length() const { return m_length; } UINT64 actual_length() const { return m_length; }
const hash_collection &expected_hashes() const { return m_exphashes; } const util::hash_collection &expected_hashes() const { return m_exphashes; }
const hash_collection &actual_hashes() const { return m_hashes; } const util::hash_collection &actual_hashes() const { return m_hashes; }
device_t *shared_device() const { return m_shared_device; } device_t *shared_device() const { return m_shared_device; }
// setters // setters
@ -118,13 +118,13 @@ public:
m_substatus = substatus; m_substatus = substatus;
} }
void set_actual(const hash_collection &hashes, UINT64 length = 0) void set_actual(const util::hash_collection &hashes, UINT64 length = 0)
{ {
m_hashes = hashes; m_hashes = hashes;
m_length = length; m_length = length;
} }
void set_actual(hash_collection &&hashes, UINT64 length = 0) void set_actual(util::hash_collection &&hashes, UINT64 length = 0)
{ {
m_hashes = std::move(hashes); m_hashes = std::move(hashes);
m_length = length; m_length = length;
@ -143,8 +143,8 @@ public:
const char * m_name; // name of item const char * m_name; // name of item
UINT64 m_explength; // expected length of item UINT64 m_explength; // expected length of item
UINT64 m_length; // actual length of item UINT64 m_length; // actual length of item
hash_collection m_exphashes; // expected hash data util::hash_collection m_exphashes; // expected hash data
hash_collection m_hashes; // actual hash information util::hash_collection m_hashes; // actual hash information
device_t * m_shared_device; // device that shares the rom device_t * m_shared_device; // device that shares the rom
}; };
using record_list = std::list<audit_record>; using record_list = std::list<audit_record>;
@ -168,7 +168,7 @@ private:
audit_record &audit_one_rom(const rom_entry *rom); audit_record &audit_one_rom(const rom_entry *rom);
audit_record &audit_one_disk(const rom_entry *rom, const char *locationtag); audit_record &audit_one_disk(const rom_entry *rom, const char *locationtag);
void compute_status(audit_record &record, const rom_entry *rom, bool found); void compute_status(audit_record &record, const rom_entry *rom, bool found);
device_t *find_shared_device(device_t &device, const char *name, const hash_collection &romhashes, UINT64 romlength); device_t *find_shared_device(device_t &device, const char *name, const util::hash_collection &romhashes, UINT64 romlength);
// internal state // internal state
record_list m_record_list; record_list m_record_list;

View File

@ -129,7 +129,7 @@ public:
void identify(const char *name); void identify(const char *name);
void identify_file(const char *name); void identify_file(const char *name);
void identify_data(const char *name, const UINT8 *data, int length); void identify_data(const char *name, const UINT8 *data, int length);
int find_by_hash(const hash_collection &hashes, int length); int find_by_hash(const util::hash_collection &hashes, int length);
private: private:
// internal state // internal state
@ -260,8 +260,8 @@ void media_identifier::identify_file(const char *name)
} }
// otherwise, get the hash collection for this CHD // otherwise, get the hash collection for this CHD
hash_collection hashes; util::hash_collection hashes;
if (chd.sha1() != sha1_t::null) if (chd.sha1() != util::sha1_t::null)
hashes.add_sha1(chd.sha1()); hashes.add_sha1(chd.sha1());
// determine whether this file exists // determine whether this file exists
@ -309,8 +309,8 @@ void media_identifier::identify_data(const char *name, const UINT8 *data, int le
} }
// compute the hash of the data // compute the hash of the data
hash_collection hashes; util::hash_collection hashes;
hashes.compute(data, length, hash_collection::HASH_TYPES_CRC_SHA1); hashes.compute(data, length, util::hash_collection::HASH_TYPES_CRC_SHA1);
// output the name // output the name
m_total++; m_total++;
@ -334,7 +334,7 @@ void media_identifier::identify_data(const char *name, const UINT8 *data, int le
// of drivers by hash // of drivers by hash
//------------------------------------------------- //-------------------------------------------------
int media_identifier::find_by_hash(const hash_collection &hashes, int length) int media_identifier::find_by_hash(const util::hash_collection &hashes, int length)
{ {
int found = 0; int found = 0;
std::unordered_set<std::string> listnames; std::unordered_set<std::string> listnames;
@ -352,10 +352,10 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length)
for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region))
for (const rom_entry *rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom)) for (const rom_entry *rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom))
{ {
hash_collection romhashes(ROM_GETHASHDATA(rom)); util::hash_collection romhashes(ROM_GETHASHDATA(rom));
if (!romhashes.flag(hash_collection::FLAG_NO_DUMP) && hashes == romhashes) if (!romhashes.flag(util::hash_collection::FLAG_NO_DUMP) && hashes == romhashes)
{ {
bool baddump = romhashes.flag(hash_collection::FLAG_BAD_DUMP); bool baddump = romhashes.flag(util::hash_collection::FLAG_BAD_DUMP);
// output information about the match // output information about the match
if (found) if (found)
@ -377,10 +377,10 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length)
for (const rom_entry *region = part.romdata(); region != nullptr; region = rom_next_region(region)) for (const rom_entry *region = part.romdata(); region != nullptr; region = rom_next_region(region))
for (const rom_entry *rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom)) for (const rom_entry *rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom))
{ {
hash_collection romhashes(ROM_GETHASHDATA(rom)); util::hash_collection romhashes(ROM_GETHASHDATA(rom));
if (hashes == romhashes) if (hashes == romhashes)
{ {
bool baddump = romhashes.flag(hash_collection::FLAG_BAD_DUMP); bool baddump = romhashes.flag(util::hash_collection::FLAG_BAD_DUMP);
// output information about the match // output information about the match
if (found) if (found)
@ -821,7 +821,7 @@ void cli_frontend::listcrc(const char *gamename)
{ {
// if we have a CRC, display it // if we have a CRC, display it
UINT32 crc; UINT32 crc;
if (hash_collection(ROM_GETHASHDATA(rom)).crc(crc)) if (util::hash_collection(ROM_GETHASHDATA(rom)).crc(crc))
osd_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), device.shortname(), device.name()); osd_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), device.shortname(), device.name());
} }
} }
@ -872,10 +872,10 @@ void cli_frontend::listroms(const char *gamename)
osd_printf_info(" "); osd_printf_info(" ");
// output the hash data // output the hash data
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP))
{ {
if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP))
osd_printf_info(" BAD"); osd_printf_info(" BAD");
osd_printf_info(" %s", hashes.macro_string().c_str()); osd_printf_info(" %s", hashes.macro_string().c_str());
} }
@ -1436,8 +1436,8 @@ void cli_frontend::output_single_softlist(FILE *out, software_list_device &swlis
fprintf( out, "\t\t\t\t\t<disk name=\"%s\"", xml_normalize_string(ROM_GETNAME(rom)) ); fprintf( out, "\t\t\t\t\t<disk name=\"%s\"", xml_normalize_string(ROM_GETNAME(rom)) );
/* dump checksum information only if there is a known dump */ /* dump checksum information only if there is a known dump */
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if ( !hashes.flag(hash_collection::FLAG_NO_DUMP) ) if ( !hashes.flag(util::hash_collection::FLAG_NO_DUMP) )
fprintf( out, " %s", hashes.attribute_string().c_str() ); fprintf( out, " %s", hashes.attribute_string().c_str() );
else else
fprintf( out, " status=\"nodump\"" ); fprintf( out, " status=\"nodump\"" );

View File

@ -567,8 +567,8 @@ void info_xml_creator::output_rom(device_t &device)
continue; continue;
// if we have a valid ROM and we are a clone, see if we can find the parent ROM // if we have a valid ROM and we are a clone, see if we can find the parent ROM
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP))
merge_name = get_merge_name(hashes); merge_name = get_merge_name(hashes);
if (&device != &m_drivlist.config().root_device()) if (&device != &m_drivlist.config().root_device())
merge_name = nullptr; merge_name = nullptr;
@ -604,7 +604,7 @@ void info_xml_creator::output_rom(device_t &device)
util::stream_format(output, " size=\"%d\"", rom_file_size(rom)); util::stream_format(output, " size=\"%d\"", rom_file_size(rom));
// dump checksum information only if there is a known dump // dump checksum information only if there is a known dump
if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP))
{ {
// iterate over hash function types and print m_output their values // iterate over hash function types and print m_output their values
output << " " << hashes.attribute_string(); output << " " << hashes.attribute_string();
@ -1603,7 +1603,7 @@ void info_xml_creator::output_ramoptions()
// parent set // parent set
//------------------------------------------------- //-------------------------------------------------
const char *info_xml_creator::get_merge_name(const hash_collection &romhashes) const char *info_xml_creator::get_merge_name(const util::hash_collection &romhashes)
{ {
// walk the parent chain // walk the parent chain
const char *merge_name = nullptr; const char *merge_name = nullptr;
@ -1614,8 +1614,8 @@ const char *info_xml_creator::get_merge_name(const hash_collection &romhashes)
for (const rom_entry *pregion = rom_first_region(*device); pregion != nullptr; pregion = rom_next_region(pregion)) for (const rom_entry *pregion = rom_first_region(*device); pregion != nullptr; pregion = rom_next_region(pregion))
for (const rom_entry *prom = rom_first_file(pregion); prom != nullptr; prom = rom_next_file(prom)) for (const rom_entry *prom = rom_first_file(pregion); prom != nullptr; prom = rom_next_file(prom))
{ {
hash_collection phashes(ROM_GETHASHDATA(prom)); util::hash_collection phashes(ROM_GETHASHDATA(prom));
if (!phashes.flag(hash_collection::FLAG_NO_DUMP) && romhashes == phashes) if (!phashes.flag(util::hash_collection::FLAG_NO_DUMP) && romhashes == phashes)
{ {
// stop when we find a match // stop when we find a match
merge_name = ROM_GETNAME(prom); merge_name = ROM_GETNAME(prom);

View File

@ -54,7 +54,7 @@ private:
void output_one_device(device_t &device, const char *devtag); void output_one_device(device_t &device, const char *devtag);
void output_devices(); void output_devices();
const char *get_merge_name(const hash_collection &romhashes); const char *get_merge_name(const util::hash_collection &romhashes);
// internal state // internal state
FILE * m_output; FILE * m_output;

View File

@ -687,8 +687,8 @@ void menu_select_game::build_available_list()
for (; !ROMENTRY_ISEND(rom) && noroms == true; ++rom) for (; !ROMENTRY_ISEND(rom) && noroms == true; ++rom)
if (ROMENTRY_ISFILE(rom)) if (ROMENTRY_ISFILE(rom))
{ {
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) if (!hashes.flag(util::hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom))
noroms = false; noroms = false;
} }
@ -711,8 +711,8 @@ void menu_select_game::build_available_list()
{ {
if (ROMENTRY_ISFILE(rom)) if (ROMENTRY_ISFILE(rom))
{ {
hash_collection hashes(ROM_GETHASHDATA(rom)); util::hash_collection hashes(ROM_GETHASHDATA(rom));
if (hashes.flag(hash_collection::FLAG_NO_DUMP) || ROM_ISOPTIONAL(rom)) if (hashes.flag(util::hash_collection::FLAG_NO_DUMP) || ROM_ISOPTIONAL(rom))
continue; continue;
UINT64 lenght = ROM_GETLENGTH(rom); UINT64 lenght = ROM_GETLENGTH(rom);
@ -721,8 +721,8 @@ void menu_select_game::build_available_list()
{ {
if (ROMENTRY_ISFILE(parentrom) && ROM_GETLENGTH(parentrom) == lenght) if (ROMENTRY_ISFILE(parentrom) && ROM_GETLENGTH(parentrom) == lenght)
{ {
hash_collection parenthashes(ROM_GETHASHDATA(parentrom)); util::hash_collection parenthashes(ROM_GETHASHDATA(parentrom));
if (parenthashes.flag(hash_collection::FLAG_NO_DUMP) || ROM_ISOPTIONAL(parentrom)) if (parenthashes.flag(util::hash_collection::FLAG_NO_DUMP) || ROM_ISOPTIONAL(parentrom))
continue; continue;
if (hashes == parenthashes) if (hashes == parenthashes)

View File

@ -115,7 +115,7 @@ struct chd_file::metadata_entry
struct chd_file::metadata_hash struct chd_file::metadata_hash
{ {
UINT8 tag[4]; // tag of the metadata in big-endian UINT8 tag[4]; // tag of the metadata in big-endian
sha1_t sha1; // hash data util::sha1_t sha1; // hash data
}; };
@ -159,9 +159,9 @@ inline void chd_file::be_write(UINT8 *base, UINT64 value, int numbytes)
// stream in bigendian order // stream in bigendian order
//------------------------------------------------- //-------------------------------------------------
inline sha1_t chd_file::be_read_sha1(const UINT8 *base) inline util::sha1_t chd_file::be_read_sha1(const UINT8 *base)
{ {
sha1_t result; util::sha1_t result;
memcpy(&result.m_raw[0], base, sizeof(result.m_raw)); memcpy(&result.m_raw[0], base, sizeof(result.m_raw));
return result; return result;
} }
@ -172,7 +172,7 @@ inline sha1_t chd_file::be_read_sha1(const UINT8 *base)
// stream in bigendian order // stream in bigendian order
//------------------------------------------------- //-------------------------------------------------
inline void chd_file::be_write_sha1(UINT8 *base, sha1_t value) inline void chd_file::be_write_sha1(UINT8 *base, util::sha1_t value)
{ {
memcpy(base, &value.m_raw[0], sizeof(value.m_raw)); memcpy(base, &value.m_raw[0], sizeof(value.m_raw));
} }
@ -311,7 +311,7 @@ chd_file::~chd_file()
} }
/** /**
* @fn sha1_t chd_file::sha1() * @fn util::sha1_t chd_file::sha1()
* *
* @brief ------------------------------------------------- * @brief -------------------------------------------------
* sha1 - return our SHA1 value * sha1 - return our SHA1 value
@ -320,24 +320,24 @@ chd_file::~chd_file()
* @return A sha1_t. * @return A sha1_t.
*/ */
sha1_t chd_file::sha1() util::sha1_t chd_file::sha1()
{ {
try try
{ {
// read the big-endian version // read the big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
file_read(m_sha1_offset, rawbuf, sizeof(rawbuf)); file_read(m_sha1_offset, rawbuf, sizeof(rawbuf));
return be_read_sha1(rawbuf); return be_read_sha1(rawbuf);
} }
catch (chd_error &) catch (chd_error &)
{ {
// on failure, return nullptr // on failure, return nullptr
return sha1_t::null; return util::sha1_t::null;
} }
} }
/** /**
* @fn sha1_t chd_file::raw_sha1() * @fn util::sha1_t chd_file::raw_sha1()
* *
* @brief ------------------------------------------------- * @brief -------------------------------------------------
* raw_sha1 - return our raw SHA1 value * raw_sha1 - return our raw SHA1 value
@ -349,7 +349,7 @@ sha1_t chd_file::sha1()
* @return A sha1_t. * @return A sha1_t.
*/ */
sha1_t chd_file::raw_sha1() util::sha1_t chd_file::raw_sha1()
{ {
try try
{ {
@ -358,19 +358,19 @@ sha1_t chd_file::raw_sha1()
throw CHDERR_UNSUPPORTED_VERSION; throw CHDERR_UNSUPPORTED_VERSION;
// read the big-endian version // read the big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
file_read(m_rawsha1_offset, rawbuf, sizeof(rawbuf)); file_read(m_rawsha1_offset, rawbuf, sizeof(rawbuf));
return be_read_sha1(rawbuf); return be_read_sha1(rawbuf);
} }
catch (chd_error &) catch (chd_error &)
{ {
// on failure, return nullptr // on failure, return nullptr
return sha1_t::null; return util::sha1_t::null;
} }
} }
/** /**
* @fn sha1_t chd_file::parent_sha1() * @fn util::sha1_t chd_file::parent_sha1()
* *
* @brief ------------------------------------------------- * @brief -------------------------------------------------
* parent_sha1 - return our parent's SHA1 value * parent_sha1 - return our parent's SHA1 value
@ -382,7 +382,7 @@ sha1_t chd_file::raw_sha1()
* @return A sha1_t. * @return A sha1_t.
*/ */
sha1_t chd_file::parent_sha1() util::sha1_t chd_file::parent_sha1()
{ {
try try
{ {
@ -391,14 +391,14 @@ sha1_t chd_file::parent_sha1()
throw CHDERR_UNSUPPORTED_VERSION; throw CHDERR_UNSUPPORTED_VERSION;
// read the big-endian version // read the big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
file_read(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); file_read(m_parentsha1_offset, rawbuf, sizeof(rawbuf));
return be_read_sha1(rawbuf); return be_read_sha1(rawbuf);
} }
catch (chd_error &) catch (chd_error &)
{ {
// on failure, return nullptr // on failure, return nullptr
return sha1_t::null; return util::sha1_t::null;
} }
} }
@ -523,10 +523,10 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32
* @param rawdata The rawdata. * @param rawdata The rawdata.
*/ */
void chd_file::set_raw_sha1(sha1_t rawdata) void chd_file::set_raw_sha1(util::sha1_t rawdata)
{ {
// create a big-endian version // create a big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
be_write_sha1(rawbuf, rawdata); be_write_sha1(rawbuf, rawdata);
// write to the header // write to the header
@ -551,14 +551,14 @@ void chd_file::set_raw_sha1(sha1_t rawdata)
* @param parent The parent. * @param parent The parent.
*/ */
void chd_file::set_parent_sha1(sha1_t parent) void chd_file::set_parent_sha1(util::sha1_t parent)
{ {
// if no file, fail // if no file, fail
if (m_file == nullptr) if (m_file == nullptr)
throw CHDERR_INVALID_FILE; throw CHDERR_INVALID_FILE;
// create a big-endian version // create a big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
be_write_sha1(rawbuf, parent); be_write_sha1(rawbuf, parent);
// write to the header // write to the header
@ -902,13 +902,13 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer)
blocklen = be_read(&rawmap[12], 2) + (rawmap[14] << 16); blocklen = be_read(&rawmap[12], 2) + (rawmap[14] << 16);
file_read(blockoffs, &m_compressed[0], blocklen); file_read(blockoffs, &m_compressed[0], blocklen);
m_decompressor[0]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes); m_decompressor[0]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes);
if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != nullptr && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != nullptr && util::crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
case V34_MAP_ENTRY_TYPE_UNCOMPRESSED: case V34_MAP_ENTRY_TYPE_UNCOMPRESSED:
file_read(blockoffs, dest, m_hunkbytes); file_read(blockoffs, dest, m_hunkbytes);
if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && util::crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
@ -916,7 +916,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer)
be_write(dest, blockoffs, 8); be_write(dest, blockoffs, 8);
for (UINT32 bytes = 8; bytes < m_hunkbytes; bytes++) for (UINT32 bytes = 8; bytes < m_hunkbytes; bytes++)
dest[bytes] = dest[bytes - 8]; dest[bytes] = dest[bytes - 8];
if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && util::crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
@ -961,15 +961,15 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer)
case COMPRESSION_TYPE_3: case COMPRESSION_TYPE_3:
file_read(blockoffs, &m_compressed[0], blocklen); file_read(blockoffs, &m_compressed[0], blocklen);
m_decompressor[rawmap[0]]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes); m_decompressor[rawmap[0]]->decompress(&m_compressed[0], blocklen, dest, m_hunkbytes);
if (!m_decompressor[rawmap[0]]->lossy() && dest != nullptr && crc16_creator::simple(dest, m_hunkbytes) != blockcrc) if (!m_decompressor[rawmap[0]]->lossy() && dest != nullptr && util::crc16_creator::simple(dest, m_hunkbytes) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
if (m_decompressor[rawmap[0]]->lossy() && crc16_creator::simple(&m_compressed[0], blocklen) != blockcrc) if (m_decompressor[rawmap[0]]->lossy() && util::crc16_creator::simple(&m_compressed[0], blocklen) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
case COMPRESSION_NONE: case COMPRESSION_NONE:
file_read(blockoffs, dest, m_hunkbytes); file_read(blockoffs, dest, m_hunkbytes);
if (crc16_creator::simple(dest, m_hunkbytes) != blockcrc) if (util::crc16_creator::simple(dest, m_hunkbytes) != blockcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
@ -1558,7 +1558,7 @@ chd_error chd_file::clone_all_metadata(chd_file &source)
} }
/** /**
* @fn sha1_t chd_file::compute_overall_sha1(sha1_t rawsha1) * @fn util::sha1_t chd_file::compute_overall_sha1(sha1_t rawsha1)
* *
* @brief ------------------------------------------------- * @brief -------------------------------------------------
* compute_overall_sha1 - iterate through the metadata and compute the overall hash of * compute_overall_sha1 - iterate through the metadata and compute the overall hash of
@ -1570,7 +1570,7 @@ chd_error chd_file::clone_all_metadata(chd_file &source)
* @return The calculated overall sha 1. * @return The calculated overall sha 1.
*/ */
sha1_t chd_file::compute_overall_sha1(sha1_t rawsha1) util::sha1_t chd_file::compute_overall_sha1(util::sha1_t rawsha1)
{ {
// only works for v4 and above // only works for v4 and above
if (m_version < 4) if (m_version < 4)
@ -1593,7 +1593,7 @@ sha1_t chd_file::compute_overall_sha1(sha1_t rawsha1)
// create an entry for this metadata and add it // create an entry for this metadata and add it
metadata_hash hashentry; metadata_hash hashentry;
be_write(hashentry.tag, metaentry.metatag, 4); be_write(hashentry.tag, metaentry.metatag, 4);
hashentry.sha1 = sha1_creator::simple(&filedata[0], metaentry.length); hashentry.sha1 = util::sha1_creator::simple(&filedata[0], metaentry.length);
hasharray.push_back(hashentry); hasharray.push_back(hashentry);
} }
@ -1602,7 +1602,7 @@ sha1_t chd_file::compute_overall_sha1(sha1_t rawsha1)
qsort(&hasharray[0], hasharray.size(), sizeof(hasharray[0]), metadata_hash_compare); qsort(&hasharray[0], hasharray.size(), sizeof(hasharray[0]), metadata_hash_compare);
// read the raw data hash from our header and start a new SHA1 with that data // read the raw data hash from our header and start a new SHA1 with that data
sha1_creator overall_sha1; util::sha1_creator overall_sha1;
overall_sha1.append(&rawsha1, sizeof(rawsha1)); overall_sha1.append(&rawsha1, sizeof(rawsha1));
if (!hasharray.empty()) if (!hasharray.empty())
overall_sha1.append(&hasharray[0], hasharray.size() * sizeof(hasharray[0])); overall_sha1.append(&hasharray[0], hasharray.size() * sizeof(hasharray[0]));
@ -1750,7 +1750,7 @@ UINT32 chd_file::guess_unitbytes()
* @param [in,out] parentsha1 The first parentsha. * @param [in,out] parentsha1 The first parentsha.
*/ */
void chd_file::parse_v3_header(UINT8 *rawheader, sha1_t &parentsha1) void chd_file::parse_v3_header(UINT8 *rawheader, util::sha1_t &parentsha1)
{ {
// verify header length // verify header length
if (be_read(&rawheader[8], 4) != V3_HEADER_SIZE) if (be_read(&rawheader[8], 4) != V3_HEADER_SIZE)
@ -1813,7 +1813,7 @@ void chd_file::parse_v3_header(UINT8 *rawheader, sha1_t &parentsha1)
* @param [in,out] parentsha1 The first parentsha. * @param [in,out] parentsha1 The first parentsha.
*/ */
void chd_file::parse_v4_header(UINT8 *rawheader, sha1_t &parentsha1) void chd_file::parse_v4_header(UINT8 *rawheader, util::sha1_t &parentsha1)
{ {
// verify header length // verify header length
if (be_read(&rawheader[8], 4) != V4_HEADER_SIZE) if (be_read(&rawheader[8], 4) != V4_HEADER_SIZE)
@ -1873,7 +1873,7 @@ void chd_file::parse_v4_header(UINT8 *rawheader, sha1_t &parentsha1)
* @param [in,out] parentsha1 The first parentsha. * @param [in,out] parentsha1 The first parentsha.
*/ */
void chd_file::parse_v5_header(UINT8 *rawheader, sha1_t &parentsha1) void chd_file::parse_v5_header(UINT8 *rawheader, util::sha1_t &parentsha1)
{ {
// verify header length // verify header length
if (be_read(&rawheader[8], 4) != V5_HEADER_SIZE) if (be_read(&rawheader[8], 4) != V5_HEADER_SIZE)
@ -1928,7 +1928,7 @@ chd_error chd_file::compress_v5_map()
try try
{ {
// first get a CRC-16 of the original rawmap // first get a CRC-16 of the original rawmap
crc16_t mapcrc = crc16_creator::simple(&m_rawmap[0], m_hunkcount * 12); util::crc16_t mapcrc = util::crc16_creator::simple(&m_rawmap[0], m_hunkcount * 12);
// create a buffer to hold the RLE data // create a buffer to hold the RLE data
dynamic_buffer compression_rle(m_hunkcount); dynamic_buffer compression_rle(m_hunkcount);
@ -2244,7 +2244,7 @@ void chd_file::decompress_v5_map()
} }
// verify the final CRC // verify the final CRC
if (crc16_creator::simple(&m_rawmap[0], m_hunkcount * 12) != mapcrc) if (util::crc16_creator::simple(&m_rawmap[0], m_hunkcount * 12) != mapcrc)
throw CHDERR_DECOMPRESSION_ERROR; throw CHDERR_DECOMPRESSION_ERROR;
} }
@ -2310,15 +2310,15 @@ chd_error chd_file::create_common()
be_write(&rawheader[48], m_metaoffset, 8); be_write(&rawheader[48], m_metaoffset, 8);
be_write(&rawheader[56], m_hunkbytes, 4); be_write(&rawheader[56], m_hunkbytes, 4);
be_write(&rawheader[60], m_unitbytes, 4); be_write(&rawheader[60], m_unitbytes, 4);
be_write_sha1(&rawheader[64], sha1_t::null); be_write_sha1(&rawheader[64], util::sha1_t::null);
be_write_sha1(&rawheader[84], sha1_t::null); be_write_sha1(&rawheader[84], util::sha1_t::null);
be_write_sha1(&rawheader[104], (m_parent != nullptr) ? m_parent->sha1() : sha1_t::null); be_write_sha1(&rawheader[104], (m_parent != nullptr) ? m_parent->sha1() : util::sha1_t::null);
// write the resulting header // write the resulting header
file_write(0, rawheader, sizeof(rawheader)); file_write(0, rawheader, sizeof(rawheader));
// parse it back out to set up fields appropriately // parse it back out to set up fields appropriately
sha1_t parentsha1; util::sha1_t parentsha1;
parse_v5_header(rawheader, parentsha1); parse_v5_header(rawheader, parentsha1);
// writes are obviously permitted; reads only if uncompressed // writes are obviously permitted; reads only if uncompressed
@ -2403,7 +2403,7 @@ chd_error chd_file::open_common(bool writeable)
throw CHDERR_UNSUPPORTED_VERSION; throw CHDERR_UNSUPPORTED_VERSION;
// read the header if we support it // read the header if we support it
sha1_t parentsha1 = sha1_t::null; util::sha1_t parentsha1 = util::sha1_t::null;
switch (m_version) switch (m_version)
{ {
case 3: parse_v3_header(rawheader, parentsha1); break; case 3: parse_v3_header(rawheader, parentsha1); break;
@ -2416,7 +2416,7 @@ chd_error chd_file::open_common(bool writeable)
throw CHDERR_FILE_NOT_WRITEABLE; throw CHDERR_FILE_NOT_WRITEABLE;
// make sure we have a parent if we need one (and don't if we don't) // make sure we have a parent if we need one (and don't if we don't)
if (parentsha1 != sha1_t::null) if (parentsha1 != util::sha1_t::null)
{ {
if (m_parent == nullptr) if (m_parent == nullptr)
m_parent_missing = true; m_parent_missing = true;
@ -2535,7 +2535,7 @@ void chd_file::verify_proper_compression_append(UINT32 hunknum)
* @param crc16 The CRC 16. * @param crc16 The CRC 16.
*/ */
void chd_file::hunk_write_compressed(UINT32 hunknum, INT8 compression, const UINT8 *compressed, UINT32 complength, crc16_t crc16) void chd_file::hunk_write_compressed(UINT32 hunknum, INT8 compression, const UINT8 *compressed, UINT32 complength, util::crc16_t crc16)
{ {
// verify that we are appending properly to a compressed file // verify that we are appending properly to a compressed file
verify_proper_compression_append(hunknum); verify_proper_compression_append(hunknum);
@ -2711,10 +2711,10 @@ void chd_file::metadata_update_hash()
return; return;
// compute the new overall hash // compute the new overall hash
sha1_t fullsha1 = compute_overall_sha1(raw_sha1()); util::sha1_t fullsha1 = compute_overall_sha1(raw_sha1());
// create a big-endian version // create a big-endian version
UINT8 rawbuf[sizeof(sha1_t)]; UINT8 rawbuf[sizeof(util::sha1_t)];
be_write_sha1(&rawbuf[0], fullsha1); be_write_sha1(&rawbuf[0], fullsha1);
// write to the header // write to the header
@ -3033,8 +3033,8 @@ void chd_file_compressor::async_walk_parent(work_item &item)
units = 1; units = 1;
for (UINT32 unit = 0; unit < units; unit++) for (UINT32 unit = 0; unit < units; unit++)
{ {
item.m_hash[unit].m_crc16 = crc16_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes()); item.m_hash[unit].m_crc16 = util::crc16_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes());
item.m_hash[unit].m_sha1 = sha1_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes()); item.m_hash[unit].m_sha1 = util::sha1_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes());
} }
item.m_status = WS_COMPLETE; item.m_status = WS_COMPLETE;
} }
@ -3075,8 +3075,8 @@ void chd_file_compressor::async_compress_hunk(work_item &item, int threadid)
item.m_codecs = m_codecs[threadid]; item.m_codecs = m_codecs[threadid];
// compute CRC-16 and SHA-1 hashes // compute CRC-16 and SHA-1 hashes
item.m_hash[0].m_crc16 = crc16_creator::simple(item.m_data, hunk_bytes()); item.m_hash[0].m_crc16 = util::crc16_creator::simple(item.m_data, hunk_bytes());
item.m_hash[0].m_sha1 = sha1_creator::simple(item.m_data, hunk_bytes()); item.m_hash[0].m_sha1 = util::sha1_creator::simple(item.m_data, hunk_bytes());
// find the best compression scheme, unless we already have a self or parent match // find the best compression scheme, unless we already have a self or parent match
// (note we may miss a self match from blocks not yet added, but this just results in extra work) // (note we may miss a self match from blocks not yet added, but this just results in extra work)
@ -3254,7 +3254,7 @@ void chd_file_compressor::hashmap::reset()
* @return An UINT64. * @return An UINT64.
*/ */
UINT64 chd_file_compressor::hashmap::find(crc16_t crc16, sha1_t sha1) UINT64 chd_file_compressor::hashmap::find(util::crc16_t crc16, util::sha1_t sha1)
{ {
// look up the entry in the map // look up the entry in the map
for (entry_t *entry = m_map[crc16]; entry != nullptr; entry = entry->m_next) for (entry_t *entry = m_map[crc16]; entry != nullptr; entry = entry->m_next)
@ -3275,7 +3275,7 @@ UINT64 chd_file_compressor::hashmap::find(crc16_t crc16, sha1_t sha1)
* @param sha1 The first sha. * @param sha1 The first sha.
*/ */
void chd_file_compressor::hashmap::add(UINT64 itemnum, crc16_t crc16, sha1_t sha1) void chd_file_compressor::hashmap::add(UINT64 itemnum, util::crc16_t crc16, util::sha1_t sha1)
{ {
// add to the appropriate map // add to the appropriate map
if (m_block_list->m_nextalloc == ARRAY_LENGTH(m_block_list->m_array)) if (m_block_list->m_nextalloc == ARRAY_LENGTH(m_block_list->m_array))

View File

@ -317,14 +317,14 @@ public:
bool compressed() const { return (m_compression[0] != CHD_CODEC_NONE); } bool compressed() const { return (m_compression[0] != CHD_CODEC_NONE); }
chd_codec_type compression(int index) const { return m_compression[index]; } chd_codec_type compression(int index) const { return m_compression[index]; }
chd_file *parent() const { return m_parent; } chd_file *parent() const { return m_parent; }
sha1_t sha1(); util::sha1_t sha1();
sha1_t raw_sha1(); util::sha1_t raw_sha1();
sha1_t parent_sha1(); util::sha1_t parent_sha1();
chd_error hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 &compbytes); chd_error hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 &compbytes);
// setters // setters
void set_raw_sha1(sha1_t rawdata); void set_raw_sha1(util::sha1_t rawdata);
void set_parent_sha1(sha1_t parent); void set_parent_sha1(util::sha1_t parent);
// file create // file create
chd_error create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]); chd_error create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 unitbytes, chd_codec_type compression[4]);
@ -359,7 +359,7 @@ public:
chd_error clone_all_metadata(chd_file &source); chd_error clone_all_metadata(chd_file &source);
// hashing helper // hashing helper
sha1_t compute_overall_sha1(sha1_t rawsha1); util::sha1_t compute_overall_sha1(util::sha1_t rawsha1);
// codec interfaces // codec interfaces
chd_error codec_configure(chd_codec_type codec, int param, void *config); chd_error codec_configure(chd_codec_type codec, int param, void *config);
@ -374,8 +374,8 @@ private:
// inline helpers // inline helpers
UINT64 be_read(const UINT8 *base, int numbytes); UINT64 be_read(const UINT8 *base, int numbytes);
void be_write(UINT8 *base, UINT64 value, int numbytes); void be_write(UINT8 *base, UINT64 value, int numbytes);
sha1_t be_read_sha1(const UINT8 *base); util::sha1_t be_read_sha1(const UINT8 *base);
void be_write_sha1(UINT8 *base, sha1_t value); void be_write_sha1(UINT8 *base, util::sha1_t value);
void file_read(UINT64 offset, void *dest, UINT32 length); void file_read(UINT64 offset, void *dest, UINT32 length);
void file_write(UINT64 offset, const void *source, UINT32 length); void file_write(UINT64 offset, const void *source, UINT32 length);
UINT64 file_append(const void *source, UINT32 length, UINT32 alignment = 0); UINT64 file_append(const void *source, UINT32 length, UINT32 alignment = 0);
@ -383,16 +383,16 @@ private:
// internal helpers // internal helpers
UINT32 guess_unitbytes(); UINT32 guess_unitbytes();
void parse_v3_header(UINT8 *rawheader, sha1_t &parentsha1); void parse_v3_header(UINT8 *rawheader, util::sha1_t &parentsha1);
void parse_v4_header(UINT8 *rawheader, sha1_t &parentsha1); void parse_v4_header(UINT8 *rawheader, util::sha1_t &parentsha1);
void parse_v5_header(UINT8 *rawheader, sha1_t &parentsha1); void parse_v5_header(UINT8 *rawheader, util::sha1_t &parentsha1);
chd_error compress_v5_map(); chd_error compress_v5_map();
void decompress_v5_map(); void decompress_v5_map();
chd_error create_common(); chd_error create_common();
chd_error open_common(bool writeable); chd_error open_common(bool writeable);
void create_open_common(); void create_open_common();
void verify_proper_compression_append(UINT32 hunknum); void verify_proper_compression_append(UINT32 hunknum);
void hunk_write_compressed(UINT32 hunknum, INT8 compression, const UINT8 *compressed, UINT32 complength, crc16_t crc16); void hunk_write_compressed(UINT32 hunknum, INT8 compression, const UINT8 *compressed, UINT32 complength, util::crc16_t crc16);
void hunk_copy_from_self(UINT32 hunknum, UINT32 otherhunk); void hunk_copy_from_self(UINT32 hunknum, UINT32 otherhunk);
void hunk_copy_from_parent(UINT32 hunknum, UINT64 parentunit); void hunk_copy_from_parent(UINT32 hunknum, UINT64 parentunit);
bool metadata_find(chd_metadata_tag metatag, INT32 metaindex, metadata_entry &metaentry, bool resume = false); bool metadata_find(chd_metadata_tag metatag, INT32 metaindex, metadata_entry &metaentry, bool resume = false);
@ -469,8 +469,8 @@ private:
// operations // operations
void reset(); void reset();
UINT64 find(crc16_t crc16, sha1_t sha1); UINT64 find(util::crc16_t crc16, util::sha1_t sha1);
void add(UINT64 itemnum, crc16_t crc16, sha1_t sha1); void add(UINT64 itemnum, util::crc16_t crc16, util::sha1_t sha1);
// constants // constants
static const UINT64 NOT_FOUND = ~UINT64(0); static const UINT64 NOT_FOUND = ~UINT64(0);
@ -480,7 +480,7 @@ private:
{ {
entry_t * m_next; // next entry in list entry_t * m_next; // next entry in list
UINT64 m_itemnum; // item number UINT64 m_itemnum; // item number
sha1_t m_sha1; // SHA-1 of the block util::sha1_t m_sha1; // SHA-1 of the block
}; };
// block of entries // block of entries
@ -511,8 +511,8 @@ private:
// a CRC-16/SHA-1 pair // a CRC-16/SHA-1 pair
struct hash_pair struct hash_pair
{ {
crc16_t m_crc16; // calculated CRC-16 util::crc16_t m_crc16; // calculated CRC-16
sha1_t m_sha1; // calculated SHA-1 util::sha1_t m_sha1; // calculated SHA-1
}; };
// a single work item // a single work item
@ -556,7 +556,7 @@ private:
bool m_walking_parent; // are we building the parent map? bool m_walking_parent; // are we building the parent map?
UINT64 m_total_in; // total bytes in UINT64 m_total_in; // total bytes in
UINT64 m_total_out; // total bytes out UINT64 m_total_out; // total bytes out
sha1_creator m_compsha1; // running SHA-1 on raw data util::sha1_creator m_compsha1; // running SHA-1 on raw data
// hash lookup maps // hash lookup maps
hashmap m_parent_map; // hash map for parent hashmap m_parent_map; // hash map for parent

View File

@ -2,7 +2,7 @@
// copyright-holders:Aaron Giles // copyright-holders:Aaron Giles
/*************************************************************************** /***************************************************************************
hash.c hash.cpp
Function to handle hash functions (checksums) Function to handle hash functions (checksums)
@ -10,11 +10,12 @@
***************************************************************************/ ***************************************************************************/
#include "emu.h" #include "hash.h"
#include "hashing.h" #include "hashing.h"
#include <ctype.h> #include <ctype.h>
namespace util {
//************************************************************************** //**************************************************************************
// GLOBAL VARIABLES // GLOBAL VARIABLES
//************************************************************************** //**************************************************************************
@ -418,3 +419,5 @@ void hash_collection::copyfrom(const hash_collection &src)
// don't copy creators // don't copy creators
m_creator = nullptr; m_creator = nullptr;
} }
} // namespace util

View File

@ -29,7 +29,7 @@
#define BAD_DUMP "^" #define BAD_DUMP "^"
namespace util {
//************************************************************************** //**************************************************************************
// TYPE DEFINITIONS // TYPE DEFINITIONS
//************************************************************************** //**************************************************************************
@ -117,4 +117,6 @@ private:
}; };
} // namespace util
#endif /* __HASH_H__ */ #endif /* __HASH_H__ */

View File

@ -14,6 +14,7 @@
#include <sstream> #include <sstream>
namespace util {
//************************************************************************** //**************************************************************************
// CONSTANTS // CONSTANTS
//************************************************************************** //**************************************************************************
@ -291,3 +292,5 @@ void crc16_creator::append(const void *data, UINT32 length)
crc = (crc << 8) ^ s_table[(crc >> 8) ^ *src++]; crc = (crc << 8) ^ s_table[(crc >> 8) ^ *src++];
m_accum.m_raw = crc; m_accum.m_raw = crc;
} }
} // namespace util

View File

@ -20,6 +20,7 @@
#include "sha1.h" #include "sha1.h"
namespace util {
//************************************************************************** //**************************************************************************
// TYPE DEFINITIONS // TYPE DEFINITIONS
//************************************************************************** //**************************************************************************
@ -217,4 +218,6 @@ protected:
}; };
} // namespace util
#endif // __HASHING_H__ #endif // __HASHING_H__