Beispiel #1
0
cFile::cFile(cOSDef::fileHandle handle,
             const uint flags /* = cFile::READ */,
             bool closeHandle /* = true */) :
    m_handle(INVALID_FILE_HANDLE)
{
    openHandle(handle, flags, closeHandle);
}
Beispiel #2
0
/*
 *  ======== UARTUtils_systemInit ========
 */
Void UARTUtils_systemInit(Int index)
{
    systemHandle = openHandle(index, FALSE);
    if (systemHandle == NULL) {
        Log_print1(Diags_USER1, "Failed to open UART %d", index);
    }
}
Beispiel #3
0
void ZProfile::openRoot (ZBoolean aCreate)
{
  ZFUNCTRACE_DEVELOP ("ZProfile::openRoot(ZBoolean aCreate)");
  if (iRootHandle == 0 || (aCreate && iRootReadOnly))
      {
        closeRoot ();
        HKEY parentKey (0);
        ZString path;
        while (!parentKey)
            {
              path = iRoot;
              ZString token (splitPath (path));
              for (unsigned i = 0;
                   i < sizeof (sysHandles) / sizeof (SystemHandle); i++)
                if (token == sysHandles[i].iName)
                    {
                      parentKey = sysHandles[i].iHandle;
                      break;
                    }           // if
              if (!parentKey)
                iRoot =
                  ZString (sysHandles[0].iName) + (char) ZC_PATHSEPARATOR +
                  iRoot;
            }                   // while
        if (path.length ())
          iRootHandle = openHandle (parentKey, path, aCreate);
        else
          iRootHandle = parentKey;
        iRootReadOnly = !aCreate;
      }                         // if
}                               // openRoot
Beispiel #4
0
/*
 *  ======== UARTUtils_loggerIdleInit ========
 */
Void UARTUtils_loggerIdleInit(Int index)
{
    Assert_isTrue(ports[index].open == FALSE, NULL);
    loggerHandle = openHandle(index, TRUE);
    if (loggerHandle == NULL) {
        System_printf("Failed to open UART %d", index);
    }
}
Beispiel #5
0
//==============================================================================
FileInputStream::FileInputStream (const File& f)
    : file (f),
      fileHandle (0),
      currentPosition (0),
      totalSize (0),
      needToSeek (true)
{
    openHandle();
}
//==============================================================================
FileInputStream::FileInputStream (const File& f)
    : file (f),
      fileHandle (nullptr),
      currentPosition (0),
      totalSize (0),
      status (Result::ok()),
      needToSeek (true)
{
    openHandle();
}
Beispiel #7
0
//==============================================================================
FileOutputStream::FileOutputStream (const File& f, const int bufferSize_)
    : file (f),
      fileHandle (nullptr),
      status (Result::ok()),
      currentPosition (0),
      bufferSize (bufferSize_),
      bytesInBuffer (0),
      buffer ((size_t) jmax (bufferSize_, 16))
{
    openHandle();
}
Beispiel #8
0
void ZProfile::openPath (ZBoolean aCreate)
{
  ZFUNCTRACE_DEVELOP ("ZProfile::openPath(ZBoolean aCreate)");
  if (iPathHandle == 0 || (aCreate && iPathReadOnly))
      {
        closePath ();
        openRoot (aCreate);
        if (iPath.size ())
          iPathHandle = openHandle ((HKEY) iRootHandle, iPath, aCreate);
        else
          iPathHandle = iRootHandle;
        iPathReadOnly = !aCreate;
      }                         // if
}                               // openPath
Beispiel #9
0
cFile::cFile(const cString& filename,
             const uint flags /* = cFile::READ */) :
    m_handle(INVALID_FILE_HANDLE)
{
    DWORD dwShareMode = 0;
    DWORD dwDesiredAccess = 0;
    DWORD dwCreationDisposition = OPEN_EXISTING;

    /* fill in the dwDesiredAccess variable */
    if (flags & READWRITE)
        dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
    else
    {
        if (flags & READ)
            dwDesiredAccess|= GENERIC_READ;

        if (flags & WRITE)
            dwDesiredAccess|= GENERIC_WRITE;
    }

    /* fill in the dwSharedMode variable */
    if (flags & SHARE_READ)
        dwShareMode|= FILE_SHARE_READ;

    if (flags & SHARE_WRITE)
        dwShareMode|= FILE_SHARE_WRITE;


    /* fill in the dwCreationDisposition variable */
    if (flags & CREATE)
        dwCreationDisposition = CREATE_ALWAYS;

    HANDLE handle = CreateFile(OS_CSTRING(filename.getBuffer()),
                          dwDesiredAccess,
                          dwShareMode,
                          NULL,
                          dwCreationDisposition,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL);

    /* Test for open errors */
    if (handle == INVALID_FILE_HANDLE)
    {
        cString msg = cOS::getLastErrorString() + ": " + filename;
        XSTL_THROW(cFileException, msg.getBuffer());
    }

    openHandle(handle, flags, true);
}
Beispiel #10
0
/*
 *  ======== UARTUtils_deviceopen ========
 */
int UARTUtils_deviceopen(const char *path, unsigned flags, int mode)
{
    Int fd;
    UART_Handle handle;
    

    /* Get the UART specified for opening. */
    fd = path[0] - '0';   

    handle = openHandle(fd, FALSE);
    
    if(handle == NULL) {
        return (-1);
    }
    else {        
        return (fd);
    }
}
int main(int argc, char* argv[])
{	
	BOOL found = FALSE;
	unsigned int memAddr = 0;
	unsigned char readBuffer[READ_BUFF_SIZE];
	unsigned char writeBuffer[] = { 0x90, 0x90 };
	unsigned int buffChar;
	unsigned char tempChar;
	int ret = 0;
	int i = 0;


	HANDLE handle = openHandle();
	if( handle == INVALID_HANDLE_VALUE )
		{ printf("Failed to open driver code %d\n", GetLastError()); return 1; }
	

	/*found = findPattern(handle, &memAddr);
	if(found)
		{ printf("found at addr %u\n", memAddr); }
	else
		{ printf("not found\n"); }*/


	ZeroMemory(readBuffer, sizeof(readBuffer));
	ret = readKernelMemory(handle, 4143055082, readBuffer, sizeof(readBuffer));
	if(ret < 0)
		{ printf("Error reading kernel memory\n"); }
	else
	{
		printf("Got %d bytes\n", ret);
		for(i = 0; i < ret; i++)
		{
			memcpy(&tempChar, &readBuffer[i], 1);
			buffChar = tempChar;
			printf("0x%X\n", buffChar);			
		}
	}


	ret = writeKernelMemory(handle, 4143055082, writeBuffer, sizeof(writeBuffer));
	if(ret < 0)
		{ printf("Error writing kernel memory\n"); }
	else
		{ printf("Memory written!\n"); }


	ZeroMemory(readBuffer, sizeof(readBuffer));
	ret = readKernelMemory(handle, 4143055082, readBuffer, sizeof(readBuffer));
	if(ret < 0)
	{ printf("Error reading kernel memory\n"); }
	else
	{
		printf("Got %d bytes\n", ret);
		for(i = 0; i < ret; i++)
		{
			memcpy(&tempChar, &readBuffer[i], 1);
			buffChar = tempChar;
			printf("0x%X\n", buffChar);			
		}
	}


	return 0;
}