Next-generation Shell scripting language, Windows power shell!_it Industry

Source: Internet
Author: User
Tags extend reflector
Go home today as usual browse the next cnbeta.com, to see what fresh content.
As a rule, I saw a Windows power Shell 1.0
Well, I'm very interested in this thing, after all, Windows is currently the shell is too weak, immediately downloaded from the Microsoft site, installation, found that it is in the form of a patch package, not a regular MSI, then, I guess Vista has brought this thing.
The following will try to understand PowerShell (hereafter referred to as PS)
After the installation is complete, open the Program menu, it seems m$ old habit or keep good, help very detailed
Release Notes
Quick reference
Entry
User Guide
Others do not make a fine table

After looking at the document, it is more important to note that PS is any object written in. NET and that fully supports. NET.
. net! What the?
Sacrifice the Dragon Knife Reflector Open the main program of the PowerShell and all the DLLs in the directory, failed: CLR header is invalid, no one is correctly decompile, not to say with PS is. NET written? How... m$ kidding us?


That's how he operates. NET object?
Then come on, sacrifice PE Explorer to open the main program of PS look at its API import, found the main program PS.
The Mscoree.dll function is referenced CorBindToRuntimeEx
MSDN explains this CorBindToRuntimeEx: Enables unmanaged hosts to load the common language runtime into a process.
This shows that PS performs the necessary initialization in unmanaged code before it is run before it enters the CLR, or it is possible to create a mixed environment in which managed and unmanaged code is executed interactively; So, where is the host program?


Use Windows search function search keyword "PowerShell", failed, find out all the things in the program directory! ~~~
Think it over, and decide to start at the root of the cause; Windows patches are packaged using cabs, so you can open them directly with WinRAR, open windowsxp-kb926140-x86-chs.exe with WinRAR, and find what I need. "_sfx_ Manifest_, opened the view in text format and found something I needed:
"Microsoft.powershell.consolehost.dll" = "_sfx_0008._p", "Powershell.exe"
"System.management.automation.dll" = "_sfx_0009._p", "Microsoft.powershell.consolehost.dll"
"Microsoft.powershell.security.dll" = "_sfx_0010._p", "System.management.automation.dll"
......


This fully illustrates that the host program is there, it is Microsoft.PowerShell.ConsoleHost.dll, so why can't I find these files?
Consider the following, and think that these things may be in the GAC, open the GAC directory view; Ha, where are they?
But there's still a problem with Reflector! Reflector can not find these assemblies ~ ~ ~, with the Open Cache also can not find!!!
No, just from the patch bag to solve the file to see it, out again with Reflector open, silly, "file is not a portable executable." DOS header does not contain ' MZ ' signature. ", the file header is not correct; with Notepad open look, find file header incredibly" PA19 ", this is what format file, why I have never seen? NGen generated local code? Or is it a managed DLL that has been encrypted?


Regardless of this, find other ways to get the assembly in the GAC well.
The GAC directory has been taken over by a Shell extension, so now it's time to get the files out of the directory and I've tried the dialog, copied the folders, and ended up with a single command line:

xcopy /e C:\Windows\assembly\GAC_MSIL G:\GAC_MSIL


Then look for the desired assembly in the copied directory. Ha, now we can look at the PS code, it will be a very enjoyable thing.
In addition, I found an additional assembly "System.Management.Automation.dll" through the _sfx_manifest_ file and the Reflector Analysis assembly reference, and its EXE note is "Microsoft Command-Line Shell Engine Core Assembly "
I'm going to pack up these unpacked assemblies, download them here, we can reflector analyze his code, or pack him up with PS's main program to implement XCOPY deployment as a scripting system for the product.


Here, we've got the code assembly all figured out, let's take a look at what PowerShell is and what it can do:
Windows PowerShell uses its own language instead of reusing existing languages for the following reasons:
Windows PowerShell requires a language for managing. NET objects.
• The language needs to provide a consistent environment for using a cmdlet.
• The language needs to support complex tasks without making simple tasks more complex.
• The language needs to be consistent with the high-level language (such as C #) that is used in. NET programming.


Some features of the PS language:
1. Some features of advanced languages (variables, arrays, operators, hash tables, functions, conditional statements, circular statements ...)
2. Direct navigation in the file system, registry, certificate store, drive, and navigation is very similar to our familiar DOS navigation methods.
3. Powerful wildcard character and string search function
4. Can be created and manipulated. NET Objects and COM objects
5. Use any object (including.) based on the object piping feature. NET and COM objects) interacting with the target
7. You can access WMI objects directly.
8. You can write. Net assemblies to extend the PS, and by extension, you can extend the functionality of PS almost indefinitely.

For additional features, refer to PowerShell's help documentation.

Common commands:
Get-date-Get the current date.
Get-help-Get help.
Get-member-View the object structure (you can use this command to view the members of a. Net object).
Get-wmiobject-Gets the WMI object.
Get-process-Gets the process object.
Get-service-Gets the Windows service object.


Now is the month black wind high urge people to sleep, can wait until tomorrow to continue to study; Finally, we end with the classic Hello World, tomorrow, we will further study PS:
using the output command

Write-Output "Hello world!"

use. Net to Output

[System.console]::foregroundcolor = [System.consolecolor]::blue
[System.console]::writeline ("Hello world!" )

    really powerful shell!.


ps: 
    I always wanted m$ to be able to provide a no graphical interface, it seems to be early, but now it is in the good direction, PowerShell let me see the Hope, Maybe PowerShell is the future prototype of a no graphical interface Server.
    So, I venture to predict that Vienna (the next OS after Vista, completely rewriting the kernel) will be the core and graphics interface separation, rather than the current based on NT kernel, the kernel and graphical interface will be together And there will be a no graphical interface of the server and the current graphics server, both will coexist for a long time, as to who will be replaced, I think it seems impossible.
    So the thing I can imagine is that Microsoft will upgrade Windows PE so that it uses the core of Vienna and will include the. Net Framework x.y, which is also divided into character interfaces and graphical interfaces. In this way, Windows PE will become a very handy system diagnostics, troubleshooting tool. The
   windows server is closer to the Unix/linux server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.