You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Show embeded timestamp of byte-decompiled file
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import sys
|
||||
from uncompyle6.load import load_file, check_object_path, load_module
|
||||
|
||||
def test_load():
|
||||
"""Basic test of load_file, check_object_path and load_module"""
|
||||
co = load_file(__file__)
|
||||
obj_path = check_object_path(__file__)
|
||||
co2 = load_module(obj_path)
|
||||
assert co == co2[2]
|
||||
version, timestamp, magic_int, co2 = load_module(obj_path)
|
||||
assert sys.version[0:3] == str(version)
|
||||
assert co == co2
|
||||
|
@@ -84,7 +84,7 @@ files=[
|
||||
|
||||
for base in files:
|
||||
filename = "bytecode_%s/%s.pyc" % (PYTHON_VERSION_STR, base)
|
||||
version, magic_int, co = uncompyle6.load_module(filename)
|
||||
version, timestamp, magic_int, co = uncompyle6.load_module(filename)
|
||||
ok = True
|
||||
|
||||
if type(co) == list:
|
||||
|
@@ -54,7 +54,7 @@ def disassemble_file(filename, outstream=None):
|
||||
try to find the corresponding compiled object.
|
||||
"""
|
||||
filename = check_object_path(filename)
|
||||
version, magic_int, co = load_module(filename)
|
||||
version, timestamp, magic_int, co = load_module(filename)
|
||||
if type(co) == list:
|
||||
for con in co:
|
||||
disco(version, con, outstream)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import imp, marshal, os, py_compile, sys, tempfile
|
||||
from struct import unpack
|
||||
|
||||
import uncompyle6.marsh
|
||||
from uncompyle6 import PYTHON3
|
||||
@@ -82,7 +83,8 @@ def load_module(filename):
|
||||
% version)
|
||||
|
||||
# print version
|
||||
fp.read(4) # timestamp
|
||||
ts = fp.read(4)
|
||||
timestamp = unpack("I", ts)[0]
|
||||
magic_int = magics.magic2int(magic)
|
||||
my_magic_int = magics.magic2int(imp.get_magic())
|
||||
|
||||
@@ -101,10 +103,13 @@ def load_module(filename):
|
||||
co = uncompyle6.marsh.load_code(fp, magic_int)
|
||||
pass
|
||||
|
||||
return version, magic_int, co
|
||||
return version, timestamp, magic_int, co
|
||||
|
||||
if __name__ == '__main__':
|
||||
co = load_file(__file__)
|
||||
obj_path = check_object_path(__file__)
|
||||
co2 = load_module(obj_path)
|
||||
assert co == co2[2]
|
||||
version, timestamp, magic_int, co2 = load_module(obj_path)
|
||||
print("version ", version, "magic int", magic_int)
|
||||
import datetime
|
||||
print(datetime.datetime.fromtimestamp(timestamp))
|
||||
assert co == co2
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from __future__ import print_function
|
||||
import inspect, os, sys
|
||||
import datetime, inspect, os, sys
|
||||
|
||||
from uncompyle6.disas import check_object_path
|
||||
from uncompyle6 import verify
|
||||
@@ -8,7 +8,7 @@ from uncompyle6.semantics import pysource
|
||||
from uncompyle6.load import load_module
|
||||
|
||||
def uncompyle(version, co, out=None, showasm=False, showast=False,
|
||||
showgrammar=False):
|
||||
timestamp=None, showgrammar=False):
|
||||
"""
|
||||
disassembles and deparses a given code block 'co'
|
||||
"""
|
||||
@@ -21,6 +21,9 @@ def uncompyle(version, co, out=None, showasm=False, showast=False,
|
||||
if co.co_filename:
|
||||
print('# Embedded file name: %s' % co.co_filename,
|
||||
file=real_out)
|
||||
if timestamp:
|
||||
print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
|
||||
file=real_out)
|
||||
|
||||
try:
|
||||
pysource.deparse_code(version, co, out, showasm, showast, showgrammar)
|
||||
@@ -35,12 +38,15 @@ def uncompyle_file(filename, outstream=None, showasm=False, showast=False,
|
||||
"""
|
||||
|
||||
filename = check_object_path(filename)
|
||||
version, magic_int, co = load_module(filename)
|
||||
version, timestamp, magic_int, co = load_module(filename)
|
||||
|
||||
if type(co) == list:
|
||||
for con in co:
|
||||
uncompyle(version, con, outstream, showasm, showast, showgrammar)
|
||||
uncompyle(version, con, outstream, showasm, showast,
|
||||
timestamp, showgrammar)
|
||||
else:
|
||||
uncompyle(version, co, outstream, showasm, showast, showgrammar)
|
||||
uncompyle(version, co, outstream, showasm, showast,
|
||||
timestamp, showgrammar)
|
||||
co = None
|
||||
|
||||
def main(in_base, out_base, files, codes, outfile=None,
|
||||
|
@@ -360,8 +360,8 @@ def compare_code_with_srcfile(pyc_filename, src_filename):
|
||||
|
||||
def compare_files(pyc_filename1, pyc_filename2):
|
||||
"""Compare two .pyc files."""
|
||||
version, magic_int1, code_obj1 = uncompyle6.load_module(pyc_filename1)
|
||||
version, magic_int2, code_obj2 = uncompyle6.load_module(pyc_filename2)
|
||||
version, timestamp, magic_int1, code_obj1 = uncompyle6.load_module(pyc_filename1)
|
||||
version, timestamp, magic_int2, code_obj2 = uncompyle6.load_module(pyc_filename2)
|
||||
cmp_code_objects(version, code_obj1, code_obj2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user