Author Archives: lytsing

汉化 google+ 1.02 Android客户端


正在研究G+ Android客户的一些设计方法,发现蛮复杂的。

很早就知道如何汉化 apk了,只是不屑于干那样的活,觉得没什么技术含量。上电子市场,发现好多人留言希望赶紧出中文版,需求蛮大的。台湾的兄弟早搞出来了,目前没有发现有简体中文的。大陆的兄弟们,是不是要跟上呢?小弟e文功底差,只能照着 google+ 网页中文版翻译一些基本的字段。翻译真是苦差活,随着使用G+的深入使用,会持续更新。有错误不妥之处,请留言提醒哈。

适用机型: Android 2.1以上
下载地址: http://lytsing.org/downloads/gplus-1.0.2.apk

更新:
忙了一个下午,再搜索,发现 Jay Chua 同学已经搞过了。看了他空间,网页字体不错,我也升级了wp。以后最好跟他一起汉化,免得浪费时间。

翻译心得:
1. 认真是一种能力,而不是仅仅是态度,既然要翻译了,就努力做好,不能做到一半就丢了。
2. 注意标点符号,注意圆角。

Android Market 最新版本 2.3.6

亮点: 在设置多一下个选项,如图:

下载地址: http://lytsing.org/downloads/Vending-2.3.6-enable-paid.apk

如包名所示,我修改了几行代码,使它可以查看付费软件。

安装后,设置 – 应用程序 – 管理应用程序 – 全部 – 电子市场 – 清除缓存

适用范围:

Android 2.2,刷过 使用 test-key 签名的 第三方 rom ,比如大名鼎鼎的 CM.否则遇到下面的FC:

I/ActivityManager( 116): Process com.android.protips (pid 537) has died and restarted (pid 0).
E/DatabaseUtils( 364): Writing exception to parcel
E/DatabaseUtils( 364): java.lang.SecurityException: Permission Denial: writing com.google.android.gsf.settings.GoogleSettingsPrS
E/DatabaseUtils( 364): at android.content.ContentProvider
$Transport.enforceWritePermission(ContentProvider.java:325)
E/DatabaseUtils( 364): at android.content.ContentProvider $Transport.insert(ContentProvider.java:173)
E/DatabaseUtils( 364): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
E/DatabaseUtils( 364): at android.os.Binder.execTransact(Binder.java:288)
E/DatabaseUtils( 364): at dalvik.system.NativeStart.run(Native
Method)
W/dalvikvm( 353): threadid=33: thread exiting with uncaught exception (group=0x4001d7c8)
E/AndroidRuntime( 353): FATAL EXCEPTION: work-service-handler-thread
E/AndroidRuntime( 353): java.lang.SecurityException: Permission Denial: writing com.google.android.gsf.settings.GoogleSettingsPS
E/AndroidRuntime( 353): at android.os.Parcel.readException(Parcel.java:1247)
E/AndroidRuntime( 353): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
E/AndroidRuntime( 353): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)

可能会出现的问题:
(一)下载软件,一直卡在“Download paused”/“下载暂停”。

解决方法:
1. 把SDCARD卸载。
2. 删除 “/mnt/secure/asec/smdl2tmp1.asec” 或者 sd卡上的空目录 “.android_secure”.

Android apk forward lock

forward lock 干啥用?Android market有用到,开发者上传apk时候,可以设置。官方文档也说明了

http://developer.android.com/guide/appendix/market-filters.html

Forward-Locked Applications

To forward lock an application, set copy protection to “On” when you upload the application to Market. Market will not show copy-protected applications on developer devices or unreleased devices.

查看源代码,frameworks/base/core/java/android/content/pm/PackageManager.java 注释说明:

标识本应用属于受限应用,应用将会被安装到保护目录,只有该应用可以访问代码段和不属于resource的asset资源。

那么安装这样的一个 apk,需要设置 FORWARD LOCK 标志位。

1758     public abstract void installPackage(
1759             Uri packageURI, IPackageInstallObserver observer, int flags,
1760             String installerPackageName);

Android 1.5, PackageManager.FORWARD_LOCK_PACKAGE = 0x00000001;

Android 2.2 改成了 INSTALL_FORWARD_LOCK

ip地址查询(C++版)

最近公司服务器被hack,怀疑的ip每次都登录ip138.com查询,很麻烦,想起维护新糊涂的时候,曾经写个小程序统计用户ip地址来源。ip数据库是纯真版,代码是参考别人的,忘了是谁写的,我就只修改了main函数。

/**
 * file: ip_from.cpp
 * @date: 2007.4.20
 *
 */

#include <cstdio>
#include <cstdlib>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <ios>
#include <fstream>
#include <vector>
#include <iterator>
#include <stdexcept>
#include <algorithm>
using namespace std;

typedef unsigned int IP_TYPE;

const int  IP_SIZE = 4;
const int  OFFSET_SIZE = 3;
const int  INDEX_RECORD_SIZE = IP_SIZE + OFFSET_SIZE;

class IpLocater {
private:
    FILE* dbfile;
    int   first_index;
    int   last_index;
    enum  { REDIRECT_MODE_1 = 0x01, REDIRECT_MODE_2 = 0x02 };
protected:

public:
    IpLocater(const string dbfilename = "QQWry.Dat")
    {
        dbfile = fopen(dbfilename.c_str(),"rb");
        if (!dbfile) {
            printf("can not open the ip db file %s\n", dbfilename.c_str());
            exit(0);
        }

        fread(&first_index, sizeof(int), 1, dbfile);
        fread(&last_index, sizeof(int), 1, dbfile);
    }
    ~IpLocater(){
        fclose(dbfile);
    }

    int getRecordCount() const {
        return (last_index - first_index ) / INDEX_RECORD_SIZE + 1;
    }
    
    string readString(const int offset = 0){
        if (offset) {
            fseek(dbfile, offset, SEEK_SET);
        }

        char ch = fgetc(dbfile);
        ostringstream sstr ;
        while (ch != 0 && ch != EOF) {
            sstr << ch;
            ch = fgetc(dbfile);
        }
        return sstr.str();
    }

    inline int readInt3(const int offset = 0 ) {
        if (offset) {
            fseek(dbfile,offset,SEEK_SET);
        }
    
        int result = 0;
        fread(&result, sizeof(char), 3, dbfile);
        return result;
    }

    string readAreaAddr(const int offset = 0) {
        if (offset) {
            fseek(dbfile, offset, SEEK_SET);
        }
        char b = fgetc(dbfile);
        if (b == REDIRECT_MODE_1 || b == REDIRECT_MODE_2) {
            int areaOffset = 0;
            fread(&areaOffset, 1, 3, dbfile);
            if (areaOffset) {
                return readString(areaOffset);
            } else {
                return "Unkown";
            }
        } else {
            fseek(dbfile, -1, SEEK_CUR);
            return readString();
        }
    }

    unsigned int readLastIp(const int offset) {
        fseek(dbfile, offset, SEEK_SET);
        unsigned int ip = 0;
        fread(&ip, sizeof(unsigned int), 1, dbfile);
        return ip;
    }

    string readFullAddr(const int offset, int ip = 0) {
        string address = "";

        fseek(dbfile, offset + 4, SEEK_SET);

        char ch = fgetc(dbfile);
        if (ch == REDIRECT_MODE_1) {
            int countryOffset = 0;
            fread(&countryOffset,sizeof(char),3,dbfile);
            
            fseek(dbfile, countryOffset, SEEK_SET);
            char byte = fgetc(dbfile);
            if (byte == REDIRECT_MODE_2 ) {
                int p = 0;
                fread(&p, 1, 3, dbfile);
                address = readString(p);
                fseek(dbfile, countryOffset + 4, SEEK_SET);
            } else {
                address = readString(countryOffset);
            }
            address += readAreaAddr(); // current position
        } else if (ch == REDIRECT_MODE_2) {
            int p = 0;
            fread(&p, 1, 3, dbfile);
            address = readString(p);
            address += readAreaAddr(offset + 8);
        } else {
            fseek(dbfile, -1, SEEK_CUR);
            address = readString();
            address += readAreaAddr();
        }

        return address;
    }

    void printAddr(int first = 0, int count = 100){
        int record_count  = getRecordCount();
        for (int i = first; i< first+count && i<record_count; i++)
        {
            fseek(dbfile,i*INDEX_RECORD_SIZE+first_index,SEEK_SET);
            unsigned int ip = 0;
            fread(&ip,sizeof(unsigned int),1,dbfile);
            int offset = 0;
            fread(&offset,1,OFFSET_SIZE,dbfile);
            cout << ip2string(ip) << "-" << ip2string(readLastIp(offset))
                << readFullAddr(offset) << endl;
        }
    }

    int find(unsigned int ip,int left ,int right) {
        if (right - left == 1) {
            return left;
        } else {
            int middle = (left + right) / 2;
            
            int offset = first_index + middle * INDEX_RECORD_SIZE;
            fseek(dbfile,offset,SEEK_SET);
            unsigned int new_ip = 0;
            fread(&new_ip,sizeof(unsigned int),1,dbfile);
            
            if (ip >= new_ip) {
                return find(ip,middle,right);
            } else {
                return find(ip,left,middle);
            }
        }
    }

    string getIpAddr( unsigned int ip){
        int index = find(ip,0, getRecordCount() - 1 );
        int index_offset = first_index + index * INDEX_RECORD_SIZE + 4;
        int addr_offset = 0;
        fseek(dbfile,index_offset,SEEK_SET);
        fread(&addr_offset,1,3,dbfile);
        string address = readFullAddr( addr_offset,ip );
        return address;
    }
    
    string ip2string( unsigned int ip) const{
        ostringstream sstr;
        sstr << ((ip & 0xff000000)>>24) ;
        sstr << "." << ((ip & 0xff0000)>>16);
        sstr << "." << ((ip & 0xff00)>>8);
        sstr << "." << (ip & 0xff);
        return sstr.str();
    }

    unsigned int string2ip(const string ipstr)const{
        string str = ipstr;
        unsigned int ip = 0;
        int p = 0;
        p = str.find(".");
        ip += atoi(str.substr(0,p).c_str());
        ip <<= 8;
        str = str.substr(p+1,str.length());
        p = str.find(".");
        ip += atoi(str.substr(0,p).c_str());
        ip <<= 8;
        str = str.substr(p+1,str.length());
        p = str.find(".");
        ip += atoi(str.substr(0,p).c_str());
        ip <<= 8;
        ip += atoi(str.substr(p+1,str.length()).c_str());
        return ip;
    }

    string getIpAddr(string ip){

        return getIpAddr( string2ip( ip ) );
    }
};

int main(int argc, char* argv[])
{
    IpLocater locater("/var/opt/QQWry.Dat");
#if 0   
    if (argc > 1) {
        string ip = argv[1];
        cout << locater.getIpAddr(ip) << endl;
    } else {
        string str;
        while (cin >> str) {
            cout << locater.getIpAddr(str) << endl;
        }
    }
#endif

    long counter = 0;

    if (argc > 1) {
        string file_name = argv[1];
        ifstream infile(file_name.c_str(), ios::in);

        if (!infile) {
            cerr << "oops: unable to open log file"
                << file_name << '\n';
            return -1;
        }

        string tmp;
        vector<string> vect;

        try {
            while (getline(infile, tmp, '\n'))
                vect.push_back(tmp.substr(0, tmp.find(' ')));
        } catch (exception& e) {
            cout << e.what() << '\n';
        }

        sort(vect.begin(), vect.end());
        vector<string>::iterator it = unique(vect.begin(), vect.end());
        typedef vector<string>::const_iterator iter;
        streamsize prec = cout.precision();

        for (iter i = vect.begin(); i != it; ++i) {
            ++counter;
            cout << setprecision(18) << *i << '\t';
            cout << setprecision(prec) << locater.getIpAddr(*i) << endl;
        }
    } else {
        string str;
        while (cin >> str) {
            cout << locater.getIpAddr(str) << endl;
        }
    }

    cout << "Today the web access ip total is: " << counter << endl;

    return 0;
}

编译:
g++ -Wall -o ip_from ip_from.cpp

代码写死了,记得ip纯真数据库放在 /var/opt/QQWry.Dat 主要用来分析apache的日志。

newytht:~/bin$ cat stat_ip_from

#!/bin/sh

now=`date +"%Y%m%d"`
log_file="/usr/local/apache2/logs/access_log.$now"

if [ -f $log_file ]; then
	ipnum=`./ip_from '  < /usr/local/apache2/logs/access_log.$now ;
	echo "$ipnum"  >> /home/bbs/0Announce/bbslist/ip_stat_from
fi

adb 通过 wifi 连接 Android 设备

1. 需要 root 权限

代码修改点:

/system/extras/su/su.c

60     /* Until we have something better, only root and the shell can use su. */
61     myuid = getuid();
62     if (myuid != AID_ROOT && myuid != AID_SHELL) {
63         fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
64         return 1;
65     }

67   if(setgid(gid) || setuid(uid)) {
68       fprintf(stderr,"su: permission denied\n");
69        return 1;
70    }

把63,64,68,69 行注释掉,编译生成su,然后push到设备。

adb push su /system/xbin/ 
adb shell chmod 6755 /system/xbin/su

2. 安装 adbwireless 软件,一键搞定
在电子市场上搜 adb,前面两个随便选一个都行。
adb-wifi in market

如果电子市场上不了,在 Terminal Emulator 直接输入:

setprop service.adb.tcp.port 8000
stop adbd
start adbd

通过adb 连上设备,下面是我机器上的操作结果:
deli@deli-laptop:~$ adb connect 192.168.1.103:8000
already connected to 192.168.1.103:8000
deli@deli-laptop:~$ adb shell
# busybox sh
/ #

Pages: Prev 1 2 3 4 5 6 7 8 9 10 ... 19 20 21 Next