NVbit : Accessing Bitlocker volumes from linux.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

99 lines
2.2KB

  1. /*
  2. nvbit Bitlocker for linux
  3. ------------------------------
  4. Nitin Kumar nitin at nvlabs.in
  5. Vipin Kumar vipin at nvlabs.in
  6. web: http://www.nvlabs.in
  7. Licensed under GPL Version 3
  8. -------------------
  9. Copyright (c) 2008
  10. Released under the GPL Version 3
  11. http://www.gnu.org/licenses/gpl-3.0.txt
  12. */
  13. #include "common.h"
  14. #include "FVE.h"
  15. #include "vmk.h"
  16. #include "interface.h"
  17. #include <malloc.h>
  18. #include <stdio.h>
  19. /* This function opens the file and returns an interface object]
  20. */
  21. Interface* InitializeInputInterface(char *input)
  22. {
  23. Interface* input_interface = malloc( sizeof(Interface));
  24. input_interface->stream = fopen(input,"rb");
  25. // if file could not be opened return NULL
  26. if( input_interface->stream == NULL) {
  27. free( input_interface);
  28. printf("File %s could not be opened",input);
  29. exit(1);
  30. }
  31. input_interface->SectorSize = 512; // init default sector size is this still the most common size ??
  32. return input_interface;
  33. }
  34. int custom_fseek( FILE * stream, int64 offset, int origin )
  35. {
  36. int error_code;
  37. #ifdef WIN32
  38. #ifdef MSVC6 // msvc doesn't have 64 bit seek support
  39. error_code = fseek( stream , offset, origin);
  40. #else
  41. error_code = _fseeki64( stream , offset, origin);
  42. #endif
  43. #else
  44. error_code= fseek( stream , offset, origin);
  45. #endif
  46. return error_code;
  47. }
  48. /* this funtion will read one sector at a time from interface, and put it in buffer
  49. however, it is responsibility of user to check the size of buffer for overflows
  50. */
  51. int32 Read_Sector( Interface *input_interface, int64 SectorNumber, int32 SectorCount, int8 * Buffer)
  52. {
  53. int64 offset;
  54. offset = SectorNumber * input_interface->SectorSize ;
  55. // first do a seek to get to position and then grab the data
  56. #ifdef WIN32
  57. #ifdef MSVC6 // msvc doesn't have 64 bit seek support
  58. fseek( input_interface->stream , offset, SEEK_SET);
  59. #else
  60. _fseeki64( input_interface->stream , offset, SEEK_SET);
  61. #endif
  62. #else
  63. fseek( input_interface->stream , offset, SEEK_SET);
  64. #endif
  65. fseek( input_interface->stream , offset, SEEK_SET);
  66. return fread(Buffer,sizeof(int8) ,input_interface->SectorSize * SectorCount,input_interface->stream) ;
  67. }