internal DllField(FieldDefinition f) { LayoutOffset = f.Offset; DeclaringType = DllTypeRef.From(f.DeclaringType); Type = DllTypeRef.From(f.FieldType); Name = f.Name; Offset = -1; if (f.HasCustomAttributes) { foreach (var ca in f.CustomAttributes) { if (ca.AttributeType.Name == "FieldOffsetAttribute") { if (ca.Fields.Count > 0) { Offset = Convert.ToInt32(ca.Fields.FirstOrDefault().Argument.Value as string, 16); } } else { // Ignore the DummyDll attributes var atr = new DllAttribute(ca); if (!string.IsNullOrEmpty(atr.Name)) { Attributes.Add(atr); } } } } Specifiers.AddRange(DllSpecifierHelpers.From(f)); This = f; Constant = f.Constant; }
/// <summary>Set <paramref name="specifier"/> as the ONLY specifier for this noun phrase</summary> private void SetSpecifier(IElementTreeNode specifier) { if (Specifiers.Count() == 0) { AddChildWithRole(specifier, ChildRole.Specifier); } else { throw new InvalidOperationException("Can't add multiple specifiers to a noun phrase"); } }
internal DllProperty(PropertyDefinition p) { DeclaringType = DllTypeRef.From(p.DeclaringType); Type = DllTypeRef.From(p.PropertyType); Name = p.Name; GetMethod = p.GetMethod != null; SetMethod = p.SetMethod != null; if (p.HasCustomAttributes) { Attributes.AddRange(p.CustomAttributes.Select(ca => new DllAttribute(ca)).Where(a => !string.IsNullOrEmpty(a.Name))); } Specifiers.AddRange(DllSpecifierHelpers.From(p)); }
private void ComparePrint(MarketDescriptionDTO dto, CultureInfo culture) { var names = _names.Aggregate(string.Empty, (current, name) => current + $", {name.Key.TwoLetterISOLanguageName}-{name.Value}").Substring(2); var desc = _descriptions.Aggregate(string.Empty, (current, d) => current + $", {d.Key.TwoLetterISOLanguageName}-{d.Value}"); var specs = Specifiers == null ? null : string.Join(", ", Specifiers.Select(s => s.Name)); var outcomes = Outcomes == null ? null : string.Join(",", Outcomes.Select(s => s.Id)); var maps = Mappings == null ? null : string.Join(",", Mappings.Select(s => s.MarketTypeId)); ExecutionLog.Debug($"Original Id={Id}, Names=[{names}], Descriptions=[{desc}], Variant=[{Variant}], Specifiers=[{specs}], Outocomes=[{outcomes}], Mappings=[{maps}]."); var specsNew = dto.Specifiers == null ? null : string.Join(", ", dto.Specifiers.Select(s => s.Name)); var outcomesNew = dto.Outcomes == null ? null : string.Join(",", dto.Outcomes.Select(s => s.Id)); var mapsNew = dto.Mappings == null ? null : string.Join(",", dto.Mappings.Select(s => s.MarketTypeId)); ExecutionLog.Debug($"New Id={dto.Id}, Name=[{culture.TwoLetterISOLanguageName}-{dto.Name}], Descriptions=[{dto.Description}], Variant=[{dto.Variant}], Specifiers=[{specsNew}], Outocomes=[{outcomesNew}], Mappings=[{mapsNew}]."); }
internal DumpProperty(TypeRef declaring, PeekableStreamReader fs) { DeclaringType = declaring; var line = fs.PeekLine()?.Trim(); while (line != null && line.StartsWith("[")) { Attributes.Add(new DumpAttribute(fs)); line = fs.PeekLine()?.Trim(); } line = fs.ReadLine()?.Trim() ?? ""; var split = line.Split(' '); if (split.Length < 5) { throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Property cannot be created from: \"{line.Trim()}\""); } // Start at the end (but before the }), count back until we hit a { (or we have gone 3 steps) // Keep track of how far back we count int i; for (i = 0; i < 3; i++) { var val = split[split.Length - 2 - i]; if (val == "{") { break; } else if (val == "get;") { GetMethod = true; } else if (val == "set;") { SetMethod = true; } } Name = split[split.Length - 3 - i]; Type = new DumpTypeRef(DumpTypeRef.FromMultiple(split, split.Length - 4 - i, out int adjust, -1, " ")); for (int j = 0; j < adjust; j++) { Specifiers.Add(new DumpSpecifier(split[j])); } }
internal DllField(FieldDefinition f, TypeDefinition info) { LayoutOffset = f.Offset; DeclaringType = DllTypeRef.From(f.DeclaringType); Type = DllTypeRef.From(f.FieldType); Name = f.Name; Offset = -1; if (f.HasCustomAttributes) { foreach (var ca in f.CustomAttributes) { if (ca.AttributeType.Name == "FieldOffsetAttribute" || ca.AttributeType.Name == "StaticFieldOffsetAttribute") { if (ca.Fields.Count > 0) { Offset = Convert.ToInt32(ca.Fields.FirstOrDefault().Argument.Value as string, 16); } //if (info.IsEnum) // // Because Il2CppInspector is bad and emits 0x10 for fields on enums. I seriously don't know why. // Offset -= 0x10; } else { // Ignore the DummyDll attributes var atr = new DllAttribute(ca); if (!string.IsNullOrEmpty(atr.Name)) { Attributes.Add(atr); } } } } Specifiers.AddRange(DllSpecifierHelpers.From(f)); This = f; Constant = f.Constant; }
public virtual bool CanHandle(Interpretation interpretation) { if (!Commands.Contains(interpretation.Command)) { return(false); } if (!string.IsNullOrEmpty(interpretation.Specifier) && !Specifiers.Contains(interpretation.Specifier)) { return(false); } if (!CheckMatch(interpretation.Primary, PrimaryTargetMode)) { return(false); } if (!CheckMatch(interpretation.Secondary, SecondaryTargetMode)) { return(false); } return(true); }
/// <summary> /// Returns a <see cref="string" /> that represents this instance. /// </summary> /// <returns>A <see cref="string" /> that represents this instance</returns> public override string ToString() { var sb = new StringBuilder(); sb.Append("Id=").Append(Id); if (Specifiers != null) { sb.Append(", Specifiers=").Append(string.Join(SdkInfo.SpecifiersDelimiter, Specifiers.Select(kv => kv.Key + "=" + kv.Value))); } return(sb.ToString()); }
private DllMethod(MethodDefinition m, ref HashSet <MethodDefinition> mappedBaseMethods) { cache.Add(m, this); This = m; // Il2CppName is the MethodDefinition Name (hopefully we don't need to convert it for il2cpp, but we might) Il2CppName = m.Name; Name = m.Name; Parameters.AddRange(m.Parameters.Select(p => new Parameter(p))); Specifiers.AddRange(DllSpecifierHelpers.From(m)); // This is not necessary: m.GenericParameters.Any(param => !m.DeclaringType.GenericParameters.Contains(param)); Generic = m.HasGenericParameters; GenericParameters = m.GenericParameters.Select(g => DllTypeRef.From(g)).ToList(); // This may not always be the case, we could have a special name in which case we have to do some sorcery // Grab the special name, grab the type from the special name int idxDot = Name.LastIndexOf('.'); if (idxDot >= 2) { // Call a utilities function for converting a special name method to a proper base method var baseMethod = m.GetSpecialNameBaseMethod(out var iface, idxDot); if (baseMethod is null) { throw new Exception("Failed to find baseMethod for dotted method name!"); } if (iface is null) { throw new Exception("Failed to get iface for dotted method name!"); } if (!mappedBaseMethods.Add(baseMethod)) { throw new InvalidOperationException($"Base method: {baseMethod} has already been overriden!"); } // Only one base method for special named methods BaseMethods.Add(From(baseMethod, ref mappedBaseMethods)); ImplementedFrom = DllTypeRef.From(iface); } else { var baseMethod = m.GetBaseMethod(); if (baseMethod == m) { var baseMethods = m.GetBaseMethods(); if (baseMethods.Count > 0) { HidesBase = true; } // We need to check here SPECIFICALLY for a method in our declaring type that shares the same name as us, since we could have the same BaseMethod as it. // If either ourselves or a method of the same safe name (after . prefixes) exists, we need to ensure that only the one with the dots gets the base method // It correctly describes. // Basically, we need to take all our specially named methods on our type that have already been defined and remove them from our current list of baseMethods. // We should only ever have baseMethods of methods that are of methods that we haven't already used yet. if (baseMethods.Count > 0) { foreach (var baseM in mappedBaseMethods) { baseMethods.Remove(baseM); } } foreach (var bm in baseMethods) { BaseMethods.Add(From(bm, ref mappedBaseMethods)); } } else { if (!mappedBaseMethods.Add(baseMethod)) { throw new InvalidOperationException($"Base method: {baseMethod} has already been overriden!"); } BaseMethods.Add(From(baseMethod, ref mappedBaseMethods)); } } if (BaseMethods.Count > 0) { // TODO: This may not be true for generic methods. Should ensure validity for IEnumerator<T> methods // This method is an implemented/overriden method. // TODO: We need to double check to see if we need multiple ImplementedFroms ImplementedFrom = BaseMethods.First().DeclaringType; // Add ourselves to our BaseMethod's ImplementingMethods foreach (var bm in BaseMethods) { bm.ImplementingMethods.Add(this); } } ReturnType = DllTypeRef.From(m.ReturnType); DeclaringType = DllTypeRef.From(m.DeclaringType); // This is a very rare condition that we need to handle if it ever happens, but for now just log it if (m.HasOverrides) { Console.WriteLine($"{m}.HasOverrides!!! Overrides: {string.Join(", ", m.Overrides)}"); } RVA = -1; Offset = -1; VA = -1; Slot = -1; if (m.HasCustomAttributes) { foreach (var ca in m.CustomAttributes) { if (ca.AttributeType.Name == "AddressAttribute") { if (ca.Fields.Count >= 3) { for (int i = 0; i < ca.Fields.Count; i++) { var f = ca.Fields[i]; if (f.Name == "RVA" || f.Name == "Offset" || f.Name == "VA") { var val = Convert.ToInt32(f.Argument.Value as string, 16); if (f.Name == "RVA") { RVA = val; } else if (f.Name == "Offset") { Offset = val; } else if (f.Name == "VA") { VA = val; } } else if (f.Name == "Slot") { Slot = Convert.ToInt32(f.Argument.Value as string); } } } } else { // Ignore the DummyDll attributes Attributes.Add(new DllAttribute(ca)); } } } }