宇郑 发表于 2024-1-17 18:50

强制签名CRC内存无视日期【人工智能第一章】

// 强制签名CRC内存无视日期

#include <iostream>
#include <string>
#include <windows.h>
//-----------------------------------------------------------------------------
using namespace std;

//-----------------------------------------------------------------------------
class CRC32
{
public:
    CRC32()
    {
      m_ulCRC = 0xFFFFFFFF;
    }

    void Add( const void *pData, int nSize )
    {
      const unsigned char *p = (const unsigned char *)pData;
      while( nSize-- )
            m_ulCRC = m_aulCRCTable[(m_ulCRC ^ *p++) & 0xFF] ^ (m_ulCRC >> 8);
    }

    unsigned int Get() { return ~m_ulCRC; }

private:
    unsigned int m_aulCRCTable[256], m_ulCRC;

    CRC32( const CRC32 & );
    CRC32 &operator=( const CRC32 & );
};
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
    if( argc < 2 )
    {
      cout << "Usage: " << argv[0] << " filename" << endl;
      return 0;
    }

    HANDLE hFile = CreateFile( argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if( hFile == INVALID_HANDLE_VALUE )
    {
      cout << "Cannot open file " << argv[1] << endl;
      return 0;
    }

    LARGE_INTEGER liFileSize;
    if( !GetFileSizeEx( hFile, &liFileSize ) )
    {
      cout << "Cannot query file size" << endl;
      return 0;
    }

    CRC32 crc;
    char *pBuf = new char[liFileSize.QuadPart];
    DWORD dwRead;
    if( ReadFile( hFile, pBuf, liFileSize.QuadPart, &dwRead, NULL ) && dwRead == liFileSize.QuadPart )
      crc.Update( pBuf, liFileSize.QuadPart );

    delete [] pBuf;
    CloseHandle( hFile );

    cout << hex << uppercase << crc.Get() << endl;

    return 0;
}


lies 发表于 2024-1-17 23:24

谢谢分享!

525293680 发表于 2024-4-17 09:59

啊 这是什么啊
页: [1]
查看完整版本: 强制签名CRC内存无视日期【人工智能第一章】