-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored obfuscator into a library
- Loading branch information
1 parent
7683ab6
commit f2e6bde
Showing
60 changed files
with
1,862 additions
and
1,242 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <zasm/zasm.hpp> | ||
#include "cfg.hpp" | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
using namespace zasm; | ||
|
||
class Analyzer | ||
{ | ||
public: | ||
Analyzer(Program& program); | ||
|
||
bool analyze(bool verbose = false); | ||
CFG& getCFG(); | ||
|
||
private: | ||
Program& program_; | ||
CFG cfg_; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <set> | ||
#include <vector> | ||
#include <zasm/zasm.hpp> | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
using namespace zasm; | ||
|
||
struct BasicBlock | ||
{ | ||
uint64_t address = 0; | ||
Label label; | ||
Node* begin = nullptr; | ||
Node* end = nullptr; | ||
|
||
uint32_t regsUse = 0; | ||
uint32_t regsDef = 0; | ||
uint32_t regsLiveIn = 0; | ||
uint32_t regsLiveOut = 0; | ||
|
||
uint32_t flagsUse = 0; | ||
uint32_t flagsDef = 0; | ||
uint32_t flagsLiveIn = 0; | ||
uint32_t flagsLiveOut = 0; | ||
}; | ||
|
||
class CFG | ||
{ | ||
public: | ||
CFG(); | ||
|
||
bool create(Program& program, Label entryLabel); | ||
void computeLiveness(); | ||
|
||
std::map<Label::Id, BasicBlock>& getBasicBlocks(); | ||
|
||
void printResults(Program& program); | ||
void printDot(Program& program); | ||
|
||
private: | ||
BasicBlock& getBlock(Label label, LabelData& data); | ||
BasicBlock& getBlock(Label::Id id); | ||
void addEdge(Label from, Label to); | ||
std::set<Label::Id> getSuccessors(Label::Id labelId); | ||
std::set<Label::Id> getPredecessors(Label::Id labelId); | ||
|
||
private: | ||
std::map<Label::Id, BasicBlock> blocks_; | ||
std::map<Label::Id, std::set<Label::Id>> predecessors_; | ||
std::map<Label::Id, std::set<Label::Id>> successors_; | ||
std::set<Label::Id> exits_; | ||
Label::Id entry_; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <deque> | ||
#include <vector> | ||
#include <zasm/zasm.hpp> | ||
#include "instruction_data.hpp" | ||
|
||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
using namespace zasm; | ||
|
||
class Context | ||
{ | ||
public: | ||
Context(Program& program); | ||
|
||
void addInstructionData(Node* node, uintptr_t address, const InstructionDetail& detail); | ||
|
||
private: | ||
Program& program_; | ||
std::deque<InstructionData> instructionDataPool_; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "context.hpp" | ||
#include <string> | ||
#include <vector> | ||
#include <zasm/zasm.hpp> | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
using namespace zasm; | ||
|
||
class Disassembler | ||
{ | ||
public: | ||
Disassembler(Program& program, Context& context); | ||
|
||
bool disassemble( | ||
const std::string& functionName, uintptr_t address, const std::vector<uint8_t>& code, bool verbose = false | ||
); | ||
|
||
private: | ||
Context& ctx_; | ||
Program& program_; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <zasm/zasm.hpp> | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
using namespace zasm; | ||
|
||
struct InstructionData | ||
{ | ||
uint64_t address = 0; | ||
uint32_t flagsModified = 0; | ||
uint32_t flagsTested = 0; | ||
uint32_t regsWritten = 0; | ||
uint32_t regsRead = 0; | ||
|
||
uint32_t regsLive = 0; | ||
uint32_t flagsLive = 0; | ||
|
||
zasm::InstructionDetail detail; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <cstdio> | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
class Logger | ||
{ | ||
public: | ||
Logger(); | ||
~Logger(); | ||
|
||
static void log(const char* format, ...); | ||
static void logLine(const char* format, ...); | ||
static void logError(const char* format, ...); | ||
static void logWarning(const char* format, ...); | ||
static void logInfo(const char* format, ...); | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace ObfuscatorLib | ||
{ | ||
|
||
class Obfuscator | ||
{ | ||
public: | ||
Obfuscator(); | ||
~Obfuscator(); | ||
|
||
bool loadPEFile(const std::string& filePath, const std::string& functionName, bool verbose = false); | ||
bool disassembleFunction(const std::string& functionName, bool verbose = false); | ||
bool analyzeFunction(bool verbose = false); | ||
bool obfuscateFunction(bool verbose = false); | ||
bool serialize(std::vector<uint8_t>& outputCode, bool verbose = false); | ||
|
||
private: | ||
class Impl; | ||
Impl* impl_; | ||
}; | ||
|
||
} // namespace ObfuscatorLib |
Oops, something went wrong.