コード例 #1
0
ファイル: libexe_section.c プロジェクト: WilliamMaber/libexe
/* Retrieves the section data file IO handle
 * Returns 1 if successful -1 on error
 */
int libexe_section_get_data_file_io_handle(
     libexe_section_t *section,
     libbfio_handle_t **file_io_handle,
     libcerror_error_t **error )
{
	libexe_section_io_handle_t *io_handle = NULL;
	static char *function                 = "libexe_section_get_data_file_io_handle";

	if( libexe_section_io_handle_initialize(
	     &io_handle,
	     section,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create section file IO handle.",
		 function );

		goto on_error;
	}
	if( libbfio_handle_initialize(
	     file_io_handle,
	     (intptr_t *) io_handle,
	     (int (*)(intptr_t **, libcerror_error_t **)) libexe_section_io_handle_free,
	     (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) libexe_section_io_handle_clone,
	     (int (*)(intptr_t *, int flags, libcerror_error_t **)) libexe_section_io_handle_open,
	     (int (*)(intptr_t *, libcerror_error_t **)) libexe_section_io_handle_close,
	     (ssize_t (*)(intptr_t *, uint8_t *, size_t, libcerror_error_t **)) libexe_section_io_handle_read,
	     (ssize_t (*)(intptr_t *, const uint8_t *, size_t, libcerror_error_t **)) libexe_section_io_handle_write,
	     (off64_t (*)(intptr_t *, off64_t, int, libcerror_error_t **)) libexe_section_io_handle_seek_offset,
	     (int (*)(intptr_t *, libcerror_error_t **)) libexe_section_io_handle_exists,
	     (int (*)(intptr_t *, libcerror_error_t **)) libexe_section_io_handle_is_open,
	     (int (*)(intptr_t *, size64_t *, libcerror_error_t **)) libexe_section_io_handle_get_size,
	     LIBBFIO_FLAG_IO_HANDLE_MANAGED | LIBBFIO_FLAG_IO_HANDLE_CLONE_BY_FUNCTION,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create file IO handle.",
		 function );

		goto on_error;
	}
	return( 1 );

on_error:
	if( io_handle != NULL )
	{
		libexe_section_io_handle_free(
		 &io_handle,
		 NULL );
	}
	return( -1 );
}
コード例 #2
0
/* Initializes the file object IO handle
 * Returns 1 if successful or -1 on error
 */
int pymsiecf_file_object_initialize(
     libbfio_handle_t **handle,
     PyObject *file_object,
     libcerror_error_t **error )
{
	pymsiecf_file_object_io_handle_t *file_object_io_handle = NULL;
	static char *function                                   = "pymsiecf_file_object_initialize";

	if( handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid handle.",
		 function );

		return( -1 );
	}
	if( *handle != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid handle value already set.",
		 function );

		return( -1 );
	}
	if( pymsiecf_file_object_io_handle_initialize(
	     &file_object_io_handle,
	     file_object,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create file object IO handle.",
		 function );

		goto on_error;
	}
	if( libbfio_handle_initialize(
	     handle,
	     (intptr_t *) file_object_io_handle,
	     (int (*)(intptr_t **, libcerror_error_t **)) pymsiecf_file_object_io_handle_free,
	     (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) pymsiecf_file_object_io_handle_clone,
	     (int (*)(intptr_t *, int, libcerror_error_t **)) pymsiecf_file_object_io_handle_open,
	     (int (*)(intptr_t *, libcerror_error_t **)) pymsiecf_file_object_io_handle_close,
	     (ssize_t (*)(intptr_t *, uint8_t *, size_t, libcerror_error_t **)) pymsiecf_file_object_io_handle_read,
	     (ssize_t (*)(intptr_t *, const uint8_t *, size_t, libcerror_error_t **)) pymsiecf_file_object_io_handle_write,
	     (off64_t (*)(intptr_t *, off64_t, int, libcerror_error_t **)) pymsiecf_file_object_io_handle_seek_offset,
	     (int (*)(intptr_t *, libcerror_error_t **)) pymsiecf_file_object_io_handle_exists,
	     (int (*)(intptr_t *, libcerror_error_t **)) pymsiecf_file_object_io_handle_is_open,
	     (int (*)(intptr_t *, size64_t *, libcerror_error_t **)) pymsiecf_file_object_io_handle_get_size,
	     LIBBFIO_FLAG_IO_HANDLE_MANAGED | LIBBFIO_FLAG_IO_HANDLE_CLONE_BY_FUNCTION,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create handle.",
		 function );

		goto on_error;
	}
	return( 1 );

on_error:
	if( file_object_io_handle != NULL )
	{
		pymsiecf_file_object_io_handle_free(
		 &file_object_io_handle,
		 NULL );
	}
	return( -1 );
}