private string GetLineId(AsmCode asmLine) { int index = mLines.IndexOf(asmLine); int distFromLabel = 0; string lineId = ""; for (; index > -1; index--) { if (mLines[index] is AsmLabel) { lineId = mLines[index].ToString(); break; } else { distFromLabel++; } } lineId += "_" + distFromLabel.ToString(); return(lineId); }
//protected void Parse() //{ // string xCode = Encoding.UTF8.GetString(mData); // // Should always be \r\n, but just in case we split by \n and ignore \r // string[] xLines = xCode.Replace("\r", "").Split('\n'); // if (xLines.Length >= 3) // { // // First line is not code, but the current label and inserted by caller // // Second line is input parameters // mCurrentLabel = xLines[0]; // mParams = xLines[1].Split('|'); // mFilterLabels = xLines[2].Split('|'); // bool xSetNextLabelToCurrent = false; // int nextCodeDistFromCurrent = 0; // bool foundCurrentLine = false; // AsmLabel xLastAsmAsmLabel = null; // for (int i = 3; i < xLines.Length; i++) // { // string xLine = xLines[i].Trim(); // string xTestLine = xLine.ToUpper(); // var xParts = xLine.Split(' '); // // Skip certain items we never care about. ie remove noise // if (xLine.Length == 0) // { // // Remove all empty lines because we completely reformat output. // // Parse below also expects some data, not empty string. // continue; // } // if (xParts[0].EndsWith(":")) // { // Label // string xLabel = xParts[0].Substring(0, xParts[0].Length - 1); // var xAsmLabel = new AsmLabel(xLabel); // // See if the label has a comment/tag // if (xParts.Length > 1) // { // xAsmLabel.Comment = xParts[1].Substring(1).Trim(); // // If its an ASM tag, store it for future use to attach to next AsmCode // if (xAsmLabel.Comment.ToUpper() == "ASM") // { // xLastAsmAsmLabel = xAsmLabel; // } // } // mLines.Add(xAsmLabel); // } // else if (xTestLine.StartsWith(";")) // { // Comment // string xComment = xLine.Trim().Substring(1).Trim(); // mLines.Add(new AsmComment(xComment)); // } // else // { // Code // var xAsmCode = new AsmCode(xLine); // xAsmCode.AsmLabel = xLastAsmAsmLabel; // xLastAsmAsmLabel = null; // if (xSetNextLabelToCurrent) // { // mCurrentLabel = xAsmCode.AsmLabel.Label; // xSetNextLabelToCurrent = false; // } // //If its Int3 or so, we need to set the current label to the next non debug op. // //And we don't want to add debug code to our parsed stuff - it shouldn't be displayed. // if (xAsmCode.IsDebugCode) // { // bool skip = true; // if (xAsmCode.LabelMatches(mCurrentLabel)) // { // xSetNextLabelToCurrent = true; // } // else // { // //Allow debug NOPs that have not been set to INT3 to be shown // if(xAsmCode.Text.Trim().ToUpper().StartsWith("NOP")) // { // if (!mFilterLabels.Contains(xAsmCode.AsmLabel.Label)) // { // skip = false; // } // } // } // if (skip) // { // //Skip adding Debug Code (INT3s) to parsed list // continue; // } // } // //If we want to filter this label because it is a debug INT3/NOP but not a permanent INT3 // if (xAsmCode.AsmLabel != null && mFilterLabels.Contains(xAsmCode.AsmLabel.Label)) // { // if (xAsmCode.LabelMatches(mCurrentLabel)) // { // xSetNextLabelToCurrent = true; // } // //Skip adding Debug Code (INT3s) to parsed list // continue; // } // if (foundCurrentLine) // { // nextCodeDistFromCurrent++; // } // if (nextCodeDistFromCurrent == 1) // { // Global.PipeUp.SendCommand(Windows2Debugger.NextASMLine1, xAsmCode.Text); // Global.PipeUp.SendCommand(Windows2Debugger.NextLabel1, xAsmCode.AsmLabel.Label); // } // else if (!foundCurrentLine && xAsmCode.LabelMatches(mCurrentLabel)) // { // //Current line of code found // Global.PipeUp.SendCommand(Windows2Debugger.CurrentASMLine, xAsmCode.Text); // Global.PipeUp.SendCommand(Windows2Debugger.NextASMLine1, new byte[0]); // foundCurrentLine = true; // } // mLines.Add(xAsmCode); // } // } // } //} protected void Parse() { Log("Start parsing {0} bytes", mData.Length); string xCode = Encoding.UTF8.GetString(mData); // Should always be \r\n, but just in case we split by \n and ignore \r string[] xLines = xCode.Replace("\r", "").Split('\n'); // First line of packet is not code, but the current label and inserted by caller. mCurrentLabel = xLines[0]; bool xSetNextLabelToCurrent = false; AsmLabel xLastAsmAsmLabel = null; for (int i = 1; i < xLines.Length; i++) { string xLine = xLines[i].Trim(); Log("Parsing line '{0}'", xLine); string xTestLine = xLine.ToUpper(); var xParts = xLine.Split(' '); // Skip certain items we never care about. ie remove noise if (xLine.Length == 0) { // Remove all empty lines because we completely reformat output. // Parse below also expects some data, not empty string. continue; } if (xParts[0].EndsWith(":")) { // Label string xLabel = xParts[0].Substring(0, xParts[0].Length - 1); var xAsmLabel = new AsmLabel(xLabel); // See if the label has a comment/tag if (xParts.Length > 1) { xAsmLabel.Comment = xParts[1].Substring(1).Trim(); // If its an ASM tag, store it for future use to attach to next AsmCode if (xAsmLabel.Comment.ToUpper() == "ASM") { xLastAsmAsmLabel = xAsmLabel; } } mLines.Add(xAsmLabel); } else if (xTestLine.StartsWith(";")) { // Comment string xComment = xLine.Trim().Substring(1).Trim(); mLines.Add(new AsmComment(xComment)); } else { // Code var xAsmCode = new AsmCode(xLine); xAsmCode.AsmLabel = xLastAsmAsmLabel; xLastAsmAsmLabel = null; if (xSetNextLabelToCurrent) { mCurrentLabel = xAsmCode.AsmLabel.Label; xSetNextLabelToCurrent = false; } // If its Int3 or so, we need to set the current label to the next non debug op. if (xAsmCode.IsDebugCode) { if (xAsmCode.LabelMatches(mCurrentLabel)) { xSetNextLabelToCurrent = true; } continue; } mLines.Add(xAsmCode); } } }
private string GetLineId(AsmCode asmLine) { int index = mLines.IndexOf(asmLine); int distFromLabel = 0; string lineId = ""; for (; index > -1; index--) { if (mLines[index] is AsmLabel) { lineId = mLines[index].ToString(); break; } else { distFromLabel++; } } lineId += "_" + distFromLabel.ToString(); return lineId; }