Skip to content

Commit

Permalink
Semantic Refactor & Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pinwhell committed Jan 27, 2024
1 parent 3df3228 commit b89c3a7
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 190 deletions.
17 changes: 2 additions & 15 deletions include/OH/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ConfigManager
JsonValueWrapper mConfigRoot;

bool mDumpDynamic;
bool mDumpEncrypt;

std::string mMainCategory;
std::string mOutputName;
Expand All @@ -21,23 +22,9 @@ class ConfigManager
std::string mObfuscationBookPath;

bool mDeclareGlobalDumpObj;
bool mObfuscationBookMutationEnabled;


void setConfigPath(const std::string& path);

std::string getDumpTargetPath();
std::string getMainCategoryName();
std::string getHppOutputPath();
std::string getDumpJsonLibName();
std::string getGlobalDumpObjectName();
std::string getObfuscationBookPath();
bool mObfustationBookDoMutate;

bool Init();
bool InitDynamicDumpInfo();
bool InitDumpInfo();

bool getObfuscationBookMutationEnabled();
bool getDumpDynamic();
bool getDeclareGlobalDumpObj();
};
1 change: 1 addition & 0 deletions include/OH/IFutureResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class IFutureResult : public IChild<SingleDumpTarget>

IJsonAccesor* getJsonAccesor();
bool getDumpDynamic();
bool getDumpEncrypt();

void setMetadata(const JsonValueWrapper& metadata);
JsonValueWrapper& getMetadata();
Expand Down
32 changes: 7 additions & 25 deletions include/OH/TargetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "IChild.h"
#include "IJsonAccesor.h"
#include "ObfuscationManager.h"
#include <OH/ConfigManager.h>

class OffsetHunter;

Expand All @@ -16,12 +17,6 @@ class TargetManager : public IChild<OffsetHunter>
private:
std::unordered_map<DumpTargetGroup*, std::unique_ptr<DumpTargetGroup>> mAllTargets; // For now just supporting DumpTargetGroup

std::string mDumpTargetsPath;
std::string mMainCategoryName;
std::string mObfuscationBookPath;
std::string mHppOutputPath;
std::string mGlobalDumpObjName;
std::string mDumpJsonLibName;
std::string mDynamicJsonObjName; // by default "obj"
std::string mDynamicOffsetSetterFuncName; // by default "Set"

Expand All @@ -33,49 +28,36 @@ class TargetManager : public IChild<OffsetHunter>
std::unique_ptr<IJsonAccesor> mJsonAccesor;
std::unique_ptr<ObfuscationManager> mObfucationManager;

bool mDumpDynamic;
bool mDeclareDumpObject;
bool mObfuscationBookMutationEnabled;
ConfigManager* mConfigMgr;

bool SaveJson();
bool SaveHpp();
bool SaveHppCompileTime();
bool SaveHppRuntime();

public:

TargetManager();

bool Init();
bool InitAllTargets();
void ComputeAll();
bool SaveResults();

void setConfigManager(ConfigManager* configMgr);
ConfigManager* getConfigManager();

void RemoveTarget(DumpTargetGroup* target);
void AddTarget(std::unique_ptr<DumpTargetGroup>& target);

void setDumpTargetPath(const std::string& path);
void setMainCategoryName(const std::string& mainCategoryName);
void setHppOutputPath(const std::string& outputPath);

bool ReadAllTargets();

bool HandleTargetGroupJson(const JsonValueWrapper& targetGroupRoot);

HeaderFileManager* getHppWriter();

void setObfuscationBookMutationEnabled(bool b);

void setDumpDynamic(bool b);
void setDeclareGlobalDumpObj(bool b);
void setGlobalDumpObjectName(const std::string& globalObjName);

void setJsonAccesor(std::unique_ptr<IJsonAccesor>&& accesor);
IJsonAccesor* getJsonAccesor();

void setDumpJsonLibName(const std::string& dumpJsonLibName);
bool getDumpDynamic();

void setDynamicOffsetSetterFuncName(const std::string& dynamicOffsetSetterFuncName);
void setObfuscationBookPath(const std::string& obfuscationBookPath);

void WriteHppIncludes();
void WriteHppStaticDeclsDefs();
Expand Down
Binary file modified samples/DummyLib/DummyOffsetMgr.hpp
Binary file not shown.
4 changes: 2 additions & 2 deletions samples/DummyLib/dummyConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

"enable_extern" : true,
"extern_name" : "g_Offs",

"dump_encrypt" : false,
"dump_dynamic" : true,
"dump_json_lib_name" : "jsoncpp",

"declare_dump_global_obj": true,

"obf_book_mut_enabled" : false,
"obf_book_do_mutate" : false,
"obf_book_path" : "dummyObfBook.json",
}
2 changes: 1 addition & 1 deletion samples/DummyLib/offsets_ARM64.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"1353524362":2105391934,"2417577301":4261248983,"3612997897":3609688003}
{"3482068232":8,"4119764849":8,"462494170":8}
55 changes: 3 additions & 52 deletions src/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,6 @@

namespace fs = std::filesystem;

void ConfigManager::setConfigPath(const std::string& path)
{
mConfigPath = path;
}

std::string ConfigManager::getDumpTargetPath()
{
return mDumpTargetPath;
}

std::string ConfigManager::getMainCategoryName()
{
return mMainCategory;
}

std::string ConfigManager::getHppOutputPath()
{
return mHppOutputPath;
}

std::string ConfigManager::getDumpJsonLibName()
{
return mDumpJsonLibName;
}

std::string ConfigManager::getGlobalDumpObjectName()
{
return mGlobalDumpObjName;
}

std::string ConfigManager::getObfuscationBookPath()
{
return mObfuscationBookPath;
}

bool ConfigManager::Init()
{
if (FileHelper::IsValidFilePath(mConfigPath, true, true) == false)
Expand Down Expand Up @@ -77,7 +42,7 @@ bool ConfigManager::InitDynamicDumpInfo()

mDumpJsonLibName = mConfigRoot.get<std::string>("dump_json_lib_name", "jsoncpp");

mObfuscationBookMutationEnabled = mConfigRoot.get<bool>("obf_book_mut_enabled", false);
mObfustationBookDoMutate = mConfigRoot.get<bool>("obf_book_do_mutate", false);

mObfuscationBookPath = mConfigRoot.get<std::string>("obf_book_path", mMainCategory + "_obf_book.json");
}
Expand All @@ -97,21 +62,7 @@ bool ConfigManager::InitDumpInfo()
mHppOutputPath = mConfigRoot.get<std::string>("hpp_output_path", mOutputName + ".hpp");
mDeclareGlobalDumpObj = mConfigRoot.get<bool>("declare_dump_global_obj", false);
mGlobalDumpObjName = mConfigRoot.get<std::string>("global_dump_obj_name", "g" + mMainCategory + "Offs");
mDumpEncrypt = mConfigRoot.get<bool>("dump_encrypt", false);

return true;
}

bool ConfigManager::getObfuscationBookMutationEnabled()
{
return mObfuscationBookMutationEnabled;
}

bool ConfigManager::getDumpDynamic()
{
return mDumpDynamic;
}

bool ConfigManager::getDeclareGlobalDumpObj()
{
return mDeclareGlobalDumpObj;
}
}
6 changes: 3 additions & 3 deletions src/FutureOffsetResultInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ void FutureOffsetResultInfo::HandleCommentPreprocess()
if (getNeedShowComment() == false)
return;

setComment(StringHelper::ReplacePlaceHolders(getComment(), [&](const std::string name) {
return "|_|" + name + "|_|";
}));
//setComment(StringHelper::ReplacePlaceHolders(getComment(), [&](const std::string name) {
// return "|_|" + name + "|_|";
// }));
}


Expand Down
7 changes: 6 additions & 1 deletion src/IFutureResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ IJsonAccesor* IFutureResult::getJsonAccesor()

bool IFutureResult::getDumpDynamic()
{
return mTargetMgr->getDumpDynamic();
return mTargetMgr->getConfigManager()->mDumpDynamic;
}

bool IFutureResult::getDumpEncrypt()
{
return mTargetMgr->getConfigManager()->mDumpEncrypt;
}

void IFutureResult::setMetadata(const JsonValueWrapper& metadata)
Expand Down
6 changes: 3 additions & 3 deletions src/IFutureResultInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ bool IFutureResultInfo::Init()
mObfKey = getObfuscationManager()->getObfKey(mUIdentifierDynamic);
mSaltKey = getObfuscationManager()->getSaltKey(mUIdentifierDynamic);

if (mSaltKey != 0)
if (mParent->getDumpEncrypt() && mSaltKey != 0)
mUIdentifierDynamic += "_" + std::to_string(mSaltKey);

mUIDHash = std::to_string((uint32_t)fnv1a_32(mUIdentifierDynamic.c_str(), mUIdentifierDynamic.size()));

mDynamicResult->setValue(mParent->getJsonAccesor()->genGetUInt(mUIDHash, mObfKey));
} else mUIDHash = std::to_string((uint32_t)fnv1a_32(mUIdentifier.c_str(), mUIdentifier.size()));
mDynamicResult->setValue(mParent->getJsonAccesor()->genGetUInt(mUIDHash, mParent->getDumpEncrypt() ? mObfKey : 0x0));
}/* else mUIDHash = std::to_string((uint32_t)fnv1a_32(mUIdentifier.c_str(), mUIdentifier.size()));*/

mCanPickAnyResult = getMetadata().get<bool>("pick_any_result", false);

Expand Down
12 changes: 2 additions & 10 deletions src/OffsetHunter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ bool OffsetHunter::Init()
if (mConfigManager->Init() == false)
return false;

mTargetManager->setDumpTargetPath(mConfigManager->getDumpTargetPath());
mTargetManager->setMainCategoryName(mConfigManager->getMainCategoryName());
mTargetManager->setHppOutputPath(mConfigManager->getHppOutputPath());
mTargetManager->setDumpDynamic(mConfigManager->getDumpDynamic());
mTargetManager->setDumpJsonLibName(mConfigManager->getDumpJsonLibName());
mTargetManager->setDeclareGlobalDumpObj(mConfigManager->getDeclareGlobalDumpObj());
mTargetManager->setGlobalDumpObjectName(mConfigManager->getGlobalDumpObjectName());
mTargetManager->setObfuscationBookPath(mConfigManager->getObfuscationBookPath());
mTargetManager->setObfuscationBookMutationEnabled(mConfigManager->getObfuscationBookMutationEnabled());
mTargetManager->setConfigManager(mConfigManager.get());

if (mTargetManager->Init() == false)
return false;
Expand Down Expand Up @@ -57,7 +49,7 @@ void OffsetHunter::setConfigPath(const std::string& path)

std::filesystem::current_path(parentPath);

mConfigManager->setConfigPath(absCfgPath.string());
mConfigManager->mConfigPath = absCfgPath.string();
}

CapstoneHelperProvider* OffsetHunter::getCapstoneHelperProvider()
Expand Down
3 changes: 2 additions & 1 deletion src/StringHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ std::string StringHelper::ReplacePlaceHolders(const std::string& input, std::fun
acum += *c;
}

result += acum;
if(acum.empty() == false)
result += acum;

return result;
}
Loading

0 comments on commit b89c3a7

Please sign in to comment.