Skip to content

Commit

Permalink
Enable gap parsing based on the binary's architecture to analyze inst…
Browse files Browse the repository at this point in the history
…ead of

the architecture where Dyninst runs
  • Loading branch information
mxz297 committed Nov 19, 2020
1 parent 246a4ce commit b834d9d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 80 deletions.
2 changes: 0 additions & 2 deletions cmake/cap_arch_def.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set (ARCH_DEFINES -Darch_x86)
set (CAP_DEFINES ${CAP_DEFINES}
-Dcap_fixpoint_gen
-Dcap_noaddr_gen
-Dcap_stripped_binaries
-Dcap_tramp_liveness
-Dcap_virtual_registers
-Dcap_stack_mods
Expand All @@ -25,7 +24,6 @@ set (CAP_DEFINES ${CAP_DEFINES}
-Dcap_fixpoint_gen
-Dcap_noaddr_gen
-Dcap_registers
-Dcap_stripped_binaries
-Dcap_tramp_liveness
-Dcap_stack_mods
)
Expand Down
48 changes: 0 additions & 48 deletions common/src/arch-x86.C
Original file line number Diff line number Diff line change
Expand Up @@ -12011,54 +12011,6 @@ entryID ia32_entry::getID(ia32_locations* l) const
return id;
}

bool isStackFramePrecheck_gcc( const unsigned char *buffer )
{
//Currently enabled entry bytes for gaps:
// 0x55 - push %ebp
static char gap_initial_bytes[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
return (gap_initial_bytes[*buffer] != 0);
}

bool isStackFramePrecheck_msvs( const unsigned char *buffer )
{
//Currently enabled entry bytes for gaps:
// 0x55 - push %ebp
static char gap_initial_bytes[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
return (gap_initial_bytes[*buffer] != 0);
}

/*
bool isStackFramePreamble( instruction& insn1 )
{
Expand Down
3 changes: 0 additions & 3 deletions common/src/arch-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,6 @@ COMMON_EXPORT bool insn_hasSIB(unsigned,unsigned&,unsigned&,unsigned&);
COMMON_EXPORT bool insn_hasDisp8(unsigned ModRM);
COMMON_EXPORT bool insn_hasDisp32(unsigned ModRM);

COMMON_EXPORT bool isStackFramePrecheck_msvs( const unsigned char *buffer );
COMMON_EXPORT bool isStackFramePrecheck_gcc( const unsigned char *buffer );

}; // namespace arch_x86

#endif
Expand Down
2 changes: 0 additions & 2 deletions dyninstAPI/src/image.C
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,6 @@ void image::analyzeImage() {
obj_->parse();


#if defined(cap_stripped_binaries)
{
vector<CodeRegion *>::const_iterator rit = cs_->regions().begin();
for( ; rit != cs_->regions().end(); ++rit)
Expand All @@ -1392,7 +1391,6 @@ void image::analyzeImage() {
}
}
}
#endif // cap_stripped_binaries


parseState_ = analyzed;
Expand Down
6 changes: 0 additions & 6 deletions parseAPI/src/IdiomModelDesc.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#if defined(cap_stripped_binaries)


#include "ProbabilisticParser.h"
#include "util.h"

Expand All @@ -14,7 +11,6 @@ using namespace hd;
using namespace Dyninst;

IdiomModel::IdiomModel(string model_spec) {
#if defined(arch_x86) || defined(arch_x86_64) || defined(i386_unknown_nt4_0)
#if defined(os_windows)
if (!strcmp(model_spec.c_str(), "32-bit")) {
bias = -10.374549;
Expand Down Expand Up @@ -1204,7 +1200,5 @@ IdiomModel::IdiomModel(string model_spec) {

}
#endif
#endif
}

#endif
68 changes: 56 additions & 12 deletions parseAPI/src/Parser-speculative.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,59 @@ using namespace std;
using namespace Dyninst;
using namespace Dyninst::ParseAPI;

#if defined(cap_stripped_binaries)

#include "ProbabilisticParser.h"

namespace hd {

bool isStackFramePrecheck_gcc( const unsigned char *buffer )
{
//Currently enabled entry bytes for gaps:
// 0x55 - push %ebp
static char gap_initial_bytes[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
return (gap_initial_bytes[*buffer] != 0);
}

bool isStackFramePrecheck_msvs( const unsigned char *buffer )
{
//Currently enabled entry bytes for gaps:
// 0x55 - push %ebp
static char gap_initial_bytes[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
return (gap_initial_bytes[*buffer] != 0);
}


Address calc_end(Function * f) {
Address ret = f->addr() + 1;
if(!f->extents().empty()) {
Expand Down Expand Up @@ -220,14 +268,12 @@ namespace hd {
bool gap_heuristics(CodeObject *co,CodeRegion *cr,Address addr)
{
bool ret = false;
#if defined(arch_x86) || defined(arch_x86_64) || defined(i386_unknown_nt4_0)

#if defined(os_windows)
ret = gap_heuristic_MSVS(co,cr,addr);
#else
ret = gap_heuristic_GCC(co,cr,addr);
#endif
#endif
return ret;
}

Expand Down Expand Up @@ -287,6 +333,9 @@ namespace hd {
*/
void Parser::parse_gap_heuristic(CodeRegion * cr)
{
Architecture arch = cr->getArch();
if (arch != Arch_x86 && arch != Arch_x86_64) return;

// ensure that we've parsed and finalized
// all vanilla parsing
if(_parse_state < COMPLETE)
Expand Down Expand Up @@ -357,6 +406,9 @@ bool Parser::getGapRange(CodeRegion* cr, Address curAddr, Address& gapStart, Add
}

void Parser::probabilistic_gap_parsing(CodeRegion *cr) {
Architecture arch = cr->getArch();
if (arch != Arch_x86 && arch != Arch_x86_64) return;

// 0. ensure that we've parsed and finalized all vanilla parsing.
// We also locate all the gaps

Expand Down Expand Up @@ -393,11 +445,3 @@ void Parser::probabilistic_gap_parsing(CodeRegion *cr) {
}
}

#else // cap_stripped binaries
void Parser::parse_gap_heuristic(CodeRegion*)
{

}
void Parser::probabilistic_gap_parsing(CodeRegion *cr) {
}
#endif
3 changes: 0 additions & 3 deletions parseAPI/src/ProbabilisticParser.C
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if defined(cap_stripped_binaries)

#include "ProbabilisticParser.h"

#include <cstdio>
Expand Down Expand Up @@ -633,5 +631,4 @@ void ProbabilityCalculator::prioritizedGapParsing() {
}

}
#endif

3 changes: 0 additions & 3 deletions parseAPI/src/ProbabilisticParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#ifndef _PROBABILISTIC_PARSER_H_
#define _PROBABILISTIC_PARSER_H_

#if defined(cap_stripped_binaries)

#include "Parser.h"

#include <string>
Expand Down Expand Up @@ -217,4 +215,3 @@ class ProbabilityCalculator {

#endif

#endif
2 changes: 1 addition & 1 deletion patchAPI/test/findPoint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LIB_DIR = -L$(DYNINST_ROOT)/$(PLATFORM)/lib
LIB = -ldyninstAPI -lsymtabAPI -linstructionAPI -lcommon -lpcontrol -lparseAPI -lpatchAPI
CC = g++
cc = gcc
CXXFLAG = -Wall -g -Dos_linux -Darch_x86_64 -Darch_64bit -Dx86_64_unknown_linux2_4 -Dcap_ptrace -Dcap_stripped_binaries -Dcap_async_events -Dcap_threads -Dcap_dynamic_heap -Dcap_relocation -Dcap_dwarf -Dcap_32_64 -Dcap_liveness -Dcap_fixpoint_gen -Dcap_noaddr_gen -Dcap_mutatee_traps -Dcap_binary_rewriter -Dcap_registers -Dcap_instruction_api -Dcap_serialization -Dcap_instruction_replacement -Dcap_tramp_liveness -Dbug_syscall_changepc_rewind -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
CXXFLAG = -Wall -g -Dos_linux -Darch_x86_64 -Darch_64bit -Dx86_64_unknown_linux2_4 -Dcap_ptrace -Dcap_async_events -Dcap_threads -Dcap_dynamic_heap -Dcap_relocation -Dcap_dwarf -Dcap_32_64 -Dcap_liveness -Dcap_fixpoint_gen -Dcap_noaddr_gen -Dcap_mutatee_traps -Dcap_binary_rewriter -Dcap_registers -Dcap_instruction_api -Dcap_serialization -Dcap_instruction_replacement -Dcap_tramp_liveness -Dbug_syscall_changepc_rewind -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
CFLAG = -Wall -fPIC

PLATFORM = x86_64-unknown-linux2.4
Expand Down

0 comments on commit b834d9d

Please sign in to comment.