Skip to content

Commit

Permalink
Update memlib fork version
Browse files Browse the repository at this point in the history
This version (https://github.com/synap5e/memlib) now also supports
GetModuleHandle and EnumProcessModules
  • Loading branch information
synap5e committed May 1, 2022
1 parent df23281 commit 6a30caa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
20 changes: 0 additions & 20 deletions onefile_python.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import std/tables
import std/strutils

import zippy/ziparchives
import minhook
import winim/lean
import memlib
import nimpy
Expand Down Expand Up @@ -84,25 +83,6 @@ python_stdlib.open(newStringStream(python_embedded.contents["python310.zip"].con

const dll_name = "python310.dll"

# hook so python shows up for nimpy
proc K32EnumProcessModules(hProcess: HANDLE, lphModule: ptr UncheckedArray[HMODULE], cb: DWORD, cbNeeded: ptr DWORD): WINBOOL {. dynlib: "kernel32", importc: "K32EnumProcessModules", stdcall.}
proc myEnumProcessModules(hProcess: HANDLE, lphModule: ptr UncheckedArray[HMODULE], cb: DWORD, cbNeeded: ptr DWORD): WINBOOL {.stdcall, minhook: K32EnumProcessModules.} =
result = K32EnumProcessModules(hProcess, lphModule, cb, cbNeeded)
if result == 1:
var sz = cbNeeded[] // 8
var mx = cb // 8
if DEBUG:
echo fmt"EnumProcessModules(0x{cast[uint](hProcess):x}, 0x{cast[uint](lphModule):x}, 0x{cast[uint](cb):x}, 0x{cast[uint](cbNeeded):x} => {sz}) => {result}"
echo fmt" 0x{cast[uint](lphModule[0]):x}, ..., 0x{cast[uint](lphModule[sz-1]):x}, 0x{cast[uint](lphModule[sz]):x}"
if sz < mx:
lphModule[sz] = LoadLibraryA(dll_name)
if DEBUG:
echo fmt" > Appending library handle: 0x{cast[uint](lphModule[0]):x}, ..., 0x{cast[uint](lphModule[sz-1]):x}, 0x{cast[uint](lphModule[sz]):x}"
echo ""
cbNeeded[] = sz + 8

enableHook(K32EnumProcessModules)


when EMBED_DLL:
let python = checkedLoadLib(python_embedded.contents[dll_name].contents.bytes)
Expand Down
4 changes: 2 additions & 2 deletions onefile_python.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.0"
version = "0.4.0"
author = "Simon Pinfold"
description = "Run python from a single exe"
license = "ISC"
Expand All @@ -9,7 +9,7 @@ bin = @["onefile_python"]
# Dependencies

requires "nim >= 1.6.2"
requires "https://github.com/synap5e/memlib.git" # Use fork while https://github.com/khchen/memlib/pull/3 is not merged
requires "https://github.com/synap5e/memlib.git >= 1.2.2" # Use fork while https://github.com/khchen/memlib/pull/3 is not merged
requires "zippy >= 0.7.3"
requires "nimpy >= 0.2.0"
requires "https://github.com/iffy/nim-argparse"
Expand Down

0 comments on commit 6a30caa

Please sign in to comment.