-
Notifications
You must be signed in to change notification settings - Fork 2
/
Stack.cpp
62 lines (55 loc) · 2.61 KB
/
Stack.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
59
60
61
62
/************************************************************************
* stack.cpp *
* This is a simple stack class for a stack of lptr's. It is used in *
* keeping track of jump locations, so that when a jump is followed it *
* can be reversed. The stack is of a set size, and when it becomes too *
* large the bottom of the stack is lost. I did have some plans on using *
* this class in a front end unpacker-emulator but my plans have changed *
* and any unpacker-emulator will use a different method more akin to *
* single step tracing. *
* The stack was added in Version 2.11 *
************************************************************************/
#include <windows.h>
#include "stacks.h"
#include "debug.h"
/************************************************************************
* constructor function *
* - simply reset the top of the stack *
************************************************************************/
stack::stack()
{ stacktop=0;
}
/************************************************************************
* destructor function *
* - nothing to do since the stack is a fixed array *
************************************************************************/
stack::~stack()
{
}
/************************************************************************
* push *
* - places an item on top of the stack. If there is no room then we *
* lose an item from the bottom and move the others down *
************************************************************************/
void stack::push(lptr loc)
{ int i;
if(stacktop==CALLSTACKSIZE) // need to remove bottom item from stack
{ for(i=0;i<CALLSTACKSIZE-1;i++)
{ callstack[i]=callstack[i+1];
stacktop--;
}
}
callstack[stacktop]=loc;
stacktop++;
}
/************************************************************************
* pop *
* - gets an item from the top of the stack, or returns nlptr if the *
* stack is empty *
************************************************************************/
lptr stack::pop(void)
{ if(!stacktop)
return nlptr;
stacktop--;
return callstack[stacktop];
}