1 : // Copyright 2012 Google Inc.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Utility functions for use with disassembler callbacks.
16 :
17 : #ifndef SYZYGY_CORE_DISASSEMBLER_UTIL_H_
18 : #define SYZYGY_CORE_DISASSEMBLER_UTIL_H_
19 :
20 : #include "base/basictypes.h"
21 : #include "distorm.h" // NOLINT
22 :
23 m : namespace core {
24 :
25 : // Decodes exactly one instruction from the given buffer.
26 : // @param address the address of the instruction, as an absolute address
27 : // consistent with the image's base address. If this is not provided a
28 : // fake address of 0x10000000 will be used.
29 : // @param buffer the buffer containing the data to decode.
30 : // @param length the length of the buffer.
31 : // @returns true if an instruction was decoded, false otherwise.
32 m : bool DecodeOneInstruction(
33 m : uint32 address, const uint8* buffer, size_t length, _DInst* instruction);
34 m : bool DecodeOneInstruction(
35 m : const uint8* buffer, size_t length, _DInst* instruction);
36 :
37 : // Determines if the given instruction is a recognized no-op. We only recognize
38 : // those instructions that we see generated by the MSVS toolchain.
39 : // @param instruction the instruction to evaluate.
40 : // @returns true if @p instruction is a recognized no-op, false otherwise.
41 m : bool IsNop(const _DInst& instruction);
42 :
43 : // Determines if the given instruction is a call.
44 : // @param instruction the instruction to evaluate.
45 : // @returns true if @p instruction is a call, false otherwise.
46 m : bool IsCall(const _DInst& instruction);
47 :
48 : // Determines if the given instruction is a control-flow instruction.
49 : // @param instruction the instruction to evaluate.
50 : // @returns true if @p instruction is a control-flow instruction, false
51 : // otherwise.
52 m : bool IsControlFlow(const _DInst& instruction);
53 :
54 : // Determines if the given instruction is an implicit control-flow instruction.
55 : // @param instruction the instruction to evaluate.
56 : // @returns true if @p instruction is an implicit control-flow instruction
57 : // (we can't explicitly compute the target due to the addressing mode)
58 : // false otherwise.
59 m : bool IsImplicitControlFlow(const _DInst& instruction);
60 :
61 : // Determines if the given instruction is an interrupt instruction.
62 : // @param instruction the instruction to evaluate.
63 : // @returns true if @p instruction is an interrupt instruction, false otherwise.
64 m : bool IsInterrupt(const _DInst& instruction);
65 :
66 : // Determines if the given instruction is the debug interrupt instruction.
67 : // @param instruction the instruction to evaluate.
68 : // @returns true if @p instruction is the debug interrupt instruction, false
69 : // otherwise.
70 m : bool IsDebugInterrupt(const _DInst& instruction);
71 :
72 m : } // namespace core
73 :
74 : #endif // SYZYGY_CORE_DISASSEMBLER_UTIL_H_
|