-
Notifications
You must be signed in to change notification settings - Fork 379
Scan uploaded levels for ACE #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
64a0dd9
2f83b44
2f84915
be129c3
1f0e864
8a81867
ffb9c01
6f8e13e
7a87c13
9a29126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| class LevelParser { | ||
| public $data = []; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tbh i don't see the point of making this a single member class. this data member is basically useless anyways (unless you were planning on extending the functionality of this class?). just make validate static and pass the level string as its param
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes in the future functionality could be expanded on validating other parts of the level request. However for now I have implemented your suggestions |
||
|
|
||
| public function __construct($levelString) | ||
| { | ||
| $this->data = self::map($levelString, ':'); | ||
|
0x1DEA marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
| * Convert GD's weird "keyed" array strings to dictionary. Works with out-of-order keys. | ||
| * | ||
| * @param $list string | ||
| * @param $separator string | ||
| * @return array | ||
| */ | ||
| public static function map($list, $separator) { | ||
| $bits = explode($separator, $list); | ||
| $array = []; | ||
| for ($i = 1; $i < count($bits); $i += 2) { | ||
| $array[$bits[$i - 1]] = $bits[$i]; | ||
| } | ||
| return $array; | ||
| } | ||
|
|
||
| /** | ||
| * Flatten dictionary to single delimited string | ||
| * | ||
| * @param $dict array|object | ||
| * @param $separator string | ||
| * @return string | ||
| */ | ||
| public static function demap($dict, $separator) { | ||
| $string = ''; | ||
| foreach ($dict as $key => $value) { | ||
| $string[] .= "${separator}${key}${separator}${value}"; | ||
| } | ||
| return $string; | ||
| } | ||
|
|
||
| /** | ||
| * @param $string string | ||
| * @return false|string | ||
| */ | ||
| public static function base64_urlencode($string) { | ||
| return base64_encode(strtr($string, '+/', '-_')); | ||
| } | ||
|
|
||
| /** | ||
| * @param $string string | ||
| * @return false|string | ||
| */ | ||
| public static function base64_urldecode($string) { | ||
| return base64_decode(strtr($string, '-_', '+/'), true); | ||
| } | ||
|
|
||
| /** | ||
| * Validates level data for various things (currently only ACE exploit) | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function validate() { | ||
| // Ocular Miracle ain't happening | ||
| $max_level_size = 50 * 1024 * 1024; // 50 MB Max uncompressed size | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep in mind that any level over this size could bypass the check entirely. it wouldn't be impossible to add padding in ways that inflate the size of the level while keeping it working on desktop platforms... |
||
| $objs = explode(';', zlib_decode(self::base64_urldecode($this->data[4]), $max_level_size)); | ||
|
0x1DEA marked this conversation as resolved.
Outdated
|
||
| // Skip level header | ||
| for ($i = 1; $i < 2; $i++) { | ||
|
0x1DEA marked this conversation as resolved.
Outdated
|
||
| $obj = self::map($objs[$i], ','); | ||
| // Check for pickup trigger exploit | ||
| if ($obj[1] == 1817) { | ||
|
0x1DEA marked this conversation as resolved.
Outdated
|
||
| $id = intval($obj[80]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would recommend checking the color id property of color triggers as well, but it's probably not necessary. mostly just crashes
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What index is color id? |
||
| if ($id > 1099 || $id < 0) return false; | ||
|
0x1DEA marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.