private void setParameter(NativeCodeSequence nativeCodeSequence, int parameter, string valueString) { if (string.ReferenceEquals(valueString, null) || valueString.Length <= 0) { nativeCodeSequence.setParameter(parameter, 0, false); return; } for (int i = 0; i < Common.gprNames.Length; i++) { if (Common.gprNames[i].Equals(valueString)) { nativeCodeSequence.setParameter(parameter, i, false); return; } } for (int i = 0; i < Common.fprNames.Length; i++) { if (Common.fprNames[i].Equals(valueString)) { nativeCodeSequence.setParameter(parameter, i, false); return; } } if (valueString.StartsWith("@", StringComparison.Ordinal)) { string label = valueString.Substring(1); int labelIndex = nativeCodeSequence.getLabelIndex(label); if (labelIndex >= 0) { nativeCodeSequence.setParameter(parameter, labelIndex, true); return; } } try { int value; if (valueString.StartsWith("0x", StringComparison.Ordinal)) { value = Convert.ToInt32(valueString.Substring(2), 16); } else { value = int.Parse(valueString); } nativeCodeSequence.setParameter(parameter, value, false); } catch (System.FormatException e) { Compiler.Console.WriteLine(e); } }
private void loadNativeCodeSequence(Element element) { string name = element.getAttribute("name"); string className = getContent(element.getElementsByTagName("Class")); Type <INativeCodeSequence> nativeCodeSequenceClass = getNativeCodeSequenceClass(className); if (nativeCodeSequenceClass == null) { return; } NativeCodeSequence nativeCodeSequence = new NativeCodeSequence(name, nativeCodeSequenceClass); string isReturningString = getContent(element.getElementsByTagName("IsReturning")); if (!string.ReferenceEquals(isReturningString, null)) { nativeCodeSequence.Returning = bool.Parse(isReturningString); } string wholeCodeBlockString = getContent(element.getElementsByTagName("WholeCodeBlock")); if (!string.ReferenceEquals(wholeCodeBlockString, null)) { nativeCodeSequence.WholeCodeBlock = bool.Parse(wholeCodeBlockString); } string methodName = getContent(element.getElementsByTagName("Method")); if (!string.ReferenceEquals(methodName, null)) { nativeCodeSequence.MethodName = methodName; } string isHookString = getContent(element.getElementsByTagName("IsHook")); if (!string.ReferenceEquals(isHookString, null)) { nativeCodeSequence.Hook = bool.Parse(isHookString); } string isMethodRetuningString = getContent(element.getElementsByTagName("IsMethodReturning")); if (!string.ReferenceEquals(isMethodRetuningString, null)) { nativeCodeSequence.MethodReturning = bool.Parse(isMethodRetuningString); } string codeInstructions = getContent(element.getElementsByTagName("CodeInstructions")); loadNativeCodeOpcodes(nativeCodeSequence, codeInstructions); // The "Parameters" and "BranchInstruction" have to be parsed after "CodeInstructions" // because they are using them (e.g. instruction labels) string parametersList = getContent(element.getElementsByTagName("Parameters")); if (!string.ReferenceEquals(parametersList, null)) { string[] parameters = parametersList.Split(" *, *", true); for (int parameter = 0; parameters != null && parameter < parameters.Length; parameter++) { setParameter(nativeCodeSequence, parameter, parameters[parameter].Trim()); } } string branchInstructionLabel = getContent(element.getElementsByTagName("BranchInstruction")); if (!string.ReferenceEquals(branchInstructionLabel, null)) { if (branchInstructionLabel.StartsWith("@", StringComparison.Ordinal)) { branchInstructionLabel = branchInstructionLabel.Substring(1); } int branchInstructionOffset = nativeCodeSequence.getLabelIndex(branchInstructionLabel.Trim()); if (branchInstructionOffset >= 0) { nativeCodeSequence.BranchInstruction = branchInstructionOffset; } else { Compiler.Console.WriteLine(string.Format("BranchInstruction: label '{0}' not found", branchInstructionLabel)); } } string beforeCodeInstructions = getContent(element.getElementsByTagName("BeforeCodeInstructions")); if (!string.ReferenceEquals(beforeCodeInstructions, null)) { loadBeforeCodeInstructions(nativeCodeSequence, beforeCodeInstructions); } addNativeCodeSequence(nativeCodeSequence); }