public void VisitNew(NewObj newer) { if (m_offset < 0) { if (DoMatchCtor(newer.Ctor)) { MethodDefinition method = DoFindCtor(newer.Ctor); if (method != null) { Log.DebugLine(this, "found ctor at {0:X2}", newer.Untyped.Offset); for (int i = 0; i < method.Parameters.Count && m_offset < 0; ++i) { ParameterDefinition p = method.Parameters[i]; Log.DebugLine(this, "checking parameter{0}: {1}", i, p.Name); if (DoIsValidArg(p)) { Log.DebugLine(this, "found parameter at {0}", i); int nth = method.Parameters.Count - i - 1; DoCheck(newer, newer.Ctor, nth); } } } } } }
bool TransformDecimalCtorToConstant(NewObj inst, out LdcDecimal result) { IType t = inst.Method.DeclaringType; result = null; if (!t.IsKnownType(KnownTypeCode.Decimal)) { return(false); } var args = inst.Arguments; if (args.Count == 1) { int val; if (args[0].MatchLdcI4(out val)) { result = new LdcDecimal(val); return(true); } } else if (args.Count == 5) { int lo, mid, hi, isNegative, scale; if (args[0].MatchLdcI4(out lo) && args[1].MatchLdcI4(out mid) && args[2].MatchLdcI4(out hi) && args[3].MatchLdcI4(out isNegative) && args[4].MatchLdcI4(out scale)) { result = new LdcDecimal(new decimal(lo, mid, hi, isNegative != 0, (byte)scale)); return(true); } } return(false); }
protected internal override void VisitNewObj(NewObj inst) { if (TransformDecimalCtorToConstant(inst, out LdcDecimal decimalConstant)) { context.Step("TransformDecimalCtorToConstant", inst); inst.ReplaceWith(decimalConstant); return; } Block block; if (TransformSpanTCtorContainingStackAlloc(inst, out ILInstruction locallocSpan)) { inst.ReplaceWith(locallocSpan); block = null; ILInstruction stmt = locallocSpan; while (stmt.Parent != null) { if (stmt.Parent is Block b) { block = b; break; } stmt = stmt.Parent; } //ILInlining.InlineIfPossible(block, stmt.ChildIndex - 1, context); return; } if (TransformArrayInitializers.TransformSpanTArrayInitialization(inst, context, out block)) { context.Step("TransformSpanTArrayInitialization: single-dim", inst); inst.ReplaceWith(block); return; } base.VisitNewObj(inst); }
/*SE consultan las materias que estan en la BD para llenar el grid*/ IEnumerator MostrarKardex(string v) { Debug.Log("NUMERO DE CONTROL " + PlayerPrefs.GetString("no_control")); WWWForm form = new WWWForm(); form.AddField("funcion", "materias_usuario"); form.AddField("parametros", PlayerPrefs.GetString("no_control")); WWW www = new WWW(ApplicationModel.URLConsultas, form); yield return(www); Debug.Log(www.text); if (www.text != "") { KardexBd[] kardlist1 = JsonHelper.FromJson <KardexBd>("{\r\n \"Items\":" + www.text + "\r\n}"); Debug.Log(kardlist1.Length); numerToCreate = kardlist1.Length; for (int i = 0; i < kardlist1.Length; i++) { GameObject NewObj; NewObj = (GameObject)Instantiate(prefab, transform); Image img = NewObj.GetComponent <Image>(); img.sprite = materiasSprites[kardlist1[i].id_materia - 1]; NewObj.transform.GetChild(0).GetComponent <Text>().text = "" + kardlist1[i].nombre_materia; //Sprite sprites = new Sprite("Spritesheet"); int idbtn = kardlist1[i].id_materia; NewObj.GetComponentInChildren <Button>().onClick.AddListener(() => Entrenar_click(idbtn)); } } }
void AddNodeText(Vector3 pos, string strTag, string name, int code) { GameObject theSelectedObj; GameObject NewObj; theSelectedObj = GameObject.FindGameObjectWithTag("txtValue"); NewObj = Instantiate(theSelectedObj, pos, Quaternion.identity); NewObj.transform.SetParent(gameObject.transform, true); NewObj.name = name; //NewObj.GetComponent<GUIText>().text = code.ToString(); NewObj.GetComponent <TextMesh>().text = code.ToString(); GameObject UItextGO = new GameObject("Text2"); UItextGO.transform.SetParent(gameObject.transform, true); RectTransform trans = UItextGO.AddComponent <RectTransform>(); trans.anchoredPosition = new Vector2(pos.x, pos.y); Text text = UItextGO.AddComponent <Text>(); text.text = code.ToString(); text.fontSize = 40; text.color = Color.black; // return UItextGO; }
/// <summary> /// newobj Delegate..ctor(target, ldvirtftn TargetMethod(target)) /// => /// ldvirtdelegate System.Delegate TargetMethod(target) /// </summary> bool TransformDelegateCtorLdVirtFtnToLdVirtDelegate(NewObj inst, out LdVirtDelegate ldVirtDelegate) { ldVirtDelegate = null; if (inst.Method.DeclaringType.Kind != TypeKind.Delegate) { return(false); } if (inst.Arguments.Count != 2) { return(false); } if (!(inst.Arguments[1] is LdVirtFtn ldVirtFtn)) { return(false); } if (!SemanticHelper.IsPure(inst.Arguments[0].Flags)) { return(false); } if (!inst.Arguments[0].Match(ldVirtFtn.Argument).Success) { return(false); } ldVirtDelegate = new LdVirtDelegate(inst.Arguments[0], inst.Method.DeclaringType, ldVirtFtn.Method) .WithILRange(inst).WithILRange(ldVirtFtn).WithILRange(ldVirtFtn.Argument); return(true); }
static bool MatchSpanTCtorWithPointerAndSize(NewObj newObj, StatementTransformContext context, out IType elementType, out FieldDefinition field, out int size) { field = default; size = default; elementType = null; IType type = newObj.Method.DeclaringType; if (!type.IsKnownType(KnownTypeCode.SpanOfT) && !type.IsKnownType(KnownTypeCode.ReadOnlySpanOfT)) { return(false); } if (newObj.Arguments.Count != 2 || type.TypeArguments.Count != 1) { return(false); } elementType = type.TypeArguments[0]; if (!newObj.Arguments[0].UnwrapConv(ConversionKind.StopGCTracking).MatchLdsFlda(out var member)) { return(false); } if (member.MetadataToken.IsNil) { return(false); } if (!newObj.Arguments[1].MatchLdcI4(out size)) { return(false); } field = context.PEFile.Metadata.GetFieldDefinition((FieldDefinitionHandle)member.MetadataToken); return(true); }
public void VisitNewObj(NewObj newobj) { if (newobj.Ctor.ToString().StartsWith("System.Void System.Threading.ThreadStart::.ctor(")) { m_newOffsets.Add(newobj.Untyped.Offset); Log.DebugLine(this, " found new at: {0:X2}", newobj.Untyped.Offset); } }
ILFunction TransformDelegateConstruction(NewObj value, out ILInstruction target) { target = null; if (!IsDelegateConstruction(value)) { return(null); } var targetMethod = ((IInstructionWithMethodOperand)value.Arguments[1]).Method; if (!IsAnonymousMethod(decompilationContext.CurrentTypeDefinition, targetMethod)) { return(null); } if (LocalFunctionDecompiler.IsLocalFunctionMethod(targetMethod.ParentModule.PEFile, (MethodDefinitionHandle)targetMethod.MetadataToken)) { return(null); } target = value.Arguments[0]; if (targetMethod.MetadataToken.IsNil) { return(null); } var methodDefinition = context.PEFile.Metadata.GetMethodDefinition((MethodDefinitionHandle)targetMethod.MetadataToken); if (!methodDefinition.HasBody()) { return(null); } var genericContext = GenericContextFromTypeArguments(targetMethod.Substitution); if (genericContext == null) { return(null); } var ilReader = context.CreateILReader(); var body = context.PEFile.Reader.GetMethodBody(methodDefinition.RelativeVirtualAddress); var function = ilReader.ReadIL((MethodDefinitionHandle)targetMethod.MetadataToken, body, genericContext.Value, context.CancellationToken); function.DelegateType = value.Method.DeclaringType; function.CheckInvariant(ILPhase.Normal); var contextPrefix = targetMethod.Name; foreach (ILVariable v in function.Variables.Where(v => v.Kind != VariableKind.Parameter)) { v.Name = contextPrefix + v.Name; } var nestedContext = new ILTransformContext(context, function); function.RunTransforms(CSharpDecompiler.GetILTransforms().TakeWhile(t => !(t is DelegateConstruction)), nestedContext); function.AcceptVisitor(new ReplaceDelegateTargetVisitor(target, function.Variables.SingleOrDefault(v => v.Index == -1 && v.Kind == VariableKind.Parameter))); // handle nested lambdas ((IILTransform) new DelegateConstruction()).Run(function, nestedContext); function.AddILRange(target.ILRange); function.AddILRange(value.Arguments[1].ILRange); return(function); }
public void VisitNewObj(NewObj newobj) { DBC.Assert(m_state == State.Calls, "state is {0}", m_state); if (m_types.Count > 0) { DoRemoveTypes(newobj.Ctor.DeclaringType); } }
public void VisitNew(NewObj newer) { int i = m_methods.BinarySearch(newer.Ctor, m_comparer); if (i >= 0) { Log.TraceLine(this, "removing {0} (ctor is called)", m_methods[i]); m_methods.RemoveAt(i); } }
/// <summary> /// Creates a new object /// </summary> /// <param name="constructor">Constructor to use</param> /// <param name="variables">Variables to use</param> /// <returns>The new object</returns> public virtual VariableBase NewObj(ConstructorInfo constructor, object[] variables = null) { SetCurrentMethod(); var tempCommand = new NewObj(constructor, variables); tempCommand.Setup(); Commands.Add(tempCommand); ++ObjectCounter; return(tempCommand.Result); }
// newobj System.Void System.ObjectDisposedException::.ctor(System.String) public void VisitNewObj(NewObj call) { if (m_disposable) { if (call.Ctor.ToString().Contains("ObjectDisposedException")) { m_doesThrow = true; } } }
/// <summary> /// Creates a new object /// </summary> /// <param name="Constructor">Constructor to use</param> /// <param name="Variables">Variables to use</param> /// <returns>The new object</returns> public virtual VariableBase NewObj(ConstructorInfo Constructor, object[] Variables = null) { SetCurrentMethod(); NewObj TempCommand = new NewObj(Constructor, Variables); TempCommand.Setup(); Commands.Add(TempCommand); ++ObjectCounter; return(TempCommand.Result); }
internal static bool IsDelegateConstruction(NewObj inst, bool allowTransformed = false) { if (inst == null || inst.Arguments.Count != 2 || inst.Method.DeclaringType.Kind != TypeKind.Delegate) { return(false); } var opCode = inst.Arguments[1].OpCode; return(opCode == OpCode.LdFtn || opCode == OpCode.LdVirtFtn || (allowTransformed && opCode == OpCode.ILFunction)); }
protected internal override void VisitNewObj(NewObj inst) { LdcDecimal decimalConstant; if (TransformDecimalCtorToConstant(inst, out decimalConstant)) { context.Step("TransformDecimalCtorToConstant", inst); inst.ReplaceWith(decimalConstant); return; } base.VisitNewObj(inst); }
public void VisitNew(NewObj obj) { if (m_offset < 0 && obj.Index + 1 < m_info.Instructions.Length) { TypedInstruction prev = m_info.Instructions[obj.Index + 1]; if (prev.Untyped.OpCode.Code == Code.Pop) { m_offset = obj.Untyped.Offset; Log.DebugLine(this, "Matched at {0:X2}", m_offset); } } }
/// <summary> /// newobj Span..ctor(localloc(conv i4->u <zero extend>(ldc.i4 sizeInBytes)), numberOfElementsExpr) /// => /// localloc.span T(numberOfElementsExpr) /// /// -or- /// /// newobj Span..ctor(Block IL_0000 (StackAllocInitializer) { /// stloc I_0(localloc(conv i4->u<zero extend>(ldc.i4 sizeInBytes))) /// ... /// final: ldloc I_0 /// }, numberOfElementsExpr) /// => /// Block IL_0000 (StackAllocInitializer) { /// stloc I_0(localloc.span T(numberOfElementsExpr)) /// ... /// final: ldloc I_0 /// } /// </summary> bool TransformSpanTCtorContainingStackAlloc(NewObj newObj, out ILInstruction locallocSpan) { locallocSpan = null; IType type = newObj.Method.DeclaringType; if (!type.IsKnownType(KnownTypeCode.SpanOfT) && !type.IsKnownType(KnownTypeCode.ReadOnlySpanOfT)) { return(false); } if (newObj.Arguments.Count != 2 || type.TypeArguments.Count != 1) { return(false); } IType elementType = type.TypeArguments[0]; if (newObj.Arguments[0].MatchLocAlloc(out var sizeInBytes) && MatchesElementCount(sizeInBytes, elementType, newObj.Arguments[1])) { locallocSpan = new LocAllocSpan(newObj.Arguments[1], type); return(true); } if (newObj.Arguments[0] is Block initializer && initializer.Kind == BlockKind.StackAllocInitializer) { if (!initializer.Instructions[0].MatchStLoc(out var initializerVariable, out var value)) { return(false); } if (!(value.MatchLocAlloc(out sizeInBytes) && MatchesElementCount(sizeInBytes, elementType, newObj.Arguments[1]))) { return(false); } var newVariable = initializerVariable.Function.RegisterVariable(VariableKind.InitializerTarget, type); foreach (var load in initializerVariable.LoadInstructions.ToArray()) { ILInstruction newInst = new LdLoc(newVariable); newInst.AddILRange(load); if (load.Parent != initializer) { newInst = new Conv(newInst, PrimitiveType.I, false, Sign.None); } load.ReplaceWith(newInst); } foreach (var store in initializerVariable.StoreInstructions.ToArray()) { store.Variable = newVariable; } value.ReplaceWith(new LocAllocSpan(newObj.Arguments[1], type)); locallocSpan = initializer; return(true); } return(false); }
/// <summary> /// Matches 'newobj TupleType(...)'. /// Takes care of flattening long tuples. /// </summary> public static bool MatchTupleConstruction(NewObj newobj, out ILInstruction[] arguments) { arguments = null; if (newobj == null) { return(false); } if (!TupleType.IsTupleCompatible(newobj.Method.DeclaringType, out int elementCount)) { return(false); } arguments = new ILInstruction[elementCount]; int outIndex = 0; while (elementCount >= TupleType.RestPosition) { if (newobj.Arguments.Count != TupleType.RestPosition) { return(false); } for (int pos = 1; pos < TupleType.RestPosition; pos++) { arguments[outIndex++] = newobj.Arguments[pos - 1]; } elementCount -= TupleType.RestPosition - 1; Debug.Assert(outIndex + elementCount == arguments.Length); newobj = newobj.Arguments.Last() as NewObj; if (newobj == null) { return(false); } if (!TupleType.IsTupleCompatible(newobj.Method.DeclaringType, out int restElementCount)) { return(false); } if (restElementCount != elementCount) { return(false); } } Debug.Assert(outIndex + elementCount == arguments.Length); if (newobj.Arguments.Count != elementCount) { return(false); } for (int i = 0; i < elementCount; i++) { arguments[outIndex++] = newobj.Arguments[i]; } return(true); }
public void VisitNew(NewObj obj) { if (m_offset < 0) { if (obj.Ctor.ToString() == "System.Void System.Text.RegularExpressions.Regex::.ctor(System.String)") { LoadString prev = m_info.Instructions[obj.Index - 1] as LoadString; if (prev != null && !DoIsValidRegEx(prev.Value)) { m_offset = obj.Untyped.Offset; } } } }
ILFunction TransformDelegateConstruction(NewObj value, out ILInstruction target) { target = null; if (!IsDelegateConstruction(value)) { return(null); } var targetMethod = ((IInstructionWithMethodOperand)value.Arguments[1]).Method; if (!IsAnonymousMethod(decompilationContext.CurrentTypeDefinition, targetMethod)) { return(null); } target = value.Arguments[0]; var methodDefinition = (Mono.Cecil.MethodDefinition)context.TypeSystem.GetCecil(targetMethod); if (methodDefinition == null) { return(null); } var localTypeSystem = context.TypeSystem.GetSpecializingTypeSystem(targetMethod.Substitution); var ilReader = new ILReader(localTypeSystem); ilReader.UseDebugSymbols = context.Settings.UseDebugSymbols; var function = ilReader.ReadIL(methodDefinition.Body, context.CancellationToken); function.DelegateType = value.Method.DeclaringType; function.CheckInvariant(ILPhase.Normal); var contextPrefix = targetMethod.Name; foreach (ILVariable v in function.Variables.Where(v => v.Kind != VariableKind.Parameter)) { v.Name = contextPrefix + v.Name; } var nestedContext = new ILTransformContext(function, localTypeSystem, context.Settings) { CancellationToken = context.CancellationToken, DecompileRun = context.DecompileRun }; function.RunTransforms(CSharpDecompiler.GetILTransforms().TakeWhile(t => !(t is DelegateConstruction)), nestedContext); function.AcceptVisitor(new ReplaceDelegateTargetVisitor(target, function.Variables.SingleOrDefault(v => v.Index == -1 && v.Kind == VariableKind.Parameter))); // handle nested lambdas ((IILTransform) new DelegateConstruction()).Run(function, nestedContext); function.AddILRange(target.ILRange); function.AddILRange(value.Arguments[1].ILRange); return(function); }
public void VisitNew(NewObj obj) { string name = obj.Ctor.ToString(); if (name == "System.Void System.Random::.ctor()") { Log.DebugLine(this, "found new at {0:X2}", obj.Untyped.Offset); ++m_numNew; if (m_offset < 0) { m_offset = obj.Untyped.Offset; } } }
public void VisitThrow(Throw thrw) { if (m_offset < 0) { NewObj newObj = m_info.Instructions[thrw.Index - 1] as NewObj; if (newObj != null) { string name = newObj.Ctor.ToString(); if (name.Contains("System.Exception::.ctor") || name.Contains("System.SystemException::.ctor") || name.Contains("System.ApplicationException::.ctor")) { m_offset = thrw.Untyped.Offset; Log.DebugLine(this, "bad throw at {0:X2}", m_offset); } } } }
public void VisitThrow(Throw thrw) { if (m_offset < 0) { NewObj newObj = m_info.Instructions[thrw.Index - 1] as NewObj; if (newObj != null) { string name = newObj.Ctor.DeclaringType.Name; if (Array.IndexOf(m_badNames, name) >= 0) { m_offset = thrw.Untyped.Offset; Log.DebugLine(this, "reserved throw at {0:X2}", m_offset); } } } }
/// <summary> /// This function adds a node to the positions pos /// </summary> void AddNode(Vector3 pos, string strTag, string name) { GameObject theSelectedObj; GameObject NewObj; theSelectedObj = GameObject.FindGameObjectWithTag(strTag); NewObj = Instantiate(theSelectedObj, pos, Quaternion.identity); if (name == "n_100") { NewObj.GetComponent <SpriteRenderer>().color = Color.magenta; NewObj.transform.localScale = NewObj.transform.localScale * 2f; } NewObj.transform.SetParent(gameObject.transform, true); NewObj.name = name; }
public void VisitNew(NewObj newer) { if (m_offset < 0) { if (newer.Ctor.ToString().StartsWith("System.Void System.Threading.Mutex::.ctor(") || newer.Ctor.ToString().StartsWith("System.Void System.Threading.Semaphore::.ctor(")) { for (int i = 0; i < newer.Ctor.Parameters.Count && m_offset < 0; ++i) { if (newer.Ctor.Parameters[i].ParameterType.FullName == "System.String") { m_offset = newer.Untyped.Offset; Log.DebugLine(this, "found bad call at {0:X2}", m_offset); } } } } }
internal static ILInstruction HandleCall(Call inst, ILTransformContext context) { if (inst.Method.IsConstructor && !inst.Method.IsStatic && inst.Method.DeclaringType.Kind == TypeKind.Struct) { Debug.Assert(inst.Arguments.Count == inst.Method.Parameters.Count + 1); context.Step("Transform call to struct constructor", inst); // call(ref, ...) // => stobj(ref, newobj(...)) var newObj = new NewObj(inst.Method); newObj.ILRange = inst.ILRange; newObj.Arguments.AddRange(inst.Arguments.Skip(1)); var expr = new StObj(inst.Arguments[0], newObj, inst.Method.DeclaringType); inst.ReplaceWith(expr); return(expr); } return(null); }
protected internal override void VisitNewObj(NewObj inst) { if (TransformDecimalCtorToConstant(inst, out LdcDecimal decimalConstant)) { context.Step("TransformDecimalCtorToConstant", inst); inst.ReplaceWith(decimalConstant); return; } Block block; if (TransformSpanTCtorContainingStackAlloc(inst, out ILInstruction locallocSpan)) { context.Step("new Span<T>(stackalloc) -> stackalloc Span<T>", inst); inst.ReplaceWith(locallocSpan); block = null; ILInstruction stmt = locallocSpan; while (stmt.Parent != null) { if (stmt.Parent is Block b) { block = b; break; } stmt = stmt.Parent; } // Special case to eliminate extra store if (stmt.GetNextSibling() is StLoc storeStmt && storeStmt.Value is LdLoc) { ILInlining.InlineIfPossible(block, stmt.ChildIndex, context); } return; } if (TransformArrayInitializers.TransformSpanTArrayInitialization(inst, context, out block)) { context.Step("TransformSpanTArrayInitialization: single-dim", inst); inst.ReplaceWith(block); return; } if (TransformDelegateCtorLdVirtFtnToLdVirtDelegate(inst, out LdVirtDelegate ldVirtDelegate)) { context.Step("new Delegate(target, ldvirtftn Method) -> ldvirtdelegate Delegate Method(target)", inst); inst.ReplaceWith(ldVirtDelegate); return; } base.VisitNewObj(inst); }
public void VisitNew(NewObj obj) { if (m_needsCheck && m_offset < 0) { TypeReference tr = obj.Ctor.DeclaringType; if (tr.IsSameOrSubclassOf("System.Security.CodeAccessPermission", Cache)) { m_offset = obj.Untyped.Offset; Log.DebugLine(this, "found CAS at {0:X2}", m_offset); } else if (tr.IsSameOrSubclassOf("System.Security.PermissionSet", Cache)) { m_offset = obj.Untyped.Offset; Log.DebugLine(this, "found PS at {0:X2}", m_offset); } } }
// ldftn System.Void Smokey.Tests.StaticSetterTest/GoodCase::DoThread(System.Object) // newobj System.Void System.Threading.ParameterizedThreadStart::.ctor(System.Object,System.IntPtr) // // ldftn System.Void Smokey.Tests.StaticSetterTest/BadCase3::DoThread() // newobj System.Void System.Threading.ThreadStart::.ctor(System.Object,System.IntPtr) // // ldftn System.Void Smokey.Tests.StaticSetterTest/BadCase5::DoCallback(System.Object) // newobj System.Void System.Threading.WaitCallback::.ctor(System.Object,System.IntPtr) // // ldftn System.Void Smokey.Tests.StaticSetterTest/BadCase7::DoCallback(System.Object) // newobj System.Void System.Threading.TimerCallback::.ctor(System.Object,System.IntPtr) public void VisitNewObj(NewObj newobj) { if (newobj.Ctor.ToString().Contains("System.Threading")) // optimize common case where it's not a threading call { if (newobj.Ctor.ToString().Contains("System.Threading.ParameterizedThreadStart::.ctor") || newobj.Ctor.ToString().Contains("System.Threading.ThreadStart::.ctor") || newobj.Ctor.ToString().Contains("System.Threading.WaitCallback::.ctor") || newobj.Ctor.ToString().Contains("System.Threading.TimerCallback::.ctor")) { LoadFunctionAddress fptr = m_info.Instructions[newobj.Index - 1] as LoadFunctionAddress; if (fptr != null) { Log.DebugLine(this, "found thread function: {0}", fptr.Method); m_threadRoots.Add(fptr.Method); } } } }