include stdio include stdlib include ntddk define SIZE_OF_ELEMENT RTL_

 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
#include <stdio.h>
#include <stdlib.h>
#include <ntddk.h>
#define SIZE_OF_ELEMENT 4
RTL_GENERIC_COMPARE_RESULTS
CompareRoutine(
__in struct _RTL_AVL_TABLE *Table,
__in PVOID FirstStruct,
__in PVOID SecondStruct
)
{
int i;
char *p1 = FirstStruct;
char *p2 = SecondStruct;
for(i = SIZE_OF_ELEMENT - 1; i >= 0; i--){
if(p1[i] - p2[i] < 0){
return GenericLessThan;
}
if(p1[i] - p2[i] > 0){
return GenericGreaterThan;
}
}
return GenericEqual;
}
PVOID
Allocate_Routine(
__in struct _RTL_AVL_TABLE *Table,
__in CLONG ByteSize
)
{
void *temp;
temp = malloc(ByteSize);
return temp;
}
VOID
FreeRoutine(
__in struct _RTL_AVL_TABLE *Table,
__in PVOID Buffer
)
{
free(Buffer);
}
void main()
{
//Start vars
BOOLEAN ok;
int A[10], i;
PRTL_AVL_TABLE Table = malloc(sizeof(RTL_AVL_TABLE));
RtlInitializeGenericTableAvl(Table, CompareRoutine, Allocate_Routine, FreeRoutine, NULL);
//Some array
A[0] = 534;
A[1] = 345;
A[2] = 3563;
A[3] = 453;
A[4] = 43;
A[5] = 65;
A[6] = 23443;
A[7] = 23546;
A[8] = 2;
A[9] = 6456;
//Adding to the Table
for(i = 0; i < 10; i++){
RtlInsertElementGenericTableAvl(Table, &A[i], sizeof(A[i]), &ok);
if (ok == 1) printf("ok\n");
}
printf("\n");
//Printing info
printf("%lu\n", Table->NumberGenericTableElements);
printf("%lu\n", Table->DepthOfTree);
printf("%lu\n", Table->DeleteCount);
free(Table);
}