public static x86ConstLocation GetNullLocation(x86Architecture Arch, IdContainer Container) { var Value = new IntegerValue(0); var Type = Container.GlobalContainer.CommonIds.VoidPtr; return(new x86ConstLocation(Arch, Value, Type, 0, Type.Size)); }
public static bool SamePosition(x86Architecture Arch, ExpressionNode Self, x86DataLocation N, x86OverlappingMode Mode = x86OverlappingMode.Whole) { var S = x86Expressions.GetLocation(Arch, Self); return(S == null ? false : S.Compare(N, Mode)); }
public x86DataList(x86Architecture Arch, bool Alloc = true) { this.Arch = Arch; if (Alloc) { GRegisters = new x86GRegisterList(Arch.RegCount); SSERegisters = new x86RegisterList(Arch.RegCount); } }
public static x86DataLocation GetLocation(x86Architecture Arch, Identifier Id) { var IdData = Id.Data.Get <x86IdentifierData>(); var IdPos = IdData == null ? null : IdData.Location; if (IdPos != null) { return(IdPos); } return(GetDefaultIdLocation(Arch, Id)); }
private static x86DataLocation GetDescLocation(x86Architecture Arch, Identifier Id) { Id = Id.UnderlyingStructureOrSelf; var Assembly = Id.Container.AssemblyScope.Assembly; if (Id.DescPosition == -1) { var Label = Assembly.DescLabel + " + ?? (" + Id.AssemblyName + ")"; return(new x86NamedLabelPosition(Arch, Label)); } else { var Label = Assembly.DescLabel + " + " + (Id.DescPosition + Arch.RegSize * 2); return(new x86NamedLabelPosition(Arch, Label)); } }
static x86DataLocation GetDefaultIdLocation(x86Architecture Arch, Identifier Id) { Id = Id.RealId; if (Id is Type) { return(GetDescLocation(Arch, Id)); } else if (Id is Function) { return(new x86NamedLabelPosition(Arch, Id.AssemblyName)); } else if (Id is GlobalVariable) { var Label = new x86NamedLabelPosition(Arch, Id.AssemblyName); var Type = Id.TypeOfSelf.RealId as Type; return(new x86IndexLocation(Arch, 0, Type.Size, Label)); } else { throw new NotImplementedException(); } }
private static x86MemoryLocation GetIndexerPosition(x86Architecture Arch, x86DataLocation Address, x86GRegLocation AddressTempGReg, x86DataLocation Offset, x86GRegLocation OffsetTempGReg, int Size, int Displacement = 0, byte Scale = 1) { if (Offset != null && Address.Size != Offset.Size) { throw new ApplicationException(); } var Ret = new x86IndexLocation(Arch, 0, Size, null); if (!Ret.Add(Address, AddressTempGReg)) { return(null); } if (Offset != null && !Ret.Add(Offset, OffsetTempGReg, Scale)) { return(null); } Ret.Offset += Displacement; return(Ret); }
public static x86DataLocation GetLocation(x86Architecture Arch, ExpressionNode Node) { var Data = Node.Data.Get <x86NodeData>(); var Type = Node.Type.RealId as Type; var Size = Type.Size; if (Data != null && Data.Output != null) { if (Data.Output is x86PostCalcedLocation) { return(Data.ExtractedOutput); } return(Data.Output); } else if (Node is OpExpressionNode) { var OpNode = Node as OpExpressionNode; var Op = OpNode.Operator; var Ch = OpNode.Children; if (Op == Operator.Assignment) { return(GetLocation(Arch, Ch[0])); } else if (Op == Operator.Index) { var Address = GetLocation(Arch, Ch[0]); var Offset = GetLocation(Arch, Ch[1]); if (Address == null || Offset == null) { return(null); } var Ch0Type = Ch[0].Type.RealId; var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 0); var OffsetTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 1); if (Ch0Type is PointerType) { return(GetIndexerPosition(Arch, Address, AddressTempGReg, Offset, OffsetTempGReg, Size, Data.Displacement, Data.Scale)); } else { throw new ApplicationException(); } } else if (Op == Operator.Member) { var IdCh1 = Ch[1] as IdExpressionNode; if (IdCh1 == null) { throw new ApplicationException(); } if (IdCh1.Identifier is Function && !IsVirtualMember(Node)) { return(GetDefaultIdLocation(Arch, IdCh1.Identifier)); } var SrcPos = GetLocation(Arch, Ch[0]); if (SrcPos == null) { return(null); } var Ch0Type = Ch[0].Type.RealId as Type; var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, 0); if ((Ch0Type.TypeFlags & TypeFlags.ReferenceValue) != 0) { SrcPos = GetIndexerPosition(Arch, SrcPos, AddressTempGReg, null, null, Ch0Type.InstanceSize); } if (SrcPos == null) { return(null); } #warning WARNING, temp solution to allow ZinniaCore compilation SrcPos = SrcPos.GetPart(0); SrcPos.Size = int.MaxValue; var Splitable = SrcPos as x86SplittableLocation; if (Splitable == null) { throw new ApplicationException(); } if (IdCh1.Identifier is MemberVariable) { var MemVar = IdCh1.Identifier as MemberVariable; return(Splitable.GetPart(MemVar.Offset, Size)); } else if (IdCh1.Identifier is MemberFunction) { var MemFunc = IdCh1.Identifier as MemberFunction; var Ptrs = Splitable.GetPart(0, Size); var RegSize = Arch.RegSize; var Global = MemFunc.Container.GlobalContainer; var OffsetValue = new IntegerValue(MemFunc.VirtualIndex * RegSize); var OffsetType = Global.CommonIds.GetIdentifier(typeof(SignedType), RegSize); var Offset = new x86ConstLocation(Arch, OffsetValue, OffsetType, 0, RegSize); return(GetIndexerPosition(Arch, Ptrs, AddressTempGReg, Offset, null, RegSize)); } throw new ApplicationException(); } else if (Op == Operator.Unknown) { if (Data.Operator == x86Operator.Swap) { var Locations = new x86DataLocation[2]; Locations[0] = GetLocation(Arch, Ch[0]); Locations[1] = GetLocation(Arch, Ch[1]); if (Locations[0] == null || Locations[1] == null) { return(null); } return(new x86MultiLocation(Arch, Size, Locations)); } } } else if (Node is ConstExpressionNode) { var ConstNode = Node as ConstExpressionNode; return(new x86ConstLocation(Arch, ConstNode, 0, Size)); } else if (Node is IdExpressionNode) { var IdNode = Node as IdExpressionNode; var Id = IdNode.Identifier; if (!(Id is LocalVariable)) { return(GetDefaultIdLocation(Arch, Id)); } var IdData = Id.Data.Get <x86IdentifierData>(); var IdPos = IdData.Location; if (IdPos == null) { return(null); } if ((Data.Flags & x86NodeFlags.IdentifierByRef) != 0) { Type = Id.Container.GlobalContainer.CommonIds.GetIdentifier(typeof(SignedType), Arch.RegSize); var Offset = new x86ConstLocation(Arch, new IntegerValue(0), Type, 0, Arch.RegSize); var AddressTempGReg = Data.TempData.GetGRegister(x86TempGRegPurposeType.Index, -1); return(GetIndexerPosition(Arch, IdPos, AddressTempGReg, Offset, null, Size)); } return(IdPos); } else if (Node is DataPointerNode) { var IdDescNode = Node as DataPointerNode; if (IdDescNode.DescPointerType == DataPointerType.Assembly) { return(new x86NamedLabelPosition(Arch, IdDescNode.Assembly.DescLabel)); } else if (IdDescNode.DescPointerType == DataPointerType.Identifier) { return(GetDescLocation(Arch, IdDescNode.Id)); } else if (IdDescNode.DescPointerType == DataPointerType.IncBin) { return(new x86NamedLabelPosition(Arch, IdDescNode.IncBin.Label)); } else { throw new NotImplementedException(); } } else if (Node is LabelExpressionNode) { var LabelNode = Node as LabelExpressionNode; return(new x86NamedLabelPosition(Arch, LabelNode.Label)); } return(null); }
public x86DataSequence(x86Architecture Arch, x86SequenceOptions Options) { this.Arch = Arch; this.Options = Options; }
public x86ExpressionPlugin(PluginRoot Parent) : base(Parent) { this.Arch = State.Arch as x86Architecture; }