Example #1
0
 /// <summary>
 /// Creates a new wrapper around a raw stream containing x86 code.
 /// </summary>
 /// <param name="architecture">The x86 architecture.</param>
 /// <param name="inputStream">The raw code stream.</param>
 /// <param name="bitness">The bitness of the x86 code. This value must be either 16, 32 or 64.</param>
 public X86DecoderInstructionProvider(
     IInstructionSetArchitecture <Instruction> architecture,
     Stream inputStream,
     int bitness)
     : this(architecture, inputStream, bitness, 0, DecoderOptions.None)
 {
 }
Example #2
0
 /// <summary>
 /// Creates a new wrapper around a raw stream containing x86 code.
 /// </summary>
 /// <param name="architecture">The x86 architecture.</param>
 /// <param name="inputCode">The raw code stream.</param>
 /// <param name="bitness">The bitness of the x86 code. This value must be either 16, 32 or 64.</param>
 public X86DecoderInstructionProvider(
     IInstructionSetArchitecture <Instruction> architecture,
     byte[] inputCode,
     int bitness)
     : this(architecture, new MemoryStream(inputCode), bitness, 0, DecoderOptions.None)
 {
 }
Example #3
0
 /// <summary>
 /// Creates a new static graph builder using the provided instruction successor resolver.
 /// </summary>
 /// <param name="architecture">The architecture of the instructions.</param>
 /// <param name="instructions">The instructions to traverse.</param>
 /// <param name="successorResolver">The object used to determine the successors of a single instruction.</param>
 /// <exception cref="ArgumentNullException">Occurs when any of the arguments is <c>null</c>.</exception>
 public StaticFlowGraphBuilder(
     IInstructionSetArchitecture <TInstruction> architecture,
     IEnumerable <TInstruction> instructions,
     IStaticSuccessorResolver <TInstruction> successorResolver)
 {
     Instructions      = new ListInstructionProvider <TInstruction>(architecture, instructions);
     SuccessorResolver = successorResolver ?? throw new ArgumentNullException(nameof(successorResolver));
 }
Example #4
0
 /// <summary>
 /// Creates a new symbolic control flow graph builder using the provided program state transition resolver.
 /// </summary>
 /// <param name="architecture">The architecture of the instructions.</param>
 /// <param name="instructions">The instructions to traverse.</param>
 /// <param name="transitionResolver">The transition resolver to use for inferring branch targets.</param>
 public SymbolicFlowGraphBuilder(
     IInstructionSetArchitecture <TInstruction> architecture,
     IEnumerable <TInstruction> instructions,
     IStateTransitionResolver <TInstruction> transitionResolver)
 {
     Instructions       = new StaticToSymbolicAdapter <TInstruction>(architecture, instructions);
     TransitionResolver = transitionResolver ?? throw new ArgumentNullException(nameof(transitionResolver));
 }
Example #5
0
        /// <summary>
        /// Creates a new wrapper for a sequence of instructions.
        /// </summary>
        /// <param name="architecture">The instruction architecture.</param>
        /// <param name="instructions">The instructions to put into the wrapper.</param>
        /// <exception cref="ArgumentException">Occurs when there are multiple instructions with the same offset.</exception>
        /// <exception cref="ArgumentNullException">Occurs when the provided instruction sequence is <c>null</c>.</exception>
        public ListInstructionProvider(IInstructionSetArchitecture <TInstruction> architecture, IEnumerable <TInstruction> instructions)
        {
            if (instructions == null)
            {
                throw new ArgumentNullException(nameof(instructions));
            }
            Architecture = architecture;

            foreach (var instruction in instructions)
            {
                long offset = architecture.GetOffset(instruction);
                if (_instructions.ContainsKey(offset))
                {
                    throw new ArgumentException($"Sequence contains multiple instructions with the offset {offset:X8}.");
                }
                _instructions[offset] = instruction;
            }
        }
Example #6
0
        /// <summary>
        /// Creates a new wrapper around a raw stream containing x86 code.
        /// </summary>
        /// <param name="architecture">The x86 architecture.</param>
        /// <param name="inputStream">The raw code stream.</param>
        /// <param name="bitness">The bitness of the x86 code. This value must be either 16, 32 or 64.</param>
        /// <param name="baseAddress">The base address of the code stream.</param>
        /// <param name="decoderOptions">Additional decoder options that need to be passed onto the Iced decoder.</param>
        public X86DecoderInstructionProvider(
            IInstructionSetArchitecture <Instruction> architecture,
            Stream inputStream,
            int bitness,
            ulong baseAddress,
            DecoderOptions decoderOptions)
        {
            _inputStream = inputStream ?? throw new ArgumentNullException(nameof(inputStream));
            if (!inputStream.CanRead)
            {
                throw new ArgumentException("Input stream must be readable.");
            }
            if (!inputStream.CanSeek)
            {
                throw new ArgumentException("Input stream must be seekable.");
            }

            _decoder     = Decoder.Create(bitness, new StreamCodeReader(inputStream), decoderOptions);
            Architecture = architecture;
            BaseAddress  = baseAddress;
        }
Example #7
0
 /// <summary>
 /// Create a new decorator around the <paramref name="isa"/>
 /// </summary>
 /// <param name="isa">The <see cref="IInstructionSetArchitecture{TInstruction}"/> to decorate</param>
 public AstArchitecture(IInstructionSetArchitecture <TInstruction> isa) =>
Example #8
0
 internal FlowControlDeterminer(IInstructionSetArchitecture <TInstruction> isa) =>
Example #9
0
 /// <summary>
 /// Creates a new instance of <see cref="X86StateTransitionResolver"/>.
 /// </summary>
 /// <param name="architecture">The x86 architecture instance.</param>
 public X86StateTransitionResolver(IInstructionSetArchitecture <Instruction> architecture)
     : base(architecture)
 {
 }
Example #10
0
 /// <summary>
 /// Creates a new data flow graph.
 /// </summary>
 public DataFlowGraph(IInstructionSetArchitecture <TContents> architecture)
 {
     Architecture = architecture ?? throw new ArgumentNullException(nameof(architecture));
     Nodes        = new DataFlowNodeCollection <TContents>(this);
 }
Example #11
0
 /// <summary>
 /// Creates a new empty graph.
 /// </summary>
 /// <param name="architecture">The architecture description of the instructions stored in the control flow graph.</param>
 public ControlFlowGraph(IInstructionSetArchitecture <TInstruction> architecture)
 {
     Architecture = architecture ?? throw new ArgumentNullException(nameof(architecture));
     Nodes        = new NodeCollection <TInstruction>(this);
     Regions      = new RegionCollection <TInstruction, ControlFlowRegion <TInstruction> >(this);
 }
 /// <summary>
 /// Creates a new instance of the <see cref="InstructionTraversalResult{TInstruction}"/> class.
 /// </summary>
 /// <param name="architecture">The architecture.</param>
 public InstructionTraversalResult(IInstructionSetArchitecture <TInstruction> architecture)
 {
     Architecture = architecture ?? throw new ArgumentNullException(nameof(architecture));
 }
 /// <summary>
 /// Initializes the base implementation of the state state transition resolver.
 /// </summary>
 /// <param name="architecture">The architecture that describes the instruction set.</param>
 public StateTransitionResolverBase(IInstructionSetArchitecture <TInstruction> architecture)
 {
     Architecture  = architecture ?? throw new ArgumentNullException(nameof(architecture));
     DataFlowGraph = new DataFlowGraph <TInstruction>(architecture);
 }
Example #14
0
 /// <summary>
 /// Creates a new instance of the <see cref="StaticToSymbolicAdapter{TInstruction}"/> adapter.
 /// </summary>
 /// <param name="architecture">The architecture of the instructions.</param>
 /// <param name="instructions">The instructions.</param>
 public StaticToSymbolicAdapter(IInstructionSetArchitecture <TInstruction> architecture, IEnumerable <TInstruction> instructions)
     : this(new ListInstructionProvider <TInstruction>(architecture, instructions))
 {
 }