protected ElfLoader(IServiceProvider services, ElfMachine machine, EndianServices endianness, byte[] rawImage) : this() { this.Services = services; this.machine = machine; this.endianness = endianness; this.rawImage = rawImage; }
public MipsProcessorArchitecture(string archId, EndianServices endianness, PrimitiveType wordSize, PrimitiveType ptrSize) : base(archId) { this.Endianness = endianness; this.WordWidth = wordSize; this.PointerType = ptrSize; this.FramePointerType = ptrSize; this.InstructionBitSize = 32; this.GeneralRegs = CreateGeneralRegisters().ToArray(); this.StackRegister = GeneralRegs[29]; this.LinkRegister = GeneralRegs[31]; this.hi = new RegisterStorage("hi", 32, 0, wordSize); this.lo = new RegisterStorage("lo", 33, 0, wordSize); this.fpuRegs = CreateFpuRegisters(); this.FCSR = RegisterStorage.Reg32("FCSR", 0x201F); this.ccRegs = CreateCcRegs(); this.fpuCcRegs = CreateFpuCcRegs(); this.fpuCtrlRegs = new Dictionary <uint, RegisterStorage> { { 0x1F, FCSR } }; this.mpNameToReg = GeneralRegs .Concat(fpuRegs) .Concat(fpuCtrlRegs.Values) .Concat(ccRegs) .Concat(new[] { hi, lo }) .ToDictionary(k => k.Name); }
public SuperHArchitecture(string archId, EndianServices endianness) : base(archId) { this.Endianness = endianness; this.FramePointerType = PrimitiveType.Ptr32; this.InstructionBitSize = 16; this.PointerType = PrimitiveType.Ptr32; this.WordWidth = PrimitiveType.Word32; // No architecture-defined stack register -- defined by platform. }
public SuperHArchitecture(IServiceProvider services, string archId, EndianServices endianness) : base(services, archId) { this.Endianness = endianness; this.FramePointerType = PrimitiveType.Ptr32; this.InstructionBitSize = 16; this.PointerType = PrimitiveType.Ptr32; this.WordWidth = PrimitiveType.Word32; // No architecture-defined stack register -- defined by platform. this.grfs = new Dictionary <uint, FlagGroupStorage>(); }
protected ElfLoader() { this.Services = null !; this.Symbols = new Dictionary <ulong, Dictionary <int, ElfSymbol> >(); this.DynamicSymbols = new Dictionary <int, ElfSymbol>(); this.Sections = new List <ElfSection>(); this.Segments = new List <ElfSegment>(); this.DynamicEntries = new Dictionary <long, ElfDynamicEntry>(); this.Dependencies = new List <string>(); this.endianness = null !; this.Architecture = null !; this.rawImage = null !; }
protected override IProcessorArchitecture?CreateArchitecture(EndianServices endianness) { var options = new Dictionary <string, object>(); string archName; switch (machine) { case ElfMachine.EM_IA_64: archName = "ia64"; break; case ElfMachine.EM_MIPS: //$TODO: detect release 6 of the MIPS architecture. // would be great to get our sweaty little hands on // such a binary. archName = endianness == EndianServices.Little ? "mips-le-64" : "mips-be-64"; break; case ElfMachine.EM_PARISC: archName = "paRisc"; options["WordSize"] = "64"; break; case ElfMachine.EM_RISCV: archName = "risc-v"; options["WordSize"] = "64"; var flags = (RiscVFlags)Header64.e_flags; // According to the Risc-V ELF spec, a RV64G implementation is strongly // encouraged to support the LP64D ABI if ((flags & RiscVFlags.EF_RISCV_FLOAT_ABI_MASK) == 0) { flags |= RiscVFlags.EF_RISCV_FLOAT_ABI_DOUBLE; } RiscVElf.SetOptions(flags, options); break; case ElfMachine.EM_S390: //$REVIEW: any pertinent differences? archName = "zSeries"; options["WordSize"] = "64"; break; default: return(base.CreateArchitecture(endianness)); } var cfgSvc = Services.RequireService <IConfigurationService>(); var arch = cfgSvc.GetArchitecture(archName, options); return(arch); }
protected override IProcessorArchitecture CreateArchitecture(EndianServices endianness) { var options = new Dictionary <string, object>(); string archName; switch (machine) { case ElfMachine.EM_IA_64: archName = "ia64"; break; case ElfMachine.EM_MIPS: //$TODO: detect release 6 of the MIPS architecture. // would be great to get our sweaty little hands on // such a binary. archName = endianness == EndianServices.Little ? "mips-le-64" : "mips-be-64"; break; case ElfMachine.EM_PARISC: archName = "paRisc"; options["WordSize"] = "64"; break; case ElfMachine.EM_RISCV: archName = "risc-v"; options["WordSize"] = "64"; RiscVElf.SetOptions((RiscVFlags)Header64.e_flags, options); break; case ElfMachine.EM_S390: //$REVIEW: any pertinent differences? archName = "zSeries"; options["WordSize"] = "64"; break; default: return(base.CreateArchitecture(endianness)); } var cfgSvc = Services.RequireService <IConfigurationService>(); var arch = cfgSvc.GetArchitecture(archName); arch.LoadUserOptions(options); return(arch); }
public ElfLoader64(IServiceProvider services, Elf64_EHdr elfHeader, byte osAbi, EndianServices endianness, byte[] rawImage) : base(services, (ElfMachine)elfHeader.e_machine, endianness, rawImage) { this.Header64 = elfHeader; this.osAbi = osAbi; base.rawImage = rawImage; }
protected virtual IProcessorArchitecture CreateArchitecture(EndianServices endianness) { var cfgSvc = Services.RequireService <IConfigurationService>(); var options = new Dictionary <string, object>(); string arch; string stackRegName = null; switch (this.machine) { case ElfMachine.EM_NONE: return(null); // No machine case ElfMachine.EM_SPARC: case ElfMachine.EM_SPARC32PLUS: arch = "sparc32"; break; case ElfMachine.EM_SPARCV9: arch = "sparc64"; break; case ElfMachine.EM_386: arch = "x86-protected-32"; break; case ElfMachine.EM_X86_64: arch = "x86-protected-64"; break; case ElfMachine.EM_68K: arch = "m68k"; break; case ElfMachine.EM_PPC: arch = "ppc-be-32"; break; case ElfMachine.EM_PPC64: arch = "ppc-be-64"; break; case ElfMachine.EM_ARM: arch = "arm"; break; case ElfMachine.EM_AARCH64: arch = "arm-64"; break; case ElfMachine.EM_XTENSA: arch = "xtensa"; break; case ElfMachine.EM_AVR: arch = "avr8"; break; case ElfMachine.EM_MSP430: arch = "msp430"; break; case ElfMachine.EM_SH: arch = endianness == EndianServices.Little ? "superH-le" : "superH-be"; // SuperH stack pointer is not defined by the architecture, // but by the application itself. It appears r15 has been // chosen by at least the NetBSD folks. stackRegName = "r15"; break; case ElfMachine.EM_ALPHA: arch = "alpha"; // Alpha has no architecture-defined stack pointer. // Alpha-Linux uses r30. stackRegName = "r30"; break; case ElfMachine.EM_NANOMIPS: arch = endianness == EndianServices.Little ? "mips-le-32" : "mips-be-32"; options["decoder"] = "nano"; break; case ElfMachine.EM_BLACKFIN: arch = "blackfin"; break; case ElfMachine.EM_MORPHOS_PPC: arch = "ppc-be-32"; break; case ElfMachine.EM_PARISC: arch = "paRisc"; options["WordSize"] = "32"; break; case ElfMachine.EM_AVR32: case ElfMachine.EM_AVR32a: arch = "avr32"; break; case ElfMachine.EM_HEXAGON: arch = "hexagon"; break; default: throw new NotSupportedException($"Processor format {machine} is not supported."); } var a = cfgSvc.GetArchitecture(arch); a.LoadUserOptions(options); if (stackRegName != null) { a.StackRegister = a.GetRegister(stackRegName); } return(a); }
public EvalCtx(EndianServices e) { this.Endianness = e; }
/// <summary> /// Creates an instance of PowerPcArchitecture. /// </summary> /// <param name="wordWidth">Supplies the word width of the PowerPC architecture.</param> public PowerPcArchitecture(IServiceProvider services, string archId, EndianServices endianness, PrimitiveType wordWidth, PrimitiveType signedWord, Dictionary <string, object> options) : base(services, archId, options) { Endianness = endianness; WordWidth = wordWidth; SignedWord = signedWord; PointerType = PrimitiveType.Create(Domain.Pointer, wordWidth.BitSize); FramePointerType = PointerType; InstructionBitSize = 32; this.lr = new RegisterStorage("lr", 0x48, 0, wordWidth); this.ctr = new RegisterStorage("ctr", 0x49, 0, wordWidth); this.xer = new RegisterStorage("xer", 0x4A, 0, wordWidth); this.fpscr = new RegisterStorage("fpscr", 0x4B, 0, wordWidth); this.cr = new RegisterStorage("cr", 0x4C, 0, wordWidth); this.acc = new RegisterStorage("acc", 0x4D, 0, PrimitiveType.Word64); // gp regs 0..1F // fpu regs 20..3F // CR regs 40..47 // vectors 80..FF fpregs = new ReadOnlyCollection <RegisterStorage>( Enumerable.Range(0, 0x20) .Select(n => new RegisterStorage("f" + n, n + 0x20, 0, PrimitiveType.Word64)) .ToList()); cregs = new ReadOnlyCollection <RegisterStorage>( Enumerable.Range(0, 8) .Select(n => new RegisterStorage("cr" + n, n + CcFieldMin, 0, PrimitiveType.Byte)) .ToList()); vregs = new ReadOnlyCollection <RegisterStorage>( Enumerable.Range(0, 128) // VMX128 extension has 128 regs .Select(n => new RegisterStorage("v" + n, n + 0x80, 0, PrimitiveType.Word128)) .ToList()); ccFlagGroups = Enumerable.Range(0, 8) .Select(n => new FlagGroupStorage(cr, 0xFu << (n * 4), $"cr{n}", PrimitiveType.Byte)) .ToDictionary(f => f.FlagGroupBits); ccFlagGroupsByName = ccFlagGroups.Values .ToDictionary(f => f.Name); regs = new ReadOnlyCollection <RegisterStorage>( Enumerable.Range(0, 0x20) .Select(n => new RegisterStorage("r" + n, n, 0, wordWidth)) .Concat(fpregs) .Concat(cregs) .Concat(new[] { lr, ctr, xer }) .Concat(vregs) .ToList()); spregs = new Dictionary <int, RegisterStorage> { { 8, new RegisterStorage("lr", 0x0100 + 8, 0, PointerType) }, { 9, new RegisterStorage("ctr", 0x0100 + 9, 0, WordWidth) }, { 26, new RegisterStorage("srr0", 0x0100 + 26, 0, PrimitiveType.Word32) }, { 27, new RegisterStorage("srr1", 0x0100 + 27, 0, PrimitiveType.Word32) }, }; //$REVIEW: using R1 as the stack register is a _convention_. It // should be platform-specific at the very least. StackRegister = regs[1]; LoadUserOptions(options); }
public ElfLoader32(IServiceProvider services, Elf32_EHdr header32, byte osAbi, EndianServices endianness, byte[] rawImage) : base(services, (ElfMachine)header32.e_machine, endianness, rawImage) { this.Header = header32 ?? throw new ArgumentNullException(nameof(header32)); }
protected override IProcessorArchitecture CreateArchitecture(EndianServices endianness) { string arch; var options = new Dictionary <string, object>(); string stackRegName = null; switch (machine) { case ElfMachine.EM_MIPS: //$TODO: detect release 6 of the MIPS architecture. // would be great to get our sweaty little hands on // such a binary. var mipsFlags = (MIPSflags)Header.e_flags; bool is64 = false; switch (mipsFlags & MIPSflags.EF_MIPS_ARCH) { case MIPSflags.EF_MIPS_ARCH_64: is64 = true; break; case MIPSflags.EF_MIPS_ARCH_64R2: is64 = true; options["decoder"] = "v6"; break; case MIPSflags.EF_MIPS_ARCH_32R2: options["decoder"] = "v6"; break; } if (endianness == EndianServices.Little) { arch = is64 ? "mips-le-64" : "mips-le-32"; } else if (endianness == EndianServices.Big) { arch = is64 ? "mips-be-64" : "mips-be-32"; } else { throw new NotSupportedException(string.Format("The MIPS architecture does not support ELF endianness value {0}", endianness)); } break; case ElfMachine.EM_RISCV: arch = "risc-v"; options["WordSize"] = "32"; RiscVElf.SetOptions((RiscVFlags)Header.e_flags, options); break; default: return(base.CreateArchitecture(endianness)); } var cfgSvc = Services.RequireService <IConfigurationService>(); var a = cfgSvc.GetArchitecture(arch); a.LoadUserOptions(options); if (stackRegName != null) { a.StackRegister = a.GetRegister(stackRegName); } return(a); }
protected override IProcessorArchitecture?CreateArchitecture(EndianServices endianness) { string arch; var options = new Dictionary <string, object>(); string?stackRegName = null; options[ProcessorOption.Endianness] = (endianness == EndianServices.Little) ? "le" : "be"; switch (machine) { case ElfMachine.EM_MIPS: //$TODO: detect release 6 of the MIPS architecture. // would be great to get our sweaty little hands on // such a binary. var mipsFlags = (MIPSflags)Header.e_flags; bool is64 = false; switch (mipsFlags & MIPSflags.EF_MIPS_ARCH) { case MIPSflags.EF_MIPS_ARCH_64: is64 = true; break; case MIPSflags.EF_MIPS_ARCH_64R2: is64 = true; options[ProcessorOption.InstructionSet] = "v6"; break; case MIPSflags.EF_MIPS_ARCH_32R2: options[ProcessorOption.InstructionSet] = "v6"; break; } if (endianness == EndianServices.Little) { arch = is64 ? "mips-le-64" : "mips-le-32"; } else if (endianness == EndianServices.Big) { arch = is64 ? "mips-be-64" : "mips-be-32"; } else { throw new NotSupportedException($"The MIPS architecture does not support ELF endianness value {endianness}."); } break; case ElfMachine.EM_RISCV: arch = "risc-v"; options[ProcessorOption.WordSize] = "32"; RiscVElf.SetOptions((RiscVFlags)Header.e_flags, options); break; default: return(base.CreateArchitecture(endianness)); } var cfgSvc = Services.RequireService <IConfigurationService>(); var a = cfgSvc.GetArchitecture(arch, options); if (a is null) { throw new InvalidOperationException($"Unknown architecture '{arch}'."); } if (stackRegName != null) { var sp = a.GetRegister(stackRegName); if (sp != null) { a.StackRegister = sp; } } return(a); }