Beispiel #1
0
        public RoverService(IInstructionFactory instructionFactory, IPlateauService plateauService)
        {
            rovers = new List <Rover>();

            _instructionFactory = instructionFactory;
            _plateauService     = plateauService;
        }
Beispiel #2
0
 /// <summary>
 /// Prepares a new disassembler instance for the code located at the memory address provided. The instructions can then be disassembled with a call to <see cref="Disassemble"/>. The base address used to resolve relative addresses should be provided in <paramref name="address"/>.
 /// </summary>
 /// <param name="codePtr">A pointer to memory to be disassembled.</param>
 /// <param name="codeLength">The maximum length to be disassembled.</param>
 /// <param name="architecture">The architecture of the code (e.g. 64-bit, 32-bit or 16-bit).</param>
 /// <param name="address">The address of the first byte of code. This value is used to resolve relative addresses into absolute addresses while disassembling.</param>
 /// <param name="copyBinaryToInstruction">Keeps a copy of the binary code for the instruction. This will increase the memory usage for each instruction. This is necessary if planning on using the <see cref="Translators.Translator.IncludeBinary"/> option.</param>
 /// <param name="vendor">What vendors to support for disassembly, default is Any. Other options are AMD or Intel.</param>
 /// <param name="instructionFactory">The instruction factory. if null InstructionFactory is used.</param>
 public Disassembler(IntPtr codePtr, int codeLength, ArchitectureMode architecture,
                     ulong address = 0x0, bool copyBinaryToInstruction = false,
                     Vendor vendor = Vendor.Any, IInstructionFactory instructionFactory = null)
     : this(new AssemblyCodeMemory(codePtr, codeLength), architecture, address, copyBinaryToInstruction, vendor, instructionFactory)
 {
     if (codePtr == IntPtr.Zero)
     {
         throw new ArgumentOutOfRangeException("codePtr");
     }
     if (codeLength <= 0)
     {
         throw new ArgumentOutOfRangeException("codeLength", "Code length must be larger than 0.");
     }
 }
Beispiel #3
0
        public IntcodeProgram(string value, IInstructionFactory instructionFactory, IOpcodeParser opcodeParser)
        {
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            _program = value
                       .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                       .Select(number => int.Parse(number, CultureInfo.InvariantCulture))
                       .ToList();

            _instructionFactory = instructionFactory ?? throw new ArgumentNullException(nameof(instructionFactory));
            _opcodeParser       = opcodeParser ?? throw new ArgumentNullException(nameof(opcodeParser));
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Disassembler"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="address">The address.</param>
        /// <param name="copyBinaryToInstruction">if set to <c>true</c> [copy binary to instruction].</param>
        /// <param name="vendor">The vendor.</param>
        /// <param name="instructionFactory">The instruction factory. if null InstructionFactory is used.</param>
        public Disassembler(IAssemblyCode code, ArchitectureMode architecture, ulong address = 0x0,
                            bool copyBinaryToInstruction = false,
                            Vendor vendor = Vendor.Any, IInstructionFactory instructionFactory = null)
        {
            this.code = code;

            this.Architecture            = architecture;
            this.Address                 = address;
            this.CopyBinaryToInstruction = copyBinaryToInstruction;
            this.Vendor = vendor;
            if (instructionFactory == null)
            {
                this.InstructionFactory = new InstructionFactory();
            }
            else
            {
                this.InstructionFactory = instructionFactory;
            }

            InitUdis86();
        }
Beispiel #5
0
        public void Add(Queue <Opcode> opcodes, IInstructionFactory factory)
        {
            if (opcodes.Any())
            {
                var opcode = opcodes.Dequeue();
                _offset = opcode.Offset;

                if (!_opSizes.ContainsKey((uint)opcode.Value.Length))
                {
                    _opSizes[(uint)opcode.Value.Length] = new Dictionary <uint, Resolver>();
                }

                if (!_opSizes[(uint)opcode.Value.Length].ContainsKey(opcode.Value.ToUnsignedInt()))
                {
                    _opSizes[(uint)opcode.Value.Length][opcode.Value.ToUnsignedInt()] = new Resolver();
                }

                _opSizes[(uint)opcode.Value.Length][opcode.Value.ToUnsignedInt()].Add(opcodes, factory);
            }
            else
            {
                _instructionFactory = factory;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Prepares a new disassembler instance for the code provided. The instructions can then be disassembled with a call to <see cref="Disassemble"/>. The base address used to resolve relative addresses should be provided in <paramref name="address"/>.
 /// </summary>
 /// <param name="code">The code to be disassembled</param>
 /// <param name="architecture">The target x86 instruction set architecture of the code (e.g. 64-bit, 32-bit or 16-bit).</param>
 /// <param name="address">The address of the first byte of code. This value is used to resolve relative addresses into absolute addresses while disassembling.</param>
 /// <param name="copyBinaryToInstruction">Keeps a copy of the binary code for the instruction. This will increase the memory usage for each instruction. This is necessary if planning on using the <see cref="Translators.Translator.IncludeBinary"/> option.</param>
 /// <param name="vendor">What vendor instructions to support during disassembly, default is Any. Other options are AMD or Intel.</param>
 /// <param name="instructionFactory">The instruction factory. if null InstructionFactory is used.</param>
 public Disassembler(byte[] code, ArchitectureMode architecture, ulong address = 0x0, bool copyBinaryToInstruction = false,
                     Vendor vendor = Vendor.Any, IInstructionFactory instructionFactory = null)
     : this(new AssemblyCodeArray(code), architecture, address, copyBinaryToInstruction, vendor, instructionFactory)
 {
 }
Beispiel #7
0
 public IntcodeProgram(int[] value, IInstructionFactory instructionFactory, IOpcodeParser opcodeParser)
 {
     _program            = value?.ToList() ?? throw new ArgumentNullException(nameof(value));
     _instructionFactory = instructionFactory ?? throw new ArgumentNullException(nameof(instructionFactory));
     _opcodeParser       = opcodeParser ?? throw new ArgumentNullException(nameof(opcodeParser));
 }
Beispiel #8
0
 public Disassembler()
 {
     _instructionFactory = new InstructionFactory();
     _inputParser        = new InputParser();
 }
 public ParseInputsService(IInstructionFactory instructionFactory)
 {
     _instructionFactory = instructionFactory;
     ParseMessages       = new ObservableCollection <string>();
 }