rizinorg / rz-ghidra

Deep ghidra decompiler and sleigh disassembler integration for rizin
GNU Lesser General Public License v3.0
825 stars 88 forks source link

No SuperH(4) arch present? #39

Closed brainstorm closed 5 years ago

brainstorm commented 5 years ago

Thanks for the good work here!

SuperH4 It was introduced recently (11th Sept)... is it too tricky to refresh the build to include it?

[0x08000040]> pdgs
DATA:LE:64:default
DATA:BE:64:default
x86:LE:32:default
x86:LE:32:System Management Mode
x86:LE:16:Real Mode
x86:LE:64:default
PIC-16:LE:16:PIC-16
PIC-16:LE:16:PIC-16F
AARCH64:LE:64:v8A
AARCH64:BE:64:v8A
PIC-17:LE:16:PIC-17C7xx
8085:LE:16:default
Dalvik:LE:32:default
6502:LE:16:default
6502:BE:16:default
MIPS:BE:32:default
MIPS:LE:32:default
MIPS:BE:32:R6
MIPS:LE:32:R6
MIPS:BE:64:default
MIPS:LE:64:default
MIPS:BE:64:micro
MIPS:LE:64:micro
MIPS:BE:64:R6
MIPS:LE:64:R6
MIPS:BE:64:64-32addr
MIPS:LE:64:64-32addr
MIPS:LE:64:micro64-32addr
MIPS:BE:64:micro64-32addr
MIPS:BE:64:64-32R6addr
MIPS:LE:64:64-32R6addr
MIPS:BE:32:micro
MIPS:LE:32:micro
z80:LE:16:default
z8401x:LE:16:default
z180:LE:16:default
z182:LE:16:default
68000:BE:32:default
68000:BE:32:MC68030
68000:BE:32:MC68020
68000:BE:32:Coldfire
PIC-24E:LE:24:default
PIC-24F:LE:24:default
PIC-24H:LE:24:default
dsPIC30F:LE:24:default
dsPIC33F:LE:24:default
dsPIC33E:LE:24:default
CR16C:LE:16:default
Toy:BE:32:default
Toy:BE:32:posStack
Toy:LE:32:default
Toy:BE:32:wordSize2
Toy:LE:32:wordSize2
Toy:BE:64:default
Toy:LE:64:default
Toy:BE:32:builder
Toy:LE:32:builder
Toy:BE:32:builder.align2
Toy:LE:32:builder.align2
TI_MSP430:LE:16:default
TI_MSP430X:LE:32:default
pa-risc:BE:32:default
sparc:BE:32:default
sparc:BE:64:default
PIC-12:LE:16:PIC-12C5xx
tricore:LE:32:default
tricore:LE:32:tc29x
tricore:LE:32:tc172x
tricore:LE:32:tc176x
6805:BE:16:default
PIC-18:LE:24:PIC-18
avr8:LE:16:default
avr8:LE:16:extended
avr8:LE:16:atmega256
avr32:BE:32:default
PIC-16:LE:16:PIC-16C5x
8051:BE:16:default
80251:BE:24:default
80390:BE:24:default
8051:BE:24:mx51
8048:LE:16:default
ARM:LE:32:v8
ARM:LEBE:32:v8LEInstruction
ARM:BE:32:v8
ARM:LE:32:v7
ARM:LEBE:32:v7LEInstruction
ARM:BE:32:v7
ARM:LE:32:Cortex
ARM:BE:32:Cortex
ARM:LE:32:v6
ARM:BE:32:v6
ARM:LE:32:v5t
ARM:BE:32:v5t
ARM:LE:32:v5
ARM:BE:32:v5
ARM:LE:32:v4t
ARM:BE:32:v4t
ARM:LE:32:v4
ARM:BE:32:v4
JVM:BE:32:default
PowerPC:BE:32:default
PowerPC:LE:32:default
PowerPC:BE:64:default
PowerPC:BE:64:64-32addr
PowerPC:LE:64:64-32addr
PowerPC:LE:64:default
PowerPC:BE:32:4xx
PowerPC:LE:32:4xx
PowerPC:BE:32:MPC8270
PowerPC:BE:32:QUICC
PowerPC:LE:32:QUICC
PowerPC:BE:64:A2-32addr
PowerPC:LE:64:A2-32addr
PowerPC:BE:64:A2ALT-32addr
PowerPC:LE:64:A2ALT-32addr
PowerPC:BE:64:A2ALT
PowerPC:LE:64:A2ALT
PowerPC:BE:64:VLE-32addr
PowerPC:BE:64:VLEALT-32addr

/cc @radare

thestr4ng3r commented 5 years ago

Updated, but I haven't tested this arch because I don't know anything about it. Also for now you have to set r2ghidra.lang to the id you want manually, so please send a pr with the respective entries here: https://github.com/radareorg/r2ghidra-dec/blob/master/src/R2Architecture.cpp#L16

brainstorm commented 5 years ago

Did that change, shows up on the pdgs listing, but:

Ghidra Decompiler Error: Could not match asm.arch sh32 to sleigh arch.

Since AFAIK all SuperH's are 32 bits, r2 maps it as sh so it kinda breaks your scheme... I'm debating myself on whether to add this weird case on r2ghidra-dec, i.e sth like (pseudocode):

(...)
std::string SleighIdFromCore(RCore *core)
{
    const char *arch = r_config_get(core->config, "asm.arch");
    bool be = r_config_get_i(core->config, "cfg.bigendian") != 0;
    ut64 bits = r_config_get_i(core->config, "asm.bits");
    string flavor = string("default");

    auto arch_it = arch_map.find(arch + to_string(bits));
    if(arch_it == arch_map.end())
        throw LowlevelError("Could not match asm.arch " + std::string(arch) + to_string(bits) + " to sleigh arch.");

    if (!arch_it->second.compare("ARM")) {
        flavor = string("v7");
        bits = 32;
    }
    if (!arch_it->second.compare("superh")) {
        arch_it = arch_map.find(arch);
        bits = 32;
    }
    if (!arch_it->second.compare("superh4")) {
        arch_it = arch_map.find(arch);
        bits = 32;
    }

Or "uniformize" it on @radare so that asm.arch becomes sh32 (unsure about how many third party r2pipes, anal & co would that break though).

radare commented 5 years ago

Better hack into ghidra. The arch is sh. Not sh32

On 21 Sep 2019, at 02:12, Roman Valls Guimera notifications@github.com wrote:

 Did that change, shows up on the pdgs listing, but:

Ghidra Decompiler Error: Could not match asm.arch sh32 to sleigh arch.

Since AFAIK all SuperH's are 32 bits, r2 maps it as sh so it kinda breaks your scheme... I'm debating myself on whether to add this weird case on r2ghidra-dec, i.e sth like (pseudocode):

(...) std::string SleighIdFromCore(RCore core) { const char arch = r_config_get(core->config, "asm.arch"); bool be = r_config_get_i(core->config, "cfg.bigendian") != 0; ut64 bits = r_config_get_i(core->config, "asm.bits"); string flavor = string("default");

auto arch_it = arch_map.find(arch + to_string(bits));
if(arch_it == arch_map.end())
    throw LowlevelError("Could not match asm.arch " + std::string(arch) + to_string(bits) + " to sleigh arch.");

if (!arch_it->second.compare("ARM")) {
    flavor = string("v7");
    bits = 32;
}
if (!arch_it->second.compare("superh")) {
    arch_it = arch_map.find(arch);
    bits = 32;
}
if (!arch_it->second.compare("superh4")) {
    arch_it = arch_map.find(arch);
    bits = 32;
}

Or "uniformize" it on @radare so that asm.arch becomes sh32 (unsure about how many third party r2pipes, anal & co would that break though).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

thestr4ng3r commented 5 years ago

Yes what is currently done is simply concatenating the arch from r2 with the bits and mapping that, which is hacky and planned to be changed, that's how sh32 is generated from sh. So for now, just adding an entry using sh32 as the key to arch_map should work.

brainstorm commented 5 years ago

I see, but not exactly as it turns out:

$ git diff
diff --git a/src/R2Architecture.cpp b/src/R2Architecture.cpp
index fc88e79..acc5af2 100644
--- a/src/R2Architecture.cpp
+++ b/src/R2Architecture.cpp
@@ -31,6 +31,8 @@ static const std::map<std::string, std::string> arch_map = {
                { "ppc64", "PowerPC" } ,
                { "sparc32", "sparc" } ,
                { "sparc64", "sparc" } ,
+               { "superh4", "sh32" } ,
+               { "superh", "sh32" } ,
                { "msp43016", "TI_MSP430" } ,
                { "m68k32", "68000" } ,
 };

Leads to:

[0x08000040]> pdg
Ghidra Decompiler Error: Could not match asm.arch sh32 to sleigh arch.
[0x08000040]>
thestr4ng3r commented 5 years ago

It's the other way around. It should be something like { "sh32", "SuperH4" }

brainstorm commented 5 years ago

Handling on PR #41, closing.