NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.62k stars 5.87k forks source link

Sleigh: there is no warning about collisioning group #5604

Open lab313ru opened 1 year ago

lab313ru commented 1 year ago

In my language I have one group with two collisioning rules, which can be applied both to the same bytes sequence, but I don't get any warning about that from Sleigh compiler.

It looks something like that:

group1: "xxxx" is rule1 & rule2 { }
group1: "yyyy" is rule3 & rule4 {}

:opc1 group1 is group1 {}

If both lines are enabled Sleigh gets the first one, but commenting the first gives me the second definition. It would be great to get a warning about such things.

GhidorahRex commented 1 year ago

You can enable the warning of colliding constructors using the -c argument to the sleigh constructor.

lab313ru commented 1 year ago

Just checked. It looks like -c flag doesn't work. I don't get any warning regarding colliding group implementations.

Do you mean sleighArgs.txt ?

emteere commented 1 year ago

Yes in the sleighArgs.txt file.

You can also use "-l" to help root out constructor order issues where two patterns could be matched and the one that comes first will match.

I'd try both to see if either can report the issue.

lab313ru commented 1 year ago

It requires removing sla manually to get these options work.

lab313ru commented 1 year ago

Also, only specifying both options does work. In result it outputs something like that:

ERROR lang.slaspec:1285: Constructor patterns cannot be distinguished: 
   InstructionPattern{1.0..... 0....... 00001010} table "instruction" constructor from lang.slaspec:1285
   InstructionPattern{1....... 01110... 0000101.} table "instruction" constructor from lang.slaspec:1271 (SleighCompile)  
emteere commented 1 year ago

We should possibly consider adding these options on by default when a language is created initially.

Then remove them for processors that have order issues, like the ARM.