/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 FsInformationClass; UINT32 Length; Stream_Read_UINT32(irp->input, FsInformationClass); Stream_Read_UINT32(irp->input, Length); Stream_Seek(irp->input, 24); /* Padding */ file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; } else if (!drive_file_set_information(file, FsInformationClass, Length, irp->input)) { irp->IoStatus = STATUS_UNSUCCESSFUL; } if (file && file->is_dir && !dir_empty(file->fullpath)) irp->IoStatus = STATUS_DIRECTORY_NOT_EMPTY; Stream_Write_UINT32(irp->output, Length); return irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_write(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); Stream_Seek(irp->input, 20); /* Padding */ file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_write(file, Stream_Pointer(irp->input), Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } Stream_Write_UINT32(irp->output, Length); Stream_Write_UINT8(irp->output, 0); /* Padding */ return irp->Complete(irp); }
static void drive_process_irp_set_information(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; UINT32 FsInformationClass; UINT32 Length; stream_read_UINT32(irp->input, FsInformationClass); stream_read_UINT32(irp->input, Length); stream_seek(irp->input, 24); /* Padding */ file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_set_information(file, FsInformationClass, Length, irp->input)) { irp->IoStatus = STATUS_UNSUCCESSFUL; DEBUG_WARN("FsInformationClass %d on %s(%d) failed.", FsInformationClass, file->fullpath, file->id); } else { DEBUG_SVC("FsInformationClass %d on %s(%d) ok.", FsInformationClass, file->fullpath, file->id); } stream_write_UINT32(irp->output, Length); irp->Complete(irp); }
static void drive_process_irp_set_information(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 FsInformationClass; UINT32 Length; Stream_Read_UINT32(irp->input, FsInformationClass); Stream_Read_UINT32(irp->input, Length); Stream_Seek(irp->input, 24); /* Padding */ file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; } else if (!drive_file_set_information(file, FsInformationClass, Length, irp->input)) { irp->IoStatus = STATUS_UNSUCCESSFUL; } else { } Stream_Write_UINT32(irp->output, Length); irp->Complete(irp); }
static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("seek %s(%d) failed.", file->fullpath, file->id); } else { buffer = (BYTE*) malloc(Length); if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; DEBUG_WARN("read %s(%d) failed.", file->fullpath, file->id); } else { DEBUG_SVC("read %llu-%llu from %s(%d).", Offset, Offset + Length, file->fullpath, file->id); } } stream_write_UINT32(irp->output, Length); if (Length > 0) { stream_check_size(irp->output, (int) Length); stream_write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else { buffer = (BYTE*) malloc(Length); if (!buffer) { WLog_ERR(TAG, "malloc failed!"); return CHANNEL_RC_OK; } if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { if (!Stream_EnsureRemainingCapacity(irp->output, (int) Length)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); return ERROR_INTERNAL_ERROR; } Stream_Write(irp->output, buffer, Length); } free(buffer); return irp->Complete(irp); }
static void drive_process_irp_read(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; BYTE* buffer = NULL; Stream_Read_UINT32(irp->input, Length); Stream_Read_UINT64(irp->input, Offset); file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; } else { buffer = (BYTE*) malloc(Length); if (!drive_file_read(file, buffer, &Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; free(buffer); buffer = NULL; Length = 0; } else { } } Stream_Write_UINT32(irp->output, Length); if (Length > 0) { Stream_EnsureRemainingCapacity(irp->output, (int) Length); Stream_Write(irp->output, buffer, Length); } free(buffer); irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_query_information(DRIVE_DEVICE* drive, IRP* irp) { DRIVE_FILE* file; UINT32 FsInformationClass; Stream_Read_UINT32(irp->input, FsInformationClass); file = drive_get_file_by_id(drive, irp->FileId); if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; } else if (!drive_file_query_information(file, FsInformationClass, irp->output)) { irp->IoStatus = STATUS_UNSUCCESSFUL; } return irp->Complete(irp); }
static void drive_process_irp_write(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; UINT32 Length; UINT64 Offset; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_seek(file, Offset)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("seek %s(%d) failed.", file->fullpath, file->id); } else if (!drive_file_write(file, stream_get_tail(irp->input), Length)) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; DEBUG_WARN("write %s(%d) failed.", file->fullpath, file->id); } else { DEBUG_SVC("write %llu-%llu to %s(%d).", Offset, Offset + Length, file->fullpath, file->id); } stream_write_UINT32(irp->output, Length); stream_write_BYTE(irp->output, 0); /* Padding */ irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_close(DRIVE_DEVICE* drive, IRP* irp) { void* key; DRIVE_FILE* file; file = drive_get_file_by_id(drive, irp->FileId); key = (void*)(size_t) irp->FileId; if (!file) { irp->IoStatus = STATUS_UNSUCCESSFUL; } else { ListDictionary_Remove(drive->files, key); drive_file_free(file); } Stream_Zero(irp->output, 5); /* Padding(5) */ return irp->Complete(irp); }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT drive_process_irp_query_directory(DRIVE_DEVICE* drive, IRP* irp) { char* path = NULL; int status; DRIVE_FILE* file; BYTE InitialQuery; UINT32 PathLength; UINT32 FsInformationClass; Stream_Read_UINT32(irp->input, FsInformationClass); Stream_Read_UINT8(irp->input, InitialQuery); Stream_Read_UINT32(irp->input, PathLength); Stream_Seek(irp->input, 23); /* Padding */ status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input), PathLength / 2, &path, 0, NULL, NULL); if (status < 1) if (!(path = (char*) calloc(1, 1))) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } file = drive_get_file_by_id(drive, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; Stream_Write_UINT32(irp->output, 0); /* Length */ } else if (!drive_file_query_directory(file, FsInformationClass, InitialQuery, path, irp->output)) { irp->IoStatus = STATUS_NO_MORE_FILES; } free(path); return irp->Complete(irp); }
static void drive_process_irp_query_directory(DRIVE_DEVICE* disk, IRP* irp) { char* path; int status; DRIVE_FILE* file; BYTE InitialQuery; UINT32 PathLength; UINT32 FsInformationClass; stream_read_UINT32(irp->input, FsInformationClass); stream_read_BYTE(irp->input, InitialQuery); stream_read_UINT32(irp->input, PathLength); stream_seek(irp->input, 23); /* Padding */ status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(irp->input), PathLength / 2, &path, 0, NULL, NULL); if (status < 1) path = (char*) calloc(1, 1); file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; stream_write_UINT32(irp->output, 0); /* Length */ DEBUG_WARN("FileId %d not valid.", irp->FileId); } else if (!drive_file_query_directory(file, FsInformationClass, InitialQuery, path, irp->output)) { irp->IoStatus = STATUS_NO_MORE_FILES; } free(path); irp->Complete(irp); }
static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp) { DRIVE_FILE* file; file = drive_get_file_by_id(disk, irp->FileId); if (file == NULL) { irp->IoStatus = STATUS_UNSUCCESSFUL; DEBUG_WARN("FileId %d not valid.", irp->FileId); } else { DEBUG_SVC("%s(%d) closed.", file->fullpath, file->id); list_remove(disk->files, file); drive_file_free(file); } stream_write_zero(irp->output, 5); /* Padding(5) */ irp->Complete(irp); }