portella.com.br

Blog pessoal de Felipe Portella

Archive for the ‘.NET Framework’ Category

String Format for Double [C#]

without comments

Many samples showing how to format float numbers to string in C#:

www.csharp-examples.net/string-format-double/

Written by Felipe Portella

agosto 23rd, 2011 at 10:45 pm

C# 3.0 and Parallel FX/LINQ in Mono – Ray Trace demo

without comments

Written by Felipe Portella

julho 27th, 2011 at 9:23 am

Ofuscamento e Engenharia reversa em .NET

without comments

Nada melhor que entender sobre como fazer engenharia reversa em .NET para entender como melhor proteger o nosso código.  Abaixo eu organizo alguns links sobre essa prática que me ajudaram a escolher melhor que ferramentas usar:

Esse primeiro artigo ensina como remover manualmente os opcodes inválidos e assim conseguir abrir o fonte “protegido” em ferramentas como .NET Reflector ou o dotPeak:

Removing Invalid OpCodes From Obfuscated Assemblies

Já este segundo é uma continuação na qual ele basicamente automatiza o processo:

Hacking Mono.Cecil – allowing invalid opcodes

Alguns outros artigos interessantes:

How to make your Obfuscator fool Reflector

Making NCloak fool Reflector

Protecting your precious code!

Protecting your precious code! – Part 2

Tamper Proofing your Code

Tamper Proofing – an implementation (Part 1)

Tamper Proofing – an implementation (Part 2)

Tamper Proofing – an implementation (Part 3)

 

Este outro site tem uma coleção de utilitários para este tipo de estudo: www.ntcore.com/utilities.php

Written by Felipe Portella

junho 3rd, 2011 at 1:26 pm

NuGet (NuPack): gerenciador de bibliotecas para .NET

without comments

O NuGet, que antes chamava-se NuPack, é um gerenciador de bibliotecas para a plataforma .NET.

O papel do Nuget é justamente ser um gerenciador de bibliotecas de modo a garantir que todas as dll´s de um pacote estejam atualizadas com suas versões corretas evitando assim erros de referência em seus projetos.

Ele é grátis e pode ser usado livremente no Visual Studio 2010. (Se você não tem o VS pode usar no Visual Web Developer 2010 Express)

Você pode obter o Nuget aqui : nuget.codeplex.com/

Após baixar e instalar o Nuget ele se integra automaticamente ao Visual Studio ou Visual Web Developer. O NuGet é uma extensão para o Visual Studio e você pode encontrá-lo no menu Tools/Library Package Manager.

Written by Felipe Portella

junho 2nd, 2011 at 4:34 pm

Problem with VC90 redistributables

without comments

I was facing a problem trying to run my application still compiled in debug in another machine (not a developer one, in other words without Visual Studio installed). Looking the Windows Logs -> Application appears this error:

Activation context generation failed for “C:\Projects\MyProgram.dll”.Error in manifest or policy file “C:\Projects\Microsoft.VC90.DebugCRT.MANIFEST” on line 4. Component identity found in manifest does not match the identity of the component requested. Reference is Microsoft.VC90.DebugCRT,processorArchitecture=”amd64″,publicKeyToken=”1fc8b3b9a1e18e3b”,type=”win32″,version=”9.0.21022.8″. Definition is Microsoft.VC90.DebugCRT,processorArchitecture=”amd64″,publicKeyToken=”1fc8b3b9a1e18e3b”,type=”win32″,version=”9.0.30729.4148″. Please use sxstrace.exe for detailed diagnosis.

The simple way to solve this was to edit the Microsoft.VC90.DebugCRT.MANIFEST file and change the version to the one that I have installed on the machine (in the case the VS 2008 redistributable download from here), so the begining of end file looks like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" 
                        processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity> 

Written by Felipe Portella

março 14th, 2011 at 11:16 pm

CryptographicException due to PaddingMode of TripleDESCryptoServiceProvider

without comments

Today I faced a “bug” in my decryption algorith due to the PaddingMode used by the TripleDESCryptoServiceProvider. As I was using the PaddingMode.PKCS7, when I try to decrypt using a wrong key (not the same key used to encrypt) I receive a System.Security.Cryptography.CryptographicException with the message “Bad Data”

This is not the behaviour that I wanted for my application. I want to decrypt and give as a result some invalid data … but decrypt …

If I change the PaddingMode in the correct cases (right keys) with input data that is not Base64, I´ll receive decrypted string that has spaces at the end … which is not also a desireble behaviour for me.

My solution was to use always PaddingMode.PKCS7, try to decrypt, catch the exception (when occurs) and decrypt again now without Padding.

If anyone has a better approach I will be happy to hear …

Written by Felipe Portella

janeiro 26th, 2011 at 2:07 pm

How to install an assembly into the Global Assembly Cache in Visual C#

without comments

Written by Felipe Portella

outubro 8th, 2009 at 4:36 pm

Posted in .NET Framework

Tagged with

Align String with Spaces [C#]

without comments

www.csharp-examples.net/align-string-with-spaces/

This example shows how to align strings with spaces. The example formats text to table and writes it to console output.

To align string to the right or to the left use static method String.Format. To align string to the left (spaces on the right) use formatting patern with comma (,) followed by a negative number of characters: String.Format(„{0,–10}“, text). To right alignment use a positive number: {0,10}.

Following example shows how to format text to the table. Values in the first and second column are aligned to the left and the third column is aligned to the right.

[C#]

Console.WriteLine("-------------------------------");
Console.WriteLine("First Name | Last Name  |   Age");
Console.WriteLine("-------------------------------");
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));
Console.WriteLine("-------------------------------");

Output string:

 -------------------------------
 First Name | Last Name  |   Age
 -------------------------------
 Bill       | Gates      |    51
 Edna       | Parker     |   114
 Johnny     | Depp       |    44
 -------------------------------

See also

Written by Felipe Portella

agosto 11th, 2009 at 11:57 am

A First Look at Visual Studio 2010 and .NET 4.0

without comments

Written by Felipe Portella

julho 14th, 2009 at 9:48 pm

Teste de classes internas

without comments

No arquivo AssemblyInfo.cs localizado na pasta Properties do projeto que
contém a classe interna que se deseja testar, adicione a seguinte
instrução:

[assembly: InternalsVisibleTo(“InternalConstructor.Test”)]

Isso torna classes internas visíveis ao assembly definido.

Dessa forma conseguiremos testar diretamente as classes internas, sem a
necessidade de testá-las através de chamadas de funções públicas que as
usam.

Written by Felipe Portella

junho 26th, 2009 at 10:07 pm