program getzcm; {$APPTYPE CONSOLE} uses 
  SysUtils, 
  Registry, 
  Windows; var 
  Reg: TRegistry;
  buf: PByteArray;
  size: Integer;  
  mask: array[0..19] of Byte = ($52,$D6,$E2,$E9,$EA,$F0,$CC,$F2,$35,$64,$07,$AD,$82,$C8,$78,$75,$9F,$31,$45,$BC);   i: integer; 
  username, password: string; 
begin 
  try 
      Reg := TRegistry.Create; 
      try 
        Reg.RootKey := HKEY_LOCAL_MACHINE; 
        if Reg.OpenKeyReadOnly('SOFTWARE\Eset\Nod\CurrentVersion\Modules\Update\Settings\Config000\Settings') then 
        begin 
            username := Reg.ReadString('Username'); 
            size := Reg.GetDataSize('Password'); 
            GetMem(buf, size); 
            Reg.ReadBinaryData('Password', buf^, size);             i := 0;             while i < size - 1 do 
            begin 
              password := password + chr(buf[i] xor mask[i]); 
              Inc(i, 2); 
            end;             WriteLn('Username: ' + username); 
            WriteLn('Password: ' + password); 
        end; 
      finally 
        Reg.CloseKey; 
        Reg.Free; 
      end; 
  except 
      on E: Exception do 
        Writeln(E.Classname, ': ', E.Message); 
  end; 
end.  
--------------------------------------------------------------------------------------以上是代码原文,我没有学delhpi 看不大懂这是我理解的:
 buf: PByteArray;//这个我不知道作什么username := Reg.ReadString('Username'); // 是读注册表的项值
            size := Reg.GetDataSize('Password'); //这个是不是读注册表中password值的 字符长度 ?
            GetMem(buf, size);//这个我上网查是说分配内存,不明白做什么
            Reg.ReadBinaryData('Password', buf^, size); //这个完全不明白这个意思            i := 0;             while i < size - 1 do 
            begin 
              password := password + chr(buf[i] xor mask[i]); //这个是把 buf[i] 和 mask[i] 进行异或比较取值 不明白buf[i]是什么? 和 mask[i]就是 mask: array[0..19] of Byte = ($52,$D6,$E2,$E9,$EA,$F0,$CC,$F2,$35,$64,$07,$AD,$82,$C8,$78,$75,$9F,$31,$45,$BC);这个 ??              Inc(i, 2); // 这个不清楚
            end;             WriteLn('Username: ' + username); //这里是写出换算好的值
            WriteLn('Password: ' + password); //这里是写出换算好的值我主要是知道这个算法的原理,我学的是易语言,看这个看不懂。希望赐教!!!感激不尽

解决方案 »

  1.   

     GetMem(buf, size); 后面要读二进制的东西进来,所以申请了个内存Reg.ReadBinaryData('Password', buf^, size);  把二进制的读到buf里面,上面buf已经申请内存了buf[i] 就是访问buf里的东西 Inc(i, 2);  就是  i:=i+2;
      

  2.   

    谢谢回答!请问  size := Reg.GetDataSize('Password'); //这个是不是读注册表中password值的 字符长度 ? 但是这里做异或比较 chr(buf[i] xor mask[i])mask: 有这个值 array[0..19] of Byte = ($52,$D6,$E2,$E9,$EA,$F0,$CC,$F2,$35,$64,$07,$AD,$82,$C8,$78,$75,$9F,$31,$45,$BC); 
    buf[i]没有值 怎么比较?
      

  3.   

                while i < size - 1 do 
                begin 
                  password := password + chr(buf[i] xor mask[i]); 
                  Inc(i, 2); 
                end; 难道是这句? 应该是异或再转换成字符,拼成字符串吧
      

  4.   

    Call GetDataSize to determine the size, in bytes, of a data value associated with the current key. ValueName is a string containing the name of the data value to query.On success, GetDataSize returns the size of the data value. On failure, GetDataSize returns -1.Note: If the data value is a string, GetDataSize returns the size of the data value and one extra byte for the terminating null character
    帮助里GetDataSize的说明,长度xor没有值默认buf[i]=$00  ,这个是我懵的 呵呵  
      

  5.   


    我就不明白 mask: 有这个值 array[0..19] of Byte = ($52,$D6,$E2,$E9,$EA,$F0,$CC,$F2,$35,$64,$07,$AD,$82,$C8,$78,$75,$9F,$31,$45,$BC); 
    buf[i]没有值 怎么比较?
     
    怎么个异或比较的  没有值啊异或,二进制运算.可逆运算.1 xor 1=0, 0 xor 0=0, 1 xor 0=1, 0 xor 1=1.
    a xor b的运算方法:将a,b 转化为2进制数,再进行对比,每个数位上的0或1如果相同,那么结果就取0,如果不同就取1,将得到的结果转化为原来进制的数,就是结果.
      

  6.   

    在计算机里所有的数据都是二进制,内部运算不需要什么转换,只要输出的时候才需要转换成字符、图像或声音等人能识别的信息。在32位的计算机里,一次就能运算32位(4个字节、一个integer32为整数)的数据。PByteArray是个指针,指针就是告诉计算机在内存的什么位置读写数据。内存什么位置多少字节可以读写,也是有操作系统按当前运行情况分配的。GetMem()就是让操作系统给程序分配一个可以操作的内存,内存位置就在这个时候确定。Reg.ReadBinaryData()就是把注册表中的数据填充到刚分配的内存中buf的作用就是为了按字节访问这段填充好的内存数据。buf[0]就是这段内存第一个字节
    buf[1]就是这段内存第二个字节
    ...这些都太基础了和具体语言没有关系,都是计算机原理,楼主还是多看看书,多找找资料吧。