Allows llvm-3.6 in cmake and does compile with 3.6. However it
does *not* work! It will segfault right away. One of the suspects is
different base for addresses used in llvm's getInstruction() and family.
TARGET_LINK_LIBRARIES(frida
${QT_LIBRARIES}
${LLVM_LDFLAGS}
TARGET_LINK_LIBRARIES(frida
${QT_LIBRARIES}
${LLVM_LDFLAGS}
${LLVM_SYSTEM_LIBS}
${LOG4CXX_LDFLAGS}
${QUAZIP_LIBRARIES})
${LLVM_SYSTEM_LIBS}
${LOG4CXX_LDFLAGS}
${QUAZIP_LIBRARIES})
ADD_SUBDIRECTORY(/usr/src/gmock gmock)
enable_testing()
add_test(NAME fridatest COMMAND fridatest ${CMAKE_SOURCE_DIR}/testdata)
ADD_SUBDIRECTORY(/usr/src/gmock gmock)
enable_testing()
add_test(NAME fridatest COMMAND fridatest ${CMAKE_SOURCE_DIR}/testdata)
-target_link_libraries(fridatest gmock gtest ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES})
+target_link_libraries(fridatest
+ gmock
+ gtest
+ ${QT_LIBRARIES}
+ ${LLVM_LDFLAGS}
+ ${LLVM_DYNAMIC_LIB}
+ ${LLVM_SYSTEM_LIBS}
+ ${LOG4CXX_LDFLAGS}
+ ${GUILE_LDFLAGS}
+ ${QUAZIP_LIBRARIES})
target_compile_options(fridatest PRIVATE -DCONFIG_TEST)
set_property(TEST fridatest
APPEND PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(fridatest PRIVATE -DCONFIG_TEST)
set_property(TEST fridatest
APPEND PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR})
-find_program(LLVM_CONFIG NAMES llvm-config-3.5 llvm-config)
+find_program(LLVM_CONFIG NAMES llvm-config-3.5 llvm-config llvm-config-3.6)
if(LLVM_CONFIG)
execute_process(COMMAND ${LLVM_CONFIG} --version
OUTPUT_VARIABLE LLVM_VERSION)
if(LLVM_CONFIG)
execute_process(COMMAND ${LLVM_CONFIG} --version
OUTPUT_VARIABLE LLVM_VERSION)
- if(((${LLVM_VERSION} VERSION_LESS 3.6.0)
+ if(((${LLVM_VERSION} VERSION_LESS 3.7.0)
AND (${LLVM_VERSION} VERSION_GREATER 3.5))
OR (${LLVM_VERSION} VERSION_EQUAL 3.5))
AND (${LLVM_VERSION} VERSION_GREATER 3.5))
OR (${LLVM_VERSION} VERSION_EQUAL 3.5))
string(REPLACE -I "-isystem" LLVM_CFLAGS ${LLVM_CFLAGS})
separate_arguments(LLVM_CFLAGS)
string(REPLACE -I "-isystem" LLVM_CFLAGS ${LLVM_CFLAGS})
separate_arguments(LLVM_CFLAGS)
+
+ if(${LLVM_VERSION} VERSION_LESS 3.6)
+ set(LLVM_CFLAGS ${LLVM_CFLAGS} -DLLVM_35)
+ set(LLVM_DYNAMIC_LIB -lLLVM-3.5)
+ else()
+ set(LLVM_CFLAGS ${LLVM_CFLAGS} -DLLVM_36)
+ set(LLVM_DYNAMIC_LIB -lLLVM-3.6)
+ message(WARNING "LLVM 3.6 support is highly experimental and may be broken in interesting ways")
+ endif()
LOG4CXX_ERROR(logger, ec.message());
return NULL;
}
LOG4CXX_ERROR(logger, ec.message());
return NULL;
}
Binary * op = retval.get();
Binary * op = retval.get();
-
- if (!op) {
- LOG4CXX_ERROR(logger, "Could not open " << filename);
- return NULL;
- }
+#elif defined(LLVM_36)
+ OwningBinary<Binary> ob;
+ ob = std::move(retval.get());
+ Binary* op = ob.getBinary();
+ auto foo = ob.takeBinary();
+ foo.first.release();
+ foo.second.release();
+#endif
// ELFType<endian, maxalign, 64bit>
if (ELF32LEObjectFile * object = dyn_cast<ELF32LEObjectFile>(op)) {
// ELFType<endian, maxalign, 64bit>
if (ELF32LEObjectFile * object = dyn_cast<ELF32LEObjectFile>(op)) {
binary.reset(result.get());
binary.reset(result.get());
+#elif defined(LLVM_36)
+ OwningBinary<Binary> ob;
+ ob = std::move(result.get());
+ Binary* op = ob.getBinary();
+
+ binary.reset(op);
+#endif
o = dyn_cast<ObjectFile>(binary.get());
} else {
o = dyn_cast<ObjectFile>(binary.get());
} else {
IP->setPrintImmHex(llvm::HexStyle::C);
IP->setPrintImmHex(true);
IP->setPrintImmHex(llvm::HexStyle::C);
IP->setPrintImmHex(true);
- std::unique_ptr<MCObjectDisassembler> OD(
- new MCObjectDisassembler(*o, *DisAsm, *MIA));
+// std::unique_ptr<MCObjectDisassembler> OD(
+// new MCObjectDisassembler(*o, *DisAsm, *MIA));
//Mod.reset(OD->buildModule(false));
readSections();
//Mod.reset(OD->buildModule(false));
readSections();
Function * function;
SectionRef text_section = getTextSection();
uint64_t base_address, size;
Function * function;
SectionRef text_section = getTextSection();
uint64_t base_address, size;
text_section.getAddress(base_address);
text_section.getSize(size);
text_section.getAddress(base_address);
text_section.getSize(size);
+#elif defined(LLVM_36)
+ base_address = text_section.getAddress();
+ size = text_section.getSize();
+#endif
if (address < base_address ||
address >= base_address + size) {
return NULL;
if (address < base_address ||
address >= base_address + size) {
return NULL;
SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRefMemoryObject ref(bytes);
+#elif defined(LLVM_36)
+ ArrayRef<uint8_t> bytearray(reinterpret_cast<const uint8_t *>(bytes.data()),
+ bytes.size());
+#else
+#error LLVM != 3.5 | 3.6 not supported
+#endif
LOG4CXX_DEBUG(logger, "Handling function " << function->getName());
LOG4CXX_DEBUG(logger, "Handling function " << function->getName());
function->addBasicBlock(block);
uint64_t base_address, size;
function->addBasicBlock(block);
uint64_t base_address, size;
text_section.getAddress(base_address);
text_section.getSize(size);
text_section.getAddress(base_address);
text_section.getSize(size);
+#elif defined(LLVM_36)
+ base_address = text_section.getAddress();
+ size = text_section.getSize();
+#endif
LOG4CXX_DEBUG(logger, "Text section at " << std::hex << base_address << " with size " << size);
while (remaining_blocks.size()) {
LOG4CXX_DEBUG(logger, "Text section at " << std::hex << base_address << " with size " << size);
while (remaining_blocks.size()) {
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#elif defined(LLVM_36)
+ DisAsm->getInstruction(inst, inst_size,
+ bytearray.slice(current_address),
+ base_address + current_address,
+ nulls(), nulls())) {
+#endif
uint64_t jmptarget;
if (MIA->evaluateBranch(inst, current_address, inst_size, jmptarget)) {
uint64_t jmptarget;
if (MIA->evaluateBranch(inst, current_address, inst_size, jmptarget)) {
bool contains;
SymbolRef::Type symbol_type;
bool contains;
SymbolRef::Type symbol_type;
if (text_section.containsSymbol(x->second, contains) || !contains)
if (text_section.containsSymbol(x->second, contains) || !contains)
+#elif defined(LLVM_36)
+ if (text_section.containsSymbol(x->second))
+#endif
continue;
if (x->second.getType(symbol_type)
continue;
if (x->second.getType(symbol_type)
if (!manager->hasFunctions()) {
uint64_t text_entry;
if (!manager->hasFunctions()) {
uint64_t text_entry;
text_section.getAddress(text_entry);
text_section.getAddress(text_entry);
+#elif defined(LLVM_36)
+ text_entry = text_section.getAddress();
+#endif
LOG4CXX_INFO(logger, "No Symbols found, starting at the beginning of the text segment");
disassembleFunctionAt(text_entry);
}
LOG4CXX_INFO(logger, "No Symbols found, starting at the beginning of the text segment");
disassembleFunctionAt(text_entry);
}
SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRefMemoryObject ref(bytes);
+#elif defined(LLVM_36)
+ ArrayRef<uint8_t> bytearray(reinterpret_cast<const uint8_t *>(bytes.data()),
+ bytes.size());
+#endif
+
LOG4CXX_DEBUG(logger, "Splitting Blocks in Function " << function->getName());
// Split blocks where jumps are going inside the block
LOG4CXX_DEBUG(logger, "Splitting Blocks in Function " << function->getName());
// Split blocks where jumps are going inside the block
}
uint64_t inst_size;
uint64_t base_address;
}
uint64_t inst_size;
uint64_t base_address;
text_section.getAddress(base_address);
text_section.getAddress(base_address);
+#elif defined(LLVM_36)
+ base_address = text_section.getAddress();
+#endif
uint64_t current_address = current_block->getStartAddress() - base_address;
while(current_block->getEndAddress() - base_address > current_address) {
MCInst inst;
uint64_t current_address = current_block->getStartAddress() - base_address;
while(current_block->getEndAddress() - base_address > current_address) {
MCInst inst;
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#elif defined(LLVM_36)
+ DisAsm->getInstruction(inst, inst_size,
+ bytearray.slice(current_address),
+ base_address + current_address,
+ nulls(), nulls())) {
+#endif
+
// See if some other block starts here
BasicBlock* other = manager->getBasicBlock(current_address
+ inst_size
// See if some other block starts here
BasicBlock* other = manager->getBasicBlock(current_address
+ inst_size
std::vector<Instruction> result;
SectionRef text_section = getTextSection();
uint64_t base_address;
std::vector<Instruction> result;
SectionRef text_section = getTextSection();
uint64_t base_address;
text_section.getAddress(base_address);
text_section.getAddress(base_address);
+#elif defined(LLVM_36)
+ base_address = text_section.getAddress();
+#endif
+
uint64_t current_address = block->getStartAddress() - base_address;
uint64_t end_position = block->getEndAddress() - base_address;
StringRef bytes;
text_section.getContents(bytes);
uint64_t current_address = block->getStartAddress() - base_address;
uint64_t end_position = block->getEndAddress() - base_address;
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRefMemoryObject ref(bytes);
+#elif defined(LLVM_36)
+ ArrayRef<uint8_t> bytearray(reinterpret_cast<const uint8_t *>(bytes.data()),
+ bytes.size());
+#endif
+
while (current_address < end_position) {
uint64_t inst_size;
while (current_address < end_position) {
uint64_t inst_size;
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
- DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#if defined(LLVM_35)
+ DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#elif defined(LLVM_36)
+ DisAsm->getInstruction(inst, inst_size,
+ bytearray.slice(current_address),
+ base_address + current_address,
+ nulls(), nulls())) {
+#endif
uint8_t bytes[inst_size+2];
uint8_t bytes[inst_size+2];
ref.readBytes(current_address, inst_size, bytes);
ref.readBytes(current_address, inst_size, bytes);
+#elif defined(LLVM_36)
+ size_t bytesindex(0);
+ for (uint8_t byte : bytearray.slice(current_address, inst_size)) {
+ bytes[bytesindex++] = byte;
+ }
+#endif
uint64_t jmptarget;
std::string ref("");
uint64_t jmptarget;
std::string ref("");
} else {
LOG4CXX_WARN(logger, "Invalid byte at" << std::hex << current_address + base_address);
uint8_t bytes[1];
} else {
LOG4CXX_WARN(logger, "Invalid byte at" << std::hex << current_address + base_address);
uint8_t bytes[1];
ref.readBytes(current_address, 1, bytes);
ref.readBytes(current_address, 1, bytes);
+#elif defined(LLVM_36)
+ bytes[0] = bytearray[current_address];
+#endif
result.push_back(Instruction(current_address + base_address, "Invalid Instruction",
std::vector<uint8_t>(bytes, bytes+1), ""));
inst_size = 1;
result.push_back(Instruction(current_address + base_address, "Invalid Instruction",
std::vector<uint8_t>(bytes, bytes+1), ""));
inst_size = 1;
const std::string&)> fun) {
SectionRef text_section = getTextSection();
uint64_t base_address;
const std::string&)> fun) {
SectionRef text_section = getTextSection();
uint64_t base_address;
text_section.getAddress(base_address);
text_section.getAddress(base_address);
+#elif defined(LLVM_36)
+ base_address = text_section.getAddress();
+#endif
+
uint64_t current_address = start - base_address;
StringRef bytes;
text_section.getContents(bytes);
uint64_t current_address = start - base_address;
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRefMemoryObject ref(bytes);
+#elif defined(LLVM_36)
+ ArrayRef<uint8_t> bytearray(reinterpret_cast<const uint8_t *>(bytes.data()),
+ bytes.size());
+#endif
+
while (current_address < end - base_address) {
uint64_t inst_size;
while (current_address < end - base_address) {
uint64_t inst_size;
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
llvm::raw_string_ostream s(buf);
if(llvm::MCDisassembler::Success ==
- DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#if defined(LLVM_35)
+ DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+#elif defined(LLVM_36)
+ DisAsm->getInstruction(inst, inst_size,
+ bytearray.slice(current_address),
+ base_address + current_address,
+ nulls(), nulls())) {
+#endif
uint8_t bytes[inst_size+2];
uint8_t bytes[inst_size+2];
ref.readBytes(current_address, inst_size, bytes);
ref.readBytes(current_address, inst_size, bytes);
+#elif defined(LLVM_36)
+ size_t bytesindex(0);
+ for (uint8_t byte : bytearray.slice(current_address, inst_size)) {
+ bytes[bytesindex++] = byte;
+ }
+#endif
uint64_t jmptarget;
std::string ref("");
uint64_t jmptarget;
std::string ref("");
std::unique_ptr<const llvm::MCRegisterInfo> MRI;
std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
std::unique_ptr<const llvm::MCRegisterInfo> MRI;
std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
- std::unique_ptr<llvm::MCModule> Mod;
+// std::unique_ptr<llvm::MCModule> Mod;
std::unique_ptr<llvm::MCInstPrinter> IP;
std::unique_ptr<llvm::MCDisassembler> DisAsm;
std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
std::unique_ptr<llvm::MCInstPrinter> IP;
std::unique_ptr<llvm::MCDisassembler> DisAsm;
std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
#include <llvm/Object/ObjectFile.h>
#include <llvm/Object/Archive.h>
#include <llvm/MC/MCAsmInfo.h>
#include <llvm/Object/ObjectFile.h>
#include <llvm/Object/Archive.h>
#include <llvm/MC/MCAsmInfo.h>
-#include <llvm/MC/MCAnalysis/MCAtom.h>
#include <llvm/MC/MCContext.h>
#include <llvm/MC/MCDisassembler.h>
#include <llvm/MC/MCContext.h>
#include <llvm/MC/MCDisassembler.h>
-#include <llvm/MC/MCAnalysis/MCFunction.h>
#include <llvm/MC/MCInst.h>
#include <llvm/MC/MCInstPrinter.h>
#include <llvm/MC/MCInstrAnalysis.h>
#include <llvm/MC/MCInstrInfo.h>
#include <llvm/MC/MCInst.h>
#include <llvm/MC/MCInstPrinter.h>
#include <llvm/MC/MCInstrAnalysis.h>
#include <llvm/MC/MCInstrInfo.h>
-#include <llvm/MC/MCAnalysis/MCModule.h>
-#include <llvm/MC/MCObjectDisassembler.h>
#include <llvm/MC/MCObjectFileInfo.h>
#include <llvm/MC/MCObjectFileInfo.h>
-#include <llvm/MC/MCObjectSymbolizer.h>
#include <llvm/MC/MCRegisterInfo.h>
#include <llvm/MC/MCRelocationInfo.h>
#include <llvm/MC/MCSubtargetInfo.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/MC/MCRegisterInfo.h>
#include <llvm/MC/MCRelocationInfo.h>
#include <llvm/MC/MCSubtargetInfo.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
-#include <llvm/Support/StringRefMemoryObject.h>
#include <llvm/Support/GraphWriter.h>
#include <llvm/Support/GraphWriter.h>
+#ifndef LLVM_36
+#include <llvm/MC/MCAnalysis/MCAtom.h>
+#include <llvm/MC/MCAnalysis/MCFunction.h>
+#include <llvm/MC/MCObjectSymbolizer.h>
+#include <llvm/Support/StringRefMemoryObject.h>
+#include <llvm/MC/MCAnalysis/MCModule.h>
+#include <llvm/MC/MCObjectDisassembler.h>
+#endif
+