forked from Th4nat0s/Chall_Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxphp.py
executable file
·55 lines (45 loc) · 1.29 KB
/
xphp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
import sys
# v 0.2
# Copyleft Thanat0s
# http://Thanat0s.trollprod.org
#
# Licence GNU GPL
# Extract "Correctly" PHP Code from file
if len(sys.argv) != 2:
print 'Extract PHP Code from a file'
print 'To Use: ' + sys.argv[0] + ' infile'
sys.exit()
file = open(sys.argv[1], 'rb')
byteArr = bytearray(file.read())
file.close()
fileSize = len(byteArr)
Result = ''
PenDown = False
Comment = False
CommentType = ''
for byte in range( 0, fileSize ):
# Ignore <? et ?> dans les strings
if ((byteArr[byte] == ord("'")) and (CommentType == '' or CommentType == ord("'"))):
Comment = not Comment # Toggle True to False
if Comment == True:
CommentType = "'"
else:
CommentType = ''
# Ignore <? et ?> dans les strings
if ((byteArr[byte] == ord('"')) and (CommentType == '' or CommentType == ord('"'))):
Comment = not Comment # Toggle True to False
if Comment == True:
CommentType = '"'
else:
CommentType = ''
# Prend entre <? et ?>
if Comment == False:
if (byteArr[byte] == ord("<")) and (byteArr[byte+1] == ord("?")) :
PenDown = True
if (byteArr[byte] == ord("?")) and (byteArr[byte+1] == ord(">")) :
PenDown = False
Result = Result + chr(byteArr[byte]) + chr(byteArr[byte+1])
if PenDown == True:
Result = Result + chr(byteArr[byte])
print Result