Raised This Month: $32 Target: $400
 8% 

[ANY] MD5 Stocks for both files and strings.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thomasjosif
AlliedModders Donor
Join Date: Mar 2016
Old 12-25-2017 , 13:06   [ANY] MD5 Stocks for both files and strings.
Reply With Quote #1

Couldn't find a way to get the MD5 hash of a file without extensions, so I did it myself. Someone could probably find it useful. (I'm using it to verify downloaded files.) It could be improved but was short on time.

Note: All I did was split up the MD5 function for it to be able to work with files.

Have fun.

PHP Code:
// Quick test of md5 functions.
#include <sourcemod>
#include <md5stocks>

public void OnPluginStart()
{
    
char path[PLATFORM_MAX_PATH];
    
char md5[512];
    
BuildPath(Path_SMpathsizeof(path), "/plugins/md5.smx");
    if(
MD5_File(pathmd5sizeof(md5)))
    {
        
PrintToServer("****** MD5 FILE ******");
        
PrintToServer(md5);
        
PrintToServer("****** MD5 FILE ******");
    }
    else
        
PrintToServer("**** FILE NOT FOUND ****");

include file
__________________
Systems Admin @ http://hellsgamers.com
thomasjosif is offline
lake393
AlliedModders Donor
Join Date: Oct 2008
Old 04-09-2018 , 01:07   Re: [ANY] MD5 Stocks for both files and strings.
Reply With Quote #2

Fixed issue with MD5_File not working on Windows machines.

Updated include file attached.
Attached Files
File Type: inc md5stocks.inc (9.5 KB, 241 views)
__________________
HellsGamers|Founder 2005.
MotdMod Server Plugin|MD5_File.inc
lake393 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 04-09-2018 , 05:09   Re: [ANY] MD5 Stocks for both files and strings.
Reply With Quote #3

To clarify on the MD5_File issue, OpenFile is implied to open in text mode by default.

This is an issue on Windows as any read newline \n characters will be read as the Windows \r\n line ending, causing the hash to be different.

The only change was to explicitly open the file in binary read mode "rb" instead.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode