本文整理汇总了C#中System.Xml.XmlNode.GetSubNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.GetSubNode方法的具体用法?C# XmlNode.GetSubNode怎么用?C# XmlNode.GetSubNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNode
的用法示例。
在下文中一共展示了XmlNode.GetSubNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractMethodCall
public MethodCall ExtractMethodCall(XmlNode node, IVariableStorage varStorage, AnalysisScope scope = AnalysisScope.File)
{
int startLine = AstNode.GetStartLine(node);
int endLine = AstNode.GetEndLine(node);
string methodName = "";
//Get the varNode which includes either (new ClassName())->MethodName or $var->MethodName
var varNode = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Var);
var classNames = new List<string>();
if (varNode.FirstChild.LocalName == AstConstants.Nodes.Expr_New)
{
//PHP: (new ClassName(args))->MethodName(args);
//Extract the ClassName directly, in this case there can be only one ClassName!
var className = varNode.FirstChild
.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Class)
.GetSubNode(AstConstants.Node + ":" + AstConstants.Nodes.Name)
.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Parts).FirstChild.FirstChild.InnerText;
classNames.Add(className);
methodName = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Name).InnerText;
return new MethodCall(methodName, classNames, node, startLine, endLine) { Arguments = ExtractArgumentNodes(node) };
}
else
{
//PHP: $var->MethodName(args);
//Resolve the variable, and get all the possible class names!
VariableResolver vr = new VariableResolver(varStorage, scope);
VariableResolveResult variableResult = null;
if (vr.IsResolvableNode(varNode.FirstChild))
{
variableResult = vr.ResolveVariable(varNode.FirstChild);
classNames.AddRange(variableResult.Variable.Info.ClassNames.Where(className => !classNames.Contains(className)));
}
var nameSubnode = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Name);
XmlNode nameNode = null;
bool success = nameSubnode.TryGetSubNode(AstConstants.Node + ":" + AstConstants.Nodes.Name, out nameNode);
if (success)
{
methodName = nameNode.InnerText;
}
else
{
if (nameSubnode.FirstChild.LocalName == AstConstants.Scalars.String)
{
methodName = nameSubnode.FirstChild.InnerText;
}
}
return variableResult == null ?
new MethodCall(methodName, classNames, node, startLine, endLine) { Arguments = ExtractArgumentNodes(node) } :
new MethodCall(methodName, classNames, node, startLine, endLine, variableResult.Variable) { Arguments = ExtractArgumentNodes(node) };
}
}
示例2: GetCondNode
public static XmlNode GetCondNode(XmlNode node)
{
Preconditions.NotNull(node, "node");
Preconditions.IsTrue(NodesWithCondSubNode.Contains(node.LocalName),
"Expected node representing conditional statement. Received a " + node.Name);
return node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Cond);
}
示例3: GetStringValue
public static string GetStringValue(XmlNode node)
{
Preconditions.NotNull(node, "node");
Preconditions.IsTrue(node.Name == AstConstants.Node + ":" + AstConstants.Nodes.Scalar_String, "String value retrieval only supported for " + AstConstants.Nodes.Scalar_String + " nodes. Was " + node.Name, "node");
return node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Value)
.GetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.String).InnerText;
}
示例4: GetLValue
public static int GetLValue(XmlNode node)
{
Preconditions.NotNull(node, "node");
Preconditions.IsTrue(node.Name == AstConstants.Node + ":" + AstConstants.Nodes.Scalar_LNumber, "LValue retrieval only supported for " + AstConstants.Nodes.Scalar_LNumber + " nodes. Was " + node.Name, "node");
var innerText = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Value)
.GetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.Int).InnerText;
return int.Parse(innerText);
}
示例5: GetDValue
public static double GetDValue(XmlNode node)
{
Preconditions.NotNull(node, "Node");
Preconditions.IsTrue(node.Name == AstConstants.Node + ":" + AstConstants.Nodes.Scalar_DNumber, "DValue retrieval only supported for " + AstConstants.Nodes.Scalar_DNumber + " nodes. Was " + node.Name, "node");
var innerText = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Value)
.GetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.Float).InnerText;
return double.Parse(innerText, CultureInfo.InvariantCulture);
}
示例6: GetVariables
public static IEnumerable<XmlNode> GetVariables(XmlNode node)
{
Preconditions.NotNull(node, "node");
Preconditions.IsTrue(node.Name == AstConstants.Node + ":" + AstConstants.Nodes.Stmt_Global,
"Node has to be a global statement. It was: " + node.Name, "node");
var variables = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Vars)
.GetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.Array)
.GetSubnodes(AstConstants.Node + ":" + AstConstants.Nodes.Expr_Variable);
return variables;
}
示例7: ExtractFunctionCall
public FunctionCall ExtractFunctionCall(XmlNode node)
{
int startLine = AstNode.GetStartLine(node);
int endLine = AstNode.GetEndLine(node);
string funcName = "";
XmlNode nameSubNode = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Name);
XmlNode nameNode = null;
bool success = nameSubNode.TryGetSubNode(AstConstants.Node + ":" + AstConstants.Nodes.Name, out nameNode);
if (success)
{
funcName = nameNode.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Parts).InnerText;
}
return new FunctionCall(funcName, node, startLine, endLine) { Arguments = ExtractArgumentNodes(node) };
}
示例8: TryGetVariableName
/// <summary>
/// Tries to get the variables name. This will only work if the variable name is static.
/// <example>$var : will be 'var'</example>
/// <example>$$var : will fail.</example>
/// </summary>
public static bool TryGetVariableName(XmlNode node, out string varName)
{
Preconditions.NotNull(node, "node");
Preconditions.IsTrue(node.Name == AstConstants.Node + ":" + AstConstants.Nodes.Expr_Variable,
"Node has to be an Expression Variable. It was: " + node.Name, "node");
var nameNode = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Name);
if (nameNode.TryGetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.String, out nameNode))
{
varName = nameNode.InnerText;
return true;
}
varName = null;
return false;
}
示例9: Node_Expr_Assign
private ExpressionInfo Node_Expr_Assign(XmlNode node)
{
var rhsExpr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Expr);
var rhsTaint = Analyze(rhsExpr);
var lhsExpr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Var);
Variable variable;
if (_varResolver.IsResolvableNode(lhsExpr.FirstChild))
{
variable = _varResolver.ResolveVariable(lhsExpr.FirstChild).Variable;
}
else
{
// LHS of assignment is not necessarily something we support. E.g. list(..,..) = ...
// In that case we use a "dummy" variable
variable = new Variable("$UNKNOWN$", _analysisScope.ToVariableScope());
}
var rhsExprNodes = rhsExpr.GetSubNodesByPrefix(AstConstants.Node);
if (rhsExprNodes.Any())
{
var rhsExprNode = rhsExprNodes.Single();
if (_varResolver.IsResolvableNode(rhsExprNode))
{
// If simple var to var assignment, move relevant var info to lhs variabel
var rhsVariable = _varResolver.ResolveVariable(rhsExprNode).Variable;
variable.Info = rhsVariable.Info.AssignmentClone();
return rhsTaint;
}
if (rhsTaint.ValueInfo.Value != null)
{
variable.Info.Value = rhsTaint.ValueInfo.Value;
variable.Info.Type = rhsTaint.ValueInfo.Type;
variable.Info.ClassNames.AddRange(rhsTaint.ValueInfo.ClassNames);
}
}
variable.Info = variable.Info.Merge(rhsTaint.ValueInfo);
if (rhsTaint.ValueInfo.Equals(new ValueInfo())) // HACK - Hacky way of determining if it hasn't been changed.
{
variable.Info.Taints = rhsTaint.ExpressionTaint;
variable.Info.PossibleStoredTaint = rhsTaint.ExpressionStoredTaint;
variable.Info.Type = rhsTaint.ValueInfo.Type;
variable.Info.ClassNames.AddRange(rhsTaint.ValueInfo.ClassNames);
return rhsTaint;
}
variable.Info = rhsTaint.ValueInfo.AssignmentClone();
return rhsTaint;
}
示例10: Node_Echo
private ExpressionInfo Node_Echo(XmlNode node)
{
var taintResult = Analyze(node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Exprs));
CheckForXssVulnerabilities(taintResult, node);
return new ExpressionInfo();
}
示例11: Expr_UnaryOp_AlwaysSafe
private ExpressionInfo Expr_UnaryOp_AlwaysSafe(XmlNode node)
{
var expr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Expr);
Analyze(expr);
return new ExpressionInfo();
}
示例12: Expr_Include
private ExpressionInfo Expr_Include(XmlNode node)
{
var inclExpr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Expr);
Analyze(inclExpr);
File file;
if (_inclusionResolver.TryResolveInclude(node, out file))
{
if (!_analysisStacks.IncludeStack.Contains(file))
{
Console.WriteLine(">> Resolved " + file.Name + ". Starting analysis.");
_analysisStacks.IncludeStack.Push(file);
var result = _analyzer(ImmutableVariableStorage.CreateFromMutable(_variableStorage), _inclusionResolver, _analysisScope, _analysisStacks);
this._variableStorage = result.Merge(ImmutableVariableStorage.CreateFromMutable(this._variableStorage)).ToMutable();
_analysisStacks.IncludeStack.Pop();
Console.WriteLine(">> Finished " + file.Name + ". Continuing.");
}
}
return new ExpressionInfo();
}
示例13: Expr_Exit
private ExpressionInfo Expr_Exit(XmlNode node)
{
var exprNode = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Expr);
var expressionTaint = Analyze(exprNode);
CheckForXssVulnerabilities(expressionTaint, node);
return new ExpressionInfo();
}
示例14: Expr_BinaryOp_NonSpecial_AlwaysSafe
private ExpressionInfo Expr_BinaryOp_NonSpecial_AlwaysSafe(XmlNode node)
{
XmlNode leftExpr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Left);
Analyze(leftExpr);
XmlNode rightExpr = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Right);
Analyze(rightExpr);
return new ExpressionInfo();
}
示例15: Scalar_Encapsed
private ExpressionInfo Scalar_Encapsed(XmlNode node)
{
var partsArray = node.GetSubNode(AstConstants.Subnode + ":" + AstConstants.Subnodes.Parts)
.GetSubNode(AstConstants.Scalar + ":" + AstConstants.Scalars.Array);
var encapsedParts = partsArray.GetSubNodesByPrefixes(AstConstants.Node, AstConstants.Scalar);
var result = new ExpressionInfo();
foreach (var partResult in encapsedParts.Select(Analyze))
{
result.ExpressionTaint = result.ExpressionTaint.Merge(partResult.ExpressionTaint);
result.ValueInfo.Value = result.ValueInfo.Value + partResult.ValueInfo.Value;
}
return result;
}