-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgagrader8051jmptable.cpp
More file actions
53 lines (41 loc) · 1.15 KB
/
gagrader8051jmptable.cpp
File metadata and controls
53 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "gagrader8051jmptable.h"
#include "gainstruction.h"
#include "gamnemonic.h"
#include "goodasm.h"
#include <QDebug>
GAGrader8051JmpTable::GAGrader8051JmpTable() {
name="8051jmptable";
//8051pushpop is more reliable.
stable=false;
}
// Is it real?
uint64_t GAGrader8051JmpTable::isValid(GoodASM *goodasm){
assert(goodasm);
//Needed to set the threshold.
isCompatible(goodasm->lang);
GAInstruction ins=goodasm->at(goodasm->baseaddress);
uint64_t invalid=0, valid=0;
/* This looks for a lot of LJMP instructions in a
* row, which is indicative of a jump table in 8051.
*
* We probably need other tricks for programs without
* jump tables.
*/
foreach(auto ins, goodasm->instructions){
if(ins.data[0]==(char) 0x02) // LJMP instruction.
valid++;
else
valid=0;
if(valid>7){
return 1;
}
}
//No jump table, so not identified by this rule.
return 0;
}
// Is this grader compatible?
bool GAGrader8051JmpTable::isCompatible(GALanguage *lang){
//Only works for 8051.
QString n=lang->name;
return n=="8051";
}