Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minor changes

<
  • Loading branch information...
commit c3b17618172cc114511e31fc5ba845ce7219da08 1 parent 0578dbe
@buffer authored
Showing with 32 additions and 22 deletions.
  1. +20 −17 tests/cpu_mem_test.py
  2. +12 −5 tests/sctest.py
View
37 tests/cpu_mem_test.py
@@ -19,6 +19,9 @@
# MA 02111-1307 USA
import pylibemu
+import logging
+
+log = logging.getLogger("pylibemu")
regs32 = ('eax',
'ecx',
@@ -65,55 +68,55 @@
offset = emulator.shellcode_getpc_test(shellcode)
for i in range(0, 7):
- print "%s => %s" % (regs32[i], hex(emulator.cpu_reg32_get(i)), )
- print "%s => %s" % (regs16[i], hex(emulator.cpu_reg16_get(i)), )
- print "%s => %s" % (regs8[i] , hex(emulator.cpu_reg8_get(i)) , )
+ log.warn("%s => %s" % (regs32[i], hex(emulator.cpu_reg32_get(i)), ))
+ log.warn("%s => %s" % (regs16[i], hex(emulator.cpu_reg16_get(i)), ))
+ log.warn("%s => %s" % (regs8[i] , hex(emulator.cpu_reg8_get(i)) , ))
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
emulator.memory_write_dword(emulator.cpu_reg32_get(i), 0x41424344)
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
dword = emulator.memory_read_dword(emulator.cpu_reg32_get(i))
assert dword == 0x41424344
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
word = emulator.memory_read_word(emulator.cpu_reg32_get(i))
assert word == 0x4344
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
byte = emulator.memory_read_byte(emulator.cpu_reg32_get(i))
assert byte == 0x44
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
emulator.memory_segment_select(5)
assert emulator.memory_segment_get() == 5
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
eip = emulator.cpu_eip_get()
-print hex(eip)
+log.warn(hex(eip))
dword = emulator.memory_read_dword(eip)
-print hex(dword)
+log.warn(hex(dword))
word = emulator.memory_read_word(eip)
-print hex(word)
+log.warn(hex(word))
byte = emulator.memory_read_byte(eip)
-print hex(byte)
+log.warn(hex(byte))
block = emulator.memory_read_block(eip, 4)
-print '0x' + ''.join(["%02x" % ord(x) for x in block[::-1]])
+#log.warn('0x' + ''.join(["%02x" % ord(x) for x in block[::-1]]))
-print emulator.cpu_get_current_instruction()
+log.warn(emulator.cpu_get_current_instruction().decode('utf-8'))
emulator.memory_write_dword(emulator.cpu_reg32_get(i), 0x00414243)
s = emulator.memory_read_string(emulator.cpu_reg32_get(i), 4)
-print s
+log.warn(s.decode('utf-8'))
-print emulator.env_w32_hook_check()
+log.warn(emulator.env_w32_hook_check())
View
17 tests/sctest.py
@@ -22,6 +22,13 @@
import getopt
import logging
+#log = logging.getLogger('pylibemu')
+#handler = logging.StreamHandler(stream = sys.stdout)
+#formatter = logging.Formatter(datefmt = None)
+#handler.setFormatter(formatter)
+#log.addHandler(handler)
+#log.setLevel(logging.INFO)
+
from pylibemu import Emulator
class ShellcodeTest():
@@ -50,7 +57,7 @@ def _runShellcode(self, shellcode, index):
self.emulator.prepare(shellcode, offset)
self.emulator.test()
- self.log.info(self.emulator.emu_profile_output)
+ self.log.info(self.emulator.emu_profile_output.decode('utf-8'))
if self.emulator.emu_profile_truncated:
self.log.warning("[WARNING] Emulation profile truncated")
@@ -61,7 +68,7 @@ def runShellcode(self, shellcode, index):
self.emulator.run(shellcode)
self.log.debug("Offset: %d" % (self.emulator.offset, ))
- self.log.info(self.emulator.emu_profile_output)
+ self.log.info(self.emulator.emu_profile_output.decode('utf-8'))
if self.emulator.emu_profile_truncated:
self.log.warning("[WARNING] Emulation profile truncated")
@@ -1585,7 +1592,7 @@ def testShellcode29(self):
def usage():
- print """
+ sys.stdout.write("""
Pylibemu test suite
Usage:
@@ -1596,7 +1603,7 @@ def usage():
-s <shellcode>, --shellcode=<shellcode> Execute the selected shellcode test (0 means 'all tests')
-i <shellcode>, --info=<shellcode> Shows information about the selected shellcode test
-"""
+""")
sys.exit(0)
if __name__ == '__main__':
@@ -1627,6 +1634,6 @@ def usage():
info = True
if info:
- print f.__doc__
+ sys.stdout.write(f.__doc__ + '\n')
if execute:
f()
Please sign in to comment.
Something went wrong with that request. Please try again.