goupviet / obfuscar

Automatically exported from code.google.com/p/obfuscar
0 stars 0 forks source link

Cant determine how to exclude legacy Cpp/Crt references from .NET linkage #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile .NET application linked to System.Dataset tchSchema XSD
2. Attempt to obfuscate 
3. Fails with crash in Mono.dll

What is the expected output? What do you see instead?
I expect to see everything filtered in the mapping log.

Instead, I get a crash, and no log. Handling the exception, I get a log with 
these results not filtered (empty { }'s indicate exception was caught and 
nothing was logged):

[AccessBuilder]<CppImplementationDetails>.??_C@_1BC@EKMDCNOB@?$AAK?$AAE?$AAR?$AA
N?$AAE?$AAL?$AA3?$AA2?$AA?$AA@$$BY0A@$$CB_W -> [AccessBuilder]A.p
{
}

[AccessBuilder]<CppImplementationDetails>.??_C@_0O@JKAFBCMB@CreateActCtxW?$AA@$$
BY0A@$$CBD -> [AccessBuilder]A.Q
{
}

[AccessBuilder]<CrtImplementationDetails>.ActivationContext -> 
[AccessBuilder]A.q
{
}

[AccessBuilder]<CrtImplementationDetails>.LanguageSupport -> [AccessBuilder]A.R
{
}

[AccessBuilder]gcroot<System::String ^> -> [AccessBuilder]A.r
{
}

[AccessBuilder]<CppImplementationDetails>.$ArrayType$$$BY00Q6MPBXXZ -> 
[AccessBuilder]A.S
{
}

[AccessBuilder]<CrtImplementationDetails>.Progress -> [AccessBuilder]A.s
{
}

[AccessBuilder]<CrtImplementationDetails>.AtExitLock -> [AccessBuilder]A.t
{
}

[AccessBuilder]<CrtImplementationDetails>.Handle<System::Object ^> -> 
[AccessBuilder]A.U
{
}

[AccessBuilder]<CrtImplementationDetails>.ThisModule -> [AccessBuilder]A.u
{
}

[AccessBuilder]<CppImplementationDetails>.??_C@_0BA@NOJDBDJO@?4?$DPAVtype_info?$
EA?$EA?$AA@$$BY0A@$$CBD -> [AccessBuilder]A.V
{
}

[AccessBuilder]<CppImplementationDetails>.$ArrayType$$$BY01Q6MXXZ -> 
[AccessBuilder]A.v
{
}

What version of the product are you using? On what operating system?
1.5.4, Win XP, SvcPk2, .NET 2.0

Please provide any additional information below.

1.)
I can bypass the crash and allow creation of the mapping log by making this 
change in obfuscator:
*** Obfuscator.cs ***
        public void SaveAssemblies( )
        {
//--                AssemblyFactory.SaveAssembly( info.Definition, outName );

//++
                try
                {
                    AssemblyFactory.SaveAssembly( info.Definition, outName );
                }
                catch (Exception ex)
                {
                    Console.WriteLine("");
                    Console.WriteLine("AssemblyFactory.SaveAssembly FAILS. Check Mapfile.");

                }

2.) These types are sucessfully filtered and everything here is working :

<?xml version='1.0'?>
<Obfuscator>
  <Var name="InPath" value="E:\Dev\" />
  <Var name="OutPath" value="E:\In\decompile" />
  <Var name="ReuseNames" value="false" />
  <Var name="RenameProperty" value="false" />
  <Var name="RenameEvents" value="false" />
  <Var name="HideStrings" value="false" />  

  <Module file="$(InPath)\AccessBuilder.exe">
    <SkipNamespace name="Harntrox*" />
    <SkipNamespace name="std*" />

    <SkipType name="_GUID" skipMethods="true" />
    <SkipType name="tagMSG" skipMethods="true" />
    <SkipType name="HWND__" skipMethods="true" />

    <SkipType name="tm" skipMethods="true" />
    <SkipType name="HDC__" skipMethods="true" />
    <SkipType name="tagRECT" skipMethods="true" />
    <SkipType name="_SECURITY_ATTRIBUTES" skipMethods="true" />
    <SkipType name="tagTEXTMETRICA" skipMethods="true" />
    <SkipType name="EHExceptionRecord" skipMethods="true" />

    <SkipType name="tagACTCTXW" skipMethods="true" />
    <SkipType name="HINSTANCE__" skipMethods="true" />
    <SkipType name="EHExceptionRecord/EHParameters" skipMethods="true" />
    <SkipType name="_s_HandlerType" skipMethods="true" />
    <SkipType name="_s_CatchableType" skipMethods="true" />
    <SkipType name="_s_ThrowInfo" skipMethods="true" />
    <SkipType name="_ldiv_t" skipMethods="true" />
    <SkipType name="PMD" skipMethods="true" />
    <SkipType name="_CONTEXT" skipMethods="true" />
    <SkipType name="FrameInfo" skipMethods="true" />
    <SkipType name="_tiddata" skipMethods="true" />
    <SkipType name="_EXCEPTION_POINTERS" skipMethods="true" />
    <SkipType name="type_info" skipMethods="true" />
    <SkipType name="__type_info_node" skipMethods="true" />
    <SkipType name="$_s__RTTIBaseClassArray$_extraBytes_4" skipMethods="true" />
    <SkipType name="_s__RTTICompleteObjectLocator" skipMethods="true" />
    <SkipType name="_s__RTTIClassHierarchyDescriptor" skipMethods="true" />
    <SkipType name="$_TypeDescriptor$_extraBytes_16" skipMethods="true" />
    <SkipType name="_s__RTTIBaseClassDescriptor2" skipMethods="true" />
    <SkipType name="localeinfo_struct" skipMethods="true" />

  </Module>

  </Obfuscator>

3.) Since This doesnt work: 
    <SkipNamespace name="CrtImplementationDetails*" />

How do i filter types with these namespaces (see mapping output above) :
        1. <CppImplementationDetails>
        2. <CrtImplementationDetails>
        3. gcroot<System::String ^>

Thanks in advance for any help you can offer !

Original issue reported on code.google.com by star...@cox.net on 26 Nov 2010 at 8:53

GoogleCodeExporter commented 9 years ago
The brackets on <CppImplementationDetails> are part of the name of the 
namespace. Did you try if this works:

<SkipNamespace name="<CrtImplementationDetails>" />

Original comment by webbi...@gmail.com on 27 Nov 2010 at 3:01

GoogleCodeExporter commented 9 years ago
I tried that and it broke the XML serializer class. I do not think the syntax 
is valid for xml: '<' embedded inside quotes. I assume the filter will work 
then if i can find the code that does the string compare and make is less 
'strict'.

Original comment by star...@cox.net on 27 Nov 2010 at 5:15

GoogleCodeExporter commented 9 years ago
Ok, you are right. '<' is not allowed in XML attributes.
But you can escape it like you would do in normal XML text:

<SkipNamespace name="<CrtImplementationDetails>" />

or use wildcards for the offending characters:

<SkipNamespace name="?CrtImplementationDetails?" />

If you want to do more complex matching use regular expressions. A name in 
SkipXXXX elements is parsed as regular expression if it starts with a '^' 
character.

Original comment by webbi...@gmail.com on 27 Nov 2010 at 5:40

GoogleCodeExporter commented 9 years ago
Unfortunately, This did not solve the crash.

However, The first problem with filtering has been solved using these

    <SkipNamespace name="?CrtImplementationDetails?" />
    <SkipNamespace name="?CppImplementationDetails?" />
    <SkipType name="*gcroot*" skipMethods="true" />

To filter out these...
        1. <CppImplementationDetails>
        2. <CrtImplementationDetails>
        3. gcroot<System::String ^>

The real Issue, the crash in Mono.dll, appears to be unrelated.
I have attached the crash dump and exception info, as well as a tester.exe and 
the associated obfuscat.xml.
Hopefully this is enough to repro the problem.

Exception Info:
Message "Object reference not set to an instance of an object." 
Source  "Mono.Cecil.dll"    
StackTrace  "   
at Mono.Cecil.TypeSpecification.get_FullName()\r\n   
at Mono.Cecil.ReferenceType.get_FullName()\r\n   
at Mono.Cecil.TypeSpecification.get_FullName()\r\n   
at Mono.Cecil.ModType.get_FullName()\r\n   
at Mono.Cecil.ReflectionWriter.CompleteMethodSig(IMethodSignature meth, 
MethodSig sig)\r\n   
at Mono.Cecil.ReflectionWriter.GetMethodDefSig(IMethodSignature meth)\r\n   
at Mono.Cecil.ReflectionWriter.VisitMethodDefinition(MethodDefinition 
method)\r\n   
at Mono.Cecil.ReflectionWriter.CompleteTypeDefinitions()\r\n   
at Mono.Cecil.StructureWriter.TerminateAssemblyDefinition(AssemblyDefinition 
asm)\r\n   
at Mono.Cecil.AssemblyDefinition.Accept(IReflectionStructureVisitor 
visitor)\r\n   
at Mono.Cecil.AssemblyFactory.WriteAssembly(AssemblyDefinition asm, 
BinaryWriter bw)\r\n   
at Mono.Cecil.AssemblyFactory.SaveAssembly(AssemblyDefinition asm, Stream 
stream)\r\n   
at Mono.Cecil.AssemblyFactory.SaveAssembly(AssemblyDefinition asm, String 
file)\r\n   
at Obfuscar.Obfuscator.SaveAssemblies() in 
E:\\Dev\\SVN\\Obfuscar\\Obfuscator.cs:line 129"

*** Obfuscator.cs ***
AssemblyFactory.SaveAssembly( info.Definition, outName ); //Exception Here

All parameters within info.Definition and outName appear valid?

Compiled with VS2005, using C++ .Net.
<zip attached contains tester.exe and .xml>

Thanks again for your awesome support.

Original comment by star...@cox.net on 27 Nov 2010 at 7:29

Attachments:

GoogleCodeExporter commented 9 years ago
I was able to reproduce this problem. The crash happens in the Cecil library 
even when no obfuscation is done at all.
Obfuscar uses Cecil version 0.6 by now. The current version is 0.9 which is a 
complete rewrite of the library.
The API has changed and I am currently porting Obfuscar to this version. I did 
a simple test with your assembly and it seems to handle it without crashing.
I think the best thing is to wait until the port to Cecil 0.9 is ready. I hope 
that I will have something working this week.

Original comment by webbi...@gmail.com on 29 Nov 2010 at 8:10

GoogleCodeExporter commented 9 years ago
I just uploaded version 2.0.0 of Obfuscar. It uses the 0.9 version of Cecil.

I tried this version on your test assembly. It seems to get saved correctly. 
The result starts and shows its GUI.

Original comment by webbi...@gmail.com on 3 Dec 2010 at 3:54

GoogleCodeExporter commented 9 years ago
The latest update to SVN binaries worked perfectly.  

All our obfuscation issues are now resolved!
Thanks for your incredible support. 

beta: SVN C# source wont compile though, needs update ? :)
***Obfuscator.cs *** line 37 using Mono.Collections.Generic;  // undef'd

Original comment by st...@starraudio.com on 3 Dec 2010 at 6:50

GoogleCodeExporter commented 9 years ago
I removed the "using Mono.Collections.Generic" from SVN.
It had no effect. Jumped in when I was testing something.

Original comment by webbi...@gmail.com on 3 Dec 2010 at 8:04