public static MethodRecord getMRFromFile(string mr_sha) { if (!File.Exists(methodsFolder + "\\" + mr_sha + ".txt")) { DLLServerDownloader.downloadMethodRecord(mr_sha); } string[] lines = System.IO.File.ReadAllLines(methodsFolder + "\\" + mr_sha + ".txt"); string shaR = lines[0]; string shaD = lines[1]; string m = lines[2]; string[] method = m.Split(new char[] { ' ', ')', '(' }); string returnN = method[0]; string classN = method[1]; string rootClassN = method[2]; string methodN = method[3]; string param = method[4]; MethodRecord mr = new MethodRecord(classN, rootClassN, methodN, param, returnN, shaD); return(mr); }
public static string generateVP(List <MethodRecord> records) { StringBuilder sb = new StringBuilder(syn_start); variableC = 0; if (records.Count > 0) { HashSet <string> definedClass = new HashSet <string>(); variableC++; sb.Append(tabBuffer + GenDef(records[records.Count - 1].argType) + "\n"); for (int i = records.Count - 1; i >= 0; i--) { MethodRecord mr = records[i]; variableC++; string fullClassN = mr.className; string[] tClassN = fullClassN.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ClassN = tClassN[tClassN.Length - 1]; if (mr.returnType != "Void") { if (i != records.Count - 1 && mr.argType != records[i + 1].returnType) { variableC--; sb.Append(tabBuffer + DefType(mr.argType)); variableC++; sb.Append(" = (" + mr.argType + ")" + records[i + 1].returnType[0] + (variableC - 1).ToString() + ";\n"); } sb.Append(tabBuffer + DefType(mr.returnType) + " = ((" + mr.className + ")" + globalobjectText + "." + mr.rootClassName + ")." + mr.methodName + "(" + mr.argType[0] + (variableC - 1).ToString() + ");\n"); } else { sb.Append(tabBuffer + "((" + globalobjectText + "." + mr.rootClassName + ")." + "." + mr.methodName + "(" + mr.argType[0] + (variableC - 1).ToString() + ");\n"); } } } sb.Append(syn_end); return(sb.ToString()); }
public static void saveMethod(MethodRecord mr) { if (!Directory.Exists(methodsFolder)) { Directory.CreateDirectory(methodsFolder); } try { System.IO.StreamWriter file = new System.IO.StreamWriter(methodsFolder + @"\" + mr.getSHA() + ".txt"); file.Write(mr.ToString()); file.Close(); } catch (IOException) { } }
public static List <MethodRecord> getDehashedRecords(ConcurrentDictionary <string, MethodRecord> methodSHADictKEYSHA, CST_MSG msg) { List <MethodRecord> mrList = new List <MethodRecord>(); string[] sha_methods = msg.SymT.Split(new char[] { ' ', '(', ')' }, StringSplitOptions.RemoveEmptyEntries); foreach (string method in sha_methods) { string[] partyNameSplit = method.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (partyNameSplit.Length <= 1) { continue; } string stripped_method = partyNameSplit[1]; MethodRecord mr = null; if (!methodSHADictKEYSHA.ContainsKey(stripped_method)) { if (!File.Exists(methodsFolder + @"\" + stripped_method + ".txt")) { DLLServerDownloader.downloadMethodRecord(stripped_method); } mr = MethodHasher.getMRFromFile(stripped_method); } else { mr = methodSHADictKEYSHA[stripped_method]; } if (!Directory.Exists(dllsFolder + @"\" + mr.SHA_of_DLL)) { DLLServerDownloader.downloadDLLandDep(mr.SHA_of_DLL); } mrList.Add(mr); } return(mrList); }
public static List <MethodRecord> getDehashedRecords(string SymT) { List <MethodRecord> mrList = new List <MethodRecord>(); string[] sha_methods = SymT.Split(new char[] { ' ', '(', ')' }, StringSplitOptions.RemoveEmptyEntries); foreach (string method in sha_methods) { string[] partyNameSplit = method.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (partyNameSplit.Length <= 1) { continue; } string stripped_method = partyNameSplit[1]; MethodRecord mr = MethodHasher.getMRFromFile(stripped_method); mrList.Add(mr); } return(mrList); }
public static void recordme(Object o, CST_MSG in_msg, CST_MSG out_msg, MethodInfo mi, string partyName, bool signed, bool server_to_server) { Type objT = o.GetType(); var t = mi.ReflectedType; string rootClass = GetRootClassName(t); string className = objT.FullName; className = className.Replace("\\", string.Empty).Replace('+', '.'); string methodName = mi.Name; ParameterInfo[] pi = mi.GetParameters(); string[] args = new string[pi.Length]; string argType = ""; if (pi.Length > 0) { argType = pi[0].ParameterType.FullName; argType = argType.Replace("\\", string.Empty).Replace('+', '.'); } string returnType = mi.ReturnType.FullName; returnType = returnType.Replace("\\", string.Empty).Replace('+', '.'); string methodkey = returnType + " " + className + " " + rootClass + "." + methodName + "(" + argType + ")"; string sha = "0000000000000000000000000000000000000000"; if (!methodSHADict.ContainsKey(methodkey)) { string dllName = objT.Module.FullyQualifiedName; string path = Path.GetDirectoryName(dllName); string name = Path.GetFileNameWithoutExtension(dllName); var descriptionAttribute = objT.Module.Assembly .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) .OfType <AssemblyDescriptionAttribute>() .FirstOrDefault(); if (descriptionAttribute != null) { sha = descriptionAttribute.Description; } MethodRecord mr = new MethodRecord(className, rootClass, methodName, argType, returnType, name + "." + sha); MethodHasher.saveMethod(mr); uploader.uploadMethodRecord(MethodHasher.methodsFolder + "\\" + mr.getSHA() + ".txt", mr.getSHA()); methodSHADict.AddOrUpdate(methodkey, mr, (k, v) => v); methodSHADictKEYSHA.AddOrUpdate(mr.getSHA(), mr, (k, v) => v); sha = mr.getSHA(); } else { sha = methodSHADict[methodkey].getSHA(); } string colons = ":"; if (signed) { colons = "::"; } string in_msg_symT = in_msg.SymT; if (server_to_server) { int idx = in_msg_symT.IndexOf('('); if (idx != -1) { in_msg_symT = '(' + in_msg_symT.Substring(0, idx) + '(' + in_msg_symT.Substring(idx, in_msg_symT.Length - idx) + "))"; } } out_msg.SymT = partyName + colons + sha + "(" + in_msg_symT + ")"; }