int _tmain(int argc, _TCHAR* argv[]) { // Initialize RAPI HRESULT hr = CeRapiInit(); hr = CeDeleteFile(L"\\Program Files\\shell\\avmshell.exe"); if (argc>1) { // Filename will be passed in argv[0] HANDLE hFile = ::CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile==INVALID_HANDLE_VALUE) { printf("Error copying file %s to device",argv[1]); CeRapiUninit(); return -1; } // Create the file on the device in the temp directory WCHAR ceFilename[MAX_PATH]; DWORD dwmblen = ::MultiByteToWideChar(CP_ACP, MB_COMPOSITE, (const char *)argv[1], strlen((const char *)argv[1]), ceFilename, MAX_PATH); ceFilename[dwmblen] = 0; WCHAR cePath[MAX_PATH]; HANDLE ceFile = CeCreateFile(L"\\Program Files\\shell\\avmshell.exe", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL); char localBuf[4096]; DWORD dwBufsize=4096, dwFilesize = ::GetFileSize(hFile, NULL); if (dwFilesize<4096) dwBufsize = dwFilesize; DWORD dwCeBytes=0, dwRead; while (ReadFile(hFile, localBuf, dwBufsize, &dwRead, NULL)) { hr = CeWriteFile(ceFile, (void*)localBuf, dwRead, &dwCeBytes, NULL); dwFilesize -= dwRead; if (dwFilesize<4096) dwBufsize = dwFilesize; if (dwBufsize<=0) break; } } // Uninitialize RAPI CeRapiUninit(); return 0; }
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 main() { VERIFY_HRESULT(CeRapiInit()); CEOSVERSIONINFO version; memset(&version, 0, sizeof(CEOSVERSIONINFO)); version.dwOSVersionInfoSize = sizeof(CEOSVERSIONINFO); printf("size = 0x%x\n", sizeof(CEOSVERSIONINFO)); TEST_NOT_EQUAL(0, CeGetVersionEx(&version)); printf("dwMajorVersion=%i, dwMinorVersion=%i, dwBuildNumber=%i, dwPlatformId=%i, szCSDVersion=\"%s\"\n", version.dwMajorVersion, version.dwMinorVersion, version.dwBuildNumber, version.dwPlatformId, // 3 == VER_PLATFORM_WIN32_CE from_unicode(version.szCSDVersion)); if (3 != version.dwPlatformId) { printf("Platform ID is not 3!\n"); return TEST_FAILED; } VERIFY_HRESULT(CeRapiUninit()); return TEST_SUCCEEDED; }
int main() { VERIFY_HRESULT(CeRapiInit()); WCHAR buffer[MAX_PATH]; DWORD length; // XXX: CSIDL_DESKTOPDIRECTORY does not work, but that's probably OK //TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_DESKTOPDIRECTORY, MAX_PATH, buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_FAVORITES, MAX_PATH, buffer)); printf("CSIDL_FAVORITES: %s\n", from_unicode(buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_FONTS, MAX_PATH, buffer)); printf("CSIDL_FONTS: %s\n", from_unicode(buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_PERSONAL, MAX_PATH, buffer)); printf("CSIDL_PERSONAL: %s\n", from_unicode(buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_PROGRAMS, MAX_PATH, buffer)); printf("CSIDL_PROGRAMS: %s\n", from_unicode(buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_RECENT, MAX_PATH, buffer)); printf("CSIDL_RECENT: %s\n", from_unicode(buffer)); TEST_NOT_FALSE(length = CeGetSpecialFolderPath(CSIDL_STARTUP, MAX_PATH, buffer)); printf("CSIDL_STARTUP: %s\n", from_unicode(buffer)); VERIFY_HRESULT(CeRapiUninit()); return TEST_SUCCEEDED; }
int main(int argc, char* argv[]) { HRESULT hRapiResult; _tprintf (TEXT("Connecting to Windows CE...\n")); hRapiResult = CeRapiInitEx (); if (FAILED(hRapiResult)) { _tprintf (TEXT("Failed\n")); return -1; } CeGetSystemInfo(); CeRapiUninit (); return 0; }
int main(int argc, char** argv) { int result = 0; RapiConnection* connection = NULL; HRESULT hr; char *shortcut, *target; WCHAR* wide_shortcut = NULL; WCHAR* wide_target = NULL; WCHAR *tmp, *tmp_quote; int tmpsize; if (!handle_parameters(argc, argv, &shortcut, &target)) 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)); result = 1; goto exit; } convert_to_backward_slashes(shortcut); wide_shortcut = wstr_from_current(shortcut); wide_shortcut = adjust_remote_path(wide_shortcut, true); convert_to_backward_slashes(target); wide_target = wstr_from_current(target); wide_target = adjust_remote_path(wide_target, true); /* Wrap target in quotes. This is required for paths with spaces (for some reason) */ tmp_quote = wstr_from_current("\""); tmpsize = (wstrlen(wide_target) + 3) * sizeof(WCHAR); tmp = malloc(tmpsize); if (!tmp) goto exit; wstrcpy(tmp,tmp_quote); if (!wstr_append(tmp,wide_target,tmpsize)) goto exit; if (!wstr_append(tmp,tmp_quote,tmpsize)) goto exit; wstr_free_string(wide_target); wstr_free_string(tmp_quote); wide_target = tmp; BOOL res = CeSHCreateShortcut(wide_shortcut, wide_target); if (!res) { fprintf(stderr, "%s: Unable to create shortcut to '%s' at '%s': %s\n", argv[0],target,shortcut, synce_strerror(hr)); result = 1; goto exit; } exit: wstr_free_string(wide_shortcut); wstr_free_string(wide_target); if (shortcut) free(shortcut); if (target) free(target); CeRapiUninit(); rapi_connection_destroy(connection); return result; }
void wceDisconnect(void) { //_tprintf( TEXT("Closing connection to Windows CE...")); CeRapiUninit(); //_tprintf( TEXT("Done\n")); }
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; }
int rapi_copy(char *source, char *dest) { int result = 1; HRESULT hr; time_t start; time_t duration; size_t bytes_copied = 0; hr = CeRapiInit(); if (RAPI_FAILED(hr)) { fprintf(stderr, "Unable to initialize RAPI: %s\n", synce_strerror(hr)); goto exit; } if (!dest) { char* p; if (is_remote_file(source)) { for (p = source + strlen(source); p != source; p--) { if (*p == '/' || *p == '\\') { dest = (char *) strdup(p+1); break; } } if (!dest || '\0' == dest[0]) { fprintf(stderr, "Unable to extract destination filename from source path '%s'\n", source); goto exit; } } else { WCHAR mydocuments[MAX_PATH]; char* mydocuments_ascii = NULL; p = strrchr(source, '/'); if (p) p++; else p = source; if ('\0' == *p) { fprintf(stderr, "Unable to extract destination filename from source path '%s'\n", source); goto exit; } if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments)) { fprintf(stderr, "Unable to get the \"My Documents\" path.\n"); goto exit; } dest = (char *) calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1); mydocuments_ascii = wstr_to_ascii(mydocuments); strcat(dest, ":"); strcat(dest, mydocuments_ascii); strcat(dest, "\\"); strcat(dest, p); wstr_free_string(mydocuments_ascii); } } if (0 == strcmp(source, dest)) { fprintf(stderr, "You don't want to copy a file to itself.\n"); goto exit; } if (is_remote_file(source) && is_remote_file(dest)) { /* * * Both are remote; use CeCopyFile() * */ if (!remote_copy(source, dest)) goto exit; } else { start = time(NULL); /* * * At least one is local, Use the AnyFile functions * */ if (!anyfile_copy(source, dest, &bytes_copied)) goto exit; } result = 0; exit: CeRapiUninit(); return result; }
int main(int argc, char** argv) { int result = 1; RapiConnection* connection = NULL; char* source = NULL; char* dest = NULL; HRESULT hr; time_t start; time_t duration; size_t bytes_copied = 0; 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; } if (!dest) { char* p; if (is_remote_file(source)) { for (p = source + strlen(source); p != source; p--) { if (*p == '/' || *p == '\\') { dest = strdup(p+1); break; } } if (!dest || '\0' == dest[0]) { fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n", argv[0], source); goto exit; } } else { WCHAR mydocuments[MAX_PATH]; char* mydocuments_ascii = NULL; p = strrchr(source, '/'); if (p) p++; else p = source; if ('\0' == *p) { fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n", argv[0], source); goto exit; } if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments)) { fprintf(stderr, "%s: Unable to get the \"My Documents\" path.\n", argv[0]); goto exit; } dest = calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1); mydocuments_ascii = wstr_to_current(mydocuments); strcat(dest, ":"); strcat(dest, mydocuments_ascii); strcat(dest, "\\"); strcat(dest, p); wstr_free_string(mydocuments_ascii); } } if (0 == strcmp(source, dest)) { fprintf(stderr, "You don't want to copy a file to itself.\n"); goto exit; } if (is_remote_file(source) && is_remote_file(dest)) { /* * Both are remote; use CeCopyFile() */ if (!remote_copy(source, dest)) goto exit; } else { start = time(NULL); /* * At least one is local, Use the AnyFile functions */ if (!anyfile_copy(source, dest, argv[0], &bytes_copied)) goto exit; duration = time(NULL) - start; if (0 == duration) printf("File copy took less than one second!\n"); else printf("File copy of %i bytes took %li minutes and %li seconds, that's %li bytes/s.\n", bytes_copied, duration / 60, duration % 60, bytes_copied / duration); } result = 0; exit: if (source) free(source); if (dest) free(dest); CeRapiUninit(); return result; }
//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); } } }
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; }
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, ¶meters)) 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; }
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; }