我正在運行程序,其中包括讀取硬盤驅動器ID和以太網MAC ID高級加密標準用來 。:'{'令牌'''',',';','asm'或'__attribute__''{'令牌
當我用命令行編譯程序「gcc -Wall securiti.c -lcrypto」得到編譯錯誤。
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/hdreg.h>
#include <net/if.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/ioctl.h>
#include <openssl/aes.h>
#include <openssl/rand.h>
unsigned char aes(char **argv)
unsigned char* hddid(char *devname);
unsigned char* macid(void);
//unsigned char* xor1(char hdd_id,char mac_id);
unsigned char* char1();
unsigned char* xor(char c,char d);
char destroy(char* argv[]);
int main(int argc, char *argv[])
{
unsigned char *hdd_id;
unsigned char *mac_id;
unsigned char c;
unsigned char d;
unsigned char e;
unsigned char c1;
//unsigned char c2;
unsigned char h;
unsigned char m;
int i,s;
char f;
//remove(argv[0]);
if (geteuid() > 0)
{
printf("ERROR: Must be root to use\n");
exit(1);
}
hdd_id = hddid(argv[1]);
h = hdd_id;
mac_id = macid();
m = mac_id;
printf("\nHard disk Serial Number A:%.20s\n", hdd_id);
printf("\nMac Id B: ");
for(i = 0; i < 6; i++)
printf("%x ", mac_id[i]);
printf("\n");
int j; /*
c = xor1(hdd_id,mac_id);
printf("\nxor of two id's C=%x\n");*/
//for(j = 0;j < 6;j++)
//printf("%x",c[j]);
c = aes(argv[1]);
printf("\n%s",aes);
//printf("\nxor of two ids c=%x\n");
printf("======================");
d = char1();
printf("\nThe value of D=%x\n",d);
printf("--------------------------");
e = xor(c,d);
printf("\nxor of C and D is E=%x\n",e);
printf("----------------------------");
FILE* fp;
fp = fopen("/tmp/mymo.lic", "w");
if (fp == NULL)
{
printf("unable to write into a file.\n");
exit(0);
}
fprintf(fp,"%c",e);
c1 = e-d;
printf("\nvlaue of c1=%x\n",c1);
printf("*****************************");
/* c2 = h + m;
printf("\nvalue of c2=%x\n",c2);
*/
if(c1!=c)
{
printf("\nThe security key is valid\n");
}
else
{
printf("\nThe security key is valid\n");
printf("*****************************\n");
}
printf("*****************************\n");
/*int r;
if(r<=2)
{
printf("Do not run the program more than two times,");
else
remove(argv[0]);
}
//s = destroy(argv[0]);
exit(0);*/
remove(argv[0]);
return 0;
}
char destroy(char *argv[0])
{
int s;
char file_name[10];
printf("Enter the file_name:");
gets(file_name);
s = remove(file_name);
if(s==0)
printf("%s\n",file_name);
return unlink(argv[0]);
remove(argv[0]);
}
//xor function
unsigned char* xor(char c,char d)
{
char z;
z = c^d;
//printf("%x\n",z);
return z;
}
//char1 function
unsigned char* char1()
{
char str[10];
int i=0;
printf("\nEnter a string: ");
scanf("%s",str);
//printf("%s",str[i]);
printf("\nASCII values of given string is D:",str);
while(str[i])
{
printf("%d",str[i++]);
printf("\n");
}
return str;
}
//xor function
/* unsigned char* xor1(char hdd_id,char mac_id)
{
char y;
y = hdd_id^mac_id;
//printf("xor c :%x\n",y);
return y;
}*/
//hddid function
unsigned char* hddid(char *devname)
{
static struct hd_driveid hd;
int fd;
if ((fd = open(devname, O_RDONLY|O_NONBLOCK)) < 0)
{
printf("ERROR: Cannot open device %s\n", devname);
exit(1);
}
if (ioctl(fd, HDIO_GET_IDENTITY, &hd))
{
perror("ERROR: HDIO_GET_IDENTITY");
exit(1);
}
return hd.serial_no;
}
unsigned char* macid(void)
{
struct ifreq ifr;
struct ifconf ifc;
char buf[1024];
int success = 0;
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1)
{
perror("sock:");
}
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1)
{
perror("ioctl:");
}
struct ifreq* it = ifc.ifc_req;
const struct ifreq* const end = it + (ifc.ifc_len/sizeof(struct ifreq));
for (it; it != end; ++it) {
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
success = 1;
break;
}
}
}
else {
perror("ioctl:");
}
}
static unsigned char mac_address[6];
int i;
if (success) memcpy(mac_address, ifr.ifr_hwaddr.sa_data, 6);
return mac_address;
}
unsigned char aes(char **argv)
{
int i;
int keylength;
printf("Give a key length [only 128 or 192 or 256]:\n");
scanf("%d", &keylength);
/* generate a key with a given length */
unsigned char aes_key[keylength];
memset(aes_key, 0, sizeof(aes_key));
if (!RAND_bytes(aes_key, keylength))
{
//printf("girish\n");
exit(-1);
}
aes_key[keylength-1] = '\0';
int inputslength;
printf("Give an input's length:\n");
scanf("%d", &inputslength);
/* generate input with a given length */
unsigned char aes_input[inputslength+1];
memset(aes_input, '0', sizeof(aes_input));
aes_input[inputslength] = '\0';
/*printf("original:\t");
for(i=0; i<inputslength; i++)
{
printf("%c ", aes_input[i]);
}
printf("\n");*/
/* init vector */
unsigned char iv[AES_BLOCK_SIZE];
if (!RAND_bytes(iv, AES_BLOCK_SIZE));
{
exit(-1);
}
//printf("AES_BLOCK_SIZE = %d\n", AES_BLOCK_SIZE);
// aes block size is 16 bytes = 128 bits
AES_KEY enc_key, dec_key;
unsigned char enc_out[AES_BLOCK_SIZE];
unsigned char dec_out[AES_BLOCK_SIZE];
// so i can do with this aes-cbc-128 aes-cbc-192 aes-cbc-256
AES_set_encrypt_key(aes_key, keylength, &enc_key);
AES_cbc_encrypt(aes_input, enc_out, inputslength, &enc_key, iv, AES_ENCRYPT);
printf("girish121\n");
AES_set_decrypt_key(aes_key, keylength, &dec_key);
printf("girish12\n");
AES_decrypt(enc_out, dec_out, &dec_key);
printf("original:\t");
for(i=0;*(aes_input+i)!=0x00;i++)
{
printf("%X ",*(aes_input+i));
//AES_set_decrypt_key(aes_key,keylength,&dec_key);
printf("\nencrypted:\t");
printf("\ng\n");
}
for(i=0;*(enc_out+i)!=0x00;i++)
{
printf("%X ",*(enc_out+i));
printf("\ng1\n");
printf("\ndecrypted:\t");
}
for(i=0;*(dec_out+i)!=0x00;i++)
{
printf("%X ",*(dec_out+i));
printf("\ng3");
printf("\n");
}
return 0;
}
任何人都可以看到這個錯誤。 – 2014-09-22 09:17:22
分號所有的語句? – downhillFromHere 2014-09-22 09:17:52
如果您有關於編譯錯誤的問題,請始終包含** complete **錯誤輸出。 – user694733 2014-09-22 09:18:39