bratah123 / maplepacketpuller Goto Github PK
View Code? Open in Web Editor NEWA Python Maplestory Packet Structure Analyzer
A Python Maplestory Packet Structure Analyzer
These 2 functions are now exactly the same except for the fact that one (additionally) prints.
Since check_keyword_and_return(keyword)
returns an empty string when false, we can make use of Python's duck/dynamic typing to do this:
elif Util.check_keyword_and_return(line):
packet_struct += Util.check_keyword_and_return(line) + "\n"
Instead of this:
Analysis.py Line 78-79
elif Util.check_keyword_and_print(line):
packet_struct += Util.check_keyword_and_return(line) + "\n"
Also, both functions have an obsolete condition.
They both check for if key in keyword.lower():
, and then check for the the same condition again just 2 lines later:
elif key not in keyword.lower() and...
Suggestion: Consider removing and/or merging.
Merging:
def check_keyword_and_return(keyword):
for key in KEYWORDS:
if key in keyword.lower():
if key != "if" and key != "else":
Util.print_dbg(f"{KEYWORDS_PRINT[KEYWORDS.index(key)]}")
return KEYWORDS_PRINT[KEYWORDS.index(key)]
elif "decode" in keyword.lower() and GET_ALL_DECODES:
Util.print_dbg(keyword)
return keyword # just in case our keywords array doesn't already have that Decode saved
return ""
Not sure if I'm interpreting the code correctly, but the function is_decode_func(func_name)
appears to check every element of a list of known decode functions against the provided line of pseudocode (i.e. func_name
), in order to determine if that line contains a decode function.
This is quite an expensive operation, since you have to check every known decode function name AND other unrelated elements (.e. if, else, do, while, etc.).
Suggestion: generalise the search pattern into searching for signatures. Based on what little literature I can get, all known decode functions seem to (unsurprisingly) have the word "decode" in them. Hence, consider the following implementation instead:
def is_decode_func(func_name):
if "decode" in func_name.lower():
return True
else:
return False
Python supports top-level functions, and does not require functions to be encapsulated within classes (unlike Java or C#).
Utility.py
An example is the Util class from Utility.py.
This is a class with only static methods and no class attributes and/or methods - and no instance methods either.
In this case, it would be safe to refactor these methods out into top level statements.
While not marked as global, the variables PRINT and GET_ALL_DECODES effectively function as global variables.
This is compounded by the fact that they are not actually directory constants.
PRINT is fine for now, since it is a manually-set variable.
Perhaps we could consider removing GET_ALL_DECODES, and passing it as a boolean variable into the method that currently use it, to avoid having to handle its state (notably for any possible future expansion of functionality).
E.g.
def check_keyword_and_return(keyword, get_all_debug):
...
Class PacketAnalysis(Analyzer):
...
def analyze_packet_structure(self), get_all_debug):
...
if KEYWORDS[5] in line:
if_or_else += "if " + Util.check_keyword_and_return(line, get_all_debug) + ":"
...
def run(self, get_all_debug):
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.