0

I decompiled a lua file with unluac and it turns out all the string variables are not readable and are instead ascii encoded

clues = {
  {
    answer = {
      "\216\173",
      "\216\177",
      "\216\168",
      "\216\167",
      "\216\161"
    },
    text = "\216\173\217\138\217\136\216\167\217\134\032\216\178\216\167\216\173\217\129\032\217\138\216\186\217\138\216\177\032\217\132\217\136\217\134\032\216\172\217\132\216\175\217\135",
    syllables = {
      {"\216\173", "\216\177"},
      {"\216\168", "\216\167"},
      {"\216\161"}
    }

How do i go about decoding the whole file ignoring any non ascii characters in python or java?

  • Please note that this may not be ACII encoding due to the value ranges (ascii ranges from 0 to 127). It may be UTF-8 (although the resulting text does not make sense to me) or a custom enconding scheme. Got any code using these strings? – Nordwald Apr 3 '17 at 6:19
  • The strings are in Arabic. I was able to decode each individual string value using this tool www.unit-conversion.info/texttools/ascii/ The string at line 10 =" حيوان زاحف يغير لون جلده ". the file i decompiled is 15k lines, and impossible to do that manually, so i wondered how i could achieve that – Rafat Refai Apr 3 '17 at 9:45
1

How do i go about decoding the whole file ignoring any non ascii characters in python or java?

did you consider replacing the symbols? You can use a regex as simple as that one:

\\\d{3}

To find all values to replace. For example, this does the trick in python:

text = r"""clues = {
  {
    answer = {
      "\216\173",
      "\216\177",
      "\216\168",
      "\216\167",
      "\216\161"
    },
    text = "\216\173\217\138\217\136\216\167\217\134\032\216\178\216\167\216\173\217\129\032\217\138\216\186\217\138\216\177\032\217\132\217\136\217\134\032\216\172\217\132\216\175\217\135",
    syllables = {
      {"\216\173", "\216\177"},
      {"\216\168", "\216\167"},
      {"\216\161"}
  }"""
import re

def decode(match):
    code = int(match.group(1))
    return chr(code)

print re.sub(r'\\(\d{3})', decode, text)

Also, please note that this is Extended ASCII and not ASCII per se.

  • Just tried it. It didn't output arabic text. Guess the encoding is not right? Output --> ホ{マ8マ^ホwマ\ホ8ホwホ{マ 9マ8ホ86マ8ホマZマ^マ\ホzマZホ}マ] expected output --> حيوان زاحف يغير لون جلده – Rafat Refai Apr 3 '17 at 17:25
  • It works (text = "حيوان زاحف يغير لون جلده"). Please be sure to treat the text you are reading as a raw string so python doesn't try to interpret the backslashes as escape sequences. Adapted my answer – Nordwald Apr 4 '17 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.