📄 resource.c
字号:
BYTE lpDecBuf[COMP_BLOCK_SIZE];
DWORD cfile=0xffffffff,cblock=0xffffffff;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
DWORD
SC_GetRomFileBytes(
DWORD type,
DWORD count,
DWORD pos,
LPVOID buffer,
DWORD nBytesToRead
)
{
TOCentry *tocptr;
FILESentry *filesptr;
DWORD dwBlock,bRead,csize, fullsize, dwGlobalFileIndex;
LPVOID buffercopy;
ROMChain_t *pROM = ROMChain;
DWORD dwResult;
dwGlobalFileIndex = count;
// verify the buffer given by user.
if ((KERN_TRUST_FULL != pCurProc->bTrustLevel)
&& !SC_MapPtrWithSize (buffer, nBytesToRead, hCurProc)) {
return 0;
}
// DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileBytes entry: %8.8lx %8.8lx %8.8lx %8.8lx %8.8lx\r\n",
// type,count,pos,buffer,nBytesToRead));
if (type == 2) {
while (pROM && (count >= pROM->pTOC->numfiles)) {
count -= pROM->pTOC->numfiles;
pROM = pROM->pNext;
}
if (!pROM) {
// DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileBytes exit: %8.8lx\r\n",0));
return 0;
}
tocptr = &(((TOCentry *)&pROM->pTOC[1])[pROM->pTOC->nummods]);
filesptr = &(((FILESentry *)tocptr)[count]);
if (pos > filesptr->nRealFileSize) {
// DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileBytes exit: %8.8lx\r\n",0));
return 0;
}
if (pos + nBytesToRead > filesptr->nRealFileSize) {
nBytesToRead = filesptr->nRealFileSize - pos;
}
if (!nBytesToRead) {
fullsize = 0;
} else {
fullsize = nBytesToRead;
buffercopy = buffer;
LockPages(buffercopy, fullsize, 0, LOCKFLAG_WRITE);
EnterCriticalSection(&RFBcs);
if (filesptr->nRealFileSize == filesptr->nCompFileSize) {
memcpy(buffer, (LPBYTE)filesptr->ulLoadOffset+pos, nBytesToRead);
} else if (!filesptr->nCompFileSize) {
memset(buffer, 0, nBytesToRead);
} else {
while (nBytesToRead) {
dwBlock = pos / COMP_BLOCK_SIZE;
bRead = nBytesToRead;
if ((pos + bRead-1) / COMP_BLOCK_SIZE != dwBlock) {
bRead = COMP_BLOCK_SIZE - (pos & (COMP_BLOCK_SIZE-1));
}
if ((dwGlobalFileIndex != cfile) || (dwBlock != cblock)) {
if (dwBlock == filesptr->nRealFileSize / COMP_BLOCK_SIZE) {
csize = filesptr->nRealFileSize - (COMP_BLOCK_SIZE*dwBlock);
} else {
csize = COMP_BLOCK_SIZE;
}
if (bRead == csize) {
dwResult = DecompressROM((LPBYTE)filesptr->ulLoadOffset,
filesptr->nCompFileSize, buffer,
csize, dwBlock*COMP_BLOCK_SIZE);
if ((dwResult == CEDECOMPRESS_FAILED) || (dwResult == 0)) {
LeaveCriticalSection(&RFBcs);
UnlockPages(buffercopy, fullsize);
return 0;
}
} else {
dwResult = DecompressROM((LPBYTE)filesptr->ulLoadOffset,
filesptr->nCompFileSize, lpDecBuf,
csize, dwBlock*COMP_BLOCK_SIZE);
if ((dwResult == CEDECOMPRESS_FAILED) || (dwResult == 0)) {
LeaveCriticalSection(&RFBcs);
UnlockPages(buffercopy, fullsize);
return 0;
}
cfile = dwGlobalFileIndex;
cblock = dwBlock;
memcpy(buffer, lpDecBuf + (pos & (COMP_BLOCK_SIZE-1)), bRead);
}
} else {
memcpy(buffer, lpDecBuf + (pos & (COMP_BLOCK_SIZE-1)), bRead);
}
buffer = (LPVOID)((LPBYTE)buffer+bRead);
nBytesToRead -= bRead;
pos += bRead;
}
}
LeaveCriticalSection(&RFBcs);
UnlockPages(buffercopy, fullsize);
}
// DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileBytes exit: %8.8lx\r\n",fullsize));
return fullsize;
}
// DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileBytes exit: %8.8lx\r\n",0));
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Return address and size of uncompressed ROM file. Used to map directly from ROM.
BOOL
FindROMFile(
DWORD type,
DWORD count,
LPVOID* ppvAddr, // Ptr to return physical address of file
DWORD* pdwLen // Ptr to return size of file
)
{
ROMChain_t *pROM = ROMChain;
TOCentry *tocptr;
FILESentry *filesptr;
if (type == 2) {
while (pROM && (count >= pROM->pTOC->numfiles)) {
count -= pROM->pTOC->numfiles;
pROM = pROM->pNext;
}
if (pROM) {
tocptr = &(((TOCentry *)&pROM->pTOC[1])[pROM->pTOC->nummods]);
filesptr = &(((FILESentry *)tocptr)[count]);
if (filesptr->nRealFileSize == filesptr->nCompFileSize) {
*ppvAddr = (LPVOID)filesptr->ulLoadOffset;
*pdwLen = filesptr->nRealFileSize;
return TRUE;
}
}
}
return FALSE;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
BOOL
SC_GetRomFileInfo(
DWORD type,
LPWIN32_FIND_DATA lpfd,
DWORD count
)
{
TOCentry *tocptr;
FILESentry *filesptr;
ROMChain_t *pROM = ROMChain;
extern const PFNVOID Win32Methods[];
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo entry: %8.8lx %8.8lx %8.8lx\r\n",type,lpfd,count));
// validate user pointer
switch (type) {
case 1:
case 2:
if (!SC_MapPtrWithSize(lpfd, sizeof(WIN32_FIND_DATAW), hCurProc)) {
return FALSE;
}
break;
case 3:
if (!SC_MapPtrWithSize((LPVOID)count, sizeof(DWORD), hCurProc)) {
return FALSE;
}
// fall through to check lpfd
case 4:
if (!SC_MapPtrWithSize(lpfd, sizeof(DWORD), hCurProc)) {
return FALSE;
}
break;
}
switch (type) {
case 1:
// MODULES section of ROM
while (pROM && (count >= pROM->pTOC->nummods)) {
count -= pROM->pTOC->nummods;
pROM = pROM->pNext;
}
if (!pROM) {
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",FALSE));
return FALSE;
}
tocptr = &(((TOCentry *)&pROM->pTOC[1])[count]);
lpfd->dwFileAttributes = (tocptr->dwFileAttributes | FILE_ATTRIBUTE_INROM | FILE_ATTRIBUTE_ROMMODULE) & ~FILE_ATTRIBUTE_ROMSTATICREF;
lpfd->ftCreationTime = tocptr->ftTime;
lpfd->ftLastAccessTime = tocptr->ftTime;
lpfd->ftLastWriteTime = tocptr->ftTime;
lpfd->nFileSizeHigh = 0;
lpfd->nFileSizeLow = tocptr->nFileSize;
AToUCopy(lpfd->cFileName,tocptr->lpszFileName,MAX_PATH);
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",TRUE));
return TRUE;
case 2:
// FILES section of ROM
while (pROM && (count >= pROM->pTOC->numfiles)) {
count -= pROM->pTOC->numfiles;
pROM = pROM->pNext;
}
if (!pROM) {
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",FALSE));
return FALSE;
}
tocptr = &(((TOCentry *)&pROM->pTOC[1])[pROM->pTOC->nummods]);
filesptr = &(((FILESentry *)tocptr)[count]);
lpfd->dwFileAttributes = filesptr->dwFileAttributes | FILE_ATTRIBUTE_INROM;
lpfd->ftCreationTime = filesptr->ftTime;
lpfd->ftLastAccessTime = filesptr->ftTime;
lpfd->ftLastWriteTime = filesptr->ftTime;
lpfd->nFileSizeHigh = 0;
lpfd->nFileSizeLow = filesptr->nRealFileSize;
AToUCopy(lpfd->cFileName,filesptr->lpszFileName,MAX_PATH);
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",TRUE));
return TRUE;
case 3:
*(LPVOID *)lpfd = Win32Methods;
*(BOOL UNALIGNED *)count = bAllKMode;
return TRUE;
case 4:
*(LPVOID *)lpfd = KmodeEntries();
return TRUE;
case 0xffffffff:
for (count = 0; count < pROM->pTOC->nummods; count++) {
tocptr = &(((TOCentry *)&pROM->pTOC[1])[count]);
if (!StrCmpAPascW(tocptr->lpszFileName,lpfd->cFileName)) {
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",TRUE));
return TRUE;
}
}
for (count = 0; count < pROM->pTOC->numfiles; count++) {
tocptr = &(((TOCentry *)&pROM->pTOC[1])[pROM->pTOC->nummods]);
filesptr = &(((FILESentry *)tocptr)[count]);
if (!StrCmpAPascW(filesptr->lpszFileName,lpfd->cFileName)) {
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",TRUE));
return TRUE;
}
}
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",FALSE));
return FALSE;
}
DEBUGCHK(0);
DEBUGMSG(ZONE_ENTRY,(L"SC_GetRomFileInfo exit: %8.8lx\r\n",FALSE));
return FALSE;
}
/*
@doc BOTH EXTERNAL WINCEUSER
@func int | LoadString| Load a string resource
@parm HINSTANCE | hinst | Identifies an instance of the module whose
executable file contains the string resource.
@parm UINT | wID | Specifies the integer identifier of the string to
be loaded.
@parm LPTSTR | lpBuffer | Points to the buffer to receive the string.
@parm int | cchBuffer | Specifies the size of the buffer, in characters.
The string is truncated and null terminated if it is longer than the number of
characters specified.
@comm Follows the Win32 reference description with the following modification.
@comm If <p lpBuffer> is NULL, <p cchBuffer> is ignored and the return value is
a pointer to the requested string, which is read-only.
@comm The length of the string, including any null terminator if present, can be
found in the word preceding the string.
@devnote All string resources are Unicode.
*/
/* This code was modified from Win95. */
int SC_LoadStringW(
HINSTANCE hInstance,
UINT wID,
LPWSTR lpBuffer,
int nBufMax)
{
HRSRC hResInfo;
HANDLE hStringSeg;
LPWSTR lpsz;
int cch;
int Ret =0;
DEBUGMSG (ZONE_ENTRY, (L"SC_LoadStringW: 0x%8.8lx 0x%x 0x%8.8lx %d\n",
hInstance, wID, lpBuffer, nBufMax));
// Make sure the parms are valid.
if (lpBuffer && (nBufMax < 0 || !nBufMax--))
return(0);
cch = 0;
// check parameters
if (lpBuffer && !SC_MapPtrWithSize (lpBuffer, nBufMax, hCurProc)) {
KSetLastError (pCurThread, ERROR_INVALID_PARAMETER);
return 0;
}
__try {
// String Tables are broken up into 16 string segments. Find the segment
// containing the string we are interested in.
if ((hResInfo = SC_FindResource(hInstance, MAKEINTRESOURCE((wID >> 4) + 1), RT_STRING))
&& (hStringSeg = SC_LoadResource(hInstance, hResInfo))) {
// map the resouce to the secure section if it's a DLL
// since it's always going to be there
if (ZeroPtr (hStringSeg) >= (DWORD) DllLoadBase)
lpsz = (LPWSTR) MapPtrProc (ZeroPtr (hStringSeg), ProcArray);
else
lpsz = (LPWSTR) hStringSeg;
// Move past the other strings in this segment.
wID &= 0x0F;
while (TRUE) {
cch = *lpsz++;
if (wID-- == 0)
break;
lpsz += cch;
}
if (lpBuffer) {
// Don't copy more than the max allowed.
if (cch > nBufMax)
cch = nBufMax;
// Copy the string into the buffer
memcpy (lpBuffer, lpsz, cch * sizeof(TCHAR));
} else if (cch) { // don't return zero-length strings
// The return value is the string itself
// return a zero based address.
Ret = ZeroPtr (lpsz);
}
}
//else failed
if (lpBuffer) { // if we are not returning the string as the return value
// Append a NULL
lpBuffer[Ret = cch] = 0;
}
}__except (EXCEPTION_EXECUTE_HANDLER) {
// Ret is already 0.
KSetLastError (pCurThread, ERROR_INVALID_PARAMETER);
}
DEBUGMSG (ZONE_ENTRY, (L"SC_LoadStringW Exits: %d\n", Ret));
return Ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -