设为首页 加入收藏

TOP

CRC32 逆向算法的C语言实现
2014-11-24 08:29:42 来源: 作者: 【 】 浏览:0
Tags:CRC32 逆向 算法 语言 实现

CRC32:


CRC32校验应用很广泛。本文提供一种算法添加4个字节实现任意的crc32校验值转换,逆向计算crc32的值。可以随意修改文件任意4个字节实现任意的crc32校验值。


原理:


下面是一组CRC32计算过程:


添加了四个字节00ba ff 30, 原crc32值2be0dd1d变成eee8a9a6。


src32val:2be0dd1d ^ 00 -->x=1d


src32val:002be0dd ^


T(x) : 63066cd9


src32val:632d8c04 (现在计算的CRC值)


src32val:632d8c04 ^ 00-->x=04 x[4]


src32val:00632d8c ^


T(x) : 076dc419


src32val:070ee995


src32val:070ee995 ^ ba-->x=2f x[3]


src32val:00070ee9 ^


T(x) : abd13d59


src32val:abd633b0


src32val:abd633b0 ^ ff-->x=4f x[1]


src32val:00abd633 ^


T(x) : e6635c01


src32val:e6c88a32


src32val:e6c88a32 ^ 30-->x=02 x[0]


src32val:00e6c88a ^


T(x) : ee0e612c tx


src32val:eee8a9a6 (添加4个字节后的目标CRC值)


事实上,crc32的table里256个元素的最高位是唯一的。


可以通过crc32值倒推前四个crctable值,如图绿色部分。


1.由最终的crc值推导出前4个T(x)值,即:T(x) x 已知。


2.由原CRC32值结合x值,推导出4个所要添加的未知字节。


以下是C语言的一个实现:


程序输出:


头文件:


//==========================================================================
//
// crc.h
//
// Interface for the CRC algorithms.
//==========================================================================


#ifndef __CRC32_H__
#define __CRC32_H__


// Gary S. Brown's 32 bit CRC


unsigned int cyg_crc32(unsigned char *s, int len);


// Gary S. Brown's 32 bit CRC, but accumulate the result from a
// previous CRC calculation


unsigned int cyg_crc32_accumulate(unsigned int crc, unsigned char *s, int len);


// Ethernet FCS Algorithm


unsigned int cyg_ether_crc32(unsigned char *s, int len);


// Ethernet FCS algorithm, but accumulate the result from a previous
// CRC calculation.


unsigned int cyg_ether_crc32_accumulate(unsigned int crc, unsigned char *s,
int len);


/**
* add 4 bytes num[4] to change crc32 value from crc_src to crc_dst
* @return: 0 on success, -1 on error.
*/
int cyg_crc32_change(unsigned int crc_dst, unsigned int crc_src, uint8_t num[4]);


/**
* cyg_crc32_reserve - reserve CRC32 value by dropping data[len]
* @return: return the CRC value before data[len]
*/
unsigned int cyg_crc32_reserve(unsigned int crc, void *data, int len);


#endif // __CRC32_H__


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇使用SWIG将C/C++库移植到其他语言.. 下一篇在OpenSSL 0.9.7c 下找不到 SHA51..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)
·关于 MySQL 数据库学 (2025-12-26 23:20:16)
·SOLVED: Ubuntu 24.0 (2025-12-26 22:51:53)
·Linux 常用命令最全 (2025-12-26 22:51:50)