ADB Shell을 설정하고 처리하는 것이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#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;
}
 
cs


 이렇게하여, 출력이 가능하다.

 PIPE가 이상 없이 되기 위해서 설정하는 방법도 있다.

Posted by JunkMam
,