Skip to content

Commit 5424ca6

Browse files
committed
apply formatting
1 parent 9bdab94 commit 5424ca6

File tree

98 files changed

+3258
-2646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3258
-2646
lines changed

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
profile=black

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ gpg: Good signature from "Jimmy Pramosi (git) <[email protected]>" [u
5757

5858
```python
5959
import json
60-
from geckordp.rdp_client import RDPClient
60+
6161
from geckordp.actors.root import RootActor
62-
from geckordp.profile import ProfileManager
6362
from geckordp.firefox import Firefox
64-
63+
from geckordp.profile import ProfileManager
64+
from geckordp.rdp_client import RDPClient
6565

6666
""" Uncomment to enable debug output
6767
"""
68-
#from geckordp.settings import GECKORDP
69-
#GECKORDP.DEBUG = 1
70-
#GECKORDP.DEBUG_REQUEST = 1
71-
#GECKORDP.DEBUG_RESPONSE = 1
68+
# from geckordp.settings import GECKORDP
69+
# GECKORDP.DEBUG = 1
70+
# GECKORDP.DEBUG_REQUEST = 1
71+
# GECKORDP.DEBUG_RESPONSE = 1
7272

7373

7474
def main():
@@ -81,10 +81,7 @@ def main():
8181
profile.set_required_configs()
8282

8383
# start firefox with specified profile
84-
Firefox.start("https://example.com/",
85-
port,
86-
profile_name,
87-
["-headless"])
84+
Firefox.start("https://example.com/", port, profile_name, ["-headless"])
8885

8986
# create client and connect to firefox
9087
client = RDPClient()
@@ -99,6 +96,7 @@ def main():
9996

10097
input()
10198

99+
102100
if __name__ == "__main__":
103101
main()
104102
```

dev/converter.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
""" This is a helper script to create a formatted output log from pcap-dumps.
22
"""
3+
34
import argparse
45
import json
56
from pathlib import Path
6-
from scapy.all import PcapReader, re, Raw, TCP, IP
7+
8+
from scapy.all import IP, TCP, PcapReader, Raw, re
79

810

9-
class JSONNode():
11+
class JSONNode:
1012

1113
def __init__(self, idx: int, packet_idx: int):
1214
self.idx = idx
@@ -23,14 +25,20 @@ def __repr__(self):
2325
def main():
2426
# parse arguments
2527
parser = argparse.ArgumentParser(description="")
26-
parser.add_argument("-i", "--input", type=str, default="",
27-
help="Input file to convert to.")
28-
parser.add_argument("-p", "--port", type=int, default=6000,
29-
help="The port of the remote debug server.")
28+
parser.add_argument(
29+
"-i", "--input", type=str, default="", help="Input file to convert to."
30+
)
31+
parser.add_argument(
32+
"-p",
33+
"--port",
34+
type=int,
35+
default=6000,
36+
help="The port of the remote debug server.",
37+
)
3038
args, _ = parser.parse_known_args()
3139

3240
input_file = Path(args.input).absolute()
33-
if (not input_file.exists() or input_file.is_dir()):
41+
if not input_file.exists() or input_file.is_dir():
3442
print(f"invalid input file '{input_file}'")
3543

3644
buffer = ""
@@ -47,38 +55,37 @@ def main():
4755

4856
# check whether it uses TCP protocol
4957
if p.haslayer(TCP) and p.haslayer(Raw):
50-
if (len(payload) < 4):
58+
if len(payload) < 4:
5159
continue
5260
root_nodes = []
5361

5462
# helper function to stack or pop nodes
5563
def parse(brackets):
5664
for idx, c in enumerate(payload):
57-
if (c == "{"):
65+
if c == "{":
5866
brackets.append(JSONNode(idx, packet_idx))
5967
continue
60-
if (c == "}"):
61-
if (len(brackets) <= 0):
68+
if c == "}":
69+
if len(brackets) <= 0:
6270
break
6371
node = brackets.pop()
6472
# check if root element
65-
if (len(brackets) == 0):
66-
root_nodes.append(
67-
(node, JSONNode(idx, packet_idx)))
73+
if len(brackets) == 0:
74+
root_nodes.append((node, JSONNode(idx, packet_idx)))
6875
continue
6976
return brackets
7077

7178
# parse and check whether it is a request
7279
# or response by checking the destination port
73-
if (args.port == p[TCP].dport):
80+
if args.port == p[TCP].dport:
7481
req_brackets = parse(req_brackets)
75-
if (len(req_brackets) > 0):
82+
if len(req_brackets) > 0:
7683
req_brackets[0].packets_list.append(packet_idx)
7784
continue
7885
buffer += "->REQUEST\n"
7986
else:
8087
res_brackets = parse(res_brackets)
81-
if (len(res_brackets) > 0):
88+
if len(res_brackets) > 0:
8289
res_brackets[0].packets_list.append(packet_idx)
8390
continue
8491
buffer += "<-RESPONSE\n"
@@ -89,9 +96,9 @@ def parse(brackets):
8996

9097
new_payload = ""
9198
# if it's only a single packet, no need to merge payloads
92-
if (len(node[0].packets_list) <= 0):
99+
if len(node[0].packets_list) <= 0:
93100
# set new payload which contains only the json data
94-
new_payload = payload[node[0].idx:node[1].idx+1]
101+
new_payload = payload[node[0].idx : node[1].idx + 1]
95102
else:
96103
adjust_offset = 1
97104
# merge payloads and its related sizes
@@ -103,7 +110,7 @@ def parse(brackets):
103110
# shift index by new offset
104111
node[1].idx += adjust_offset
105112
# set new payload which contains only the json data
106-
new_payload = new_payload[node[0].idx:node[1].idx]
113+
new_payload = new_payload[node[0].idx : node[1].idx]
107114

108115
# format payload
109116
new_payload = new_payload.replace("'", "\\'")
@@ -113,10 +120,10 @@ def parse(brackets):
113120
except Exception as ex:
114121
print(f"{ex}\n\n", new_payload)
115122
return 1
116-
new_payload = "\t".expandtabs(
117-
8) + new_payload.replace("\n", "\n\t".expandtabs(8))
123+
new_payload = "\t".expandtabs(8) + new_payload.replace(
124+
"\n", "\n\t".expandtabs(8)
125+
)
118126
buffer += f"{new_payload}\n"
119-
120127

121128
# write buffer to the same path
122129
output_file = f"{input_file.parent.joinpath(input_file.stem)}.log"
@@ -125,6 +132,5 @@ def parse(brackets):
125132
print(f"converted pcap-dump in '{output_file}'")
126133

127134

128-
129135
if __name__ == "__main__":
130136
main()

dev/profile.py

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
""" This is a Firefox cli profile manager.
22
Create, clone or remove a profile.
33
"""
4-
import os
4+
55
import argparse
6+
import os
67
from argparse import RawTextHelpFormatter
78
from pprint import pprint
9+
810
from geckordp.profile import ProfileManager
911
from geckordp.settings import GECKORDP
1012

@@ -16,72 +18,80 @@ def main():
1618
]
1719
epilog = """available environment variables:\n\t"""
1820

19-
2021
parser = argparse.ArgumentParser(
2122
description="",
2223
formatter_class=RawTextHelpFormatter,
23-
epilog=epilog+"\n\t".join(env_names)
24+
epilog=epilog + "\n\t".join(env_names),
25+
)
26+
parser.add_argument(
27+
"-n",
28+
"--new",
29+
type=str,
30+
default="",
31+
metavar="<profile-name>",
32+
help="Creates a new firefox profile",
33+
)
34+
parser.add_argument(
35+
"-c",
36+
"--clone",
37+
action="append",
38+
nargs=2,
39+
metavar=("<source-profile-name>", "<clone-profile-name>"),
40+
help="Clones an existing profile with a different name",
41+
)
42+
parser.add_argument(
43+
"-rm",
44+
"--remove",
45+
type=str,
46+
default="",
47+
metavar="<profile-name>",
48+
help="Removes a profile",
2449
)
25-
parser.add_argument("-n", "--new", type=str, default="", metavar="<profile-name>",
26-
help="Creates a new firefox profile")
27-
parser.add_argument("-c", "--clone", action="append", nargs=2,
28-
metavar=("<source-profile-name>",
29-
"<clone-profile-name>"),
30-
help="Clones an existing profile with a different name")
31-
parser.add_argument("-rm", "--remove", type=str, default="", metavar="<profile-name>",
32-
help="Removes a profile")
33-
parser.add_argument("-ls", "--list", action="store_true",
34-
help="List all profiles")
50+
parser.add_argument("-ls", "--list", action="store_true", help="List all profiles")
3551
args, _ = parser.parse_known_args()
3652

37-
3853
env_vars = {}
3954
for env_name in env_names:
4055
env_vars[env_name] = os.environ.get(env_name, "")
4156

42-
4357
GECKORDP.DEBUG = 1
4458
pm = ProfileManager(env_vars["FIREFOX_PATH"], env_vars["PROFILE_PATH"])
4559

46-
47-
if (args.new != ""):
60+
if args.new != "":
4861
profile = pm.create(args.new)
49-
if (profile == None):
62+
if profile == None:
5063
return 1
5164
profile.set_required_configs()
5265
return 0
5366

54-
55-
if (args.clone != None):
56-
if (not isinstance(args.clone, list)):
67+
if args.clone != None:
68+
if not isinstance(args.clone, list):
5769
print("'--clone' expected 2 strings")
5870
return 1
5971

60-
if (len(args.clone) != 1):
72+
if len(args.clone) != 1:
6173
print("'--clone' encountered an unknown error")
6274
return 1
6375

6476
for n in args.clone[0]:
65-
if (str(n).isdecimal()):
77+
if str(n).isdecimal():
6678
print(f"'--clone' expected a string value not '{n}'")
6779
return 1
6880

6981
profile = pm.clone(args.clone[0][0], args.clone[0][1])
70-
if (profile == None):
82+
if profile == None:
7183
print(f"cloning profile failed")
7284
return 1
73-
85+
7486
profile.set_required_configs()
7587
return 0
7688

77-
78-
if (args.remove != ""):
79-
if (pm.remove(args.remove)):
89+
if args.remove != "":
90+
if pm.remove(args.remove):
8091
return 0
8192
return 1
8293

83-
84-
if (args.list is True):
94+
if args.list is True:
8595
pprint(pm.list_profiles())
8696
return 0
8797

0 commit comments

Comments
 (0)