关于SQL SERVER数据页checksum校验算法整理
发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,SQL SERVER数据页checksum校验算法在SQL SERVER2005以上版本中,数据页默认开启checksum,标识为m_flagBits & 0x200 == True,其值m_torn
千家信息网最后更新 2025年02月23日关于SQL SERVER数据页checksum校验算法整理
SQL SERVER数据页checksum校验算法
在SQL SERVER2005以上版本中,数据页默认开启checksum,标识为m_flagBits & 0x200 == True,其值m_tornBits位于页头0x3C,4字节。
其算法概述如下:
读8KB 进BUF将BUF头部 CHECKSUM的4字节值清0uint32 checksum = 0 //初始checksumfor i in range(0,15): //每扇区的初始checksum overall = 0; for ii in range(0,127): //对当前扇区的每个4字节做累加异或 overall = overall ^ BUF[i][ii]; //对每扇区的checksum进行移位,方法为向左移位15-i位, //左边移出的15-i位补到最低位。 checksum = checksum ^ rol(overall, 15- i); return checksum; //Gets checksum
c源码如下:
//***CODE***//#include #include #define seed 15 //Initial seed(for first sector)#define CHAR_BIT 8 //***PROTOTYPES***//unsigned int page_checksum(int page_id, unsigned int *ondisk);unsigned int rol(unsigned int value, unsigned int rotation);int main(int argc, char *argv[]) { unsigned int computed_checksum; //Var to retrieve calculated checksum unsigned int ondisk_checksum; //Var to retrieve checksum on disk computed_checksum = page_checksum(152, &ondisk_checksum); //page_checksum call to retrieve stored and calculated checksum for page 152 //***PRINTS***// printf("Calculated checksum: 0xx\n", computed_checksum); printf("On disk checksum: 0xx\n", ondisk_checksum);}unsigned int page_checksum(int page_id, unsigned int *ondisk){ FILE *fileptr; unsigned int i; unsigned int j; unsigned int checksum; unsigned int overall; unsigned int *pagebuf[16][128]; //A pointer to describe 2d array [sector][element] fileptr = fopen("C:\\Users\\andre\\Desktop\\teste.mdf", "r+b"); //Open dummy data file for binary read fseek(fileptr, page_id * 8192, SEEK_SET); //Calculate page address on data file and points to it fread(pagebuf, 4, 2048, fileptr); //Read page buffer fclose(fileptr); checksum = 0; overall = 0; *ondisk = pagebuf[0][15]; //This means that torn bits is stored on first sector in 15th element, Internals researches understand this pagebuf[0][15] = 0x00000000; //Fill checksum field with zeroes (this field will be discarded in algorithm) for (i = 0; i < 16; i++) //Loop through sectors { overall = 0; //Reset overall sum for sectors for (j = 0; j < 128; j++) //Loop through elements in sector i { overall = overall ^ (unsigned int)pagebuf[i][j]; //XOR operation between sector i elements } checksum = checksum ^ rol(overall, seed - i); //Current checksum is overall for sector i circular shifted by seed (15 - i) } return checksum; //Gets checksum}unsigned int rol(unsigned int value, unsigned int rotation){ return (value) << (rotation) | (value) >> (sizeof(int) * CHAR_BIT - rotation) & ( (1 << rotation) -1);}
字节
数据
算法
最低
头部
方法
标识
源码
版本
j++
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器主板浪涌
凤阳工业软件开发技术哪家好
软件开发功能分析
陕西云广互联网科技有限公司
网络安全渗透工程师辅警
长电科技互联网
和县天气预报软件开发
教师如何做好网络安全工作
dnf单机版服务器怎么搭建
软件开发项目开发经理职责
mc服务器ip被封怎么办
无线网络技术谁发明的
造物法则服务器
广州 招标 大数据库
湖北招商网络技术有限公司
西安中恺网络技术
计算机网络技术的典型应用
苏州数据库服务推销
erp信息系统软件开发
数据库技术发展有哪五个阶段
学习网络安全需要哪些条件
软件开发难还是复杂
凤阳工业软件开发技术哪家好
在数据库xskc
南京 票务软件开发公司
数据库怎么添加vip
深圳运维服务软件开发多少钱
宁津启明星软件开发部
软件开发专业的当今政策
达梦数据库可以使用下划线