public int ClearContent(DCILGroup group) { for (int iCount = group.StartLineIndex; iCount <= group.EndLineIndex; iCount++) { this.SourceLines[iCount] = string.Empty; } return(group.EndLineIndex - group.StartLineIndex); }
private void ReadAllDefines(DCILGroup rootGroup, int startLineIndex) { int lineNum = this.SourceLines.Length; //List<StringDefine> strDefines = new List<StringDefine>(); string currentMethodName = null; if (rootGroup.Type == Name_method) { currentMethodName = rootGroup.Name; } int currentLevel = 0; for (int iCount = startLineIndex; iCount < lineNum; iCount++) { var line = this.SourceLines[iCount]; if (line.Length == 0) { continue; } //if( line.IndexOf(".class") >= 0 ) //{ //} string firstWord = null; int firstCharIndex = line.Length; for (int iCount2 = 0; iCount2 < firstCharIndex; iCount2++) { var c = line[iCount2]; if (c != ' ' && c != '\t') { for (int iCount3 = iCount2 + 1; iCount3 < firstCharIndex; iCount3++) { var c2 = line[iCount3]; if (c2 == ' ' || c2 == '\t') { firstWord = line.Substring(iCount2, iCount3 - iCount2); break; } } if (firstWord == null) { firstWord = line.Substring(iCount2); } firstCharIndex = iCount2; break; } } if (firstWord == null || firstWord.Length == 0) { // 完全的空白行 continue; } if (firstWord.StartsWith("IL_", StringComparison.Ordinal)) { // 执行代码行 string strOperData = null; string strLabelID = null; string strILCode = GetILCode(line, ref strLabelID, ref strOperData); if (strOperData == null || strOperData.Length == 0) { continue; } if (strILCode == "call") { //if (strOperData.StartsWith("string", StringComparison.Ordinal)) //{ // string methodName = strOperData.Substring(7).Trim(); // if (methodName[0] != '[') // { // int index9 = methodName.IndexOf("::"); // if (index9 > 0) // { // string typeName = methodName.Substring(0, index9); // string mn2 = methodName.Substring(index9 + 2); // int index10 = mn2.IndexOf('('); // mn2 = mn2.Substring(0, index10); // if (mn2.StartsWith("get_", StringComparison.Ordinal)) // { // StringResourceFileDefine file = null; // if (_StrResourceFiles.TryGetValue(typeName, out file)) // { // file.References[iCount] = mn2.Substring(4); // } // } // } // } //} } else if (strILCode == "newobj") { if (strOperData.Contains("ComponentResourceManager::.ctor") && rootGroup.Name == "InitializeComponent") { var line2 = this.SourceLines[iCount - 2]; string labelID2 = null; string operData2 = null; string operCode2 = GetILCode(line2, ref labelID2, ref operData2); if (operCode2 == "ldtoken") { ComponentResourceManagerInfo info = new ComponentResourceManagerInfo(); info.LineIndex = iCount; info.Method = (DCILMethod)rootGroup; info.ClassName = operData2; this.ComponentResourceManagers.Add(info); } } } else if (strILCode == "ldstr") { var strDif = new DCStringValueDefine(); strDif.NativeSourcde = this.SourceLines[iCount]; strDif.LabelID = strLabelID; strDif.MethodName = currentMethodName; strDif.LineIndex = iCount; strDif.EndLineIndex = iCount; if (strOperData[0] == '"') { strDif.IsBinary = false; if (strOperData.Length == 2 && strOperData[1] == '"') { // use string.Empty this.SourceLines[iCount] = strLabelID + ":ldsfld string [" + this.LibName_mscorlib + "]System.String::Empty"; this.ModifiedCount++; continue; } var strFinalValue = new StringBuilder(); GetFinalValue(strOperData, strFinalValue); for (int iCount2 = iCount + 1; iCount2 < lineNum; iCount2++) { string line2 = this.SourceLines[iCount2].Trim(); if (line2.Length > 0 && line2[0] == '+') { //line2 = RemoveComment(line2).Trim(); strOperData = strOperData + Environment.NewLine + line2; GetFinalValue(line2, strFinalValue); strDif.EndLineIndex = iCount2; iCount++; } else { break; } } strDif.Value = strOperData; strDif.FinalValue = strFinalValue.ToString(); } else if (strOperData.StartsWith("bytearray", StringComparison.Ordinal)) { _HexCharNum = 0; strDif.IsBinary = true; bool hasFinish = false; var strOperDataLength = strOperData.Length; for (int iCount2 = 9; iCount2 < strOperDataLength; iCount2++) { char c = strOperData[iCount2]; if (AddHexChar(c) == false) { if (c == ')') { hasFinish = true; break; } else if (c == '/') { break; } } } if (hasFinish) { // 光靠一行就结束了 strDif.Value = GetHexString(); } else { for (iCount++; iCount < lineNum; iCount++) { string line2 = this.SourceLines[iCount]; int len2 = line2.Length; for (int iCount4 = 0; iCount4 < len2; iCount4++) { var c = line2[iCount4]; if (AddHexChar(c) == false) { if (c == '/') { // 开始注释 break; } else if (c == ')') { // 结束定义字符串 strDif.EndLineIndex = iCount; goto EndReadStringDefine; } } } } EndReadStringDefine :; strDif.Value = GetHexString(); } var bsText = HexToBinary(strDif.Value); if (bsText != null && bsText.Length > 0) { strDif.FinalValue = Encoding.Unicode.GetString(bsText); } else { strDif.FinalValue = string.Empty; } } if (strDif.FinalValue == null) { } if (strDif.FinalValue == SecurityMethodFlags && rootGroup is DCILMethod) { // is Securty method var method9 = (DCILMethod)rootGroup; if (method9.ReturnType == "string") { this.SecurityMethods.Add(new Tuple <DCILMethod, int>((DCILMethod)rootGroup, iCount)); strDif.FinalValue = DateTime.Now.Second.ToString(); strDif.Value = '"' + strDif.FinalValue + '"'; } } this.StringDefines.Add(strDif); if (iCount < lineNum && currentMethodName == ".cctor") { string nextLine = this.SourceLines[iCount + 1]; strILCode = GetILCode(nextLine, ref strLabelID, ref strOperData); if (strILCode == "stsfld") { strDif.IsSetStaticField = true; } } } } else if (firstWord == ".field") { for (int iCount9 = iCount + 1; iCount9 < lineNum; iCount9++) { var line9 = this.SourceLines[iCount9]; if (IsEmptyLine(line9) == false) { if (line9.Contains(".field")) { ((DCILClass)rootGroup).FieldLineIndexs.Add(iCount); } break; } } } else if (firstWord == Name_method || firstWord == Name_class || firstWord == Name_property) { currentMethodName = null; DCILGroup group = null; if (firstWord == Name_method) { group = new DCILMethod(); } else if (firstWord == Name_property) { group = new DCILProperty(); } else { group = new DCILClass(); this.AllClasses.Add((DCILClass)group); } group.OwnerDocument = this; group.Type = firstWord; this.AllGroups.Add(group); group.StartLineIndex = iCount; group.Level = rootGroup.Level + 1; var strHeader = new StringBuilder(); strHeader.Append(line); for (int iCount2 = iCount + 1; iCount2 < lineNum; iCount2++) { var line2 = this.SourceLines[iCount2].Trim(); if (line2.Length > 0 && line2[0] == '{') { group.BodyLineIndex = iCount2; break; } strHeader.Append(' '); strHeader.Append(line2); } group.SetHeader(strHeader.ToString()); rootGroup.ChildNodes.Add(group); int back = this.ComponentResourceManagers.Count; ReadAllDefines(group, group.BodyLineIndex + 1); iCount = group.EndLineIndex; } else if (firstWord == Name_get) { if (rootGroup is DCILProperty) { ((DCILProperty)rootGroup).HasGetMethod = true; } } else if (firstWord == Name_set) { if (rootGroup is DCILProperty) { ((DCILProperty)rootGroup).HasSetMethod = true; } } else if (firstWord == Name_mresource) { var items = SplitByWhitespace(line); string name = items[items.Count - 1]; if (name.EndsWith(EXT_resources)) { name = name.Substring(0, name.Length - EXT_resources.Length); var file = new DCILMResource(); file.Name = name; file.OwnerDocument = this; file.StartLineIndex = iCount; for (iCount++; iCount < lineNum; iCount++) { var line2 = this.SourceLines[iCount].Trim(); if (line2.StartsWith("}")) { file.EndLineIndex = iCount; break; } } //_StrResourceFiles[name] = file; this.ResouceFiles[name] = file; } } else if (firstWord[0] == '{') { // 进入一个代码组 currentLevel++; } else if (firstWord[0] == '}') { // 退出一个代码组 currentLevel--; if (currentLevel < 0) { rootGroup.EndLineIndex = iCount; return; } } else if (firstWord == Name_custom) { var strHeader = new StringBuilder(); bool hasEqualOper = false; int startLineIndex2 = iCount; for (; iCount < lineNum; iCount++) { var line2 = RemoveComment(this.SourceLines[iCount]).Trim(); strHeader.Append(line2); if (hasEqualOper == false && line2.IndexOf('=') > 0) { hasEqualOper = true; } if (hasEqualOper) { if (line2.EndsWith(")")) { break; } } } var attr = new DCILCustomAttribute(); attr.OwnerDocument = this; attr.SetHeader(strHeader.ToString()); attr.StartLineIndex = startLineIndex2; attr.EndLineIndex = iCount; if (rootGroup.CustomAttributes == null) { rootGroup.CustomAttributes = new List <DCILCustomAttribute>(); } rootGroup.CustomAttributes.Add(attr); } else if (firstWord == ".assembly") { var words = SplitByWhitespace(line); if (words.Count == 3) { var asmName = words[2]; this.ReferenceAssemblies.Add(asmName); if (this.LibName_mscorlib == null) { if (asmName == "System.Runtime" || asmName == "mscorlib") { this.LibName_mscorlib = asmName; } } } } } }