-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor analysis and output a liveness JSON
- Loading branch information
Showing
9 changed files
with
346 additions
and
161 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 |
---|---|---|
@@ -1,8 +1,60 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <set> | ||
#include <vector> | ||
|
||
#include <obfuscator/context.hpp> | ||
|
||
namespace obfuscator | ||
{ | ||
bool analyze(Context& ctx, bool verbose = false); | ||
} | ||
struct BasicBlock | ||
{ | ||
uint64_t address = 0; | ||
zasm::Label label; | ||
zasm::Node* begin = nullptr; | ||
zasm::Node* end = nullptr; | ||
std::vector<zasm::Label> successors; | ||
}; | ||
|
||
struct BlockLiveness | ||
{ | ||
uint32_t regsGen = 0; | ||
uint32_t regsKill = 0; | ||
uint32_t regsLiveIn = 0; | ||
uint32_t regsLiveOut = 0; | ||
|
||
zasm::InstrCPUFlags flagsGen = 0; | ||
zasm::InstrCPUFlags flagsKill = 0; | ||
zasm::InstrCPUFlags flagsLiveIn = 0; | ||
zasm::InstrCPUFlags flagsLiveOut = 0; | ||
}; | ||
|
||
struct InstructionLiveness | ||
{ | ||
zasm::Node* node = nullptr; | ||
uint32_t regsLive = 0; | ||
zasm::InstrCPUFlags flagsLive = 0; | ||
}; | ||
|
||
class CFG | ||
{ | ||
explicit CFG(const zasm::Program& program) : program(program) | ||
{ | ||
} | ||
|
||
public: | ||
const zasm::Program& program; | ||
std::map<uint64_t, BasicBlock> blocks; | ||
std::set<uint64_t> exits; | ||
|
||
static zasm::Expected<CFG, std::string> | ||
analyze(const zasm::Program& program, zasm::Label entry, bool verbose = false); | ||
|
||
std::map<uint64_t, std::set<uint64_t>> getPredecessors() const; | ||
std::map<uint64_t, BlockLiveness> getLivenessBlocks(bool verbose = false) const; | ||
std::vector<InstructionLiveness> | ||
getInstructionLiveness(const std::map<uint64_t, BlockLiveness>& blockLiveness, bool verbose = false) const; | ||
}; | ||
|
||
} // namespace obfuscator |
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
namespace obfuscator | ||
{ | ||
bool obfuscate(Context& ctx); | ||
bool obfuscate(Context& ctx, bool verbose = false); | ||
} |
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
Oops, something went wrong.