示例#1
0
/*
 * Returns the SHA1 hash for a specified file path
 *
 * req: TLV_TYPE_FILE_PATH - The file path that is to be stat'd
 */
DWORD request_fs_sha1(Remote *remote, Packet *packet)
{
	Packet *response = packet_create_response(packet);
	char *filePath;
	DWORD result = ERROR_SUCCESS;
	SHA_CTX context;

	FILE *fd;
	size_t ret;
	unsigned char buff[16384];
	unsigned char hash[SHA_DIGEST_LENGTH];

	filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);

	result = fs_fopen(filePath, "rb", &fd);
	if (result == ERROR_SUCCESS) {
		SHA1_Init(&context);

		while ((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) {
			SHA1_Update(&context, buff, ret);
		}

		fclose(fd);
		SHA1_Final(hash, &context);

		packet_add_tlv_raw(response, TLV_TYPE_FILE_HASH, hash, sizeof(hash));
	}

	return packet_transmit_response(result, remote, response);
}
示例#2
0
void fs_uae_read_custom_uae_options(int argc, char **argv) {
	fs_log("read_custom_uae_options\n");
    if (g_fs_uae_config_file_path) {
        FILE *f = fs_fopen(g_fs_uae_config_file_path, "rb");
		read_custom_uae_options_from_file(f);
        fclose(f);
    }

    for (int i = 0; i < argc; i++) {
        char *arg = argv[i];
        if (!fs_str_has_prefix(arg, "--")) {
            continue;
        }
        char *key = arg + 2;
        char *value = strchr(arg, '=');
        if (value) {
            char *k = fs_strndup(key, value - key);
            fs_strdelimit (k, "-", '_');
            char *v = fs_strdup(value + 1);
            char *key_lower = fs_ascii_strdown(k, -1);
            free(k);
            parse_option(key_lower, v);
            free(key_lower);
            free(v);
        }
    }
}
示例#3
0
/*
 * Returns the MD5 hash for a specified file path
 *
 * req: TLV_TYPE_FILE_PATH - The file path that is to be stat'd
 */
DWORD request_fs_md5(Remote *remote, Packet *packet)
{
	Packet *response = packet_create_response(packet);
	char *filePath;
	DWORD result = ERROR_SUCCESS;
	MD5_CTX context;

	FILE *fd;
	size_t ret;
	unsigned char buff[16384];
	unsigned char hash[MD5_DIGEST_LENGTH + 1] = {0};

	filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);

	result = fs_fopen(filePath, "rb", &fd);
	if (result == ERROR_SUCCESS) {

		MD5_Init(&context);

		while ((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) {
			MD5_Update(&context, buff, ret);
		}

		MD5_Final(hash, &context);

		packet_add_tlv_raw(response, TLV_TYPE_FILE_NAME, hash, sizeof(hash));

		fclose(fd);
	}

	packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
	return PACKET_TRANSMIT(remote, response, NULL);
}
示例#4
0
//ethan_20110801_add
ER Cal_SaveAWBGS(void)
{
    ER ercode = 0;
    FLGPTN  uiFlag = 0;
    HNVT_FILE *pFile;
    Cal_ClearOSD(_OSD_INDEX_TRANSPART);

    if(AAA_Adjust.AWB_Status == _AWB_Status)
    {
        AAA_Adjust.AWBGS_Status = _AWB_Status;
        AAA_Adjust.AWBGS.Rgain = AAA_Adjust.AWB.Rgain;
        AAA_Adjust.AWBGS.Bgain = AAA_Adjust.AWB.Bgain;
        sprintf(CalStringBuffer,"AWB GS: Rgain:%d Bgain:%d",AAA_Adjust.AWBGS.Rgain,AAA_Adjust.AWBGS.Bgain);
        Cal_ShowStringWithColor(CalStringBuffer,20, 100, 4);
        ercode =  E_OK;
    }
    else
        ercode =  E_SYS;
    sprintf(CalStringBuffer,"Press SHUTTER to return");
    Cal_ShowStringWithColor(CalStringBuffer,20, 120, 4);

    if(ercode == E_OK)
    {
        FilesysWaitCmdFinish(FST_TIME_INFINITE);
        pFile = fs_fopen("A:\\AWBGS.txt","w");
        if(pFile == NULL)
        {
            sprintf(CalStringBuffer, "create  AWBGS.txt fail");
            Cal_ShowStringWithColor(CalStringBuffer,20, 40, 4);
            TimerDelayMs(2000);
        }
        else
        {
            sprintf(CalStringBuffer, "%d %d",AAA_Adjust.AWBGS.Rgain,AAA_Adjust.AWBGS.Bgain);
            fs_fwrite(CalStringBuffer, 1, 7, pFile);
            fs_fclose(pFile);
            g_CalStringRect.uiLeft    = 20;
            g_CalStringRect.uiTop     = 200;
            g_CalStringRect.uiWidth   = 300;
            g_CalStringRect.uiHeight  = 30;
            sprintf(CalStringBuffer, "AWBGS.txt OK");
            Cal_ShowStringWithColor(CalStringBuffer,20, 40, 4);
            TimerDelayMs(2000);
        }

        Cal_WriteCalData(PSTORE_SEC_SENSOR);
    }
    clr_flg(FLG_ID_KEY, FLGKEY_SHUTTER2);
    wai_flg(&uiFlag, FLG_ID_KEY, FLGKEY_SHUTTER2, TWF_ORW | TWF_CLR);
    return ercode;
}
示例#5
0
FILE *fsdb_open_meta_file_for_path(const char *path, const char *mode,
        int always_open) {
    char *meta_file = fs_strconcat(path, ".uaem", NULL);
    if (g_fsdb_debug) {
        write_log("opening meta file %s mode %s\n", meta_file, mode);
    }
    if (!always_open) {
        if (!fs_path_exists(meta_file)) {
            if (g_fsdb_debug) {
                write_log("- didn't exist, don't force open\n");
            }
            return NULL;
        }
    }
    FILE *f = fs_fopen(meta_file, mode);
    if (g_fsdb_debug) {
        write_log("FILE is %p\n", f);
    }
    free(meta_file);
    return f;
}
示例#6
0
FILE *uae_fopen(const char *path, const char *mode) {
    char *p = uae_expand_path(path);
    FILE *f = fs_fopen(p, mode);
    free(p);
    return f;
}
示例#7
0
文件: file.c 项目: 12019/YCOS
uint16 as_select(asgard_handle * handle, uint16 fid) {
	fs_file * cur_file = NULL;
	fs_file * root = NULL;
#if USE_ENTRY_STACK
	if(handle->stack_index > 2 && handle->stack_index <=8) {
		cur_file = handle->stack[handle->stack_index -2];				//check for parent
		if(cur_file != NULL) {
			if(cur_file->entry.fid == fid) {
				as_pop(handle);											//freed current file
				goto as_select_finished;
			}
		}
	}
	cur_file = fs_fopen(as_peek(handle), fid, handle->mode);			//select child
	as_select_finished:
	if(cur_file != NULL) {
		as_push(handle, cur_file);
		return APDU_SUCCESS_RESPONSE;
	}
	cur_file = as_peek(handle);
	if(cur_file != NULL && (file->entry.type & FS_TYPE_DIR)) {			//entry exist and type directory
		as_push(handle, NULL);											//push no selected file
	}
#else
	//printf("select\n");
	if(fid == FID_MF) {
		root = fs_root(handle->fs);
		if(root == NULL) return APDU_FILE_NOT_FOUND;
		//printf("root : %x\n", root);
		cur_file = fs_fopen(root, FID_MF, handle->mode);
		if(handle->cur_dir != NULL) { free(handle->cur_dir); handle->cur_dir = NULL; }
		if(handle->cur_file != NULL && handle->cur_dir != handle->cur_file) { free(handle->cur_file); handle->cur_file = NULL; }
		handle->cur_dir = cur_file;
		handle->cur_file = cur_file;
		free(root);													//prevent memory leakage
		if(cur_file != NULL) return APDU_SUCCESS_RESPONSE;				//selection successful
	}
	if(handle->cur_dir != NULL && fid == handle->cur_dir->entry.fid) return APDU_SUCCESS_RESPONSE;
	if(handle->cur_file != NULL && fid == handle->cur_file->entry.fid) return APDU_SUCCESS_RESPONSE;
	//m_mem_dump();
	//printf("select : %x\n", handle->cur_dir->entry.fid);
	//printf("handle->cur_dir : %x\n", handle->cur_dir);
	cur_file = fs_fopen(handle->cur_dir, fid, handle->mode);
	//if(cur_file == NULL) printf("file not found\n");
	//getch();
	if(cur_file == NULL) return APDU_FILE_NOT_FOUND;
	if(cur_file->entry.type & FS_TYPE_DIR) {						//type is directory
		//printf("handle is directory\n");
		if(handle->cur_dir != NULL) { free(handle->cur_dir); handle->cur_dir = NULL; }
		if(handle->cur_file != NULL && handle->cur_dir != handle->cur_file) { free(handle->cur_file); handle->cur_file = NULL; }
		handle->cur_dir = cur_file;
		handle->cur_file = cur_file;
		//getch();
		if(cur_file != NULL) return APDU_SUCCESS_RESPONSE;			//selection successful
	} else {														//type is file
		//if(handle->cur_dir != NULL) { free(handle->cur_dir); handle->cur_dir = NULL; }
		if(handle->cur_file != NULL && handle->cur_dir != handle->cur_file) { free(handle->cur_file); handle->cur_file = NULL; }
		handle->cur_file = cur_file;
		//getch();
		if(cur_file != NULL) return APDU_SUCCESS_RESPONSE;			//selection successful
	}
#endif
	return APDU_FILE_NOT_FOUND;
}
示例#8
0
/*
 * Handles the open request for a file channel and returns a valid channel
 * identifier to the requestor if the file is opened successfully
 */
DWORD request_fs_file_channel_open(Remote *remote, Packet *packet)
{
	Packet *response = NULL;
	PCHAR filePath, mode;
	DWORD res = ERROR_SUCCESS;
	DWORD flags = 0;
	Channel *newChannel = NULL;
	PoolChannelOps chops = { 0 };
	FileContext *ctx;
	LPSTR expandedFilePath = NULL;

	// Allocate a response
	response = packet_create_response(packet);

	// Get the channel flags
	flags = packet_get_tlv_value_uint(packet, TLV_TYPE_FLAGS);

	// Allocate storage for the file context
	if (!(ctx = calloc(1, sizeof(FileContext)))) {
		res = ERROR_NOT_ENOUGH_MEMORY;
		goto out;
	}

	// Get the file path and the mode
	filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);
	mode     = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_MODE);

	if (mode == NULL) {
		mode = "rb";
	}

	res = fs_fopen(filePath, mode, &ctx->fd);
	if (res != ERROR_SUCCESS) {
		goto out;
	}

	memset(&chops, 0, sizeof(chops));

	// Initialize the pool operation handlers
	chops.native.context = ctx;
	chops.native.write   = file_channel_write;
	chops.native.close   = file_channel_close;
	chops.read           = file_channel_read;
	chops.eof            = file_channel_eof;
	chops.seek           = file_channel_seek;
	chops.tell           = file_channel_tell;

	// Check the response allocation & allocate a un-connected
	// channel
	if ((!response) || (!(newChannel = channel_create_pool(0, flags, &chops)))) {
		res = ERROR_NOT_ENOUGH_MEMORY;
		goto out;
	}

	// Add the channel identifier to the response
	packet_add_tlv_uint(response, TLV_TYPE_CHANNEL_ID, channel_get_id(newChannel));

out:
	// Transmit the packet if it's valid
	packet_transmit_response(res, remote, response);

	// Clean up on failure
	if (res != ERROR_SUCCESS) {
		if (newChannel) {
			channel_destroy(newChannel, NULL);
		}
		free(ctx);
	}

	return res;
}