int DoReq(CLEAN_STRING s) { int code_size = 0; int data_size = 0; int code = NULL; int data = NULL; int label = 0; int n_libraries, s_buffer; char *hServerLibraryBufferView = NULL; char *hClientLibraryBufferView = NULL; char *hClientView; char *hServerView; HINSTANCE library; int i; char bs[100]; HANDLE h; #ifdef STATIC_CLIENT_CHANNEL if( first_time == 0 ) { InitializeStaticClient(); first_time = 1; // i = 1; } #endif // message header b[MESSAGE_TYPE] = (char) ADDRESS_REQUEST; b[SIZE_OF_MESSAGE] = s->length; *((DWORD *) (b+DATA_START)) = GetCurrentProcessId(); // Copy module/label-string rsncopy (b + DATA_START + sizeof(DWORD), s->characters, s->length); b[(s->length)+ DATA_START + sizeof(DWORD)] = 0; Send(); #ifdef DEBUG msg( "CLIENT: tussen Send() en Receive()" ); #endif // Receive code and data sizes if( (Receive()) == SERVER_KILLED) { ExitProcess(-1); } if( b[MESSAGE_TYPE] == ADDRESS_UNKNOWN ) { // Allocate code #ifdef DEBUG msg( "CLIENT: allocate code and data" ); #endif code_size = *((int *) (b+DATA_START)); if( code_size != 0 ) { code = (int *) VirtualAlloc( NULL, code_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); if( !code ) { error(); msg( "DoReq 1" ); ExitProcess(-1); } *((int *) (b+DATA_START)) = code; } // Allocate data data_size = *((int *) (b+DATA_START+sizeof(int))); if( data_size != 0 ) { data = (int *) VirtualAlloc( NULL, data_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); if( !data ) { error(); ExitProcess(-1); } *((int *) (b+DATA_START+sizeof(int))) = data; } Send(); // Receive a label or a request to return the base // addresses of used libraries if( (Receive()) == SERVER_KILLED) { msg( "sever killed"); ExitProcess(-1); } /* ** Need base addresses of libraries */ if( b[MESSAGE_TYPE] == NEED_BASE_OF_LIBRARIES ) { #ifdef DEBUG && CLIENT_DLL msg( "CLIENT: return base addresses of libraries" ); #endif n_libraries = *((int *) (b+DATA_START)); s_buffer = *((int *) (b+DATA_START+sizeof(int))); #ifdef DEBUG && CLIENT_DLL sprintf( bs, "n_libraries: %d, size: %d", n_libraries, s_buffer); msg( bs ); #endif /* ** Open the server buffer containing the names of the ** needed libraries */ hServerLibraryBufferView = CreateBuffer( "ServerLibraryBuffer", s_buffer, TRUE); hServerView = hServerLibraryBufferView; /* ** Allocate a client buffer to contain the base addresses ** of all libraries */ //n_libraries = *((int *) (b+DATA_START)); #ifdef DEBUG && CLIENT_DLL sprintf( bs, "Client: creating buffer %d bytes", n_libraries * sizeof(HINSTANCE) ); msg( bs ); #endif hClientLibraryBufferView = CreateBuffer( "ClientLibraryBuffer", n_libraries * sizeof(HINSTANCE), FALSE ); hClientView = hClientLibraryBufferView; #ifdef DEBUG && CLIENT_DLL sprintf( bs, "Client: <%s>", hServerLibraryBufferView ); msg( bs ); #endif // msg( "Client libraries: "); for(i = 0; i < n_libraries; i++ ) { library = LoadLibrary(hServerLibraryBufferView); #ifdef DEBUG msg( hServerLibraryBufferView ); #endif if( library == NULL ) { error(); msg( hServerLibraryBufferView); msg( "channel.c: 2" ); ExitProcess(-1); } *((int *) (hClientLibraryBufferView)) = library; hServerLibraryBufferView += rstrlen(hServerLibraryBufferView) + 1; hClientLibraryBufferView += sizeof(HINSTANCE); } /* for */ Send(); CloseBuffer( hServerView ); /* ** Receive label */ #ifdef DEBUG && CLIENT_DLL msg ( "CLIENT: receive label " ); #endif Receive(); CloseBuffer( hClientView ); // msg( "NEED_BASE_OF_LIBRARIES not implemented" ); } /* if */ } if( b[MESSAGE_TYPE] == ADDRESS_KNOWN ) { // Receive reply containing label //Receive(); label = *((int *) (b+DATA_START)); //msg((char *)code); } else { msg("!client: unknown message"); ExitProcess(-1); } #ifdef DEBUG && CLIENT_DLL msg( "CLIENT: label obtained" ); #endif return( label ); }