How do I find Byte patterns in a byte array, and represent them if it's available in checkedlistbox in C#?
I am trying to make software to search for byte patterns, I have many bin files and many patterns to search. If the pattern exists on the file. it will represent it on CheckedListBox with a specific name . and if the checked box is unchecked for a particular one , it will replace the pattern with 0000000000 on the saved file. For example, I have this pattern to search (note that I have more than 100 patterns to search): {"2004940101000078", "3004940101000078", "3E04940101000028", .... ,.... }
{"2004940101000078", "3004940101000078", "3E04940101000028", .... ,.... }
replace 2004940101000078 with 0000000000000000
I tried with this code to search for the patterns, but its give the offset position of the pattern only. please this code-only example and part of my codes. if you have a solution or other code or way. please help, I am new in C#
string hex2 = BitConverter.ToString(byteArray).Replace("-", string.Empty); string[] patterns = {"2004940101000078", "3004940101000078", "3E04940101000028" }; foreach (string p in patterns) { int i = 0; int indice = 0; // teminate loop when no more occurrence is found; while (indice != -1) { // index if the pattern is found AFTER i position, -1 if not indice = hex2.IndexOf(p, i); i = indice + 0; // skip the pattern occurrence itself int indexxx = (i / 2); //Transform the index into hexadecimal string outputHex = int.Parse(indexxx.ToString()).ToString("X"); //Output the index as an hexadecimal offset address MessageBox.Show("0x" + outputHex); break; } }