所以我需要了解这段代码的作用。我不知道帕斯卡或加密,我正在努力去理解这里发生了什么。我需要将SHA1DigestToHex
反向工程到scala中,并且完全失去了学习pascal的能力。你能告诉我这个功能在做什么吗?或者我怎么能搞清楚它?
Function SHA1DigestToHex (const Digest : T160BitDigest) : String;
Begin
Result := DigestToHex (Digest, Sizeof (Digest));
End;
Function DigestToHex (const Digest; const Size : Integer) : String;
Begin
SetLength (Result, Size * 2);
DigestToHexBuf (Digest, Size, Pointer (Result)^);
End;
Procedure DigestToHexBuf (const Digest; const Size : Integer; const Buf);
const s_HexDigitsLower : String [16] = '0123456789abcdef';
var I : Integer;
P : PChar;
Q : PByte;
Begin
P := @Buf;;
Assert (Assigned (P), 'Assigned (Buf)');
Q := @Digest;
Assert (Assigned (Q), 'Assigned (Digest)');
For I := 0 to Size - 1 do
begin
P^ := s_HexDigitsLower [Q^ shr 4 + 1];
Inc (P);
P^ := s_HexDigitsLower [Q^ and 15 + 1];
Inc (P);
Inc (Q);
end;
End;
type
PByte = ^Byte;
PWord = ^Word;
PLongWord = ^LongWord;
T128BitDigest = record
case integer of
0 : (Int64s : Array [0..1] of Int64);
1 : (Longs : Array [0..3] of LongWord);
2 : (Words : Array [0..7] of Word);
3 : (Bytes : Array [0..15] of Byte);
end;
P128BitDigest = ^T128BitDigest;
T160BitDigest = record
case integer of
0 : (Longs : Array [0..4] of LongWord);
1 : (Words : Array [0..9] of Word);
2 : (Bytes : Array [0..19] of Byte);
end;
P160BitDigest = ^T160BitDigest;
const
MaxHashDigestSize = Sizeof (T160BitDigest);
Procedure DigestToHexBuf (const Digest; const Size : Integer; const Buf);
Function DigestToHex (const Digest; const Size : Integer) : String;
Function Digest128Equal (const Digest1, Digest2 : T128BitDigest) : Boolean;
Function Digest160Equal (const Digest1, Digest2 : T160BitDigest) : Boolean;
答案 0 :(得分:3)
它只是将传入的二进制缓冲区的字节转换为!ifdef CreateSymbolicLinkFolder_
,形成一个十六进制数字字符串,表示!include Util.nsh
!include FileFunc.nsh
!macro CreateSymbolicLinkFolderImplementation
Exch $0 ; _TARGET
Exch 1
Exch $1 ; _JUNCTION
IfFileExists "$0" 0 done
${GetParent} "$1" $R0
CreateDirectory "$R0"
System::Call "kernel32::CreateSymbolicLinkW(w `$1`, w `$0`, i 1) i .s"
done:
Pop $R0
Pop $1
Pop $0
!macroend
!macro CreateSymbolicLinkFolder _JUNCTION _TARGET
Push "${_JUNCTION}"
Push "${_TARGET}"
${CallArtificialFunction} CreateSymbolicLinkFolderImplementation
!macroend
!define CreateSymbolicLinkFolder "!insertmacro CreateSymbolicLinkFolder"
Section
${CreateSymbolicLinkFolder} "c:\foo" "c:\bar"
SectionEnd
中的相同字节。
所以,例如如果Buf是字节数组(0x12,0x34,0x56),那么之后摘要将是' 123456'。
这是一个更简单的Pascal(Delphi)版本,可以做同样的事情:
Buf