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

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

2017-3-3 23:05
3472
// @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工程和编译好的工具


[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

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