internal void GetAllBuiltInFunctions(Function startFunction, Action <Instruction> addSomething) { int startAddress = startFunction.Address; int address = startAddress; int endAddress = startFunction.GetEndAddress(); while (address < endAddress) { var ins = ainFile.Peek(address); if (CodeSearchCache.BuiltInFunctions.ContainsKey((int)ins.instruction)) { addSomething(ins.instruction); } address = ins.nextAddress; } }
private void FindFunctionTypesMain(bool makeNewStuffUp) { foreach (var function in ainFile.Functions) { if (function.Name.EndsWith("CADVCallFunction@ADV_CallFunction")) { //specific blacklisted function continue; } int address = function.Address; int endAddress = Decompiler.FindEndAddress(address, ainFile); while (address < endAddress) { InstructionInfo ins = ainFile.Peek(address); if (ins.instruction == Instruction.FUNC || ins.instruction == Instruction.ENDFUNC) { break; } if (ins.instruction == Instruction.CALLFUNC2 || ins.instruction == Instruction.FT_ASSIGNS) { FindFunctionTypes(function, makeNewStuffUp); break; } if (ins.instruction == Instruction.DG_CALLBEGIN) { FindFunctionTypes(function, makeNewStuffUp); break; } if (ins.instruction == Instruction.DG_STR_TO_METHOD) { FindFunctionTypes(function, makeNewStuffUp); break; } if (ins.instruction == Instruction.DG_NEW_FROM_METHOD) { FindFunctionTypes(function, makeNewStuffUp); break; } address = ins.nextAddress; } } }
private List <string> GetTextFromFunction(Function function) { int numberOfNonCommentedLines = 0; int numberOfStrings = 0; int numberOfMessages = 0; //Expression expression = null; //int expressionLastAddress = function.Address; useStringsToMatch = StringsToMatch != null && StringsToMatch.Count > 0; //List<string> strings = new List<string>(); //List<string> messages = new List<string>(); List <string> functionLines = new List <string>(); string functionLineString = "FUNCTION " + /*function.Index.ToString() + " " + */ AssemblerProjectWriter.SanitizeVariableName(function.Name); functionLines.Add(functionLineString); functionLines.Add("#x strings, x messages"); //this line gets changed later (it's index 1) int address = function.Address; string lastName = null; while (address < ainFile.Code.Length) { var instructionInfo = ainFile.Peek(address); if (instructionInfo.instruction == Instruction.ENDFUNC || instructionInfo.instruction == Instruction.FUNC) { break; } if (this.AnnotateEnumerationType != null && instructionInfo.instruction == Instruction.CALLFUNC) { var func = ainFile.GetFunction(instructionInfo.word1); if (VariablesUsingEnumerationType.Contains(func)) { var parameters = GetParametersThatUsesEnumerationType(func); if (parameters.FirstOrDefault() != null) { foreach (var parameter in parameters) { int i = parameter.Index; int addr = instructionInfo.CurrentAddress - (func.ParameterCount) * 6 + i * 6; var ins2 = ainFile.Peek(addr); if (ins2.instruction == Instruction.PUSH) { string enumerationValue = this.AnnotateEnumerationType.GetOrDefault(ins2.word1, ""); if (!String.IsNullOrEmpty(enumerationValue)) { functionLines.Add(""); functionLines.Add("#" + enumerationValue); } } else if (ins2.instruction == Instruction.S_PUSH) { string str = ainFile.GetString(ins2.word1); if (!String.IsNullOrEmpty(str)) { if (this.replacementStringsForAnnotations != null && this.replacementStringsForAnnotations.ContainsKey(str)) { string nextStr = this.replacementStringsForAnnotations[str]; if (!nextStr.StartsWith("*")) { str = nextStr; } else { str = lastName; } } else { } if (lastName != str) { lastName = str; functionLines.Add(""); functionLines.Add("#" + str); } } } } } } } if (instructionInfo.instruction == Instruction.MSG) { //if (this.AnnotateEnumerationType != null) //{ // if (expression == null) // { // expression = ainFile.DecompiledCodeCache.GetDecompiledCode(function); // } // CatchUpToAddress(ref expression, functionLines, address); //} int messageNumber = instructionInfo.word1; string message = ainFile.GetMessage(messageNumber); if (message != null) { if (useStringsToMatch == false || StringsToMatch.Contains(message)) { string messageLine = "m " + numberOfMessages.ToString("000") + " " + StringExportImport.EscapeText(message); functionLines.Add(messageLine); } numberOfMessages++; numberOfNonCommentedLines++; } } else if (instructionInfo.instruction == Instruction.STRSWITCH) { int switchBlockNumber = instructionInfo.word1; var switchBlock = ainFile.Switches.GetOrNull(switchBlockNumber); if (switchBlock != null) { foreach (var switchCase in switchBlock.SwitchCases) { int stringNumber = switchCase.Value; string str = ainFile.GetString(stringNumber); if (str != null) { AddString(ref numberOfNonCommentedLines, ref numberOfStrings, functionLines, stringNumber, str); } } } } else { int indexOfStringArgument = instructionInfo.instruction.IndexOfStringArgument(); if (indexOfStringArgument != -1) { int stringNumber = instructionInfo.words[indexOfStringArgument]; string str = ainFile.GetString(stringNumber); if (str != null) { AddString(ref numberOfNonCommentedLines, ref numberOfStrings, functionLines, stringNumber, str); } } } address = instructionInfo.nextAddress; } functionLines[1] = "#" + numberOfStrings.ToString() + " strings, " + numberOfMessages.ToString() + " messages"; if (numberOfNonCommentedLines == 0) { functionLines.Clear(); } return(functionLines); }