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;aACrB;SACF;QACD,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;SAC1C;QACD,MAAM,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;QAC/C,MAAM,EAAE,CAAC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,CAAA;IACnD,CAAC;CACF;AAtFD,8CAsFC","sourcesContent":["import { Arch, log } from \"builder-util\"\nimport { PackageFileInfo } from \"builder-util-runtime\"\nimport { getBinFromUrl, getBinFromCustomLoc } from \"../../binDownload\"\nimport { copyFile, dirSize } from \"builder-util/out/fs\"\nimport * as path from \"path\"\nimport { getTemplatePath } from \"../../util/pathManager\"\nimport { NsisTarget } from \"./NsisTarget\"\nimport * as fs from \"fs/promises\"\nimport * as zlib from \"zlib\"\nimport { NsisOptions } from \"./nsisOptions\"\n\nexport const nsisTemplatesDir = getTemplatePath(\"nsis\")\n\nexport const NsisTargetOptions = (() => {\n let _resolve: (options: NsisOptions) => any\n const promise = new Promise<NsisOptions>(resolve => (_resolve = resolve))\n return {\n then: (callback: (options: NsisOptions) => any): Promise<string> => promise.then(callback),\n resolve: (options: NsisOptions): any => _resolve(options),\n }\n})()\n\nexport const NSIS_PATH = () => {\n const custom = process.env.ELECTRON_BUILDER_NSIS_DIR\n if (custom != null && custom.length > 0) {\n return Promise.resolve(custom.trim())\n }\n return NsisTargetOptions.then((options: NsisOptions) => {\n if (options.customNsisBinary) {\n const { checksum, url, version } = options.customNsisBinary\n if (checksum && url) {\n const binaryVersion = version || checksum.substr(0, 8)\n return getBinFromCustomLoc(\"nsis\", binaryVersion, url, checksum)\n }\n }\n // Warning: Don't use v3.0.4.2 - https://github.com/electron-userland/electron-builder/issues/6334\n // noinspection SpellCheckingInspection\n return getBinFromUrl(\"nsis\", \"3.0.4.1\", \"VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==\")\n })\n}\n\nexport interface PackArchResult {\n fileInfo: PackageFileInfo\n unpackedSize: number\n}\n\nexport class AppPackageHelper {\n private readonly archToResult = new Map<Arch, Promise<PackArchResult>>()\n private readonly infoToIsDelete = new Map<PackageFileInfo, boolean>()\n\n /** @private */\n refCount = 0\n\n constructor(private readonly elevateHelper: CopyElevateHelper) {}\n\n async packArch(arch: Arch, target: NsisTarget): Promise<PackArchResult> {\n let resultPromise = this.archToResult.get(arch)\n if (resultPromise == null) {\n const appOutDir = target.archs.get(arch)!\n resultPromise = this.elevateHelper\n .copy(appOutDir, target)\n .then(() => target.buildAppPackage(appOutDir, arch))\n .then(async fileInfo => ({\n fileInfo,\n unpackedSize: await dirSize(appOutDir),\n }))\n this.archToResult.set(arch, resultPromise)\n }\n\n const result = await resultPromise\n const { fileInfo: info } = result\n if (target.isWebInstaller) {\n this.infoToIsDelete.set(info, false)\n } else if (!this.infoToIsDelete.has(info)) {\n this.infoToIsDelete.set(info, true)\n }\n return result\n }\n\n async finishBuild(): Promise<any> {\n if (--this.refCount > 0) {\n return\n }\n\n const filesToDelete: Array<string> = []\n for (const [info, isDelete] of this.infoToIsDelete.entries()) {\n if (isDelete) {\n filesToDelete.push(info.path)\n }\n }\n\n await Promise.all(filesToDelete.map(it => fs.unlink(it)))\n }\n}\n\nexport class CopyElevateHelper {\n private readonly copied = new Map<string, Promise<any>>()\n\n copy(appOutDir: string, target: NsisTarget): Promise<any> {\n if (!target.packager.info.framework.isCopyElevateHelper) {\n return Promise.resolve()\n }\n\n let isPackElevateHelper = target.options.packElevateHelper\n if (isPackElevateHelper === false && target.options.perMachine === true) {\n isPackElevateHelper = true\n log.warn(\"`packElevateHelper = false` is ignored, because `perMachine` is set to `true`\")\n }\n\n if (isPackElevateHelper === false) {\n return Promise.resolve()\n }\n\n let promise = this.copied.get(appOutDir)\n if (promise != null) {\n return promise\n }\n\n promise = NSIS_PATH().then(it => {\n const outFile = path.join(appOutDir, \"resources\", \"elevate.exe\")\n const promise = copyFile(path.join(it, \"elevate.exe\"), outFile, false)\n if (target.packager.platformSpecificBuildOptions.signAndEditExecutable !== false) {\n return promise.then(() => target.packager.sign(outFile))\n }\n return promise\n })\n this.copied.set(appOutDir, promise)\n return promise\n }\n}\n\nclass BinaryReader {\n private readonly _buffer: Buffer\n private _position: number\n\n constructor(buffer: Buffer) {\n this._buffer = buffer\n this._position = 0\n }\n\n get length(): number {\n return this._buffer.length\n }\n\n get position(): number {\n return this._position\n }\n\n match(signature: Array<number>): boolean {\n if (signature.every((v, i) => this._buffer[this._position + i] === v)) {\n this._position += signature.length\n return true\n }\n return false\n }\n\n skip(offset: number) {\n this._position += offset\n }\n\n bytes(size: number): Buffer {\n const value = this._buffer.subarray(this._position, this._position + size)\n this._position += size\n return value\n }\n\n uint16(): number {\n const value = this._buffer[this._position] | (this._buffer[this._position + 1] << 8)\n this._position += 2\n return value\n }\n\n uint32(): number {\n return this.uint16() | (this.uint16() << 16)\n }\n\n string(length: number): string {\n let value = \"\"\n for (let i = 0; i < length; i++) {\n const c = this._buffer[this._position + i]\n if (c === 0x00) {\n break\n }\n value += String.fromCharCode(c)\n }\n this._position += length\n return value\n }\n}\n\nexport class UninstallerReader {\n // noinspection SpellCheckingInspection\n static async exec(installerPath: string, uninstallerPath: string) {\n const buffer = await fs.readFile(installerPath)\n const reader = new BinaryReader(buffer)\n // IMAGE_DOS_HEADER\n if (!reader.match([0x4d, 0x5a])) {\n throw new Error(\"Invalid 'MZ' signature.\")\n }\n reader.skip(58)\n // e_lfanew\n reader.skip(reader.uint32() - reader.position)\n // IMAGE_FILE_HEADER\n if (!reader.match([0x50, 0x45, 0x00, 0x00])) {\n throw new Error(\"Invalid 'PE' signature.\")\n }\n reader.skip(2)\n const numberOfSections = reader.uint16()\n reader.skip(12)\n const sizeOfOptionalHeader = reader.uint16()\n reader.skip(2)\n reader.skip(sizeOfOptionalHeader)\n // IMAGE_SECTION_HEADER\n let nsisOffset = 0\n for (let i = 0; i < numberOfSections; i++) {\n const name = reader.string(8)\n reader.skip(8)\n const rawSize = reader.uint32()\n const rawPointer = reader.uint32()\n reader.skip(16)\n switch (name) {\n case \".text\":\n case \".rdata\":\n case \".data\":\n case \".rsrc\": {\n nsisOffset = Math.max(rawPointer + rawSize, nsisOffset)\n break\n }\n default: {\n if (rawPointer !== 0 && rawSize !== 0) {\n throw new Error(\"Unsupported section '\" + name + \"'.\")\n }\n break\n }\n }\n }\n const executable = buffer.subarray(0, nsisOffset)\n const nsisSize = buffer.length - nsisOffset\n const nsisReader = new BinaryReader(buffer.subarray(nsisOffset, nsisOffset + nsisSize))\n const nsisSignature = [0xef, 0xbe, 0xad, 0xde, 0x4e, 0x75, 0x6c, 0x6c, 0x73, 0x6f, 0x66, 0x74, 0x49, 0x6e, 0x73, 0x74]\n nsisReader.uint32() // ?\n if (!nsisReader.match(nsisSignature)) {\n throw new Error(\"Invalid signature.\")\n }\n nsisReader.uint32() // ?\n if (nsisSize !== nsisReader.uint32()) {\n throw new Error(\"Size mismatch.\")\n }\n\n let innerBuffer = null\n while (true) {\n let size = nsisReader.uint32()\n const compressed = (size & 0x80000000) !== 0\n size = size & 0x7fffffff\n if (size === 0 || nsisReader.position + size > nsisReader.length || nsisReader.position >= nsisReader.length) {\n break\n }\n let buffer = nsisReader.bytes(size)\n if (compressed) {\n buffer = zlib.inflateRawSync(buffer)\n }\n const innerReader = new BinaryReader(buffer)\n innerReader.uint32() // ?\n if (innerReader.match(nsisSignature)) {\n if (innerBuffer) {\n throw new Error(\"Multiple inner blocks.\")\n }\n innerBuffer = buffer\n }\n }\n if (!innerBuffer) {\n throw new Error(\"Inner block not found.\")\n }\n await fs.writeFile(uninstallerPath, executable)\n await fs.appendFile(uninstallerPath, innerBuffer)\n }\n}\n"]}
|