Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts

Friday, March 6, 2015

Having fun with C# dynamic and reflection: create a class that let us to avoid access modifier

Yeah, the title says it all.

Have you ever get tired of manually call reflection methods to get a value of an hidden field? Yes I do!

In my spare time I found a funny solution to work around this problem.
I found a dummy way to avoid access modifier without losing 'deafult' syntax: thanks to c# dynamic object!
public class MyClass
{
    private int value = 1 ; 
}
private static void Main(string[] args)
{
    MyClass myInstance = new MyClass();

    //cannot access private field 'value' here
    //myInstance.value = 2;

    dynamic myInstance2 = myInstance.Expose();

    //can do it!
    myInstance2.value = 2;
}

Thursday, January 26, 2012

Getting started with Lamba Expressions

C# 3.0 brought so much news (for example var, extensions ,LINQ, lambda expressions etc...).
Sometime companies have its reason to don't update .NET framework in their applications.
For this, developers who grow parallely to those applications, never have time to upgrade their knowledges.

I know companies that use 2003's IDE in 2011!

For those who never had a chance to see what's new in latest framework, like me, I dedicate this post.

What is a lambda expression and what can I do with it?

It's "an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types" (msdn).

Thursday, January 5, 2012

Server Multi-client in C# .NET

Un altro progetto a scopo didattico che è sempre carino da affrontare è la comunicazione Client/Server via socket TCP.

E cosa schiarisce meglio le idee di un immagine?

Il progetto in questione si divide quindi in due parti. La prima è semplicemente un server, realizzato in c# .net, che:
-riceve in ingresso delle stringhe formattate in un certo modo,
-effettua un operazione a seconda di che stringa riceve,
-rimanda al client la risposta in formato stringa.

Questo tipo di progetto può avere numerosissimi tipi di applicazione: in teoria tutto quello che può fare un applicativo .Net è "attivabile/reperibile" via socket. Le più stupide modalità di utilizzo che mi vengono in mente ora possono essere: reperire dei dati da un database, lanciare procedure, controllare funzioni di sistema ecc... ecc... 

Vediamo un po' più nel dettaglio come funziona.

Wednesday, December 14, 2011

Keylogger in .NET (parte1)

Un giorno vidi, su una nota webzine, un articolo sui tipi di malware esistenti nel campo informatico.
Mi balzò all'occhio il keylogger e mi domandai... che ci vorrà mai a farne uno?

Perchè fare ciò? Per passare in qualche modo il mio giorno di requiem ;)

________________________________________________________________________________

Per prima cosa vediamo che caratteristiche dovrà avere questo keylogger (da ora in poi KL):

-Il software dovrà essere in grado di catturare tutti i tasti digitati dall'utente, segnalando tutti i comandi speciali e hotkey
-Il software dovrà essere in grado di riconoscere le finestre in uso dall'utente
-Il software dovrà loggare tutte le informazioni sopracitate e poterle inviare tramite mail o socket
-Il software dovrà essere totalmente trasparente all'utilizzatore del computer e individuabile solamente come processo nel task manager

Questo dovrebbe bastare per far si che il programma possa essere un keylogger.