📄 misc.c
字号:
close(fd); errno = len; return -1; } hs.br.jmpCode[0]='B'; len = write(fd,&hs,sizeof(hs)); if ( -1 == len ) { len = errno; close(fd); errno = len; return -1; } close(fd); return 0;}int unlock_container(char *name){ struct HiddenSector hs; int fd,len; if ( -1 == (fd = open(name,O_RDWR|O_LARGEFILE)) ) { return -1; } len = read(fd,&hs,sizeof(hs)); if ( -1 == len ) { len = errno; close(fd); errno = len; return -1; } if ( lseek(fd,0,SEEK_SET) < 0 ) { len = errno; close(fd); errno = len; return -1; } hs.br.jmpCode[0]=0xeb; len = write(fd,&hs,sizeof(hs)); if ( -1 == len ) { len = errno; close(fd); errno = len; return -1; } close(fd); return 0; }int GetRandomSeed( char *seed, int seedLength ){ FILE *fd; int i; if ( ! (fd=fopen("/dev/urandom","r")) ) return ERROR_INTERNAL_PROBLEM; for ( i=0; i<seedLength; i++ ) seed[i]=(char)fgetc(fd); fclose (fd); return ERROR_NO;} int get_priv(unsigned long drop_pid){ ALG_SERV Alg; char device[MAX_DEV_PATH]; Alg.bc_fd = open_bc_dev(device,0); if (-1 == Alg.bc_fd) { msg(stderr,"open(%s,O_RDONLY): %s\n",device, strerror(errno)); close(Alg.bc_fd); return -1; } if ( bc_get_priv(Alg,drop_pid)!=0 ) { msg(stderr,"bc_get_priv: %s\n",strerror(errno)); close(Alg.bc_fd); return -1; } close(Alg.bc_fd); return 0;}void usage(FILE *fd){ char *usage_string="Usage:\n\bctool command [options] arguments\n\\n\commands:\n\ new - create container (-a alg_name -s size [-d description] filename)\n\ format - format container ([-t fstype] filename)\n\ mount - mount container ([-t fstype] [-m mode] [-u user] [-g group] [-r] filename mountpoint)\n\ umount - unmount container (mountpoint)\n\ info - get info on container (filename)\n\ passwd - change container's password (filename)\n\ add_passwd - add additional password for container (filename)\n\ del_passwd - delete additional password (filename)\n\ fsck - filesystem check (filename [-t fstype])\n\ reencrypt - reencrypt container (-a alg_name filename)\n\ make_hidden - make hidden part in container (filename size_of_hidden_part)\n\ where: size_of_hidden_part may be xxx - in bytes; xxxK - in Kb; xxxM - in Mb; xx%% - in percents of container size\n\ link - link container to BestCrypt device (filename devicename)\n\ unlink - unlink container from device (devicename)\n\\n\options:\n\ -t fstype - to specify filesystem type (default: msdos)\n\ -a alg_name - to specify algorithm name\n\ -s size - to specify container size\n\ example: -s xxx - in bytes; -s xxxK - in Kb; -s xxxM - in Mb; -s xxxG - in Gb\n\ -d desc - to specify description of container (up to 64 symbols)\n\ -r - to mount read only\n\ -m mode - to specify mountpoint mode in octal (default 0700)\n\ -u user - to specify mountpoint's owner (root only can do it)\n\ -g group - to specify mountpoint's group\n\\n"; msg(fd,usage_string);}/*int check_msdos_partition(int device_fd)reads the first sector of block device;returns first partition offset (sector) if partition table found, zero otherwise*/struct partition { unsigned char active; unsigned char start_head; unsigned char start_sec; unsigned char start_cyl; unsigned char os_type; unsigned char end_head; unsigned char end_sec; unsigned char end_cyl; unsigned int lba_start_sec; unsigned int lba_nr_sec;} __attribute__((packed));unsigned int check_msdos_partition(int device_fd, int *flags){ struct partition *prt; unsigned char *buf; int x[4], i, rc, flg; off_t offset, sz; unsigned int start; *flags = 0; buf = (unsigned char *)malloc(0x200); if (NULL == buf) return 0; sz = lseek64(device_fd, 0, SEEK_END); sz >>= 9; // device size in sectors // rewind to the very beginning offset = 0; offset = lseek64(device_fd, offset, SEEK_SET); if (0 != offset) goto err_out; // read the first sector of device // simply return 'no partition' on // failure rc = read(device_fd, buf, 0x200); if (0x200 != rc) goto err_out; // check msdos partition signature if (0x55 != buf[0x1FE] || 0xAA != buf[0x1FF]) goto err_out; // partition entries offsets are // 0x1BE 0x1CE 0x1DE 0x1EE prt = (struct partition *)(buf+0x1BE); start = 0x0; flg = 0x0000FFFF; for (i = 0; i < 4; i++, prt++) { x[i] = 0; if (0 == prt->lba_nr_sec) continue; // no partition in this slot if (sz < prt->lba_nr_sec + prt->lba_start_sec) goto err_out; flg += 0x01000000; switch (prt->os_type) { case 0x05: // DOS extended case 0x0F: // Windows 95 extended case 0x85: // Linux extended x[i] = -prt->lba_start_sec; flg += 0x00010000; break; default: x[i] = prt->lba_start_sec; if (0 == start || start > prt->lba_start_sec) { start = prt->lba_start_sec; *flags &= 0xFFFF0000; *flags |= i; } } } *flags = flg; return start;err_out: if (NULL != buf) free(buf); return 0;}static void *sha256handle;static void *sha1handle;static void* sha1CreateKeyHandle;static void* sha256CreateKeyHandle;static void* sha1CreateKeyHandleEx;static void* sha256CreateKeyHandleEx;static void* sha1FreeKeyHandle;static void* sha256FreeKeyHandle;static void* sha1FreeDataBlock;static void* sha256FreeDataBlock;/*CreateKeyHandleCreateKeyHandleExFreeKeyHandleFreeDataBlock*/int LoadKeygens(){ char *error; sha1handle = dlopen ("libkgsha.so", RTLD_NOW); if (!sha1handle) { msg (stderr, "%s\n", dlerror()); return -1; } sha256handle = dlopen ("libkgsha256.so", RTLD_NOW); if (!sha256handle) { msg (stderr, "%s\n", dlerror()); return -1; } sha1CreateKeyHandle = dlsym(sha1handle, "CreateKeyHandle"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha1CreateKeyHandleEx = dlsym(sha1handle, "CreateKeyHandleEx"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha1FreeKeyHandle = dlsym(sha1handle, "FreeKeyHandle"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha1FreeDataBlock = dlsym(sha1handle, "FreeDataBlock"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha256CreateKeyHandle = dlsym(sha256handle, "CreateKeyHandle"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha256CreateKeyHandleEx = dlsym(sha256handle, "CreateKeyHandleEx"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha256FreeKeyHandle = dlsym(sha256handle, "FreeKeyHandle"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } sha256FreeDataBlock = dlsym(sha256handle, "FreeDataBlock"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } RandomGenerate = dlsym(sha1handle, "SHA1RandomGenerate"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } RandomGenerateKey = dlsym(sha1handle, "SHA1RandomGenerateKey"); if ((error = dlerror()) != NULL) { msg (stderr, "%s\n", error); return -1; } UseSha1(); return 0;}int UnLoadKeygens(){ dlclose(sha1handle); dlclose(sha256handle); return 0;}int UseSha1(){ CreateKeyHandle = sha1CreateKeyHandle; CreateKeyHandleEx = sha1CreateKeyHandleEx; FreeKeyHandle = sha1FreeKeyHandle; FreeDataBlock = sha1FreeDataBlock; return 0;}int UseSha256(){ CreateKeyHandle = sha256CreateKeyHandle; CreateKeyHandleEx = sha256CreateKeyHandleEx; FreeKeyHandle = sha256FreeKeyHandle; FreeDataBlock = sha256FreeDataBlock; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -