public static string GetSampleUtf8CartridgeTitle() => "「ホ」 abcヲァィ TEST123"; // don't pad this here, it'll happen later public static (int originalUnpaddedSize, ByteSource byteSource) Create(int padToSize = 0x8000) { var byteSource = new ByteSource { Bytes = CreateRawStorageSampleBytes(), Name = "Diz Sample Snes Rom" }; var unpaddedSize = byteSource.Bytes.Count; // tricky: this sample data can be used to populate the "sample assembly output" // window to demo some features. One thing we'd like to demo is showing generated // labels that reach into "unreached" code (i.e. labels like "UNREACH_XXXXX") // // To accomplish this, we'll pad the size of the sample ROM data to 32k, but, // we'll tell the assembly exporter to limit to the first couple hundred bytes by // only assembling bytes up to BaseSampleData.SizeOverride. while (byteSource.Bytes.Count < padToSize) { byteSource.Bytes.Add(new ByteEntry { Byte = 0x00 }); } // perf: this is going to be pretty slow, i don't think we care much since it's mostly for testing. byteSource.Bytes.AddRange( Enumerable.Repeat( new ByteEntry { Byte = 0x00 }, padToSize - unpaddedSize) .ToArray()); return(unpaddedSize, byteSource); }
//------------------------------------------------------------------------- /// <summary> /// Parses FpML from the specified source, extracting the trades. /// <para> /// This parses the specified byte source which must be an XML document. /// </para> /// <para> /// Sometimes, the FpML document is embedded in a non-FpML wrapper. /// This method will intelligently find the FpML document at the root or within one or two levels /// of wrapper by searching for an element that contains both {@code <trade>} and {@code <party>}. /// /// </para> /// </summary> /// <param name="source"> the source of the FpML XML document </param> /// <returns> the parsed trades </returns> /// <exception cref="RuntimeException"> if a parse error occurred </exception> public IList <Trade> parseTrades(ByteSource source) { XmlFile xmlFile = XmlFile.of(source, FpmlDocument.ID); XmlElement root = findFpmlRoot(xmlFile.Root); return(parseTrades(root, xmlFile.References)); }
private static void TestRemoveLabelFromNullByteIndex(ByteSource byteSourceSparse) { byteSourceSparse.IsValidIndex(0).Should().Be(true); byteSourceSparse.Bytes[0].Should().Be(null); byteSourceSparse.Bytes.Should().BeOfType(typeof(StorageSparse <ByteEntry>)); byteSourceSparse.Invoking(x => x.RemoveAllAnnotationsAt(0, ByteSourceLabelProvider.IsLabel)) .Should().NotThrow <NullReferenceException>(); }
//------------------------------------------------------------------------- /// <summary> /// Creates an instance from another byte source. /// </summary> /// <param name="other"> the other byte source </param> /// <returns> the byte source </returns> /// <exception cref="UncheckedIOException"> if an IO error occurs </exception> public static ArrayByteSource from(ByteSource other) { if (other is ArrayByteSource) { return((ArrayByteSource)other); } return(new ArrayByteSource(Unchecked.wrap(() => other.read()))); }
public virtual void test_from_Supplier() { ByteSource source = ByteSource.wrap(new sbyte[] { 1, 2, 3 }); ArrayByteSource test = ArrayByteSource.from(() => source.openStream()); assertEquals(test.size(), 3); assertEquals(test.read()[0], 1); assertEquals(test.read()[1], 2); assertEquals(test.read()[2], 3); }
public virtual void test_from_ByteSource() { ByteSource source = ByteSource.wrap(new sbyte[] { 1, 2, 3 }); ArrayByteSource test = ArrayByteSource.from(source); assertEquals(test.size(), 3); assertEquals(test.read()[0], 1); assertEquals(test.read()[1], 2); assertEquals(test.read()[2], 3); }
public static Data InitializeEmptyRomMapping(this Data data, int size, RomMapMode mode, RomSpeed speed) { var romByteSource = new ByteSource { Bytes = new StorageList <ByteEntry>(size), Name = "Snes ROM" }; PopulateFromRom(data, romByteSource, mode, speed); return(data); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_toCharSource_noBomUtf8() throws java.io.IOException public virtual void test_toCharSource_noBomUtf8() { sbyte[] bytes = new sbyte[] { (sbyte)'H', (sbyte)'e', (sbyte)'l', (sbyte)'l', (sbyte)'o' }; ByteSource byteSource = ByteSource.wrap(bytes); CharSource charSource = UnicodeBom.toCharSource(byteSource); string str = charSource.read(); assertEquals(str, "Hello"); assertEquals(charSource.asByteSource(StandardCharsets.UTF_8), byteSource); assertEquals(charSource.ToString().StartsWith("UnicodeBom", StringComparison.Ordinal), true); }
// special function. attempts to recurse the graph and collapse all the nodes into // one ByteEntry which represents all of the information about our offset. // // this works in simple cases where you'd only expect i.e. one offset, or bytes are ok // to be overwritten. This doesn't work for more complex stuff like mirrored offsets/etc. // In those cases, you should more manually walk the graph node yourself in whatever manner // is appropriate for the calling code. public static ByteEntry BuildFlatDataFrom(ByteSource byteSource, int index) { if (!byteSource.IsValidIndex(index)) { return(null); } var node = BuildFullGraph(byteSource, index); var finalData = BuildFlatDataFrom(node); return(finalData); }
// return a directed graph with all possible values for this offset including all child regions public static ByteGraphNode BuildFullGraph(ByteSource byteSource, int sourceIndex) { if (sourceIndex < 0 || sourceIndex >= byteSource.Bytes.Count) { return(null); } var node = new ByteGraphNode(byteSource, sourceIndex); BuildChildGraph(byteSource, sourceIndex, ref node); return(node); }
//------------------------------------------------------------------------- public virtual void test_equalsHashCodeToString() { ByteSource source = ByteSource.wrap(SAMPLE.GetBytes(Encoding.UTF8)); XmlFile test = XmlFile.of(source); XmlFile test2 = XmlFile.of(source); assertFalse(test.Equals(null)); assertFalse(test.Equals(ANOTHER_TYPE)); assertEquals(test, test); assertEquals(test, test2); assertEquals(test.GetHashCode(), test2.GetHashCode()); assertEquals(test.ToString(), test2.ToString()); }
//------------------------------------------------------------------------- public virtual void test_of_ByteSource() { ByteSource source = ByteSource.wrap(SAMPLE.GetBytes(Encoding.UTF8)); XmlFile test = XmlFile.of(source); XmlElement root = test.Root; assertEquals(root.Name, "base"); assertEquals(root.Attributes, ATTR_MAP_EMPTY); assertEquals(root.Content, ""); assertEquals(root.Children.size(), 1); XmlElement child = root.getChild(0); assertEquals(child, XmlElement.ofChildren("test", ATTR_MAP, CHILD_LIST_MULTI)); assertEquals(test.References, ImmutableMap.of()); }
// caution: recursion private static void BuildChildGraph(ByteSource byteSource, int sourceIndex, ref ByteGraphNode nodeToPopulate) { foreach (var childSourceToTraverse in byteSource.ChildSources) { var childIndex = childSourceToTraverse.RegionMapping .ConvertIndexFromParentToChild(sourceIndex, childSourceToTraverse.ByteSource); var newChildNode = BuildFullGraph(childSourceToTraverse.ByteSource, childIndex); if (newChildNode == null) { continue; } nodeToPopulate.AttachChildNode(newChildNode); } }
public PDFFileStream(IPDFSource source) { if (source is FileSource) { FileSource fileSource = (FileSource)source; Context = MuPDFNativeApi.Native.NewContext(IntPtr.Zero, IntPtr.Zero, FZ_STORE_DEFAULT); Stream = MuPDFNativeApi.Native.OpenFile(Context, fileSource.Filename); Document = MuPDFNativeApi.Native.OpenDocumentStream(Context, PDF_EXTENSION, Stream); } else if (source is ByteSource) { ByteSource byteSource = (ByteSource)source; Context = MuPDFNativeApi.Native.NewContext(IntPtr.Zero, IntPtr.Zero, FZ_STORE_DEFAULT); GCHandle pinnedArray = GCHandle.Alloc(byteSource.Data, GCHandleType.Pinned); IntPtr ptr = pinnedArray.AddrOfPinnedObject(); Stream = MuPDFNativeApi.Native.OpenStream(Context, ptr, byteSource.Data.Length); Document = MuPDFNativeApi.Native.OpenDocumentStream(Context, PDF_EXTENSION, Stream); pinnedArray.Free(); } }
/// <summary> /// Parses the specified source as an XML file to an in-memory DOM-like structure. /// <para> /// This parses the specified byte source expecting an XML file format. /// The resulting instance can be queried for the root element. /// </para> /// <para> /// This supports capturing attribute references, such as an id/href pair. /// Wherever the parser finds an attribute with the specified name, the element is added /// to the internal map, accessible by calling <seealso cref="#getReferences()"/>. /// </para> /// <para> /// For example, if one part of the XML has {@code <foo id="fooId">}, the references map will /// contain an entry mapping "fooId" to the parsed element {@code <foo>}. /// /// </para> /// </summary> /// <param name="source"> the XML source data </param> /// <param name="refAttrName"> the attribute name that should be parsed as a reference </param> /// <returns> the parsed file </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public static XmlFile of(ByteSource source, string refAttrName) { ArgChecker.notNull(source, "source"); return(Unchecked.wrap(() => { using (Stream @in = source.openBufferedStream()) { XMLStreamReader xmlReader = xmlInputFactory().createXMLStreamReader(@in); try { Dictionary <string, XmlElement> refs = new Dictionary <string, XmlElement>(); XmlElement root = parse(xmlReader, refAttrName, refs); return new XmlFile(root, refs); } finally { xmlReader.close(); } } })); }
public virtual void test_of_ByteSource_namespace() { ByteSource source = ByteSource.wrap(SAMPLE_NAMESPACE.GetBytes(Encoding.UTF8)); XmlFile test = XmlFile.of(source); XmlElement root = test.Root; assertEquals(root.Name, "base"); assertEquals(root.Attributes, ImmutableMap.of()); assertEquals(root.Content, ""); assertEquals(root.Children.size(), 2); XmlElement child1 = root.getChild(0); assertEquals(child1.Name, "p"); assertEquals(child1.Content, "Some text"); assertEquals(child1.Attributes, ImmutableMap.of()); XmlElement child2 = root.getChild(1); assertEquals(child2.Name, "leaf1"); assertEquals(child2.Content, "leaf"); assertEquals(child2.Attributes, ImmutableMap.of("foo", "bla", "og", "strata")); assertEquals(test.References, ImmutableMap.of()); }
public ShiroAuthenticationInfo(object principal, object hashedCredentials, ByteSource credentialsSalt, string realmName, AuthenticationResult authenticationResult) : base(principal, hashedCredentials, credentialsSalt, realmName) { this._authenticationResult = authenticationResult; }
private void ByteSourceOnConnectionChanged(object sender, EventArgs eventArgs) { IsConnected = ByteSource.IsConnected(); }
//----------------------------------------------------------------------- /// <summary> /// Parses the specified source as an XML file to an in-memory DOM-like structure. /// <para> /// This parses the specified byte source expecting an XML file format. /// The resulting instance can be queried for the root element. /// /// </para> /// </summary> /// <param name="source"> the XML source data </param> /// <returns> the parsed file </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public static XmlFile of(ByteSource source) { return(of(source, "")); }
public override int ConvertIndexFromChildToParent(int childIndex, ByteSource byteSource) => childIndex;
public static Data PopulateFromRom(this Data data, ByteSource romByteSource, RomMapMode romMapMode, RomSpeed romSpeed) { var mapping = RomUtil.CreateRomMappingFromRomByteSource(romByteSource, romMapMode, romSpeed); return(PopulateFrom(data, mapping)); }
/// <summary> /// Converts a {@code ByteSource} to a {@code CharSource}. /// <para> /// This ensures that any Unicode byte order marker is used correctly. /// The default encoding is UTF-8 if no BOM is found. /// /// </para> /// </summary> /// <param name="byteSource"> the byte source </param> /// <returns> the char source, that uses the BOM to determine the encoding </returns> public static CharSource toCharSource(ByteSource byteSource) { return(new CharSourceAnonymousInnerClass(byteSource)); }
// pass in topleve (i.e. Data.SnesAddressSpace) public ByteSourceLabelProvider(ByteSource byteSource) { ByteSource = byteSource; }
public CharSourceAnonymousInnerClass(ByteSource byteSource) { this.byteSource = byteSource; }
public override int GetHashCode() { return(ByteSource.GetHashCode()); }
public abstract int ConvertIndexFromParentToChild(int parentIndex, ByteSource byteSource);
public static Data CreateInputRom() { var bytes = new List <ByteEntry> { // -------------------------- // highlighting a particular section here // we will use this for unit tests as well. // SNES address: 808000 // instruction: LDA.W Test_Data,X new() { Byte = 0xBD, TypeFlag = FlagType.Opcode, MFlag = true, Point = InOutPoint.InPoint, DataBank = 0x80, DirectPage = 0x2100 }, new() { Byte = 0x5B, TypeFlag = FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100 }, // Test_Data new() { Byte = 0x80, TypeFlag = FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100 }, // Test_Data // SNES address: 808003 // instruction: STA.W $0100,X new() { Byte = 0x9D, TypeFlag = FlagType.Opcode, MFlag = true, DataBank = 0x80, DirectPage = 0x2100, Annotations = { new Label { Name = "Fn_go1", Comment = "Store some stuff" } } }, new() { Byte = 0x00, TypeFlag = FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100 }, new() { Byte = 0x01, TypeFlag = FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100 }, // SNES address: 808006 // instruction: DEX new() { Byte = 0xCA, TypeFlag = FlagType.Opcode, MFlag = true, DataBank = 0x80, DirectPage = 0x2100, Annotations = { new Label { Name = "Test22", Comment = "LabelComment" }, new Comment{ Text = "LineComment" } } }, // SNES address: 808007 // instruction: BPL CODE_808000 new() { Byte = 0x10, TypeFlag = FlagType.Opcode, MFlag = true, Point = InOutPoint.OutPoint, DataBank = 0x80, DirectPage = 0x2100 }, new() { Byte = 0xF7, TypeFlag = FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100 }, }; var actualRomBytes = new ByteSource { Name = "Space Cats 2: Rise of Lopsy Dumpwell", Bytes = new StorageList <ByteEntry>(bytes) }; // var data = new TestData() var data = new Data() .PopulateFromRom(actualRomBytes, RomMapMode.LoRom, RomSpeed.FastRom); // another way to add comments, adds it to the SNES address space instead of the ROM. // retrievals should be unaffected. data.Labels.AddLabel(0x808000 + 0x5B, new Label { Name = "Test_Data", Comment = "Pretty cool huh?" }); data.AddComment(0x808000 + 0x5C, "XYZ"); return(data); }
public abstract int ConvertIndexFromChildToParent(int childIndex, ByteSource byteSource);
//------------------------------------------------------------------------- /// <summary> /// Creates an instance of the locator. /// </summary> /// <param name="locator"> the locator </param> /// <param name="source"> the byte source </param> private ResourceLocator(string locator, ByteSource source) : base() { this.locator = locator; this.source = source; }
public override int ConvertIndexFromParentToChild(int parentIndex, ByteSource byteSource) => parentIndex;