Exetools  

Go Back   Exetools > General > Community Tools

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-22-2018, 19:26
Elesty Elesty is offline
Friend
 
Join Date: Feb 2017
Posts: 9
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 9
Thanks Rcvd at 14 Times in 5 Posts
Elesty Reputation: 0
MD5 replace tool

Hi,

I just wrote a quick tool to patch all occurrences of a file inside a program folder (no matter the file name) given an MD5 checksum.
It is useful when the original files may have different names and are present in multiple sub directories.

Usage:
python replace.py FOLDER MD5_SUM CRACKED_FILE_PATH

Example:
python replace.py 098f6bcd4621d373cade4e832627b4f6 c:\mysoftware license.dll

Where:
-> 098f6bcd4621d373cade4e832627b4f6: is the MD5 of the original files to be replaced by the cracked file. You can get the MD5 checksum by using powershell with the function Get-FileHash -alg md5 ORIGINAL_FILE
-> c:\mysoftware is the folder of the software
-> license.dll is the path to the cracked file

You can also edit the file and set DEBUG_MODE=True to only print the occurrence of the files instead of replacing them.

Compiled version is also available attached.


Code:
import os
import sys
import hashlib
import shutil

DEBUG_MODE=False

if len(sys.argv) < 4:
  print("Usage: python replace.py FOLDER MD5_SUM FILE_PATH_TO_REPLACE_BY")
  sys.exit(-1)

g_path = sys.argv[1]
md5_to_find = sys.argv[2]
to_replace_by = sys.argv[3]

if not os.path.isfile(to_replace_by):
  print("Error: the path of the file to replace by does not exists")
  sys.exit(-1)

def md5sum(fname):
  try:
    hash_md5 = hashlib.md5()
    with open(fname, "rb") as f:
      for chunk in iter(lambda: f.read(4096), b""):
        hash_md5.update(chunk)
    return hash_md5.hexdigest()
  except:
    pass
  return "ERROR"

for root, directories, filenames in os.walk(g_path):
  for filename in filenames:
    full_path = os.path.join(root, filename)
    checksum = md5sum(full_path)
    #print(full_path, md5sum(full_path))
    if not DEBUG_MODE and checksum == md5_to_find:
      print("Replacing [%s] by [%s]" % (full_path, to_replace_by))
      shutil.copy(to_replace_by, full_path)
    elif checksum == md5_to_find:
      print("Should replace [%s] by [%s]" %  (full_path, to_replace_by))
Attached Files
File Type: 7z replace.7z (4.81 MB, 56 views)
Reply With Quote
The Following 2 Users Say Thank You to Elesty For This Useful Post:
Indigo (07-19-2019)
 

Thread Tools
Display Modes

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any tool to replace the files packed in the NullSoft Install System package? BlackWhite General Discussion 4 09-02-2018 00:27
OllyCapstone :OllyDbg1.10 plugin to replace its original disasm engine with Capstone sh3dow Community Tools 3 09-27-2015 01:54
Search and Replace? prejker General Discussion 6 05-28-2004 23:32
how to replace kernel32.dll in win2k/xp tAz General Discussion 12 02-06-2004 03:46


All times are GMT +8. The time now is 18:04.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )