Exemplo n.º 1
0
        public bool IsAllowed(ModuleHeader <Payload> objHeader)
        {
            if (objHeader == null)
            {
                return(false);
            }

            Target t = _Module.Target;

            if (t == null)
            {
                return(false);
            }

            if (t.Arquitecture == EArquitecture.None)
            {
                return(false);
            }
            if (t.Platform == EPlatform.None)
            {
                return(false);
            }

            Payload obj = objHeader.Current;

            return(t.Arquitecture == obj.Arquitecture && t.Platform == obj.Platform);
        }
            public bool IsAllowed(ModuleHeader <Nop> objHeader)
            {
                if (objHeader == null)
                {
                    return(false);
                }

                if (!typeof(INopAsm).IsAssignableFrom(objHeader.Type))
                {
                    return(false);
                }

                INopAsm nop = (INopAsm)objHeader.Current;

                if (nop.AllowedTargets != null)
                {
                    foreach (Target t in nop.AllowedTargets)
                    {
                        if (t.Arquitecture == Target.Arquitecture && t.Platform == Target.Platform)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
Exemplo n.º 3
0
Arquivo: Main.cs Projeto: j0nat/JCIW
        /// <summary>
        /// Check if app is valid and load.
        /// </summary>
        /// <param name="appId">Application ID</param>
        /// <param name="filePath">Path on file system.</param>
        private void LoadApp(long appId, string filePath)
        {
            FileInfo     file         = new FileInfo(Path.Combine(Local.Folder, filePath));
            ModuleHeader moduleHeader = ModuleHeaderReader.AppHeader(Local.Folder, file.FullName);

            if (moduleHeader != null)
            {
                if (apps.ContainsKey(appId))
                {
                    ModuleInstance app = apps[appId];

                    app.Load();

                    currentApp = app;
                }
                else
                {
                    ModuleInstance app = new ModuleInstance(file.FullName, "Module.App",
                                                            new object[] { Frame, Networking, PlatformFunctions, Platform, UserGroups.ToArray() });

                    bool result = app.Load();

                    apps.Add(appId, app);

                    currentApp = app;
                }

                CurrentlyRunningAppName = moduleHeader.Name;
            }
        }
        public bool IsAllowed(ModuleHeader <Payload> payload)
        {
            if (payload != null && typeof(IBufferOverflowPayload).IsAssignableFrom(payload.Type))
            {
                // Check size
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public bool IsAllowed(ModuleHeader <Nop> nop)
        {
            Type t2 = nop.Type;

            foreach (Type t in _Types)
            {
                if (t == t2)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public bool VerifyModule(string fileName)
        {
            bool returnValue = false;

            ModuleHeader serviceHeader = ModuleHeaderReader.ServiceHeader(Path.GetDirectoryName(fileName), fileName);
            ModuleHeader pluginHeader  = ModuleHeaderReader.AppHeader(Path.GetDirectoryName(fileName), fileName);

            if (pluginHeader != null || serviceHeader != null)
            {
                returnValue = true;
            }

            return(returnValue);
        }
Exemplo n.º 7
0
        public bool IsAllowed(ModuleHeader <Payload> payload)
        {
            Type t2 = payload.Type;

            foreach (Type t in _Types)
            {
                if (t == t2)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Load service from disk.
        /// </summary>
        /// <param name="filePath"></param>
        public void RegisterModule(string filePath)
        {
            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if (baseDirectory.Length == 0)
            {
                baseDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            }

            string fullPath = Path.Combine(baseDirectory, filePath);

            if (File.Exists(filePath))
            {
                ModuleHeader pluginHeader = ModuleHeaderReader.AppHeader(
                    baseDirectory, fullPath);

                ModuleHeader serviceHeader = ModuleHeaderReader.ServiceHeader(
                    baseDirectory, fullPath);

                if (pluginHeader != null)
                {
                    Module module = new Module();
                    module.enabled = 0;
                    module.type    = (int)ModuleType.App;
                    module.path    = filePath;
                    module.name    = pluginHeader.Name;
                    module.version = pluginHeader.Version;

                    moduleRepository.Add(module);
                }

                if (serviceHeader != null)
                {
                    Module module = new Module();
                    module.enabled = 0;
                    module.type    = (int)ModuleType.Service;
                    module.path    = filePath;
                    module.name    = serviceHeader.Name;
                    module.version = serviceHeader.Version;

                    moduleRepository.Add(module);

                    serviceManager.LoadServices();
                }
            }
            else
            {
                // No such file
            }
        }
Exemplo n.º 9
0
 private void HeaderClickUp(object sender, MouseButtonEventArgs e)
 {
     if (_drag)
     {
         _mouseDownInToolbar = false;
         ModuleHeader.ReleaseMouseCapture();
         _drag = !_drag;
     }
     else
     {
         _mouseDownInToolbar = true;
         _dragOffset         = e.GetPosition(FarmsTree);
         ModuleHeader.CaptureMouse();
         _drag = !_drag;
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Return true if are in this query
        /// </summary>
        /// <param name="query">Query</param>
        bool AreInThisSearch(ModuleHeader <T> m, string[] query)
        {
            if (query == null || query.Length == 0)
            {
                return(true);
            }

            string search = m.FullPath + " " + m.Description + " " + m.Author;

            foreach (string a in query)
            {
                if (search.IndexOf(a, StringComparison.InvariantCultureIgnoreCase) < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 11
0
        public void Save(UserAddedScript script, Stream output)
        {
            var nameBytes  = Encoding.UTF8.GetBytes(script.Symbol);
            var bodyStream = new MemoryStream(8 * 1024);

            _formatter.Serialize(bodyStream, script.Image);

            var header = new ModuleHeader
            {
                NameLen = nameBytes.Length,
                BodyLen = bodyStream.Length,
                IsClass = script.Type == UserAddedScriptType.Class
            };

            WriteStruct(output, header);

            output.Write(nameBytes, 0, nameBytes.Length);
            bodyStream.Position = 0;
            bodyStream.WriteTo(output);
            bodyStream.Dispose();
        }
Exemplo n.º 12
0
 public bool IsAllowed(ModuleHeader <Nop> nop)
 {
     return(_Type.IsAssignableFrom(nop.Type));
 }
Exemplo n.º 13
0
        public override bool Init()
        {
            mh = new ModuleHeader();

            return(true);
        }
Exemplo n.º 14
0
        public void Write(ModuleWriter writer)
        {
            // Create the header.
            ModuleHeader header = new ModuleHeader();

            // Populate it.

            // Store the module type.
            header.moduleType = (uint)moduleType;

            // Write the header.
            header.Write(writer);

            // Prepare the members.
            globalNamespace.PrepareSerialization();
            foreach(ScopeMember instance in genericInstances)
                instance.PrepareSerialization();

            // Prepare type referemnces.
            PrepareTypeReferences();

            // Prepare resource writing.
            PrepareResources();

            // Prepare debug information.
            DebugEmitter debugEmitter = null;
            if(debugBuild)
            {
                debugEmitter = new DebugEmitter(this);
                debugEmitter.Prepare();
                globalNamespace.PrepareDebug(debugEmitter);
            }

            // Don't allow registering members.
            writingModule = true;

            // Write the members.
            header.memberTableOffset = writer.GetPosition();
            foreach(ScopeMember member in memberTable)
            {
                // Write local members, and a pointer for the externals.
                ChelaModule memberModule = member.GetModule();
                if(memberModule == this)
                {
                    member.Write(writer);
                }
                else
                {
                    // Don't write external generic instances.
                    if(member.GetGenericInstance() != null)
                        throw new ModuleException("Write external generic instance.");

                    // Create the member reference header.
                    MemberHeader mheader = new MemberHeader();
                    mheader.memberSize = 1;
                    mheader.memberName = RegisterString(member.GetFullName()); // TODO: Use mangled name.
                    mheader.memberType = (byte)MemberHeaderType.Reference;

                    // Write the reference header and module id.
                    mheader.Write(writer);
                    writer.Write((byte)AddReference(memberModule));
                }
            }
            header.memberTableSize = writer.GetPosition() - header.memberTableOffset;

            // Write module references.
            header.moduleRefTableOffset = writer.GetPosition();
            header.moduleRefTableEntries = (uint) (referencedModules.Count + 1);

            // Write myself.
            ModuleReference modRef = new ModuleReference();
            modRef.moduleName = RegisterString(GetName());
            modRef.Write(writer);

            // Write module references.
            foreach(ChelaModule mod in referencedModules)
            {
                modRef.moduleName = RegisterString(mod.GetName());
                modRef.Write(writer);
            }

            // Write the libraries table.
            header.libTableOffset = writer.GetPosition();
            header.libTableEntries = (uint)nativeLibraries.Count;
            foreach(string libname in nativeLibraries)
                writer.Write(RegisterString(libname));

            // Write the anonymous types.
            header.anonTypeTableOffset = writer.GetPosition();
            WriteAnonType(writer);
            header.anonTypeTableSize = writer.GetPosition() - header.anonTypeTableOffset;

            // Write the type table.
            header.typeTableOffset = writer.GetPosition();
            header.typeTableEntries = (uint)typeTable.Count;
            TypeReference typeRef = new TypeReference();
            foreach(IChelaType type in typeTable)
            {
                // Write the type kind.
                if(type.IsTypeInstance())
                    typeRef.typeKind = (byte)TypeKind.Instance;
                else if(type.IsStructure())
                    typeRef.typeKind = (byte)TypeKind.Structure;
                else if(type.IsClass())
                    typeRef.typeKind = (byte)TypeKind.Class;
                else if(type.IsInterface())
                    typeRef.typeKind = (byte)TypeKind.Interface;
                else if(type.IsFunction())
                    typeRef.typeKind = (byte)TypeKind.Function;
                else if(type.IsReference())
                    typeRef.typeKind = (byte)TypeKind.Reference;
                else if(type.IsPointer())
                    typeRef.typeKind = (byte)TypeKind.Pointer;
                else if(type.IsConstant())
                    typeRef.typeKind = (byte)TypeKind.Constant;
                else if(type.IsArray())
                    typeRef.typeKind = (byte)TypeKind.Array;
                else if(type.IsVector())
                    typeRef.typeKind = (byte)TypeKind.Vector;
                else if(type.IsMatrix())
                    typeRef.typeKind = (byte)TypeKind.Matrix;
                else if(type.IsPlaceHolderType())
                    typeRef.typeKind = (byte)TypeKind.PlaceHolder;

                if(!type.IsStructure() && !type.IsClass() && !type.IsInterface() &&
                   !type.IsTypeInstance())
                {
                    // Write a reference into the anonymous types.
                    typeRef.memberId = (uint)anonymousTypeMap[type];
                    typeRef.typeName = 0;//RegisterString(type.GetName());
                }
                else
                {
                    // Write the type member reference.
                    ScopeMember member = (ScopeMember)type;
                    typeRef.memberId = RegisterMember(member);
                    typeRef.typeName = 0;//RegisterString(type.GetName());
                }

                // Write the type reference.
                typeRef.Write(writer);
            }

            // Write the string table.
            header.stringTableOffset = writer.GetPosition();
            header.stringTableEntries = (uint)stringTable.Count;
            foreach(string s in stringTable)
                writer.Write(s);

            // Write the debug info
            if(debugBuild)
            {
                header.debugInfoOffset = writer.GetPosition();
                debugEmitter.Write(writer);
                header.debugInfoSize = writer.GetPosition() - header.debugInfoOffset;
            }

            // Write the resources.
            header.resourceDataOffset = writer.GetPosition();
            WriteResources(writer);
            header.resourceDataSize = writer.GetPosition() - header.resourceDataOffset;

            // Store the module size.
            header.moduleSize = writer.GetPosition();

            // Store the entry point.
            if(mainFunction != null)
                header.entryPoint = mainFunction.GetSerialId();

            // Write the header again.
            writer.MoveBegin();
            header.Write(writer);

            // Allow more modifications from here.
            writingModule = false;
        }
Exemplo n.º 15
0
        public static ChelaModule LoadModule(ModuleReader reader, bool fullLoad)
        {
            // Try to guess the file type.
            uint moduleStart = reader.GetPosition();
            byte[] signature;
            reader.Read(out signature, 8);

            // Check for elf file type.
            bool isElf = true;
            for(int i = 0; i < 4; ++i)
            {
                if(signature[i] != ElfFormat.ElfMagic[i])
                {
                    isElf = false;
                    break;
                }
            }

            // Check for PE.
            bool isPE = signature[0] == 'M' && signature[1] == 'Z';

            // Find the module content.
            reader.SetPosition(moduleStart);
            if(isElf)
            {
                // Move to the embedded module.
                ElfFormat.GetEmbeddedModule(reader);
                reader.FixBase();
            }
            else if(isPE)
            {
                // Move to the embedded module.
                PEFormat.GetEmbeddedModule(reader);
                reader.FixBase();
            }

            // Read the module header.
            ModuleHeader header = new ModuleHeader();
            header.Read(reader);

            // Create the output module.
            ChelaModule result = new ChelaModule();

            // Read the string table.
            reader.SetPosition(header.stringTableOffset);
            for(uint i = 0; i < header.stringTableEntries; ++i)
            {
                uint id = i+1u;
                string s = reader.ReadString();
                result.stringTable.Add(s);
                result.registeredStrings.Add(s, id);
            }

            // Read myself data.
            ModuleReference modref = new ModuleReference();
            reader.SetPosition(header.moduleRefTableOffset);
            modref.Read(reader);
            result.SetName(result.GetString(modref.moduleName));

            // Read the module type.
            result.moduleType = (ModuleType)header.moduleType;

            // Read the referenced modules.
            for(uint i = 1; i < header.moduleRefTableEntries; ++i)
            {
                // Read the referenced module.
                modref.Read(reader);

                // Load it.
                ChelaModule referencedModule = LoadNamedModule(result.GetString(modref.moduleName));
                result.referencedModules.Add(referencedModule);
            }

            // Preload the members.
            reader.SetPosition(header.memberTableOffset);
            uint end = header.memberTableOffset + header.memberTableSize;
            MemberHeader mheader = new MemberHeader();
            while(reader.GetPosition() < end)
            {
                // Read the member header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Preload the member.
                MemberHeaderType mtype = (MemberHeaderType)mheader.memberType;
                switch(mtype)
                {
                case MemberHeaderType.Namespace:
                    Namespace.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Structure:
                    Structure.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Class:
                    Class.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Interface:
                    Interface.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Function:
                    Function.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Field:
                    FieldVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.FunctionGroup:
                    FunctionGroup.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.TypeInstance:
                    StructureInstance.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Property:
                    PropertyVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Event:
                    EventVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.TypeName:
                    TypeNameMember.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.MemberInstance:
                case MemberHeaderType.FunctionInstance:
                    // Ignore the member instance.
                    result.memberTable.Add(null);
                    reader.Skip(mheader.memberSize);
                    break;
                case MemberHeaderType.TypeGroup:
                    TypeGroup.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Reference:
                    {
                        // Read the module id.
                        byte moduleId = reader.ReadByte();

                        // Get the referenced module.
                        ChelaModule refMod = result.GetReferenced(moduleId);

                        // Find the member there.
                        ScopeMember member = refMod.GetMember(result.GetString(mheader.memberName));
                        result.memberTable.Add(member);
                    }
                    break;
                default:
                    // Unknown member.
                    System.Console.WriteLine("add unknown member {0}", mtype);
                    result.memberTable.Add(null);
                    reader.Skip(mheader.memberSize);
                    break;
                }
            }

            // Read the type table.
            reader.SetPosition(header.typeTableOffset);
            for(uint i = 0; i < header.typeTableEntries; ++i)
            {
                // Read the type reference.
                TypeReference typeRef = new TypeReference();
                typeRef.Read(reader);

                // Try to load direct members.
                TypeKind kind = (ChelaModule.TypeKind)typeRef.typeKind;
                if(kind == TypeKind.Class || kind == TypeKind.Interface ||
                   kind == TypeKind.Structure || kind == TypeKind.Instance)
                {
                    // Store the actual type.
                    result.typeTable.Add(result.GetMember(typeRef.memberId));
                }
                else
                {
                    // Store the reference for delayed loading.
                    result.typeTable.Add(typeRef);
                }
            }

            // Read the anonymous types.
            reader.SetPosition(header.anonTypeTableOffset);
            end = header.anonTypeTableOffset + header.anonTypeTableSize;
            while(reader.GetPosition() < end)
            {
                // Read the anonymous type data.
                AnonTypeHeader anonType = new AnonTypeHeader();
                anonType.Read(reader);

                // Store it in the anonymous type table.
                result.anonymousTypes.Add(anonType);
            }

            // Now, read the actual members.
            reader.SetPosition(header.memberTableOffset);
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                // Get the preloaded member.
                ScopeMember member = result.memberTable[i];

                // Read his header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Read the member.
                if(member != null && mheader.memberType != (int)MemberHeaderType.Reference)
                    member.Read(reader, mheader);
                else
                    reader.Skip(mheader.memberSize); // Skip unknown members.
            }

            // The first member must be the global namespace.
            result.globalNamespace = (Namespace)result.GetMember(1);

            // Update the parent children relationship.
            result.globalNamespace.UpdateParent(null);

            // Now, perform second read pass, required by function groups.
            reader.SetPosition(header.memberTableOffset);
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                // Get the preloaded member.
                ScopeMember member = result.memberTable[i];

                // Read his header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Read the member.
                if(member != null && mheader.memberType != (int)MemberHeaderType.Reference)
                    member.Read2(reader, mheader);
                else
                    reader.Skip(mheader.memberSize); // Skip unknown members.
            }

            // Finish all of the loading.
            result.globalNamespace.FinishLoad();

            // Register the member names.
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                ScopeMember member = result.memberTable[i];
                if(member != null)
                    result.memberNameTable[member.GetFullName()] = member;
            }

            // Load the runtime classes.
            if(result.referencedModules.Count == 0)
                result.LoadRuntimeReferences(result);

            // Dump the readed module.
            //result.Dump();

            // Return the result module.
            return result;
        }
Exemplo n.º 16
0
 public bool IsAllowed(ModuleHeader <Payload> payload)
 {
     return(_Type.IsAssignableFrom(payload.Type));
 }
Exemplo n.º 17
0
 public override void Cleanup()
 {
     mh       = null;
     patbuf   = null;
     m_Module = null;
 }