static object ReadCodedToken(int col, MetadataTable tbl, MetadataReader rdr, uint[] lens) { TableToken tkn = new TableToken(tbl.Heap); tkn.Token = CodedIndexDefs.MdCodedIndexDefs[(CodedIndex)tbl.TableDef.Columns[col].Value].ReadToken(rdr, lens); return(tkn); }
public void Read(SignatureReader rdr) { m = rdr.ReadElementType(); if (m != ElementType.Modifier_Optional && m != ElementType.Modifier_Required) { throw new InvalidOperationException(); } TablesHeap h = rdr.BaseStream.Root[MetadataStreamType.Tables].Heap as TablesHeap; t = new TableToken(h); int len = Math.Max(h[TableType.TypeDef].Rows.Count, Math.Max(h[TableType.TypeRef].Rows.Count, h[TableType.TypeSpec].Rows.Count)); uint tkn; if (len > ushort.MaxValue) { tkn = rdr.ReadUInt32(); } else { tkn = rdr.ReadUInt16(); } switch (tkn & 0x3) { case 0: t.Token = new MetadataToken(MetadataTokenType.TypeDef, (uint)tkn >> 2); break; case 1: t.Token = new MetadataToken(MetadataTokenType.TypeRef, (uint)tkn >> 2); break; case 2: t.Token = new MetadataToken(MetadataTokenType.TypeSpec, (uint)tkn >> 2); break; } }
public static void ValidateTypeDefOfRef(TableToken tkn) { if (tkn.Token.Type != MetadataTokenType.TypeDef && tkn.Token.Type != MetadataTokenType.TypeRef && tkn.Token.Type != MetadataTokenType.TypeSpec) { throw new InvalidOperationException(); } }
public void Load(bool isTiny, BinaryReader rdr) { if (isTiny) { f = (ExceptionClauseFlags)rdr.ReadUInt16(); to = rdr.ReadUInt16(); tl = rdr.ReadByte(); ho = rdr.ReadUInt16(); hl = rdr.ReadByte(); } else { f = (ExceptionClauseFlags)rdr.ReadUInt32(); to = rdr.ReadUInt32(); tl = rdr.ReadUInt32(); ho = rdr.ReadUInt32(); hl = rdr.ReadUInt32(); } if ((f & ExceptionClauseFlags.Filter) == ExceptionClauseFlags.Filter) { fo = rdr.ReadUInt32(); } else { tkn = new TableToken(par.Container.Heap); tkn.Token = rdr.ReadUInt32(); } }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); vt = rdr.ReadElementType() == ElementType.ValueType; t = rdr.ReadTypeDefOrRefEncoded(); ts = new TypeElementCollection(); ts.Read(rdr); }
static object ReadTableToken(int col, MetadataTable tbl, MetadataReader rdr, uint[] lens) { TableToken tkn = new TableToken(tbl.Heap); tkn.Token = new MetadataToken((MetadataTokenType)tbl.TableDef.Columns[col].Value, 0); if (lens[(int)tbl.Type] > ushort.MaxValue) { tkn.Token.Index = rdr.ReadUInt32(); } else { tkn.Token.Index = rdr.ReadUInt16(); } return(tkn); }
public void WriteTypeDefOrRefEncoded(TableToken tkn) { TablesHeap h = BaseStream.Root[MetadataStreamType.Tables].Heap as TablesHeap; switch (tkn.Token.Type) { case MetadataTokenType.TypeDef: base.Write7BitEncodedInt((int)(tkn.Token.Index << 2 | 0)); break; case MetadataTokenType.TypeRef: base.Write7BitEncodedInt((int)(tkn.Token.Index << 2 | 1)); break; case MetadataTokenType.TypeSpec: base.Write7BitEncodedInt((int)(tkn.Token.Index << 2 | 2)); break; } }
public async void IdsAvailable(string playerId, string pushToken) { var db = new DbContext(); var token = db.GetToken(); if (token != null) { var table = new TableToken(); table.PlayerID = playerId; table.Token = pushToken; db.UpdateToken(table); } else { var table = new TableToken(); table.PlayerID = playerId; table.Token = pushToken; db.InsertToken(table); } }
public override void Load(BinaryReader rdr) { byte fmt = rdr.ReadByte(); switch ((HeaderFlags)(fmt & 0x3)) { case HeaderFlags.TinyFormat: f = HeaderFlags.TinyFormat; ms = 8; lvs = new TableToken(Parent.Container.Heap); lvs.Token = 0; c = rdr.ReadBytes(fmt >> 2); break; case HeaderFlags.FatFormat: rdr.BaseStream.Seek(-1, SeekOrigin.Current); ushort ff = rdr.ReadUInt16(); f = (HeaderFlags)(ff & 0xfff); if ((ff >> 12) != 3) { throw new InvalidOperationException(); } ms = rdr.ReadUInt16(); uint s = rdr.ReadUInt32(); lvs = new TableToken(Parent.Container.Heap); lvs.Token = rdr.ReadUInt32(); c = rdr.ReadBytes((int)s); break; } rdr.ReadBytes((int)(((rdr.BaseStream.Position + 3) & ~3) - rdr.BaseStream.Position)); sects = new DataSectionCollection(Parent); if ((f & HeaderFlags.MoreSects) == HeaderFlags.MoreSects) { sects.Load(rdr); } }
void ReadRvaData(MetadataTable tbl, MetadataReader mdRdr, List <Rva> rvas, MetadataRowCollection rows) { List <Rva> sorted = new List <Rva>(rvas); sorted.Sort(); for (int i = 0; i < rvas.Count; i++) { Rva rva = rvas[i]; MetadataRow r = rows[i + 1]; byte[] dat = null; VirtualReader rdr = new VirtualReader(mdRdr.BaseStream.File.SectionHeaders.GetVirtualStream()); if (tbl.Type == TableType.FieldRVA) { MetadataRoot root = tbl.Heap.Stream.Root; rdr.SetPosition(rva); MetadataRow fd = (r["Field"] as TableToken).ResolveRow(); FieldSig sig = new FieldSig(); SignatureReader sigRdr = new SignatureReader(new MetadataReader(root[MetadataStreamType.Blob])); sigRdr.BaseStream.Position = (fd["Signature"] as BlobToken).Token.Index; sig.Read(sigRdr); int c = 0; switch (sig.Type.Element) { case ElementType.Boolean: case ElementType.UInt8: case ElementType.Int8: c = 1; break; case ElementType.UInt16: case ElementType.Int16: case ElementType.Char: c = 2; break; case ElementType.UInt32: case ElementType.Int32: case ElementType.Single: c = 4; break; case ElementType.UInt64: case ElementType.Int64: case ElementType.Double: c = 8; break; case ElementType.ValueType: TableToken vt = (sig.Type as VALUETYPE).Type; foreach (MetadataRow cl in tbl.Heap[TableType.ClassLayout]) { if (cl["Parent"] == vt) { c = (int)cl["ClassSize"]; break; } } break; default: throw new InvalidOperationException("ReadRvaData"); } dat = rdr.ReadBytes(c); } else if (tbl.Type == TableType.MethodDef && rva != 0) { //MethodBody bdy; //if (((MethodImplAttributes)r["ImplFlags"] & MethodImplAttributes.Native) == MethodImplAttributes.Native) //{ // bdy = new NativeMethodBody(r); //} //else //{ // bdy = new ManagedMethodBody(r); //} //rdr.SetPosition(rva); //bdy.Load(rdr); //rdr.SetPosition(rva); //dat = rdr.ReadBytes((int)bdy.Size); int idx; Rva next; if ((idx = sorted.IndexOf(rva)) == sorted.Count - 1) { CLRDirectory root = tbl.Heap.Stream.Root.Directory; Rva now; next = uint.MaxValue; rdr.SetPosition(root.Location.Address); rdr.BaseStream.Seek(0x8, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0xC, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } } else { next = sorted[idx + 1]; } rdr.SetPosition(rva); dat = rdr.ReadBytes((int)(next - rva)); } if (!tbl.Heap.Stream.Root.Directory.Datas.ContainsAddress(rva) && dat != null) { tbl.Heap.Stream.Root.Directory.Datas.Add(new CLRData() { Address = rva, Data = dat }); } } }
public LexicalAnalyzer() { TableToken.ClearTable(); TableSymbol.ClearTable(); TableSymbol.AddSymbol(new Symbol { Id = 1, Name = "algoritmo" }); TableSymbol.AddSymbol(new Symbol { Id = 2, Name = "var" }); TableSymbol.AddSymbol(new Symbol { Id = 3, Name = "inicio" }); TableSymbol.AddSymbol(new Symbol { Id = 4, Name = "fimalgoritmo" }); TableSymbol.AddSymbol(new Symbol { Id = 5, Name = "inteiro" }); TableSymbol.AddSymbol(new Symbol { Id = 6, Name = "real" }); TableSymbol.AddSymbol(new Symbol { Id = 7, Name = "caractere" }); TableSymbol.AddSymbol(new Symbol { Id = 8, Name = "logico" }); TableSymbol.AddSymbol(new Symbol { Id = 9, Name = "vetor" }); TableSymbol.AddSymbol(new Symbol { Id = 10, Name = "escreval" }); TableSymbol.AddSymbol(new Symbol { Id = 11, Name = "leia" }); TableSymbol.AddSymbol(new Symbol { Id = 12, Name = "para" }); TableSymbol.AddSymbol(new Symbol { Id = 13, Name = "de" }); TableSymbol.AddSymbol(new Symbol { Id = 14, Name = "ate" }); TableSymbol.AddSymbol(new Symbol { Id = 15, Name = "faca" }); TableSymbol.AddSymbol(new Symbol { Id = 16, Name = "fimpara" }); TableSymbol.AddSymbol(new Symbol { Id = 17, Name = "se" }); TableSymbol.AddSymbol(new Symbol { Id = 18, Name = "senao" }); TableSymbol.AddSymbol(new Symbol { Id = 19, Name = "fimse" }); TableSymbol.AddSymbol(new Symbol { Id = 19, Name = "entao" }); }
public void AnalyzeCode(string code) { code = code.ToLower(); StringBuilder str = new StringBuilder(); int estate = 0; Symbol symbol; bool literal = false; for (int i = 0; i < code.Length; i++) { while (estate != -1) { if (i >= code.Length) { break; } if (char.IsDigit(code[i])) { estate = TransitionTable[estate, GetKeywordColumn('d')]; } else if (char.IsLetter(code[i])) { estate = TransitionTable[estate, GetKeywordColumn('l')]; } else if (char.IsWhiteSpace(code[i]) && literal == false) { break; } else if (!char.IsLetterOrDigit(code[i])) { if (!char.IsWhiteSpace(code[i])) { estate = TransitionTable[estate, GetKeywordColumn(code[i])]; if (code[i] == '\"') { if (literal == false) { literal = true; } else { literal = false; } } } if (literal == false && code[i] != '\"') { break; } } if (estate == -1) { break; } str.Append(code[i]); i++; } double num; if (!string.IsNullOrWhiteSpace(str.ToString())) { symbol = new Symbol() { Id = TableSymbol.Table.Count + 1, Name = str.ToString() }; if (!TableSymbol.ContainsSymbol(symbol)) { TableSymbol.AddSymbol(symbol); } if (reservedWords.Contains(symbol.Name)) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.PALAVRA_RESERVADA }); } else if (separators.Contains(symbol.Name)) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.SEPARADOR }); } else if (operators.Contains(symbol.Name)) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.OPERADOR }); } else if (symbol.Name.StartsWith("\\")) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.COMENTARIO }); } else if (symbol.Name.StartsWith("\"") && symbol.Name.EndsWith("\"")) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.LITERAL }); } else if (double.TryParse(symbol.Name, out num)) { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.NUMERO }); } else { TableToken.AddToken(new Token() { Id = TableSymbol.GetSymbolId(symbol), Name = symbol.Name, Type = TypeToken.IDENTIFICADOR }); } } str = new StringBuilder(); estate = 0; } }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); tkn = rdr.ReadTypeDefOrRefEncoded(); }