Skip to content

Commit

Permalink
fix: objc & memory dependence loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulghost committed Jun 28, 2021
1 parent db7f614 commit e191c79
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions iblessing/iblessing-core/v2/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "memory.hpp"
#include <iblessing-core/v2/util/StringUtils.h>
#include <iblessing-core/v2/objc/objc.hpp>
#include <iblessing-core/v2/vendor/keystone/keystone.h>
#include <iblessing-core/v2/vendor/capstone/capstone.h>

Expand Down Expand Up @@ -114,6 +115,10 @@ ib_return_t Memory::loadSync() {
}
}
macho->context->symtab->sync();

shared_ptr<Objc> objc = Objc::create(macho, this);
this->objc = objc;
macho->context->objcRuntime = objc->getRuntime();
vm2->relocAllRegions(macho->context->symtab, macho->context->objcRuntime);
return IB_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions iblessing/iblessing-core/v2/memory/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace iblessing {

class Objc;

class Memory {
public:
Memory(std::shared_ptr<MachO> macho) : macho(macho) {}
Expand All @@ -25,6 +27,7 @@ class Memory {

std::shared_ptr<VirtualMemory> fileMemory;
std::shared_ptr<VirtualMemoryV2> virtualMemory;
std::shared_ptr<Objc> objc;

protected:
std::shared_ptr<MachO> macho;
Expand Down
4 changes: 2 additions & 2 deletions iblessing/iblessing-core/v2/objc/objc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using namespace std;
using namespace iblessing;

Objc::Objc(shared_ptr<MachO> macho, shared_ptr<Memory> memory) {
Objc::Objc(shared_ptr<MachO> macho, Memory *memory) {
shared_ptr<ObjcRuntime> rt = make_shared<ObjcRuntime>(macho->context->symtab, memory->virtualMemory);
this->runtime = rt;
this->macho = macho;
Expand All @@ -24,7 +24,7 @@ Objc::Objc(shared_ptr<MachO> macho, shared_ptr<Memory> memory) {
rt->catlist_size = fileMemory->objc_catlist_size;
}

shared_ptr<Objc> Objc::create(std::shared_ptr<MachO> macho, std::shared_ptr<Memory> memory) {
shared_ptr<Objc> Objc::create(std::shared_ptr<MachO> macho, Memory *memory) {
return make_shared<Objc>(macho, memory);
}

Expand Down
6 changes: 3 additions & 3 deletions iblessing/iblessing-core/v2/objc/objc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ typedef std::function<void (ObjcClassRuntimeInfo *classInfo, uint64_t current, u

class Objc {
public:
Objc(std::shared_ptr<MachO> macho, std::shared_ptr<Memory> memory);
Objc(std::shared_ptr<MachO> macho, Memory *memory);

static std::shared_ptr<Objc> create(std::shared_ptr<MachO> macho, std::shared_ptr<Memory> memory);
static std::shared_ptr<Objc> create(std::shared_ptr<MachO> macho, Memory *memory);
ib_return_t loadClassList();
ib_return_t loadCategoryList();

Expand All @@ -30,7 +30,7 @@ class Objc {
protected:
std::shared_ptr<ObjcRuntime> runtime;
std::shared_ptr<MachO> macho;
std::shared_ptr<Memory> memory;
Memory *memory;
};

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,7 @@ int ObjcMethodXrefScanner::start() {
printf(" [*] Status: Track C Symbols: %d, Anti Wrapper: %d, Find All Path Level: %d, Track Call Snapshots: %d\n", shouldTrackSymbols, shouldAntiWrapper, findAllPathLevel, trackingCallSnapshots);

printf(" [*] Step 1. realize all app classes\n");
shared_ptr<Objc> objc = Objc::create(macho, memory);
this->objc = objc;
this->objc = memory->objc;
objc->loadClassList();
vector<ObjcMethod *> methods;
set<uint64_t> impAddrs;
Expand Down

0 comments on commit e191c79

Please sign in to comment.