-
Notifications
You must be signed in to change notification settings - Fork 2
/
Xref.cpp
143 lines (132 loc) · 4.94 KB
/
Xref.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/************************************************************************
* xref.cpp *
* *
* class to maintain xref list - xref items consist simply of an address *
* which is the location being referenced and a ref_by address which is *
* where the reference is from. It is ordered by location and then by *
* ref_by. *
************************************************************************/
// include files
#include <windows.h>
#include "xref.h"
#include "schedule.h"
#include "dasm.h"
#include "disasm.h"
#include "data.h"
#include "debug.h"
#include "mainwind.h"
/************************************************************************
* constructor - now empty *
************************************************************************/
xref::xref()
{
}
/************************************************************************
* destructor - nothing is done here, the item can simply be freed *
************************************************************************/
xref::~xref()
{
}
/************************************************************************
* basic function which adds an xref to the current list. *
* - just need loc=location for which to create an xref *
* - and ref_by=where it is being referenced from *
* after the xref has been added we still need to add a line *
* to the disassembly and so a task to do this is added using *
* the scheduler. *
************************************************************************/
void xref::addxref(lptr loc,lptr ref_by)
{ xrefitem *newxref,*chk;
dsegitem *chkseg;
chkseg=dta.findseg(loc);
if(chkseg==NULL)
return;
newxref=new xrefitem;
newxref->addr=loc;
newxref->refby=ref_by;
chk=find(newxref);
if(chk!=NULL)
if(!compare(newxref,chk))
{ delete newxref;
return;
}
addto(newxref);
scheduler.addtask(dis_xref,priority_xref,loc,NULL);
}
/************************************************************************
* compare function for list - uses address/referencing address *
* to sort list *
************************************************************************/
int xref::compare(xrefitem *i,xrefitem *j)
{ if(i->addr < j->addr)
return -1;
if(i->addr > j->addr)
return 1;
if(i->refby < j->refby)
return -1;
if(i->refby > j->refby)
return 1;
return 0;
}
/************************************************************************
* function to delete an xref from the list *
* after the xref has been deleted we check if we need to *
* delete anything from the disassembly as well if there are *
* no xrefs left for that loc *
* does a window update if deleting one, but not the comment, which *
* ensures that the number of xrefs is changed *
************************************************************************/
void xref::delxref(lptr loc,lptr ref_by)
{ xrefitem xtmp,*xfind;
xtmp.addr=loc;
xtmp.refby=ref_by;
xfind=find(&xtmp);
if(xfind!=NULL)
if((xfind->addr==loc)&&(xfind->refby==ref_by))
{ delfrom(xfind);
xtmp.refby=nlptr;
xfind=findnext(&xtmp);
if(xfind!=NULL)
if(xfind->addr==loc)
{ dio.updatewindowifinrange(loc);
return;
}
dsm.delcomment(loc,dsmxref);
}
}
/************************************************************************
* prints the first xref for a given loc *
************************************************************************/
void xref::printfirst(lptr loc)
{ dword numents=0;
xrefitem findit,*chk;
findit.addr=loc;
findit.refby=nlptr;
findnext(&findit);
chk=nextiterator();
if(chk==NULL)
return;
if(options.mode32)
LastPrintBuff("%04lx:%08lx",chk->refby.segm,chk->refby.offs);
else
LastPrintBuff("%04lx:%04lx",chk->refby.segm,chk->refby.offs);
while(chk!=NULL)
{ if(chk->addr==loc)
{ chk=nextiterator();
numents++;
}
else
break;
}
LastPrintBuff(" Number : %ld",numents);
}
/************************************************************************
* userdel *
* - deletes an xref, using the users current line and the refby passed *
* from the scheduler, which is from the xref viewer dialog *
************************************************************************/
void xref::userdel(lptr loc)
{ lptr xcur;
dio.findcurrentaddr(&xcur);
delxref(xcur,loc);
}