I do not remember when I made this change
This commit is contained in:
parent
928bbd3dfa
commit
cd4e4c156c
22
grapher.cpp
22
grapher.cpp
@ -4,7 +4,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <unordered_map>
|
#include <tr1/unordered_map>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include <mach-o/nlist.h>
|
#include <mach-o/nlist.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace std::tr1;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FULL_HASH,
|
FULL_HASH,
|
||||||
@ -89,13 +90,13 @@ struct Function {
|
|||||||
jumpTarget = ((p[0] & 0x200) >> 4) | ((p[0] & 0xf8) >> 3);
|
jumpTarget = ((p[0] & 0x200) >> 4) | ((p[0] & 0xf8) >> 3);
|
||||||
} else if((p[0] & 0xf800) == 0x4800) { // LDR literal
|
} else if((p[0] & 0xf800) == 0x4800) { // LDR literal
|
||||||
auto target = (uint32_t *) (p + ((addr & 2) ? 1 : 2) + 2*(p[0] & 0xff));
|
auto target = (uint32_t *) (p + ((addr & 2) ? 1 : 2) + 2*(p[0] & 0xff));
|
||||||
if(target < (uint32_t *) endOfWorld) {
|
if(target < (uint32_t *) endOfWorld && *target) {
|
||||||
refs.push_back(make_pair(make_pair(addr, *target), false));
|
refs.push_back(make_pair(make_pair(addr, *target), false));
|
||||||
}
|
}
|
||||||
p[0] = 0x45;
|
p[0] = 0x45;
|
||||||
} else if((p[0] & 0xff7f) == 0xf85f) { // LDR literal 2
|
} else if((p[0] & 0xff7f) == 0xf85f) { // LDR literal 2
|
||||||
auto target = (uint32_t *) ((uint8_t *) p + ((addr & 2) ? 2 : 4) + (p[1] & 0xfff));
|
auto target = (uint32_t *) ((uint8_t *) p + ((addr & 2) ? 2 : 4) + (p[1] & 0xfff));
|
||||||
if(target < (uint32_t *) endOfWorld) {
|
if(target < (uint32_t *) endOfWorld && *target) {
|
||||||
refs.push_back(make_pair(make_pair(addr, *target), false));
|
refs.push_back(make_pair(make_pair(addr, *target), false));
|
||||||
}
|
}
|
||||||
p[0] = p[1] = 0x46;
|
p[0] = p[1] = 0x46;
|
||||||
@ -112,6 +113,7 @@ struct Function {
|
|||||||
} else { // BLX
|
} else { // BLX
|
||||||
target &= ~2;
|
target &= ~2;
|
||||||
}
|
}
|
||||||
|
if(target)
|
||||||
refs.push_back(make_pair(make_pair(addr, target), true));
|
refs.push_back(make_pair(make_pair(addr, target), true));
|
||||||
|
|
||||||
p[0] = p[1] = 0x46;
|
p[0] = p[1] = 0x46;
|
||||||
@ -206,6 +208,10 @@ struct Edge {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this was a lambda, then I tried to compile with clang
|
||||||
|
static bool compareStartAddr(Function *const& a, Function *const& b) {
|
||||||
|
return a->startAddr < b->startAddr;
|
||||||
|
}
|
||||||
|
|
||||||
struct Binary {
|
struct Binary {
|
||||||
struct binary binary;
|
struct binary binary;
|
||||||
@ -254,7 +260,7 @@ struct Binary {
|
|||||||
Function *addFunc(uint16_t *start, uint16_t *end, addr_t addr, int type) {
|
Function *addFunc(uint16_t *start, uint16_t *end, addr_t addr, int type) {
|
||||||
Function *&func = funcs[addr];
|
Function *&func = funcs[addr];
|
||||||
if(!func) {
|
if(!func) {
|
||||||
func = new Function(start, end, (uint16_t *) (binary.valid_range.start + binary.valid_range.size), addr, reverseSymbols[addr], type);
|
func = new Function(start, end, (uint16_t *) ((char *) binary.valid_range.start + binary.valid_range.size), addr, reverseSymbols[addr], type);
|
||||||
funcsList.push_back(func);
|
funcsList.push_back(func);
|
||||||
}
|
}
|
||||||
return func;
|
return func;
|
||||||
@ -290,7 +296,9 @@ struct Binary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto func : funcsList) {
|
// can't use for( : ) because it will be mutated
|
||||||
|
for(auto i = 0u; i < funcsList.size(); i++) {
|
||||||
|
auto func = funcsList[i];
|
||||||
for(auto p : func->refs) {
|
for(auto p : func->refs) {
|
||||||
auto b = p.first.second;
|
auto b = p.first.second;
|
||||||
auto executable = p.second;
|
auto executable = p.second;
|
||||||
@ -304,7 +312,7 @@ struct Binary {
|
|||||||
// quick guess
|
// quick guess
|
||||||
pr.size = 0;
|
pr.size = 0;
|
||||||
}
|
}
|
||||||
func2 = addFunc((uint16_t *) pr.start, (uint16_t *) (pr.start + pr.size), b, INCOMPLETE_FUNC);
|
func2 = addFunc((uint16_t *) pr.start, (uint16_t *) ((char *) pr.start + pr.size), b, INCOMPLETE_FUNC);
|
||||||
}
|
}
|
||||||
new Edge(func, func2);
|
new Edge(func, func2);
|
||||||
}
|
}
|
||||||
@ -327,7 +335,7 @@ struct Binary {
|
|||||||
#undef X
|
#undef X
|
||||||
}
|
}
|
||||||
|
|
||||||
sort(funcsList.begin(), funcsList.end(), [](Function *const& a, Function *const& b) { return a->startAddr < b->startAddr; });
|
sort(funcsList.begin(), funcsList.end(), compareStartAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doHashes() {
|
void doHashes() {
|
||||||
|
Loading…
Reference in New Issue
Block a user