From cb81c9b6ce3f52903ced91a299ccae6ccfa00086 Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Sat, 11 May 2024 17:47:33 +0300 Subject: [PATCH] Initial commit --- classes/bas.class.php | 404 +++++++++++++++++++++++++++++++++++ classes/lis.class.php | 485 ++++++++++++++++++++++++++++++++++++++++++ compile.php | 32 +++ decompile.php | 35 +++ index.php | 44 ++++ mbstyle/mbs.css | 75 +++++++ midlet.php | 38 ++++ obf.php | 34 +++ 8 files changed, 1147 insertions(+) create mode 100644 classes/bas.class.php create mode 100644 classes/lis.class.php create mode 100644 compile.php create mode 100644 decompile.php create mode 100644 index.php create mode 100644 mbstyle/mbs.css create mode 100644 midlet.php create mode 100644 obf.php diff --git a/classes/bas.class.php b/classes/bas.class.php new file mode 100644 index 0000000..f91603f --- /dev/null +++ b/classes/bas.class.php @@ -0,0 +1,404 @@ +new BAS("Autorun.bas"); */ + + function __construct($files) { + $this->file = $files; + $this->init(); + } + + function init() { + $this->data = file_get_contents($this->file); + } + + /* EXAMPLE, $output = $bas->decompile(); */ + + function decompile() { + $ops = array( + " STOP ", + " POP ", + " RETURN ", + " END ", + " NEW ", + " RUN ", + " DIR ", + " DEG ", + " RAD ", + " BYE ", + " GOTO ", + " GOSUB ", + " SLEEP ", + " PRINT ", + " REM ", + " DIM ", + " IF", + " THEN ", + " CLS ", + " PLOT ", + " DRAWLINE ", + " FILLRECT ", + " DRAWRECT ", + " FILLROUNDRECT ", + " DRAWROUNDRECT ", + " FILLARC ", + " DRAWARC ", + " DRAWSTRING ", + " SETCOLOR ", + " BLIT ", + " FOR ", + " TO ", + " STEP ", + " NEXT ", + " INPUT ", + " LIST ", + " ENTER ", + " LOAD ", + " SAVE ", + " DELETE ", + " EDIT ", + " TRAP ", + " OPEN ", + " CLOSE ", + " NOTE ", + " POINT ", + " PUT ", + " GET ", + " DATA ", + " RESTORE ", + " READ ", + "=", + "<>", + "<", + "<=", + ">", + ">=", + "(", + ")", + ",", + "+", + "-", + "-", + "*", + "/", + "^", + " BITAND ", + " BITOR ", + " BITXOR ", + " NOT ", + " AND ", + " OR ", + "SCREENWIDTH", + "SCREENHEIGHT", + " ISCOLOR ", + " NUMCOLORS ", + "STRINGWIDTH", + "STRINGHEIGHT", + "LEFT$", + "MID$", + "RIGHT$", + "CHR$", + "STR$", + "LEN", + "ASC", + "VAL", + " UP ", + " DOWN ", + " LEFT ", + " RIGHT ", + " FIRE ", + " GAMEA ", + " GAMEB ", + " GAMEC ", + " GAMED ", + " DAYS ", + " MILLISECONDS ", + " YEAR ", + " MONTH ", + " DAY ", + " HOUR ", + " MINUTE ", + " SECOND ", + " MILLISECOND ", + "RND", + " ERR ", + " FRE ", + "MOD", + "EDITFORM ", + "GAUGEFORM ", + "CHOICEFORM", + "DATEFORM", + "MESSAGEFORM", + "LOG", + "EXP", + "SQR", + "SIN", + "COS", + "TAN", + "ASIN", + "ACOS", + "ATAN", + "ABS", + "=", + "#", + " PRINT ", + " INPUT ", + ":", + " GELGRAB ", + " DRAWGEL ", + " SPRITEGEL ", + " SPRITEMOVE ", + " SPRITEHIT ", + "READDIR$", + "PROPERTY$", + " GELLOAD ", + " GELWIDTH", + " GELHEIGHT", + " PLAYWAV ", + " PLAYTONE ", + " INKEY", + "SELECT", + "ALERT ", + " SETFONT ", + " MENUADD ", + " MENUITEM", + " MENUREMOVE ", + " CALL ", + " ENDSUB " + ); + if ($this->readInt($this->data) != "4d420001") { + // $this->init(); + return -1; + } else { + $isDIM = false; + $varnum = hexdec($this->readShort($this->data)); ///количество переменных + $varname = []; + $main = ''; + //чтение имен переменных + for ($i = 0; $i < $varnum; $i++) { + $num = hexdec($this->readShort($this->data)); ///длина имени переменной + for ($ii = 0; $ii < $num; $ii++) { + $varname[$i] = $varname[$i] ?? ''; + $varname[$i] .= substr($this->data, 0, 1); + $this->readByte($this->data); + } + $this->readByte($this->data); + } + ///echo $varname[0]; + $codeln = hexdec($this->readShort($this->data)); //длина остального кода + if ($codeln != strlen($this->data)) { + $this->init(); + return -2; + } + //for($i=0; $i<$codeln; $i++) ///чтение кода + while (strlen($this->data) > 0) { + $line = ""; + $line .= hexdec($this->readShort($this->data)); //пишем номер строки + $lineS = hexdec($this->readByte($this->data)); //длина строки + $isl = 1; + unset($lims); + for ($ii = 0; $ii < $lineS - 4; $ii++) { ///читаем операторы строки в массив + $lims[$ii] = $this->readByte($this->data); + } + $cur = 0; //позиция чтения + while ($cur < count($lims)) { //декомпилятор + $opType = $lims[$cur]; + $cur++; + if (hexdec($opType) == 0xfc) { ///присваивание + $varNum = hexdec($lims[$cur]); + + $limsIndex = $cur - 2; + if (array_key_exists($limsIndex, $lims) && hexdec($lims[$limsIndex]) == 16) + $line .= " "; + + if ($isl == 1) { + $line .= " " . $varname[$varNum]; + } else + $line .= $varname[$varNum]; + + + $cur++; + } else { ///оператор + $isl = 0; + switch (hexdec($opType)) { + case 0x0e: + $line .= " REM \""; + $str = hexdec($lims[$cur]); ///длина + $cur++; + for ($i = 0; $i < $str; $i++) { + $line .= iconv("WINDOWS-1251", "UTF-8", chr(hexdec($lims[$cur]))); + $cur++; + } + $line .= "\""; + break; + case 0xfd: + $line .= "\""; + $str = hexdec($lims[$cur]); ///длина + $cur++; + for ($i = 0; $i < $str; $i++) { + $line .= iconv("WINDOWS-1251", "UTF-8", chr(hexdec($lims[$cur]))); + $cur++; + } + $line .= "\""; + break; + case 0x30: + $line .= " DATA "; + $str = hexdec($lims[$cur]); ///длина + $cur++; + for ($i = 0; $i < $str; $i++) { + $line .= iconv("WINDOWS-1251", "UTF-8", chr(hexdec($lims[$cur]))); + $cur++; + } + break; + case 0xf6: + $line .= "="; + break; + case 0xf8: + $line .= hexdec($lims[$cur]); + $cur++; + break; + case 0xf7: + $line .= "("; + continue 2; + case 0xf9: + $line .= hexdec($lims[$cur]); + $cur++; + break; + case 0xfa: + $line .= (hexdec($lims[$cur]) * 256 + hexdec($lims[$cur + 1])); + $cur = $cur + 2; + break; + case 0xfb: + $line .= (hexdec($lims[$cur]) * 16777216 + hexdec($lims[$cur + 1]) * 65536 + hexdec($lims[$cur + 2]) * 256 + hexdec($lims[$cur + 3])); + $cur = $cur + 4; + break; + case 0xfe: + (int) $exp = $this->tosbyte(hexdec($lims[$cur + 3])); + $m = (hexdec($lims[$cur]) * 65536 + hexdec($lims[$cur + 1]) * 256 + hexdec($lims[$cur + 2])) / 500000; + $e = 1; + if ($exp > 0) { + $d = 1; + for ($i = 0; $i < $exp; $i++) + $d = $d * 10; + $e = $d; + } + if ($exp < 0) { + $d = 1; + for ($i = $exp; $i < 0; $i++) + $d = $d / 10; + $e = $d; + } + $line .= (float) ($m * $e); + + $cur = $cur + 4; + break; + default: + $line .= $ops[hexdec($opType)]; + if ($opType == 15 || ($ops[$opType] ?? '') == ' READ ') { + $isDIM = true; + } + break; + } + } + } + $this->readByte($this->data); + $line .= "\r\n"; + $main .= $line; + } + + $this->init(); + return $main; + } + } + + function obfuscation($name) { + if ($this->readInt($this->data) != "4d420001") { + /// $this->init(); + return -1; + } else { + $main = ""; + $main .= pack('H*', "4d420001"); //writeHex + + $varnum = hexdec($this->readShort($this->data)); + $main .= pack('n*', $varnum); //writeShort + // $main.= $this->writeUTF("hello"); + /// echo hexdec($this->readShort($this->data)); + for ($i = 0; $i < $varnum; $i++) { //пропуск переменных + $this->readUTF($this->data); + $main .= $this->writeUTF(" "); + $main .= pack('H*', $this->readByte($this->data)); + } + $leng = hexdec($this->readShort($this->data)); + $main .= pack('n*', $leng + 7); + + for ($i = 0; $i < $leng; $i++) { + $main .= pack('H*', $this->readByte($this->data)); + } + + $main .= pack('H*', "FFFF"); + + file_put_contents($name, $main); + } + + $this->init(); + return 0; + } + + function tosbyte($byte) { + if (0 <= $byte && $byte <= 63) + return (int) $byte; + if (64 <= $byte && $byte <= 191) + return (int) (-(128 - $byte)); + if (192 <= $byte && $byte <= 255) + return (int) (-(256 - $byte)); + return 0; + } + + function readInt($text) { + $this->data = substr($text, 4, strlen($text)); + return bin2hex(substr($text, 0, 4)); + } + + function readShort($text) { + $this->data = substr($text, 2, strlen($text)); + return bin2hex(substr($text, 0, 2)); + } + + function readByte($text) { + $this->data = substr($text, 1, strlen($text)); + return bin2hex(substr($text, 0, 1)); + } + + function readUTF() { + // $this->data = substr($text, 1, strlen($text)); + // return bin2hex(substr($text, 0, 1)); + $to = hexdec($this->readShort($this->data)); + $bombom = ""; + while ($to <> 0) { + $bombom .= iconv("WINDOWS-1251", "UTF-8", chr(hexdec($this->readByte($this->data)))); + $to--; + } + // $this->readByte($this->data); + return $bombom; + } + + function writeUTF($text) { + $pack = pack('n*', mb_strlen($text)); + $pack .= pack('a*', $text); + return $pack; + } +} \ No newline at end of file diff --git a/classes/lis.class.php b/classes/lis.class.php new file mode 100644 index 0000000..af40810 --- /dev/null +++ b/classes/lis.class.php @@ -0,0 +1,485 @@ +BAS для MobileBASIC + * *Автор - Андрей Рейгант (HoldFast) + * *http://mbteam.ru + * * + */ + +class LIS { + + public $data, $file, $save, $coderror, $bufbody, $buffer, $compile = false; + public $lines = ['']; + public $ltypes = ['']; + public $lexems = []; + public $vars = ['']; + public $vtypes = ['']; + public $currLine; + + const INT = 0, FLOAT = 1, STR = 2; + const Operator = 0, Integer = 1, Float = 2, String = 3, Variable = 4, Data = 5, ArrayByte = 6; + + public $ops = array("STOP", "POP", "RETURN", "END", "NEW", "RUN", "DIR", "DEG", "RAD", "BYE", "GOTO", "GOSUB", "SLEEP", "PRINT", "REM", "DIM", "IF", "THEN", "CLS", "PLOT", "DRAWLINE", "FILLRECT", "DRAWRECT", "FILLROUNDRECT", "DRAWROUNDRECT", "FILLARC", "DRAWARC", "DRAWSTRING", "SETCOLOR", "BLIT", "FOR", "TO", "STEP", "NEXT", "INPUT", "LIST", "ENTER", "LOAD", "SAVE", "DELETE", "EDIT", "TRAP", "OPEN", "CLOSE", "NOTE", "POINT", "PUT", "GET", "DATA", "RESTORE", "READ", "=", "<>", "<", "<=", ">", ">=", "(", ")", ",", "+", "-", "-", "*", "/", "^", "BITAND", "BITOR", "BITXOR", "NOT", "AND", "OR", "SCREENWIDTH", "SCREENHEIGHT", "ISCOLOR", "NUMCOLORS", "STRINGWIDTH", "STRINGHEIGHT", "LEFT$", "MID$", "RIGHT$", "CHR$", "STR$", "LEN", "ASC", "VAL", "UP", "DOWN", "LEFT", "RIGHT", "FIRE", "GAMEA", "GAMEB", "GAMEC", "GAMED", "DAYS", "MILLISECONDS", "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND", "MILLISECOND", "RND", "ERR", "FRE", "MOD", "EDITFORM", "GAUGEFORM", "CHOICEFORM", "DATEFORM", "MESSAGEFORM", "LOG", "EXP", "SQR", "SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ABS", "=", "#", "PRINT", "INPUT", ":", "GELGRAB", "DRAWGEL", "SPRITEGEL", "SPRITEMOVE", "SPRITEHIT", "READDIR$", "PROPERTY$", "GELLOAD", "GELWIDTH", "GELHEIGHT", "PLAYWAV", "PLAYTONE", "INKEY", "SELECT", "ALERT", "SETFONT", "MENUADD", "MENUITEM", "MENUREMOVE", "CALL", "ENDSUB"); + public $keywords = array("STOP", "POP", "RETURN", "END", "RUN", "DIR", "DEG", "RAD", "BYE", "CLS", "ENDSUB"); + public $functions = array("SCREENHEIGHT", "SCREENWIDTH", "ISCOLOR", "NUMCOLORS", "STRINGWIDTH", "STRINGHEIGHT", "LEFT$", "MID$", "RIGHT$", "CHR$", "STR$", "LEN", "ASC", "VAL", "UP", "DOWN", "LEFT", "RIGHT", "FIRE", "GAMEA", "GAMEB", "GAMEC", "GAMED", "DAYS", "MILLISECONDS", "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND", "MILLISECOND", "RND", "ERR", "FRE", "MOD", "EDITFORM", "GAUGEFORM", "CHOICEFORM", "DATEFORM", "MESSAGEFORM", "LOG", "EXP", "SQR", "SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ABS", "SPRITEHIT", "READDIR$", "PROPERTY$", "GELWIDTH", "GELHEIGHT", "INKEY", "SELECT", "MENUITEM", "MENUREMOVE"); + + function __construct($name, $newname) { + $this->file = $name; + $this->save = $newname; + } + + function init() { + $this->data = file_get_contents($this->file); + } + + function compile() { + if (!$this->compile) { + $this->init(); + $string = explode("\n", $this->data); + + for ($i = 0; $i < count($string); $i++) { + if (trim($string[$i]) != "") { + $this->lines[] = trim($string[$i]); + } + } + + $this->analize(); + if ($this->coderror != "") + return $this->coderror; + $this->compileCode(); + file_put_contents($this->save, $this->buffer); + $this->compile = true; + } + } + + function analize() { + $this->currLine = 1; + + for ($i = 1; $i < count($this->lines); $i++) { + $this->analizeLine($this->lines[$i]); + $this->check($this->currLine); + $this->currLine++; + if ($this->coderror != "") + break; + } + } + + function check($lineNum) { + + // for($i=0; $ilexems[$lineNum]); $i++){ + // echo $this->lexems[$lineNum][$i]; + //} + // echo "\n"; + + $bracketCount = 0; + if ($this->ltypes[$lineNum][0] != self::Integer) { + $this->coderror = "Invalid line number [" . $this->lexems[$lineNum][0] . "] "; + // return; + } + + for ($i = 0; $i < count($this->lexems[$lineNum]); $i++) { + + if ($this->lexems[$lineNum][$i] == "(") + $bracketCount++; + if ($this->lexems[$lineNum][$i] == ")") + $bracketCount--; + } + + for ($ii = 0; $ii < count($this->lexems[$lineNum]); $ii++) { + $i = $ii; + + if ($this->ltypes[$lineNum][$i] == self::Operator) { + if (in_array($this->lexems[$lineNum][$i], $this->keywords)) { + if (!($i == count($this->lexems[$lineNum]) - 1 || $this->lexems[$lineNum][$i + 1] == ":")) + $this->coderror = "Operator must have 0 arguments [" . $this->lexems[$lineNum][$i] . "] on line " . $this->lexems[$lineNum][0]; + return; + } elseif (in_array($this->lexems[$lineNum][$i], $this->functions)) { + if ($i == count($this->lexems[$lineNum]) - 1 || $this->lexems[$lineNum][$i + 1] != "(") + $this->coderror = "Error function [" . $this->lexems[$lineNum][$i] . "] on line " . $this->lexems[$lineNum][0]; + return; + } elseif (!in_array($this->lexems[$lineNum][$i], $this->functions) && mb_strlen($this->lexems[$lineNum][$i]) > 1) { + if ($i == count($this->lexems[$lineNum]) - 1 || $this->lexems[$lineNum][$i + 1] == ":") { + $this->coderror = "Operator must have arguments [" . $this->lexems[$lineNum][$i] . "]"; + return; + } elseif ($this->lexems[$lineNum][$i + 1] == "(" && $this->lexems[$lineNum][$i] != "TO" && $this->lexems[$lineNum][$i] != "STEP") { + $this->coderror = "Not an operator [" . $this->lexems[$lineNum][$i] . "]"; + return; + } + } + + + if ($this->lexems[$lineNum][$i] == "DIM") { + $this->lexems[$lineNum][$i + 2] = ""; + $this->ltypes[$lineNum][$i + 2] = self::ArrayByte; + } + + if ($i < count($this->ltypes[$lineNum]) - 1) + if ($this->ltypes[$lineNum][$i] == self::Variable && $this->lexems[$lineNum][$i + 1] == "(") { { + $this->lexems[$lineNum][$i + 1] = ""; + $this->ltypes[$lineNum][$i + 1] = self::ArrayByte; + } + } + } + } + + + if ($bracketCount != 0) { + $this->coderror = "Error: any brakets no open/close"; + return; + } + } + + function analizeLine($line) { + $i = 0; + while ($i < mb_strlen($line)) { + $i += $this->readToken($line, $i); + if ($this->coderror != "") + break; + } + } + + function isLetter($ch) { + return ($ch >= 'A' && $ch <= 'Z') + || ($ch >= 'a' && $ch <= 'z'); + } + + function isDigit($ch) { + return ($ch >= '0' && $ch <= '9'); + } + + function isLetterOrDigit($ch) { + return $this->isLetter($ch) || $this->isDigit($ch); + } + + function isVariablePartSymbol($ch) { + return ($ch == '_' || $ch == '$' || $ch == '%'); + } + + function isValidVariableChar($ch) { + return $this->isLetterOrDigit($ch) || $this->isVariablePartSymbol($ch); + } + + function readToken($line, $startPos) { + $initPos = $startPos; + $op = ""; + + if ($this->isLetter(mb_substr($line, $startPos, 1))) { + while ($this->isValidVariableChar(mb_substr($line, $startPos, 1))) { + $op .= mb_substr($line, $startPos, 1); + $startPos++; + if ($startPos >= mb_strlen($line)) + break; + } + + + + $op = mb_strtoupper($op); + $this->lexems[$this->currLine][] = $op; + // echo "лан, не урчи"; + + $isData = false; + $data = ""; + + if ($op == "DATA" || $op == "REM") { + $isData = true; + $startPos++; + while ($startPos < mb_strlen($line)) { + $data .= mb_substr($line, $startPos, 1); + $startPos++; + } + $this->lexems[$this->currLine][] = $data; + } + + if (!in_array($op, $this->ops)) { + if (!in_array($op, $this->vars)) + $this->vars[] = $op; + if ($this->endWith($op, "$")) { + $this->vtypes[] = self::STR; + } elseif ($this->endWith($op, "%")) { + $this->vtypes[] = self::INT; + } else + $this->vtypes[] = self::FLOAT; + $this->ltypes[$this->currLine][] = self::Variable; + // } + } else { + $this->ltypes[$this->currLine][] = self::Operator; + if ($isData) { + $this->ltypes[$this->currLine][] = self::Data; + } + } + } + + //STRING + elseif (mb_substr($line, $startPos, 1) == '"') { + $startPos++; + while (!(mb_substr($line, $startPos, 1) == '"')) { + $op .= mb_substr($line, $startPos, 1); + $startPos++; + if ($startPos >= mb_strlen($line)) { + $this->coderror = "Error complie: Not forund close \""; + break; + } + } + + $startPos++; + $this->lexems[$this->currLine][] = '"' . $op . '"'; + $this->ltypes[$this->currLine][] = self::String; + } + // NUMBER + elseif ($this->isDigit(mb_substr($line, $startPos, 1))) { + while ($this->isDigit(mb_substr($line, $startPos, 1)) + || mb_substr($line, $startPos, 1) == '.' + || mb_substr($line, $startPos, 1) == 'e' || mb_substr($line, $startPos, 1) == 'E') { + $op .= mb_substr($line, $startPos, 1); + if (mb_substr($line, $startPos, 1) == 'e' || mb_substr($line, $startPos, 1) == 'E') { + $op .= mb_substr($line, $startPos + 1, 1); + $startPos += 2; + } else + $startPos++; + if ($startPos >= mb_strlen($line)) + break; + } + + $containPoint = false; + $error = false; + + for ($i = 0; $i < mb_strlen($op); $i++) { + if ($op[$i] == '.') { + if (!$containPoint) + $containPoint = true; + else { + // exit; + $this->coderror = "NumberLexem contains more than one point [" . $op . "]"; + return; + } + } + } + + if (!$error) { + $this->lexems[$this->currLine][] = $op; + if ($containPoint) + $this->ltypes[$this->currLine][] = self::Float; + else + $this->ltypes[$this->currLine][] = self::Integer; + } + } + ///SYMBOL + else { + if (mb_substr($line, $startPos, 1) != ' ' && mb_substr($line, $startPos, 1) < 'А') { + $this->lexems[$this->currLine][] = mb_substr($line, $startPos, 1); + $this->ltypes[$this->currLine][] = self::Operator; + $startPos++; + } elseif (mb_substr($line, $startPos, 1) >= 'А' && mb_substr($line, $startPos, 1) <= 'я') { + $this->coderror = "SymbolLexem not recognized [" . $line[$startPos] . "]"; + return; + } else + $startPos++; + } + + return $startPos - $initPos; + } + + function compileHead() { + $buf = ""; + $buf .= pack('H*', "4d420001"); + $buf .= pack('n*', count($this->vars) - 1); + for ($i = 1; $i < count($this->vars); $i++) { + $buf .= $this->writeUTF($this->vars[$i]); + switch ($this->vtypes[$i]) { + case self::INT: + $buf .= pack('H*', "00"); + break; + + case self::FLOAT: + $buf .= pack('H*', "01"); + break; + + case self::STR: + $buf .= pack('H*', "02"); + break; + } + } + $buf .= pack('n*', strlen($this->bufbody)); + $this->buffer = $buf . $this->bufbody; + } + + function compileCode() { + $lexems = $this->lexems; + $ltypes = $this->ltypes; + + $buf = ""; + for ($currLine = 1; $currLine < count($lexems) + 1; $currLine++) { + $line = ""; + $buf .= pack('n*', $lexems[$currLine][0]); + + for ($currLex = 1; $currLex < count($lexems[$currLine]); $currLex++) { + /////Operator + + $ifStarted = false; + $forStarted = false; + if ($ltypes[$currLine][$currLex] == self::Operator) { + if (trim($lexems[$currLine][$currLex]) == "IF") { + $ifStarted = true; + } elseif (trim($lexems[$currLine][$currLex]) == "THEN") { + $ifStarted = false; + } elseif (trim($lexems[$currLine][$currLex]) == "FOR") { + $forStarted = true; + } + + for ($i = 0; $i < count($this->ops); $i++) { + if (trim($lexems[$currLine][$currLex]) == $this->ops[$i]) { + if (trim($lexems[$currLine][$currLex]) == "=") { + if ($ifStarted) { + $i = "33"; + } else if ($forStarted) { + $i = "7b"; + $forStarted = false; + } else { + $i = "f6"; + } + } else { + $i = dechex($i); + if (strlen($i) < 2) + $i = "0" . $i; + } + /// echo $i; + $line .= pack('H*', $i); + break; + } + } + } + /////Variable + if ($ltypes[$currLine][$currLex] == self::Variable) { + for ($i = 1; $i < count($this->vars); $i++) { + if (trim($lexems[$currLine][$currLex]) == trim($this->vars[$i])) { + $line .= pack('H*', "FC"); + $i = dechex($i - 1); + //echo $i; + if (strlen($i) < 2) + $i = "0" . $i; + $line .= pack('H*', $i); + break; + } + } + } + + if ($ltypes[$currLine][$currLex] == self::ArrayByte) { + $line .= pack('H*', "F7"); + } + + + if ($ltypes[$currLine][$currLex] == self::Integer) { + if (strlen($lexems[$currLine][$currLex]) > 5) + $ltypes[$currLine][$currLex] = self::Float; + else { + $val = intval($lexems[$currLine][$currLex]); + if ($val <= 127) { + $line .= pack('H*', "F8"); + $i = dechex($val); + if (strlen($i) < 2) + $i = "0" . $i; + $line .= pack('H*', $i); + } elseif ($val >= 128 && $val <= 255) { + $line .= pack('H*', "F9"); + $i = dechex($val); + if (strlen($i) < 2) + $i = "0" . $i; + $line .= pack('H*', $i); + } elseif ($val >= 256 && $val < 65536) { + $line .= pack('H*', "FA"); + $line .= pack('n*', $val); + } else { + $line .= pack('H*', "FB"); + // $line .= pack('I',$val); + $line .= pack('c', $this->shiftRight($val, 24) & 0xFF); + $line .= pack('c', $this->shiftRight($val, 16) & 0xFF); + $line .= pack('c', $this->shiftRight($val, 8) & 0xFF); + $line .= pack('c', $this->shiftRight($val, 0) & 0xFF); + } + } + } + ///// + + if ($ltypes[$currLine][$currLex] == self::String) { + $text = mb_substr($lexems[$currLine][$currLex], 1, mb_strlen($lexems[$currLine][$currLex]) - 2); + if (preg_match('//u', $text)) + $text = iconv("UTF-8", "WINDOWS-1251", $text); + $line .= pack('H*', "FD"); + $line .= $this->writeTEXT($text); + } + + if ($ltypes[$currLine][$currLex] == self::Data) { + $line .= $this->writeTEXT($lexems[$currLine][$currLex]); + } + + if ($ltypes[$currLine][$currLex] == self::Float) { + $line .= pack('H*', "FE"); + + $exp = 0x80; + + $num = doubleval($lexems[$currLine][$currLex]); + if ($num < 1) { + while ($num < 1) { + $num = $num * 10; + $exp--; + } + } else if ($num >= 10) { + while ($num >= 10) { + $num = $num / 10; + $exp++; + } + } + $radix = ($num * 500000); + + $line .= pack('c', $this->shiftRight($radix, 16) & 0xFF); + $line .= pack('c', $this->shiftRight($radix, 8) & 0xFF); + $line .= pack('c', $this->shiftRight($radix, 0) & 0xFF); + $line .= pack("c", $exp); + } + } + + $len = dechex(strlen($line) + 4); + if (mb_strlen($len) < 2) + $len = "0" . $len; + $buf .= pack('H*', $len) . $line . pack('H*', 'FF'); + } + + $this->bufbody = $buf; + $this->compileHead(); + } + + function writeUTF($text) { + $pack = pack('n*', mb_strlen($text)); + + $pack .= pack('a*', $text); + + return $pack; + } + + function writeTEXT($text) { + $len = dechex(strlen($text)); + if (strlen($len) < 2) + $len = "0" . $len; + $pack = pack('H*', $len); + + $pack .= pack('a*', $text); + + return $pack; + } + + function shiftRight($a, $b) { + if (is_numeric($a) && $a < 0) { + return ($a >> $b) + (2 << ~$b); + } else { + return ($a >> $b); + } + } + + function endWith($haystack, $needle) { + $length = strlen($needle); + if ($length == 0) { + return true; + } + return (substr($haystack, -$length) === $needle); + } +} \ No newline at end of file diff --git a/compile.php b/compile.php new file mode 100644 index 0000000..0988ccd --- /dev/null +++ b/compile.php @@ -0,0 +1,32 @@ + + + + + +Сервис для работы с BAS файлами + + + +

Компилятор

+ +Выберите ваш lis файл:
+
+ +'; +} else { + if (is_uploaded_file($_FILES["lis"]["tmp_name"])) { + $namebas = "bas".rand(1000,99999).".bas"; + $bas = new LIS($_FILES['lis']['tmp_name'], './tmp/'.$namebas); + $log = $bas->compile(); + if ($log == '') { + echo 'Файл успешно скомпилирован!
Скачать'; + } + } +} +?> + + diff --git a/decompile.php b/decompile.php new file mode 100644 index 0000000..99a777b --- /dev/null +++ b/decompile.php @@ -0,0 +1,35 @@ + + + + + +Сервис для работы с BAS файлами + + + +

Декомпилятор

+ +Выберите ваш BAS файл:
+
+ +'; +} else { + if (is_uploaded_file($_FILES["bas"]["tmp_name"])) { + $namebas = "bas" . rand(1000, 99999) . ".lis"; + $bas = new BAS($_FILES["bas"]["tmp_name"]); + $log = $bas->decompile(); + if ($log != "-2" && $log != "-1" && $log != "0") { + file_put_contents('tmp/' . $namebas, $log); + echo 'Файл успешно декомпилирован!
Скачать'; + } else { + echo 'Ошибка декомпиляции!'; + } + } +} +?> + + diff --git a/index.php b/index.php new file mode 100644 index 0000000..66301cc --- /dev/null +++ b/index.php @@ -0,0 +1,44 @@ + + + + + +Сервис для работы с BAS файлами + + + + $exp_time) && is_file($unlink)) { + unlink($unlink); + } + } + closedir($dh); +} + +scanDirs('tmp'); +?> + +

Данный сервис поможет вам скомпилировать, декомпилировать и обфусцировать ваши BAS и LIS файлы, а также собрать мидлет

+Компилировать LIS=>BAS
+Декомпилировать BAS в текст
+Обфускация BAS
+Собрать мидлет + +
+
+

Заметка! +
+ссылки на файлы действительны в течении 1-го часа с момента создания +

+ + + + diff --git a/mbstyle/mbs.css b/mbstyle/mbs.css new file mode 100644 index 0000000..1ca77ef --- /dev/null +++ b/mbstyle/mbs.css @@ -0,0 +1,75 @@ +@charset "UTF-8"; + +body{ + color: #fff; + font-size: 12pt; + font-style: Giff Sans, sans-serif; + background-color: #aaa; + +} + +form{ + + color: #bfbfbf; + border-radius: 5px; + margin-bottom: 5px; + border: 1px solid #CCC; + padding: 3px; + background-color: #F0F4F7; + font-size: medium; + +} + +form input[type="file"]{ + + color: #fff; + border-radius: 5px; + margin-bottom: 5px; + border: 1px solid #CCC; + padding: 3px; + background-color: #262626; + font-size: medium; + +} + +form input[type="submit"]{ + padding: 2px 5px; + margin-bottom: 4px; + margin-right: 2px; + border: 1px #0F78DA solid; + background-color: #212121; + border-radius: 2px; + color: white; + box-shadow: 0 0 1px 0 white inset, 0 1px 5px -2px black; + +} + +h2{ + + color: #fff; + font-size: 16pt; + font-style: Giff Sans, sans-serif; + +} + +a:link{ + color: #fff; + font-size: 12pt; + font-style: Teams New Roman, Arial, Tahoma; + +} + +a:visited{ + color: #0000ff; + font-size: 12pt; + font-style: Teams New Roman, Arial, Tahoma; + +} + +a:hover{ + color: #fff; + font-size: 12pt; + font-style: Teams New Roman, Arial, Tahoma; + background: #212121; + +} \ No newline at end of file diff --git a/midlet.php b/midlet.php new file mode 100644 index 0000000..3763eff --- /dev/null +++ b/midlet.php @@ -0,0 +1,38 @@ + + + + + +Сервис для работы с BAS файлами + + + +

Сборщик мидлета

+ +Выберите ваш bas файл:
+
+ +'; +} else { + if (is_uploaded_file($_FILES["bas"]["tmp_name"])) { + $name_bas = $_FILES["bas"]["tmp_name"]; + $name = 'tmp/midlet'.rand(1000,99999).".jar"; + + $jar = new ZipArchive(); + $jar->open($name, ZIPARCHIVE::CREATE); + $jar->addFile("midlet/META-INF/MANIFEST.MF" , "META-INF/MANIFEST.MF"); + $jar->addFile($name_bas, "Autorun.bas"); + $classes = ["Main", "a", "b", "c", "d", "e", "f", "g", "h", "s"]; + foreach ($classes as $cl) { + $class = "$cl.class"; + $jar->addFile("midlet/$class" , $class); + } + $jar->close(); + echo 'Мидлет успешно собран!
Скачать'; + } +} +?> + + diff --git a/obf.php b/obf.php new file mode 100644 index 0000000..a7f1be4 --- /dev/null +++ b/obf.php @@ -0,0 +1,34 @@ + + + + + +Сервис для работы с BAS файлами + + + +

Обфускация

+ +Выберите ваш BAS файл:
+
+ +'; +} else { + if (is_uploaded_file($_FILES['bas']['tmp_name'])) { + $namebas = 'bas_obf' . rand(1000,99999) . '.bas'; + $bas = new BAS($_FILES['bas']['tmp_name']); + $log = $bas->obfuscation('tmp/' . $namebas); + if ($log != '-2' && $log != '-1') { + echo 'Файл успешно обфусцирован!
Скачать'; + } else { + echo 'Ошибка обфскации!'; + } + } +} +?> + +