Last active
August 29, 2015 14:07
-
-
Save FedericoPonzi/7609f571740060961d76 to your computer and use it in GitHub Desktop.
File reverser usando le win32api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) | |
{ | |
char s; //buffer | |
HANDLE file; //Handle del file | |
DWORD fileSize; //La dimensione del file | |
LPDWORD lpFileSizeHigh; //In caso la dimensione sia > 2gb | |
file = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, | |
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
if (file == INVALID_HANDLE_VALUE) | |
{ | |
printf("Error opening the file: %x", GetLastError()); | |
return 1; | |
} | |
fileSize = GetFileSize(file, &lpFileSizeHigh); | |
LPVOID lpBuffer = &s; | |
DWORD nBytesToRead, lpnBytesToRead; | |
nBytesToRead = 1; | |
SetFilePointer(file, -1L, NULL, SEEK_END); | |
while (fileSize > 0) | |
{ | |
fileSize--; | |
if (!ReadFile(file, &lpBuffer, nBytesToRead, &lpnBytesToRead, NULL)) { | |
printf("Error on the Read: %d", GetLastError()); | |
return 2; | |
} | |
printf("%c", lpBuffer); | |
SetFilePointer(file, -2L, NULL, SEEK_CUR); | |
} | |
if (!CloseHandle(file)) | |
{ | |
printf("Error, can't close the file: %x", GetLastError()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment