Android adb push在简中window乱码问题

adb readdir在windows(简体)下读取出来为GBK,而Android使用UTF-8编码,导致adb push传入机器内为乱码。

1. 安装mingw32
  sudo apt-get install mingw32

2. 修改adb源码
  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. 编译adb
  source build/envsetup.sh
  mm acp
  mm USE_MINGW=y adb 

4. 调试adb
  拷贝out/host/windows-x86/obj/EXECUTABLES/adb_intermediates到cygwin目录下,使用gdb调试(可修改Android.mk中的CFLAG为-O0调试)。 

 

adb_windows

posted @ 2011-12-01 22:47  Devァer、  阅读(2720)  评论(0编辑  收藏  举报