This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
asdasd.txt
283 lines (195 loc) · 5.48 KB
/
asdasd.txt
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include "module.h"
#include "../drv/drv.h"
#include "../mm/mm.h"
#include <lib/utill.h>
#include "../ntuser/ntuser.h"
/*
Desktop Window Manager
*/
#define MAX_WINDOWS 128
#define BACKGROUND_COLOR 0x00008080
#define TITLE_BAR_THICKNESS 22
struct KSYSTEM_WINDOW
{
CHAR* Title;
UINT* Framebuffer;
UINT X;
UINT Y;
UINT Width;
UINT Height;
UINT WindowType;
/*0 - Form
1 - Label
2 - Button
*/
INT WindowID;
};
INT iLastWindow = 0;
struct KSYSTEM_WINDOW* Windows; // Swaggers
STATIC UINT* DwmFramebuffer;
STATIC INT DwmScreenWidth;
STATIC INT DwmScreenHeight;
INT DwmScreenPitch;
STATIC INT DwmFramebufferSize;
UINT* DwmAntiBuffer;
BOOLEAN bRefreshBuffer = FALSE;
static char *dwm_strcpy( char *dest, const char *src )
{
INT i;
for ( i = 0; src[ i ]; i++ )
dest[ i ] = src[ i ];
dest[ i ] = 0;
return dest;
}
VOID
DwmCreateObject(
CHAR* Title,
UINT X,
UINT Y,
UINT Width,
UINT Height,
UINT WindowType
)
{
if ( iLastWindow == MAX_WINDOWS ) return;
iLastWindow++;
CHAR* tempTitle = ( CHAR* )kcalloc( RtlStringLength( Title ) );
UINT* Framebuffer = kcalloc( ( Width - X ) * ( Height - Y ) * sizeof( UINT ) );
RtlSetMemory( Framebuffer, 0x000000, ( Width - X ) * ( Height - Y ) * sizeof( UINT ) );
dwm_strcpy( tempTitle, Title );
Windows[ iLastWindow ].Title = tempTitle;
Windows[ iLastWindow ].X = X;
Windows[ iLastWindow ].Y = Y;
Windows[ iLastWindow ].Width = Width;
Windows[ iLastWindow ].Height = Height;
Windows[ iLastWindow ].WindowType = WindowType;
Windows[ iLastWindow ].WindowID = iLastWindow;
Windows[ iLastWindow ].Framebuffer = Framebuffer;
DbgPrintFmt( "%lx %lx %lx %lx", tempTitle, Windows[ iLastWindow ].Framebuffer, DwmAntiBuffer, DwmFramebuffer);
DbgPrintFmt( "Created new window:\nTitle: %s\nX: %d\nY: %d\nWidth: %d\nHeight: %d\nWindowType: %d\nWindowID: %d",
Windows[ iLastWindow ].Title, Windows[ iLastWindow ].X, Windows[ iLastWindow ].Y, Windows[ iLastWindow ].Width, Windows[ iLastWindow ].Height, Windows[ iLastWindow ].WindowType, Windows[ iLastWindow ].WindowID );
free( tempTitle );
bRefreshBuffer = TRUE;
}
struct KSYSTEM_WINDOW
DwmAcquireInformation(
INT WindowID
)
{
for ( int i = 0; i < MAX_WINDOWS; ++i )
{
if ( Windows[ i ].WindowID == WindowID )
return Windows[ i ];
}
}
VOID
DwmPlotPixelOnWindowFramebuffer(
INT WindowID,
INT x,
INT y,
INT hex
)
{
struct KSYSTEM_WINDOW window = DwmAcquireInformation( WindowID );
if ( !window.WindowID )
return;
if ( x >= window.Width || y >= window.Height || x < 0 || y < 0 )
return;
INT iOffset = x + (window.Width) * y;
window.Framebuffer[ iOffset ] = hex;
bRefreshBuffer = TRUE;
}
static void plot_px( int x, int y, UINT hex )
{
if ( x >= DwmScreenWidth || y >= DwmScreenHeight || x < 0 || y < 0 )
return;
INT iOffset = x + ( DwmScreenPitch / sizeof( UINT ) ) * y;
DwmAntiBuffer[ iOffset ] = hex;
return;
}
VOID
DwmRefreshBuffer(
)
{
if ( !bRefreshBuffer ) return;
bRefreshBuffer = FALSE;
//Set background
for ( INT i = 0; i < DwmFramebufferSize; ++i )
DwmAntiBuffer[ i ] = BACKGROUND_COLOR;
//Draw Forms
for ( INT tempI = 0; tempI < MAX_WINDOWS; ++tempI )
{
//DbgPrintFmt( "lol" );
//If NULL, don't render!
struct KSYSTEM_WINDOW Window = DwmAcquireInformation( tempI );
if ( Window.WindowID != NULL )
{
//DbgPrintFmt( "sex" );
/*switch ( Window.WindowType )
{
case 0:
break;
case 1:
break;
case 2:
break;
}*/
//render test
/*for ( INT i = Window.X; i < Window.Width; ++i )
{
for ( INT j = Window.Y; j < Window.Height; ++j )
{
INT iOffset = i + ( DwmScreenPitch / sizeof( UINT ) ) * j;
DwmAntiBuffer[ iOffset ] = 0xffffff;
}
}
*/
INT iStartX = Window.X;
INT iEndX = Window.Width;
INT iStartY = Window.Y;
INT iEndY = Window.Height;
DwmDrawFilled( iStartX, iEndX, iStartY, iEndY, 0x000000 );
DwmDrawFilled( iStartX, iEndX - 1, iStartY, iEndY - 1, 0xDFDFDF );
DwmDrawFilled( iStartX + 1, iEndX - 1, iStartY + 1, iEndY - 1, 0x808080 );
DwmDrawFilled( iStartX + 1, iEndX - 2, iStartY + 1, iEndY - 2, 0xFFFFFF );
DwmDrawFilled( iStartX + 2, iEndX - 2, iStartY + 2, iEndY - 2, 0xC0C0C0 );
DwmDrawFilled( iStartX + 3, iEndX - 3, iStartY + 3, iStartY + TITLE_BAR_THICKNESS - 1, 0x000080 );
INT in_x = 1;
INT in_y = TITLE_BAR_THICKNESS;
for ( INT i = 0; i < ( Window.Width - Window.X ) * ( Window.Height - Window.Y ) * sizeof(UINT); i++ )
{
in_x++;
//DbgPrintFmt( "%lx %lx %lx", DwmFramebuffer, Windows[ iLastWindow ].Framebuffer, DwmAntiBuffer );
plot_px( in_x + Window.X, in_y + Window.Y, Window.Framebuffer[ i ] );
if ( in_x - 1 == Window.Width - Window.X - 4 )
{
in_y++;
in_x = 1;
}
if ( in_y == Window.Height - Window.Y - 3 )
break;
}
}
}
//Apply changes
for ( INT i = 0; i < DwmFramebufferSize / sizeof( UINT ); ++i )
DwmFramebuffer[ i ] = DwmAntiBuffer[ i ];
}
BOOLEAN
DwmInitialize(
)
{
DwmFramebuffer = ( UINT* )KiVBEData.Address; //cast
DwmScreenWidth = KiVBEData.Width;
DwmScreenHeight = KiVBEData.Height;
DwmScreenPitch = KiVBEData.Pitch;
Windows = ( struct KSYSTEM_WINDOW* )malloc( sizeof( struct KSYSTEM_WINDOW ) * MAX_WINDOWS );
DwmFramebufferSize = DwmScreenPitch * DwmScreenHeight;
DwmAntiBuffer = ( UINT* )kcalloc( DwmFramebufferSize );
if ( !DwmAntiBuffer )
return FALSE;
bRefreshBuffer = TRUE;
DwmCreateObject( "xd", 10, 10, 500, 300, 0 );
//DwmPlotPixelOnWindowFramebuffer( 1, 10, 10, 0x000000);
//DwmCreateObject( "tst", 280, 10, 300, 200, 0 );
}