#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define MAX_LINE 4096
int main(int argc, char** argv)
{
HANDLE write_in, write_out;
HANDLE read_in, read_out;
SECURITY_ATTRIBUTES sec;
long unsigned int writen=0;
long unsigned int readn=0;
int rtv;
char command[80] = {0,};
char buffer[MAX_LINE];
STARTUPINFO si={0,};
PROCESS_INFORMATION pi;
//pthread
pthread_t read_pthread;
pthread_t write_pthread;
sec.nLength=sizeof(SECURITY_ATTRIBUTES);
sec.bInheritHandle=TRUE;
sec.lpSecurityDescriptor=NULL;
CreatePipe(&write_out,&write_in,&sec,0);
CreatePipe(&read_in,&read_out,&sec,0);
sprintf(command,"./adb.exe shell",NULL);
si.cb=sizeof(STARTUPINFO);
si.hStdInput=write_out;
si.hStdOutput=read_out;
si.dwFlags=STARTF_USESTDHANDLES;
rtv=CreateProcess(NULL,
command,
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
&si,
&pi);
if(!rtv){
printf("Error");
return -1;
}
int i=0;
int n = 0;
char tmpkey=0;
char filenames[100];
FILE *fp=NULL;
while(1){
writen=0;
readn=0;
for(i=0;i<MAX_LINE;i++){
buffer[i]=0x00;
}
//ReadFile(read_in,buffer,sizeof(buffer),&readn,NULL);
//ReadFile(read_in,buffer,sizeof(buffer),&readn,FILE_FLAG_OVERLAPPED);
ReadFile(read_in,buffer,sizeof(buffer),&readn,NULL);
if(!strncmp(buffer,"exit",4)){
break;
}
printf("%s",buffer);
for(i=0;i<MAX_LINE;i++){
buffer[i]=0x00;
}
fgets(buffer,MAX_LINE,stdin);
//WriteFile(write_in,buffer,strlen(buffer),&writen,NULL);
if(!strncmp(buffer,"exit\n",5)){
WriteFile(write_in,buffer,strlen(buffer),&writen,NULL);
break;
}
WriteFile(write_in,buffer,strlen(buffer),&writen,NULL);
}
while(system("start ./adb.exe kill-server"));
CloseHandle(write_in);
CloseHandle(write_out);
CloseHandle(read_in);
CloseHandle(read_out);
return 0;
}