summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3e7900d)
Currently has no way to find the Entrypoint. Doesn't seem to be too easy
-- we probably need to get it out of the cpu_thread_state struct from
the thread_command in the MachO header.
+
+ class MACHOT {
+
+ };
if (COFFObjectFile * object = dyn_cast<COFFObjectFile>(op)) {
return new LLVMDisassembler<COFFT>(filename, manager, object);
}
if (COFFObjectFile * object = dyn_cast<COFFObjectFile>(op)) {
return new LLVMDisassembler<COFFT>(filename, manager, object);
}
+ if (MachOObjectFile * object = dyn_cast<MachOObjectFile>(op)) {
+ return new LLVMDisassembler<MACHOT>(filename, manager, object);
+ }
template <typename ELFT>
Function* LLVMDisassembler<ELFT>::disassembleFunctionAt(uint64_t address, const std::string& name) {
Function * function;
template <typename ELFT>
Function* LLVMDisassembler<ELFT>::disassembleFunctionAt(uint64_t address, const std::string& name) {
Function * function;
- SectionRef text_section = sections[".text"];
+ SectionRef text_section = getTextSection();
uint64_t base_address, size;
text_section.getAddress(base_address);
text_section.getSize(size);
uint64_t base_address, size;
text_section.getAddress(base_address);
text_section.getSize(size);
* the other ones at the end of the function!
*/
std::map<uint64_t, BasicBlock*> new_blocks;
* the other ones at the end of the function!
*/
std::map<uint64_t, BasicBlock*> new_blocks;
- SectionRef text_section = sections[".text"];
+ SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
template <typename ELFT>
void LLVMDisassembler<ELFT>::disassemble() {
template <typename ELFT>
void LLVMDisassembler<ELFT>::disassemble() {
- SectionRef text_section = sections[".text"];
+ SectionRef text_section = getTextSection();
std::vector<Function*> remaining_functions;
// Assume all function symbols actually start a real function
std::vector<Function*> remaining_functions;
// Assume all function symbols actually start a real function
if (!x->second.getAddress(result)) {
Function * fun = manager->newFunction(result);
if (!x->second.getAddress(result)) {
Function * fun = manager->newFunction(result);
- fun->setName(x->first);
- remaining_functions.push_back(fun);
- LOG4CXX_DEBUG(logger, "Disasembling " << x->first);
+ if (fun) {
+ fun->setName(x->first);
+ remaining_functions.push_back(fun);
+ LOG4CXX_DEBUG(logger, "Disasembling " << x->first);
+ } else {
+ LOG4CXX_DEBUG(logger, "Function at " << std::hex << result
+ << " already disassembled as " << manager->getFunction(result)->getName());
+ }
+template<>
+uint64_t LLVMDisassembler<MACHOT>::entryAddress() {
+ // TODO
+ return 0;
+}
+
template <typename ELFT>
uint64_t LLVMDisassembler<ELFT>::entryAddress() {
const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
template <typename ELFT>
uint64_t LLVMDisassembler<ELFT>::entryAddress() {
const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
template <typename ELFT>
void LLVMDisassembler<ELFT>::splitBlocks(Function* function) {
template <typename ELFT>
void LLVMDisassembler<ELFT>::splitBlocks(Function* function) {
- SectionRef text_section = sections[".text"];
+ SectionRef text_section = getTextSection();
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
StringRef bytes;
text_section.getContents(bytes);
StringRefMemoryObject ref(bytes);
+template<>
+void LLVMDisassembler<MACHOT>::readDynamicSymbols() {
+ //TODO
+}
+
template <typename ELFT>
void LLVMDisassembler<ELFT>::readDynamicSymbols() {
const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
template <typename ELFT>
void LLVMDisassembler<ELFT>::readDynamicSymbols() {
const auto elffile = dyn_cast<ELFObjectFile<ELFT>>(o)->getELFFile();
std::function<void (uint8_t*, size_t,
const std::string&,
const std::string&)> fun) {
std::function<void (uint8_t*, size_t,
const std::string&,
const std::string&)> fun) {
- SectionRef text_section = sections[".text"];
+ SectionRef text_section = getTextSection();
uint64_t base_address;
text_section.getAddress(base_address);
uint64_t current_address = start - base_address;
uint64_t base_address;
text_section.getAddress(base_address);
uint64_t current_address = start - base_address;
current_address += inst_size;
}
}
current_address += inst_size;
}
}
+
+template <typename ELFT>
+SectionRef LLVMDisassembler<ELFT>::getTextSection() {
+ return sections[".text"];
+}
+
+template <>
+SectionRef LLVMDisassembler<MACHOT>::getTextSection() {
+ return sections["__text"];
+}
void disassembleFunction(Function* function);
void splitBlocks(Function* fun);
void disassemble();
void disassembleFunction(Function* function);
void splitBlocks(Function* fun);
void disassemble();
+ llvm::object::SectionRef getTextSection();
void readSymbols();
void readSections();
void readSymbols();
void readSections();
#include <llvm/MC/MCAsmInfo.h>
#include <llvm/Object/ELFObjectFile.h>
#include <llvm/Object/COFF.h>
#include <llvm/MC/MCAsmInfo.h>
#include <llvm/Object/ELFObjectFile.h>
#include <llvm/Object/COFF.h>
+#include <llvm/Object/MachO.h>
#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>