`
xuela_net
  • 浏览: 494678 次
文章分类
社区版块
存档分类
最新评论

Android adb “push pull”中文支持解决方案

 
阅读更多

Android adb “push pull”中文支持解决方案

在windows底下文件(夹)命名所采用的是GBK编码,而在Android中采用的UTF-8编码,所有使用adb 的push和pull命令时就会导致由于编码方式的不同而产生的错误,解决这一问题就只有对adb工具的源代码进行修改,让adb对文件名的编码进行相应的转换。

具体过程如下:使用ubuntu 12.04 下载android的源代码,具体过程参考网络,ubuntu一定要使用64位机,因为最新的android源代码只能在64位机进行编译。
http://source.android.com/
下载源代码可能需要比较长的时间,把机器挂在那,放一晚上基本就OK了。下载好源代码以后,就可以开始对adb的源码进行相应的修改。
adb的源码所在的目录是/system/core/adb
pull和push命令进行文件传输的主要的过程是位于file_sync_client.c这个文件中,在文件的开头部分增加,
#ifdef USE_MINGW
#include<windows.h>
#endif
头文件声明,然后增加两个GBK同UTF-8编码相互转换的函数
static int GBKToUTF8(char *lpGBKStr, char *lpUTF8Str, int nUTF8StrLen)
{
wchar_t *lpUnicodeStr = NULL;
int nRetLen = 0;

if (!lpGBKStr) return 0;

nRetLen = MultiByteToWideChar(CP_ACP, 0, (char *)lpGBKStr, -1, NULL, 0);
lpUnicodeStr = (wchar_t *)malloc(sizeof(WCHAR) * (nRetLen + 1));
nRetLen = MultiByteToWideChar(CP_ACP, 0, (char *)lpGBKStr, -1, lpUnicodeStr, nRetLen);

if (!nRetLen) return 0;

nRetLen = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, NULL, 0, NULL, 0);
if (!lpUTF8Str)
{
if (lpUnicodeStr) free(lpUnicodeStr);
return nRetLen;
}
if (nUTF8StrLen < nRetLen)
{
if (lpUnicodeStr) free(lpUnicodeStr);
return 0;
}
nRetLen = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, (char *)lpUTF8Str,nUTF8StrLen, NULL, 0);

if (lpUnicodeStr) free(lpUnicodeStr);

return nRetLen;
}
static int UTF8ToGBK(char *lpGBKStr,char *lpUTF8Str, int nGBKStrLen)
{
wchar_t *lpUnicodeStr=NULL;
int nRetLen =0;

if (!lpUTF8Str)return 0;

nRetLen=MultiByteToWideChar(CP_UTF8,0,(char*)lpUTF8Str,-1,NULL,NULL);
lpUnicodeStr = (wchar_t *)malloc(sizeof(WCHAR) * (nRetLen + 1));
nRetLen = MultiByteToWideChar(CP_UTF8, 0, (char *)lpUTF8Str, -1, lpUnicodeStr, nRetLen);

if (!nRetLen)return 0;
nRetLen = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, NULL, 0, NULL, NULL);


if (!lpGBKStr)
{
if (lpUnicodeStr) free(lpUnicodeStr);
return nRetLen;
}

if (nGBKStrLen < nRetLen)
{
if (lpUnicodeStr) free(lpUnicodeStr);
return 0;
}

nRetLen = WideCharToMultiByte(CP_ACP, 0, lpUnicodeStr, -1, (char *)lpGBKStr,nGBKStrLen, NULL, NULL);

if (lpUnicodeStr) free(lpUnicodeStr);

return nRetLen;
}

再添加了这两个编码的函数后,就需要修改copyinfo *mkcopyinfo这个函数,使这个函数增加对UTF8编码的支持:
copyinfo *mkcopyinfo(const char *spath, const char *dpath,
const char *sname, const char *dname,int isdir)
{
int slen = strlen(spath);
int dlen = strlen(dpath);
int snlen = strlen(sname);
int dnlen = strlen(dname);
int ssize = slen + snlen + 2;
int dsize = dlen + dnlen + 2;

copyinfo *ci = malloc(sizeof(copyinfo) + ssize + dsize);
if(ci == 0) {
fprintf(stderr,"out of memory\n");
abort();
}

ci->next = 0;
ci->time = 0;
ci->mode = 0;
ci->size = 0;
ci->flag = 0;
ci->src = (const char*)(ci + 1);
ci->dst = ci->src + ssize;
snprintf((char*) ci->src, ssize, isdir ? "%s%s/" : "%s%s", spath, sname);
snprintf((char*) ci->dst, dsize, isdir ? "%s%s/" : "%s%s", dpath, dname);

// fprintf(stderr,"mkcopyinfo('%s','%s')\n", ci->src, ci->dst);
return ci;
}
继续修改函数:
local_build_list();让该函数传进去的参数的名称为utf-8编码
static int local_build_list(copyinfo **filelist,
const char *lpath, const char *rpath)
{
DIR *d;
struct dirent *de;
struct stat st;
copyinfo *dirlist = 0;
copyinfo *ci, *next;

// fprintf(stderr,"local_build_list('%s','%s')\n", lpath, rpath);

d = opendir(lpath);
if(d == 0) {
fprintf(stderr,"cannot open '%s': %s\n", lpath, strerror(errno));
return -1;
}

while((de = readdir(d))) {
char stat_path[PATH_MAX];
char *name = de->d_name;

if(name[0] == '.') {
if(name[1] == 0) continue;
if((name[1] == '.') && (name[2] == 0)) continue;
}

#ifdef USE_MINGW
char utf8name[260];
int name_len=GBKToUTF8(name,NULL,0);
name_len=GBKToUTF8(name,utf8name,name_len);
#endif

if (strlen(lpath) + strlen(de->d_name) + 1 > sizeof(stat_path))
continue;
strcpy(stat_path, lpath);
strcat(stat_path, de->d_name);
stat(stat_path, &st);

if (S_ISDIR(st.st_mode)) {
ci = mkcopyinfo(lpath, rpath, name,name, 1);
#ifdef USE_MINGW
ci = mkcopyinfo(lpath,rpath,name,utf8name,1);
#endif
ci->next = dirlist;
dirlist = ci;
} else {
ci = mkcopyinfo(lpath, rpath, name, name,0);
#ifdef USE_MINGW
ci = mkcopyinfo(lpath,rpath,name,utf8name,0);
#endif
if(lstat(ci->src, &st)) {
fprintf(stderr,"cannot stat '%s': %s\n", ci->src, strerror(errno));
closedir(d);

return -1;
}
if(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) {
fprintf(stderr, "skipping special file '%s'\n", ci->src);
free(ci);
} else {
ci->time = st.st_mtime;
ci->mode = st.st_mode;
ci->size = st.st_size;
ci->next = *filelist;
*filelist = ci;
}
}
}

closedir(d);

for(ci = dirlist; ci != 0; ci = next) {
next = ci->next;
local_build_list(filelist, ci->src, ci->dst);
free(ci);

}


return 0;
}
以及相应的一些有关于名称编码的函数,现将修改好的c文件以及编译好的adb文件的下载链接提供如下
提供的下载地址为:
http://download.csdn.net/detail/shuaihj/5353463

分享到:
评论

相关推荐

    adb push pull中文支持解决方案

    解决adb push pull时,中文乱码,不能完成文件拷贝的问题。

    adb push不支持中文乱码的解决方案

    1.android adb push不支持中文乱码的解决方案. 2.在windows底下文件(夹)命名所采用的是GBK编码,而在Android中采用的UTF-8编码,所有使用adb 的push和pull命令时就会导致由于编码方式的不同而产生的错误,解决这一...

    解决adb push pull中文出现乱码截断的的adb.exe 版本34.01

    解决adb传输中文出现乱码的最新版adb.exe文件

    支持中文路径push/pull的adb

    1.Windows下面对Android4.2.2系列的手机进行adb调试; 2.支持中文路径的push和pull; 3.感谢csdn网友"水的发毛"提供win下的编译版本;

    ADB支持中文pull/push

    谷歌ADB工具,完美解决中文问题,可支持中文pull/push,支持读取中文目录,在实际项目中使用,需要的同学可以下载使用,如有问题请联系我

    adb push /adb pull工具

    【解决】当设备已root使用adb命令, 提示'adbd cannot run as root in production builds',adb push /adb pull 到系统目录 解决方案 解压密码:hkxgame.com

    android adb shell 命令大全

    android adb shell 命令大全 1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器): android create avd --name 名称 --...

    adb push 中文文件

    搞android开发的童鞋都知道,有时需要上传文件到SD卡中,但是苦于中文的不好对付(利用数据线,开启SD卡除外),这时用ADB PUSH相当方便,但是就是不支持中文(GBK),现在上传一个重写过的ADB工具,可以自动进行...

    解决adb传输中文出现乱码的最新版adb.exe文件

    1.解决adb在push 或者pull过程中因文件带有中文,出现中文乱码,文件失效的问题 2.重写adb.exe的源码,解决编码问题(Windows下为GBK,Android则为UTF-8)

    支持中文路径pull-push的adb源码.zip

    支持中文路径pull-push的adb源码.zip

    adb pull --sync 支持增量拉取设备文件到本地(windows版本adb),adb pull 增量同步

    官方adb push支持--sync增量同步本地文件到设备,但是pull不支持此参数,当需要从设备同步文件到电脑时不方便,每次都会全量同步。所以参考push的--sync,修改官方adb源码给adb pull 增加一个参数 --sync,支持增量...

    adb_push.bat

    想一想每一次将手机连接电脑并传入文件的繁琐过程,每次都要打开手机的文件夹,再将windows中的文件复制到手机中。有了这个脚本,只需要在windows上操作就可以完成文件的传送,无需去操作手机(但是需要手机连接电脑...

    Android Adb工具

    Android ADB工具,支持4.4以上系统,测试可正常使用~~~

    android adb 配置文件 ubuntu环境

    android adb 配置文件 ubuntu环境android adb 配置文件 ubuntu环境android adb 配置文件 ubuntu环境android adb 配置文件 ubuntu环境android adb 配置文件 ubuntu环境android adb 配置文件 ubuntu环境android adb ...

    android adb调试usb驱动

    android adb调试usb驱动 adb shell adb push adb pull

    vs2008 编译adb 支持4.2 android 系统(增加push 命令的进度)

    1)支持4.2 android 系统连接 2)修复了一些山寨手机识别不了的问题。 3)安装APK 支持中文名字 ...4) PUSH,PULL 命令支持中文 5) 不会无缘无故的退出了。还有一些其他的优化了 6) 增加push 命令的进度

    android adb

    配置android开发环境需要的adb文件。

    adb push中文路径文件名丢失后缀的解决方法

    在本篇文章里小编给各位整理的是关于adb push中文路径文件名丢失后缀的解决方法以及知识点整理,有需要的朋友们参考下。

Global site tag (gtag.js) - Google Analytics