Esempio n. 1
0
bool wceRunProcess(const char *process, const char *args)
{
	HRESULT hRapiResult;
	HRESULT hr;
	PROCESS_INFORMATION pi;    
	WCHAR wszProgram[MAX_PATH];
	WCHAR wszArgs[MAX_PATH];

#ifdef UNICODE
	int nResult = 0;
	nResult = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED, process, strlen(process)+1, wszProgram, ARRAYSIZE(wszProgram));
	if(0 == nResult) { return false;}
	if (args) {
		nResult = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED, args, strlen(args)+1, wszArgs, ARRAYSIZE(wszArgs));
		if(0 == nResult) 
			return false;
	}
#else
	hr = StringCchCopy(wszProgram, ARRAYSIZE(wszProgram), argv[1]);
	if(FAILED(hr)) return true;
#endif
	if (wceConnect()) {
		if (!CeCreateProcess(wszProgram, wszArgs, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) {
			_tprintf( TEXT("CreateProcess failed with Errorcode = %ld\n"), CeGetLastError());
			return false;
		}
		CeCloseHandle( pi.hProcess);
		CeCloseHandle( pi.hThread);
	}
	wceDisconnect();
    return true;
}
Esempio n. 2
0
int copyExecutable (TCHAR *file_name, TCHAR *app_dir)
{
	TCHAR exe_fullpath[MAX_PATH];
	int retval = 0;
	HANDLE hDest, hSrc;
	BYTE  buffer[5120];
	DWORD dwNumRead, dwNumWritten;

	USES_CONVERSION;
	
	_tcscpy(exe_fullpath, app_dir);
	_tcscat(exe_fullpath, _T("\\"));
	_tcscat(exe_fullpath, app_name);
	_tcscat(exe_fullpath, _T(".exe"));


	hSrc = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE == hSrc) {
		_tprintf( TEXT("Unable to open host file\n"));
		return EXIT_FAILURE;
	}

	hDest = CeCreateFile(exe_fullpath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE == hDest ) {
		_tprintf( TEXT("Unable to open target WinCE file\n"));
		return CeGetLastError();
	}

	do {
		if(ReadFile(hSrc, &buffer, sizeof(buffer), &dwNumRead, NULL)) {
			if (!CeWriteFile(hDest, &buffer, dwNumRead, &dwNumWritten, NULL)) {
				_tprintf( TEXT("Error !!! Writing WinCE file\n"));
				goto copyFailure;
				}
			} else {
				_tprintf( TEXT("Error !!! Reading host file\n"));
				goto copyFailure;
		}
		_tprintf( TEXT("."));                                        
	} while (dwNumRead);
	_tprintf( TEXT("\n"));

	CeCloseHandle( hDest);
	CloseHandle (hSrc);

	return EXIT_SUCCESS;

copyFailure:
	CeCloseHandle( hDest);
	CloseHandle (hSrc);
/*

	if (wcePutFile (T2A(file_name), T2A(exe_fullpath)))
		return EXIT_SUCCESS;
*/
	return EXIT_FAILURE;
}
int rapi_mkdir(char *dir) {
    HRESULT hr;
    WCHAR* wide_path = NULL;
    char *path = NULL;
    
    path = (char *) strdup(dir);
    
    hr = CeRapiInit();

    if (RAPI_FAILED(hr))
    {
        fprintf(stderr, "Unable to initialize RAPI: %s\n",
                synce_strerror(hr));
        if (wide_path)
            wstr_free_string(wide_path);

        if (path)
            free(path);

        CeRapiUninit();
        return (-1);
    }

    convert_to_backward_slashes(path);
    wide_path = wstr_from_utf8(path);
    wide_path = adjust_remote_path(wide_path, true);
    
    if (!CeCreateDirectory(wide_path, NULL))
    {
        fprintf(stderr, "Failed to create directory '%s': %s\n",
                path,
                synce_strerror(CeGetLastError()));
        if (wide_path)
            wstr_free_string(wide_path);

        if (path)
            free(path);

        CeRapiUninit();
        return (-2);
    }

    if (wide_path)
        wstr_free_string(wide_path);

    if (path)
        free(path);

    CeRapiUninit();
    return 0;
}
int rapi_run(char *program, char *parameters)
{
	int result = 1;
	HRESULT hr;
	WCHAR* wide_program = NULL;
	WCHAR* wide_parameters = NULL;
	PROCESS_INFORMATION info;
    char *tmpprogram = NULL;

    tmpprogram = (char *) strdup(program);
    
	hr = CeRapiInit();

	if (RAPI_FAILED(hr))
	{
		fprintf(stderr, "Unable to initialize RAPI: %s\n", 
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(tmpprogram);
	wide_program = wstr_from_utf8(tmpprogram);
	if (parameters)
		wide_parameters = wstr_from_utf8(parameters);

	memset(&info, 0, sizeof(info));
	
	if (!CeCreateProcess(
				wide_program,
				wide_parameters,
				NULL,
				NULL,
				false,
				0,
				NULL,
				NULL,
				NULL,
				&info
				))
	{
		fprintf(stderr, "Failed to execute '%s': %s\n", 
				tmpprogram,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	CeCloseHandle(info.hProcess);
	CeCloseHandle(info.hThread);

	result = 0;

exit:
	wstr_free_string(wide_program);
	wstr_free_string(wide_parameters);

	if (tmpprogram)
		free(tmpprogram);

	CeRapiUninit();
	return result;
}
Esempio n. 5
0
//ccw 2 aug 2000
//this also now launches the client on the CE device using
//the RAPI.H interface.
remoteDevice::remoteDevice(){
  int index = 0;                      // Integer index
  TCHAR szError[100];                 // Error message string

  SOCKET WinSocket = INVALID_SOCKET;  // Window socket
          // Socket for communicating 
                                      // between the server and client
  SOCKADDR_IN local_sin,              // Local socket address
              accept_sin;             // Receives the address of the 
                                      // connecting entity
  int accept_sin_len;                 // Length of accept_sin

  WSADATA WSAData;                    // Contains details of the Winsock
                                      // implementation


  // Initialize Winsock.
  if (WSAStartup (MAKEWORD(1,1), &WSAData) != 0) 
  {
    /*wsprintf (szError, TEXT("WSAStartup failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }

  // Create a TCP/IP socket, WinSocket.
  if ((WinSocket = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 
  {
    /*wsprintf (szError, TEXT("Allocating socket failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }

 // Fill out the local socket's address information.
  local_sin.sin_family = AF_INET;
  local_sin.sin_port = htons (PORTNUM);  
  local_sin.sin_addr.s_addr = htonl (INADDR_ANY);

  // Associate the local address with WinSocket.
  if (bind (WinSocket, 
            (struct sockaddr *) &local_sin, 
            sizeof (local_sin)) == SOCKET_ERROR) 
  {
    /*wsprintf (szError, TEXT("Binding socket failed. Error: %d"), 
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);*/
    closesocket (WinSocket);
    success = FALSE;
  }

  // Establish a socket to listen for incoming connections.
  if (listen (WinSocket, MAX_PENDING_CONNECTS) == SOCKET_ERROR) 
  {
    /*wsprintf (szError, 
              TEXT("Listening to the client failed. Error: %d"),
              WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    closesocket (WinSocket);
    success = FALSE;
  }

  accept_sin_len = sizeof (accept_sin);



	//// ccw 2 aug 2000
	//launch the CE client when we are sure the socket creation has
	//succeded.
	////
	HRESULT hr = CeRapiInit();   
	WCHAR *appName= L"testRemoteCE.exe";
	bool result;
	//PROCESS_INFORMATION  procInfo;
	if ( FAILED(hr) )    {
		cout<<" SPAWN FAILED"<<endl;
		exit(-1);
	}
	
	result = 1;
	if ( result ==0 )    {
		cout<<"ERR--"<< CeGetLastError() <<endl;
		exit(-11);  
	}
	hr = CeRapiGetError();
	if ( FAILED(hr) )    {     
		cout<<"ERR2--"<<endl;
		exit(-11);  
	}
	CeRapiUninit();

  // Accept an incoming connection attempt on WinSocket.
  deviceSocket = accept (WinSocket, 
                       (struct sockaddr *) &accept_sin, 
                       (int *) &accept_sin_len);

  // Stop listening for connections from clients.
  closesocket (WinSocket);

  if (deviceSocket == INVALID_SOCKET) 
  {
    /*wsprintf (szError, TEXT("Accepting connection with client failed.")
              TEXT(" Error: %d"), WSAGetLastError ());
    MessageBox (NULL, szError, TEXT("Error"), MB_OK);
	*/
    success = FALSE;
  }else{
	//good connection.
	//set up the baseTramp stuff....
	  if(!RemoteGetTrampTemplate()){
		cout <<" ERROR.. GETTING TRAMP ASM"<<endl;
	        exit(-1);
	 }
  }

}
Esempio n. 6
0
File: prun.c Progetto: pfeilbr/repo
int main( int argc, char *argv[])
{
    RAPIINIT ri;
    HRESULT hRapiResult;
    DWORD dwRet;
    PROCESS_INFORMATION pi;

    if (2 != argc)
    {
        _tprintf( TEXT("Syntax: PRUN <WinCE EXE>"));
        return 1;
    }
    else
#ifdef UNICODE
    MultiByteToWideChar(
            CP_ACP,    
            MB_PRECOMPOSED,
            argv[1],
            strlen(argv[1])+1,
            wszProgram,
            sizeof(wszProgram));
#else
    _tcscpy( wszProgram, argv[1]);
#endif

    _tprintf( TEXT("Connecting to Windows CE..."));
    
    ri.cbSize = sizeof(RAPIINIT);
    hRapiResult = CeRapiInitEx(&ri);
    dwRet = WaitForSingleObject(ri.heRapiInit, 500);
    
    if ((dwRet != WAIT_OBJECT_0) || !SUCCEEDED(ri.hrRapiInit))
    {
        // Could not initialize Rapi
        CeRapiUninit();
        _tprintf( TEXT("Failed\n"));
        return 1;
    }

    _tprintf( TEXT("Success\n"));

    if (!CeCreateProcess(
            wszProgram,
            NULL,
            NULL,
            NULL,
            FALSE,
            0,
            NULL,
            NULL,
            NULL,
            &pi))
    {
        _tprintf( TEXT("CreateProcess failed with Errorcode = %ld\n"), CeGetLastError());
    }
    else
    {
        CeCloseHandle( pi.hProcess);
        CeCloseHandle( pi.hThread);
    }
        
    _tprintf( TEXT("Closing connection ..."));
    CeRapiUninit();
    _tprintf( TEXT("Done\n"));

    return 0;
}
Esempio n. 7
0
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* program = NULL;
	char* parameters = NULL;
	HRESULT hr;
	WCHAR* wide_program = NULL;
	WCHAR* wide_parameters = NULL;
	PROCESS_INFORMATION info;

	if (!handle_parameters(argc, argv, &program, &parameters))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(program);
	wide_program = wstr_from_current(program);
	if (parameters)
		wide_parameters = wstr_from_current(parameters);

	memset(&info, 0, sizeof(info));
	
	if (!CeCreateProcess(
				wide_program,
				wide_parameters,
				NULL,
				NULL,
				false,
				0,
				NULL,
				NULL,
				NULL,
				&info
				))
	{
		fprintf(stderr, "%s: Failed to execute '%s': %s\n", 
				argv[0],
				program,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	CeCloseHandle(info.hProcess);
	CeCloseHandle(info.hThread);

	result = 0;

exit:
	wstr_free_string(wide_program);
	wstr_free_string(wide_parameters);

	if (program)
		free(program);

	if (parameters)
		free(parameters);

	CeRapiUninit();
	return result;
}
Esempio n. 8
0
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* source = NULL;
	char* dest = NULL;
	HRESULT hr;
	WCHAR* wide_source = NULL;
	WCHAR* wide_dest = NULL;
	
	if (!handle_parameters(argc, argv, &source, &dest))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(source);
	wide_source = wstr_from_current(source);
	wide_source = adjust_remote_path(wide_source, true);

	convert_to_backward_slashes(dest);
	wide_dest   = wstr_from_current(dest);
	wide_dest   = adjust_remote_path(wide_dest, true);

	if (!CeMoveFile(wide_source, wide_dest))
	{
		fprintf(stderr, "%s: Cannot move '%s' to '%s': %s\n", 
				argv[0],
				source,
				dest,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	result = 0;

exit:
	wstr_free_string(wide_source);
	wstr_free_string(wide_dest);

	if (source)
		free(source);

	if (dest)
		free(dest);

	CeRapiUninit();
	return result;
}