protected virtual ILuaJitConstant ReadComplexConstant()
        {
            var type = Reader.ReadULEB128();

            if (type >= 5)
            {
                var str = Encoding.UTF8.GetString(Reader.ReadBytes((int)(type - 5)));

                if (!String.IsNullOrEmpty(str) && str.Length > 10 && str.StartsWith("x64:"))
                {
                    var hash = Convert.ToUInt64(str.Substring(4).Replace(".lua", ""), 16) & 0xFFFFFFFFFFFFFFF;
                    if (Decompiler.HashEntries.ContainsKey(hash))
                    {
                        str = Decompiler.HashEntries[hash];
                    }
                    else
                    {
                        // Replace the hash with the masked version so it's easier to find the actual file back
                        str = $"x64:{hash:x}";
                    }
                }

                return(new LuaJitConstant(str));
            }

            if (type == 0)
            {
                var child = ((LuaJitFile)LuaFile).Functions.Pop();
                ChildFunctions.Add(child);
                return(new LuaJitConstant((LuaJitFunction)child));
            }

            if (type == 1)
            {
                // Parse table
                return(new LuaJitConstant(ReadTable()));
            }
            if (type == 2)
            {
                Console.WriteLine("TYPE 2");
            }
            if (type == 3)
            {
                Console.WriteLine("TYPE 3");
            }
            if (type == 4)
            {
                Console.WriteLine("TYPE 4");
            }
            Console.WriteLine("unknown TYPE " + type);

            return(null);
        }
Beispiel #2
0
        protected override ILuaJitConstant ReadComplexConstant()
        {
            var type = Reader.ReadULEB128();

            if (type >= 6)
            {
                var str = Encoding.UTF8.GetString(Reader.ReadBytes((int)(type - 6)));

                return(new LuaJitConstant(str));
            }

            if (type == 0)
            {
                var child = ((LuaJitFile)LuaFile).Functions.Pop();
                ChildFunctions.Add(child);
                return(new LuaJitConstant((LuaJitFunction)child));
            }

            if (type == 1)
            {
                // Parse table
                return(new LuaJitConstant(ReadTable()));
            }
            if (type == 2)
            {
                Console.WriteLine("TYPE 2");
            }
            if (type == 3)
            {
                Console.WriteLine("TYPE 3");
            }
            if (type == 4)
            {
                var hi   = Reader.ReadULEB128();
                var lo   = Reader.ReadULEB128();
                var hash = ((hi << 32) | lo) & 0xFFFFFFFFFFFFFFF;
                if (Decompiler.HashEntries.ContainsKey(hash))
                {
                    return(new LuaJitConstant(Decompiler.HashEntries[hash]));
                }
                return(new LuaJitConstant(hash));
            }
            Console.WriteLine("unknown TYPE " + type);

            return(null);
        }
Beispiel #3
0
        public ChildFunctionData GetChildFunction(SyntaxNode node, SemanticModel semanticModel, bool create = false)
        {
            if (ChildFunctions.TryGetValue(node, out var typeData))
            {
                return(typeData);
            }
            if (!create)
            {
                return(null);
            }

            if (node is AnonymousFunctionExpressionSyntax anonymousFunc)
            {
                var symbol = semanticModel.GetSymbolInfo(node).Symbol as IMethodSymbol;
                return(ChildFunctions.GetOrAdd(node, syntax => OnChildCreated(new AnonymousFunctionData(GetBaseMethodData(), symbol, anonymousFunc, this))));
            }

            if (node is LocalFunctionStatementSyntax localFunc)
            {
                var symbol = semanticModel.GetDeclaredSymbol(node) as IMethodSymbol;
                return(ChildFunctions.GetOrAdd(node, syntax => OnChildCreated(new LocalFunctionData(GetBaseMethodData(), symbol, localFunc, this))));
            }
            throw new InvalidOperationException($"Cannot get a ChildFunctionData from syntax node {node}");
        }
Beispiel #4
0
 public void AddChildFunction(RevitFunctionModel function)
 {
     function.ParentFunction = this;
     ChildFunctions.Add(function);
 }