首页 > 学院 > 开发设计 > 正文

RadASM配色方案工具fix

2019-11-06 07:53:19
字体:
来源:转载
供稿:网友

前言

找到一个开源工程, 里面有2个子工程用MASM写的RadASM工程. 在pediy上看到一个RadASM配色方案, 发现用的有一点不方便. 逆了一下, 还原了一个vc6控制台工程. 在逆完后, 学到了如何高效的得到ini文件中指定key值中的Item数量, 对于Item数量巨大的ini操作, 效率提高很多. 以前取Key值中的Item数量, 总是用输错法完成, 效率太低了.

工程下载点

RadAsmColorConfig.zip

编译环境

vc6sp6 + Win7x64

工程预览

// @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 resultfind RadAsm install directory [D:/RadASM/]update D:/RadASM/RadASM.ini ...ok : add LsColorCfgOnRadAsm to RadASMupdate 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 RadAsmEND请按任意键继续. . .*/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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表