我认为它还是要用到外部文件,exe 文件运行是驻留在内存,否则,电脑重新启动,
内存的信息全部丢失,如果不用到外部文件,怎样保留!
我认为它可能以外部文件或注册表的方式保存!

解决方案 »

  1.   

    摘子 PMS(高山流水) 的程序,看看有没有用,是 BCB 的代码关于自释放解密的编程算法        关于自解密释放的编程,至少需要创建两个project,假设project1编译为
    main.exe,字节数为334848;project2编译为extract.exe,字节数为269824,用
            copy/b main.exe+extract.exe main.exe /y
    命令将extract.exe加到main.exe后面。
            在project1中,用
            fseek(fp0,334848,SEEK_SET); 
    跳过主模块的字节数,将其余部分(也就是extract.exe)写入到一个目标文件中,比如是s.exe,然后将密码及每个文件的文件名、所在路径名、字节数、日期时间、属性以及文件加密后的部分分别加入到s.exe中。
            在project2中,用
            fseek(fp0,269824L,SEEK_SET); 
    跳过自运行解密模块的字节长度,然后取密码及每个文件的文件名、所在路径名、字节数、日期时间、属性以及将文件加密后的部分解密,最后写成一个个解密后的文件。
            附件中是自解密释放部分的源代码,不足之处,还请朋友们多多指教。//---------------------------------------------------------------------------#include <vcl.h>
    #pragma hdrstop
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <dir.h>
    #include <conio.h>
    #include <io.h>
    #include <ctype.h>
    #define  PWDLEN  100  //密码长度上限#include "extract.h"
    #include "choosedir.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm5 *Form5;
    //---------------------------------------------------------------------------
    __fastcall TForm5::TForm5(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm5::FormCreate(TObject *Sender)
    {
      char pathname[MAXPATH];
      getcwd(pathname,MAXPATH);
      Edit1->Text=StrPas(pathname); //在Edit1中显示当前路径(也是默认的文件释放路径)
      Edit2->Clear();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm5::Button1Click(TObject *Sender)
    {
      Form6->ShowModal();  //调用选择文件释放路径的窗口
      Edit1->Text=Form6->DirectoryListBox1->Directory;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm5::Button3Click(TObject *Sender)
    {
      exit(0);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm5::Button2Click(TObject *Sender)
    {
      char buf[MAXDIR],fname[MAXDIR],pathname[MAXDIR],flen[15];
      char year[5],month[3],day[3],hour[3],min[3],tsec[3];
      char FileReadOnly,FileHidden,FileSys,FileArchive;
      unsigned char ch,epasswd[PWDLEN];
      unsigned char passwd[PWDLEN];
      register unsigned long i,FileLength;
      register int k;
      int m=0,ans,flag=1;
      struct ftime ft;
      FILE *fp0,*fp1;
      if(Edit2->Text=="")
      {
        Application->MessageBox("请输入密码!","出错信息",MB_OK);
        return;
      }
      Button2->Enabled=false;
      Button3->Enabled=false;
      mkdir(Edit1->Text.c_str());
      chdir(Edit1->Text.c_str());
      if((fp0=fopen(_argv[0],"rb"))==NULL)
      {
        MessageBeep(0);
        sprintf(buf,"无法打开文件:%s!",_argv[0]);
        Application->MessageBox(buf,"出错信息",MB_OK);
        return;
      }
      fseek(fp0,269824L,SEEK_SET); //跳过自运行解密模块的字节长度(不同环境可能会不一样)
      fgets(buf,100,fp0);  //取文件中的密码串
      strcpy(passwd,Edit2->Text.c_str());
      passwd[strlen(passwd)]='\0';  
      for(i=0;i<strlen(passwd);i++)
        epasswd[i]=decrypt(buf[i],passwd);   //将文件中加密后的密码串解密
      epasswd[i]='\0';
      if(strcmp(epasswd,passwd))  //将输入密码与解密后的密码串进行比较
      {
        MessageBeep(0);
        Application->MessageBox("密码不符!请重新输入!","出错信息",MB_OK);
        ActiveControl=Edit2;
        return;
      }
      for(k=0;k<7;k++)
      {
        Memo1->Lines->Add("  ");
      }
      Memo1->Lines->Clear();
      for(k=0;;k++)
      {
        fgets(pathname,MAXDIR,fp0); //取路径名
        pathname[strlen(pathname)-1]='\0';
        if(feof(fp0))  break;
        if(pathname[0]!='.')
          if(!DirectoryExists(pathname))
            if(mkdir(pathname))
              if(MakeDir(pathname))  //如果子目录不存在则创建之          {
                sprintf(buf,"创建子目录:\"%s\" 时出错!",pathname);
                Application->MessageBox(buf,"出错信息",MB_OK);
                return;
              }
        fgets(fname,MAXDIR,fp0);  //取文件名
        fname[strlen(fname)-1]='\0';
        if(strcmp(pathname,".\\")!=0)
            strcat(pathname,"\\");
        strcat(pathname,fname);
        if(FileExists(pathname)&&flag)
        {
          MessageBeep(0);
          sprintf(buf,"文件:%s已存在!!\n是否覆盖原文件?",pathname);
          ans=MessageDlg(buf,mtConfirmation,TMsgDlgButtons() << mbYes << mbNo <<mbAbort <<mbAll,0);
          if(ans==mrNo)
          {
            m++;
            fgets(flen,100,fp0);  //取字节数
            flen[strlen(flen)-1]='\0';
            FileLength=atol(flen);
            fgets(buf,MAXDIR,fp0);
            fgets(buf,MAXDIR,fp0);
            for(i=0;i<FileLength+1;i++)      ch=fgetc(fp0);
            continue;
          }
          else if(ans==mrAbort)
            break;
          else if(ans==mrAll)
            flag=0;
        }
        if(FileExists(pathname))
        {
          int Attrs=FileGetAttr(pathname);
          if(Attrs & faReadOnly) 
            FileSetAttr(pathname,Attrs & !faReadOnly);  //如是只读属性,解除之
          if(Attrs & faHidden)
            FileSetAttr(pathname,Attrs & !faHidden);  //如是隐藏属性,解除之
          if(Attrs & faSysFile)
            FileSetAttr(pathname,Attrs & !faSysFile);  //如是系统属性,解除之
        }
        if((fp1=fopen(pathname,"wb"))==NULL)
        {
          MessageBeep(0);
          sprintf(buf,"无法打开文件:%s!\n是否继续?",pathname);
          if(Application->MessageBox(buf,"出错信息",MB_YESNO)==IDYES)
          {
            m++;
            fgets(flen,100,fp0);  //取文件的字节数
            flen[strlen(flen)-1]='\0';
            FileLength=atol(flen);
            fgets(buf,MAXDIR,fp0);
            fgets(buf,MAXDIR,fp0);
            for(i=0;i<FileLength+1;i++)      ch=fgetc(fp0);
            continue;
          }
          else
            break;
        }
        sprintf(buf,"正在解密并释放文件:%s......",pathname);
        Memo1->Lines->Add(buf);
        fgets(flen,100,fp0);  //取文件的字节数
        flen[strlen(flen)-1]='\0';
        FileLength=atol(flen); 
        int FileAttr=0;
        if((FileReadOnly=fgetc(fp0))=='1')  FileAttr=faReadOnly;  //只读属性
        if((FileHidden=fgetc(fp0))=='1')  FileAttr|=faHidden;  //隐藏属性
        if((FileSys=fgetc(fp0))=='1')  FileAttr|=faSysFile;  //系统属性
        if((FileArchive=fgetc(fp0))=='1')  FileAttr|=faArchive;  //归档属性
        fgetc(fp0);
        fscanf(fp0,"%s%s%s%s%s%s",year,month,day,hour,min,tsec);  //取文件的日期时间
        fgetc(fp0);
        ft.ft_year=atoi(year);
        ft.ft_month=atoi(month);
        ft.ft_day=atoi(day);
        ft.ft_hour=atoi(hour);
        ft.ft_min=atoi(min);
        ft.ft_tsec=atoi(tsec);
        for(i=0;i<FileLength;i++) //根据每个文件的字节数来控制循环次数
        {
          ch=fgetc(fp0);
          ch=decrypt(ch,passwd); //解密
          fputc(ch,fp1);
        }
        fgetc(fp0);
        setftime(fileno(fp1),&ft);  //设置文件时间
        fclose(fp1);
        if(FileAttr!=0) FileSetAttr(pathname,FileAttr); //设置文件属性
        Memo1->Lines->Add("完毕!");
      }
      fcloseall();
      sprintf(buf,"已经解密并释放了%d个文件。",k-m);
      Application->MessageBox(buf,"信息",MB_OK);
    //  exit(0);
    }
    //---------------------------------------------------------------------------
    char __fastcall TForm5::decrypt(unsigned char ch,char passwd[PWDLEN])
    //解密函数
    //现在还不能公布解密算法,请大家谅解
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm5::Edit2Change(TObject *Sender)
    {
      if(Edit1->Text!=""&&Edit2->Text.Length()>=6)
        Button2->Enabled=true;
      else
        Button2->Enabled=false;        
    }
    //---------------------------------------------------------------------------
    //创建多层子目录,逐层创建int TForm5::MakeDir(char pathname[MAXDIR])
    {
      char dname[MAXDIR],buf[MAXDIR];
      int i,j=0,k,pos[50];
      for(i=0;i<strlen(pathname);i++)
      {
        if(pathname[i]=='\\')
        {
          pos[j]=i;
          j++;
        }
      }
      for(i=0;i<j;i++)
      {
        for(k=0;k<MAXDIR;k++)  dname[k]='\0';
        strncpy(dname,pathname,pos[i]);
        if(!DirectoryExists(dname))
          if(mkdir(dname))
          {
            sprintf(buf,"创建子目录:%s 时出错!",dname);
            Application->MessageBox(buf,"出错信息",MB_OK);
            return(-1);
          }
      }
      if(!DirectoryExists(pathname))
        if(mkdir(pathname))
        {
          sprintf(buf,"创建子目录:\"%s\"时出错!",pathname);
          Application->MessageBox(buf,"出错信息",MB_OK);
          return(-1);
        }
      return(0);
    }
      

  2.   

    sephil(木牌独行侠)所讲的这种东东我用BCB, Delphi和VC都做过,
    不过xiaotian2000所讲的应该不是指的这种。
      

  3.   

    xiaotian2000所讲的程序我刚刚Down下来看了,
    我原来以为很棒,看了后才知道它也要关闭后重开,
    这种东东我也做过,很简单的。
      

  4.   

    prometheusphinx(白日梦) 可以给我写个例子吗?谢谢
      

  5.   

    prometheusphinx(白日梦) 可以给我写个例子吗?谢谢 
    要实现可以往程序里写字符串,还可以更改程序图标