Android ADB "Push Pull" Chinese Support Solution

Source: Internet
Author: User

Android ADB "Push Pull" Chinese Support Solution

Under the Windows File (folder) Naming adopts GBK encoding, while in Android UTF-8 encoding, all the push and pull commands using ADB may cause errors due to different encoding methods. To solve this problem, only the source code of the ADB tool can be modified, let ADB convert the file name encoding accordingly.

The specific process is as follows: Use Ubuntu 12.04 to download the android source code. For details about the process, refer to the network. Ubuntu must use a 64-bit server, because the latest Android source code can only be compiled on a 64-bit server.
Http://source.android.com/
It may take a long time to download the source code. If you put the machine there, it will be okay after one night. After downloading the source code, you can start to modify the source code of ADB.
The directory where ADB source code is located is/system/CORE/ADB
The main process of pull and push commands for file transmission is located in the file file_sync_client.c, which is added at the beginning of the file,
# Ifdef use_mingw
# Include <windows. h>
# Endif
Header file declaration, then add two GBK functions that convert each other with UTF-8 Encoding
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;
}

After adding these two encoding functions, You need to modify the copyinfo * mkcopyinfo function to enable utf8 encoding support:
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", Spath, sname );
Snprintf (char *) ci-> DST, dsize, isdir? "% S/": "% S % s", dpath, dname );

// Fprintf (stderr, "mkcopyinfo ('% s',' % s') \ n", CI-> SRC, CI-> DST );
Return ci;
}
Continue to modify the function:
Local_build_list (); Name of the parameter passed in by the function is UTF-8 encoded
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;
}
As well as some functions related to name encoding, the following links are provided to download the modified C file and the compiled ADB file:
Provided:
Http://download.csdn.net/detail/shuaihj/5353463

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.