-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisassembler.cpp
More file actions
31 lines (29 loc) · 788 Bytes
/
Copy pathdisassembler.cpp
File metadata and controls
31 lines (29 loc) · 788 Bytes
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
#include "VM.h"
#include <fstream>
#include <sstream>
#include "VM_binaries.h"
using namespace std;
using namespace VM_BINARIES;
int main(int argc, char const *argv[]){
if(argc < 2){
cerr << "please enter a binary file name\n";
return 1;
}
ifstream f(argv[1], ios::binary);
if(!f){
cerr << "can't open file" << '\n';
return 1;
}
#ifdef USE_GMP_LIB
mpf_set_default_prec(1024);
#endif
vector<Value> vals = parseBin(string((istreambuf_iterator<char>(f)), istreambuf_iterator<char>()));
for(int c = 0; c < vals.size(); c++){
if (vals[c].getType() == VALUE_TYPE_NUMBER) {
cout << VM::disassemble(vals[c].getLong(), (vals.size() - 1 == c)? 0:vals[c + 1]) << endl;
if (vals[c].getNumber() == opcode_PUT) c++;
}
}
f.close();
return 0;
}