apply clang-format

This commit is contained in:
Chiharu Shirasaka 2022-01-24 01:52:45 +09:00
parent 3689ee66f7
commit d67326dc8f
6 changed files with 468 additions and 467 deletions

1
.clang-format Normal file
View File

@ -0,0 +1 @@
BasedOnStyle: Microsoft

View File

@ -36,188 +36,198 @@
#include "BrainLILODrv.h" #include "BrainLILODrv.h"
#include <string.h> #include <string.h>
static bool g_initialized=false; static bool g_initialized = false;
static HANDLE g_helperHandle=NULL; static HANDLE g_helperHandle = NULL;
static HINSTANCE g_hInstance; static HINSTANCE g_hInstance;
static void initialize(){ static void initialize()
if(g_initialized) {
if (g_initialized)
return; return;
g_initialized=true; g_initialized = true;
} }
static void getThisDllDirectoryPath(LPWSTR buffer){ static void getThisDllDirectoryPath(LPWSTR buffer)
// retrive the path of the application. {
GetModuleFileName(g_hInstance, buffer, 512); // retrive the path of the application.
GetModuleFileName(g_hInstance, buffer, 512);
const size_t notFound=(size_t)-1; const size_t notFound = (size_t)-1;
size_t i=0; size_t i = 0;
size_t j=notFound; size_t j = notFound;
while(buffer[i]){ while (buffer[i])
if(buffer[i]==L'/' || buffer[i]==L'\\'){ {
j=i; if (buffer[i] == L'/' || buffer[i] == L'\\')
{
j = i;
} }
i++; i++;
} }
if(j==notFound) if (j == notFound)
return; return;
buffer[j]=0; buffer[j] = 0;
} }
static bool isDriverLoaded(){ static bool isDriverLoaded()
{
HANDLE handle; HANDLE handle;
handle=CreateFile(L"LIN0:", GENERIC_READ|GENERIC_WRITE|FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL); handle =
if(handle==INVALID_HANDLE_VALUE) CreateFile(L"LIN0:", GENERIC_READ | GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL);
handle=NULL; if (handle == INVALID_HANDLE_VALUE)
if(handle){ handle = NULL;
if (handle)
{
CloseHandle(handle); CloseHandle(handle);
return true; return true;
} }
return false; return false;
} }
static bool addDriverToRegistry(){ static bool addDriverToRegistry()
HKEY hKey; {
DWORD dw; HKEY hKey;
RegCreateKeyEx(HKEY_LOCAL_MACHINE, (L"Drivers\\BuiltIn\\LILODrv"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, &dw); DWORD dw;
RegCreateKeyEx(HKEY_LOCAL_MACHINE, (L"Drivers\\BuiltIn\\LILODrv"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey,
&dw);
dw = 0x0000;
if (RegSetValueEx(hKey, (L"Index"), 0, REG_DWORD, (BYTE *)&dw, sizeof(DWORD)) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return false;
}
dw = 0x0000; dw = 0x0100;
if(RegSetValueEx(hKey, (L"Index"), 0, REG_DWORD, (BYTE*)&dw, sizeof(DWORD)) != ERROR_SUCCESS) if (RegSetValueEx(hKey, (L"Order"), 0, REG_DWORD, (BYTE *)&dw, sizeof(DWORD)) != ERROR_SUCCESS)
{ {
RegCloseKey(hKey); RegCloseKey(hKey);
return false; return false;
} }
dw = 0x0100; if (RegSetValueEx(hKey, (L"Dll"), 0, REG_SZ, (BYTE *)(L"\\Windows\\BrainLILODrv.dll"),
if(RegSetValueEx(hKey, (L"Order"), 0, REG_DWORD, (BYTE*)&dw, sizeof(DWORD)) != ERROR_SUCCESS) sizeof(TCHAR) * ((DWORD)wcslen((L"\\Windows\\BrainLILODrv.dll")) + 1)) != ERROR_SUCCESS)
{ {
RegCloseKey(hKey); RegCloseKey(hKey);
return false; return false;
} }
if(RegSetValueEx(hKey, (L"Dll"), 0, REG_SZ, (BYTE*)(L"\\Windows\\BrainLILODrv.dll"), sizeof(TCHAR) * ((DWORD)wcslen((L"\\Windows\\BrainLILODrv.dll")) + 1)) != ERROR_SUCCESS) if (RegSetValueEx(hKey, (L"Prefix"), 0, REG_SZ, (BYTE *)(L"LIN"), sizeof(TCHAR) * ((DWORD)wcslen((L"LIN")) + 1)) !=
{ ERROR_SUCCESS)
RegCloseKey(hKey); {
return false; RegCloseKey(hKey);
} return false;
}
if(RegSetValueEx(hKey, (L"Prefix"), 0, REG_SZ, (BYTE*)(L"LIN"), sizeof(TCHAR) * ((DWORD)wcslen((L"LIN")) + 1)) != ERROR_SUCCESS) return true;
{
RegCloseKey(hKey);
return false;
}
return true;
} }
static void loadDriverIfNeeded(){ static void loadDriverIfNeeded()
if(isDriverLoaded()) {
if (isDriverLoaded())
return; return;
OutputDebugString(L"BrainLILO: installing LILODriver..."); OutputDebugString(L"BrainLILO: installing LILODriver...");
DWORD err; DWORD err;
HANDLE driver=NULL; HANDLE driver = NULL;
wchar_t driverPath[1024]; wchar_t driverPath[1024];
getThisDllDirectoryPath(driverPath); getThisDllDirectoryPath(driverPath);
TCHAR newDriverPath[128]; TCHAR newDriverPath[128];
getThisDllDirectoryPath(driverPath); getThisDllDirectoryPath(driverPath);
wcscat(driverPath, L"\\BrainLILODrv.dll"); wcscat(driverPath, L"\\BrainLILODrv.dll");
wcscpy(newDriverPath,L"\\Windows\\BrainLILODrv.dll"); wcscpy(newDriverPath, L"\\Windows\\BrainLILODrv.dll");
{ {
wchar_t buf[1024]; wchar_t buf[1024];
swprintf(buf, L"BrainLILO: copying \"%ls\" to \"%ls\"", swprintf(buf, L"BrainLILO: copying \"%ls\" to \"%ls\"", driverPath, newDriverPath);
driverPath, newDriverPath);
OutputDebugString(buf); OutputDebugString(buf);
} }
if(!CopyFile(driverPath,newDriverPath, FALSE)){ if (!CopyFile(driverPath, newDriverPath, FALSE))
{
if (GetFileAttributes(newDriverPath) == (DWORD)-1)
{
OutputDebugString(L"BrainLILO: failed to copy");
return;
}
}
if(GetFileAttributes(newDriverPath)==(DWORD)-1){ OutputDebugString(L"BrainLILO: registering BrainLILODriver...");
OutputDebugString(L"BrainLILO: failed to copy");
return;
}
} try
{
driver = RegisterDevice(L"LIN", 0, L"\\Windows\\BrainLILODrv.dll", 0);
OutputDebugString(L"BrainLILO: registering BrainLILODriver..."); if (driver == INVALID_HANDLE_VALUE)
driver = NULL;
try{ if (!driver)
driver=RegisterDevice(L"LIN", 0, L"\\Windows\\BrainLILODrv.dll", 0); {
if(driver==INVALID_HANDLE_VALUE) driver = RegisterDevice(L"LIN", 0, L"BrainLILODrv.dll", 0);
driver=NULL;
if(!driver){ if (driver == INVALID_HANDLE_VALUE)
driver = NULL;
}
driver=RegisterDevice(L"LIN", 0, L"BrainLILODrv.dll", 0); err = GetLastError();
}
if(driver==INVALID_HANDLE_VALUE) catch (DWORD e)
driver=NULL; {
err = e;
} }
if (!driver && (err != 0x964))
err=GetLastError(); {
}catch(DWORD e){ OutputDebugString(L"BrainLILO: failed to install...");
err=e;
}
if(!driver && (err!=0x964)){
OutputDebugString(L"BrainLILO: failed to install...");
return;
}
}
static void openDriver(){
if(g_helperHandle)
return; return;
g_helperHandle=CreateFile(L"LIN0:", GENERIC_READ|GENERIC_WRITE|FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL); }
if(g_helperHandle==INVALID_HANDLE_VALUE)
g_helperHandle=NULL;
} }
extern "C" BOOL APIENTRY DllMain(HINSTANCE hInstance, static void openDriver()
DWORD ul_reason_for_call, {
LPVOID lpReserved if (g_helperHandle)
) return;
g_helperHandle =
CreateFile(L"LIN0:", GENERIC_READ | GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL);
if (g_helperHandle == INVALID_HANDLE_VALUE)
g_helperHandle = NULL;
}
extern "C" BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD ul_reason_for_call, LPVOID lpReserved)
{ {
switch (ul_reason_for_call) switch (ul_reason_for_call)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
g_hInstance=hInstance; g_hInstance = hInstance;
initialize(); initialize();
loadDriverIfNeeded(); loadDriverIfNeeded();
openDriver(); openDriver();
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
break; break;
} }
return TRUE; return TRUE;
} }
BRAINLILO_API BOOL RKDoSoftReset(){ BRAINLILO_API BOOL RKDoSoftReset()
{
initialize(); initialize();
loadDriverIfNeeded(); loadDriverIfNeeded();
openDriver(); openDriver();
return DeviceIoControl(g_helperHandle, IOCTL_LIN_DO_LINUX, return DeviceIoControl(g_helperHandle, IOCTL_LIN_DO_LINUX, NULL, 0, NULL, 0, NULL, NULL);
NULL, 0, NULL, 0,
NULL, NULL);
} }

View File

@ -9,12 +9,12 @@
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C"{ extern "C"
{
#endif #endif
BRAINLILO_API BOOL RKDoSoftReset(); BRAINLILO_API BOOL RKDoSoftReset();
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif

View File

@ -30,34 +30,27 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
*/ */
#include <windows.h>
#include <stdint.h> #include <stdint.h>
#include <windows.h>
#define FSNOTIFY_POWER_OFF 1 #define FSNOTIFY_POWER_OFF 1
#define FSNOTIFY_POWER_ON 0 #define FSNOTIFY_POWER_ON 0
#define BRAINLILODRV_API __declspec(dllexport) #define BRAINLILODRV_API __declspec(dllexport)
#include "BrainLILODrv.h" #include "BrainLILODrv.h"
#define FILE_DEVICE_POWER FILE_DEVICE_ACPI #define FILE_DEVICE_POWER FILE_DEVICE_ACPI
#define IOCTL_POWER_CAPABILITIES \ #define IOCTL_POWER_CAPABILITIES CTL_CODE(FILE_DEVICE_POWER, 0x400, METHOD_BUFFERED, FILE_ANY_ACCESS)
CTL_CODE(FILE_DEVICE_POWER, 0x400, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_POWER_GET CTL_CODE(FILE_DEVICE_POWER, 0x401, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_POWER_GET \ #define IOCTL_POWER_SET CTL_CODE(FILE_DEVICE_POWER, 0x402, METHOD_BUFFERED, FILE_ANY_ACCESS)
CTL_CODE(FILE_DEVICE_POWER, 0x401, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_POWER_QUERY CTL_CODE(FILE_DEVICE_POWER, 0x403, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_POWER_SET \
CTL_CODE(FILE_DEVICE_POWER, 0x402, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_POWER_QUERY \
CTL_CODE(FILE_DEVICE_POWER, 0x403, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef BOOL (*KernelIoControlProc)(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf,
typedef BOOL (*KernelIoControlProc)(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize,LPDWORD lpBytesReturned);
static KernelIoControlProc KernelIoControl; static KernelIoControlProc KernelIoControl;
typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
typedef PVOID (*MmMapIoSpaceProc)(PHYSICAL_ADDRESS, ULONG, BOOL); typedef PVOID (*MmMapIoSpaceProc)(PHYSICAL_ADDRESS, ULONG, BOOL);
@ -66,238 +59,238 @@ static MmMapIoSpaceProc MmMapIoSpace;
typedef void (*FileSystemPowerFunctionProc)(DWORD); typedef void (*FileSystemPowerFunctionProc)(DWORD);
static FileSystemPowerFunctionProc FileSystemPowerFunction; static FileSystemPowerFunctionProc FileSystemPowerFunction;
typedef LPVOID (*AllocPhysMemProc)(DWORD,DWORD,DWORD,DWORD,PULONG); typedef LPVOID (*AllocPhysMemProc)(DWORD, DWORD, DWORD, DWORD, PULONG);
DWORD FileSize; DWORD FileSize;
static void disableInterrupts(){ static void disableInterrupts()
{
asm volatile("mrs r0, cpsr\n" asm volatile("mrs r0, cpsr\n"
"orr r0,r0,#0x80\n" "orr r0,r0,#0x80\n"
"msr cpsr_c,r0\n" "msr cpsr_c,r0\n"
"mov r0,#1":::"r0"); "mov r0,#1" ::
: "r0");
} }
static void EDNA2_physicalInvoker(){ static void EDNA2_physicalInvoker()
// r0-r7=params {
// r8=proc address // r0-r7=params
asm volatile("nop\n" // who cares interrupt vectors? // r8=proc address
"nop\n" asm volatile("nop\n" // who cares interrupt vectors?
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"nop\n" "nop\n"
"msr cpsr_c, #211\n" // to supervisor mode "nop\n"
"mov r9, #0\n" "msr cpsr_c, #211\n" // to supervisor mode
"mcr p15,0,r9,c13,c0,0\n" // clear fcse PID "mov r9, #0\n"
"mrc p15,0,r9,c1,c0,0\n" // read ctrl regs "mcr p15,0,r9,c13,c0,0\n" // clear fcse PID
"bic r9, r9, #5\n" // disable MMU/DCache "mrc p15,0,r9,c1,c0,0\n" // read ctrl regs
"bic r9, r9, #4096\n" // disable ICache "bic r9, r9, #5\n" // disable MMU/DCache
"orr r9, r9, #8192\n" // and reset vectors to upper "bic r9, r9, #4096\n" // disable ICache
"mcr p15,0,r9,c1,c0,0\n" // write ctrl regs "orr r9, r9, #8192\n" // and reset vectors to upper
"mov r9, #0\n" "mcr p15,0,r9,c1,c0,0\n" // write ctrl regs
"mcr p15,0,r9,c7,c7,0\n" // invalidate cache "mov r9, #0\n"
"mcr p15,0,r9,c8,c7,0\n" // invalidate tlb "mcr p15,0,r9,c7,c7,0\n" // invalidate cache
"mov pc, r8\n" "mcr p15,0,r9,c8,c7,0\n" // invalidate tlb
"nop\n" "mov pc, r8\n"
"nop\n" "nop\n"
); "nop\n");
} }
static void EDNA2_installPhysicalInvoker()
static void EDNA2_installPhysicalInvoker(){ {
void *ptr=(void *)0xa8000000; void *ptr = (void *)0xa8000000;
wchar_t buf[256]; wchar_t buf[256];
swprintf(buf, L"BrainLILO: copying PhysicalInvoker to 0x%08x from 0x%08x\n", swprintf(buf, L"BrainLILO: copying PhysicalInvoker to 0x%08x from 0x%08x\n", (int)(ptr),
(int)(ptr), (int)(&EDNA2_physicalInvoker)); (int)(&EDNA2_physicalInvoker));
OutputDebugString(buf); OutputDebugString(buf);
memcpy(ptr, (const void *)&EDNA2_physicalInvoker, 64*4); memcpy(ptr, (const void *)&EDNA2_physicalInvoker, 64 * 4);
//clearCache(); // clearCache();
} }
__attribute__((noreturn)) static void EDNA2_runPhysicalInvoker()
{
// r0=info
asm volatile("msr cpsr_c, #211\n" // to supervisor mode
"mrc p15,0,r0,c1,c0,0\n" // read ctrl regs
"bic r0, r0, #8192\n" // reset vector to lower
"mcr p15,0,r0,c1,c0,0\n" // write ctrl regs
);
__attribute__((noreturn)) for (DWORD i = 0; i < FileSize; i++)
static void EDNA2_runPhysicalInvoker(){ *((char *)(0xa0200000 + i)) = *((char *)(0xa0000000 + i));
// r0=info
asm volatile("msr cpsr_c, #211\n" // to supervisor mode
"mrc p15,0,r0,c1,c0,0\n" // read ctrl regs
"bic r0, r0, #8192\n" // reset vector to lower
"mcr p15,0,r0,c1,c0,0\n" // write ctrl regs
);
for(DWORD i=0;i<FileSize;i++)*((char *)(0xa0200000+i))=*((char *)(0xa0000000+i)); asm volatile("ldr r0, =0x0000\n"
"ldr r1, =0x0000\n"
"ldr r2, =0x0000\n"
"ldr r3, =0x0000\n"
"ldr r4, =0x0000\n"
"ldr r5, =0x0000\n"
"ldr r6, =0x0000\n"
"ldr r7, =0x0000\n"
"ldr r8, =0x40200000\n"
"ldr r9, =0x0000\n"
asm volatile("ldr r0, =0x0000\n" "mrc p15,0,r10,c1,c0,0\n" // read ctrl regs
"ldr r1, =0x0000\n" "bic r10, r10, #5\n" // disable MMU/DCache
"ldr r2, =0x0000\n" "mcr p15,0,r10,c1,c0,0\n" // write ctrl regs
"ldr r3, =0x0000\n" "swi #0\n" // jump!
"ldr r4, =0x0000\n" );
"ldr r5, =0x0000\n"
"ldr r6, =0x0000\n"
"ldr r7, =0x0000\n"
"ldr r8, =0x40200000\n"
"ldr r9, =0x0000\n"
"mrc p15,0,r10,c1,c0,0\n" // read ctrl regs // never reach here
"bic r10, r10, #5\n" // disable MMU/DCache while (true)
"mcr p15,0,r10,c1,c0,0\n" // write ctrl regs ;
"swi #0\n" // jump!
);
// never reach here
while(true);
} }
__attribute__((noreturn)) __attribute__((noreturn)) static DWORD EDNA2_callKernelEntryPoint()
static DWORD EDNA2_callKernelEntryPoint(){ {
OutputDebugString(L"BrainLILO: disabling interrupts"); OutputDebugString(L"BrainLILO: disabling interrupts");
disableInterrupts(); disableInterrupts();
OutputDebugString(L"BrainLILO: injecting code to internal ram"); OutputDebugString(L"BrainLILO: injecting code to internal ram");
EDNA2_installPhysicalInvoker(); EDNA2_installPhysicalInvoker();
OutputDebugString(L"BrainLILO: invoking"); OutputDebugString(L"BrainLILO: invoking");
EDNA2_runPhysicalInvoker(); EDNA2_runPhysicalInvoker();
} }
static bool doLinux(){ static bool doLinux()
TCHAR bootloaderFileName[128]=TEXT("\\Storage Card\\loader\\u-boot.bin"); {
HANDLE hFile; TCHAR bootloaderFileName[128] = TEXT("\\Storage Card\\loader\\u-boot.bin");
LPVOID bootloaderptr; HANDLE hFile;
wchar_t buf[256]; LPVOID bootloaderptr;
HINSTANCE dll; wchar_t buf[256];
DWORD wReadSize; HINSTANCE dll;
DWORD wReadSize;
OutputDebugString(L"BrainLILO: Opening Bootloader file..."); OutputDebugString(L"BrainLILO: Opening Bootloader file...");
hFile = CreateFile(bootloaderFileName , GENERIC_READ , 0 , NULL ,OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL); hFile = CreateFile(bootloaderFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) { if (hFile == INVALID_HANDLE_VALUE)
OutputDebugString(L"Cant open bootloader"); {
return false; OutputDebugString(L"Cant open bootloader");
} return false;
swprintf(buf, L"BrainLILO: Bootloader file handle 0x%08x\n",(int)(hFile)); }
OutputDebugString(buf); swprintf(buf, L"BrainLILO: Bootloader file handle 0x%08x\n", (int)(hFile));
OutputDebugString(buf);
FileSize=GetFileSize(hFile , NULL); FileSize = GetFileSize(hFile, NULL);
swprintf(buf, L"BrainLILO: Bootloader file size %d Byte\n",FileSize); swprintf(buf, L"BrainLILO: Bootloader file size %d Byte\n", FileSize);
OutputDebugString(buf); OutputDebugString(buf);
OutputDebugString(L"BrainLILO: Preloading bootloader to 0xa0000000...");
if (!ReadFile(hFile, (void *)0xa0000000, FileSize, &wReadSize, NULL))
{
OutputDebugString(L"Cant read bootloader");
return false;
}
OutputDebugString(L"BrainLILO: Bootloader copied! Closing file handle...");
CloseHandle(hFile);
OutputDebugString(L"BrainLILO: Preloading bootloader to 0xa0000000..."); OutputDebugString(L"BrainLILO: Notifying power off to filesystems...");
if (!ReadFile(hFile , (void *)0xa0000000 , FileSize , &wReadSize , NULL)) { if (FileSystemPowerFunction)
OutputDebugString(L"Cant read bootloader"); FileSystemPowerFunction(FSNOTIFY_POWER_OFF);
return false;
}
OutputDebugString(L"BrainLILO: Bootloader copied! Closing file handle...");
CloseHandle(hFile);
OutputDebugString(L"BrainLILO: Notifying power off to filesystems..."); OutputDebugString(L"BrainLILO: Starting bootloader call sequence...");
if(FileSystemPowerFunction) FileSystemPowerFunction(FSNOTIFY_POWER_OFF); EDNA2_callKernelEntryPoint();
return true;
OutputDebugString(L"BrainLILO: Starting bootloader call sequence...");
EDNA2_callKernelEntryPoint();
return true;
} }
extern "C" BRAINLILODRV_API BOOL LIN_IOControl(DWORD handle, DWORD dwIoControlCode, DWORD *pInBuf, DWORD nInBufSize, DWORD * pOutBuf, DWORD nOutBufSize, extern "C" BRAINLILODRV_API BOOL LIN_IOControl(DWORD handle, DWORD dwIoControlCode, DWORD *pInBuf, DWORD nInBufSize,
PDWORD pBytesReturned){ DWORD *pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned)
{
SetLastError(0); SetLastError(0);
switch(dwIoControlCode){ switch (dwIoControlCode)
case IOCTL_LIN_DO_LINUX: {
if(!doLinux()){ case IOCTL_LIN_DO_LINUX:
if(FileSystemPowerFunction) if (!doLinux())
FileSystemPowerFunction(FSNOTIFY_POWER_ON); {
return FALSE; if (FileSystemPowerFunction)
} FileSystemPowerFunction(FSNOTIFY_POWER_ON);
return FALSE;
}
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
extern "C" BRAINLILODRV_API BOOL LIN_Read(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes){ extern "C" BRAINLILODRV_API BOOL LIN_Read(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes)
SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}
extern "C" BRAINLILODRV_API BOOL LIN_Write(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes){
SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}
extern "C" BRAINLILODRV_API DWORD LIN_Seek(DWORD handle, long lDistance, DWORD dwMoveMethod){
SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}
extern "C" BRAINLILODRV_API void LIN_PowerUp(void){
OutputDebugString(L"BrainLILO: resuming.");
}
extern "C" BRAINLILODRV_API void LIN_PowerDown(void){
}
extern "C" BRAINLILODRV_API DWORD LIN_Init(LPCTSTR pContext,
DWORD dwBusContext){
void *ctx;
ctx=(void *)LocalAlloc(LPTR, sizeof(4));
return (DWORD)ctx;
}
extern "C" BRAINLILODRV_API DWORD LIN_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode){
void *hnd=(void *)LocalAlloc(LPTR, 4);
return (DWORD)hnd;
}
extern "C" BRAINLILODRV_API BOOL LIN_Close(DWORD handle){
LocalFree((void *)handle);
return TRUE;
}
extern "C" BRAINLILODRV_API BOOL LIN_Deinit(DWORD dwContext){
LocalFree((void *)dwContext);
return TRUE;
}
extern "C" BOOL APIENTRY DllMainCRTStartup( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{ {
switch (ul_reason_for_call) SetLastError(ERROR_INVALID_FUNCTION);
{ return FALSE;
case DLL_PROCESS_ATTACH: }
case DLL_THREAD_ATTACH:
KernelIoControl=(KernelIoControlProc)
GetProcAddress(LoadLibrary(L"COREDLL"),
L"KernelIoControl");
MmMapIoSpace=(MmMapIoSpaceProc) extern "C" BRAINLILODRV_API BOOL LIN_Write(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes)
GetProcAddress(LoadLibrary(L"CEDDK"), {
L"MmMapIoSpace"); SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}
FileSystemPowerFunction=(FileSystemPowerFunctionProc) extern "C" BRAINLILODRV_API DWORD LIN_Seek(DWORD handle, long lDistance, DWORD dwMoveMethod)
GetProcAddress(LoadLibrary(L"COREDLL"), {
L"FileSystemPowerFunction"); SetLastError(ERROR_INVALID_FUNCTION);
return FALSE;
}
extern "C" BRAINLILODRV_API void LIN_PowerUp(void)
{
OutputDebugString(L"BrainLILO: resuming.");
}
extern "C" BRAINLILODRV_API void LIN_PowerDown(void)
{
}
extern "C" BRAINLILODRV_API DWORD LIN_Init(LPCTSTR pContext, DWORD dwBusContext)
{
void *ctx;
ctx = (void *)LocalAlloc(LPTR, sizeof(4));
return (DWORD)ctx;
}
extern "C" BRAINLILODRV_API DWORD LIN_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
void *hnd = (void *)LocalAlloc(LPTR, 4);
return (DWORD)hnd;
}
extern "C" BRAINLILODRV_API BOOL LIN_Close(DWORD handle)
{
LocalFree((void *)handle);
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE; return TRUE;
} }
extern "C" BRAINLILODRV_API BOOL LIN_Deinit(DWORD dwContext)
{
LocalFree((void *)dwContext);
return TRUE;
}
extern "C" BOOL APIENTRY DllMainCRTStartup(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
KernelIoControl = (KernelIoControlProc)GetProcAddress(LoadLibrary(L"COREDLL"), L"KernelIoControl");
MmMapIoSpace = (MmMapIoSpaceProc)GetProcAddress(LoadLibrary(L"CEDDK"), L"MmMapIoSpace");
FileSystemPowerFunction =
(FileSystemPowerFunctionProc)GetProcAddress(LoadLibrary(L"COREDLL"), L"FileSystemPowerFunction");
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include <winioctl.h> #include <winioctl.h>
#define _LIN_ACCESS_CTL_CODE(_Function) \ #define _LIN_ACCESS_CTL_CODE(_Function) CTL_CODE(FILE_DEVICE_UNKNOWN, _Function, METHOD_BUFFERED, FILE_ANY_ACCESS)
CTL_CODE(FILE_DEVICE_UNKNOWN, _Function, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_LIN_DO_LINUX _LIN_ACCESS_CTL_CODE(0x804) #define IOCTL_LIN_DO_LINUX _LIN_ACCESS_CTL_CODE(0x804)

View File

@ -1,80 +1,80 @@
// This file is in public domain. // This file is in public domain.
#include <windows.h>
#include <vector>
#include <algorithm> #include <algorithm>
#include <tchar.h> #include <tchar.h>
#include <vector>
#include <windows.h>
#define MainWindowClassName L"SelectorMainWindowClass" #define MainWindowClassName L"SelectorMainWindowClass"
#define DataTypeAlertError 0x1000 #define DataTypeAlertError 0x1000
#define DataTypeAlertInformation 0x1001 #define DataTypeAlertInformation 0x1001
#define DataTypeAlertWarning 0x1002 #define DataTypeAlertWarning 0x1002
static void showAlertWarning(LPCWSTR message, static void showAlertWarning(LPCWSTR message, LPCWSTR title)
LPCWSTR title){ {
HWND selectorMainWindow=FindWindow(MainWindowClassName, NULL); HWND selectorMainWindow = FindWindow(MainWindowClassName, NULL);
if(!selectorMainWindow){ if (!selectorMainWindow)
MessageBox(NULL, message, title, {
MB_ICONWARNING); MessageBox(NULL, message, title, MB_ICONWARNING);
return; return;
} }
wchar_t data[2048]; wchar_t data[2048];
wcscpy(data, message); wcscpy(data, message);
data[wcslen(message)]=0; data[wcslen(message)] = 0;
wcscpy(data+wcslen(message)+1, title); wcscpy(data + wcslen(message) + 1, title);
size_t dataLen=wcslen(message)+wcslen(title)+1; size_t dataLen = wcslen(message) + wcslen(title) + 1;
COPYDATASTRUCT info; COPYDATASTRUCT info;
info.dwData=DataTypeAlertWarning; info.dwData = DataTypeAlertWarning;
info.cbData=dataLen*sizeof(wchar_t); info.cbData = dataLen * sizeof(wchar_t);
HGLOBAL global=GlobalAlloc(GPTR, info.cbData); HGLOBAL global = GlobalAlloc(GPTR, info.cbData);
memcpy((LPVOID)global, data, info.cbData); memcpy((LPVOID)global, data, info.cbData);
info.lpData=(LPVOID)global; info.lpData = (LPVOID)global;
SendMessage(selectorMainWindow, WM_COPYDATA, NULL, (LPARAM)&info);
SendMessage(selectorMainWindow, WM_COPYDATA, NULL,
(LPARAM)&info);
GlobalFree(global); GlobalFree(global);
} }
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow){ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow)
HINSTANCE lib=LoadLibrary(L"BrainLILO"); {
if(!lib){ HINSTANCE lib = LoadLibrary(L"BrainLILO");
wchar_t buf[256]; if (!lib)
swprintf(buf, L"Cannot perform a soft reset.\n" {
L"BrainLILO was not loaded (0x%08x).", wchar_t buf[256];
GetLastError()); swprintf(buf,
L"Cannot perform a soft reset.\n"
L"BrainLILO was not loaded (0x%08x).",
GetLastError());
showAlertWarning(buf, L"Error"); showAlertWarning(buf, L"Error");
return 1; return 1;
} }
typedef BOOL (*RKDoSoftResetProc)(); typedef BOOL (*RKDoSoftResetProc)();
RKDoSoftResetProc RKDoSoftReset= RKDoSoftResetProc RKDoSoftReset = (RKDoSoftResetProc)GetProcAddress(lib, L"RKDoSoftReset");
(RKDoSoftResetProc)GetProcAddress(lib, L"RKDoSoftReset"); if (!RKDoSoftReset)
if(!RKDoSoftReset){ {
wchar_t buf[256]; wchar_t buf[256];
swprintf(buf, L"Cannot perform a soft reset.\n" swprintf(buf,
L"Cannot perform a soft reset.\n"
L"RKDoSoftReset not found (0x%08x).", L"RKDoSoftReset not found (0x%08x).",
GetLastError()); GetLastError());
showAlertWarning(buf, L"Error"); showAlertWarning(buf, L"Error");
return 1; return 1;
} }
if(!RKDoSoftReset()){ if (!RKDoSoftReset())
{
wchar_t buf[256]; wchar_t buf[256];
swprintf(buf, L"Cannot perform a soft reset.\n" swprintf(buf,
L"Cannot perform a soft reset.\n"
L"Operation failed (0x%08x).", L"Operation failed (0x%08x).",
GetLastError()); GetLastError());
showAlertWarning(buf, L"Error"); showAlertWarning(buf, L"Error");
@ -82,5 +82,3 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow){
} }
return 0; return 0;
} }