2010年7月23日星期五

Install XP/Windows 7 by command line

硬盘安装XP的实用方法:
用WINPE x86/x64启动, 运行:
winnt32.exe /syspart:c /tempdrive:c /makelocalsource

硬盘安装windows7:
1、imagex /apply d:\sources\install.wim 5 c: (注意,这里5是指ultimate版,要装其它版本把这个数字换成其它)
2、bcdboot c:\windows /s e: /l zh-CN (一条命令搞定bootmgr和bcd,并把启动菜单设成中文的)
3、bootsect /nt60 e: (写入c:盘的bootmgr引导扇区)   
启动即可继续安装.


硬盘安装windows7的高级实用方法:
1、把镜像用虚拟光驱加载,然后拷贝到任一硬盘分区中,我的是E:\windwos7。  


2、把E:\windwos7目录下的bootmgr和boot目录(其实只要里面的boot.sdi和bcd文件)拷贝到c盘根目录下,并在C盘根目录下建个sources文件夹。(原系统是vista的话需要取得权限,覆盖相应文件,取得权限的方法参照vista区的vista优化大师的右键取得管理权限法)  

3、把E:\windwos7\sources下的boot.win复制到C盘下sourse文件夹。  

4、用管理员身份运行cmd,然后输入c:\boot\bootsect.exe /nt60 c:

(注意,此处bootsect在c:\boot目录下),然后提示successful(即成功了!)
再将系统盘的卷名称改为英文:本地磁盘--bdcp  

5、重启计算机,正在启动安装程序  

6、安装程序启动,选择你要安装的语言类型,同时选择适合自己的时间和货币显示种类及键盘和输入方式。  

7、出现“开始安装界面”,(要注意了,不点击“现在安装”)点左下角“修复计算机”(repair my computer)。  

8、进入“系统恢复选项”,选择最后一项“命令提示符”(command prompt),进入DOS窗口。

9、执行格式化命令format c:/q(注:如C盘是FAT32格式,想转NTFS格式的话,执行format c:/fs:ntfs)。
注:此步可能需要输入卷的名称bdcp  

10、安装系统,输入E:windwos7sourcessetup.exe(注意文件路径是在E盘的windwos7文件夹下的sources文件里),之后就是正常的安装了。

2010年7月13日星期二

Visual Studio 2005 Remote Debugging to Vista and Windows 7

When you run MSVSMON.EXE on Vista and Windows 7, do you get the dreaded message indicating that you need to set the firewall, but when you do, MSVSMON.EXE errors out with an Incorrect Function message? After much struggle, I finally found the trick to remote debugging working correctly. Many thanks to this post on the MSDN Forums from Sam George.

It seems that even with the Vista SP1 Update, MSVSMON.EXE does not properly set the firewall. You'll need to set it up manually with the following batch file:


netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - UDP 137" dir=in action=allow enable=yes localport=137 protocol=udp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - UDP 138" dir=in action=allow enable=yes localport=138 protocol=udp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - TCP 139" dir=in action=allow enable=yes localport=139 protocol=tcp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - TCP 445" dir=in action=allow enable=yes localport=445 protocol=tcp

Of course, make sure you run the batch file from an elevated command prompt.

2010年7月1日星期四

无法解析外部符号 __security_cookie

1)选择“项目”-》“属性”-》“C/C++”-》“代码生成”-》“缓冲区安全检查”,设为“否”


2)选择“项目”-》“属性”-》“链接器”-》“输入”-》“附加依赖项”,增加”bufferoverflowU.lib”

http://support.microsoft.com/kb/894573.

2010年6月30日星期三

How To: compile Dolphin with SSE2, SSE3, SSE4.1, SSE4.2, and SSSE3 on Windows

General Requirements as suggested by me:


- WindowsXP or higher

- Nothing less than 2.1 GHz core2duo CPU

- No less than 3GB RAM

- No less than 10GB free on your Hard Drive.

-An extra $1400 laying around (no joke, you're actually gonna need this)



NOTE: If you can't afford it, you can get the builds for free from my website. You support me and save time and money.





Step 1: Get the Software

-Visual Studio 2008 Pro (yes PRO. There's no known workaround for Express) ($799)

-Intel C++ Compiler (version 11.1 Update 6 recommended) (Free to Try, $599.00 to buy)

-TortoiseSVN

-Latest DirectX SDK

-Windows SDK *May or may not be needed* (get version that's appropriate for your OS, ie Windows 7 requires Windows 7 SDK)

-Latest .NET Framework







Step 2: Installation

1) Install the latest version of the .NET Framework.



2) Install VS 2008 Pro (NOT Express!)

-FULL INSTALLATION!

-You may or may not need MSDN Library. I chose to install it.



3) Install Intel C++ Compiler

-FULL INSTALLATION (if IA-64 is disabled in the install, that's ok. That's the ONE thing you do not need...Unless you are building for IA-64 (instead of regular 64bit). If that's the case, you'll need VS 2008 Team Suite instead of Pro.)



4) Install Windows SDK, TortoiseSVN, and DirectX SDK



Step 3: Configuration

1) For Visual Studio (open Visual Studio)

-Under Tools > Options > Projects > VC++ Directories Select the Platform you will be building for. Make sure you have the following:

Under Executables: DirectX SDK Folder (Normally located: C:\Program Files\Microsoft DirectX SDK ([month and year released])\Utilities\bin\[x86 OR x64]

Under Includes: DirectX SDK Includes (Normally located: C:\Program Files\Microsoft DirectX SDK ([month and year released])\Include

Under Library: DirectX SDK Library (Normally located: C:\Program Files\Microsoft DirectX SDK ([month and year released])\Lib\[x86 OR x64]

Note: You can go to "Path Fixing" here if you need more detail.



Step 4: Checkout

1) Make a new folder and name it whatever. We'll refer to it as the "Checkout Folder."



2) Right-click the folder and select "SVN Checkout"



3) The URL of repository is "http://dolphin-emu.googlecode.com/svn/trunk/" without quotes.



4) Click OK or choose specific revision under "Revision" and then click OK.



Step 5: RVSN fixes

In your Checkout Folder there are some files we need to change to work with Intel C++ Compiler.



1) "_export" Fix

-Replace all instances of "_export" with "export_" (without quotes) in the following (you can use any text editor):

Checkout Folder\Source\Core\DolphinWX\Src\MemoryCards\WiiSaveCrypted.cpp

Checkout Folder\Source\Core\DolphinWX\Src\MemoryCards\WiiSaveCrypted.h



2) "VCEnd" fix (R5637 and later) Click here for an alternate method of fixing

-Replace all instances of "else (goto VCEnd" with "else (goto finish)" (without quotes) in the following (you can use any text editor):

CheckoutFolder\Source\Core\DolphinWX\DolphinWX.vcproj

CheckoutFolder\Source\Core\Common\Common.vcproj



-Replace all instances of "goto VCEnd" with ":finish" (without quotes) in the following (you can use any text editor):

CheckoutFolder\Source\Core\DolphinWX\DolphinWX.vcproj

CheckoutFolder\Source\Core\Common\Common.vcproj



NOTE: "2)" Must be done in the order shown to work correctly!

NOTE: I find that using NotePad++ to find and replace the code snippets is very quick and easy, as you can replace all instances of a value in all opened documents.













Step 6: Compiling

1) Open CheckoutFolder\Source\Dolphin.sln in VS 2008.



2) Right-click the "Solution 'Dolphin'" and select Intel C++ Compiler Pro -> Use Intel C++...



3) Click OK for any windows that pop-up.



4) Once it has finished converting the solution to use Intel C++, Select the Type of build you want (ie Debug/Release and Win32/x64 ("Release" is recomended))

Note: if you change either of these values after you change the following, you will have to redo the following steps.



5) Select all Projects in the Solution Explorer except DSPSpy, right-click them, and select click "Properties"



6) Under C++ -> Code Generation, you can set the Instruction Set used (ie SSE2, SSE3, SSE4.1, SSE4.2, or SSSE3).

-For Intel processors only: Set "Intel Processor-Specific Optimization"

-For all processors that support SSE instructions: Set "Add Processor-Optimized Code Path"



7) Click OK to apply settings.



8) Select "Plugin_VideoOGL" and all the projects under "Solution Explorer" that start with "wx" (without the quotes).



9) Right-Click and select properties. Under C++ -> Precompiled Headers set "Create/Use Precompiled Header" to "Not Using Precompiled Headers"



10) Right-click "Solution 'Dolphin'" and select "Rebuild"





You should end up with XX Succeeded, 0 failed, and X skipped. If you do not, either you missed one or more instructions in this tutorial, or their are specific settings needed for the revision you are trying to compile.



If you are not using an English OS and get error #13000, go here.





Step 7: Have Fun!

1) Where's my build?!

- It's under CheckoutFolder\Binary\{Win32 OR x64}\

-Just run "Dolphin{}.exe" (the {} stands for various things that may be appended, such as "FS" or "D" or nothing)



NOTE: Now that you know how to do this, you can find out what additional optimizations work for you! You can test your builds against mine to see if yours has a faster, slower, or about the same frame rate (remember to test the same rvsn number builds!)



Final words: (can anyone guess what they are lol) Free builds at my website! Go there, support me! yada yada yada... What better purpose for a tutorial than to advertise one's work lol







...And there you have it. What took 2 weeks of constant research and experimenting for me to learn you have learned in just 10 minutes.

convert between big-endian and little-endian values

Code:

inline void endian_swap(unsigned short& x)

{

x = (x>>8)


(x<<8);

}



inline void endian_swap(unsigned int& x)

{

x = (x>>24)


((x<<8) & 0x00FF0000)


((x>>8) & 0x0000FF00)


(x<<24);

}



// __int64 for MSVC, "long long" for gcc

inline void endian_swap(unsigned __int64& x)

{

x = (x>>56)


((x<<40) & 0x00FF000000000000)


((x<<24) & 0x0000FF0000000000)


((x<<8) & 0x000000FF00000000)


((x>>8) & 0x00000000FF000000)


((x>>24) & 0x0000000000FF0000)


((x>>40) & 0x000000000000FF00)


(x<<56);

}

在vista中跳过uac获得高权限

在window中(包括vista)最高权限是system account,拥有所有权限,该账户是专门为service配置的(个人猜测)。在vista中,在权限方面,微软使用了一种新的访问控制UAC,在administrators的帐户下面,用户启动进程的权限也仅仅是一般user的权限,若想使进程跑在administrator权限下面,就要使用run as administrator,通过uac使用户确认当前的操作,才能真正获得administrator的权限。vista使一般的程序跑在普通用户的权限下,提高了系统的安全性,但如果程序的确需要提高到 administrator的权限下才能正常工作(如调用驱动接口 etc)那么上述提高进程的流程比较繁琐。现在我们讲述另一种提高权限的方法,绕过uac。



该方法就是通过service来启动程序,这样就能提高权限到system account的级别(比administrator还高),因为service可以运行在system accout下面,(在servcie的配置中有logon选项设置,log on as system account.所以上面我说system account 专门为service配置)通过service运行的进程自然就具有了system account的权限。这个方法在windows xp下也经常使用,并且很容易实现,但是在vista下面就稍微有点麻烦,在vista下变麻烦是因为微软对service 运行的session有了改动。



那么下面先讲一下vista和xp下的针对service的改动,在xp下,service和app都是运行在同一个session的不同station下面,xp的第一个登陆账户运行在session 0中,所有的service 和app也都运行 在session中,第二个启动的账户运行在session 1中只有app,第三个类同第二个等。这样app和service运行在一个session中,那么app和service是很容易通信的 如 sendmessage mapfile pipe …etc,而在vista下,它把session 0 隔离了,成为service专用session ,所有的service都运行在session 0中,第一个账户运行在session 1中,第二个类同,这样在不同的session 下app和service通信就比较麻烦,需要global类通信如(name pipe,socket etc)。从上面的论述可以看出,微软这么改的目的也是为了安全性。



现在我们就开始讲提高进程的运行权限,先讲xp吧,这个比较容易。在xp下想要把进程提高到无所不能的system account权限,那就要做一个service,然后通过serivce启动进程。直接createprocess就可以实现了 ,简单吧。那么在vista下面呢,因为service在session 0下,所以不能直接createprocess去创建,因为这样创建出来的进程会跑在session 0 下面,而不是当前得user桌面下面。要用CreateProcessAsUser去创建,而该api需要一个当前session 下面的service token,听上去好复杂是不是,呵呵,其实也挺简单得,首先就是DuplicateTokenEx一个当前service的token 完成一步,然后修改成当前user的session ,这样就完成了。下面就看以下代码,这样就更容易理解了:



VOID RunAp()

{

HANDLE hUserTokenDup,hPToken,hProcess;

DWORD dwCreationFlags;

DWORD dwSessionId = WTSGetActiveConsoleSessionId();



hProcess =::GetCurrentProcess();

LOGVAR(_T("dwSessionId value : %u\n"),dwSessionId);

if(!::OpenProcessToken(hProcess,TOKEN_ALL_ACCESS,&hPToken))

{

int abcd = GetLastError();

LOGVAR(_T("Process token open Error: %u\n"),GetLastError());

}

DuplicateTokenEx(hPToken,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hUserTokenDup);



//change Token session id

if(! SetTokenInformation(hUserTokenDup,TokenSessionId,&dwSessionId,sizeof(DWORD)))

{

LOGVAR(_T("Set Token Information value Error: %u\n"),GetLastError());

}



//binding environment path

LPVOID pEnv =NULL;

dwCreationFlags = NORMAL_PRIORITY_CLASS
CREATE_NEW_CONSOLE;

if(CreateEnvironmentBlock(&pEnv,hUserTokenDup,TRUE))

{

dwCreationFlags
=CREATE_UNICODE_ENVIRONMENT;

}

else

pEnv=NULL;



// Launch the process in the client's logon session.

PROCESS_INFORMATION pi;

STARTUPINFO si;

ZeroMemory(&si, sizeof(STARTUPINFO));

si.cb= sizeof(STARTUPINFO);

si.lpDesktop = _T("winsta0\\default");

ZeroMemory(&pi, sizeof(pi));

CreateProcessAsUser(hUserTokenDup,

_T("E:\\SVN\\Shared\\FrameworkFoundation\\build\\debug\\bin\\PrivateSafe.exe"),

NULL,

NULL,

NULL,

FALSE,

dwCreationFlags,

pEnv,

NULL,

&si,

&pi

);

CloseHandle(hUserTokenDup);

CloseHandle(hPToken);

if(pEnv)

DestroyEnvironmentBlock (pEnv);



return ;

}