Download MetaTrader 5

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

To add comments, please log in or register
pfx
88
pfx 2014.05.20 12:38  
l00p:

Can you plz explain this...

My install folder is: D:\MT4 Platforms\MT4 NEW

My data folder is: 7C839FAD9F5CD2AF910277D0DD718556

MD5 hash (D:\MT4 Platforms\MT4 NEW) = d510de28146f7af658870ce8e8c1cdb5

MD5 hash (D:\MT4 Platforms\MT4 NEW\) = f91ed39f76c6cadf21bf42a7969cb896

MD5 hash (D:\MT4 PLATFORMS\MT4 NEW\) = 672e300f4b82f2dc2d836de582d96659

MD5 hash (D:\MT4 PLATFORMS\MT4 NEW) = d50360cc7c2266eb97152e0667a8d82e

MD5 hash (d:\mt4 platforms\mt4 new) = cc2639dae0689b2633b7f9afe9df50aa

MD5 hash (d:\mt4 platforms\mt4 new\) = f92a70ba5d49510a7cd669bd6f4a704d

:(

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.


Alain Verleyen
Moderator
31090
Alain Verleyen 2014.05.20 15:23  
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.


Thank you.
Tero
5
Tero 2014.08.05 14:43  
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 having the same problem and unfortunately this doesn't work, using the example above:

Install folder is: D:\MT4 Platforms\MT4 NEW

Uppercase, no slash: D:\MT4 PLATFORMS\MT4 NEW

UTF-8 encoded BASE64 conversion:  RDpcTVQ0IFBMQVRGT1JNU1xNVDQgTkVX

MD5( RDpcTVQ0IFBMQVRGT1JNU1xNVDQgTkVX) = 22d538c2010ec617bccb563ce5128345

 

Which is different from the examples  7C839FAD9F5CD2AF910277D0DD718556. What am I doing wrong ?

Alain Verleyen
Moderator
31090
Alain Verleyen 2014.08.05 15:20  
DrTuner:


I'm having the same problem and unfortunately this doesn't work, using the example above:

Install folder is: D:\MT4 Platforms\MT4 NEW

Uppercase, no slash: D:\MT4 PLATFORMS\MT4 NEW

UTF-8 encoded BASE64 conversion:  RDpcTVQ0IFBMQVRGT1JNU1xNVDQgTkVX

MD5( RDpcTVQ0IFBMQVRGT1JNU1xNVDQgTkVX) = 22d538c2010ec617bccb563ce5128345

 

Which is different from the examples  7C839FAD9F5CD2AF910277D0DD718556. What am I doing wrong ?

Probably UTF-8 which is not the same as unicode :

2. convert to base64 string using unicode encoding

Not tested though.
Tero
5
Tero 2014.08.05 15:52  
angevoyageur:

Probably UTF-8 which is not the same as unicode :

Not tested though.

Unicode is the character set, which I think for the characters in that path is equal to ASCII. UTF-8,16,32 are the encodings.

 

Let's try UTF-16 and UTF-32 as well:

UTF-16 encoded BASE64 conversion: RAA6AFwATQBUADQAIABQAEwAQQBUAEYATwBSAE0AUwBcAE0AVAA0ACAATgBFAFcA

MD5(RAA6AFwATQBUADQAIABQAEwAQQBUAEYATwBSAE0AUwBcAE0AVAA0ACAATgBFAFcA) = a639ffe8ecb997a41b208936140151aa

 

So no match there,  UTF-32:

UTF-32 encoded BASE64 conversion: RAAAADoAAABcAAAATQAAAFQAAAA0AAAAIAAAAFAAAABMAAAAQQAAAFQAAABGAAAATwAAAFIAAABNAAAAUwAAAFwAAABNAAAAVAAAADQAAAAgAAAATgAAAEUAAABXAAAA

MD5(RAAAADoAAABcAAAATQAAAFQAAAA0AAAAIAAAAFAAAABMAAAAQQAAAFQAAABGAAAATwAAAFIAAABNAAAAUwAAAFwAAABNAAAAVAAAADQAAAAgAAAATgAAAEUAAABXAAAA) = 946a6477d3052eec0dc70666f8258879

No luck either.

 

BTW I used http://www5.rptea.com/base64/ and http://md5-hash-online.waraxe.us/ for these.

 I'm currently developing installers for some EA's I've made (somewhat complex ones with dll's and a java runtime) and it's a bit of a pain to ask the user to navigate to the MQL4 directory since it's under the hidden AppData folder. Detecting the folders by looking for origin.txt works somewhat, but I'd still like to have the option to point at an installation directory and figure out the location of the MQL4 directory from there.

 If somebody would have an actual piece of code in any programming language to calculate the md5 hash needed, I'd be much obliged.

JC
1456
JC 2014.08.05 16:30  
DrTuner:

Unicode is the character set, which I think for the characters in that path is equal to ASCII. UTF-8,16,32 are the encodings. [...]

ASCII representation, in hexadecimal bytes, of the string "hello": 68 65 6C 6C 6F. Unicode representation: 68 00 65 00 6C 00 6C 00 6F 00

I haven't yet seen an online MD5 generator which will treat the input text as Unicode, with 2 bytes per character, rather than ASCII. (And I've got no idea why you're trying to use base64.)

Example C# code, adapted from http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx 

string strTest = "C:\\MT4\\TEST";
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes(strTest);   // <!---- NOTE Encoding.Unicode, not Encoding.ASCII, Encoding.UTF8 etc.
byte[] hash = md5.ComputeHash(inputBytes);

StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++) {
  sb.Append(hash[i].ToString("X2"));
}
MessageBox.Show(sb.ToString());
JC
1456
JC 2014.08.05 17:14  
DrTuner:

 If somebody would have an actual piece of code in any programming language to calculate the md5 hash needed, I'd be much obliged.


... or, if you want an MQL4 version, then you can do the following using the MD5 library at https://www.mql5.com/en/code/1553:

#include <MD5Hash.mqh>

void OnStart()
{
   string strTest = "C:\\MT4\\TEST";

   // Convert the string to an ASCII byte array (which will include a terminating zero)
   uchar arrInput[];
   StringToCharArray(strTest, arrInput, 0, WHOLE_ARRAY, CP_ACP);
   
   // Do a horrible pseudo-conversion from ASCII to Unicode by inserting a zero byte after each character
   int szInput = StringLen(strPath);
   uchar arrNastyUnicodeConversion[];
   ArrayResize(arrNastyUnicodeConversion, szInput * 2);
   for (int i = 0; i < szInput; i++) {
      arrNastyUnicodeConversion[i * 2] = arrInput[i];
      arrNastyUnicodeConversion[(i * 2) + 1] = 0;
   }
   
   // Do an MD5 hash of the pseudo-Unicode array
   CMD5Hash md5();
   MessageBox(md5.Hash(arrNastyUnicodeConversion, ArraySize(arrNastyUnicodeConversion)));
}
JC
1456
JC 2014.08.05 17:42  
DrTuner:

[...] a java runtime [...]

(What may be confusing you is that MT4 is Windows software, and in Windows programming "Unicode" is basically synonymous with UTF-16. Hence the fact that .NET has encodings called UTF8, Unicode, and UTF32, not UTF8, UTF16, and UTF32. Similarly, because of the Windows background, the MetaQuotes documentation e.g. at https://docs.mql4.com/convert uses the term Unicode when UTF-16 would be more strictly accurate.)
Tero
5
Tero 2014.08.06 06:50  
jjc:

ASCII representation, in hexadecimal bytes, of the string "hello": 68 65 6C 6C 6F. Unicode representation: 68 00 65 00 6C 00 6C 00 6F 00

I haven't yet seen an online MD5 generator which will treat the input text as Unicode, with 2 bytes per character, rather than ASCII. (And I've got no idea why you're trying to use base64.)

Example C# code, adapted from http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx  


Excellent, Thank You! I found out that the encoding needed in Java is UTF-16LE (UCS-2), UTF-16 inserts a couple of bytes at the beginning. Here's a one-liner of it in Java:

String dataFolderID = Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(installFolder.toUpperCase().getBytes("UTF-16LE"))).toUpperCase(); 

 Works perfectly now. I was using the base64 because of the comment above, probably a mix-up with base64 and ucs-2.

Loopy
6
Loopy 2014.09.09 21:40  
jjc:

ASCII representation, in hexadecimal bytes, of the string "hello": 68 65 6C 6C 6F. Unicode representation: 68 00 65 00 6C 00 6C 00 6F 00

I haven't yet seen an online MD5 generator which will treat the input text as Unicode, with 2 bytes per character, rather than ASCII. (And I've got no idea why you're trying to use base64.)

Example C# code, adapted from http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx 

 


Thank you jjc!
12
To add comments, please log in or register