LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-27-2005, 12:09 AM   #1
alphasophie
LQ Newbie
 
Registered: Mar 2005
Posts: 5

Rep: Reputation: 0
SOS,please!!i want to make a checksum of kernel ,but it does't work.


i want to make a checksum of linux kernel ,with the CRC arigorithm.but i didn't work. i 'm confused .
The code is following:
////////////////////////////////////////////////////////////////////////
// the kernel is no matter, i use the kernel at the url:
//ftp://ftp.arca.com.cn/pub/Arca-Products/5Software/2os/linux/v2.4.18/binary/vm-draco
#include <stdio.h>
#include <stdlib.h>
#define KERNEL_SIZE 14911305 //bytes£¬here is the true size of kernel£®
int main(int argc,char *argv[])
{
unsigned char *crc_input=malloc(sizeof(char)*KERNEL_SIZE£«£±);
unsigned long crc_output;
FILE *fp;
int i;
if (!crc_input){
printf("out of memory. \n");
exit(1);
}
//vm-draco is a kernel where is in the url:
//ftp://ftp.arca.com.cn/pub/Arca-Products/5Software/2os/linux/v2.4.18/binary/vm-draco
if((fp=fopen("vm-draco","rb"))==NULL){
printf("Cannot open file. \n");
exit(1);
}
fseek(fp,0,SEEK_SET);
fread(crc_input,sizeof(char),KERNEL_SIZE,fp);
crc_input[KERNEL_SIZE]=0;
fclose(fp);
//crc_input="polynomial";
crc_output=crc32(crc_input,KERNEL_SIZE); // the CRC32 function is in Linux /// source code , not listed here.
printf("the crc_input is : 0x%x \n",crc_input);
printf("the length of crc_input is: %d \n",strlen(crc_input));
printf("the crc_output is :0x%x\n",crc_output);

free(crc_input);
return 0;
}
///////////////////////////////////////////////
but the result is:
the crc_input is : 0x40029008
the length of crc_input is: 7
the crc_output is : 0xa4ae400c

why?
1.why the length of crc_input is 7?
2.i have test the checksum of the kernel in Windows with some checksum tools ,but the CRC checksum is 0x7adfb959.
If my program is wrong ,how can i get the CRC checksum of kernel ???

Thanks a lot .


best regards..

yours alphasophie.
 
Old 03-27-2005, 12:24 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 53
What the hell is stuff like «£± supposed to be? Please use code tags when posting code.
 
Old 03-27-2005, 09:05 AM   #3
alphasophie
LQ Newbie
 
Registered: Mar 2005
Posts: 5

Original Poster
Rep: Reputation: 0
sorry,i don't understand your words completely.
my english is a bit poor.
but i just want to make a checksum of kernel,
perhaps i didn't descripte it clearly.
any advice? your help is needed.

Last edited by alphasophie; 03-27-2005 at 09:14 AM.
 
Old 03-27-2005, 11:17 AM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
presumeably the eighth byte of your kernel image is 0; thus strlen() sees a string of seven bytes.

I don't know what library you found the crc32() function in so I can't tell if you're using it correctly.
 
Old 03-27-2005, 07:48 PM   #5
alphasophie
LQ Newbie
 
Registered: Mar 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by aluser
presumeably the eighth byte of your kernel image is 0; thus strlen() sees a string of seven bytes.

I don't know what library you found the crc32() function in so I can't tell if you're using it correctly.
thanks a lot for your reply,
first,the kernel image indeed contain some ugly chars not shown as ASCII code,perhaps
as you said ,the eighth byte is 0,i am to check it.but how to solve it? The CRC tool can get correct checksum,it should use some correct method to solve the problem,what is it?
second ,the crc32() function is in linux/addon/cipe/crc32.c, i think it is in correct use.
as following:
///////////////////////////////////////////////
// COPYRIGHT (C) 1986 Gary S. Brown.
static unsigned long crc32_tab[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
...........
}
/* Return a 32-bit CRC of the contents of the buffer. */

unsigned long crc32(unsigned char *s, unsigned int len)
{
unsigned int i;
unsigned long crc32val;

crc32val = 0;
for (i = 0; i < len; i ++)
{
crc32val =
crc32_tab[(crc32val ^ s[i]) & 0xff] ^
(crc32val >> 8);
}
return crc32val;
}
/////////////////////////////////////////////

best regards and your help is needed.

Last edited by alphasophie; 03-27-2005 at 07:50 PM.
 
Old 03-28-2005, 05:12 AM   #6
alphasophie
LQ Newbie
 
Registered: Mar 2005
Posts: 5

Original Poster
Rep: Reputation: 0
any advise?
 
Old 03-28-2005, 12:01 PM   #7
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
the only error I see left is that crcinput should be KERNEL_SIZE+1 bytes long, not just KERNEL_SIZE. (I'm assuming the garbled characters in the malloc call aren't a +1..) I don't think this is what's causing your problem though. not sure what is.
 
Old 03-29-2005, 09:37 AM   #8
alphasophie
LQ Newbie
 
Registered: Mar 2005
Posts: 5

Original Poster
Rep: Reputation: 0
thanks a lot ,aluser.
let me try again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot make a custom kernel work dannyk1 Linux - General 5 06-12-2005 07:20 AM
How do I make a change to a current kernel? Would 'make oldconfig' work... jtp51 Slackware 11 11-01-2004 11:02 PM
Cannot make 2.6.* Kernel work! ZephyrXero Linux - Newbie 6 05-21-2004 10:35 PM
DNS need help ? pls help me ! SOS SOS AngelOfTheDamn Linux - Networking 2 02-23-2004 12:13 PM
make limmodem for kernel 2.4.20-8 work on 2.4.22 qwijibow Linux - Hardware 4 11-03-2003 05:16 PM


All times are GMT -5. The time now is 05:25 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration