Xbox 360 executable designed to apply freedom-unlocking patches based on xeBuild to the kernel and hypervisor. (Mirrored from https://github.com/FreeMyXe/FreeMyXe)
1/*
2 fs.c
3 from the FreeMyXe project
4 https://github.com/FreeMyXe/FreeMyXe
5*/
6
7#include <xtl.h>
8#include <stdio.h>
9
10int FSFileExists(char *filename)
11{
12 DWORD attr = GetFileAttributesA(filename);
13 DWORD lastError = GetLastError();
14 return !(attr == -1 && (lastError == 2 || lastError == 3 || lastError == 1617));
15}
16
17int FSOpenFile(char *filename)
18{
19 HANDLE handle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
20 if (handle == INVALID_HANDLE_VALUE)
21 return -1;
22 return (int)handle;
23}
24
25int FSFileSize(int file)
26{
27 return GetFileSize((HANDLE)file, NULL);
28}
29
30int FSReadFile(int file, int offset, void *buffer, int size)
31{
32 DWORD readBytes;
33 SetFilePointer((HANDLE)file, offset, NULL, FILE_BEGIN);
34 if (ReadFile((HANDLE)file, buffer, size, &readBytes, NULL) == FALSE)
35 return -1;
36 return readBytes;
37}
38
39void FSCloseFile(int file)
40{
41 XCloseHandle((HANDLE)file);
42}