C/C++教程

反调试--CRC检测

本文主要是介绍反调试--CRC检测,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include"CRC32.h"
#include<Windows.h>
#include<iostream>
using namespace std;
void test1()
{
    int a = 1;
    cout << "1111111111111111111111" << endl;
}
void Crc32Test()
{
    char *buffer=(char*)GetModuleHandleA(0);//参数为0就获取当前进程的句柄
    PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)buffer;
    PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)(pDosHeader->e_lfanew + buffer);
    PIMAGE_SECTION_HEADER pSectionHeader = IMAGE_FIRST_SECTION(pNtHeader);
    for (int i = 0; i < pNtHeader->FileHeader.NumberOfSections - 1; i++)
    {
        if (pSectionHeader->Characteristics / 0x10000000 == 6)
        {
            cout << pSectionHeader->Name << endl;
            auto CrcNum = make_crc((unsigned char*)(pSectionHeader->VirtualAddress + buffer), pSectionHeader->Misc.VirtualSize);
            cout << CrcNum << endl;
        }
        pSectionHeader++;
    }
}
int main()
{
    Crc32Test();
    system("pause");
    return 0;
}

 

 

头文件:

#pragma once
#include<iostream>
uint32_t crc32_table[256];

int make_crc32_table()
{
    uint32_t c;
    int i = 0;
    int bit = 0;

    for (i = 0; i < 256; i++)
    {
        c = (uint32_t)i;

        for (bit = 0; bit < 8; bit++)
        {
            if (c & 1)
            {
                c = (c >> 1) ^ (0xEDB88320);
            }
            else
            {
                c = c >> 1;
            }

        }
        crc32_table[i] = c;
    }

    return 1;
}
uint32_t make_crc(unsigned char* string, uint32_t size)
{
    uint32_t crc = 0xFFFFFFFF;
    make_crc32_table();
    while (size--)
        crc = (crc >> 8) ^ (crc32_table[(crc ^ *string++) & 0xff]);

    return crc;
}

 

这篇关于反调试--CRC检测的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!