Skip to content
⌘ NSIS Forum Archive

Base64 decoder

11 posts

Yathosho#

Base64 decoder

the location of a dropbox folder is stored in a plain text file, encoded in base64. since the only base64 decoder for nsis has no documentation at all, i'm wondering how i can decode the file. for a smaller footprint, i wouldn't mind an alternative to decode only.
DrO#
actually msvcr80 is down to the plug-in having been built with dynamic linking in VS2005 and doesn't relate to .NET. however using it (no idea in respect to the original question) wouldn't be nice unless you make sure the dependency dll is in the same folder as the plug-in before it is then used.

-daz
Afrow UK#
Yes of course but the dist comes with .NET (2.0 not 3.5) and that can be a good indicator as whether or not it is installed on the destination machine.

Stu
Animaether#
well, there is the alternative linked to from that wiki.. and I think the original had the source code included, so could be recompiled to get rid of the dependency as well?

there's also plenty of code on the internet for base64 decoding in scripting languages.. presumably one of those could be adapted for NSIS use.

edit: in fact.. just do what this does.. but in reverse 😉 http://nsis.sourceforge.net/Base64
Afrow UK#
I posted a step by step on how to build a non MSVCRT dependant DLL in VS2008/VS2010 here:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


However, that plug-in would still need some mods to get it to build. For example, the way the the variables (such as string_to_encode) are being initialized to an empty string will cause the compiler to want to link memset. You can't use ZeroMemory either (again, memset) but a for loop would do the job.

Stu
Animaether#
Figured it'd be a fun coding exercise... I've updated http://nsis.sourceforge.net/Base64 to include the decoding function.

I haven't tested it rigorously - if there's an actual error in it (I know it uses more variables than it would strictly need, that's just for clarity), let me know or just edit the WiKi, of course.

Here's a further testbed, though:
!addincludedir "."
!include "LogicLib.nsh"
!include "CharToASCII.nsh"
!include "Base64.nsh"
OutFile "$%temp%\temp.exe"
Section
  /* testing a string with some typical URL chars */
  StrCpy $R9 "This is a test, this is only a test. http://nsis.sourceforge.net/?not+a%20query#at_all"
  ${Base64_Encode} $R9
  Pop $R8
  ${Base64_Decode} $R8
  Pop $R7
  MessageBox MB_OK "$R9 (in)$\n$R8 (encoded)$\n$R7 (decoded)$\n$R9 (in)"
  /* testing a supershort string */
  StrCpy $R9 "A"
  ${Base64_Encode} $R9
  Pop $R8
  ${Base64_Decode} $R8
  Pop $R7
  MessageBox MB_OK "$R9 (in)$\n$R8 (encoded)$\n$R7 (decoded)$\n$R9 (in)"
  /* testing a short string */
  StrCpy $R9 "AAA"
  ${Base64_Encode} $R9
  Pop $R8
  ${Base64_Decode} $R8
  Pop $R7
  MessageBox MB_OK "$R9 (in)$\n$R8 (encoded)$\n$R7 (decoded)$\n$R9 (in)"
  /* testing decoding of a looooooong string */
  StrCpy $R9 "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4NCk1hdXJpcyB2b2x1dHBhdCBsZWN0dXMgdmVsIG1pIHBoYXJldHJhIG1vbGxpcy4NCkluIG51bmMgZXJhdCwgYmxhbmRpdCBldSBncmF2aWRhIHZpdGFlLCBjb25zZWN0ZXR1ciBhIHF1YW0uDQpOdWxsYW0gc2FnaXR0aXMgbGliZXJvIHNpdCBhbWV0IHF1YW0gZGFwaWJ1cyB0aW5jaWR1bnQuDQpJbnRlZ2VyIGFudGUgYW50ZSwgZGFwaWJ1cyB1bGxhbWNvcnBlciBsYW9yZWV0IHNlZCwgcGVsbGVudGVzcXVlIHZlbCB0ZWxsdXMuDQpJbnRlZ2VyIGxhY2luaWEgaW1wZXJkaWV0IGxhY3VzIHV0IGRpZ25pc3NpbS4gTW9yYmkgZmFjaWxpc2lzIG1hZ25hIHZlbGl0Lg0KQWxpcXVhbSBwZWxsZW50ZXNxdWUgaWFjdWxpcyBuaXNpIGV1IGFsaXF1YW0uIEFsaXF1YW0gdGluY2lkdW50IHBlbGxlbnRlc3F1ZSBtb2xsaXMuDQpBZW5lYW4gY29uc2VjdGV0dXIgaW1wZXJkaWV0IGJsYW5kaXQuDQpJbnRlZ2VyIGFjIHJpc3VzIGEgbG9yZW0gY3Vyc3VzIHNjZWxlcmlzcXVlLg0KUGhhc2VsbHVzIHBlbGxlbnRlc3F1ZSwgbGliZXJvIHF1aXMgcG9zdWVyZSBydXRydW0sIG5lcXVlIHZlbGl0IGNvbnNlY3RldHVyIHRvcnRvciwgYWMgbWF0dGlzIGxpZ3VsYSBsZW8gZXUgYXJjdS4="
  ${Base64_Decode} $R9
  Pop $R7
  MessageBox MB_OK "$R7$\n$\n^^^ Lorem ipsum etc. with linebreaks ^^^"
SectionEnd 
As far as I can tell, the URLDecode variant works correctly as well - but difficult to find actual use examples via Google.
Animaether#
good to hear 🙂 I guess it works on the dropbox folder location storage bit as well, then 🙂