上一個主題: 樣本表頭下一個主題: 語言功能


樣本指令檔

#include "SampleHeader.hdr"

function Detection()
{
     var e;

     SharedFunction( "Detection" );

     RecursionTest( "x" );

     {
     var result0 = ReturnTest( 0 );

     Print( "return test = " + result0 );
     }

     ScopeTest();

     BreakTest();

     lang = LANGUAGE;
     Print( "lang = " + lang );

     if (Detect("foo.exe") == false) return;

     Option( "Test", "TestStore", "TestApply", "test" );

     var eList = EnumKey(  "HKLM\\Software" );
     for (var eIdx in eList)
     {
          var e = eList[eIdx];

          var strWhileScope = "while scope key = " + e;

          Print( strWhileScope, VERY_DETAILED );
     }

     e = e;

     var eList = EnumValue(  "HKLM\\Software" );
     for (var eIdx in eList)
     {
          var e = eList[eIdx];

          Print( "value = " + e, VERY_DETAILED );
     }

     var eList = EnumFiles(  "c:\\" );
     for (var eIdx in eList)
     {
          var e = eList[eIdx];

          Print( "file = " + e, VERY_DETAILED );
     }

     var eList = EnumDirectories(  "c:\\" );
     for (var eIdx in eList)
     {
          var e = eList[eIdx];

          Print( "dir = " + e, VERY_DETAILED );
     }

     path = WINDOWSPATH;
     Print( path, MODERATE );

     Message( "this shouldn't fire another event to client; it should be cached already" );
     path = WINDOWSPATH;
     Print( path, MODERATE );
     
     RestartRequired(false);

     var myString               = "This is my very special string.";
     var myStringBinary     = ConvertStringToBinary(myString);
     var myStringString = ConvertBinaryToString(myStringBinary);
     if (myString == myStringString)
     {
          Print("String/Binary conversion works.");
     }
}

function PreProcess()
{
     Print("In PreProcess() function");
}

function PostProcess()
{
     Print("In PostProcess() function");
}

function TestStore()
{
     SharedFunction( "TestStore" );

     StoreKey( "HKCU\\Software\\Foo International\\Foo application" );
     StoreValue( "HKCU\\Software\\Foo International\\Foo application", "foo" );

     StoreMappedKey( "HKCU\\Software\\Foo International\\Foo application" );
     StoreMappedKey( "HKCU\\Software\\Foo International\\Foo application", "," );
     StoreMappedSubKeys( "HKCU\\Software\\Foo International\\Foo application" );
     StoreMappedSubKeys( "HKCU\\Software\\Foo International\\Foo application", "," );
     StoreMappedValue( "HKCU\\Software\\Foo International\\Foo application", "Install path" );
     StoreMappedValue( "HKCU\\Software\\Foo International\\Foo application", "Install path", "," );

     StoreFile( APPLICATIONPATH + "\\foo.exe" );
     StoreMappedFile( DESKTOPPATH + "\\mapped.txt" );
     StoreDirectory( APPLICATIONPATH );
}

function TestApply()
{
     SharedFunction( "TestApply" );

     strBaseKey = "HKCU\\Software\\Foo International\\Foo application";
     strMoveKey = "HKCU\\Software\\Foo International\\evil Foo application";

     MapPath( SYSTEMPATH, NEW_SYSTEMPATH );

     strMappedPath = GetMappedPath( WINDOWSPATH );
     Print( "mapped path = " + strMappedPath );
     strMappedPath = GetMappedPath( NEW_WINDOWSPATH, "," );
     Print( "mapped path = " + strMappedPath );

     ApplyKey( strBaseKey );
     ApplyKey( strBaseKey, strMoveKey );
     ApplySubKeys( strBaseKey );
     ApplySubKeys( strBaseKey, strMoveKey );
     ApplyValue( strBaseKey, "foo" );
     ApplyValue( strBaseKey, "foo", strMoveKey );
     ApplyValue( strBaseKey, "foo", strMoveKey, "evil foo" );

     ApplyMappedKey( strBaseKey );
     ApplyMappedKey( strBaseKey, strMoveKey );
     ApplyMappedKey( strBaseKey, strMoveKey, false );
     ApplyMappedKey( strBaseKey, strMoveKey, true, "," );
     ApplyMappedSubKeys( strBaseKey );
     ApplyMappedSubKeys( strBaseKey, strMoveKey );
     ApplyMappedSubKeys( strBaseKey, strMoveKey, false );
     ApplyMappedSubKeys( strBaseKey, strMoveKey, true, "," );
     ApplyMappedValue( strBaseKey, "Install path" );
     ApplyMappedValue( strBaseKey, "Install path", strMoveKey );
     ApplyMappedValue( strBaseKey, "Install path", strMoveKey, "evil Install path" );
     ApplyMappedValue( strBaseKey, "Install path", strMoveKey, "evil Install path", false );
     ApplyMappedValue( strBaseKey, "Install path", strMoveKey, "evil Install path", true, "," );

     ApplyFile( APPLICATIONPATH + "\\foo.exe" );
     ApplyFile( APPLICATIONPATH + "\\foo.exe", ALWAYS );
     ApplyFile( APPLICATIONPATH + "\\foo.exe", NEW_APPLICATIONPATH + "\\evil foo.exe" );
     ApplyFile( APPLICATIONPATH + "\\foo.exe", NEW_APPLICATIONPATH + "\\evil foo.exe", NEVER );
     ApplyMappedFile( DESKTOPPATH + "\\mapped.txt" );
     ApplyMappedFile( DESKTOPPATH + "\\mapped.txt", ALWAYS );
     ApplyMappedFile( DESKTOPPATH + "\\mapped.txt", NEW_DESKTOPPATH + "\\mapped.txt");
     ApplyMappedFile( DESKTOPPATH + "\\mapped.txt", NEW_DESKTOPPATH + "\\mapped.txt", NEVER);
     ApplyDirectory( APPLICATIONPATH );
     ApplyDirectory( APPLICATIONPATH, NEW_APPLICATIONPATH );
     ApplyDirectory( APPLICATIONPATH, NEW_APPLICATIONPATH, ALWAYS );
     ApplyDirectory( APPLICATIONPATH, NEW_APPLICATIONPATH, NEWER );

     DeleteKey( strBaseKey );
     DeleteValue( strBaseKey, "foo" );

     Register( APPLICATIONPATH + "\\FooCom.dll" );

     SetKey( strBaseKey );
     SetValue( strBaseKey, "foo", "STRING value", STRING );
     SetValue( strBaseKey, "foo", "DWORD value", DWORD );
     SetValue( strBaseKey, "foo", "BINARY value", BINARY );
     SetValue( strBaseKey, "foo", "EXPAND_STRING value", EXPAND_STRING );
     SetValue( strBaseKey, "foo", "MULTI_STRING value", MULTI_STRING );
     SetValue( strBaseKey, "foo", "DWORD_LITTLE_ENDIAN value", DWORD_LITTLE_ENDIAN );
     SetValue( strBaseKey, "foo", "DWORD_BIG_ENDIAN value", DWORD_BIG_ENDIAN );
     SetValue( strBaseKey, "foo", "SYMBOLIC_LINK value", SYMBOLIC_LINK );
     SetValue( strBaseKey, "foo", "RESOURCE_LIST value", RESOURCE_LIST );
     SetValue( strBaseKey, "foo", "FULL_RESOURCE_DESCRIPTOR value", FULL_RESOURCE_DESCRIPTOR );
     SetValue( strBaseKey, "foo", "RESOURCE_REQUIREMENTS_LIST value", RESOURCE_REQUIREMENTS_LIST );

     if (     KeyExists( strBaseKey )
          &&     KeyExists( strBaseKey, SOURCE ))
     {
          Print( "key exists" );
     }

     if (     ValueExists( strBaseKey, "foo" )
          &&     ValueExists( strBaseKey, "foo", SOURCE ))
     {
          Print( "value exists" );
     }

     if (     FileExists( APPLICATIONPATH + "\\foo.exe" )
          &&     FileExists( APPLICATIONPATH + "\\foo.exe", SOURCE ))
     {
          Print( "file exists" );
     }

     if (     DirectoryExists( APPLICATIONPATH )
          &&     DirectoryExists( APPLICATIONPATH, SOURCE ))
     {
          Print( "dir exists" );
     }

     platform = GetPlatform();
     PrintException( "platform = " + platform );

     platform = GetPlatform( true );
     PrintException( "platform = " + platform, VERY_DETAILED );

     Execute( NEW_APPLICATIONPATH + "\\foo.exe", "foo args" );
     Execute( NEW_APPLICATIONPATH + "\\foo.exe", "foo args", true );

     /* 成功完成 */
     Exit( "***BANG*** (exit test)" );
     Exit("unreachable code, just for parsing");
     Exit();     /* unreachable code, just for parsing */
}