Portable version of NodeJS on Windows

(This is a corrected version of this blog post)

  1. Install Cmder in your desired location.
  2. Download nvm-noinstall.zip from the latest release.
  3. Extract the contents of nvm-noinstall.zip (i.e.: nvm.exe …) into the bin folder inside of the portable Cmder folder.
  4. Navigate to the bin.
  5. Create a new file called install_fix.cmd that contains this code.
  6. Open a terminal in the bin folder and type .\install_fix.cmd
  7. When asked to enter the path use the full path to your Cmder bin folder.
  8. If it worked, a file called settings.txt has been created in the your Cmder bin folder.
  9. Close the terminal, and reopen it in the bin folder.
  10. Install the version of Node you want, e.g. nvm install latest.
  11. Wait until the installation is completed, then, inside the bin folder, there should be a new folder containing the latest Node version (e.g. v17.3.0).

From there, you can use the full path to your Cmder bin + the Node version folder + node.exe to execute something with this version of Node using Powershell, CMD or other terminal.

For example:

1
PS D:\experiments\my-stuff\> D:\experiments\nodejs-portable\cmder_mini\bin\v17.3.0\node.exe index.js

You could use Cmder with the Node path in the Startup Settings of the app; e.g. set "PATH=D:\experiments\nodejs-portable\cmder_mini\bin\v17.3.0;%PATH%". This way, in Cmder, when typing node.exe it’s the portable version that will be used.

Redirect non-www to www on a PHPBB Forum

In the PHPBB directory, edit the file .htaccess and after RewriteRule ^(.*)$ app.php [QSA,L] you can enter:

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Debug a third party Android APK

(inspired by this blog post)

1) Install smalidea plugin

Download the smalidea plugin (see also the related Github Repository).

Open up Android Studio and you should see the welcome screen like the one on screenshot below (if not, close your current project by selecting File -> Close project), go to the Plugins section, and from the wheel icon, select Install Plugin from Disk.... Select the smalidea plugin (ZIP file) you downloaded.
Android Studio welcome screen

2) Get the third party APK

You first need to know the type of platform where you’ll do your debug tests. To do so, make sure your device is connected to your computer (it could also be a virtual device started from the AVD Manager) with adb devices.
Then, use the command adb shell getprop ro.product.cpu.abi to find the type of processor you have. When I use my phone, I got arm64-v8a.

Go to an APK platform, like https://apkcombo.com/ and search for the Android app you want to debug. Download the APK version that fits to the type you found before:
screenshot of https://apkcombo.com/

2bis) Have a look at the APK content

You can use JADX to open the APK and have a quick look at the code.

3) Decompile APK

With APKTool, we’ll use the command: .\apktool.bat d ".\the_original_app_from_apkcombo.com.apk" -o app_to_debug.
A folder called app_to_debug is created with the decompiled version of the application.

Next, we need to copy the source files: create a folder called “src” in the new app_to_debug folder, and type cp -R smali*/* src/.

4) Import project in Android Studio

Open an existing Android Studio project and select the app_to_debug folder where you unpacked APK.

Once the project loads, you need to tell the IDE where is your source code. Make sure you’re using the “Project view” in the left side panel:

Now you can see folder structure in your left panel. Find src/ subfolder right click it and select Mark Directory as -> Sources Root.

5) Prepare App for Debugging

Open AndroidManifest.xml from the app_to_debug and find the XML element <application>. Add the attribute android:debuggable with value “true”. Example:

1
<application android:debuggable="true" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:largeHeap="true" android:name="org.horaapps.leafpic.App" android:theme="@style/Theme.AppCompat">

6) Repack to APK

You can now repack to APK with the command .\apktool.bat b -d ".\app_to_debug\" -o app_unsigned.apk

7) Sign the APK

7a) Create a keystore

You first need a keystore using keytool and type the below command:
keytool -genkeypair -v -keystore mykey.keystore -alias mykey -keyalg RSA -keysize 2048 -validity 10000

Several questions you’ll be asked, as well as a password. Make sure to remember the password for later.

7b) Validate the APK

You then need zipalign that can be found in the Android SDK folder (e.g. C:\Users\USERNAME\AppData\Local\Android\Sdk\build-tools\31.0.0\zipalign.exe) to validate your APK:
.\Path\to\Android\Sdk\build-tools\31.0.0\zipalign.exe -f -v 4 .\app_unsigned.apk .\app_ready.apk

7c) Sign the APK

Finally you can sign the new created APK with apksigner:
.\Path\to\Android\Sdk\build-tools\31.0.0\apksigner.bat sign --ks .\mykey.keystore --ks-key-alias app_to_debug --out .\app_signed.apk .\app_ready.apk

8) Install the APK

You can install it using adb install app_signed.apk

9) Prepare the host

On your Android device, go to Settings -> Developer options and set USB debugging and Wait for debugger options on. The latter is optional but useful as it allows you wait for debugger connection and not to run app yet.

Finally, you should tap on Select debug app and choose the app you just installed. After all of these, your Developer options menu should look somewhat like this:

Now, launch the app on the Android device, and you’ll get the below message:

10) Forward debugger port

You can use the adb’s port forwarding feature and forward JDWP service where application’s debug interface is listening.

Find the JDWP port with the command adb jdwp, then use this port with the command:
adb forward tcp:5005 jdwp:JDWP_PORT

11) Connect Debugger

Go to Android Studio and from its top menu bar choose Run -> Debug…, then a small message appears with one unique option that is Edit Configurations.... There, in the window, use a plus (+) button at the opt left, and add a new configuration of type Remote. Leave the default configuration as is. Click the Debug button and your app should be running with the attached debugger which means it will stop once a breakpoint is hit and you can investigate the content of app’s variables.

Capacitor Plugin for HTTP requests with self-signed SSL certificates

I’m using CapacitorJS for easy development with Android. I needed a way to do an HTTPS request to a box that uses self-signed SSL certificate. To accomplish it, I created my own capacitor plugin.

See this wiki page for details: https://github.com/Aymkdn/assistant-freebox-cloud/wiki/Capacitor-Plugin-for-HTTP-requests-with-self-signed-SSL-certificates

Enable CORS with IIS

It’s as easy as editing the web.config file with the below:

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="https://my.site.com" />
        <add name="Access-Control-Allow-Headers" value="Authorization,Accept,Content-Type,X-Requested-With" />
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

L’application Android “Huawei Health” (ou “Santé” en français) retourne l’erreur : “les notifications sont indisponibles”

“Erreur du système, les notifications sont indisponibles. Veuillez redémarrer votre téléphone. Si le problème persiste, contactez le fabricant de votre appareil.”

J’ai eu cette erreur sur mon Samsung S20 FE. J’ai réussi à m’en sortir ou désinstallant tout puis en réinstallant… Mais je pense que la solution pouvait être autre : dans les Paramètres du téléphone, chercher Accès aux notifications, puis vérifier que l’application “Santé” est bien cochée !

Problème d’accès avec C:\Program Files\WindowsApps

J’utilise d’habitude le raccourci wt.exe dans la barre de Windows Explorer, mais j’ai reçu une erreur aujourd’hui me disant que le fichier n’existe pas…

Après quelques recherches, j’ai découvert que je n’ai aucun accès au répertoire C:\Program Files\WindowsApps là où se trouve Windows Terminal.

J’ai réussi à le refaire marcher en lançant un terminal en mode administrateur puis en exécutant la commande icacls "C:\Program Files\WindowsApps" /reset /t /c /q

J’ai reçu beaucoup de échec de traitement, mais ce fut quand même suffisant !

Access to Sharepoint Online with Windows Explorer

If you want to access your Sharepoint online (https://[tenant].sharepoint.com), you first need to make sure the site is in the Trusted Website in Internet Explorer.
Open Internet Explorer, navigate to the website, then open the Internet Options:

Add your website to the Trusted Website zone:

Next open Windows Explorer and right-click on “Your PC “, then select “Map network drive…”:

You need to use a special path to your website. Let’s say your website is located at https://tenant.sharepoint.com/sites/Marketing then the path to use is:
\\tenant.sharepoint.com@ssl\DavWWWRoot\sites\Marketing\

Note the @ssl and DavWWWRoot that are required.

Assign this path to a drive letter: