Windows OS 경우 네이티브 컴파일러를 이용하여 애플리케이션을 만들 수 있는 환경은 MFC(Win32API), QT(C++) 그리고 델파이(C++Builder) 정도에 불과하다. QT는 5.15 LTS 버전을 마지막으로 QT 6.0을 올 하반기에 출시한다. 6.0은 C++17을 기반으로 하고 있으며, qmake를 빌드시스템으로 사용하지 않는다고 한다. 자세한 내용은 여기를 참고하자. 이번 글에서는 QT(C++)에서 class를 사용하는 기초 예제를 소스 형태(템플릿)로 작성하여 보았다.
// Qt Console Application
#include "circle.h"
#include "shape.h"
#include <QCoreApplication>
#include <iostream>
#include <memory>
using namespace std;
void ShowArea(Shape &shape);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// [1...]
// Shape square(10, 5);
// Circle circle(10);
// ShowArea(square);
// ShowArea(circle);
// [2...]
// Shape *square = new Shape(10, 5);
// Circle *circle = new Circle(10);
// ShowArea(*square);
// ShowArea(*circle);
// delete square;
// delete circle;
// [3...]
auto square = make_unique<Shape>(10, 5);
auto circle = make_unique<Circle>(10);
ShowArea(*square);
ShowArea(*circle);
return 0;
// return a.exec();
}
void ShowArea(Shape &shape) { cout << "Area : " << shape.Area() << endl; }
WPF(MVVM 패턴)개발을 위해 Caliburn.Micro를 사용할 때 Event 처리하는 방법을 살펴보자. xaml파일에 ‘Message.Attach’, ‘Command’, 기본 바인딩을 작성하고 ViewModel 클래스 파일에서 해당 이벤트를 처리한다. 기본 골격을 위한 세부 내용은 ‘Caliburn.Micro, MVVM 기반 WPF’, ‘ICommand, RelayCommand in WPF’를 참고한다.
<Window x:Class="WpfApp1.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:cal="http://www.caliburnproject.org"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
Title="CALIBURN MICRO" Height="450" Width="800">
<Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Button Content="Click me" Width="100" Height="40" x:Name="TestButton" />
<Button Content="Click me 0" Width="100" Height="40"
cal:Message.Attach="[Event Click] = [Action TestButton0($source)]" />
<Button Content="Click me 1" Width="100" Height="40"
cal:Message.Attach="[Event PreviewMouseUp] = [Action HelloClicked1($eventArgs)]" />
<Button Content="Click me 2" Width="100" Height="40" x:Name="TestButton2"
cal:Message.Attach="[Event PreviewMouseUp] = [Action HelloClicked2($source, $eventArgs)]" />
<Button Content="Click me 3" Width="100" Height="40" x:Name="TestButton3"
Command="{Binding ButtonTest}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />
<Button Content="Click me 4" Width="100" Height="40">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ButtonClick}"
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</Grid>
</Window>
C#과 같은 Managed code(GC) 언어는 바이너리(exe, dll) 리버스 엔지니어링을 통하면 개발 소스와 거의 동일한 결과물(code)을 얻을 수 있다. 이러한 역공학을 쉽게 지원하는 툴은 대표적으로 ILSpy와 dotPeek 등이 있다. C# 언어에 문제가 있어서 역공학이 쉽다는 말이 아니고 Managed code(GC, ARC)의 언어(Java, Python etc)의 특징이다.
Database 연결 문자열과 같은 보안에 취약한 소스를 보호하기 위해 난독화(Obfuscation:리버스 엔지니어링을 적용하지 못하게 만드는 기술) 프로그램을 사용한다. 난독화한 바이너리는 디컴파일러를 하여도 원래의 소스 코드는 보이지 않고 읽기 어려운 소스 코드로 나타난다. 대표적은 난독화 프로그램은 상용인 Eazfuscator, Skater와 무료로 사용할 수 있는 ConfuserEx, obfuscar 등이 있다.
위의 이미지는 ConfuserEx를 실행했을 때의 화면이며, obfuscar는 콘솔프로그램으로써 아래의 절차에 따라 난독화를 진행한다.