Execute Obfuscar Before Fody.Costura Merge Files - fody-costura

How can I Execute Obfuscar Before Fody.Costura Merge the Files Because Merged Files Are not obfuscated, using Fody.Costura compression or wihout it.
I've downloaded https://github.com/obfuscar/example.git project example for obfuscar, then I've installed Fody and Fody.Costura by nuget, But output example is not obfuscated if i check it with ILSpy project.
https://github.com/icsharpcode/ILSpy (ILSpy project to download compressed files and see dll code)
https://github.com/G4224T/Fody-Costura-Decompress (To decompress fody costura files).
My obfuscar configuration is
<?xml version='1.0'?>
<Obfuscator>
<Var name="InPath" value="." />
<Var name="OutPath" value=".\Obfuscator_Output" />
<Var name="HidePrivateApi" value="true" />
<Var name="KeepPublicApi" value="false" />
<Var name="KeyFile" value=".\test.snk" />
<Module file="$(InPath)\BasicExampleExe.exe" />
<!--<Module file="$(InPath)\BasicExampleLibrary.dll" />-->
</Obfuscator>
And in fody costura I've tried with
<Costura DisableCompression="true" />
and
<Costura DisableCompression="false" />
I want any option for obfuscate and merge files using this projects because are free, Thanks all

I've found a workarround of this, and was to make a new form project in solution that reference the ofuscated dlls and exe, then in this new project install fody.costura nuget package, after it you need to change some configuration and code:
obsfucar.xml
<Obfuscator>
<Var name="InPath" value="." />
<Var name="OutPath" value=".\Obfuscator_Output" />
<Var name="HidePrivateApi" value="true" />
<Var name="KeepPublicApi" value="false" />
<Var name="KeyFile" value=".\test.snk" />
<Module file="$(InPath)\BasicExampleExe.exe">
<!-- You need to ommit afuscate startup form to call it from new project with fody.costura -->
<SkipType name="BasicExampleExe.ExampleUI" />
</Module>
<Module file="$(InPath)\BasicExampleLibrary.dll" />
</Obfuscator>
Then in the Program class of the new project with fody.costura
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ObfuscatorBeforeFodyCostura
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new BasicExampleExe.ExampleUI());//Edit this part with the ofuscated form.
}
}
}
Here the solution project edited:
git clone https://juandrn#bitbucket.org/juandrn/obfuscatorbeforefodycostura.git
Thanks!

Related

Why is a generated file (via SourceGenerator) in .NET7-Windows csproj file not included, if a local namespace in xaml file is used?

The .NET7-Windows project with SourceGenerator e.g. MimeTypes is working.
When adding a local namespace to the WPF-UserControl the generated file is not included anymore.
How can I modify the project file, that all generated files are automatically included?
Reproducable Example:
Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<LangVersion>10</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<NoWarn>CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MimeTypes" Version="2.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
UserControl1.xaml:
<UserControl x:Class="Example.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid/>
</UserControl>
UserControl1.xaml.cs:
using System.Windows.Controls;
namespace Example
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
var x = MimeTypes.GetMimeType("Testfile.exe");
}
}
}
This is working as expected, but when adding:
xmlns:local="clr-namespace:Example"
The generated MimeTypes file is not included anymore, which leads to the compiler error CS0103 (The name 'MimeTypes' does not exist in the current context)

WPF: what could happen if 2 instances of my application report to the same log [duplicate]

I'm using a RollingFileAppender to log some info to a file with a conversionPattern (in the web.config) that looks like this for the header of each log section:
<conversionPattern value="%date - %property{userId} - %property{method}%newline--------------------------------%newline%message%newline%newline"/>
I'd like to log details under this header as bullet points. I'm currently trying to use another RollingFileAppender that logs to the same file with a simple conversionPattern of just a dash, like this:
<conversionPattern value="- %message%newline"/>
But these messages aren't making it into the log file. I'm using Log.Info() for the header and Log.Debug() for the bullet points and filtering each appender on their respective log levels. Is what I'm trying to do possible? Or is there a better way to get header and detail information into a log file from log4net?
Yes you can have two log4net appenders that append (write) to the same log file.
You need to place the following line in each of your Appenders:
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
This will make log4net use a minimal locking model that allows multiple processes to write to the same file.
Here's an example XML that uses two appenders writing to the same log file:
<log4net debug="false">
<appender name="RollingLogFileAppender1" type="log4net.Appender.RollingFileAppender">
<!-- this configures a log for the application messages -->
<file value="TestLog.log" />
<appendToFile value="true" />
<!-- next line uses a minimal locking model that allows multiple processes to write to the same file -->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<!-- make the most recent log the highest numbered log -->
<countDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date{MM-dd-yyyy HH:mm:ss.ff} [%property{NDC}] %message%newline [Thread: %thread] %c{1} Method:%method(%file{1}, Line:%line) %newline" />
</layout>
<!-- The following two filters insure only log requests of
version '1' use this Appender -->
</appender>
<appender name="RollingLogFileAppender2" type="log4net.Appender.RollingFileAppender">
<file value="TestLog.log" />
<appendToFile value="true" />
<!-- next line uses a minimal locking model that allows multiple processes to write to the same file -->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<!-- make the most recent log the highest numbered log -->
<countDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date{MM-dd-yyyy HH:mm:ss.ff} [%property{NDC}] [Thread: %thread] %c{1} Method:%method(%file{1}, Line:%line) %newline%message" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender1" />
<appender-ref ref="RollingLogFileAppender2" />
</root>
This can be found in the Apache documentation here:
Apache Log4Net Docs
Just search on this page for 'same file'.
Hope this helps.
You could realize if there is any problem with log4net checking the output window on visual studio. The library log errors there, very useful to detect configuration mistakes.

log4net log file not being written when the app is deployed

I have a WPF app that uses log4net. When I run it in Visual Studio, the log file is created in the Debug or Release folder as expected.
However, when I create an installer and run the installed app, the log file is not created. I added the following lines to the code...
string logFilePath = ((Hierarchy)LogManager.GetRepository())
.Root.Appenders.OfType<FileAppender>()
.FirstOrDefault()?.File;
using (StreamWriter sw = new StreamWriter(#"d:\log.log")) {
sw.WriteLine("Log file: " + logFilePath);
}
...to enable me to check that the log file was being written in the location I expected. It showed me that the log file was supposed to be written to C:\Program Files (x86)\Physio Diary\PhysioDiaryClient.log which is what I expected.
However, the file doesn't exist. Any idea why?
Here is the top of the App.config file...
<?xml version="1.0"
encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<param name="File"
value="PhysioDiaryClient.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="2" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-7level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
The bottom of the file looks like this...
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
The bits in between are all to do with the WCF services that the app uses.
Anyone any ideas?
Edit: As a test, I tried hard-coding the log file path in App.config to my D: drive (so it's hard-coded, and no question of a permissions issue), but the file still wasn't created.
Thanks to #dymanoid for pointing me in the right direction. The log4net docs are a bit weak in this area, but I found this answer that pointed out that you can use normal environment variables in the config file.
With the aid of this list of environment variables, I ended up with the following...
<param name="File"
value="${LOCALAPPDATA}\Physio Diary\PhysioDiaryClient.log" />
This correctly write the file to C:\Users\MyUsername\AppData\Local\Physio Diary\PhysioDiaryClient.log
Hope this helps someone.

Wix Burn select msi and apply mst dynamically

I have MSI's in english, german and a MST transform file for german installer.
Now in burn boostrapper how to bundle these MSI's and MST's so that appropriate localized MST is applied to the msi during runtime ?
<Bundle ....>
<Chain>
<PackageGroupRef Id='Netfx4Full' />
<PackageGroupRef Id='SQLServerCompact4.0' />
<MsiPackage Id="EN_MSI_x86"
SourceFile="$(var.MsiDir_x86)MyApp_x86.msi"
Compressed="yes" EnableFeatureSelection="no" Vital="yes" Visible="no"
InstallCondition="NOT VersionNT64">
<MsiProperty Name="INSTALL_LANG" Value="1033" />
<MsiProperty Name="TRANSFORMS" Value="[SystemLanguageID].mst"/>
<Payload Id="1031.mst" Compressed="yes" Name="de-localization" SourceFile="$(var.MsiDir_x86)1031.mst" />
</MsiPackage>
</Chain>
</Bundle>
Is this the right way to include MST in the bundle ?
I guess the error is in the payload attributes. If you swap the values of Id an Name it should work. The msi installer looks for a file named 1031.mst but you named it de-localization.

GAE log on localhost to file

when i debug my GAE application on localhost, how can i save the log created with Logger class to file? I can see it in console now(stderr) but dont want to redirct console to file. I found some solutions for python but cant make it work for java. Please can you help me?
Add an ApplicationAppender in your log.xml setting file:
<appender name="applicationAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="encoding" value="UTF-8"/>
<param name="file" value="C:/logs/yourlogname.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss} %-5p %l - %m%n" />
</layout>
</appender>
This is for log4j, but it is a standard logging paradigm. Also you need to have your logger definition use the appender you create.
In Linux and OSX, you can use tee to direct output to a file while still making it visible on standard out:
my_command | tee filename

Resources