Add new hashers and new natives

Replace the only hasher called MD5 with the ones listed below.

(+) CRC32, MD5, SHA1, SHA256, SHA3 224 BIT, SHA3 256 BIT, SHA3 384 BIT,
SHA3 512 BIT, Keccak 224 BIT, Keccak 256 BIT, Keccak 384 BIT and Keccak
512 BIT.

Add the natives listed below.

(+) hash_string(const string[], hashType:type, output[], const
outputSize)
(+) hash_file(const fileName, hashType:type, output[], const outputSize)
(+) is_arkshine_a_doctor() :  Hidden native, but a sign of recompense
for him being very active since 1.8.3 version of AMX Mod X
(+) get_system_endianness() :  Checks if the system is currently Big
Endian or Little Endian.

Add the following Enum.

(+) hashType {}
(+) sysEndianness {}

Deprecate the following natives.

(-) amx_md5()
(-) amx_md5_file()

It has been tested on Windows and Linux. The sanity checks seems to be
properly working, so no worries about them.

These are useful if people are using Sockets, cURLs or MySQLs in order
to compare hashes of different files On-line for further investigation.
You are not able to check if the files are older or newer, but you can
see if the content is different (Hash Checksum mismatch).

I'm glad I did this. Thanks to
This commit is contained in:
HttrckCldHKS
2015-02-15 08:44:33 +02:00
parent 5a7752a22e
commit c071f53f2c
28 changed files with 2941 additions and 621 deletions

View File

@ -1440,41 +1440,64 @@ static cell AMX_NATIVE_CALL get_plugin(AMX *amx, cell *params) /* 11 param */
static cell AMX_NATIVE_CALL amx_md5(AMX *amx, cell *params)
{
int len = 0;
int len;
char *str = get_amxstring(amx, params[1], 0, len);
char buffer[33];
const char *hash = hashString((const char *)str, len, Hash_Md5);
MD5 md5;
md5.update((unsigned char *)str, len);
md5.finalize();
md5.hex_digest(buffer);
return set_amxstring(amx, params[2], buffer, 32);
return set_amxstring(amx, params[2], hash, 32);
}
static cell AMX_NATIVE_CALL amx_md5_file(AMX *amx, cell *params)
{
int len = 0;
int len;
char *str = get_amxstring(amx, params[1], 0, len);
char buffer[33];
char file[255];
build_pathname_r(file, sizeof(file)-1, "%s", str);
FILE *fp = fopen(file, "rb");
if (!fp)
const char *hash = hashFile((const char *)file, Hash_Md5);
if (!hash)
{
LogError(amx, AMX_ERR_NATIVE, "Cant open file \"%s\"", file);
return 0;
}
MD5 md5;
md5.update(fp); //closes for you
md5.finalize();
md5.hex_digest(buffer);
return set_amxstring(amx, params[2], hash, 32);
}
return set_amxstring(amx, params[2], buffer, 32);
static cell AMX_NATIVE_CALL amx_hash_string(AMX *amx, cell *params)
{
int len;
char *str = get_amxstring(amx, params[1], 0, len);
HashType type = (HashType)params[2];
const char *hash = hashString((const char *)str, len, type);
if (!hash)
{
LogError(amx, AMX_ERR_NATIVE, "Cant hash string \"%s\"", str);
return 0;
}
return set_amxstring(amx, params[3], hash, params[4]);
}
static cell AMX_NATIVE_CALL amx_hash_file(AMX *amx, cell *params)
{
int len;
char *str = get_amxstring(amx, params[1], 0, len);
char file[255];
build_pathname_r(file, sizeof(file)-1, "%s", str);
HashType type = (HashType)params[2];
const char *hash = hashFile((const char *)file, type);
if (!hash)
{
LogError(amx, AMX_ERR_NATIVE, "Cant open file \"%s\"", file);
return 0;
}
return set_amxstring(amx, params[3], hash, params[4]);
}
static cell AMX_NATIVE_CALL get_pluginsnum(AMX *amx, cell *params)
@ -4535,6 +4558,8 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"log_to_file", log_to_file},
{"md5", amx_md5},
{"md5_file", amx_md5_file},
{"hash_string", amx_hash_string},
{"hash_file", amx_hash_file},
{"module_exists", module_exists},
{"mkdir", amx_mkdir},
{"next_hudchannel", next_hudchannel},