Search code examples
google-chrome-extensionnsis

NSIS script that installs Chrome extension kills Outlook


This is an incredibly bizarre bug.

Here is an NSIS script that installs an extension into Google Chrome. Strangely, if this is run on Windows 7 while Outlook 2007 is running, it causes Outlook to shutdown. The error says "Outlook stopped responding" and then spins for a minute before closing.

Can anyone shed any light on what the cause is and how to fix it?

!define VERSION "1.0.0" 
!define EXT_ID "kmffervcdaycdjlksmflkjghksdf"
!define INSTALL_DIR "$LOCALAPPDATA\Google\Chrome\User Data\Default\Extensions\${EXT_ID}\${VERSION}_0"
!define P_FILE "$LOCALAPPDATA\Google\Chrome\User Data\Default\Preferences"

!include "ZipDLL.nsh" 

!include "TextFunc.nsh"
!insertmacro LineFind

!include "WordFunc.nsh"
!insertmacro WordFind


Name "Chrome Extension Installer"
OutFile "extension_installer.exe"
RequestExecutionLevel admin

Var PMEMORY
Var SIZE

Function .onInit
    SetSilent silent
FunctionEnd

Section
    SetOutPath $TEMP 
    File "extension.crx" 
    File "chrome_preferences.txt"

    CreateDirectory "${INSTALL_DIR}"
    ZipDLL::extractall "$TEMP\extension.crx" "${INSTALL_DIR}"

    StrCpy $0 "${P_FILE}"
    StrCpy $1 "${P_FILE}"
    StrCpy $R0 '"settings": {'
    StrCpy $R1 "$TEMP\chrome_preferences.txt"
    StrCpy $R2 "0"
    StrCpy $R3 "0"
    ${LineFind} "$0" "$1" "1:-2 -1" "LineFindCallback"
SectionEnd


Function LineFindCallback
    StrCmp $PMEMORY '0' end

    begin:
    ${WordFind} "$R9" "$R0" "E+1{" $1
    IfErrors freemem
    FileWrite $R4 "$1"

    StrCmp $PMEMORY '' 0 write
    FileOpen $1 $R1 a
    FileSeek $1 0 END $SIZE
    System::Alloc $SIZE
    Pop $PMEMORY
    FileSeek $1 0 SET
    System::Call 'kernel32::ReadFile(i r1, i $PMEMORY, i $SIZE, t.,)'
    FileClose $1

    write:
    IntOp $R3 $R3 + 1
    System::Call 'kernel32::WriteFile(i R4, i $PMEMORY, i $SIZE, t.,)'
    ${WordFind} "$R9" "$R0" "+1}" $R9
    StrCmp $R3 $R2 0 begin

    freemem:
    StrCmp $PMEMORY '' end
    StrCmp $R7 -1 +2
    StrCmp $R3 $R2 0 end
    System::Free $PMEMORY
    StrCpy $PMEMORY 0

    end:
    Push $0
FunctionEnd

Solution

  • The problem turned out to be ZipDLL. Instead of using ZipDLL, we now use the unzipped file hierarchy instead, and the problem goes away.

    (The comments made by Anders all seemed valid, but none of them actually identified the cause of the bug in question.)