private void setParameter( NativeCodeSequence nativeCodeSequence, int parameter, String valueString) { if (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("@")) { 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")) { value = Integer.parseInt(valueString.substring(2), 16); } else { value = Integer.parseInt(valueString); } nativeCodeSequence.setParameter(parameter, value, false); } catch (NumberFormatException e) { Compiler.log.error(e); } }
private void loadNativeCodeSequence(Element element) { String name = element.getAttribute("name"); String className = getContent(element.getElementsByTagName("Class")); Class<INativeCodeSequence> nativeCodeSequenceClass = getNativeCodeSequenceClass(className); if (nativeCodeSequenceClass == null) { return; } NativeCodeSequence nativeCodeSequence = new NativeCodeSequence(name, nativeCodeSequenceClass); String isReturningString = getContent(element.getElementsByTagName("IsReturning")); if (isReturningString != null) { nativeCodeSequence.setReturning(Boolean.parseBoolean(isReturningString)); } String wholeCodeBlockString = getContent(element.getElementsByTagName("WholeCodeBlock")); if (wholeCodeBlockString != null) { nativeCodeSequence.setWholeCodeBlock(Boolean.parseBoolean(wholeCodeBlockString)); } String methodName = getContent(element.getElementsByTagName("Method")); if (methodName != null) { nativeCodeSequence.setMethodName(methodName); } String isHookString = getContent(element.getElementsByTagName("IsHook")); if (isHookString != null) { nativeCodeSequence.setHook(Boolean.parseBoolean(isHookString)); } String isMethodRetuningString = getContent(element.getElementsByTagName("IsMethodReturning")); if (isMethodRetuningString != null) { nativeCodeSequence.setMethodReturning(Boolean.parseBoolean(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 (parametersList != null) { String[] parameters = parametersList.split(" *, *"); for (int parameter = 0; parameters != null && parameter < parameters.length; parameter++) { setParameter(nativeCodeSequence, parameter, parameters[parameter].trim()); } } String branchInstructionLabel = getContent(element.getElementsByTagName("BranchInstruction")); if (branchInstructionLabel != null) { if (branchInstructionLabel.startsWith("@")) { branchInstructionLabel = branchInstructionLabel.substring(1); } int branchInstructionOffset = nativeCodeSequence.getLabelIndex(branchInstructionLabel.trim()); if (branchInstructionOffset >= 0) { nativeCodeSequence.setBranchInstruction(branchInstructionOffset); } else { Compiler.log.error( String.format("BranchInstruction: label '%s' not found", branchInstructionLabel)); } } String beforeCodeInstructions = getContent(element.getElementsByTagName("BeforeCodeInstructions")); if (beforeCodeInstructions != null) { loadBeforeCodeInstructions(nativeCodeSequence, beforeCodeInstructions); } addNativeCodeSequence(nativeCodeSequence); }