Trying obfuscating Dot Net Core applications - .net-core

I am trying to obfuscate a Dot Net Core application but I am having no success. I am using ConfuserEx, managed to get it to work with a Net Framework, but no luck when trying it out with a Net Core Console Application or Net Core DLL.
I get the error:
Object reference not set to an instance of an object.
Did anyone managed to obfuscate a Net Core application? If not is there any other tool that can do it?

You can try Obfuscar. Its free and open source.
Binaries can be loaded at https://www.nuget.org/packages/Obfuscar/
Project sample:
<Obfuscator>
<Var name="InPath" value=".\" />
<Var name="OutPath" value=".\output" />
<Var name="HideStrings" value="true" />
<Var name="UseKoreanNames" value="true" />
<Var name="ReuseNames" value="true" />
<Var name="RenameFields" value="true" />
<Var name="RenameProperties" value="true" />
<Var name="RenameEvents" value="true" />
<Var name="OptimizeMethods" value="true" />
<Var name="SuppressIldasm" value="true" />
<Var name="KeepPublicApi" value="false" />
<Var name="HidePrivateApi" value="true" />
<Module file="$(InPath)\YourApplication.dll" />
</Obfuscator>
Running obfuscation:
Obfuscar.Console.exe your_project.xml

I saw this error when I tried to obfuscate EXE file. DLLs do not yield this error.
But I need to add that at the moment ConfuserEx does not really support .NET Core assemblies, because it does not handle metapackages; all dependent assemblies must be explicitly specified in the main DLL, which makes it quite a hassle.

Related

Using NLog to log to MySql database using Pomelo provider in an ASP .Net Core 5 Web API

I have an ASP .Net Core Web API using NLog, and I am trying to configure it to log to a MySQL database. I am using Pomelo in my app to talk to MySql.
In the nlog.config file, I have:
<target name="db"
xsi:type="Database"
dbProvider="Pomelo.EntityFrameworkCore.MySql, Pomelo.EntityFrameworkCore"
connectionString="blah blah blah"
commandType="StoredProcedure"
commandText="`InsertLog`"
>
<parameter name="machineName" layout="${machinename}" />
<parameter name="logged" layout="${date}" />
<parameter name="logLevel" layout="${level}" />
<parameter name="message" layout="${message}" />
<parameter name="logger" layout="${logger}" />
<parameter name="properties" layout="${all-event-properties:separator=|}" />
<parameter name="callsite" layout="${callsite:fileName:true}" />
<parameter name="exception" layout="${exception:tostring}" />
<parameter name="callsiteLineNumber" layout="${callsite-linenumber}" />
<parameter name="stackTrace" layout="${stacktrace}" />
</target>
However, it's giving an error "Could not load file or assembly 'Pomelo.EntityFrameworkCore"
Do I have the wrong dbProvider? Does Nlog not work with Pomelo?
I followed lauxjpn's comment, and it worked. Thanks lauxjpn!

Strange error while trying to use desktop bridge for wpf

I am trying to use Visual studio project template for desktop bridge to add to wpf app and it will not build successfully and shows this strange warning that i have attached.
warning when building desktop bridge project template
i had followed this post on official documentation :
https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net
and before that i had used this blog post to add winmd and runtime to my project:
https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/
and here is the code form Package.appxmanifest file:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp rescap iot">
<Identity Name="09b95fbd-84cc-426f-9fd2-2c1d3d304fab" Publisher="CN=SO-PC-005" Version="1.0.0.0" />
<Properties>
<DisplayName>WapProjTemplate</DisplayName>
<PublisherDisplayName>SO-PC-005</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements DisplayName="WapProjTemplate" Description="WapProjTemplate" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<iot:Capability Name="systemManagement" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
I also would like to mention that i am trying to use windows.graphics.display for brightness override in a wpf app and it requires systemManagement capapbility. And also that my project builds successfully without packaging project but when I add packaging project to my wpf solution it will not build.

How can I speed up MXMLC compiles?

I am using ant to build my web application. I have a target in my ant script which takes approximately 8 minutes to compile. Since mxmlc compiles everything from scratch and loads up the JVM each time, it is taking a lot of time. Is there a way to optimize this task?
I am using Flex SDK 3.0. Here is my ant target:
<target name="compile.organic.flash" depends="setup">
<property name="WelcomeBack.swf" value="${www.dir}/swf/as3/apps/welcome/WelcomeBack.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/welcome/src/WelcomeBack.as"
output="${WelcomeBack.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
accessible="true"
default-background-color="${swf.backgrond.color}"
allow-source-path-overlap="true"
compiler.strict="true">
<default-size width="940" height="528" />
<source-path path-element="${Welcome.path}"/>
<source-path path-element="${AS3.classpath}"/>
</mxmlc>
<property name="Welcome.swf" value="${www.dir}/swf/as3/apps/welcome/Welcome.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/welcome/src/Welcome.as"
output="${Welcome.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
accessible="true"
default-background-color="${swf.backgrond.color}"
allow-source-path-overlap="true"
compiler.strict="true">
<default-size width="940" height="528" />
<source-path path-element="${Welcome.path}"/>
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="App.swf" value="${www.dir}/swf/as3/apps/App-${svnVersion}.swf" />
<mxmlc file="${AS3.classpath}/com/organic/app/fthb/App.as"
output="${App.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
default-background-color="${swf.backgrond.color}"
compiler.strict="true">
<default-size width="300" height="300" />
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="LSOApp.swf" value="${www.dir}/swf/as3/apps/LSOApp-${svnVersion}.swf" />
<mxmlc file="${AS3.classpath}/com/organic/boa/fthb/LSOApp.as"
output="${LSOApp.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="30"
default-background-color="${swf.backgrond.color}"
compiler.strict="true">
<default-size width="300" height="300" />
<source-path path-element="${AS3.classpath}"/>
<compiler.include-libraries dir="${AS3.component}/" >
</compiler.include-libraries>
</mxmlc>
<property name="CheckRates.swf" value="${www.dir}/swf/as3/apps/CheckRates-${svnVersion}.swf" />
<mxmlc file="${CheckRates.path}/CheckRates.as"
output="${CheckRates.swf}"
incremental="${mxmlc.inc}"
default-frame-rate="40"
accessible="true"
default-background-color="${swf.backgrond.color}"
compiler.strict="true" compiler.allow-source-path-overlap="true" >
<default-size width="940" height="528" />
<compiler.source-path path-element="${AS3.classpath}"/>
<compiler.source-path path-element="${CheckRates.path}"/>
<!-- <source-path path-element="${AS3.classpath}"/> -->
<compiler.include-libraries dir="${AS3.classpath}">
<include name="fl/fl.swc" />
</compiler.include-libraries>
</mxmlc>
<copy file="${AS3.classpath}/com/organic/app/fthb/checkRates/js/config/check_rates_config.js" tofile="${www.dir}/swf/as3/apps/config/check_rates_config.js"/>
<property name="PointsCalculator.swf" value="${www.dir}/swf/as3/apps/PointsCalculator-${svnVersion}.swf" />
<property name="flash.apps.build.dir" value="${www.dir}/swf/as3/apps" />
<compile-flash basename="PointsCalculator" srcdir="${flash.apps.src.dir}/pointsCalculator">
</compile-flash>
<copy todir="${flash.apps.build.dir}/config">
<fileset dir="${flash.apps.src.dir}/pointsCalculator/config" includes="*.js"/>
</copy>
<copy todir="${build.dir}/www/css">
<fileset dir="${flash.apps.src.dir}/pointsCalculator/css" includes="*.css"/>
</copy>
<copy todir="${build.dir}/www/swf/as3/apps/welcome/assets/swfs">
<fileset dir="${flash.apps.src.dir}/welcome/assets/swfs" includes="*.swf"/>
</copy>
<copy file="${videoplayer.dir}/videoplayer.swf" tofile="${www.dir}/swf/as3/apps/videoplayer.swf" />
</target>
Use fcsh. From the first paragraph of that link
The fcsh (Flex Compiler Shell) utility provides a shell environment
that you use to compile Flex applications, modules, and component
libraries. It works very similarly to the mxmlc and compc command line
compilers, but it compiles faster than the mxmlc and compc
command-line compilers. One reason is that by keeping everything in
memory, fcsh eliminates the overhead of launching the JVM and loading
the compiler classes. Another reason is that compilation results (for
example, type information) can be kept in memory for subsequent
compilations.
We found that what was slowing down the compiler was mostly linking assets. We made a library project swf that is just used for assets (images, swfs, etc.) except fonts, and it works a treat.
We have a massive project building under 2 mins from maven.

Error "Could not resolve <s:SolidColorStroke>" When Trying to Compile a Flex 4 SWC with Ant

I'm trying to compile a component using ant and keep getting this error message throughout the component . . .
ButtonSkin.mxml(179): Error: Could not resolve <s:SolidColorStroke> to a component implementation.
ButtonSkin.mxml(210): Error: Could not resolve <s:GradientEntry> to a component implementation.
It compiles fine in FlashBuilder 4. Here is the contents of the build.xml:
<project name="Flex Ant Tasks Build Script" default="compile flex project">
<property name="FLEX_HOME" value="c:/build/flex_sdk" />
<property name="SDK_VERSION" value="4.1.0.16076" />
<taskdef resource="flexTasks.tasks" classpath="c:/build/flex_sdk/lib/flexTasks.jar"/>
<echo message="File: ${FLEX_HOME}"/>
<!-- Build and output the Main.swf-->
<target name="compile flex project">
<compc output="${basedir}/../FlexSI/libs/MyLibrary.swc" locale="en_US">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${basedir}/src"/>
<include-sources dir="${basedir}/src" includes="*" />
<library-path dir="${basedir}/libs" includes="*" append="true"/>
<namespace uri="http://testapp.com/siLibrary" manifest="${basedir}/src/xml/manifest.xml" />
</compc>
</target>
</project>
SolidColorStroke doesn't belong to Spark theme. Try to use mx:SolidColorStroke instead of s:SolidColorStroke. Same with GradientEntry.
Discussion on the related issue at forums.adobe.com.
Suggested workaround or solution is to explicitly specify all Spark (Flex4) and Halo (Flex3) related class namespaces, e.g.
<namespace uri="library://ns.adobe.com/flex/spark" manifest="${FLEX_HOME}/frameworks/spark-manifest.xml"/>
<namespace uri="http://ns.adobe.com/mxml/2009" manifest="${FLEX_HOME}/frameworks/mxml-2009-manifest.xml"/>
<namespace uri="http://www.adobe.com/2006/mxml" manifest="${FLEX_HOME}/frameworks/mxml-manifest.xml"/>

How do you update FX_schema.xml file in IIS 7?

We are deploying our ASP.Net MVC application to a windows 2008 R2 server, running IIS 7.5.
After deployment, we get this error in the event log (we also get an email) :
"Unrecognized element 'providerOption'" on line x in c:\wwwroot\web.config
which is:
<providerOption name="CompilerVersion" value="v3.5">
located in the system.codedom compiliers section of our standard web config. I investigated the problem a bit. (I also checked the namespace details on msdn to find out abit about it). Amongst many other solutions, I found this post recommending updating the FX_Schema.xml file on our server. (I think this is where the problem is, please correct me if I'm mistaken)
I looked through fx_schema file, and, as defined in the event viewer, the attribute "providerOption" is not in this schema! Here is the copy of the system.codedom section from the FX_schema.xml
<sectionSchema name="system.codedom">
<element name="compilers">
<collection addElement="compiler" removeElement="remove" clearElement="clear">
<attribute name="language" type="string" isCombinedKey="true" />
<attribute name="extension" type="string" isCombinedKey="true" />
<attribute name="type" type="string" />
<attribute name="warningLevel" type="int" />
<attribute name="compilerOptions" type="string" />
</collection>
</element>
</sectionSchema>
I am sure that I can not be the the only person who has this problem, but has anyone else anyone come across this before and found a solution?
EDIT: Another way to produce this quickly is (on IIS 7 in Windows 7)
In IIS Managment console, open your MVC website, in the website home. You should see ASP.NET, IIS, and Managment groups. Under Management, open the "Configuration Editor". I get the error message popping up here!
EDIT: My copy of the web config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
I've managed to recreate the error in IIS by simply going to the system.codedom section of the configuration manager.
I don't get any error using either a .net3.5 or .net4.0 app but these are very basic test apps, also only .net3.5 test apps put a system.codedom section in the web.config file by default.
.net4.0 simplified the web.config file and moved out a lot of options
I've found some information here about possible config conflicts which may be of use
It recomends
The workaround for the second scenario
is to delete or comment out all the
system.web.extensions configuration
section definitions and configuration
section group definitions from the
application-level Web.config file.
These definitions are usually at the
top of the application-level
Web.config file and can be identified
by the configSections element and its
children.
For both scenarios, it is recommended
that you also manually delete the
system.codedom section, although this
is not required
Not exactly the same problem but similar
I had an issue very similar to this that I posted and then solved myself and posted the solution I came up with. My solution: I made my own file and placed it in with the schema files. I called it the inventive name ThreeFive.xml and placed it at C:\Windows\System32\inetsrv\config\schema. The entire contents of the file are as follows:
<configSchema>
<sectionSchema name="system.codedom">
<element name="compilers">
<collection addElement="compiler" removeElement="remove" clearElement="clear">
<attribute name="language" type="string" isCombinedKey="true" />
<attribute name="extension" type="string" isCombinedKey="true" />
<attribute name="type" type="string" />
<attribute name="warningLevel" type="int" />
<attribute name="compilerOptions" type="string" />
<collection addElement="providerOption">
<attribute name="name" required="true" isUniqueKey="true" type="string" />
<attribute name="value" required="true" type="string" />
</collection>
</collection>
</element>
</sectionSchema>
</configSchema>
I then published a 3.5 site that retrieved information from an appconfig setting and did some LINQ to make sure the config and the 3.5 were in effect. The config file was not blanked and the LINQ is working as expected so I am tempted to call this a solution.

Resources