C++ 尝试读取evtx文件时出现编译器错误?

C++ 尝试读取evtx文件时出现编译器错误?,c++,C++,我收到编译器错误\u T找不到标识符..请帮助我解决此错误??我也想用C做这个程序?? 但是首先要解决错误,这样我才能调试和观察流程??在VS2008上编译 #include <iostream> #include <fstream> using namespace std; typedef unsigned long ULONG; typedef struct _EVENTLOGHEADER { ULONG HeaderSize; ULONG Signature;

我收到编译器错误\u T找不到标识符..请帮助我解决此错误??我也想用C做这个程序?? 但是首先要解决错误,这样我才能调试和观察流程??在VS2008上编译

#include <iostream>
#include <fstream>
using namespace std;

typedef unsigned long ULONG;

typedef struct _EVENTLOGHEADER {
ULONG HeaderSize;
ULONG Signature;
ULONG MajorVersion;
ULONG MinorVersion;
ULONG StartOffset;
ULONG EndOffset;
ULONG CurrentRecordNumber;
ULONG OldestRecordNumber;
ULONG MaxSize;
ULONG Flags;
ULONG Retention;
ULONG EndHeaderSize;
} EVENTLOGHEADER, *PEVENTLOGHEADER;  

typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef struct _EVENTLOGRECORD {
    DWORD Length;
    DWORD Reserved;
    DWORD RecordNumber;
    DWORD TimeGenerated;
    DWORD TimeWritten;
    DWORD EventID;
    WORD  EventType;
    WORD  NumStrings;
    WORD  EventCategory;
    WORD  ReservedFlags;
    DWORD ClosingRecordNumber;
    DWORD StringOffset;
    DWORD UserSidLength;
    DWORD UserSidOffset;
    DWORD DataLength;
    DWORD DataOffset;
} EVENTLOGRECORD, *PEVENTLOGRECORD;

void main()
{
    ifstream file;
    file.open("C:\Windows\System32\winevt\Logs\\Application.evtx",ios::in|ios::binary);

    if(file.is_open()){
        _EVENTLOGHEADER logheader;
        _EVENTLOGRECORD logRecord;

        //Reading the header
        file.read((char*)&logheader,sizeof(_EVENTLOGHEADER));

        int startOfLog;
        //Loop on every record
        for(unsigned int numberFile=0;numberFile < logheader.CurrentRecordNumber -1;numberFile++){
            //Save the position
            startOfLog = file.tellg();
            //Read log record
            file.read((char*)&logRecord,sizeof(_EVENTLOGRECORD));

            /*******************************************************
            Here are the other information (section 'Remarks' on the 'EVENTLOGRECORD structure' link 
            ********************************************************/

            //Reading sourcename
            wchar_t buffData;
            wstring SourceName;
            file.read((char*)&buffData,sizeof(wchar_t));
            while(buffData!=_T('\0')){
                SourceName.push_back(buffData);
                file.read((char*)&buffData,sizeof(wchar_t));
            }

            //Reading computer name
            wstring ComputerName;
            file.read((char*)&buffData,sizeof(wchar_t));
            while(buffData!=_T('\0')){
                ComputerName.push_back(buffData);
                file.read((char*)&buffData,sizeof(wchar_t));
            }

            //Sets the position to the SID offset 
            int readCursor = startOfLog + logRecord.UserSidOffset;
            file.seekg(readCursor);

            char * userSid = NULL;
            if(logRecord.UserSidLength != 0)
            {
                userSid = (PCHAR)malloc(logRecord.UserSidLength);
                file.read(userSid,logRecord.UserSidLength); //Reading the sid
                //Here you can work on the SiD (but you need win32 API).If you need it, I could show you how i deal with this sid 
                free(userSid);
            }

            //Sets the position to the Strings offset
            readCursor = startOfLog + logRecord.StringOffset;
            file.seekg(readCursor);
            wstring buffString;
            vector<wstring> allStrings;
            //Reading all the strings
            for(int i=0; i< logRecord.NumStrings; i++) {
                file.read((char*)&buffData,sizeof(wchar_t));
                while(buffData!=_T('\0')){
                    buffString.push_back(buffData);
                    file.read((char*)&buffData,sizeof(wchar_t));
                }
                allStrings.push_back(buffString);
                buffString.clear();
            }

            //Sets the position to the Data offset
            readCursor = startOfLog + logRecord.DataOffset;
            file.seekg(readCursor);
            unsigned char *Data = (unsigned char *)malloc(logRecord.DataLength*sizeof(unsigned char));
            file.read((char*)Data,logRecord.DataLength); //Lecture des données

            //Sets the position to the end of log offset
            readCursor = startOfLog + logRecord.Length - sizeof(DWORD) ;
            file.seekg(readCursor);
            DWORD length;
            file.read((char*)&length,sizeof(DWORD));

            //Do what you want with the log record

            //Clean before reading next log
            ComputerName.clear();
            SourceName.clear();
            allStrings.clear();
            free(Data);
    }
}
}
#包括
#包括
使用名称空间std;
typedef无符号长ULONG;
类型定义结构\u事件日志头{
乌龙中学;
乌龙签名;
乌龙大版本;
乌龙寺;
乌隆斯塔夫赛特;
乌隆内偏移;
ULONG CurrentRecordNumber;
ULONG Oldestrecordenumber;
ULONG MaxSize;
乌龙旗;
乌龙保留;
乌龙EndHeaderSize;
}EVENTLOGHEADER,*PEVENTLOGHEADER;
typedef无符号长双字;
typedef无符号短字;
类型定义结构\u事件日志记录{
德沃德长度;
德沃德保留;
德沃德记录号码;
德沃德时间生成;
德沃德时间书写;
德沃德·埃文蒂德;
单词事件类型;
单词NumStrings;
词类;
字保留延迟;
DWORD ClosingRecordNumber;
德沃德;
德沃德长度;
德沃德;
DWORD数据长度;
DWORD数据偏移量;
}事件日志记录,*PEVENTLOGRECORD;
void main()
{
ifstream文件;
打开(“C:\Windows\System32\winevt\Logs\\Application.evtx”,ios::in | ios::binary);
if(file.is_open()){
_事件日志头日志头;
_事件日志记录;
//阅读标题
read((char*)&logheader,sizeof(_EVENTLOGHEADER));
int startOfLog;
//在每条记录上循环
for(unsigned int numberFile=0;numberFile
宏是在
Tchar.h
中定义的,因此您似乎只需要包含该头


这就是说,您似乎没有编写可以同时编译ANSI和Unicode的代码,因此停止使用
TCHAR
,并在宽字符前面加上
L
,而不是编写
\u t('\0')
write
L'\0'
,甚至只是简单的旧
0

\u
是一种特定于Windows的方法,可以根据项目设置指定窄字符常量/字符串文字,也可以指定宽字符常量/字符串文字。它需要适当的
\include
指令,这些指令在项目中不存在你的代码,它不是编译器定义的宏


但是,您不需要它。您在
while(buffData!=\u t('\0')中使用它
,但是
buffData
具有类型
wchar\u t
,与项目设置无关。在这种情况下,只需使用宽字符常量:
L'\0'

在C中不完全重写它是不可能的。您应该指定正在使用的编译器和环境。如何在C@g-makulik中编写它。实际上想读取evt吗仅使用c语言的x文件取决于很多事情如何做到这一点。应该使用哪种API等等。我也不认为有什么好的理由重新编写