2012年2月26日星期日

WinDBG命令

在断点上打log, 然后继续执行.
bp 10843770 "dd @esp+4 L 4; g"

设置条件断点
bp 10843770 ".if (poi(@esp+4)=0x00110214) {} .else {gc}"
bp 10843770 ".if (poi(@esp+4)=0x10204) {.if (poi(@esp+8)=0x7) {} .else {gc} } .else {gc}"

从内核一直调试到用户
http://www.codeproject.com/Articles/7913/Debug-Tutorial-Part-6-Navigating-The-Kernel-Debugg

During kernel-mode debugging, you can set the process context by using the .process (Set Process Context) command. Use this command to select which processs page directory is used to interpret virtual addresses. After you set the process context, you can use this context in any command that takes addresses. You can even set breakpoints at this address. By including a /i option in the .process command to specify invasive debugging, you can also use the kernel debugger to set breakpoints in user space.

You can also set user-mode breakpoints from the kernel debugger by using a process-specific breakpoint on a kernel-space function. Set strategic breakpoints and wait for the appropriate context to come up.

With WinDBG, another thing you can do is use !bpid to have the kernel debugger break into the context of the process you e interested in and then you can set your breakpoints in the user-mode code (after running .reload to reload your symbols).

For example, setting a breakpoint in CreateFileW in a process:
0: kd> !process 0 0
**** NT ACTIVE PROCESS DUMP ****
....
PROCESS 861c9d90 SessionId: 1 Cid: 0f10 Peb: 7ffd3000 ParentCid: 0b48
DirBase: 0174e2a0 ObjectTable: 96f14eb0 HandleCount: 5.
Image: testapp.exe
1: kd> .process /r /p 861c9d90
Implicit process is now 861c9d90
..cache forcedecodeuser done
Loading User Symbols

2012年2月23日星期四

Ubuntu上build insight

insight-6.8-1
1. sudo apt-get install libx11-dev
2. sudo apt-get install libncurses5-dev
3. tar -xjvf insight-6.8-1.tar.bz2
4. cd insight-6.8-1/
5. ./configure (need do configure first)
5. ./configure –disable-werror
6. make
7. sudo make install

解决电话加锁

am startservice -a com.fd.settings -d content://device/unlock -n com.futuredial.FDSettingsService/.FDSettingsService

adb shell am start -n com.futuredial.fdbox721/.fdbox721Activity

2012年2月10日星期五

.net 4.0 新的非托管异常处理机制.

在.NET 4.0之后,CLR将会区别出一些异常(都是SEH异常),将这些异常标识为破坏性异常(Corrupted State Exception)。针对这些异常,CLR的catch块不会捕捉这些异常,即使你用类似下面的代码:
try
{
TestMethod();
}
catch (Exception e)
{
Console.WriteLine("Catching exception: {0}", e);
}
也没有办法捕捉到这些异常。之所以要这样设计,在MSDN的文章Handling Corrupted State Exceptions里已经提到了。即,有一些支持插件的程序,例如Visual Studio或者SQL Server,它们支持调用托管代码编写成的插件,但是它们自己本身有很多代码是由非托管的C++写成的。由于插件经常会调用到非托管的API,而很多时间,这些插件的代码根本就不知道如何处理非托管的API抛出来的SEH异常。在4.0以前,因为SEH异常被转换成了跟普通.NET异常相同的异常,这样程序员只要用catch ( Exception e)的模式就可以捕捉到所有的异常。这样处理的问题是,由于SEH异常通常都不是托管代码抛出的,托管代码根本就不知道SHE异常被扔出来的原因,简单的catch ( Exception e)处理使得整个程序会处于一个非常不稳定的状态,使得前面被忽略的问题在后面以更严重的方式出现 — 例如保存被破坏的数据。这样,看起来使用catch ( Exception e)处理所有的异常的方法很简单,但实际上让程序员或者用户在问题延后发生时,分析起来需要花费更多的精力。

因此在4.0以后,大部分SHE(我怀疑是所有)异常都被标识成破坏性异常,在.NET里,默认情况下CLR不会捕捉它们,而是任由操作系统来处理—即关闭程序,并打开一个错误对话框通知用户。为了保证兼容性,在4.0以前编译的程序,例如在2.0、3.0和3.5编译的程序,依然采用的是老的策略—即.NET会同时捕捉.NET异常和SHE异常。而在4.0下面编译的程序才会使用新的策略,这也是在文章的开头,我的朋友所碰到的问题。你可以在.NET 4.0下面编译下面的程序,体验一下这个新变化:

Program.cs:
using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program { [DllImport("Ref.dll")] private extern static void TestMethod(); static void Main(string[] args) { try { TestMethod(); } catch (Exception e) { Console.WriteLine("Catching exception: {0}", e); } } } }

Ref.cpp:
#include "stdafx.h" extern "C" __declspec(dllexport) void TestMethod() { int *p = NULL; // 会导致.NET抛出一个AccessViolation异常 *p = 10; }

上面的代码里,Program.cs使用P/Invoke技术调用了Ref.dll文件里的TestMethod,但是TestMethod尝试给一个空指针赋值,导致一个AccessViolation异常。如果你在2.0下面编译program.cs,并执行的话,这个AccessViolation异常会被catch(Exception e)捕捉到,而如果你在4.0下面编译并执行的话,你会发现catch (Exception e)是不能捕捉到这个异常的。

然而并不是所有人都想要这个新的异常机制,如果你的程序是在4.0下面编译并运行,而你又想在.NET程序里捕捉到SHE异常的话,有两个方案可以尝试:
1. 在托管程序的.config文件里,启用legacyCorruptedStateExceptionsPolicy这个属性,即简化的.config文件类似下面的文件:

App.config:


 
 
 





 
 
 





这个设置告诉CLR 4.0,整个.NET程序都要使用老的异常捕捉机制。

2. 在需要捕捉破坏性异常的函数外面加一个HandleProcessCorruptedStateExceptions属性,这个属性只控制一个函数,对托管程序的其他函数没有影响,例如:
[HandleProcessCorruptedStateExceptions] static void Main(string[] args) { try { TestMethod(); } catch (Exception e) { Console.WriteLine("Catching exception: {0}", e); } }

2011年6月2日星期四

HTC(多普达)手机的生产日期及主机序列号


一直想了解自己手机的生产日期等信息,今天终于解开了这个秘密,把它记下来,也希望对想买(HTC)多普达手机的朋友有点帮助。。。。
           可以通过S/N进行查询:
           例如 S/N: SSYWWPPZZZZZ  
           SS: 
是生产地代码,一般HTCH比较常见

           HT 是新竹(台湾HTC总部工厂)
           CH 是武汉
           SZ 是深圳
           SH 是上海
           Y: 是生产年份的最后一个数字,如9即表示该手机为2009年生产的.
           WW: 是生产的周:有01-54周,(09年用新的方法了,月是123456789ABC代表123456789101112月。日从19AZ(26个字母中不使用到其中的四个“IOQU”)是代表191031)1=1 2=2 3=3 4=4 5=5 6=6 7=7 8=8 9=9 10=A 11=B 12=C 13=D 14=E 15=F 16=G 17=H 18=J 19=K 20=L 21=M 22=N 23=P 24=R 25=S 26=T 27=V 28=W 29=X 30=Y 31=Z 
           PP:
是产品代码  
           ZZZZZ:
是序号

2011年4月25日星期一

Flash NVidia Tegra APX device

IDK what knowledge (in case of eLocity A7) have Koush, but i'm trying to allocate all info about hard-flashing process here.

------------------------------------------------------------------------

1. Recovery

eLocity A7 has Android System Recovery <1e>. According info from official update: recovery.img will flash to partition named "SOS"
To get into recovery you should:
- turn Tablet off
- quickly turn on and release power-button (notice green light)
- press power again and hold till text "Booting recovery kernel image"
- if you hold longer your Tablet will turn off)

2. ADB (Android Debug Bridge)

2.1 Cable
Ensure you have USB Cable A-A like in attached image
http://forum.xda-developers.com/attachment.php?attachmentid=530427&stc=1&d=1298973504

2.2 Drivers
Ensure you have Android SDK Tools. If you have SDK Tools already you could start from section "Modifying drivers"

2.2.1 Installing SDK Tools
- Download it from http://developer.android.com/sdk/index.html
- Unpack it to (avoid long-names and desktop-folders; good folder: c:\asdk)
- Run "sdk manager.exe"
- From "Android repository" download "Android SDK Platform-tools"
- From "Third-party Add-ons / Google Inc. add-ons" download "Google USB Driver package"
- Exit from SDK Manager

2.2.2 Modifying drivers
- Go to /google-usb_driver
- Find android_winusb.inf and edit it
- Add following to both sections [Google.NTx86] and [Google.NTamd64]
;NVIDIA Tegra
%SingleAdbInterface% = USB_Install, USB\VID_0955&PID_7000
%CompositeAdbInterface% = USB_Install, USB\VID_0955&PID_7100&MI_01
%CompositeAdbInterface% = USB_Install, USB\VID_0955&PID_7100
- Save and exit
- Run Windows command-promt and type
echo 0x955 >> "%USERPROFILE%\.android\adb_usb.ini"

2.3 Switch modes
eLocity A7 has USB-Host "out-of-box", but it can be converted to simple USB

- Ensure you have Root Explorer
- Run it and go to /data/data
- Create folder name com.compal.usb_otg
- Go into and make file usb.txt
- In usb.txt write 0
- Connect tablet to PC with USB Cable A-A
- Reboot (tablet can switch modes only while rebooting)

Note: 
0 - USB Slave mode
1 - USB Host mode

2.4 Checking ADB
- If you done steps above correctly Windows would search adb-drivers. Point them at /google-usb_driver
- Check connection by running adb from /platform-tools
adb devices
If it returned serial number you have success

3. APX mode

3.1 Getting Nvidia Tools
- Go to http://developer.nvidia.com/tegra/devkit-250tango and download "Android 2.2 (Froyo) for Tegra 250 & Tango ONLY" (one or both Windows/ Linux)
Speedlinks (NVidia updated tools 7 feb 2011, so links would change in future)
Windows: http://developer.download.nvidia.com/tegra/files/os/tegra_froyo_20110207.msi
Linux: http://developer.download.nvidia.com/tegra/files/os/tegra_froyo_20110207.run.gz
- [WIN] Install it in (default it is there C:\Program Files\NVIDIA Corporation\tegra_froyo_20110207) 

3.2 Running into APX
- Connect to PC (remember: in USB Slave mode and with Cable A-A)
- Run following command in terminal emulator
echo 1 >/proc/naz10_diag/force_recovery
- Tablet should reboot into APX
- If you've connected properly Windows should search another drivers
- Point them to /usbpcdriver

3.3 Getting partitions
- Go to
- Run nvflash-command to get into bootloader. I used stock bootloader from elocity official update. I didn't use bootloader from .
nvflash --bl bootloader.bin --go
- Tablet should write something at screen (recovery mode bla-bla)
- Run nvflash-command to get list of partitions
nvflash -r --getpartitiontable partitiontable.txt
- I have last official update and in partitiontable.txt "SOS"-partition has number 6
- Run nvflash-command to get specified X partition
nvflash -r --read X part-X.img

I successfully got partition number 6 and it is about 8 MB
I got partition "APP" (with number 9) and it is about 500 Mb - i think our system image can be extended ;)
nvflash has command "--download N filename". It downloads partition filename to N. But i'm afraid to experiments, cause don't have warranty
------------------------------------------------------------------------

Things to investigate

- Running into APX-mode with hardware-buttons. I don't know how it can be. Viewsonic GTablet owners have to press VolumeDown and Power to get into. But our Tablet doesn't have VolumeDown. I tried Volume already but it seems that this button starts working after system was loaded.
Without this method we have only two methods to restore:
1) If tablet is booting properly -> nvflash
2) If tablet won't boot -> recovery

- Custom recovery. It would be great if Koush will realize it. Last step left)
------------------------------------------------------------------------
Thanks to
- greenar
- Dexter_nlb
- nicofs (he added info about nvflash to toshiba ac100 wiki)

2010年12月8日星期三

XP - 全自动开启匿名GUEST访问局域网共享

彻底解决winXP访问问题:
一、首先启用guest来宾帐户;
二、控制面板→管理工具→本地安全策略→本地策略→用户权利指派里

  • “从网络访问此计算机”中加入guest帐户
  • “拒绝从网络访问这台计算机”中删除guest帐户
三、我的电脑→工具→文件夹选项→查看→去掉“使用简单文件共享(推荐)”前的勾;
四、设置共享文件夹;
五、控制面板→管理工具→本地安全策略→本地策略→安全选项里,
  • 把“网络访问:本地帐户的共享和安全模式”设为“仅来宾-本地用户以来宾的身份验证”(可选,此项设置可去除访问时要求输入密码的对话框,也可视情况设为“经典-本地用户以自己的身份验证”);