飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 3915|回复: 1

[转贴] 【SDK完全接触---之Enigma篇】

[复制链接]

该用户从未签到

发表于 2008-11-2 17:03:33 | 显示全部楼层 |阅读模式
原帖:http://www.unpack.cn/viewthread.php?tid=29779
作者:xingyuwanwan

其实这个教程也是和上次的系列一块写好了,为了不让大家看多了眼花,所以隔了一段时间,今天贴出来.

enigma这个壳在易用性,人性化方面做的是很不错的,尤其是允许你自行设计它的注册框,这在其他程序中是难得一见的,记得很久以前的幻影中曾有这一功能,不过幻影早就不更新了.

我们先来看看几个常用的SDK:

{$I unprotected_begin.inc}
{$I unprotected_end.inc}
之间的代码只在未加壳保护时执行.如果加壳后,这之间的代码将不再被执行.

{$I decrypt_on_execute_begin.inc}
{$I decrypt_on_execute_end.inc}

之间的代码或模块,平常的时候是加密的,只有在需要运行它们的时候,才被解密到内存中并执行.这是为了防止内存dump.

{$I reg_crypt_begin9.inc} // (可取1--16)
{$I reg_crypt_end9.inc}

之间的代码,必须要在KEY中有相对应的解码标志才能被解密并执行.

{$I unreg_crypt_begin6.inc} //(可取1--16)
{$I unreg_crypt_end6.inc}

和上面的是相反的.
之间的代码,必须要在KEY中没有相对应的解码标志才能被解密并执行.

EP_ProtectedStringByID
返回相应ID的加密存储的字串.原型:
function EP_ProtectedStringByID(ID : integer; Buffer : pointer; Len : integer) : integer
把你需要加密的字串在程序中加密存储,只有在你需要调用它的时候,再解密到内存中.
要加密的字符串要在界面中"保护特性"--"protected strings"中加入,ID对应于界面中的ID,看下面:


0.GIF


调用方法:

var
arr:array of char;
begin
  setlength(arr,255); //请按你的实际字串长度初始化数组.这里255就够用.
  if EP_ProtectedStringByID(0,arr,255)>0 then //取0号,函数失败返回0,成功返回字串实际长度.
    begin
    Label1.caption:=string(arr);
    end;

  if EP_ProtectedStringByID(1,arr,255)>0 then //取ID1
    begin
    caption:=string(arr);
    end;
end;


再来看看如何自己实现注册框:

主窗体:
unit main;

inte**ce

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses enigma_ide,reg; //note uses

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
buf:array[0..1024] of char;
begin

if Not(EP_RegLoadAndCheckKey) then //EP_RegLoadAndCheckKey,load并check注册信息.
   begin
     Form2:=TForm2.Create(application); //如果没注册或注册信息不正确,创建注册窗体.
     Form2.ShowModal; //ShowModal注册窗体.
   end;

ZeroMemory(@buf, sizeof(buf)); //int
if EP_ProtectedStringByID(0,@buf,sizeof(buf))>0 then //取ID为0的加密字串.
   begin
   Label1.caption:=strpas(buf); //显示解密的字串.
   end;
end;

end.

再来看注册窗体代码:

unit reg;

inte**ce

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Label4: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}
uses enigma_ide;
procedure TForm2.Button1Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
edit1.Text:=strpas(EP_RegHardwareID); //取硬件ID
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
if EP_RegCheckAndSaveKey(pchar(edit2.Text),pchar(edit3.Text)) then //检查输入的注册信息.
   begin
   showmessage('注册信息正确的!'); //当然这里你可以应用EP_ProtectedStringByID将是更好的.
   close; //重启验证.
   end
esle
   begin
   showmessage('注册信息不正确!');
   close;
   end;
end;

end.


好了.可以加壳了:注意下图中几个选项不要选择:


1.GIF

source.rar

26.04 KB, 下载次数: 9, 下载积分: 飘云币 -2 枚

PYG19周年生日快乐!
  • TA的每日心情
    开心
    2024-3-31 23:36
  • 签到天数: 20 天

    [LV.4]偶尔看看III

    发表于 2017-7-30 15:46:35 | 显示全部楼层
    收藏一份,3Q
    PYG19周年生日快乐!
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表