@@ -18,6 +18,7 @@ internal class Program
1818 {
1919 public const long FileVersion450 = ( 4 << 24 ) + ( 50 << 16 ) + 0 ;
2020 public const long FileVersion456 = ( 4 << 24 ) + ( 56 << 16 ) + 0 ;
21+ public const long FileVersion493 = ( 4 << 24 ) + ( 59 << 16 ) + 30 ;
2122
2223 public class Options
2324 {
@@ -206,7 +207,7 @@ static int Main(string[] args)
206207 }
207208
208209 string exeFile = Path . Combine ( inputDir , "ISTAGUI.exe" ) ;
209- if ( ! UpdateExeConfig ( exeFile , noIcomVerCheck , verificationMode , overwriteConfig ) )
210+ if ( ! UpdateExeConfig ( exeFile , noIcomVerCheck , verificationMode , overwriteConfig , out long ? exeFileVersion ) )
210211 {
211212 Console . WriteLine ( "*** Update config file failed for: {0}" , exeFile ) ;
212213 return 1 ;
@@ -1452,117 +1453,120 @@ static int Main(string[] args)
14521453 Console . WriteLine ( "*** checkForPsdzInstancesLogFile Exception: {0}" , ex . Message ) ;
14531454 }
14541455
1455- try
1456+ if ( exeFileVersion == FileVersion493 )
14561457 {
1457- Target target = new Target
1458- {
1459- Namespace = "RheingoldPsdzWebApi.Adapter" ,
1460- Class = "PsdzWebService" ,
1461- Method = "StartPsdzWebserviceProcess" ,
1462- } ;
1463- IList < Instruction > instructions = patcher . GetInstructionList ( target ) ;
1464- if ( instructions != null )
1458+ try
14651459 {
1466- Console . WriteLine ( "PsdzWebService.StartPsdzWebserviceProcess found" ) ;
1467- bool alreadyPatched = false ;
1468- object psdzWebserviceProcessField = null ;
1469- object psdzWebApiLogDirField = null ;
1470- int insertIndex = - 1 ;
1471-
1472- // Bereits gepatcht?
1473- foreach ( Instruction inst in instructions )
1460+ Target target = new Target
14741461 {
1475- if ( inst . OpCode == OpCodes . Callvirt &&
1476- inst . Operand ? . ToString ( ) ? . Contains ( "set_WorkingDirectory" ) == true )
1477- {
1478- alreadyPatched = true ;
1479- break ;
1480- }
1481- }
1482-
1483- if ( ! alreadyPatched )
1462+ Namespace = "RheingoldPsdzWebApi.Adapter" ,
1463+ Class = "PsdzWebService" ,
1464+ Method = "StartPsdzWebserviceProcess" ,
1465+ } ;
1466+ IList < Instruction > instructions = patcher . GetInstructionList ( target ) ;
1467+ if ( instructions != null )
14841468 {
1485- // psdzWebserviceProcess-Feld: ldfld direkt vor call StartAndRegisterWebserviceProcess
1486- for ( int index = 0 ; index < instructions . Count ; index ++ )
1469+ Console . WriteLine ( "PsdzWebService.StartPsdzWebserviceProcess found" ) ;
1470+ bool alreadyPatched = false ;
1471+ object psdzWebserviceProcessField = null ;
1472+ object psdzWebApiLogDirField = null ;
1473+ int insertIndex = - 1 ;
1474+
1475+ // Bereits gepatcht?
1476+ foreach ( Instruction inst in instructions )
14871477 {
1488- if ( index >= 2 &&
1489- instructions [ index ] . OpCode == OpCodes . Call &&
1490- instructions [ index ] . Operand ? . ToString ( ) ? . Contains ( "StartAndRegisterWebserviceProcess" ) == true &&
1491- instructions [ index - 1 ] . OpCode == OpCodes . Ldfld &&
1492- instructions [ index - 2 ] . OpCode == OpCodes . Ldarg_0 )
1478+ if ( inst . OpCode == OpCodes . Callvirt &&
1479+ inst . Operand ? . ToString ( ) ? . Contains ( "set_WorkingDirectory" ) == true )
14931480 {
1494- psdzWebserviceProcessField = instructions [ index - 1 ] . Operand ;
1495- insertIndex = index - 2 ; // ldarg.0 vor ldfld psdzWebserviceProcess
1496- Console . WriteLine ( "psdzWebserviceProcess field found at index: {0}" , index - 1 ) ;
1481+ alreadyPatched = true ;
14971482 break ;
14981483 }
14991484 }
15001485
1501- // _psdzWebApiLogDir-Feld: im Konstruktor aus stfld nach ldarg.0, ldarg.1
1502- Target targetCtor = new Target
1503- {
1504- Namespace = "RheingoldPsdzWebApi.Adapter" ,
1505- Class = "PsdzWebService" ,
1506- Method = ".ctor" ,
1507- } ;
1508- IList < Instruction > ctorInstructions = patcher . GetInstructionList ( targetCtor ) ;
1509- if ( ctorInstructions != null )
1486+ if ( ! alreadyPatched )
15101487 {
1511- for ( int index = 0 ; index < ctorInstructions . Count ; index ++ )
1488+ // psdzWebserviceProcess-Feld: ldfld direkt vor call StartAndRegisterWebserviceProcess
1489+ for ( int index = 0 ; index < instructions . Count ; index ++ )
15121490 {
15131491 if ( index >= 2 &&
1514- ctorInstructions [ index ] . OpCode == OpCodes . Stfld &&
1515- ctorInstructions [ index - 1 ] . OpCode == OpCodes . Ldarg_1 &&
1516- ctorInstructions [ index - 2 ] . OpCode == OpCodes . Ldarg_0 )
1492+ instructions [ index ] . OpCode == OpCodes . Call &&
1493+ instructions [ index ] . Operand ? . ToString ( ) ? . Contains ( "StartAndRegisterWebserviceProcess" ) == true &&
1494+ instructions [ index - 1 ] . OpCode == OpCodes . Ldfld &&
1495+ instructions [ index - 2 ] . OpCode == OpCodes . Ldarg_0 )
15171496 {
1518- psdzWebApiLogDirField = ctorInstructions [ index ] . Operand ;
1519- Console . WriteLine ( "_psdzWebApiLogDir field found in .ctor at index: {0}" , index ) ;
1497+ psdzWebserviceProcessField = instructions [ index - 1 ] . Operand ;
1498+ insertIndex = index - 2 ; // ldarg.0 vor ldfld psdzWebserviceProcess
1499+ Console . WriteLine ( "psdzWebserviceProcess field found at index: {0}" , index - 1 ) ;
15201500 break ;
15211501 }
15221502 }
1503+
1504+ // _psdzWebApiLogDir-Feld: im Konstruktor aus stfld nach ldarg.0, ldarg.1
1505+ Target targetCtor = new Target
1506+ {
1507+ Namespace = "RheingoldPsdzWebApi.Adapter" ,
1508+ Class = "PsdzWebService" ,
1509+ Method = ".ctor" ,
1510+ } ;
1511+ IList < Instruction > ctorInstructions = patcher . GetInstructionList ( targetCtor ) ;
1512+ if ( ctorInstructions != null )
1513+ {
1514+ for ( int index = 0 ; index < ctorInstructions . Count ; index ++ )
1515+ {
1516+ if ( index >= 2 &&
1517+ ctorInstructions [ index ] . OpCode == OpCodes . Stfld &&
1518+ ctorInstructions [ index - 1 ] . OpCode == OpCodes . Ldarg_1 &&
1519+ ctorInstructions [ index - 2 ] . OpCode == OpCodes . Ldarg_0 )
1520+ {
1521+ psdzWebApiLogDirField = ctorInstructions [ index ] . Operand ;
1522+ Console . WriteLine ( "_psdzWebApiLogDir field found in .ctor at index: {0}" , index ) ;
1523+ break ;
1524+ }
1525+ }
1526+ }
15231527 }
1524- }
15251528
1526- if ( alreadyPatched )
1527- {
1528- Console . WriteLine ( "StartPsdzWebserviceProcess already patched" ) ;
1529- }
1530- else if ( insertIndex >= 0 && psdzWebserviceProcessField != null && psdzWebApiLogDirField != null )
1531- {
1532- List < Instruction > insertInstructions = new List < Instruction > ( ) ;
1529+ if ( alreadyPatched )
1530+ {
1531+ Console . WriteLine ( "StartPsdzWebserviceProcess already patched" ) ;
1532+ }
1533+ else if ( insertIndex >= 0 && psdzWebserviceProcessField != null && psdzWebApiLogDirField != null )
1534+ {
1535+ List < Instruction > insertInstructions = new List < Instruction > ( ) ;
15331536
1534- // psdzWebserviceProcess.StartInfo.WorkingDirectory = _psdzWebApiLogDir;
1535- insertInstructions . Add ( new Instruction ( OpCodes . Ldarg_0 ) ) ;
1536- insertInstructions . Add ( Instruction . Create ( OpCodes . Ldfld , ( dnlib . DotNet . IField ) psdzWebserviceProcessField ) ) ;
1537- insertInstructions . Add ( Instruction . Create ( OpCodes . Callvirt ,
1538- patcher . BuildCall ( typeof ( System . Diagnostics . Process ) , "get_StartInfo" ,
1539- typeof ( System . Diagnostics . ProcessStartInfo ) , null ) ) ) ;
1540- insertInstructions . Add ( new Instruction ( OpCodes . Ldarg_0 ) ) ;
1541- insertInstructions . Add ( Instruction . Create ( OpCodes . Ldfld , ( dnlib . DotNet . IField ) psdzWebApiLogDirField ) ) ;
1542- insertInstructions . Add ( Instruction . Create ( OpCodes . Callvirt ,
1543- patcher . BuildCall ( typeof ( System . Diagnostics . ProcessStartInfo ) , "set_WorkingDirectory" ,
1544- typeof ( void ) , new [ ] { typeof ( string ) } ) ) ) ;
1537+ // psdzWebserviceProcess.StartInfo.WorkingDirectory = _psdzWebApiLogDir;
1538+ insertInstructions . Add ( new Instruction ( OpCodes . Ldarg_0 ) ) ;
1539+ insertInstructions . Add ( Instruction . Create ( OpCodes . Ldfld , ( dnlib . DotNet . IField ) psdzWebserviceProcessField ) ) ;
1540+ insertInstructions . Add ( Instruction . Create ( OpCodes . Callvirt ,
1541+ patcher . BuildCall ( typeof ( System . Diagnostics . Process ) , "get_StartInfo" ,
1542+ typeof ( System . Diagnostics . ProcessStartInfo ) , null ) ) ) ;
1543+ insertInstructions . Add ( new Instruction ( OpCodes . Ldarg_0 ) ) ;
1544+ insertInstructions . Add ( Instruction . Create ( OpCodes . Ldfld , ( dnlib . DotNet . IField ) psdzWebApiLogDirField ) ) ;
1545+ insertInstructions . Add ( Instruction . Create ( OpCodes . Callvirt ,
1546+ patcher . BuildCall ( typeof ( System . Diagnostics . ProcessStartInfo ) , "set_WorkingDirectory" ,
1547+ typeof ( void ) , new [ ] { typeof ( string ) } ) ) ) ;
15451548
1546- int offset = 0 ;
1547- foreach ( Instruction insertInstruction in insertInstructions )
1549+ int offset = 0 ;
1550+ foreach ( Instruction insertInstruction in insertInstructions )
1551+ {
1552+ instructions . Insert ( insertIndex + offset , insertInstruction ) ;
1553+ offset ++ ;
1554+ }
1555+
1556+ patched = true ;
1557+ Console . WriteLine ( "PsdzWebService.StartPsdzWebserviceProcess patched" ) ;
1558+ }
1559+ else
15481560 {
1549- instructions . Insert ( insertIndex + offset , insertInstruction ) ;
1550- offset ++ ;
1561+ Console . WriteLine ( "*** Patching StartPsdzWebserviceProcess failed - " +
1562+ $ "insertIndex= { insertIndex } , processField= { psdzWebserviceProcessField != null } , logDirField= { psdzWebApiLogDirField != null } " ) ;
15511563 }
1552-
1553- patched = true ;
1554- Console . WriteLine ( "PsdzWebService.StartPsdzWebserviceProcess patched" ) ;
1555- }
1556- else
1557- {
1558- Console . WriteLine ( "*** Patching StartPsdzWebserviceProcess failed - " +
1559- $ "insertIndex={ insertIndex } , processField={ psdzWebserviceProcessField != null } , logDirField={ psdzWebApiLogDirField != null } ") ;
15601564 }
15611565 }
1562- }
1563- catch ( Exception ex )
1564- {
1565- Console . WriteLine ( "*** StartPsdzWebserviceProcess Exception: {0}" , ex . Message ) ;
1566+ catch ( Exception ex )
1567+ {
1568+ Console . WriteLine ( "*** StartPsdzWebserviceProcess Exception: {0}" , ex . Message ) ;
1569+ }
15661570 }
15671571
15681572 try
@@ -2071,8 +2075,9 @@ static int Main(string[] args)
20712075 return 0 ;
20722076 }
20732077
2074- static bool UpdateExeConfig ( string exeFileName , bool noIcomVerCheck , bool verificationMode , bool overwriteConfig )
2078+ static bool UpdateExeConfig ( string exeFileName , bool noIcomVerCheck , bool verificationMode , bool overwriteConfig , out long ? fileVersion )
20752079 {
2080+ fileVersion = null ;
20762081 try
20772082 {
20782083 if ( ! File . Exists ( exeFileName ) )
@@ -2089,7 +2094,6 @@ static bool UpdateExeConfig(string exeFileName, bool noIcomVerCheck, bool verifi
20892094 }
20902095
20912096 FileVersionInfo fvi = FileVersionInfo . GetVersionInfo ( exeFileName ) ;
2092- long ? fileVersion = null ;
20932097 string companyName = fvi ? . CompanyName ?? string . Empty ;
20942098 string legalCopyright = fvi ? . LegalCopyright ?? string . Empty ;
20952099 if ( ! string . IsNullOrEmpty ( fvi ? . FileVersion ) )
0 commit comments