作者归档:superaj

一个获取APK的packagename,versionCode,versionName

因为应用经常我这里分析包名,所以写了此bat

使用方法,另存下面的内容为xxx.bat,然后把apk直接拖到此bat上,就会把信息直接赋值到剪切板,直接粘贴就是了

ps:需要android环境支持

 

@echo off
title 获取包名
echo 获取包名
aapt d badging %1 >>qq.txt
findstr "\<package: name=\'*\'\>" qq.txt >>qq2.txt
del qq.txt
CLIP < qq2.txt
del qq2.txt
echo 结束!
#pause
exit

 

自动修改android模拟器的imei的小程序

该程序实现一下功能,

1,修改android模拟器的imei,

2,自动启动android模拟器

3,运行开机启动程序,ps:这个开机启动程序apk就没放出来了。

4,停止android模拟器;

重复1,2,3过程

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
 /**
  * @param args
  */
 public static void main(String[] args) {
  try {
     while(true){//
         eidtEmulator();//修改imei

         Runtime rt = Runtime.getRuntime();  
         String command = "C:\\Program Files\\Android\\android-sdk\\tools\\emulator -avd AVD-10";    
         rt.exec(command);  // 运行android模拟器
         System.out.println("success run");
         Thread.sleep(2*60*1000);//  等待2分钟后,停止android模拟器
         if(findRunningWindowsProcess("emulator-arm.exe")){
               killRunningWindowsProcess("emulator-arm.exe");
        }
   }
  } catch (IOException e) {
   e.printStackTrace();
  } catch (Exception e) {
   e.printStackTrace();
  }  
 }

 public static void eidtEmulator() throws Exception{
     String oldFilePath = "C:\\Program Files\\Android\\android-sdk\\tools\\emulator-arm.exe ";
     String newFilePath = "C:\\Program Files\\Android\\android-sdk\\tools\\emulator-arm1.exe";
     FileInputStream in = new FileInputStream(oldFilePath);
     FileOutputStream out = new FileOutputStream(newFilePath);
     byte bytes[] = new byte[1];
     byte gsnbytes[] = new byte[3];
     byte imeiBytes[] = new byte[15];
     int count;
     while ((count = in.read(bytes)) != -1) {
           out.write(bytes);
           if (bytes[0] == 0x43) {// if is char 'C'
                    count = in.read(gsnbytes);
                    if (count == -1) {
                         break;
                    }
                    out.write(gsnbytes);
                    if (gsnbytes[0] == 0x47 && gsnbytes[1] == 0x53 && gsnbytes[2] == 0x4E) {//if is char 'GSN'
                         count = in.read(bytes);//read char '.'
                         if (count == -1) {
                                break;
                          }
                          out.write(bytes);
                          count = in.read(imeiBytes);//read old imei
                         if (count == -1) {
                                 break;
                          }
                          byte[] imeis = getIMEIBytes();
                          out.write(imeis);//write new imei;
                     }
               }
        }
  in.close();
  out.close();
  File oldFile = new File(oldFilePath);
  oldFile.delete();
  File newFile = new File(newFilePath);
  newFile.renameTo(oldFile);

 }

 public static byte[] getIMEIBytes() {//随即生成15位imei号
       StringBuffer bff = new StringBuffer();
       byte imeiBytes[] = new byte[15];
       for(int i=0;i<imeiBytes.length;i++){
                int num = (int) Math.round(Math.random()*8);
                bff.append(num);
                imeiBytes[i] = Byte.parseByte("3"+num, 16);
         }
      //  printArray(imeiBytes);
       System.err.println("start imei: "+bff.toString());
       return imeiBytes;
 }

 public static void printArray(byte bytes[]) {
  StringBuffer buff = new StringBuffer();
  for (byte b : bytes) {
   buff.append(String.format("%02X", b) + " ");
  }
   System.out.println(buff.toString());
 }

 public static boolean killRunningWindowsProcess(String processName){   
        try {   
            Runtime.getRuntime().exec("taskkill /IM " + processName);   
            System.out.println("kill process successful");   
//            System.out.println("Process " + processName + " was killed. Mission completed.");   
            return true;   
        } catch (Exception ex) {   
            ex.printStackTrace();   
            System.out.println("kill process fail");   
            System.out.println("Misson failed.");   
            return false;   
        }   
    }   
 public static boolean findRunningWindowsProcess(String processName) {   
        BufferedReader bufferedReader = null;   
        Process proc = null;   
        try {   
            proc = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq " + processName + "\"");   
            bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));   
            String line;   
            while ((line = bufferedReader.readLine()) != null) {   
                if (line.contains(processName)) {   
                    return true;   
                }   
            }   
            return false;   
        } catch (Exception ex) {   
            ex.printStackTrace();   
            return false;   
        } finally {   
            if (bufferedReader != null) {   
                try {   
                    bufferedReader.close();   
                } catch (Exception ex) {   
                }   
            }   
            if (proc != null) {   
                try {   
                    proc.destroy();   
                } catch (Exception ex) {   
                }   
            }   
        }   
    }  
}

 

bat获取页面内容

URL = "http:\\pic.zhengqianer.com"
Set strIE = CreateObject("InternetExplorer.Application")
strIE.Visible = False
strIE.Navigate(URL)
Do While strIE.ReadyState <> 4
Loop
str = strIE.document.body.innerHTML
strIE.quit

Set FSO = CreateObject("scripting.filesystemobject")
set strfile = FSO.CreateTextFile("temp.txt",true,true)
strfile.write str
Set FSO = Nothing

 

bat文件比较

1.txt和2.txt两个文件,比较文件是否相同,如果相同退出dos,不相同执行一个3.bat文件

@echo off
fc 1.txt 2.txt>nul
if not %errorlevel%==0 (start "" 3.bat)
exit

 

apache自带压力测试工具ab的使用

AB(ApacheBench) 是 Apache 自带的超文本传输协议 (HTTP) 性能测试工具。 其 设计意图是描绘当前所安装的 Apache 的执行性能, 主要是显示 Apache 每秒可以处理多少个请求。

 

该工具是 Apache 自带的工具。 安装 了 Apache Http Server , 就有了 ap 程序。   Apache Server 可以从 Apache 官网直接下载:

 

http://httpd.apache.org/download.cgi#apache22

 

安装完后,在 apache 的 Bin 目录下有 ab.exe 程序。 这个就是 我们的 AB 工具。

 

AB 工具的使用方法:

 

C: >cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>ab

ab: wrong number of arguments

Usage: ab [options] [http://]hostname[:port]/path

Options are:

-n requests     Number of requests to perform

-c concurrency  Number of multiple requests to make

-t timelimit    Seconds to max. wait for responses

-b windowsize   Size of TCP send/receive buffer, in bytes

-p postfile     File containing data to POST. Remember also to set -T

-u putfile      File containing data to PUT. Remember also to set -T

-T content-type Content-type header for POSTing, eg.

‘application/x-www-form-urlencoded’

Default is ‘text/plain’

-v verbosity    How much troubleshooting info to print

-w              Print out results in HTML tables

-i              Use HEAD instead of GET

-x attributes   String to insert as table attributes

-y attributes   String to insert as tr attributes

-z attributes   String to insert as td or th attributes

-C attribute    Add cookie, eg. ‘Apache=1234. (repeatable)

-H attribute    Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’

Inserted after all normal header lines. (repeatable)

-A attribute    Add Basic WWW Authentication, the attributes

are a colon separated username and password.

-P attribute    Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

-X proxy:port   Proxyserver and port number to use

-V              Print version number and exit

-k               Use HTTP KeepAlive feature

-d              Do not show percentiles served table.

-S              Do not show confidence estimators and warnings.

-g filename     Output collected data to gnuplot format file.

-e filename     Output CSV file with percentages served

-r              Don’t exit on socket receive errors.

-h              Display usage information (this message)

 

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>

 

 

示例:

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>ab -n 1000 -c 50http://blog.csdn.net/tianlesoftware/archive/2010/05/25/5622268.aspx

 

— 注意, 这里要写一个具体的页面

 

This is ApacheBench, Version 2.3 <$Revision: 655654 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

 

Benchmarking blog.csdn.net (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Completed 1000 requests

Finished 1000 requests

 

 

Server Software:        nginx/0.7.65

Server Hostname:        blog.csdn.net

Server Port:            80

 

Document Path:      /tianlesoftware/archive/2010/05/25/5622268.aspx — 请求资源

Document Length:        169 bytes  — 文档返回的长度,不包括相应头

 

Concurrency Level:      50  — 并发个数

Time taken for tests:   118.549 seconds  — 请求消耗总时间

Complete requests:      1000  — 总请求数

Failed requests:        1

(Connect: 1, Receive: 0, Length: 0, Exceptions: 0)

Write errors:           0

Non-2xx responses:      1000

Total transferred:      334000 bytes

HTML transferred:       169000 bytes

Requests per second:    8.44 [#/sec] (mean)  — 平均每秒请求数

Time per request:       5927.439 [ms] (mean)   — 平均每个请求时间

Time per request:       118.549 [ms] (mean, across all concurrent requests)

— 平均每个请求时间除以并发数, 这里是 5927.439/50

Transfer rate:          2.75 [Kbytes/sec] received   — 时间传输速率

 

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:       47   97  72.8     63     742

Processing:    57 5720 4597.9   4666   25381

Waiting:       54 2711 3312.5   2128   25176

Total:        112 5817 4595.1   4754   25435

 

Percentage of the requests served within a certain time (ms)

50%   4754   —

66%   5491

75%   6005

80%   6274

90%   7366

95%   8697

98%  25232

99%  25415

100%  25435 (longest request)

 

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin>

 

 

含义:   同时处理 50 个并发请求并运行 1000 次 :

/tianlesoftware/archive/2010/05/25/5622268.aspx

 

结果:   在并发 50 个请求的情况下,完成 1000 次的访问请求,共花了 118.549 秒,这个程序每秒可处理 8.44 个请求。

 

 

1,使用ab,发送post数据:

apachebench网上的资料很多
但是甚至包括国外的文章以及官方文档
出了help显示的内容之外就没有任何一丁点更详细些的内容了
要使用ab进行post数据测试.从help可以看出我们需要定义两个内容
一个是-p参数.指定需要post的数据
还有一个是-T参数,指定使用的content-type
我在服务器端简单的写了一个脚本.将获取到的post请求输出到文件

<?php
echo $_REQUEST[‘test’];
$file=fopen(‘/data/www/log.txt’,’a+’);
fwrite($file,date(“Y-m-d H:i:s”));
fwrite($file,$_REQUEST[‘test’]);
fclose($file);
?>

然后在本地生成post.txt文件
内容为test=abc
使用ab进行测试
ab -n 1 -p post.txt http://192.168.0.2/test.php
发现服务器端接受到了请求,但是没有受到post的数据
使用类型之后.也还是不行
ab -n 1 -p post.txt -T ‘text/html’ http://192.168.0.2/test.php
使用get方式测试
ab -n 1 http://192.168.0.2/test.php?test=abc
服务器端则可以正常工作
和开始说的一样.翻烂了google也没有找到
最后只能用wireshark抓包
最后发现content-type一定要设置成为
application/x-www-form-urlencoded
最后如下测试.才最后通过
ab -n 1 -p post.txt -T ‘application/x-www-form-urlencoded’ http://192.168.0.2/test.php
还有postfile
如果有多条记录
内容可以写成
test1=a&test2=b
类似这样即可
这个也是文档中没有提及的,让我一开始以为postfile的格式有误.
网上有提到过一种格式
test1=a
test2=b
这种是不对的
这样的ab会把整个
a回车test2=b
当作test1这个field传送出去

2,使用ab发送get数据

直接将url地址,加双引号如果””http://test.qq/?c=index&r=104717283&sid=dShRB6zkP0twTOOwIim5

webbench压力测试

webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便。

1、适用系统:Linux

2、编译安装:

引用
wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make && make install

3、使用:

引用
webbench -c 500 -t 30 http://127.0.0.1/test.jpg

参数说明:-c表示并发数,-t表示时间(秒)

4、测试结果示例:

引用
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://127.0.0.1/test.jpg
500 clients, running 30 sec.

Speed=3230 pages/min, 11614212 bytes/sec.
Requests: 1615 susceed, 0 failed.

IIS配置PHP环境(快速最新版)

我们知道php配置有几种:

1、CGI方式加载PHP环境,通常就是IIS里面配置解释器为php.exe,早期比较常见,目前使用较少。
特点是:稳定,但效率太低。

2、ISAPI方式加载PHP环境,通常就是IIS里面配置解释器为php5isapi.dll,目前使用最多,应用最广。
特点是:多线程,效率较高,但不够稳定。

3、FastCGI方式加载PHP环境,在IIS环境里并不常见,但其它系统环境应用还是有的,不过IIS7.0开始内置FastCGI了。
特点是:高效率,高稳定性,属于将来发展趋势。

我试过其他的特别麻烦,PHP 5.3发布的Windows版已经不支持ISAPI模式了,所以我打算按微软推荐的FastCGI方式运行PHP。

我用的就第三种,也是最好最快的,因为FastCGI大大加强了IIS处理PHP的能力,能迅速提高PHP站点的反应速度和生产力,

并具有更高的稳定性和安全性.

下载地址:http://windows.php.net/download/里面有好多种,要那种呢?

PHP现在推出5.3.2版本了,不过下载的时候有几个不同版本选择。那就是VC6 X86和VC9 X86。
首先我来解答:
VC6是什么?
VC6就是legacy Visual Studio 6 compiler,就是使用这个编译器编译的。
VC9是什么?
VC9就是the Visual Studio 2008 compiler,就是用微软的VS编辑器编译的。

那我们如何选择下载哪个版本的PHP呢?
如果你是在windows下使用Apache+PHP的,请选择VC6版本;
如果你是在windows下使用IIS+PHP的,请选择VC9版本;

那Non Thread Safe是什么?
Non Thread Safe就是非线程安全;
Thread Safe 是什么?
Non Thread Safe 是线程安全;

FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以 FastCGI(无论搭配 IIS 6 或 IIS 7)执行 PHP ,都建议下载、执行 non-thread safe 的 PHP (PHP 的二進位檔有兩種包裝方式:msi 、zip ,請下載 zip 套件)所以我们选择NO-Thread Safe 版本的PHP来使用
而线程安全检查正是为ISAPI方式的PHP准备的,因为有许多php模块都不是线程安全的,所以需要使用Thread Safe的PHP。

 

下载安装,我安装默认路径了:

曾祥展

记得选中第三项:IIS FASTCGI

曾祥展

如果没有安装IIS FASTCGI的 下一步会提示没有安装的,下载安装就行了

FastCGI  for IIS 6  7   http://www.iis.net/expand/fastcgi

曾祥展

2-1

安装好后,继续下一步,我按照默认了:

曾祥展

安装完毕后,就是配置了。

这种配置有两种方法,我用cmd配置,一条命令就行了。

 

 

 

转到刚才安装CGI的目录下:

>cd C:\WINDOWS\system32\inetsrv

>cscript fcgiconfig.js -add -section:”PHP” -extension:php -path:”C:\Program Files\PHP\php-cgi.exe”

注意:path:”xxxx\php-cgi.exe” 是你安装php的目录

cscript fcgiconfig.js -set -section:”PHP” -InstanceMaxRequests:10000
cscript fcgiconfig.js -set -section:”PHP” -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

曾祥展

ok!完毕!

测试下:

新建一个.php文件,里面

<?php

phpinfo();

?>

保存!

运行,出现下面页面,说明配置成功了!

曾祥展

这样的方法 IIS就不用怎么配置,他都会自动配置好了!微软提供的配置更加详细 !

如果按上面的教程配置好后,运行php测试页面,出现了500错误。

那就设置php.ini中的date.timezone项。

我这里设置成上海时区:date.timezone = Asia/beijing

设置完后就一切正常了!

Android之读取Resource和Assets中的文件

public String getFromRes(String FileName){
     String result = "";
     try{
      InputStream in = getResources().openRawResource(R.raw.test2);//获取资源
      int length = in.available();//获取文字字数
      byte[]buffer = new byte[length];
      in.read(buffer);//读到数组中
            //设置编码
      result = EncodingUtils.getString(buffer, "UTF-8");
     }catch (Exception e) {
  }
  return result;
    }
    public String getFromAssets(String FileName){
     String result = "";
     try{
      InputStream in = getAssets().open(FileName);//获取资源
      int length = in.available();//获取文字字数
      byte[]buffer = new byte[length];
      in.read(buffer);//读到数组中
            //设置编码
      result = EncodingUtils.getString(buffer, "UTF-8");
     }catch (Exception e) {
  }
  return result;
    }

 

ps: 继承 Activity

或者可以使用 context.getAssets().open(FileName);// 获取资源