public LongDoubleInfo(ref ReadOnlySpan <byte> fileData, ConstantPoolTag tag) : base(tag) { HighBytes = (int)fileData.ReadFourBytes(); LowBytes = (int)fileData.ReadFourBytes(); LongValue = (long)((((ulong)HighBytes) << 32) & (ulong)LowBytes); }
public XElement Convert(BinaryFormat source) { DataReader reader = new DataReader(source.Stream) { Endianness = EndiannessMode.BigEndian, DefaultEncoding = new EucJpEncoding() }; // Read header var magicStamp = reader.ReadUInt32(); if (magicStamp != 0xCAFEBABE) { throw new FormatException("Invalid MagicStamp CAFEBABE"); } reader.ReadUInt16(); // Minor version reader.ReadUInt16(); // Major version // Read the constant pool var textConstants = new Dictionary <int, string>(); var stringsIdx = new List <int>(); var constantPoolCount = reader.ReadUInt16(); for (int i = 0; i < constantPoolCount - 1; i++) { ConstantPoolTag tag = (ConstantPoolTag)reader.ReadByte(); if (tag == ConstantPoolTag.Utf8) { textConstants.Add(i, reader.ReadString(typeof(ushort))); } else if (tag == ConstantPoolTag.String) { stringsIdx.Add(reader.ReadUInt16() - 1); } else { reader.ReadBytes(GetConstantPoolItemInfoLength(tag)); } } // Generate the XML element var xml = new XElement("StringConstants"); foreach (var index in stringsIdx) { // We are skipping some text with encoding issues if (!textConstants.ContainsKey(index)) { continue; } var xmlString = new XElement("StringConstant"); xmlString.SetAttributeValue("index", index); xmlString.SetIndentedValue(textConstants[index].Replace("\0", ""), 3); xml.Add(xmlString); } return(xml); }
public Po Convert(BinaryFormat source) { DataReader reader = new DataReader(source.Stream) { Endianness = EndiannessMode.BigEndian, DefaultEncoding = new EucJpEncoding() }; // Read header var magicStamp = reader.ReadUInt32(); if (magicStamp != 0xCAFEBABE) { throw new FormatException("Invalid MagicStamp CAFEBABE"); } reader.ReadUInt16(); // Minor version reader.ReadUInt16(); // Major version // Read the constant pool var textConstants = new Dictionary <int, string>(); var stringsIdx = new List <int>(); var constantPoolCount = reader.ReadUInt16(); for (int i = 0; i < constantPoolCount - 1; i++) { ConstantPoolTag tag = (ConstantPoolTag)reader.ReadByte(); if (tag == ConstantPoolTag.Utf8) { textConstants.Add(i, reader.ReadString(typeof(ushort))); } else if (tag == ConstantPoolTag.String) { stringsIdx.Add(reader.ReadUInt16() - 1); } else { reader.ReadBytes(GetConstantPoolItemInfoLength(tag)); } } // Generate the PO Po po = new Po { Header = new PoHeader("Xenosaga I", "*****@*****.**") }; foreach (var index in stringsIdx) { po.Add(new PoEntry(textConstants[index].Replace("\0", "")) { Context = index.ToString() }); } return(po); }
static int GetConstantPoolItemInfoLength(ConstantPoolTag tag) { switch (tag) { case ConstantPoolTag.Class: return(2); case ConstantPoolTag.FieldRef: return(4); case ConstantPoolTag.MethodRef: return(4); case ConstantPoolTag.InterfaceMethodRef: return(4); case ConstantPoolTag.String: return(2); case ConstantPoolTag.Integer: return(4); case ConstantPoolTag.Float: return(4); case ConstantPoolTag.Long: return(8); case ConstantPoolTag.Double: return(8); case ConstantPoolTag.NameAndType: return(4); case ConstantPoolTag.MethodHandle: return(3); case ConstantPoolTag.MethodType: return(2); case ConstantPoolTag.InvokeDynamic: return(4); default: throw new FormatException("Unknown tag"); } }
public InvokeDynamicInfo(ConstantPoolTag tag, ushort bootstrapMethodAttrIndex, ushort nameAndTypeIndex) : base(tag) { BootstrapMethodAttrIndex = bootstrapMethodAttrIndex; _nameAndTypeIndex = nameAndTypeIndex; }
public MethodTypeInfo(ConstantPoolTag tag, ushort descriptorIndex) : base(tag) { _descriptorIndex = descriptorIndex; }
public MethodHandleInfo(ConstantPoolTag tag, MethodHandleType referenceKind, ushort referenceIndex) : base(tag) { ReferenceKind = referenceKind; _referenceIndex = referenceIndex; }
public ConstantPoolInfo(ConstantPoolTag tag) { this.tag = tag; }
public StringInfo(ConstantPoolTag tag, ushort stringIndex) : base(tag) { _stringIndex = stringIndex; }
public ClassInfo(ConstantPoolTag tag, ushort nameIndex) : base(tag) { _nameIndex = nameIndex; }
public FloatInfo(ConstantPoolTag tag, float value) : base(tag) { Value = value; }
public IntegerInfo(ConstantPoolTag tag, int value) : base(tag) { Value = value; }
public RefInfo(ref ReadOnlySpan <byte> fileData, ConstantPoolTag tag) : base(tag) { classIndex = fileData.ReadTwoBytes(); nameAndTypeIndex = fileData.ReadTwoBytes(); }
public ConstantPoolDescription(ConstantPoolTag tag, ByteSerializable info) { Tag = tag; Info = info; }
public ClassStringInfo(ref ReadOnlySpan <byte> fileData, ConstantPoolTag tag) : base(tag) { stringIndex = fileData.ReadTwoBytes(); }
protected CpInfo(ConstantPoolTag tag) { Tag = tag; }
public ModuleOrPackageInfo(ConstantPoolTag tag, ushort nameIndex) : base(tag) { _nameIndex = nameIndex; }
public LongInfo(ConstantPoolTag tag, long value) : base(tag) { Value = value; }
public FieldOrMethodrefInfo(ConstantPoolTag tag, ushort classIndex, ushort nameAndTypeIndex) : base(tag) { _classIndex = classIndex; _nameAndTypeIndex = nameAndTypeIndex; }
public DoubleInfo(ConstantPoolTag tag, double value) : base(tag) { Value = value; }
public NameAndTypeInfo(ConstantPoolTag tag, ushort nameIndex, ushort descriptorIndex) : base(tag) { _nameIndex = nameIndex; _descriptorIndex = descriptorIndex; }
public Utf8Info(ConstantPoolTag tag, ushort length, string data) : base(tag) { Data = data; }
public BinaryFormat Convert(Po source) { if (OriginalStream == null) { throw new InvalidOperationException("Cannot convert from XML without original stream"); } // Get the list of strings to change Dictionary <int, string> textConstants = new Dictionary <int, string>(); foreach (var element in source.Entries) { int index = Int32.Parse(element.Context); textConstants[index] = element.Translated ?? element.Original; } OriginalStream.Position = 0; DataReader reader = new DataReader(OriginalStream) { Endianness = EndiannessMode.BigEndian, DefaultEncoding = new EucJpEncoding() }; BinaryFormat format = new BinaryFormat(); DataWriter writer = new DataWriter(format.Stream) { Endianness = EndiannessMode.BigEndian, DefaultEncoding = new EucJpEncoding() }; // Magic stamp + Version writer.Write(reader.ReadBytes(8)); // Read pool and write into new stream changing texts ushort poolCount = reader.ReadUInt16(); writer.Write(poolCount); for (int i = 0; i < poolCount - 1; i++) { ConstantPoolTag tag = (ConstantPoolTag)reader.ReadByte(); writer.Write((byte)tag); if (tag == ConstantPoolTag.Utf8) { var textData = reader.ReadBytes(reader.ReadUInt16()); if (textConstants.ContainsKey(i)) { writer.Write(textConstants[i], typeof(ushort), textConstants[i].Length > 0); } else { writer.Write((ushort)textData.Length); writer.Write(textData); } } else { writer.Write(reader.ReadBytes(GetConstantPoolItemInfoLength(tag))); } } // Write the rest of the file without changes writer.Write(reader.ReadBytes((int)(OriginalStream.Length - OriginalStream.Position))); // Clean to prevent errors OriginalStream = null; return(format); }
public IntegerFloatInfo(ref ReadOnlySpan <byte> fileData, ConstantPoolTag tag) : base(tag) { IntegerValue = (int)fileData.ReadFourBytes(); }