-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutDlg.asm
209 lines (189 loc) · 8.58 KB
/
AboutDlg.asm
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
;------------------------------------------------------------------------------
; CD - Compress-Decompress Utility using MS Compression API
; fearless 2023 - github.com/mrfearless
;------------------------------------------------------------------------------
; https://learn.microsoft.com/en-us/windows/win32/cmpapi/-compression-portal
; https://learn.microsoft.com/en-us/windows/win32/cmpapi/using-the-compression-api
; https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-compress
; https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-decompress
;------------------------------------------------------------------------------
;
; CD uses the Microsoft Compression API to compress or decompress data using
; one of the four supported compression algorithms: XPRESS, XPRESS with Huffman
; encoding, MSZIP or LZMS.
;
; The files compressed by CD using those compression algorithms also store a
; signature DWORD value as the header at the start of the file. This is so that
; the appropriate compression algorithm can be used for the decompression.
;
; CD also makes use of the compression API to store bitmap resources as LZMS
; compressed data. There are two ways in which CD uses that compressed bitmap
; data:
;
; 1) In the about box, by uncompressing the bitmap data before creating the
; bitmap in memory. The LZMS compressed bitmap data is stored as static hex
; bytes in the CD128x128x4.bmp.asm file.
;
; 2) Adding LZMS compressed bitmap files (.lzms) as resources which are
; compiled into CD.exe. These resources are loaded into memory, and then
; uncompressed before creating the bitmaps in memory.
;
;------------------------------------------------------------------------------
;
; XPRESS
; ------
; Microsoft Xpress Compression Algorithm (MS-XCA), more commonly known as
; LZXpress, implements the LZ77 algorithm.
;
; XPRESS-HUFFMAN
; --------------
; The Huffman variant of the Microsoft Xpress Compression Algorithm (MS-XCA)
; uses LZ77-style dictionary compression combined with Huffman coding.
; Designed for fast compression and decompression with a small dictionary size.
;
; MSZIP
; -----
; MSZIP uses a combination of LZ77 and Huffman coding. It has only minor
; variations from Phil Katz's 'deflate' method. MSZIP uses only the three basic
; modes of deflate: stored, fixed Huffman tree, and dynamic Huffman tree.
;
; LZMS
; ----
; LZMS is an LZ77-based algorithm achieving a high compression ratio by relying
; on a large LZ77 dictionary size and Huffman coding in addition to more
; concise arithmetic coding.
;
;------------------------------------------------------------------------------
AboutDlgProc PROTO hWin:HWND, iMsg:DWORD, wParam:WPARAM, lParam:LPARAM
; Reference to other functions in other files:
EXTERN CDBitmapCreateFromMem: PROTO pBitmapData:DWORD
EXTERN CDDecompressMem: PROTO pCompressedData:DWORD, dwCompressedDataLength:DWORD
.CONST
; About Dialog
IDD_AboutDlg EQU 17000
IDC_ABOUT_EXIT EQU 17001
IDC_ABOUT_BANNER EQU 17002
IDC_WEBSITE_URL EQU 17003
IDC_TxtInfo EQU 17004
IDC_TxtVersion EQU 17005
IDC_EDT_INFO EQU 17006
.DATA
mrfearless_github DB "https://github.com/mrfearless",0
szStringInMemoryError DB "This is meant to show some text. Maybe something went wrong?",0
szShellOpen DB "open",0
pBMPInMemory DD 0
hBMPInMemory DD 0
pStringInMemory DD 0
.DATA?
hWebsiteURL DD ?
hAboutBanner DD ?
hTxtInfo DD ?
hTxtVersion DD ?
hEdtInfo DD ?
.CODE
;------------------------------------------------------------------------------
; About Dialog Procedure
;------------------------------------------------------------------------------
AboutDlgProc PROC hWin:HWND, iMsg:DWORD, wParam:WPARAM, lParam:LPARAM
; SS_NOTIFY equ 00000100h in resource editor - in radasm resource editor directly edit dword value to get this added to static control
mov eax,iMsg
.IF eax == WM_INITDIALOG
Invoke SendMessage, hWin, WM_SETICON, ICON_SMALL, hIcoMain
.IF eax != NULL
Invoke DeleteObject, eax
.ENDIF
;----------------------------------------------------------------------
; Create our about banner bitmap from the static data stored in the
; CD128X128X4.bmp.asm file which is compressed LZMS bitmap data.
;----------------------------------------------------------------------
Invoke CDBitmapCreateFromCompressedMem, Addr CD128X128X4, CD128X128X4Length
.IF eax != NULL
mov hBMPInMemory, eax
Invoke SendDlgItemMessage, hWin, IDC_ABOUT_BANNER, STM_SETIMAGE, IMAGE_BITMAP, hBMPInMemory
.ENDIF
; ;------------------------------------------------------------------------------
; ; Alternative way of manually calling CDDecompressMem & CDBitmapCreateFromMem
; ;------------------------------------------------------------------------------
; Invoke CDDecompressMem, Addr CD128X128X4, CD128X128X4Length
; .IF eax != NULL
; mov pBMPInMemory, eax
; Invoke CDBitmapCreateFromMem, pBMPInMemory
; .IF eax != NULL
; mov hBMPInMemory, eax
; Invoke SendDlgItemMessage, hWin, IDC_ABOUT_BANNER, STM_SETIMAGE, IMAGE_BITMAP, hBMPInMemory
; .ENDIF
; .ENDIF
Invoke GetDlgItem, hWin, IDC_WEBSITE_URL
mov hWebsiteURL, eax
Invoke GetDlgItem, hWin, IDC_TxtInfo
mov hTxtInfo, eax
Invoke GetDlgItem, hWin, IDC_TxtVersion
mov hTxtVersion, eax
Invoke GetDlgItem, hWin, IDC_ABOUT_BANNER
mov hAboutBanner, eax
Invoke GetDlgItem, hWin, IDC_EDT_INFO
mov hEdtInfo, eax
;----------------------------------------------------------------------
; Decompress a compressed string stored in Infotext.asm as szMSZPText
; Original string size is 2297 Bytes, compressed it is 1035 Bytes long
;----------------------------------------------------------------------
Invoke CDDecompressMem, Addr szMSZPText, szMSZPTextLength
.IF eax != NULL
mov pStringInMemory, eax
Invoke SetWindowText, hEdtInfo, pStringInMemory
.ELSE
Invoke SetWindowText, hEdtInfo, Addr szStringInMemoryError
.ENDIF
;----------------------------------------------------------------------
; Change class for these controls to show a hand when mouse over.
; These controls also have SS_NOTIFY equ 00000100h set so they will
; respond to a mouse click and send a WM_COMMAND message which allows
; us to fake a hyperlink to open browser at desired website
;----------------------------------------------------------------------
Invoke LoadCursor, 0, IDC_HAND
Invoke SetClassLong, hWebsiteURL, GCL_HCURSOR, eax
Invoke LoadCursor, 0, IDC_HAND
Invoke SetClassLong, hAboutBanner, GCL_HCURSOR, eax
.ELSEIF eax == WM_CTLCOLORDLG
invoke SetBkMode, wParam, WHITE_BRUSH
invoke GetStockObject, WHITE_BRUSH
ret
.ELSEIF eax == WM_CTLCOLORSTATIC ; set to transparent background for listed controls
mov eax, lParam
.IF eax == hWebsiteURL || eax == hTxtInfo || eax == hTxtVersion
Invoke SetTextColor, wParam, 0h ;0FFFFFFh
Invoke SetBkMode, wParam, TRANSPARENT
Invoke GetStockObject, NULL_BRUSH
ret
.ENDIF
.ELSEIF eax == WM_CLOSE
.IF pStringInMemory != 0
Invoke GlobalFree, pStringInMemory
.ENDIF
.IF pBMPInMemory != 0
Invoke GlobalFree, pBMPInMemory
.ENDIF
.IF hBMPInMemory != 0
Invoke DeleteObject, hBMPInMemory
.ENDIF
mov pStringInMemory, 0
mov pBMPInMemory, 0
mov hBMPInMemory, 0
Invoke EndDialog, hWin, NULL
.ELSEIF eax == WM_COMMAND
mov eax, wParam
and eax, 0FFFFh
.IF eax == IDC_ABOUT_EXIT
Invoke SendMessage, hWin, WM_CLOSE, NULL, NULL
.ENDIF
mov eax, lParam
.IF eax == hWebsiteURL || eax == hAboutBanner
Invoke ShellExecute, hWin, Addr szShellOpen, Addr mrfearless_github, NULL, NULL, SW_SHOW
.ENDIF
.ELSE
mov eax,FALSE
ret
.ENDIF
mov eax,TRUE
ret
AboutDlgProc ENDP