首页
社区
课程
招聘
[下载]RadASM配色方案工具fix
发表于: 2017-3-3 23:05 3610

[下载]RadASM配色方案工具fix

2017-3-3 23:05
3610
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
// @file RadAsmColorConfig.cpp
// @brief 给RadAsm添加自己的配色方案
// @note RadASM配色方案工具fix
//
// 看着默认的RadAsm(2.2.1.5)配色方案看着心都碎了, 各种难受
// 在pediy上看到一个同学写的RadASM配色方案工具(http://bbs.pediy.com/thread-112918.htm), 效果不错(看着养眼), 逆了一下
// 在他2进制代码基础上优化一下, 去注册表中找RadAsm安装目录, 而不是手工选择目录.
// 写.ini的过程用他的
//
// 在任意目录运行一次, 就添加了配色方案 :)
// 在RadASM中选择新添加的配色方案, 就可以应用新的配色方案了
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#define EDITOR_FONT_NAME "Fixedsys"
#define EDITOR_FONT_HEIGHT "16"
#define EDITOR_FONT_WEIGHT "400"
#define IS_FONT_ITALIC "0"
#define EDITOR_FONT_CHARSET_GB2132 "134"
#define MY_COLOR_CONFIG_NAME "LsColorCfgOnRadAsm"
const char* g_pColorCfgData = MY_COLOR_CONFIG_NAME",12632256,8388608,8388608,16777215,15777984,12644544,12632304,12632256,8421504,8388608,16777215,0,16777215,0,16777215,0,16777215,10485760,50331647,32768,0,0,0,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,16711680,10485920,136,16711680,12632256,12632256,12632256,12632256,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,0,0,0";
BOOL FindRadAsmInstallDir(char* pcInstallDir, int iBufLen);
BOOL WriteRadAsmColorConfig(char* pcInstallDir, int iBufLen);
DWORD GetIniItemCountByKey(char* pcIniPathName, char* pcIniKeyName);
int main(int argc, char* argv[])
{
    char szRadAsmInstallDir[_MAX_PATH + 1] = {'\0'};
     
    do {
        if (!FindRadAsmInstallDir(szRadAsmInstallDir, sizeof(szRadAsmInstallDir) - 1)) {
            printf("failed : not find RadAsm install directory\n");
            break;
        }
         
        printf("find RadAsm install directory [%s]\n", szRadAsmInstallDir);
         
        if (!WriteRadAsmColorConfig(szRadAsmInstallDir, strlen(szRadAsmInstallDir))) {
            printf("failed : write RadAsm color config\n");
            break;
        }
         
        printf("ok : %s add to RadAsm\n", MY_COLOR_CONFIG_NAME);
    while (0);
     
    printf("END\n");
    system("pause");
    return 0;
}
/** run result
find RadAsm install directory [D:\RadASM\]
update D:\RadASM\RadASM.ini ...
ok : add LsColorCfgOnRadAsm to RadASM
update D:\RadASM\masm.ini ...
ok : change RadASM editor font to [Fixedsys]
ok : change RadASM editor font height to [16]
ok : change RadASM editor font weight to [400]
ok : change RadASM editor font italic to [TRUE]
ok : change RadASM editor font charset to [GB2132]
ok : LsColorCfgOnRadAsm add to RadAsm
END
请按任意键继续. . .
*/
BOOL FindRadAsmInstallDir(char* pcInstallDir, int iBufLen)
{
    BOOL bRc = FALSE;
    long lRc = ERROR_SUCCESS;
    DWORD cbData = 0;
    DWORD dwType = 0;
    HKEY hSubKey = NULL;
    char* pTmp = NULL;
     
    do {
        ZeroMemory(pcInstallDir, iBufLen);
        // lRc = 0xa1, is dir invalid
        lRc = RegOpenKey(HKEY_LOCAL_MACHINE, // handle to open key
                         "SOFTWARE\\RadASM"// name of subkey to open
                         &hSubKey // handle to open key
                        );
                         
        if (ERROR_SUCCESS != lRc) {
            break;
        }
         
        lRc = RegQueryValueEx(hSubKey, "", NULL, &dwType, NULL, &cbData);
         
        if (ERROR_SUCCESS != lRc) {
            break;
        }
         
        if (((cbData >= (DWORD)iBufLen)) || (REG_SZ != dwType)) {
            break;
        }
         
        lRc = RegQueryValueEx(hSubKey, "", NULL, &dwType, (UCHAR*)pcInstallDir, &cbData);
         
        if (ERROR_SUCCESS != lRc) {
            break;
        }
         
        // append '\\' to path
        pTmp = strrchr(pcInstallDir, '\\');
         
        if (pTmp != (pcInstallDir + cbData - 1)) {
            strcat(pcInstallDir, "\\");
        }
         
        bRc = TRUE;
    while (0);
     
    if (NULL != hSubKey) {
        RegCloseKey(hSubKey);
        hSubKey = NULL;
    }
     
    return bRc;
}
BOOL WriteRadAsmColorConfig(char* pcInstallDir, int iBufLen)
{
    BOOL bRc = FALSE;
    DWORD dwTmp = 0;
    DWORD dwItemCnt = 0;
    char szPathName[_MAX_PATH + 1] = {'\0'};
    char szBuf[_MAX_PATH + 1] = {'\0'};
     
    do {
        if ((NULL == pcInstallDir)
                || (((DWORD)iBufLen + strlen("RadASM.ini")) > (sizeof(szPathName) - 1))) {
            break;
        }
         
        // write to RadASM.ini
        strcpy(szPathName, pcInstallDir);
        strcat(szPathName, "RadASM.ini");
        printf("update %s ...\n", szPathName);
        dwItemCnt = GetIniItemCountByKey(szPathName, "Color");
        sprintf(szBuf, "%ld", dwItemCnt);
         
        if (!WritePrivateProfileString(
                    "Color"// section name
                    szBuf, // key name
                    g_pColorCfgData, // string to add
                    szPathName // initialization file
                )) {
            break;
        }
         
        printf("ok : add %s to RadASM\n", MY_COLOR_CONFIG_NAME);
        // write to masm.ini
        strcpy(szPathName, pcInstallDir);
        strcat(szPathName, "masm.ini");
        printf("update %s ...\n", szPathName);
        bRc = TRUE;
         
        do {
            if (!WritePrivateProfileString("Edit""Font", EDITOR_FONT_NAME, szPathName)) {
                break;
            }
             
            printf("ok : change RadASM editor font to [%s]\n", EDITOR_FONT_NAME);
             
            if (!WritePrivateProfileString("Edit""FontHeight""-"EDITOR_FONT_HEIGHT, szPathName)) {
                break;
            }
             
            printf("ok : change RadASM editor font height to [%s]\n", EDITOR_FONT_HEIGHT);
             
            if (!WritePrivateProfileString("Edit""FontWeight", EDITOR_FONT_WEIGHT, szPathName)) {
                break;
            }
             
            printf("ok : change RadASM editor font weight to [%s]\n", EDITOR_FONT_WEIGHT);
             
            if (!WritePrivateProfileString("Edit""FontItalic", IS_FONT_ITALIC, szPathName)) {
                break;
            }
             
            printf("ok : change RadASM editor font italic to [%s]\n", (0 == atol(IS_FONT_ITALIC)) ? "TRUE" "FALSE");
             
            if (!WritePrivateProfileString("Edit""FontCharSet", EDITOR_FONT_CHARSET_GB2132, szPathName)) {
                break;
            }
             
            printf("ok : change RadASM editor font charset to [GB2132]\n");
        while (0);
    while (0);
     
    return bRc;
}
DWORD GetIniItemCountByKey(char* pcIniPathName, char* pcIniKeyName)
{
    DWORD dwIniKeyItemCnt = 0;
    char* pBuf = NULL;
    char* pBufTmp = NULL;
#ifdef _DEBUG
    size_t nBufSize = 4; // 为了调试, 验证实现是否正确. 发布版工程可以搞大点, 提高效率.
#else
    size_t nBufSize = 0x1000;
#endif
    DWORD dwTmp = 0;
    DWORD dwMaxBufSize = 0;
     
    // 让ini调用最少的次数, 去得到该IniKey下的item counter,
    // 而不是遍历调用GetPrivateProfileString进行试错, 这种方法效率高.
    do {
        if ((NULL == pcIniPathName) || (NULL == pcIniKeyName)) {
            break;
        }
         
        try {
            do {
                pBuf = new char[nBufSize];
                ZeroMemory(pBuf, nBufSize);
                dwTmp = GetPrivateProfileString(pcIniKeyName, NULL, NULL, pBuf, nBufSize, pcIniPathName);
                 
                if (dwTmp > dwMaxBufSize) {
                    dwMaxBufSize = dwTmp;
                     
                    if (NULL != pBuf) {
                        delete []pBuf;
                        pBuf = NULL;
                    }
                     
                    nBufSize += sizeof(DWORD);
                else {
                    // 0018FDFC  30 00 31 00 32 00 33 00 34 00 35 00              0.1.2.3.4.5.
                    // find the right size for buffer to recive result by GetPrivateProfileString
                    if (NULL != pBuf) {
                        delete []pBuf;
                        pBuf = NULL;
                    }
                     
                    dwMaxBufSize += sizeof(WORD); // ready append 0x0000 to tail
                    nBufSize = dwMaxBufSize;
                    pBuf = new char[dwMaxBufSize];
                    ZeroMemory(pBuf, dwMaxBufSize);
                    dwTmp = GetPrivateProfileString(pcIniKeyName, NULL, NULL, pBuf, nBufSize, pcIniPathName);
                    break;
                }
            while (1);
             
            // 正常到这时, pBuf不为空
            // pBuf内容为 0.1.2.3.4.5.N.
            pBufTmp = pBuf;
             
            while ((NULL != pBufTmp) && (*pBufTmp != '\0')) {
                dwIniKeyItemCnt = atol(pBufTmp);
                pBufTmp += (strlen(pBufTmp) + 1);
            }
             
            pBufTmp = NULL;
        catch (...) {
            dwIniKeyItemCnt = 0;
        }
         
        if (NULL != pBuf) {
            delete []pBuf;
            pBuf = NULL;
        }
    while (0);
     
    return dwIniKeyItemCnt;
}

附件中是vc6工程和编译好的工具


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
免费
支持
分享
最新回复 (2)
雪    币: 4020
活跃值: (4282)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
用3系列吧。
2017-3-4 00:10
0
雪    币: 13
活跃值: (324)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
不错
2017-3-9 15:47
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册