|
!ifndef BASE64_NSH |
|
!define BASE64_NSH |
|
|
|
!define BASE64_ENCODINGTABLE "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
|
!define BASE64_ENCODINGTABLEURL "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" |
|
|
|
!define BASE64_PADDING "=" |
|
|
|
VAR OCTETVALUE |
|
VAR BASE64TEMP |
|
|
|
!define Base64_Encode "!insertmacro Base64_Encode" |
|
!define Base64_URLEncode "!insertmacro Base64_URLEncode" |
|
|
|
!macro Base64_Encode _cleartext |
|
push $R0 |
|
push $R1 |
|
push $R2 |
|
push $0 |
|
push $1 |
|
push $2 |
|
push $3 |
|
push $4 |
|
push $5 |
|
push $6 |
|
push $7 |
|
push `${_cleartext}` |
|
push `${BASE64_ENCODINGTABLE}` |
|
Call Base64_Encode |
|
Pop $BASE64TEMP |
|
Pop $7 |
|
Pop $6 |
|
Pop $5 |
|
Pop $4 |
|
Pop $3 |
|
Pop $2 |
|
Pop $1 |
|
Pop $0 |
|
pop $R2 |
|
pop $R1 |
|
pop $R0 |
|
Push $BASE64TEMP |
|
!macroend |
|
|
|
!macro Base64_URLEncode _cleartext |
|
push $R0 |
|
push $R1 |
|
push $R2 |
|
push $0 |
|
push $1 |
|
push $2 |
|
push $3 |
|
push $4 |
|
push $5 |
|
push $6 |
|
push $7 |
|
push `${_cleartext}` |
|
push `${BASE64_ENCODINGTABLEURL}` |
|
Call Base64_Encode |
|
Pop $BASE64TEMP |
|
Pop $7 |
|
Pop $6 |
|
Pop $5 |
|
Pop $4 |
|
Pop $3 |
|
Pop $2 |
|
Pop $1 |
|
Pop $0 |
|
pop $R2 |
|
pop $R1 |
|
pop $R0 |
|
Push $BASE64TEMP |
|
!macroend |
|
|
|
Function Base64_Encode |
|
pop $R2 |
|
pop $R0 |
|
StrCpy "$R1" "" |
|
|
|
StrLen $1 "$R0" |
|
StrCpy $0 0 |
|
|
|
${WHILE} $0 < $1 |
|
|
|
StrCpy $OCTETVALUE 0 |
|
|
|
StrCpy $5 $0 |
|
StrCpy $4 "$R0" 1 $5 |
|
${CharToASCII} $4 "$4" |
|
|
|
IntOp $OCTETVALUE $4 << 16 |
|
|
|
IntOp $5 $5 + 1 |
|
${IF} $5 < $1 |
|
StrCpy $4 "$R0" 1 $5 |
|
${CharToASCII} $4 "$4" |
|
|
|
IntOp $4 $4 << 8 |
|
IntOp $OCTETVALUE $OCTETVALUE + $4 |
|
|
|
IntOp $5 $5 + 1 |
|
${IF} $5 < $1 |
|
StrCpy $4 "$R0" 1 $5 |
|
${CharToASCII} $4 "$4" |
|
|
|
IntOp $OCTETVALUE $OCTETVALUE + $4 |
|
${ENDIF} |
|
${ENDIF} |
|
|
|
|
|
IntOp $4 $OCTETVALUE >> 18 |
|
IntOp $4 $4 & 63 |
|
StrCpy $5 "$R2" 1 $4 |
|
StrCpy $R1 "$R1$5" |
|
|
|
IntOp $4 $OCTETVALUE >> 12 |
|
IntOp $4 $4 & 63 |
|
StrCpy $5 "$R2" 1 $4 |
|
StrCpy $R1 "$R1$5" |
|
|
|
StrCpy $6 $0 |
|
StrCpy $7 2 |
|
|
|
IntOp $6 $6 + 1 |
|
${IF} $6 < $1 |
|
IntOp $4 $OCTETVALUE >> 6 |
|
IntOp $4 $4 & 63 |
|
StrCpy $5 "$R2" 1 $4 |
|
StrCpy $R1 "$R1$5" |
|
IntOp $7 $7 - 1 |
|
${ENDIF} |
|
|
|
IntOp $6 $6 + 1 |
|
${IF} $6 < $1 |
|
IntOp $4 $OCTETVALUE & 63 |
|
StrCpy $5 "$R2" 1 $4 |
|
StrCpy $R1 "$R1$5" |
|
IntOp $7 $7 - 1 |
|
${ENDIF} |
|
|
|
|
|
${IF} $7 > 0 |
|
${WHILE} $7 > 0 |
|
StrCpy $R1 "$R1${BASE64_PADDING}" |
|
IntOp $7 $7 - 1 |
|
${ENDWHILE} |
|
${ENDIF} |
|
|
|
IntOp $0 $0 + 3 |
|
${ENDWHILE} |
|
|
|
Push "$R1" |
|
FunctionEnd |
|
|
|
|
|
!define Base64_Decode "!insertmacro Base64_Decode" |
|
!define Base64_URLDecode "!insertmacro Base64_URLDecode" |
|
|
|
!macro Base64_Decode _encodedtext |
|
push `${_encodedtext}` |
|
push `${BASE64_ENCODINGTABLE}` |
|
Call Base64_Decode |
|
!macroend |
|
|
|
!macro Base64_URLDecode _encodedtext |
|
push `${_encodedtext}` |
|
push `${BASE64_ENCODINGTABLEURL}` |
|
Call Base64_Decode |
|
!macroend |
|
|
|
Function base64_Decode |
|
|
|
Push $9 |
|
Exch 2 |
|
Exch |
|
Exch $0 |
|
Exch |
|
Exch $1 |
|
|
|
Push $2 |
|
Push $3 |
|
Push $4 |
|
Push $5 |
|
Push $6 |
|
Push $7 |
|
|
|
Push $R0 |
|
Push $R1 |
|
Push $R2 |
|
Push $R3 |
|
Push $R4 |
|
|
|
Push $R5 |
|
Push $R6 |
|
|
|
Push $R7 |
|
Push $R8 |
|
Push $R9 |
|
|
|
StrCpy $9 "" |
|
|
|
StrLen $2 "$0" |
|
StrLen $3 "$1" |
|
IntOp $3 $3 - 1 |
|
|
|
StrCpy $R0 4 |
|
|
|
${ForEach} $5 0 $3 + 1 |
|
StrCpy $7 $1 1 $5 |
|
|
|
${If} $7 == "${BASE64_PADDING}" |
|
Push 0 |
|
${Else} |
|
${ForEach} $4 0 $2 + 1 |
|
StrCpy $6 $0 1 $4 |
|
${If} $6 S== $7 |
|
${ExitFor} |
|
${EndIf} |
|
${Next} |
|
Push $4 |
|
${EndIf} |
|
|
|
IntOp $R0 $R0 - 1 |
|
|
|
${If} $R0 = 0 |
|
|
|
Pop $R4 |
|
Pop $R3 |
|
Pop $R2 |
|
Pop $R1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IntOp $R5 $R1 << 2 |
|
IntOp $R6 $R2 >> 4 |
|
IntOp $R5 $R5 | $R6 |
|
IntFmt $R7 "%c" $R5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
IntOp $R5 $R2 & 15 |
|
InTop $R5 $R5 << 4 |
|
IntOp $R6 $R3 >> 2 |
|
IntOp $R5 $R5 | $R6 |
|
IntFmt $R8 "%c" $R5 |
|
|
|
|
|
IntOp $R5 $R3 & 3 |
|
IntOp $R5 $R5 << 6 |
|
IntOp $R5 $R5 | $R4 |
|
IntFmt $R9 "%c" $R5 |
|
|
|
StrCpy $9 "$9$R7$R8$R9" |
|
StrCpy $R0 4 |
|
${EndIf} |
|
${Next} |
|
|
|
|
|
Pop $R9 |
|
Pop $R8 |
|
Pop $R7 |
|
Pop $R6 |
|
Pop $R5 |
|
Pop $R4 |
|
Pop $R3 |
|
Pop $R2 |
|
Pop $R1 |
|
Pop $R0 |
|
Pop $7 |
|
Pop $6 |
|
Pop $5 |
|
Pop $4 |
|
Pop $3 |
|
Pop $2 |
|
Pop $1 |
|
Pop $0 |
|
Exch $9 |
|
FunctionEnd |
|
!endif |