mirror of
https://github.com/brain-hackers/lab
synced 2024-12-22 12:10:04 +09:00
table walker for mx28
This commit is contained in:
parent
1ed83389f2
commit
561982b6dd
48
tablewalker/Makefile
Normal file
48
tablewalker/Makefile
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
CC=/opt/cegcc/bin/arm-mingw32ce-gcc
|
||||
CXX=/opt/cegcc/bin/arm-mingw32ce-g++
|
||||
LD=/opt/cegcc/bin/arm-mingw32ce-g++
|
||||
STRIP=/opt/cegcc/bin/arm-mingw32ce-strip
|
||||
DLLTOOL=/opt/cegcc/bin/arm-mingw32ce-dlltool
|
||||
AS=/opt/cegcc/bin/arm-mingw32ce-as
|
||||
NM=/opt/cegcc/bin/arm-mingw32ce-nm
|
||||
WINDRES=/opt/cegcc/bin/arm-mingw32ce-windres
|
||||
|
||||
OUTPUT=ResetKit.dll ResetKitHelper.dll SoftReset.exe
|
||||
|
||||
CXXFLAGS= -DEV_PLATFORM_WIN32 -DUNICODE -D_UNICODE -DEV_UNSAFE_SWPRINTF -mwin32 \
|
||||
-Os -mcpu=arm926ej-s -D_WIN32_WCE=0x600 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \
|
||||
-D_FILE_OFFSET_BITS=64 -static
|
||||
|
||||
DLLFLAGS=-DEV_PLATFORM_WIN32 -DUNICODE -D_UNICODE -DEV_UNSAFE_SWPRINTF -mwin32 \
|
||||
-Os -mcpu=arm926ej-s -D_WIN32_WCE=0x600 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \
|
||||
-D_FILE_OFFSET_BITS=64 -DNDEBUG -Wall -static \
|
||||
-Wl,--image-base,0x100000 \
|
||||
-shared
|
||||
|
||||
DRVFLAGS= -DEV_PLATFORM_WIN32 -DUNICODE -D_UNICODE -DEV_UNSAFE_SWPRINTF -mwin32 \
|
||||
-O0 -mcpu=arm926ej-s -D_WIN32_WCE=0x600 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 \
|
||||
-D_FILE_OFFSET_BITS=64 -DNDEBUG -Wall -static \
|
||||
-Wl,--image-base,0x100000 \
|
||||
-nostdlib -lcoredll -shared
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUTPUT)
|
||||
|
||||
clean:
|
||||
rm -f $(OUTPUT)
|
||||
|
||||
ResetKit.dll: ResetKit.cpp
|
||||
$(CXX) ResetKit.cpp -o ResetKit.dll $(DLLFLAGS)
|
||||
$(STRIP) ResetKit.dll
|
||||
|
||||
ResetKitHelper.dll: ResetKitHelper.cpp
|
||||
$(CXX) ResetKitHelper.cpp -o ResetKitHelper.dll $(DRVFLAGS)
|
||||
$(STRIP) ResetKitHelper.dll
|
||||
|
||||
|
||||
SoftReset.exe: SoftReset.cpp
|
||||
$(CXX) SoftReset.cpp -o SoftReset.exe $(CXXFLAGS)
|
||||
$(STRIP) SoftReset.exe
|
||||
|
234
tablewalker/ResetKit.cpp
Normal file
234
tablewalker/ResetKit.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* ResetKit
|
||||
* Soft/hard reset the electronic dictionary.
|
||||
*
|
||||
* Copyright (C) 2012 T. Kawada <tcppjp [ at ] gmail.com>
|
||||
*
|
||||
* This file is licensed in MIT license.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#define RESETKIT_API extern "C" __declspec(dllexport)
|
||||
#include "ResetKit.h"
|
||||
#include "ResetKitHelper.h"
|
||||
#include <string.h>
|
||||
|
||||
static bool g_initialized=false;
|
||||
static HANDLE g_helperHandle=NULL;
|
||||
static HINSTANCE g_hInstance;
|
||||
|
||||
static void initialize(){
|
||||
if(g_initialized)
|
||||
return;
|
||||
|
||||
g_initialized=true;
|
||||
}
|
||||
|
||||
static void getThisDllDirectoryPath(LPWSTR buffer){
|
||||
// retrive the path of the application.
|
||||
GetModuleFileName(g_hInstance, buffer, 512);
|
||||
|
||||
const size_t notFound=(size_t)-1;
|
||||
size_t i=0;
|
||||
size_t j=notFound;
|
||||
|
||||
while(buffer[i]){
|
||||
if(buffer[i]==L'/' || buffer[i]==L'\\'){
|
||||
j=i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(j==notFound)
|
||||
return;
|
||||
|
||||
buffer[j]=0;
|
||||
|
||||
}
|
||||
|
||||
static bool isDriverLoaded(){
|
||||
HANDLE handle;
|
||||
handle=CreateFile(L"RKH0:", GENERIC_READ|GENERIC_WRITE|FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(handle==INVALID_HANDLE_VALUE)
|
||||
handle=NULL;
|
||||
if(handle){
|
||||
CloseHandle(handle);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool addDriverToRegistry(){
|
||||
HKEY hKey;
|
||||
DWORD dw;
|
||||
RegCreateKeyEx(HKEY_LOCAL_MACHINE, (L"Drivers\\BuiltIn\\ResetKitHelper"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, &dw);
|
||||
if(!hKey)
|
||||
return false;
|
||||
|
||||
dw = 0x0000;
|
||||
if(RegSetValueEx(hKey, (L"Index"), 0, REG_DWORD, (BYTE*)&dw, sizeof(DWORD)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return false;
|
||||
}
|
||||
|
||||
dw = 0x0100;
|
||||
if(RegSetValueEx(hKey, (L"Order"), 0, REG_DWORD, (BYTE*)&dw, sizeof(DWORD)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(RegSetValueEx(hKey, (L"Dll"), 0, REG_SZ, (BYTE*)(L"\\Windows\\ResetKitHelper.dll"), sizeof(TCHAR) * ((DWORD)wcslen((L"\\Windows\\ResetKitHelper.dll")) + 1)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(RegSetValueEx(hKey, (L"Prefix"), 0, REG_SZ, (BYTE*)(L"RKH"), sizeof(TCHAR) * ((DWORD)wcslen((L"RKH")) + 1)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void loadDriverIfNeeded(){
|
||||
if(isDriverLoaded())
|
||||
return;
|
||||
|
||||
OutputDebugString(L"ResetKit: installing ResetKitHelper...");
|
||||
|
||||
DWORD err;
|
||||
HANDLE driver=NULL;
|
||||
|
||||
wchar_t driverPath[1024];
|
||||
getThisDllDirectoryPath(driverPath);
|
||||
wcscat(driverPath, L"\\ResetKitHelper.dll");
|
||||
|
||||
LPCWSTR newDriverPath;
|
||||
newDriverPath=L"\\Windows\\ResetKitHelper.dll";
|
||||
|
||||
{
|
||||
wchar_t buf[1024];
|
||||
swprintf(buf, L"ResetKit: copying \"%ls\" to \"%ls\"",
|
||||
driverPath, newDriverPath);
|
||||
OutputDebugString(buf);
|
||||
}
|
||||
|
||||
if(!CopyFile(driverPath,
|
||||
newDriverPath, FALSE)){
|
||||
|
||||
|
||||
if(GetFileAttributes(newDriverPath)==(DWORD)-1){
|
||||
OutputDebugString(L"ResetKit: failed to copy");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
addDriverToRegistry();
|
||||
OutputDebugString(L"ResetKit: activating ResetKitHelper...");
|
||||
ActivateDevice(L"Drivers\\ResetKitHelper", NULL);
|
||||
{
|
||||
wchar_t buf[256];
|
||||
DWORD err=GetLastError();
|
||||
if(err){
|
||||
swprintf(buf, L"ResetKit: ActivateDevice error: 0x%08x", (int)err);
|
||||
OutputDebugString(buf);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
OutputDebugString(L"ResetKit: registering ResetKitHelper...");
|
||||
|
||||
try{
|
||||
driver=RegisterDevice(L"RKH", 0, L"\\Windows\\ResetKitHelper.dll", 0);
|
||||
|
||||
if(driver==INVALID_HANDLE_VALUE)
|
||||
driver=NULL;
|
||||
|
||||
if(!driver){
|
||||
|
||||
driver=RegisterDevice(L"RKH", 0, L"ResetKitHelper.dll", 0);
|
||||
|
||||
if(driver==INVALID_HANDLE_VALUE)
|
||||
driver=NULL;
|
||||
|
||||
}
|
||||
|
||||
err=GetLastError();
|
||||
}catch(DWORD e){
|
||||
err=e;
|
||||
}
|
||||
if(!driver && (err!=0x964)){
|
||||
OutputDebugString(L"ResetKit: failed to install...");
|
||||
return;
|
||||
}
|
||||
|
||||
//addDriverToRegistry();
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void openDriver(){
|
||||
if(g_helperHandle)
|
||||
return;
|
||||
g_helperHandle=CreateFile(L"RKH0:", 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)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
|
||||
g_hInstance=hInstance;
|
||||
|
||||
initialize();
|
||||
loadDriverIfNeeded();
|
||||
openDriver();
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
RESETKIT_API BOOL RKDoSoftReset(){
|
||||
|
||||
initialize();
|
||||
loadDriverIfNeeded();
|
||||
openDriver();
|
||||
|
||||
return DeviceIoControl(g_helperHandle, IOCTL_RKH_DO_SOFT_RESET,
|
||||
NULL, 0, NULL, 0,
|
||||
NULL, NULL);
|
||||
}
|
31
tablewalker/ResetKit.h
Normal file
31
tablewalker/ResetKit.h
Normal file
@ -0,0 +1,31 @@
|
||||
// This file is in public domain.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifndef RESETKIT_API
|
||||
#define RESETKIT_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#define ERROR_GENERATION_NOT_SUPPORTED 0x1200
|
||||
#define ERROR_NKFORCECLEANBOOT_NOT_FOUND 0x1201
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
RESETKIT_API DWORD RKDeviceGeneration();
|
||||
|
||||
RESETKIT_API BOOL RKCanSoftReset();
|
||||
RESETKIT_API BOOL RKCanHardReset();
|
||||
|
||||
RESETKIT_API BOOL RKDoSoftReset();
|
||||
RESETKIT_API BOOL RKDoHardReset();
|
||||
|
||||
RESETKIT_API BOOL RKInstallDicProtect();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
275
tablewalker/ResetKitHelper.cpp
Normal file
275
tablewalker/ResetKitHelper.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* ResetKitHelper
|
||||
* Soft/hard reset the electronic dictionary.
|
||||
*
|
||||
* Copyright (C) 2012 T. Kawada <tcppjp [ at ] gmail.com>
|
||||
*
|
||||
* This file is licensed in MIT license.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define RESETKITHELPER_API __declspec(dllexport)
|
||||
|
||||
#include "ResetKitHelper.h"
|
||||
|
||||
#pragma mark - EDNA2 Specific
|
||||
|
||||
// only for 0x80000000 - 0x80100000
|
||||
#define EDNA2Register(addr) (*(volatile uint32_t *)((addr) + 0x30000000))
|
||||
|
||||
unsigned int pow(unsigned int base, unsigned int exponent) {
|
||||
unsigned int ans = 1;
|
||||
for (unsigned int i = 0; i < exponent; i++) {
|
||||
ans *= base;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void print(char *string,unsigned int *addr) {
|
||||
do {
|
||||
*addr |= *string;
|
||||
string++;
|
||||
} while (*string != '\0');
|
||||
}
|
||||
|
||||
unsigned int div(unsigned int dividend,unsigned int divisor){
|
||||
unsigned int ans;
|
||||
ans=0;
|
||||
while(dividend>divisor){
|
||||
dividend-=divisor;
|
||||
ans++;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void printhex(unsigned int num,unsigned int *addr) {
|
||||
int digit=8;
|
||||
print("0x",addr);
|
||||
while (digit) {
|
||||
unsigned int weight = pow(16, digit - 1);
|
||||
unsigned int ans = div(num,weight);
|
||||
if (ans < 10)
|
||||
*addr |= '0' + ans;
|
||||
else
|
||||
*addr |= 'A' + ans - 10;
|
||||
num -= ans * weight;
|
||||
digit--;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API BOOL RKH_IOControl(DWORD handle, DWORD dwIoControlCode, DWORD *pInBuf, DWORD nInBufSize, DWORD *pOutBuf, DWORD nOutBufSize,
|
||||
PDWORD pBytesReturned){
|
||||
SetLastError(0);
|
||||
switch (dwIoControlCode){
|
||||
case IOCTL_RKH_DO_SOFT_RESET:
|
||||
wchar_t buf[256];
|
||||
unsigned int TTBCR,addrmask,TTBR0,TTBR1,*table0,*table1,ram=0,ahp=0,descriptor;
|
||||
asm volatile(
|
||||
"msr cpsr_c, #211\n" // to supervisor mode
|
||||
"mrs r0, cpsr\n"
|
||||
"orr r0,r0,#0x80\n"
|
||||
"msr cpsr_c,r0\n" //interrupt disable
|
||||
"mov r0,#1\n"
|
||||
//"mrc p15,0,r9,c1,c0,0\n" // read ctrl regs
|
||||
//"bic r9, r9, #4\n" // disable DCache
|
||||
//"bic r9, r9, #4096\n" // disable ICache
|
||||
//"mcr p15,0,r9,c1,c0,0\n" // write ctrl regs
|
||||
//"mov r9, #0\n"
|
||||
//"mcr p15,0,r9,c7,c7,0\n" // invalidate cache
|
||||
//"mcr p15,0,r9,c8,c7,0\n" // invalidate tlb
|
||||
:::"r0"
|
||||
);
|
||||
OutputDebugString(L"stop interrupt\r\n");
|
||||
asm volatile(
|
||||
"mrc p15, 0, %1, c2, c0, 0\n"
|
||||
: "=r" (TTBCR),"=r" (TTBR0),"=r" (TTBR1)
|
||||
);
|
||||
swprintf(buf, L"TTBR=%#x\r\n", TTBR0);
|
||||
OutputDebugString(buf);
|
||||
for(unsigned int i=0;i<0xffffffff;i+=4096){
|
||||
table0=(unsigned int *)((TTBR0&0xFFFFC000)|((i>>19)<<2));
|
||||
swprintf(buf, L"table0 addr=%#x\r\n", table0);
|
||||
OutputDebugString(buf);
|
||||
asm volatile(
|
||||
"mrc p15,0,r10,c1,c0,0\n" // read ctrl regs
|
||||
"mov r9,r10\n"
|
||||
"bic r10, r10, #1\n"
|
||||
"mcr p15,0,r10,c1,c0,0\n"// disable MMU
|
||||
"ldr %0, [%1]\n"
|
||||
"mcr p15,0,r9,c1,c0,0\n" // enable MMU
|
||||
"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"
|
||||
:"=r" (descriptor): "r" (table0):"r10","r9","r8"
|
||||
);
|
||||
swprintf(buf, L"table0=%#x\r\n", descriptor);
|
||||
OutputDebugString(buf);
|
||||
if((descriptor&0x3)==0)continue; //Invalid
|
||||
else if((descriptor&0x3)==1){ //Page Table
|
||||
table1=(unsigned int *)((descriptor&0xFFFFFC00)|((i&0xFF000)>>9));
|
||||
swprintf(buf, L"table1 addr=%#x\r\n", table1);
|
||||
OutputDebugString(buf);
|
||||
asm volatile(
|
||||
"mrc p15,0,r10,c1,c0,0\n" // read ctrl regs
|
||||
"mov r9,r10\n"
|
||||
"bic r10, r10, #1\n"
|
||||
"mcr p15,0,r10,c1,c0,0\n"// disable MMU
|
||||
"ldr %0, [%1]\n"
|
||||
"mcr p15,0,r9,c1,c0,0\n" // enable MMU
|
||||
"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"
|
||||
: "=r" (table1):"r" (descriptor):"r10","r9","r8"
|
||||
);
|
||||
if(descriptor&0x3==1){//large page
|
||||
if(((descriptor&0xFFFF0000)|(i&0xFFFF))==0x40000000)ram=i;
|
||||
else if(((descriptor&0xFFFF0000)|(i&0xFFFF0000))==0x80070000)ahp=i;
|
||||
}else{//small page
|
||||
if(((descriptor&0xFFFFF000)|(i&0xFFF))==0x40000000)ram=i;
|
||||
else if(((descriptor&0xFFFFF000)|(i&0xFFF))==0x80070000)ahp=i;
|
||||
}
|
||||
}else if((descriptor&0x40000)){ //Section
|
||||
if(((descriptor&0xFFF00000)|(i&0xFFFFF))==0x40000000)ram=i;
|
||||
else if(((descriptor&0xFFF00000)|(i&0xFFFFF))==0x80070000)ahp=i;
|
||||
}else continue; //Supersection
|
||||
}
|
||||
|
||||
swprintf(buf, L"RAM=%#x\r\nNear UART=%#x\r\n", ram, ahp);
|
||||
OutputDebugString(buf);
|
||||
/*
|
||||
if(ahp){
|
||||
*((unsigned int *)(ahp+0x4000+0x30)) |= 0x101; //UART Tx Enable
|
||||
*((unsigned int *)(ahp+0x4000+0x38)) &= 0x0; //UART Intr disable
|
||||
print("DUART=",(unsigned int *)ahp+0x4000);
|
||||
printhex(ahp+0x2D0000+0x1C,(unsigned int *)ahp+0x4000);
|
||||
print("\n",(unsigned int *)ahp+0x4000);
|
||||
|
||||
if(ram){
|
||||
print("DRAM=",(unsigned int *)ahp+0x4000);
|
||||
printhex(ram,(unsigned int *)ahp+0x4000);
|
||||
print("\n",(unsigned int *)ahp+0x4000);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
while(1);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API BOOL RKH_Read(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_FUNCTION);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API BOOL RKH_Write(DWORD handle, LPVOID pBuffer, DWORD dwNumBytes)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_FUNCTION);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API DWORD RKH_Seek(DWORD handle, long lDistance, DWORD dwMoveMethod)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_FUNCTION);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API void RKH_PowerUp(void)
|
||||
{
|
||||
OutputDebugString(L"ResetKit: resuming.");
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API void RKH_PowerDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API DWORD RKH_Init(LPCTSTR pContext, DWORD dwBusContext)
|
||||
{
|
||||
|
||||
void *ctx;
|
||||
ctx = (void *)LocalAlloc(LPTR, sizeof(4));
|
||||
|
||||
return (DWORD)ctx;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API DWORD RKH_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
|
||||
{
|
||||
|
||||
//SetProcPermissions(-1);
|
||||
|
||||
void *hnd = (void *)LocalAlloc(LPTR, 4);
|
||||
return (DWORD)hnd;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API BOOL RKH_Close(DWORD handle)
|
||||
{
|
||||
LocalFree((void *)handle);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern "C" RESETKITHELPER_API BOOL RKH_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:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
22
tablewalker/ResetKitHelper.h
Normal file
22
tablewalker/ResetKitHelper.h
Normal file
@ -0,0 +1,22 @@
|
||||
// This file is in public domain.
|
||||
|
||||
#pragma once
|
||||
#include <winioctl.h>
|
||||
|
||||
#define _RKH_ACCESS_CTL_CODE(_Function) \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, _Function, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_RKH_GET_DEVICE_GENERATION _RKH_ACCESS_CTL_CODE(0x801)
|
||||
|
||||
#define IOCTL_RKH_CAN_SOFT_RESET _RKH_ACCESS_CTL_CODE(0x802)
|
||||
|
||||
#define IOCTL_RKH_CAN_HARD_RESET _RKH_ACCESS_CTL_CODE(0x803)
|
||||
|
||||
#define IOCTL_RKH_DO_SOFT_RESET _RKH_ACCESS_CTL_CODE(0x804)
|
||||
|
||||
#define IOCTL_RKH_DO_HARD_RESET _RKH_ACCESS_CTL_CODE(0x805)
|
||||
|
||||
#define IOCTL_RKH_INSTALL_DICPROTECT _RKH_ACCESS_CTL_CODE(0x806)
|
||||
|
||||
#define ERROR_GENERATION_NOT_SUPPORTED 0x1200
|
||||
#define ERROR_NKFORCECLEANBOOT_NOT_FOUND 0x1201
|
25
tablewalker/ResetKitHelper.rc
Normal file
25
tablewalker/ResetKitHelper.rc
Normal file
@ -0,0 +1,25 @@
|
||||
// This file is in public domain.
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0, 2, 0, 0
|
||||
PRODUCTVERSION 0, 2, 0, 0
|
||||
FILEOS 4
|
||||
FILETYPE 3
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Neur0k.info\000"
|
||||
VALUE "FileDescription", "ResetKitHelper\000"
|
||||
VALUE "FileVersion", "0.2.0\000"
|
||||
VALUE "InternalName", "ResetKitHelper\000"
|
||||
VALUE "OriginalFilename", "ResetKitHelper.dll\000"
|
||||
VALUE "LegalCopyright", "Copyright (c) 2012 T. Kawada\000"
|
||||
VALUE "LegalTrademarks", "T.Kawada is Tomoaki Kawada.\000"
|
||||
VALUE "ProductName", "ResetKit\000"
|
||||
VALUE "ProductVersion", "0.2.0\000"
|
||||
VALUE "Comments", "Soft/hard reset the electronic dictionary.\000"
|
||||
END
|
||||
END
|
||||
END
|
85
tablewalker/SoftReset.cpp
Normal file
85
tablewalker/SoftReset.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
// This file is in public domain.
|
||||
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <tchar.h>
|
||||
|
||||
#define MainWindowClassName L"SelectorMainWindowClass"
|
||||
|
||||
#define DataTypeAlertError 0x1000
|
||||
#define DataTypeAlertInformation 0x1001
|
||||
#define DataTypeAlertWarning 0x1002
|
||||
|
||||
static void showAlertWarning(LPCWSTR message,
|
||||
LPCWSTR title){
|
||||
|
||||
HWND selectorMainWindow=FindWindow(MainWindowClassName, NULL);
|
||||
|
||||
if(!selectorMainWindow){
|
||||
MessageBox(NULL, message, title,
|
||||
MB_ICONWARNING);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
wchar_t data[2048];
|
||||
wcscpy(data, message);
|
||||
data[wcslen(message)]=0;
|
||||
wcscpy(data+wcslen(message)+1, title);
|
||||
|
||||
size_t dataLen=wcslen(message)+wcslen(title)+1;
|
||||
|
||||
COPYDATASTRUCT info;
|
||||
info.dwData=DataTypeAlertWarning;
|
||||
info.cbData=dataLen*sizeof(wchar_t);
|
||||
|
||||
HGLOBAL global=GlobalAlloc(GPTR, info.cbData);
|
||||
memcpy((LPVOID)global, data, info.cbData);
|
||||
|
||||
info.lpData=(LPVOID)global;
|
||||
|
||||
|
||||
|
||||
SendMessage(selectorMainWindow, WM_COPYDATA, NULL,
|
||||
(LPARAM)&info);
|
||||
|
||||
GlobalFree(global);
|
||||
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR lpCmd, int nShow){
|
||||
HINSTANCE lib=LoadLibrary(L"ResetKit");
|
||||
if(!lib){
|
||||
wchar_t buf[256];
|
||||
swprintf(buf, L"Cannot perform a soft reset.\n"
|
||||
L"ResetKit was not loaded (0x%08x).",
|
||||
GetLastError());
|
||||
showAlertWarning(buf, L"Error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef BOOL (*RKDoSoftResetProc)();
|
||||
RKDoSoftResetProc RKDoSoftReset=
|
||||
(RKDoSoftResetProc)GetProcAddress(lib, L"RKDoSoftReset");
|
||||
if(!RKDoSoftReset){
|
||||
wchar_t buf[256];
|
||||
swprintf(buf, L"Cannot perform a soft reset.\n"
|
||||
L"RKDoSoftReset not found (0x%08x).",
|
||||
GetLastError());
|
||||
showAlertWarning(buf, L"Error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!RKDoSoftReset()){
|
||||
wchar_t buf[256];
|
||||
swprintf(buf, L"Cannot perform a soft reset.\n"
|
||||
L"Operation failed (0x%08x).",
|
||||
GetLastError());
|
||||
showAlertWarning(buf, L"Error");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user