Compare commits
3 commits
9b2ad65c3a
...
6d3760c96e
Author | SHA1 | Date | |
---|---|---|---|
DataHoarder | 6d3760c96e | ||
DataHoarder | 2324a561f3 | ||
DataHoarder | bf7c3cefe5 |
|
@ -52,6 +52,10 @@ std::string OutputContext::getComment(uint32_t location) const {
|
|||
return "";
|
||||
}
|
||||
|
||||
bool OutputContext::isNop(uint32_t location) const {
|
||||
return nop.find(location) != nop.end();
|
||||
}
|
||||
|
||||
|
||||
std::string OutputContext::getDataHeader(uint32_t location) const {
|
||||
std::stringstream s;
|
||||
|
@ -193,6 +197,11 @@ void OutputContext::addComment(uint32_t location, const std::string &comment) {
|
|||
}
|
||||
}
|
||||
|
||||
void OutputContext::setNop(uint32_t location) {
|
||||
|
||||
nop[location] = true;
|
||||
}
|
||||
|
||||
std::string OutputContext::getAddressRegisterName(uint32_t addr, uint8_t offset) const {
|
||||
if (offset || registers.find(addr) == registers.end()) {
|
||||
return ::getAddressRegisterName(addr, offset);
|
||||
|
|
|
@ -42,10 +42,11 @@ private:
|
|||
std::unordered_map<uint32_t, std::string> mappings;
|
||||
std::unordered_map<uint32_t, std::string> comments;
|
||||
std::unordered_map<uint32_t, std::string> registers;
|
||||
std::unordered_map<uint32_t, bool> nop;
|
||||
|
||||
public:
|
||||
|
||||
OutputContext(const ImageFormat &image) : image(image) {
|
||||
explicit OutputContext(const ImageFormat &image) : image(image) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -53,6 +54,8 @@ public:
|
|||
|
||||
void addComment(uint32_t location, const std::string &comment);
|
||||
|
||||
void setNop(uint32_t location);
|
||||
|
||||
void addRegister(uint32_t addr, const std::string &name) {
|
||||
registers[addr] = name;
|
||||
}
|
||||
|
@ -69,6 +72,8 @@ public:
|
|||
|
||||
std::string getDataHeader(uint32_t location) const;
|
||||
|
||||
bool isNop(uint32_t location) const;
|
||||
|
||||
std::string getDataEntry(uint32_t location, const std::string &representation = "") const;
|
||||
|
||||
std::string getInstructionString(const Instruction::Instruction &instruction) const;
|
||||
|
|
|
@ -180,7 +180,7 @@ Instruction::Calc::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Calc::toBytes() const {
|
||||
|
|
|
@ -179,7 +179,7 @@ Instruction::CalcImm::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::CalcImm::toBytes() const {
|
||||
|
|
|
@ -91,7 +91,7 @@ Instruction::Copy::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,14 +52,14 @@ std::vector<Instruction::OutputFormat> Instruction::End::toOutputFormat(const Ou
|
|||
}
|
||||
|
||||
std::vector<uint32_t> Instruction::End::getPossibleBranches() const {
|
||||
return std::vector<uint32_t>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
|
||||
Instruction::End::execute(AnalysisState &state) const {
|
||||
state.current = 0;
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::End::toBytes() const {
|
||||
|
|
|
@ -97,7 +97,7 @@ Instruction::Init::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Init::toBytes() const {
|
||||
|
|
|
@ -48,6 +48,8 @@ namespace Instruction {
|
|||
uint32_t _endAddress{};
|
||||
public:
|
||||
|
||||
virtual ~Instruction()= default;
|
||||
|
||||
enum class CommandOp : uint8_t {
|
||||
WRITE = 0b00000000,
|
||||
COPY = 0b01000000,
|
||||
|
|
|
@ -70,7 +70,7 @@ Instruction::Jump::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(jumpAddress, getAddress(), JumpKind::Absolute);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Jump::toBytes() const {
|
||||
|
|
|
@ -220,7 +220,7 @@ Instruction::Load::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Load::toBytes() const {
|
||||
|
|
|
@ -63,7 +63,7 @@ std::vector<Instruction::OutputFormat> Instruction::Return::toOutputFormat(const
|
|||
}
|
||||
|
||||
std::vector<uint32_t> Instruction::Return::getPossibleBranches() const {
|
||||
return std::vector<uint32_t>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
|
||||
|
@ -73,7 +73,7 @@ Instruction::Return::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(jumpAddress, getAddress(), JumpKind::Return);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ Instruction::Set::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Set::toBytes() const {
|
||||
|
|
|
@ -70,7 +70,7 @@ Instruction::Wait::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Wait::toBytes() const {
|
||||
|
|
|
@ -108,7 +108,7 @@ Instruction::Write::execute(AnalysisState &state) const {
|
|||
|
||||
state.addKnownJump(getEndAddress(), getAddress(), JumpKind::Continue);
|
||||
|
||||
return std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Instruction::Write::toBytes() const {
|
||||
|
|
|
@ -47,7 +47,7 @@ void decodeImage(const std::string &fileName) {
|
|||
auto imageObject = ImageFormat::fromBytes(bytes);
|
||||
|
||||
|
||||
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", imageObject.getHeader().speed, imageObject.getHeader().mode,
|
||||
printf("SPEED: 0x%02x MODE: 0x%02x BOOT: 0x%08x\n", static_cast<uint32_t>(imageObject.getHeader().speed), static_cast<uint32_t>(imageObject.getHeader().mode),
|
||||
imageObject.getHeader().baseAddress);
|
||||
|
||||
std::cout << "SIGNATURE: " << imageObject.imageSignature << "\n";
|
||||
|
@ -359,6 +359,9 @@ void decodeImage(const std::string &fileName) {
|
|||
functionName.push_back(c);
|
||||
}
|
||||
knownNames[functionStart] = functionName;
|
||||
|
||||
ctx.setNop(loadPointer.getAddress());
|
||||
ctx.setNop(endPointer->getAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +417,9 @@ void decodeImage(const std::string &fileName) {
|
|||
uint32_t prevAddress = 0;
|
||||
for (const auto &entry : imageObject.getInstructions()) {
|
||||
const auto &instruction = entry.second;
|
||||
if (instruction->getAddress() < prevAddress) {
|
||||
if(ctx.isNop(instruction->getAddress())){
|
||||
continue;
|
||||
}else if (instruction->getAddress() < prevAddress) {
|
||||
std::cout << "========== DECODE ERROR? ========== " << std::hex << std::setw(8) << std::setfill('0')
|
||||
<< prevAddress << " - " << std::hex << std::setw(8) << std::setfill('0')
|
||||
<< instruction->getAddress() << "\n";
|
||||
|
|
Loading…
Reference in a new issue