⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logserv.c

📁 PE Monitor是一个小调试器和反汇编器
💻 C
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  FileName    :   LogServ.c
//  Version     :   1.0
//  Author      :   Luo Cong
//  Date        :   2004-09-02 9:59:19
//  Comment     :   
//
///////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <string.h>
#include "LogServ.h"
#include "Misc.h"

char g_szLogContent[LOG_MAXLENGTH];
char g_szLogFileName[MAX_PATH];

int WriteToLog(
    /* [in] */ const int nLen
)
{
    int nRetResult = 0;
    FILE *fp_out = NULL;

    fp_out = fopen(g_szLogFileName, "w");
    MY_PROCESS_ERROR_WITH_MSG1(fp_out, ErrMsg[ERR_OPEN_LOG_FILE]);

    fwrite(g_szLogContent, 1, nLen, fp_out);

    nRetResult = 1;
Exit0:
    if (fp_out)
    {
        fclose(fp_out);
        fp_out = NULL;
    }
    return nRetResult;
}

int TruncateLogBuff(void)
{
    int nRetResult = 0;
    int nRetCode;
    int nLen = 0;

    nLen = strlen(g_szLogContent);
    if (nLen >= LOG_TRUNCATELEN)
    {
        nRetCode = WriteToLog(LOG_TRUNCATELEN);
        MY_PROCESS_ERROR(nRetCode);
        strcpy(g_szLogContent, g_szLogContent + LOG_TRUNCATELEN);
    }

    nRetResult = 1;
Exit0:
    return nRetResult;
}

int AddToLogTail(
    /* [in] */ const char *szLogContent
)
{
    int nRetResult = 0;
    int nRetCode;

    strcat(g_szLogContent, szLogContent);
    nRetCode = TruncateLogBuff();
    MY_PROCESS_ERROR(nRetCode);

    nRetResult = 1;
Exit0:
    return nRetResult;
}

int InitLogFile(
    /* [in] */ const char *szVirusFileName
)
{
    int nRetResult = 0;

    int nPos;
    char *pDest = NULL;

    pDest = strrchr(szVirusFileName, '.');
    if (!pDest)
        goto Exit0;

    nPos = pDest - szVirusFileName;
    strcpy(g_szLogFileName, szVirusFileName);
    strcpy(&g_szLogFileName[nPos], ".log");

    nRetResult = 1;
Exit0:
    return nRetResult;
}

int FinalizeLogFile()
{
    int nRetResult = 0;
    int nRetCode;
    int nLen = 0;

    nLen = strlen(g_szLogContent);
    if (0 != nLen)
    {
        nRetCode = WriteToLog(nLen);
        MY_PROCESS_ERROR(nRetCode);
    }

    nRetResult = 1;
Exit0:
    return nRetResult;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -