-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVNProcess.cpp
58 lines (51 loc) · 1.81 KB
/
VNProcess.cpp
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
54
55
56
57
58
#include <VNProcess.h>
#include <Instruction.h>
#include <iostream>
#include <memory>
VNProcess::VNProcess(std::unique_ptr<IVirtualAddressSpace<unsigned short> >& space, std::unique_ptr<IRegistryProvider>& registers) :
space(std::move(space)),
registers(std::move(registers))
{
}
bool VNProcess::Iteration()
{
if(IsTerminated()) {
return false;
}
std::byte value = space->Read(*registers->GetRegistryAt(std::byte(ProcessCounterRegister)));
std::unique_ptr<IInstruction> instruction(Parse(static_cast<TInstructionValue>(value), *registers, *space));
instruction->Eval(space->ReadDword(*registers->GetRegistryAt(std::byte(ProcessCounterRegister))));
if(IsTerminated()) {
return false;
}
*registers->GetRegistryAt(std::byte(ProcessCounterRegister)) += sizeof(Dword);
return true;
}
bool VNProcess::IsTerminated()
{
if(*registers->GetRegistryAt(std::byte(ProcessCounterRegister)) == TerminalState) {
return true;
}
return false;
}
void VNProcess::DumpStack(int n)
{
for(int i = 0; i < n; ++i) {
std::byte value = space->Read(*registers->GetRegistryAt(std::byte(StackPointerRegister)) - i);
std::cout << std::hex << static_cast<unsigned int>(value);
}
}
void VNProcess::DumpImage(std::string path)
{
std::ofstream output(path, std::ofstream::out);
space->DumpAllTo(output);
}
void VNProcess::DumpRegisters()
{
for(int i = 0; i < StackPointerRegister; ++i) {
std::cout << "r" << i << ": " << *registers->GetRegistryAt(std::byte(i)) << " ";
}
std::cout << "sp: " << *registers->GetRegistryAt(std::byte(StackPointerRegister)) << " ";
std::cout << "lr: " << *registers->GetRegistryAt(std::byte(LinkRegister)) << " ";
std::cout << "pc: " << *registers->GetRegistryAt(std::byte(ProcessCounterRegister)) << std::endl;
}