中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 综合文章
简单的文件解码单元
作者:未知 时间:2005-08-07 20:58 出处:编程爱好者网站 责编:chinaitpower
              摘要:简单的文件解码单元
uses
   crt,
   dos;

var
  key:string[8];

{ decode file ---------------------------------------------------------------}
{your code here}
procedure decode(infname:pathstr);
var
  infile,outfile:file;
  fdir:dirstr; fname:namestr; fext:extstr;
  dbuf,sbuf:pointer;
  idx,i,j,srcseg,srcofs,dstseg,dstofs,start,csize:word;
  src,rep:byte;
begin
  if maxavail<2*65500 then Begin
Writeln(#13#10,'No Memory');
halt;
End;
getmem(dbuf,65500);
getmem(sbuf,65500);
srcseg:=seg(sbuf^); srcofs:=ofs(sbuf^);
dstseg:=seg(dbuf^); dstofs:=ofs(dbuf^); start:=dstofs;
assign(infile,infname);
{$i-} reset(infile,1); {$i+}
if ioresult<>0 then Begin
     Writeln(#13#10'File I/O!');
     halt;
  End;
  if filesize(infile)>65500 then halt;
  blockread(infile,sbuf^,filesize(infile));
  csize:=filesize(infile);
  close(infile);
  randseed:=ord(key[length(key)]); j:=0;
  for i:=0 to csize do begin
    mem[srcseg:srcofs+i]:=mem[srcseg:srcofs+i] xor
(ord(key[j])+random(ord(key[j])));
    j:=1+j mod 8;
  end;
  idx:=0;
  while idx
0 then Begin
     Writeln(#13#10'Output Error!');
     halt(4);
  End;
  blockwrite(outfile,key[1],length(key)); {so I know which key did it!}
  blockwrite(outfile,dbuf^,csize);        {un encoded}
  close(outfile);
  freemem(sbuf,65500);
  freemem(dbuf,65500);
end;

{ main ----------------------------------------------------------------------}

Procedure ShowFile(FName:String); {just a test ... not used in live version!}
Var
   T:Text;
   S:String;

Begin
   Assign(T,FName);
   ReSet(T);
   While not eof(t) do begin
{$I-}      Readln(t,s); {$I+}
      Writeln(s);
   End;
   Close(T);
End;

Var
   Cnt1:Integer;        {character 1}
   Cnt2:Integer;        {2}
   Cnt3:Integer;        {3}
   Cnt4:Integer;        {4}
   Cnt5:Integer;        {5}
   Cnt6:Integer;        {6}
   Cnt7:Integer;        {7}
   Cnt8:Integer;        {8}
   Ch:Char;             {did I press a local key?}
   outfile:file;        {just for making an empty file to append to}
   Dumb:Byte;           {dumb!}
   done:boolean;        {tried from '' to #255#255#255#255#255#255#255#255}

begin
   assign(outfile,'hack.org');
   {$i-} rewrite(outfile,1); {$i+}
   Close(outfile); {made a 0 byte file to append to}
{init}
   Cnt1:=0;
   Cnt2:=0;
   Cnt3:=0;
   Cnt4:=0;
   Cnt5:=0;
   Cnt6:=0;
   Cnt7:=0;
   Cnt8:=0;
   done:=false;
   While not done do begin
{not I inc 1 char at a time}
      Inc(Cnt1);
      If Cnt1>255 then Begin
  Cnt1:=0;
  Inc(Cnt2);
      End;
      If Cnt2>255 then Begin
  Cnt2:=0;
  Inc(Cnt3);
      End;
      If Cnt3>255 then Begin
  Cnt3:=0;
  Inc(Cnt4);
      End;
      If Cnt4>255 then Begin
  Cnt4:=0;
  Inc(Cnt5);
      End;
      If Cnt5>255 then Begin
  Cnt5:=0;
  Inc(Cnt6);
      End;
      If Cnt6>255 then Begin
  Cnt6:=0;
  Inc(Cnt7);
      End;
      If Cnt7>255 then Begin
  Cnt7:=0;
  Inc(Cnt8);
      End;
      If Cnt8>255 then Halt;
      Key:='';
      If Cnt1<>0 then key:=key+chr(cnt1);
      If Cnt2<>0 then key:=key+chr(cnt2);
      If Cnt3<>0 then key:=key+chr(cnt3);
      If Cnt4<>0 then key:=key+chr(cnt4);
      If Cnt5<>0 then key:=key+chr(cnt5);
      If Cnt6<>0 then key:=key+chr(cnt6);
      If Cnt7<>0 then key:=key+chr(cnt7);
      If Cnt8<>0 then key:=key+chr(cnt8);
{call your decode method}
      Decode('HACK.DAT');
      {ShowFile('HACK.ORG');}
{so I can see its running:}
      Writeln('KEY: ',Key);
      If Keypressed then Begin
  Ch:=Readkey;
  if ch=#27 then halt;
      End;
   End;
(*  if (paramcount<>2) or (pos('?',paramstr(1))>0) then begin
    writeln('Syntax: DECODE  
  
');
    writeln('Both parameters are required!');
    halt;
  end;
  key:=paramstr(2);
  decode(paramstr(1));
  writeln('File successfully decoded!'); *)
end.

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有