Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation script for interception and intercept.exe #27

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
PR 2014.txt
PR 2017.txt
PR 2017.txt
Intercept/Interception
Intercept/intercept
Intercept/tmp
Intercept/installer/getdeviceid.exe
Intercept/deviceid.ini
123 changes: 123 additions & 0 deletions Intercept/Installer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
@echo off
setlocal EnableDelayedExpansion

echo Press enter to confirm the installation...
pause > NUL

If NOT exist "tmp" (
mkdir tmp
)

:download_interception
REM @TODO: We should only download and install interception if it's not already avalible on the system

If exist "tmp/interception.zip" (
echo Interception already downloaded. Skipping....
GOTO unzip_interception
)

REM Using a static link to version 1.0 meaning we wont get updates.
REM We could write some more complicated logic that checks for new
REM versions but im not gonna do that now
set interception_url="https://github.com/oblitum/Interception/releases/download/1.0.0/Interception.zip"

REM Since batch cant download files directly we have to use a vbs file.
REM We're just gonna tell it to download the latest release of Interception
REM from github and save it as interception.zip
echo Downloading Interception...
cscript //Nologo installer/download.vbs %interception_url% tmp/interception.zip

:unzip_interception
REM Just exiting if we where not able to download the program
If not exist "tmp/interception.zip" (
echo Oh noes. We where not able to download interception. Aborting program...
pause
goto exit
)

REM If the zip file is not extracted we then do it...
if not exist "Interception" (
:: Since batch cant extract zip files either, we're gonna use a VBscript here again.
echo Extracting Interception...
cscript //Nologo installer/unzip.vbs tmp/interception.zip ./
) else (
echo Interception already extracted. Skipping....
)

:install_interception
echo.
echo.
ECHO **************************************
ECHO ATTENTION
ECHO **************************************
echo We're now gonna install 'Interception' for you. This requires administrator rights. Press yes on the popup for the installation to continue.
pause

start /B /WAIT installer\elevated.bat install_interception.bat

echo Press enter when the interception install is done AND you've closed the secondary window.
pause>nul


:download_intercept
echo Downloading Intercept.exe...

set intercept_url="http://octopup.org/img/code/interception/intercept.zip"

REM Since batch cant download files directly we have to use a vbs file.
REM We're just gonna tell it to download the latest release of Interception
REM from github and save it as interception.zip
cscript //Nologo installer/download.vbs %intercept_url% tmp/intercept.zip

:unzip_intercept
REM Just exiting if we where not able to download the program
If not exist "tmp/intercept.zip" (
echo Oh noes. We where not able to download intercept. Aborting program...
pause
goto exit
)

REM If the zip file is not extracted we then do it...
if not exist "intercept" (
:: Since batch cant extract zip files either, we're gonna use a VBscript here again.
echo Extracting Intercept.exe...
cscript //Nologo installer/unzip.vbs tmp/intercept.zip ./
) else (
echo Intercept.exe already extracted. Skipping....
)


:download_other_dependencies
echo Downloading other dependencies...

REM Using a static link to version 1.0 meaning we wont get updates.
REM We could write some more complicated logic that checks for new
REM versions but im not gonna do that now
set getdeviceid_url="https://github.com/jlndk/getdeviceid/releases/download/v1.0/getdeviceid.zip"

REM Since batch cant download files directly we have to use a vbs file.
REM We're just gonna tell it to download the latest release of Interception
REM from github and save it as interception.zip
cscript //Nologo installer/download.vbs %getdeviceid_url% tmp/getdeviceid.zip

:unzip_intercept
REM Just exiting if we where not able to download the program
If not exist "tmp/getdeviceid.zip" (
echo Oh noes. We where not able to download getdeviceid. Aborting program...
pause
goto exit
)

REM If the zip file is not extracted we then do it...
if not exist "installer/getdeviceid.exe" (
:: Since batch cant extract zip files either, we're gonna use a VBscript here again.
echo Extracting Dependencies...
cscript //Nologo installer/unzip.vbs tmp/getdeviceid.zip installer
)

echo Installation successfull. Now reboot your computer and run 'keymap.bat'


:exit
REM cleaning up a bit before we exit
rmdir /s /q tmp
52 changes: 52 additions & 0 deletions Intercept/installer/create_keyremap.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'http://stackoverflow.com/questions/23641070/create-a-text-document-from-template-vbscript

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

' IMPORT inireader functions
DIM objShell
Set objShell = wscript.createObject("wscript.shell")
Dim iniReaderPath
iniReaderPath = objFSO.GetAbsolutePathName("installer\iniReader.vbs")
Dim vbsFile
Set vbsFile = objFSO.OpenTextFile(iniReaderPath, 1, False)
Dim functions
functions = vbsFile.ReadAll
vbsFile.Close
Set vbsFile = Nothing
ExecuteGlobal functions
'END import inireader function


Dim args
Set args = Wscript.Arguments

Dim iniPath
iniPath = objFSO.GetAbsolutePathName(args(0))

Dim distPath
distPath = objFSO.GetAbsolutePathName(args(1))

Dim devId
devId = ReadIni(iniPath,iniPath,"device")

Const ForReading = 1
Const ForWriting = 2

Dim templatePath
templatePath = objFSO.GetAbsolutePathName("installer\template.ini")

Dim objTemplateTS
Set objTemplateTS = objFSO.OpenTextFile(templatePath, ForReading, False)

Dim strAllTemplateText
strAllTemplateText = objTemplateTS.ReadAll()
objTemplateTS.Close()
strAllTemplateText = Replace(strAllTemplateText, "<DID_PLACEHOLDER>", devId)


Dim objOutputTS
Set objOutputTS = objFSO.OpenTextFile(distPath, ForWriting, True)

objOutputTS.Write(strAllTemplateText)
objOutputTS.Close()
28 changes: 28 additions & 0 deletions Intercept/installer/download.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Option Explicit
Dim args, http, fileSystem, adoStream, url, target, status

Set args = Wscript.Arguments
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
url = args(0)
target = args(1)
'WScript.Echo "Getting '" & target & "' from '" & url & "'..."

http.Open "GET", url, False
http.Send
status = http.Status

If status <> 200 Then
WScript.Echo "FAILED to download: HTTP Status " & status
WScript.Quit 1
End If

Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1
adoStream.Write http.ResponseBody
adoStream.Position = 0

Set fileSystem = CreateObject("Scripting.FileSystemObject")
If fileSystem.FileExists(target) Then fileSystem.DeleteFile target
adoStream.SaveToFile target
adoStream.Close
45 changes: 45 additions & 0 deletions Intercept/installer/elevated.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
::::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights V2
:: http://www.winhelponline.com/blog/automatically-elevate-batch-file-run-administrator/
::::::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.

:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO **************************************
ECHO Asking for administrator permissions.
ECHO **************************************

ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit \B

:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)

::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
start /B /WAIT %1

cmd /k
Loading