SHARE
TWEET

Untitled

a guest Nov 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7.     const size_t int_len = 4;
  8.     HANDLE input_file = CreateFile(
  9.         argv[1],
  10.         GENERIC_READ,
  11.         FILE_SHARE_READ,
  12.         NULL,
  13.         OPEN_EXISTING,
  14.         FILE_ATTRIBUTE_NORMAL,
  15.         0);
  16.  
  17.     DWORD file_size = GetFIleSize(input_file, NULL);
  18.     if (file_size == 0) {
  19.         goto finally_ok;
  20.     }
  21.     DWORD next_position = 0;
  22.     int value = 0;
  23.     bool is_ok = TRUE;
  24.     is_ok = ReadFile(input_file, &value, sizeof(int), NULL, NULL);
  25.     if (!is_ok) {
  26.         goto finally_err;
  27.     }
  28.     printf("%d ", value);
  29.     bool info_read =
  30.         ReadFile(input_file, &next_position, sizeof(DWORD), NULL, NULL);
  31.     if (!info_read) {
  32.         goto finally_err;
  33.     }
  34.     while (next_position != 0) {
  35.         SetFilePointer(input_file, next_position, NULL, FILE_BEGIN);
  36.         ReadFile(input_file, &value, sizeof(int), NULL, NULL);
  37.  
  38.         printf("%d ", value);
  39.  
  40.         ReadFile(input_file, &next_position, sizeof(DWORD), NULL, NULL);
  41.     }
  42.     goto finally_ok;
  43.  
  44. finally_err:
  45.     CloseHandle(input_file);
  46.     return 1;
  47.  
  48. finally_ok:
  49.     CloseHandle(input_file);
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top