Skip to content

Commit

Permalink
replace pywin32 with ctypes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurnec committed Dec 21, 2017
1 parent 13f3e55 commit 129c09d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
30 changes: 20 additions & 10 deletions btcrecover/btcrpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# (all optional futures for 2.7)
from __future__ import print_function, absolute_import, division, unicode_literals

__version__ = "0.17.9"
__version__ = "0.17.10"
__ordering_version__ = b"0.6.4" # must be updated whenever password ordering changes

import sys, argparse, itertools, string, re, multiprocessing, signal, os, cPickle, gc, \
Expand All @@ -38,11 +38,6 @@
# The progressbar module is recommended but optional; it is typically
# distributed with btcrecover (it is loaded later on demand)

# The pywin32 module is also recommended on Windows but optional; it's only

This comment has been minimized.

Copy link
@Pvuadmin

Pvuadmin Jul 2, 2023

ctypes`

# used to adjust the process priority to be more friendly and to catch more
# signals (other than just Ctrl-C) for better autosaves. When used with
# Armory, btcrecover will just load the version that ships with Armory.


def full_version():
from struct import calcsize
Expand Down Expand Up @@ -5137,8 +5132,14 @@ def init_worker(wallet, char_mode):
def set_process_priority_idle():
try:
if sys.platform == "win32":
import win32process
win32process.SetPriorityClass(win32process.GetCurrentProcess(), win32process.IDLE_PRIORITY_CLASS)
import ctypes, ctypes.wintypes
GetCurrentProcess = ctypes.windll.kernel32.GetCurrentProcess
GetCurrentProcess.argtypes = ()
GetCurrentProcess.restype = ctypes.wintypes.HANDLE
SetPriorityClass = ctypes.windll.kernel32.SetPriorityClass
SetPriorityClass.argtypes = ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD
SetPriorityClass.restype = ctypes.wintypes.BOOL
SetPriorityClass(GetCurrentProcess(), 0x00000040) # IDLE_PRIORITY_CLASS
else:
os.nice(19)
except StandardError: pass
Expand Down Expand Up @@ -5544,14 +5545,20 @@ def windows_ctrl_handler(signal):

# Try to catch all types of intentional program shutdowns so we can
# display password progress information and do a final autosave
windows_handler_routine = None
try:
sigint_handler = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGTERM, sigint_handler) # OK to call on any OS
if sys.platform != "win32":
signal.signal(signal.SIGHUP, sigint_handler) # can't call this on windows
else:
import win32api
win32api.SetConsoleCtrlHandler(windows_ctrl_handler, True)
import ctypes, ctypes.wintypes
HandlerRoutine = ctypes.WINFUNCTYPE(ctypes.wintypes.BOOL, ctypes.wintypes.DWORD)
SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler
SetConsoleCtrlHandler.argtypes = HandlerRoutine, ctypes.wintypes.BOOL
SetConsoleCtrlHandler.restype = ctypes.wintypes.BOOL
windows_handler_routine = HandlerRoutine(windows_ctrl_handler) # creates a C callback from the Python function
SetConsoleCtrlHandler(windows_handler_routine, True)
except StandardError: pass

# Make est_passwords_per_5min evenly divisible by chunksize
Expand Down Expand Up @@ -5611,6 +5618,9 @@ def windows_ctrl_handler(signal):

if not handled and not isinstance(e, KeyboardInterrupt): raise
password_found = None # neither False nor True -- unknown
finally:
if windows_handler_routine:
SetConsoleCtrlHandler(windows_handler_routine, False)

# Autosave the final state (for all non-error cases -- we're shutting down (e.g. Ctrl-C or a
# reboot), the password was found, or the search was exhausted -- or for handled out-of-memory)
Expand Down
2 changes: 1 addition & 1 deletion btcrecover/test/test_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def setUpModule():
# except these from Armory:
warnings.filterwarnings("ignore", r"the sha module is deprecated; use the hashlib module instead", DeprecationWarning)
warnings.filterwarnings("ignore", r"import \* only allowed at module level", SyntaxWarning)
# except this from Google protobuf, PyWin32, and because of pkg_resources (used by PyOpenCL) many others (see #62):
# except this from Google protobuf, and because of pkg_resources (used by PyOpenCL) many others (see #62):
warnings.filterwarnings("ignore", r"Not importing directory '.*': missing __init__\.py", ImportWarning)

if tstr is None:
Expand Down
6 changes: 0 additions & 6 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ Locate your wallet type in the list below, and follow the instructions for only
* Dogecoin Wallet for Android - [Python 2.7](#python-27), recommended: [PyCrypto](#pycrypto)


### Windows ###

***After*** installing the requirements for your wallet from above, if you'd like you may *optionally* install pywin32 which allows *btcrecover* to run as a low-priority process so it doesn’t hog your CPU, and slightly improves autosave safety.

Download and run the latest version of the pywin32 installer for Python 2.7, either the 32-bit version or the 64-bit version to match the version of Python you installed. Currently this is `pywin32-221.win32-py2.7.exe` for the 32-bit version or `pywin32-221.win-amd64-py2.7.exe` for the 64-bit version available in the `Build 221` folder here: <http://sourceforge.net/projects/pywin32/files/pywin32/>

----------


Expand Down
2 changes: 1 addition & 1 deletion docs/Limitations_and_Caveats.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ By default, *btcrecover* tries to use as much CPU time as is available and spare

With MultiBit or Electrum wallets, *btcrecover* may not be able to efficiently use more than four or five CPU cores, sometimes even less depending on the contents of the tokenlist and the chosen typos. Specifying the `--no-dupchecks` option may help improve CPU usage and therefore the password guess rate in many cases with these two wallet types, and using slightly fewer or slightly greater `--threads` might also help. The only way to find out is to experiment.

*btcrecover* places itself in the lowest CPU priority class to minimize disruption to your PC while searching (but for Windows, it can only do this if you've installed the optional pywin32).
*btcrecover* places itself in the lowest CPU priority class to minimize disruption to your PC while searching.

### Security Issues ###

Expand Down
2 changes: 0 additions & 2 deletions docs/Seedrecover_Quick_Start_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Additional requirements are described below.

C:\Python27\Scripts\pip install coincurve==5.2.0 pysha3

3. (optional) Follow [these instructions](INSTALL.md#windows) to download and install pywin32 which allows *seedrecover.py* to run as a low-priority process so it doesn’t hog your CPU.

### Linux ###

Most distributions include Python 2.7 pre-installed. Two additional Python libraries, coincurve and (for Ethereum wallets) pysha3 are required. For example on Debian-like distributions (including Ubuntu), open a terminal window and type this:
Expand Down

3 comments on commit 129c09d

@Jorhbache
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/addresses.db

@Cody-Ashmore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello i lodt my passphraze to my wallet i have my .dat file for proof can you help me find it

@Cody-Ashmore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lost

Please sign in to comment.