本文整理汇总了C#中Stream.SliceWithLength方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.SliceWithLength方法的具体用法?C# Stream.SliceWithLength怎么用?C# Stream.SliceWithLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.SliceWithLength方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Detect
public String Detect(Stream Stream)
{
var StartMagic = Stream.SliceWithLength(0, 4).ReadAllContentsAsString(Encoding.ASCII);
Console.WriteLine(StartMagic);
if (StartMagic == '\0' + "PBP") return "Pbp";
if (StartMagic == '\0' + "PSF") return "Psf";
if (StartMagic == '\x7F' + "ELF") return "Elf";
if (StartMagic == "CISO") return "Cso";
if (StartMagic == "DAX" + '\0') return "Dax";
if (Stream.SliceWithLength(0x8000, 6).ReadAllContentsAsString() == '\x01' + "CD001") return "Iso";
return "Unknown";
}
示例2: LoadSectionsTo
public void LoadSectionsTo(Stream MemoryStream)
{
Console.WriteLine("{0:X}", ExeStream.Length);
//400-1600 -> 82000400-820015E4
//PeStream.SliceWithLength(0).CopyToFast(MemoryStream.SliceWithLength(0x82000000));
//return;
//var BaseMemoryStream = MemoryStream.SliceWithLength(PeOptionalHeader.ImageBase);
File.WriteAllBytes(@"C:\projects\csharp\cs360emu\test.bin", ExeStream.ReadAll());
foreach (var ImageSectionHeader in ImageSectionHeaderList)
{
Console.WriteLine("-------------------------------------------------");
Console.WriteLine(ImageSectionHeader.ToStringDefault());
var FileSlice = ExeStream.SliceWithLength(ImageSectionHeader.PointerToRawData, ImageSectionHeader.SizeOfRawData);
var MemorySlice = MemoryStream.SliceWithLength(ImageSectionHeader.VirtualAddress + PeOptionalHeader.ImageBase, ImageSectionHeader.VirtualSize);
Console.WriteLine("Segment: {0:X}-{1:X} -> {2:X}-{3:X}", FileSlice.SliceLow, FileSlice.SliceHigh, MemorySlice.SliceLow, MemorySlice.SliceHigh);
var Data = FileSlice.ReadAll(true);
//Console.WriteLine(BitConverter.ToString(Data));
MemorySlice.WriteBytes(Data);
//FileSlice.Position = 0;
//MemorySlice.Position = 0;
//FileSlice.CopyToFast(MemorySlice);
}
}
示例3: DetectSubType
public SubType DetectSubType(Stream Stream)
{
var StartMagic = Stream.SliceWithLength(0, 4).ReadAllContentsAsString(Encoding.ASCII);
//Console.WriteLine(StartMagic);
if (StartMagic == '\0' + "PBP") return SubType.Pbp;
if (StartMagic == '\0' + "PSF") return SubType.Psf;
if (StartMagic == '\x7F' + "ELF") return SubType.Elf;
if (StartMagic == "~PSP") return SubType.EncryptedElf;
if (StartMagic == "CISO") return SubType.Cso;
if (StartMagic == "DAX" + '\0') return SubType.Dax;
if (Stream.SliceWithLength(0x8000, 6).ReadAllContentsAsString() == '\x01' + "CD001") return SubType.Iso;
return SubType.Unknown;
}
示例4: Load
public Psf Load(Stream Stream)
{
EntryDictionary = new Dictionary<string, object>();
Header = Stream.ReadStruct<HeaderStruct>();
Entries = Stream.ReadStructVector<EntryStruct>(Header.NumberOfPairs);
KeysStream = Stream.SliceWithLength(Header.KeyTable);
ValuesStream = Stream.SliceWithLength(Header.ValueTable);
foreach (var Entry in Entries)
{
var Key = KeysStream.ReadStringzAt(Entry.KeyOffset);
var ValueStream = ValuesStream.SliceWithLength(Entry.ValueOffset, Entry.ValueSize);;
switch (Entry.DataType)
{
case DataType.Binary: EntryDictionary[Key] = ValueStream.ReadAll(); break;
case DataType.Int: EntryDictionary[Key] = ValueStream.ReadStruct<int>(); break;
case DataType.Text: EntryDictionary[Key] = ValueStream.ReadStringz(-1, Encoding.UTF8); break;
default: throw(new NotImplementedException());
}
}
return this;
}
示例5: Load
public Pmf Load(Stream Stream)
{
Header = Stream.ReadStruct<HeaderStruct>();
var Chunk = ReadChunk(Stream.SliceWithLength(0x50));
InfoHeader = Chunk.Stream.ReadStruct<InfoHeaderStruct>();
/*
Console.WriteLine("0x{0:X}", (ulong)InfoHeader.FirstTimestamp);
Console.WriteLine("0x{0:X}", (ulong)InfoHeader.LastTimestamp);
Console.WriteLine("{0}", (ulong)InfoHeader.Width);
Console.WriteLine("{0}", (ulong)InfoHeader.Height);
*/
return this;
}
示例6: LoadHeader
public Pe LoadHeader(Stream _ExeStream)
{
ExeStream = _ExeStream;
DosExe = new DosExe().LoadHeader(ExeStream);
PeStream = ExeStream.SliceWithLength(DosExe.Header.OffsetToPEHeader);
PeHeader = PeStream.ReadStruct<PeHeaderStruct>();
OptionalHeaderStream = PeStream.ReadStream(PeHeader.SizeOfOptionalHeader);
PeOptionalHeader = OptionalHeaderStream.ReadStruct<PeOptionalHeaderStruct>();
ImageSectionHeaderList = new ImageSectionHeader[PeHeader.NumSections];
for (int n = 0; n < PeHeader.NumSections; n++)
{
ImageSectionHeaderList[n] = PeStream.ReadStruct<ImageSectionHeader>();
}
return this;
}
示例7: Load
public virtual void Load(Stream FileStream, string Name)
{
FileStream = new MemoryStream(FileStream.ReadAll());
this.FileStream = FileStream;
this.Header = FileStream.ReadStruct<Elf.HeaderStruct>();
if (this.Header.Magic != Elf.HeaderStruct.MagicEnum.ExpectedValue)
{
throw(new InvalidProgramException("Not an ELF File '" + Name + "'"));
}
if (this.Header.Machine != Elf.HeaderStruct.MachineEnum.ALLEGREX)
{
throw (new InvalidProgramException("Invalid Elf.Header.Machine"));
}
this.ProgramHeaders = FileStream.ReadStructVectorAt<Elf.ProgramHeader>(Header.ProgramHeaderOffset, Header.ProgramHeaderCount, Header.ProgramHeaderEntrySize);
this.SectionHeaders = FileStream.ReadStructVectorAt<Elf.SectionHeader>(Header.SectionHeaderOffset, Header.SectionHeaderCount, Header.SectionHeaderEntrySize);
this.NamesSectionHeader = this.SectionHeaders[Header.SectionHeaderStringTable];
this.StringTable = FileStream.SliceWithLength(this.NamesSectionHeader.Offset, this.NamesSectionHeader.Size).ReadAll();
this.SectionHeadersByName = new Dictionary<string, Elf.SectionHeader>();
foreach (var SectionHeader in this.SectionHeaders)
{
var SectionHeaderName = GetStringFromStringTable(SectionHeader.Name);
this.SectionHeadersByName[SectionHeaderName] = SectionHeader;
}
Console.WriteLine("ProgramHeaders:{0}", this.ProgramHeaders.Length);
foreach (var ProgramHeader in ProgramHeaders)
{
Console.WriteLine("{0}", ProgramHeader.ToStringDefault());
}
Console.WriteLine("SectionHeaders:{0}", this.SectionHeaders.Length);
foreach (var SectionHeader in SectionHeaders)
{
Console.WriteLine("{0}:{1}", GetStringFromStringTable(SectionHeader.Name), SectionHeader.ToStringDefault());
}
if (NeedsRelocation && this.ProgramHeaders.Length > 1)
{
//throw (new NotImplementedException("Not implemented several ProgramHeaders yet using relocation"));
}
}
示例8: LoadModule
public HleModuleGuest LoadModule(Stream FileStream, Stream MemoryStream, MemoryPartition MemoryPartition, HleModuleManager ModuleManager, String GameTitle, string ModuleName, bool IsMainModule)
{
this.HleModuleGuest = new HleModuleGuest(PspEmulatorContext);
this.ElfLoader = new ElfLoader();
this.ModuleManager = ModuleManager;
var Magic = FileStream.SliceWithLength(0, 4).ReadString(4);
Logger.Info("Magic: '{0}'", Magic);
if (Magic == "~PSP")
{
try
{
var DecryptedData = new EncryptedPrx().Decrypt(FileStream.ReadAll(), true);
File.WriteAllBytes("last_decoded_prx.bin", DecryptedData);
FileStream = new MemoryStream(DecryptedData);
}
catch (Exception Exception)
{
Logger.Error(Exception);
throw (Exception);
}
}
this.ElfLoader.Load(FileStream, ModuleName);
PspEmulatorContext.PspConfig.InfoExeHasRelocation = this.ElfLoader.NeedsRelocation;
if (this.ElfLoader.NeedsRelocation)
{
var DummyPartition = MemoryPartition.Allocate(
0x4000,
Name: "Dummy"
);
BaseAddress = MemoryPartition.ChildPartitions.OrderByDescending(Partition => Partition.Size).First().Low;
Logger.Info("BASE ADDRESS (Try ): 0x{0:X}", BaseAddress);
BaseAddress = MathUtils.NextAligned(BaseAddress, 0x1000);
Logger.Info("BASE ADDRESS (Aligned): 0x{0:X}", BaseAddress);
}
else
{
BaseAddress = 0;
}
PspEmulatorContext.PspConfig.RelocatedBaseAddress = BaseAddress;
PspEmulatorContext.PspConfig.GameTitle = GameTitle;
this.ElfLoader.AllocateAndWrite(MemoryStream, MemoryPartition, BaseAddress);
if (this.ElfLoader.NeedsRelocation)
{
RelocateFromHeaders();
}
if (!ElfLoader.SectionHeadersByName.ContainsKey(".rodata.sceModuleInfo"))
{
throw(new Exception("Can't find segment '.rodata.sceModuleInfo'"));
}
HleModuleGuest.ModuleInfo = ElfLoader.SectionHeaderFileStream(ElfLoader.SectionHeadersByName[".rodata.sceModuleInfo"]).ReadStruct<ElfPsp.ModuleInfo>(); ;
//Console.WriteLine(this.ModuleInfo.ToStringDefault());
HleModuleGuest.InitInfo = new InitInfoStruct()
{
PC = ElfLoader.Header.EntryPoint + BaseAddress,
GP = HleModuleGuest.ModuleInfo.GP + BaseAddress,
};
UpdateModuleImports();
UpdateModuleExports();
ModuleManager.LoadedGuestModules.Add(HleModuleGuest);
return HleModuleGuest;
}
示例9: WriteSegmentsToStream
/// <summary>
/// Function that writtes all the mappings into another stream.
/// Useful for patching a file or memory.
/// </summary>
/// <param name="TargetStream">Stream to write the mapped contents to</param>
public void WriteSegmentsToStream(Stream TargetStream)
{
foreach (var StreamEntry in _StreamEntries)
{
var SourceSliceStream = StreamEntry.Stream.SliceWithLength(0, StreamEntry.Length);
var TargetSliceStream = TargetStream.SliceWithLength(StreamEntry.Position, StreamEntry.Length);
SourceSliceStream.CopyToFast(TargetSliceStream);
}
}
示例10: LoadHeader
public Xex LoadHeader(Stream XexStream)
{
Header = XexStream.ReadStruct<HeaderStruct>();
var OptionalHeaders = XexStream.ReadStructVector<OptionalHeader>(Header.OptionalHeaderCount);
Console.WriteLine("{0:X}", XexStream.Position);
InfoList = new Dictionary<OptionalHeader.Ids, ulong>();
foreach (var OptionalHeader in OptionalHeaders)
{
//Console.WriteLine("{0}: 0x{1:X}", OptionalHeader.Id, (uint)OptionalHeader.Data);
//InfoList[OptionalHeader.Id] = OptionalHeader.Data;
InfoList.Add(OptionalHeader.Id, OptionalHeader.Data);
switch (OptionalHeader.Id)
{
case Xex.OptionalHeader.Ids.OriginalPEName:
this.OriginalPeName = LoadChunk(XexStream, OptionalHeader.Data).ReadStringz(Encoding: Encoding.UTF8);
break;
case Xex.OptionalHeader.Ids.LANKey:
this.LanKey = XexStream.SliceWithLength(OptionalHeader.Data, 0x10).ReadAll();
break;
case Xex.OptionalHeader.Ids.DefaultStackSize:
this.DefaultStackSize = OptionalHeader.Data;
break;
case Xex.OptionalHeader.Ids.ChecksumTimestamp:
this.ChecksumTimestamp = XexStream.SliceWithLength(OptionalHeader.Data).ReadStruct<ChecksumTimestampStruct>();
break;
case Xex.OptionalHeader.Ids.ImageBaseAddress:
this.ImageBaseAddress = OptionalHeader.Data;
break;
case Xex.OptionalHeader.Ids.EntryPoint:
this.EntryPoint = OptionalHeader.Data;
break;
case Xex.OptionalHeader.Ids.StaticLibraries:
this.StaticLibs = LoadChunk(XexStream, OptionalHeader.Data).ReadStructVectorUntilTheEndOfStream<StaticLib>();
foreach (var StaticLib in StaticLibs)
{
Console.WriteLine("StaticLib: {0}", StaticLib.ToStringDefault());
}
break;
case Xex.OptionalHeader.Ids.ImportLibraries:
{
var ImportLibrariesStream = LoadChunk(XexStream, OptionalHeader.Data);
var TextLength = (uint)ImportLibrariesStream.ReadStruct<uint_be>();
var LibraryCount = (uint)ImportLibrariesStream.ReadStruct<uint_be>();
var TextStream = ImportLibrariesStream.ReadStream(TextLength);
var LibraryNames = new String[LibraryCount];
for (int n = 0; n < LibraryCount; n++)
{
LibraryNames[n] = TextStream.ReadStringz(AllowEndOfStream: false);
Console.WriteLine("ImportLib: {0}", LibraryNames[n]);
}
var ChunkUnk1 = ReadChunkIncludingTheSize(ImportLibrariesStream);
var ImportAddressList = ReadChunkIncludingTheSize(ImportLibrariesStream);
Console.Error.WriteLine("@TODO: Xex.OptionalHeader.Ids.ImportLibraries");
}
break;
case Xex.OptionalHeader.Ids.TLSInfo:
{
this.TLSInfo = XexStream.SliceWithLength(OptionalHeader.Data).ReadStruct<TLSInfoStruct>();
}
break;
default:
Console.WriteLine("{0}: 0x{1:X}", OptionalHeader.Id, (uint)OptionalHeader.Data);
break;
}
}
PeStream = XexStream.SliceWithLength(Header.PeDataOffset);
Pe = new Pe().LoadHeader(PeStream);
Console.WriteLine("SecurityInfoOffset: {0:X}", (uint)Header.SecurityInfoOffset);
var SecurityStream = LoadChunk(XexStream, Header.SecurityInfoOffset);
var NumberOfSections = (ushort)SecurityStream.ReadStruct<ushort_be>();
Console.WriteLine("NumberOfSections: {0:X}", NumberOfSections);
return this;
}
示例11: LoadChunk
public Stream LoadChunk(Stream Stream, uint Offset)
{
return ReadChunkIncludingTheSize(Stream.SliceWithLength(Offset));
}