The window garbled problem in the simplicity of Android adb push

Source: Internet
Author: User

ADB readdir is read as GBK in Windows (simplified), while Android uses UTF-8 encoding, resulting in ADB push incoming machine garbled.

1. Install mingw32
Sudo apt-Get install mingw32

2. Modify ADB source code
File_sync_client.c

 1 diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c
2 old mode 100644
3 new mode 100755
4 index 64e393c..028b966
5 --- a/adb/file_sync_client.c
6 +++ b/adb/file_sync_client.c
7 @@ -26,6 +26,10 @@
8 #include <sys/types.h>
9 #include <zipfile/zipfile.h>
10
11 +#ifdef USE_MINGW
12 +#include <windows.h>
13 +#endif
14 +
15 #include "sysdeps.h"
16 #include "adb.h"
17 #include "adb_client.h"
18 @@ -568,6 +572,40 @@ struct copyinfo
19 //char data[0];
20 };
21
22 +static int GBKToUTF8(unsigned char *lpGBKStr, unsigned char *lpUTF8Str, int nUTF8StrLen)
23 +{
24 + wchar_t *lpUnicodeStr = NULL;
25 + int nRetLen = 0;
26 +
27 + if (!lpGBKStr) return 0;
28 +
29 + nRetLen = MultiByteToWideChar(CP_ACP, 0, (char *)lpGBKStr, -1, NULL, NULL);
30 + lpUnicodeStr = malloc(sizeof(WCHAR) * (nRetLen + 1));
31 + nRetLen = MultiByteToWideChar(CP_ACP, 0, (char *)lpGBKStr, -1, lpUnicodeStr, nRetLen);
32 +
33 + if (!nRetLen) return 0;
34 +
35 + nRetLen = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, NULL, 0, NULL, NULL);
36 + if (!lpUTF8Str)
37 + {
38 + if (lpUnicodeStr) free(lpUnicodeStr);
39 + return nRetLen;
40 + }
41 +
42 + if (nUTF8StrLen < nRetLen)
43 + {
44 + if (lpUnicodeStr) free(lpUnicodeStr);
45 + return 0;
46 + }
47 +
48 + nRetLen = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, (char *)lpUTF8Str,
49 + nUTF8StrLen, NULL, NULL);
50 +
51 + if (lpUnicodeStr) free(lpUnicodeStr);
52 +
53 + return nRetLen;
54 +}
55 +
56 copyinfo *mkcopyinfo(const char *spath, const char *dpath,
57 const char *name, int isdir)
58 {
59 @@ -577,12 +615,19 @@ copyinfo *mkcopyinfo(const char *spath, const char *dpath,
60 int ssize = slen + nlen + 2;
61 int dsize = dlen + nlen + 2;
62
63 +#ifdef USE_MINGW
64 + int name_len = GBKToUTF8((unsigned char *)name, NULL, NULL);
65 + char UTF8name[PATH_MAX];
66 + name_len = GBKToUTF8((unsigned char *)name, (unsigned char *)UTF8name, name_len);
67 + dsize = dlen + name_len + 2;
68 +#endif
69 +
70 copyinfo *ci = malloc(sizeof(copyinfo) + ssize + dsize);
71 if(ci == 0) {
72 fprintf(stderr,"out of memory\n");
73 abort();
74 }
75 -
76 +
77 ci->next = 0;
78 ci->time = 0;
79 ci->mode = 0;
80 @@ -591,13 +636,12 @@ copyinfo *mkcopyinfo(const char *spath, const char *dpath,
81 ci->src = (const char*)(ci + 1);
82 ci->dst = ci->src + ssize;
83 snprintf((char*) ci->src, ssize, isdir ? "%s%s/" : "%s%s", spath, name);
84 - snprintf((char*) ci->dst, dsize, isdir ? "%s%s/" : "%s%s", dpath, name);
85 + snprintf((char*) ci->dst, dsize, isdir ? "%s%s/" : "%s%s", dpath, UTF8name);
86
87 // fprintf(stderr,"mkcopyinfo('%s','%s')\n", ci->src, ci->dst);
88 return ci;
89 }
90
91 -
92 static int local_build_list(copyinfo **filelist,
93 const char *lpath, const char *rpath)
94 {

 

3. Compile ADB
Source build/envsetup. Sh
MM ACP
MM use_mingw = y ADB

4. debug ADB
Copy out/host/windows-x86/obj/executables/adb_intermediates to the cygwin directory and use GDB for debugging (you can modify cflag in Android. mk to-O0 for debugging ).

 

Adb_windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.