Advertisement
Lexolordan

Untitled

Nov 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdint.h>
  6.  
  7. union value {
  8.     int i32;
  9.     char buffer[4];
  10. } value;
  11.  
  12. union next_pointer {
  13.     uint32_t ui32;
  14.     char buffer[4];
  15. } next_pointer;
  16.  
  17. int main(int argc, char **argv) {
  18.     HANDLE in = CreateFileA(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  19.  
  20.     BOOL result;
  21.     DWORD counts;
  22.     result = ReadFile(in, &value.buffer, sizeof(value.buffer), &counts, NULL);
  23.     if (!result || counts != sizeof(value.buffer)) {
  24.         goto finally;
  25.     }
  26.     result = ReadFile(in, &next_pointer.buffer, sizeof(next_pointer.buffer), &counts, NULL);
  27.     if (!result || counts != sizeof(next_pointer.buffer)) {
  28.         goto finally;
  29.     }
  30.  
  31.     printf("%d ", value.i32);
  32.     LARGE_INTEGER pointer;
  33.     while (next_pointer.ui32 != 0) {
  34.         pointer.QuadPart = next_pointer.ui32;
  35.         result = SetFilePointerEx(in, pointer, NULL, FILE_BEGIN);
  36.         if (!result) {
  37.             goto finally;
  38.         }
  39.  
  40.         result = ReadFile(in, &value.buffer, sizeof(value.buffer), &counts, NULL);
  41.         if (!result || counts != sizeof(value.buffer)) {
  42.             goto finally;
  43.         }
  44.         result = ReadFile(in, &next_pointer.buffer, sizeof(next_pointer.buffer), &counts, NULL);
  45.         if (!result || counts != sizeof(next_pointer.buffer)) {
  46.             goto finally;
  47.         }
  48.         printf("%d ", value.i32);
  49.     }
  50. finally:
  51.     CloseHandle(in);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement