Skip to content

Commit

Permalink
Add adapter for gb (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r authored Sep 8, 2023
1 parent c9c4d07 commit 1a6346b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Trace sources
The following sources are currently known to produce meaningful results with
rz-tracetest:

* [VICE](https://github.com/rizinorg/vice) Patched VICE emulator for testing
6502.
* [QEMU](https://github.com/BinaryAnalysisPlatform/qemu) Patched for the BAP
project. Specifically useful for ARM and potentially later x86 too.
* [VICE](https://github.com/rizinorg/vice) Patched VICE emulator for testing
6502.
* [SameBoy](https://github.com/rizinorg/SameBoy) Patched Game Boy emulator for
testing gb (sm83)

Other sources which have not been tested with rz-tracetest specifically yet:

Expand Down
2 changes: 1 addition & 1 deletion bap-frames
54 changes: 51 additions & 3 deletions rz-tracetest/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class PPCTraceAdapter : public TraceAdapter {
return false;
}

bool IgnoreUnknownReg(const std::string &rz_reg_name) const {
bool IgnoreUnknownReg(const std::string &rz_reg_name) const override {
return rz_reg_name == "ca32" || rz_reg_name == "ov32";
}

Expand Down Expand Up @@ -261,7 +261,7 @@ class I8051TraceAdapter : public TraceAdapter {
return false;
}

bool IgnoreUnknownReg(const std::string &rz_reg_name) const {
bool IgnoreUnknownReg(const std::string &rz_reg_name) const override {
return true;
}
};
Expand All @@ -280,7 +280,53 @@ class MipsTraceAdapter : public TraceAdapter {
return false;
}

bool IgnoreUnknownReg(const std::string &rz_reg_name) const {
bool IgnoreUnknownReg(const std::string &rz_reg_name) const override {
return true;
}
};

class GBTraceAdapter : public TraceAdapter {
public:
std::string RizinArch() const override {
return "gb";
}

std::string TraceRegToRizin(const std::string &tracereg) const override {
if (tracereg == "pc") {
// Rizin extends pc to 32bit mpc
return "mpc";
}
return tracereg;
}

void AdjustRegContentsFromTrace(const std::string &tracename, RzBitVector *trace_val, RzAnalysisOp *op) const override {
if (tracename == "pc") {
// Rizin extends pc to 32bit mpc
ut16 v = rz_bv_to_ut16(trace_val);
rz_bv_fini(trace_val);
rz_bv_init(trace_val, 32);
rz_bv_set_from_ut64(trace_val, v);
}
}

void PrintRegisterDetails(const std::string &tracename, const std::string &data, size_t bits_size) const override {
if (tracename == "f") {
if (bits_size != 8) {
return;
}
ut8 f = data[0];
printf(" 0 %#04x = %d\n", 1 << 0, (f & (1 << 0)) != 0);
printf(" 1 %#04x = %d\n", 1 << 1, (f & (1 << 1)) != 0);
printf(" 2 %#04x = %d\n", 1 << 2, (f & (1 << 2)) != 0);
printf(" 3 %#04x = %d\n", 1 << 3, (f & (1 << 3)) != 0);
printf(" 4 %#04x C = %d\n", 1 << 4, (f & (1 << 4)) != 0);
printf(" 5 %#04x H = %d\n", 1 << 5, (f & (1 << 5)) != 0);
printf(" 6 %#04x N = %d\n", 1 << 6, (f & (1 << 6)) != 0);
printf(" 7 %#04x Z = %d\n", 1 << 7, (f & (1 << 7)) != 0);
}
}

bool AllowNoOperandSameValueAssignment() const override {
return true;
}
};
Expand All @@ -299,6 +345,8 @@ std::unique_ptr<TraceAdapter> SelectTraceAdapter(frame_architecture arch) {
return std::unique_ptr<TraceAdapter>(new I8051TraceAdapter());
case frame_arch_mips:
return std::unique_ptr<TraceAdapter>(new MipsTraceAdapter());
case frame_arch_sm83:
return std::unique_ptr<TraceAdapter>(new GBTraceAdapter());
default:
return nullptr;
}
Expand Down

0 comments on commit 1a6346b

Please sign in to comment.