Exemplo n.º 1
0
        private static void Initialize()
        {
            VfsDirectory root = new VfsDirectory();

            root.AddDirectory("lib").AddDirectory("security").Add("cacerts", new VfsCacertsEntry());
            VfsDirectory bin = new VfsDirectory();

            root.Add("bin", bin);
            root.Add("assembly", new VfsAssembliesDirectory());
            AddDummyLibrary(bin, "zip");
            AddDummyLibrary(bin, "awt");
            AddDummyLibrary(bin, "rmi");
            AddDummyLibrary(bin, "w2k_lsa_auth");
            AddDummyLibrary(bin, "jaas_nt");
            AddDummyLibrary(bin, "jaas_unix");
            AddDummyLibrary(bin, "net");
            AddDummyLibrary(bin, "splashscreen");
            AddDummyLibrary(bin, "osx");
            AddDummyLibrary(bin, "management");
            bin.Add("java", new VfsJavaExe());
            bin.Add("javaw", new VfsJavaExe());
            bin.Add("java.exe", new VfsJavaExe());
            bin.Add("javaw.exe", new VfsJavaExe());

            // this is a weird loop back, the vfs.zip resource is loaded from vfs,
            // because that's the easiest way to construct a ZipFile from a Stream.
            java.util.zip.ZipFile zf = new java.util.zip.ZipFile(RootPath + "vfs.zip");
            java.util.Enumeration e  = zf.entries();
            while (e.hasMoreElements())
            {
                AddZipEntry(zf, root, (java.util.zip.ZipEntry)e.nextElement());
            }

            Interlocked.CompareExchange(ref VirtualFileSystem.root, root, null);
        }
Exemplo n.º 2
0
            internal VfsDirectory AddDirectory(string name)
            {
                VfsDirectory dir = new VfsDirectory();

                Add(name, dir);
                return(dir);
            }
Exemplo n.º 3
0
    protected override async Task DeleteFileImplAsync(string path, FileFlags flags = FileFlags.None, CancellationToken cancel = default)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(path, cancel))
        {
            if (ctx.Exception != null)
            {
                throw ctx.Exception;
            }

            if (ctx.LastEntity is VfsFile file)
            {
                Debug.Assert(ctx.EntityStack.Count >= 2);
                Debug.Assert(ctx.EntityStack.Last() == file);
                VfsDirectory parentDir = (ctx.EntityStack[ctx.EntityStack.Count - 2] as VfsDirectory) !;
                Debug.Assert(parentDir != null);

                file.ReleaseHandleRef();
                ctx.EntityStack.RemoveAt(ctx.EntityStack.Count - 1);

                await parentDir.RemoveFileAsync(file, cancel);
            }
            else
            {
                throw new VfsNotFoundException(path, "File not found.");
            }
        }
    }
Exemplo n.º 4
0
        private static VfsEntry GetVfsEntry(string name)
        {
            if (root == null)
            {
                if (name == RootPath + "vfs.zip")
                {
                    return(new VfsVfsZipEntry());
                }
                Initialize();
            }
            if (name.Length <= RootPath.Length)
            {
                return(root);
            }
            string[]     path = name.Substring(RootPath.Length).Split(java.io.File.separatorChar);
            VfsDirectory dir  = root;

            for (int i = 0; i < path.Length - 1; i++)
            {
                dir = dir.GetEntry(path[i]) as VfsDirectory;
                if (dir == null)
                {
                    return(null);
                }
            }
            return(dir.GetEntry(path[path.Length - 1]));
        }
Exemplo n.º 5
0
    public override async Task AddDirectoryAsync(VfsDirectory directory, CancellationToken cancel = default)
    {
        using (await AsyncLock.LockWithAwait(cancel))
        {
            int r = directory.AddLinkRef();
            try
            {
                if (r >= 2)
                {
                    throw new VfsException(directory.Name, "The directory object is already referenced by other directory.");
                }
                if (directory.FileSystem != this.FileSystem)
                {
                    throw new VfsException(directory.Name, "directory.FileSystem != this.FileSystem");
                }
                FileSystem.PathParser.ValidateFileOrDirectoryName(directory.Name);
                if (EntityTable.ContainsKey(directory.Name))
                {
                    throw new VfsException(directory.Name, "The same name already exists.");
                }
                EntityTable.Add(directory.Name, directory);
            }
            catch
            {
                await directory.ReleaseLinkAsync();

                throw;
            }
        }
    }
Exemplo n.º 6
0
    public VirtualFileSystem(VirtualFileSystemParams param) : base(param)
    {
        var rootDir = new VfsRamDirectory(this, "/", true);

        rootDir.AddLinkRef();

        this.Root = rootDir;
    }
Exemplo n.º 7
0
        internal static string[] List(string path)
        {
#if FIRST_PASS
            return(null);
#else
            VfsDirectory dir = GetVfsEntry(path) as VfsDirectory;
            return(dir == null ? null : dir.List());
#endif
        }
Exemplo n.º 8
0
    public override async Task RemoveDirectoryAsync(VfsDirectory directory, CancellationToken cancel = default)
    {
        using (await AsyncLock.LockWithAwait(cancel))
        {
            if (EntityTable.ContainsValue(directory) == false)
            {
                throw new VfsException(directory.Name, $"The object is not contained on the parent directory \"{this.Name}\".");
            }

            await directory.ReleaseLinkAsync();

            EntityTable.Remove(directory.Name);
        }
    }
Exemplo n.º 9
0
 private VfsEntry GetOrAddEntry(string name, Assembly asm)
 {
     lock (entries)
     {
         VfsEntry entry;
         if (!entries.TryGetValue(name, out entry))
         {
             VfsDirectory dir = new VfsDirectory();
             dir.Add("resources", new VfsAssemblyResourcesDirectory(asm));
             dir.Add("classes", new VfsAssemblyClassesDirectory(asm));
             Add(name, dir);
             entry = dir;
         }
         return(entry);
     }
 }
Exemplo n.º 10
0
            internal virtual VfsEntry GetEntry(int index, string[] path)
            {
                VfsEntry entry = GetEntry(path[index++]);

                if (index == path.Length)
                {
                    return(entry);
                }
                else
                {
                    VfsDirectory dir = entry as VfsDirectory;
                    if (dir == null)
                    {
                        return(null);
                    }
                    return(dir.GetEntry(index, path));
                }
            }
Exemplo n.º 11
0
Arquivo: vfs.cs Projeto: sreejukg/ikvm
        private static void Initialize()
        {
            VfsDirectory root = new VfsDirectory();

            root.AddDirectory("lib").AddDirectory("security").Add("cacerts", new VfsCacertsEntry());
            VfsDirectory bin = new VfsDirectory();

            root.Add("bin", bin);
            root.Add("assembly", new VfsAssembliesDirectory());
            AddDummyLibrary(bin, "zip");
            AddDummyLibrary(bin, "awt");
            AddDummyLibrary(bin, "rmi");
            AddDummyLibrary(bin, "w2k_lsa_auth");
            AddDummyLibrary(bin, "jaas_nt");
            AddDummyLibrary(bin, "jaas_unix");
            AddDummyLibrary(bin, "net");
            AddDummyLibrary(bin, "splashscreen");
            AddDummyLibrary(bin, "osx");
            AddDummyLibrary(bin, "management");
            bin.Add("java", new VfsJavaExe());
            bin.Add("javaw", new VfsJavaExe());
            bin.Add("java.exe", new VfsJavaExe());
            bin.Add("javaw.exe", new VfsJavaExe());

            // this is a weird loop back, the vfs.zip resource is loaded from vfs,
            // because that's the easiest way to construct a ZipFile from a Stream.
            //Console.Error.WriteLine($"Opening virtual Zip file: {RootPath + "vfs.zip"}");
            java.util.zip.ZipFile zf = new java.util.zip.ZipFile(RootPath + "vfs.zip");
            java.util.Enumeration e  = zf.entries();
            while (e.hasMoreElements())
            {
                AddZipEntry(zf, root, (java.util.zip.ZipEntry)e.nextElement());
            }

            // make "lib/security/local_policy.jar" point to "lib/security/US_export_policy.jar"
            // to get the unrestricted crypto policy
            VfsDirectory security = (VfsDirectory)((VfsDirectory)root.GetEntry("lib")).GetEntry("security");

            security.Add("local_policy.jar", security.GetEntry("US_export_policy.jar"));

            Interlocked.CompareExchange(ref VirtualFileSystem.root, root, null);
        }
Exemplo n.º 12
0
        private static void AddZipEntry(java.util.zip.ZipFile zf, VfsDirectory root, java.util.zip.ZipEntry entry)
        {
            if (entry.isDirectory())
            {
                return;
            }
            string[]     path = entry.getName().Split('/');
            VfsDirectory dir  = root;

            for (int i = 0; i < path.Length - 1; i++)
            {
                VfsDirectory existing = dir.GetEntry(path[i]) as VfsDirectory;
                if (existing == null)
                {
                    existing = dir.AddDirectory(path[i]);
                }
                dir = existing;
            }
            dir.Add(path[path.Length - 1], new VfsZipEntry(zf, entry));
        }
Exemplo n.º 13
0
    protected override async Task DeleteDirectoryImplAsync(string directoryPath, bool recursive, CancellationToken cancel = default)
    {
        if (recursive)
        {
            await this.DeleteDirectoryRecursiveInternalAsync(directoryPath, cancel);

            return;
        }

        using (VfsPathParserContext ctx = await ParsePathInternalAsync(directoryPath, cancel))
        {
            if (ctx.Exception != null)
            {
                throw ctx.Exception;
            }

            if (ctx.LastEntity is VfsDirectory dir)
            {
                if (dir.IsRoot)
                {
                    throw new VfsException(directoryPath, "The root directory cannot be removed.");
                }

                Debug.Assert(ctx.EntityStack.Count >= 2);
                Debug.Assert(ctx.EntityStack.Last() == dir);
                VfsDirectory parentDir = (ctx.EntityStack[ctx.EntityStack.Count - 2] as VfsDirectory) !;
                Debug.Assert(parentDir != null);

                dir.ReleaseHandleRef();
                ctx.EntityStack.RemoveAt(ctx.EntityStack.Count - 1);

                await parentDir.RemoveDirectoryAsync(dir, cancel);
            }
            else
            {
                throw new VfsNotFoundException(directoryPath, "Directory not found.");
            }
        }
    }
Exemplo n.º 14
0
		private static void AddZipEntry(java.util.zip.ZipFile zf, VfsDirectory root, java.util.zip.ZipEntry entry)
		{
			if (entry.isDirectory())
			{
				return;
			}
			string[] path = entry.getName().Split('/');
			VfsDirectory dir = root;
			for (int i = 0; i < path.Length - 1; i++)
			{
				VfsDirectory existing = dir.GetEntry(path[i]) as VfsDirectory;
				if (existing == null)
				{
					existing = dir.AddDirectory(path[i]);
				}
				dir = existing;
			}
			dir.Add(path[path.Length - 1], new VfsZipEntry(zf, entry));
		}
Exemplo n.º 15
0
		private static void AddDummyLibrary(VfsDirectory dir, string name)
		{
			dir.Add(java.lang.System.mapLibraryName(name), VfsDummyFile.Instance);
		}
Exemplo n.º 16
0
		private static void Initialize()
		{
			VfsDirectory root = new VfsDirectory();
			root.AddDirectory("lib").AddDirectory("security").Add("cacerts", new VfsCacertsEntry());
			VfsDirectory bin = new VfsDirectory();
			root.Add("bin", bin);
			root.Add("assembly", new VfsAssembliesDirectory());
			AddDummyLibrary(bin, "zip");
			AddDummyLibrary(bin, "awt");
			AddDummyLibrary(bin, "rmi");
			AddDummyLibrary(bin, "w2k_lsa_auth");
			AddDummyLibrary(bin, "jaas_nt");
			AddDummyLibrary(bin, "jaas_unix");
			AddDummyLibrary(bin, "unpack");
			AddDummyLibrary(bin, "net");
			AddDummyLibrary(bin, "splashscreen");
			AddDummyLibrary(bin, "osx");
			bin.Add("java", new VfsJavaExe());
			bin.Add("javaw", new VfsJavaExe());
			bin.Add("java.exe", new VfsJavaExe());
			bin.Add("javaw.exe", new VfsJavaExe());

			// this is a weird loop back, the vfs.zip resource is loaded from vfs,
			// because that's the easiest way to construct a ZipFile from a Stream.
			java.util.zip.ZipFile zf = new java.util.zip.ZipFile(RootPath + "vfs.zip");
			java.util.Enumeration e = zf.entries();
			while (e.hasMoreElements())
			{
				AddZipEntry(zf, root, (java.util.zip.ZipEntry)e.nextElement());
			}

			// make "lib/security/local_policy.jar" point to "lib/security/US_export_policy.jar"
			// to get the unrestricted crypto policy
			VfsDirectory security = (VfsDirectory)((VfsDirectory)root.GetEntry("lib")).GetEntry("security");
			security.Add("local_policy.jar", security.GetEntry("US_export_policy.jar"));

			Interlocked.CompareExchange(ref VirtualFileSystem.root, root, null);
		}
Exemplo n.º 17
0
			internal VfsDirectory AddDirectory(string name)
			{
				VfsDirectory dir = new VfsDirectory();
				Add(name, dir);
				return dir;
			}
Exemplo n.º 18
0
			private VfsEntry GetOrAddEntry(string name, Assembly asm)
			{
				lock (entries)
				{
					VfsEntry entry;
					if (!entries.TryGetValue(name, out entry))
					{
						VfsDirectory dir = new VfsDirectory();
						dir.Add("resources", new VfsAssemblyResourcesDirectory(asm));
						dir.Add("classes", new VfsAssemblyClassesDirectory(asm));
						Add(name, dir);
						entry = dir;
					}
					return entry;
				}
			}
Exemplo n.º 19
0
            private void Populate()
            {
                bool populate;

                lock (entries)
                {
                    populate = entries.Count == 0;
                }
                if (populate)
                {
                    Dictionary <string, string> names = new Dictionary <string, string>();
                    AssemblyClassLoader         acl   = AssemblyClassLoader.FromAssembly(this.asm);
                    foreach (Assembly asm in acl.GetAllAvailableAssemblies())
                    {
                        Type[] types;
                        try
                        {
                            types = asm.GetTypes();
                        }
                        catch (ReflectionTypeLoadException x)
                        {
                            types = x.Types;
                        }
                        catch
                        {
                            types = Type.EmptyTypes;
                        }
                        foreach (Type type in types)
                        {
                            if (type != null)
                            {
                                string name = null;
                                try
                                {
                                    bool isJavaType;
                                    name = acl.GetTypeNameAndType(type, out isJavaType);
#if !FIRST_PASS
                                    // annotation custom attributes are pseudo proxies and are not loadable by name (and should not exist in the file systems,
                                    // because proxies are, ostensibly, created on the fly)
                                    if (isJavaType && type.BaseType == typeof(global::[email protected]) && name.Contains(".$Proxy"))
                                    {
                                        name = null;
                                    }
#endif
                                }
                                catch
                                {
                                }
                                if (name != null)
                                {
                                    names[name] = name;
                                }
                            }
                        }
                    }
                    lock (entries)
                    {
                        if (entries.Count == 0)
                        {
                            foreach (string name in names.Keys)
                            {
                                string[]     parts = name.Split('.');
                                VfsDirectory dir   = this;
                                for (int i = 0; i < parts.Length - 1; i++)
                                {
                                    dir = dir.GetEntry(parts[i]) as VfsDirectory ?? dir.AddDirectory(parts[i]);
                                }
                                // we're adding a dummy file, to make the file appear in the directory listing, it will not actually
                                // be accessed, because the code above handles that
                                dir.Add(parts[parts.Length - 1] + ".class", VfsDummyFile.Instance);
                            }
                        }
                    }
                }
            }
Exemplo n.º 20
0
    protected async Task <FileObject> AddFileAsync(FileParameters option, CreateFileCallback createFileCallback, CancellationToken cancel = default, bool noOpen = false)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(option.Path, cancel))
        {
            if (ctx.Exception == null)
            {
                if (ctx.LastEntity is VfsFile file)
                {
                    // Already exists
                    if (option.Mode == FileMode.CreateNew)
                    {
                        throw new VfsException(option.Path, $"The file already exists.");
                    }

                    if (noOpen == false)
                    {
                        return(await file.OpenAsync(option, ctx.NormalizedPath, cancel));
                    }
                    else
                    {
                        return(null !);
                    }
                }
                else
                {
                    // There is existing another type object
                    throw new VfsException(option.Path, $"There are existing object at the speficied path.");
                }
            }

            if (ctx.Exception is VfsNotFoundException && ctx.RemainingPathElements.Count == 1 && ctx.LastEntity is VfsDirectory && option.Mode != FileMode.Open)
            {
                // Create new RAM file
                VfsDirectory lastDir = (VfsDirectory)ctx.LastEntity;

                string fileName = ctx.RemainingPathElements.Peek();

                var newFile = await createFileCallback(fileName, option, cancel);

                string fullPath = PathParser.Combine(ctx.NormalizedPath, fileName);

                try
                {
                    await lastDir.AddFileAsync(newFile);
                }
                catch
                {
                    await newFile.ReleaseLinkAsync(true);

                    throw;
                }

                if (noOpen == false)
                {
                    return(await newFile.OpenAsync(option, fullPath, cancel));
                }
                else
                {
                    return(null !);
                }
            }
            else
            {
                throw ctx.Exception;
            }
        }
    }
Exemplo n.º 21
0
 private static void AddDummyLibrary(VfsDirectory dir, string name)
 {
     dir.Add(java.lang.System.mapLibraryName(name), VfsDummyFile.Instance);
 }
Exemplo n.º 22
0
 public abstract Task RemoveDirectoryAsync(VfsDirectory directory, CancellationToken cancel = default);