参考:http://www.mouseos.com/assembly/06.html

参考:http://www.cnblogs.com/tk091/archive/2012/04/18/2456174.html

typedef struct CV_INFO_PDB70
{
    DWORD CvSignature;
    GUID Guid;
    DWORD Age;
    //BYTE PdbFileName[];
    char PdbFilePath[MAX_PATH];
} CV_INFO_PDB70_T;

static const DWORD g_dwTimeStamp = 0x52C652E0;

// 一共有3个地方要replace
int _tmain(int argc, _TCHAR* argv[])
{
    if (argc < 3 || _tcscmp(argv[1], _T("-m")) != 0)
    {
        printf("cmdline format err.\n");
        return 0;
    }

_tprintf(_T("---------------\nprocess file %s.\n"), argv[2]);

FILE *fp;
    fp = _tfopen(argv[2], _T("rb+"));
    if (!fp)
    {
        printf("occur error -1,reason:%d\n", errno);
        return -1;
    }

// IMAGE_NT_HEADER address
    LONG e_lfanew;
    fseek(fp, 0x3c, SEEK_SET);
    fread(&e_lfanew, 4, 1, fp);

// Signature
    DWORD sign;
    fseek(fp, e_lfanew, SEEK_SET);
    fread(&sign, 4, 1, fp);
    if (sign != 0x00004550)
    {
        printf("PE header not matched,sign:%x\n---------------\n", sign);
        fclose(fp);
        return -2;
    }

// IMAGE_FILE_HEADER
    IMAGE_FILE_HEADER ifh;
    fseek(fp, e_lfanew + 4, SEEK_SET);
    fread(&ifh, sizeof(IMAGE_FILE_HEADER), 1, fp);

#ifdef _DEBUG
    printf("IMAGE_FILE_HEADER结构:\n");
    printf("Machine       : %04X\n", ifh.Machine);
    printf("NumberOfSections  : %04X\n", ifh.NumberOfSections);
    printf("TimeDateStamp    : %08X\n", ifh.TimeDateStamp);
    printf("PointerToSymbolTable : %08X\n", ifh.PointerToSymbolTable);
    printf("NumberOfSymbols   : %08X\n", ifh.NumberOfSymbols);
    printf("SizeOfOptionalHeader : %04X\n", ifh.SizeOfOptionalHeader);
    printf("Characteristics   : %04X\n", ifh.Characteristics);
    printf("\n");
#endif

// replace timestamp
    _tprintf(_T("replace %s timestamp,old : %08X, new : %08X.\n"), argv[2], ifh.TimeDateStamp, g_dwTimeStamp);
    ifh.TimeDateStamp = g_dwTimeStamp;
    fseek(fp, e_lfanew + 4, SEEK_SET);
    fwrite((void *)&ifh, sizeof(ifh), 1, fp);

// IMAGE_DIRECTORY_ENTRY_DEBUG
    LONG debugEntryAddr = e_lfanew + 4 + sizeof(IMAGE_FILE_HEADER) + ifh.SizeOfOptionalHeader + (-10) * (long)sizeof(IMAGE_DATA_DIRECTORY);
    fseek(fp, debugEntryAddr, SEEK_SET);

// IMAGE_DATA_DIRECTORY
    IMAGE_DATA_DIRECTORY idd;
    fread(&idd, sizeof(IMAGE_DATA_DIRECTORY), 1, fp);

#ifdef _DEBUG
    printf("IMAGE_DIRECTORY_ENTRY_DEBUG结构:\n");
    printf("VirtualAddress : %08X\n", idd.VirtualAddress);
    printf("Size   : %08X\n", idd.Size);
    printf("IMAGE_DEBUG_DIRECTORY一共有%f个\n", 1.0 * idd.Size / sizeof(IMAGE_DEBUG_DIRECTORY));
    printf("\n");
#endif

// check the address valid or not
    if (idd.VirtualAddress == 0x00 || idd.Size == 0x00)
    {
        _tprintf(_T("Debug information not found in file %s, skip modify debug info.\n---------------\n"), argv[2]);
        fclose(fp);
        return 0;
    }

// IMAGE_DEBUG_DIRECTORY
    IMAGE_DEBUG_DIRECTORY idd2;
    fseek(fp, (WORD)idd.VirtualAddress, SEEK_SET); // need convert virtual address
    fread(&idd2, sizeof(IMAGE_DEBUG_DIRECTORY), 1, fp);

#ifdef _DEBUG
    printf("IMAGE_DEBUG_DIRECTORY结构:\n");
    printf("AddressOfRawData : %08X\n", idd2.AddressOfRawData);
    printf("Characteristics : %08X\n", idd2.Characteristics);
    printf("MajorVersion : %08X\n", idd2.MajorVersion);
    printf("MinorVersion : %08X\n", idd2.MinorVersion);
    printf("PointerToRawData : %08X\n", idd2.PointerToRawData);
    printf("SizeOfData : %08X\n", idd2.SizeOfData);
    printf("TimeDateStamp : %08X\n", idd2.TimeDateStamp);
    printf("Type : %08X\n", idd2.Type);
    printf("\n");
#endif

// replace timestamp
    _tprintf(_T("replace pdb timestamp, old : %08X, new : %08X.\n"), idd2.TimeDateStamp, g_dwTimeStamp);
    idd2.TimeDateStamp = g_dwTimeStamp;
    fseek(fp, (WORD)idd.VirtualAddress, SEEK_SET); // need convert virtual address
    fwrite((void *)&idd2, sizeof(idd2), 1, fp);

// CV_INFO_PDB70
    CV_INFO_PDB70_T cvInfo;
    fseek(fp, idd2.PointerToRawData, SEEK_SET);
    fread(&cvInfo, sizeof(CV_INFO_PDB70_T), 1, fp);

#ifdef _DEBUG
    printf("CV_INFO_PDB70结构:\n");
    printf("Age : %04X\n", cvInfo.Age);
    printf("CvSignature : %04X\n", cvInfo.CvSignature);
    printf("PdbFileName : %s\n", cvInfo.PdbFilePath);
    printf("Guid : %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
        cvInfo.Guid.Data1, cvInfo.Guid.Data2, cvInfo.Guid.Data3,
        cvInfo.Guid.Data4[0], cvInfo.Guid.Data4[1], cvInfo.Guid.Data4[2],
        cvInfo.Guid.Data4[3], cvInfo.Guid.Data4[4], cvInfo.Guid.Data4[5],
        cvInfo.Guid.Data4[6], cvInfo.Guid.Data4[7]);
    printf("\n");
#endif

if (cvInfo.CvSignature != 0x53445352)   //RSDS
    {
        printf("pdb signature not matched, CvSignature:%x\n---------------\n", cvInfo.CvSignature);
        fclose(fp);
        return -2;
    }

// replace guid
    printf("replace pdb guid,old : %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
        cvInfo.Guid.Data1, cvInfo.Guid.Data2, cvInfo.Guid.Data3, cvInfo.Guid.Data4[0],
        cvInfo.Guid.Data4[1], cvInfo.Guid.Data4[2], cvInfo.Guid.Data4[3], cvInfo.Guid.Data4[4],
        cvInfo.Guid.Data4[5], cvInfo.Guid.Data4[6], cvInfo.Guid.Data4[7]);
    //_tprintf(_T("replace pdb guid,old : %08X-%04X-%04X-%llX\n"), cvInfo.Guid.Data1, cvInfo.Guid.Data2, cvInfo.Guid.Data3, (__int64)cvInfo.Guid.Data4);
    __int64 tmp = 0xdc38466dca416db1;
    cvInfo.Guid.Data1 = 0xf363bf77;
    cvInfo.Guid.Data2 = 0xb00b;
    cvInfo.Guid.Data3 = 0x4fb0;
    memcpy(&cvInfo.Guid.Data4, &tmp, 8);

//_tprintf(_T("replace pdb guid,new : %08X-%04X-%04X-%llX\n"), cvInfo.Guid.Data1, cvInfo.Guid.Data2, cvInfo.Guid.Data3, tmp);
    printf("replace pdb guid,new : %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
        cvInfo.Guid.Data1, cvInfo.Guid.Data2, cvInfo.Guid.Data3, cvInfo.Guid.Data4[0],
        cvInfo.Guid.Data4[1], cvInfo.Guid.Data4[2], cvInfo.Guid.Data4[3], cvInfo.Guid.Data4[4],
        cvInfo.Guid.Data4[5], cvInfo.Guid.Data4[6], cvInfo.Guid.Data4[7]);
    fseek(fp, idd2.PointerToRawData, SEEK_SET);
    fwrite((void *)&cvInfo, sizeof(cvInfo), 1, fp);

fclose(fp);

printf("---------------\n");
    //system("pause");
    getchar();

return 0;
}

Make the PE file consistent when code not changed的更多相关文章

  1. PE File.

    Figure 1 - PE File The CLR header stores information to indicate that the PE file is a .NET executab ...

  2. Delphi : Analyze PE file headers?

    Analyze PE file headers? { You'll need a OpenDialog to open a Exe-File and a Memo to show the file i ...

  3. Inject shellcode into PE file

    先声明这是不免杀的,只是演示. 哔哩哔哩视频 新增节 一般能实现特定功能的shellcode的长度都比较长,可以分到几个节上的空白区,但是这样麻烦啊,或者把最后一个节扩大,但是最后一个节一般没有执行的 ...

  4. 《Peering Inside the PE: A Tour of the Win32 Portable Executable File Format》阅读笔记二

    Common Sections The .text section is where all general-purpose code emitted by the compiler or assem ...

  5. dnSpy PE format ( Portable Executable File Format)

    Portable Executable File Format PE Format  微软官方的 What is a .PE file in the .NET framework? [closed] ...

  6. PE Header and Export Table for Delphi

    Malware Analysis Tutorial 8: PE Header and Export Table 2. Background Information of PE HeaderAny bi ...

  7. Reverse Core 第二部分 - 13章 - PE文件格式

    @date: 2016/11/24 @author: dlive ​ PE (portable executable) ,它是微软在Unix平台的COFF(Common Object File For ...

  8. 利用PE数据目录的导入表获取函数名及其地址

    PE文件是以64字节的DOS文件头开始的(IMAGE_DOS_HEADER),接着是一段小DOS程序,然后是248字节的 NT文件头(IMAGE_NT_HEADERS),NT的文件头位置由IMAGE_ ...

  9. Load PE from memory(反取证)(未完)

      Article 1:Loading Win32/64 DLLs "manually" without LoadLibrary() The most important step ...

随机推荐

  1. Spring Boot 2.x教程-Thymeleaf 原理是什么

    layout: post title: Spring Boot 2.x教程-Thymeleaf 原理是什么 categories: SpringBoot description: Spring Boo ...

  2. MySQL之正则

    八:正则匹配: 语法: select * from 表名 where 字段名 regexp "正则表达式"; PS:MySQL中正则匹配,不能使用\w等字幕作为匹配

  3. requests库 代理

    import requests proxy = { 'http': '125.123.137.2208:9999' } res = requests.get('http://httpbin.org/i ...

  4. Ollydbg使用问题汇总

    1.可疑的断点 描述:看上去您想在一些命令的中间位置或数据中设置断点. 如果真是这样的话, 这些断点将不会执行并可能严重影响调试的程序. 您真的希望在此设置断点吗? 选择  否 的话还是会出现这个问题 ...

  5. 凤凰系统(Phoenix OS)PC版安装,电脑上体验功能丰富的安卓系统

    PC版(X86版)ISO镜像下载地址:http://www.phoenixos.com/download_x86 下载完成后,可按照官方给出的安装教程进行安装. 凤凰系统帮助中心:http://www ...

  6. Tomcat服务更新流程:

    Tomcat服务更新流程: 1.把需要更新的war包放在服务器/servers/tomcat9/update下.2.负载均衡服务上把要更新的服务器权重值调为0,即服务不转在这台要更新的服务器上.(重要 ...

  7. java 8时间使用LocalDateTime,ZonedDateTime,LocalDate

    前言 java 8的时间已经能够满足日常的使用,也方便理解.joda-time作为一个有优秀的时间组件也不得不告知使用者在java 8以后使用自带的时间 LocalDateTime以及ZonedDat ...

  8. Nacos client 客户端cpu占用100% 问题排查和解决方案

    Nacos version:1.1.3client version:1.0.0 dependency: 'org.springframework.cloud:spring-cloud-alibaba- ...

  9. 敏捷团队协作:Confluence简易教程

      0.Confluence简介 Confluence是一个企业级的Wiki软件,可用于在企业.部门.团队内部进行信息共享和协同编辑. 1.基础概念 Confluence的使用并不复杂,只需掌握如下几 ...

  10. linux服务器上安装jdk8的两种方法

    这里介绍两种安装方式: yum安装(力荐) 从官网下载包安装 获得一台linux服务器 要在linux下安装jdk,首先你得先有一台linux服务器,虚拟机或者租一台都可以   yum安装jdk 在l ...