EA Install and setting a path to custom indicators - page 3

 
pfx:

This is how I got it to work in c#.

  1. convert path to uppercase with no trailing slash
  2. convert to base64 string using unicode encoding
  3. MD5 has the result from step 2
Hope that helps ya.


I'm trying to do that with c#, but I fail :

var tmpPath = @"C:\Path-to-installation" ; // dynamic value with no slash at the end of string
var inpMql = tmpPath.ToUpper();
var inpBytes = Convert.ToBase64String(Encoding.ASCII.GetBytes(inpMql));
MD5 md5 = new MD5CryptoServiceProvider();
byte[] textToHash = Encoding.Unicode.GetBytes(inpBytes);
byte[] result = md5.ComputeHash(textToHash);
var output = BitConverter.ToString(result).Replace("-", "").ToLower();

I've used another encoding for GetBytes , but I failed on them too.

Do you know what is wrong? (or, How do you done it with c# ?)

 

This is how to do it in Python:

>>> import hashlib

>>> m = hashlib.md5("C:\PROGRAM FILES\METATRADER 4 TELETRADE".encode('utf-16LE'))

>>> m.hexdigest()
 

this is the function for c#:

public static string CalculateMD5Hash(string input)
        {
            // step 1, calculate MD5 hash from input
            input = input.ToUpper();
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
 

Here's a favor for python programmers out there ;)

result = hashlib.md5("C:\Program Files (x86)\Your Installation Folder".encode('utf-16-le').upper()).hexdigest()
data_folder = result.upper()

# You can also get %APPDATA% using os.getenv('APPDATA') and easily construct the absolute path. 
 

One liner in git-bash

echo -n "C:\Program Files (x86)\Pepperstone MetaTrader 4" | tr a-z A-Z | iconv -t UTF-16LE | md5sum | tr a-f A-F
 
Does anyone know how to do this in powershell?
 

Here's what worked for me in PowerShell.


function Get-MD5Hash {
    param (
        [string]$inputString
    )

    $md5 = [System.Security.Cryptography.MD5]::Create()
    $utf16 = [System.Text.Encoding]::Unicode.GetBytes($inputString)
    $hash = $md5.ComputeHash($utf16)
    $hashString = [System.BitConverter]::ToString($hash).Replace("-", "").ToUpper()
    return $hashString
}
 
Any idea how to do it in Inno setup (Pascal scripting)?
 
Adam Sowiński #:
Any idea how to do it in Inno setup (Pascal scripting)?

Actually, with Inno setup PowerShell version above is enough.