Skip to content

Commit 8cf231e

Browse files
committed
v1.4.1: Fix powershell & telnet bugs
1 parent ff8ae7e commit 8cf231e

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

exe2hex.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Name: exe2hex v1.4 (2016-04-14)
3+
# Name: exe2hex v1.4.1 (2016-06-30) ~ Codename: hEXE
44
# Author: g0tmilk ~ https://blog.g0tmi1k.com/
55
# Licence: MIT License ~ http://opensource.org/licenses/MIT
66
# Credit to: exe2bat.exe & https://github.com/acjsec/exe2bam
@@ -16,7 +16,7 @@
1616

1717
import urllib.parse
1818

19-
version = '1.4'
19+
version = '1.4.1'
2020

2121

2222
###################
@@ -328,7 +328,7 @@ def finish_bat(self, loop=0):
328328
# The final few things
329329
output += '%sdel /F /Q %s%s\r\n' % (prefix, parts, suffix)
330330
if self.telnet_file == None:
331-
output += '%sstart /wait /b %s%s\r\n' % (prefix, self.exe_filename, suffix)
331+
output += '%sstart /wait /b %s%s\r\n\r\n' % (prefix, self.exe_filename, suffix)
332332

333333
# Write the file out
334334
self.write_file(self.bat_file, output, "BATch", False)
@@ -338,11 +338,15 @@ def bin_to_posh(self):
338338
# Feedback for the user, to know where they are
339339
verbose_msg('Converting to PoSH')
340340

341+
# Null any previous files
342+
#self.posh_hex += '%secho|set /p="">%s.hex%s\r\n' % (prefix, self.short_file, suffix)
343+
self.posh_hex += '%secho|set /p="">%s.hex%s\r\n' % (prefix, self.short_file, suffix)
344+
341345
# Loop through binary bytes
342346
for i in range(0, len(self.exe_bin), hex_len):
343-
self.posh_hex += '%sset /p "=' % (prefix)
347+
self.posh_hex += '%secho|set /p="' % (prefix)
344348
self.posh_hex += ''.join('%02x' % i for i in self.exe_bin[i:i + hex_len])
345-
self.posh_hex += '"<NUL>>%s.hex%s\r\n' % (self.short_file, suffix)
349+
self.posh_hex += '">>%s.hex%s\r\n' % (self.short_file, suffix)
346350

347351
# Write resulting bat file
348352
def save_bat(self, loop=0):
@@ -365,16 +369,16 @@ def save_bat(self, loop=0):
365369
def save_posh(self):
366370
# Create PoSh file!
367371
output = self.posh_hex
368-
output += "%spowershell -Command \"$hex=Get-Content -readcount 0 -path './%s.hex';" % (prefix, self.short_file)
369-
output += "$len=$hex[0].length;"
370-
output += "$bin=New-Object byte[] ($len/2);"
372+
output += "%spowershell -Command \"$h=Get-Content -readcount 0 -path './%s.hex';" % (prefix, self.short_file)
373+
output += "$l=$h[0].length;"
374+
output += "$b=New-Object byte[] ($l/2);"
371375
output += "$x=0;"
372-
output += "for ($i=0;$i -le $len-1;$i+=2)"
373-
output += "{$bin[$x]=[byte]::Parse($hex.Substring($i,2),[System.Globalization.NumberStyles]::HexNumber);"
376+
output += "for ($i=0;$i -le $l-1;$i+=2)"
377+
output += "{$b[$x]=[byte]::Parse($h[0].Substring($i,2),[System.Globalization.NumberStyles]::HexNumber);"
374378
output += "$x+=1};"
375-
output += "set-content -encoding byte '%s' -value $bin;\"%s\r\n" % (self.exe_filename, suffix)
379+
output += "set-content -encoding byte '%s' -value $b;\"%s\r\n" % (self.exe_filename, suffix)
376380
output += "%sdel /F /Q %s.hex%s\r\n" % (prefix, self.short_file, suffix)
377-
output += "%sstart /b %s%s\r\n" % (prefix, self.exe_filename, suffix)
381+
output += "%sstart /b %s%s\r\n\r\n" % (prefix, self.exe_filename, suffix)
378382

379383
# Write file out
380384
self.write_file(self.posh_file, output, "PoSh", True)
@@ -628,7 +632,7 @@ def run(self):
628632
error_exit('Cannot use the same input as output')
629633

630634
# Are we missing .bat when doing telnet?
631-
if bat == None and telnet != None:
635+
if bat == None and telnet != False:
632636
error_exit("Need a BATch file (-b) to use Telnet (-t)")
633637

634638
# Read in file information

0 commit comments

Comments
 (0)