Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Handle lomg string in lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Nov 25, 2015 10:20 pm    Post subject: Handle lomg string in lua Reply with quote

Hi there,

i try to handle long string with lua :

Code:

text = [[
f = createForm(false)
control_setSize(f, 170, 180)
control_setCaption(f,"Test")
f.show()

b = createButton(f)
control_setPosition(b, 45, 65)
control_setCaption(b, "Go..!!")

function test()
showMessage("Button has clicked")
end

control_onClick(b, test)
]]


code above will identifying as a string without problem / error.

Now, how i can handle long string syntax in lua if the text also contains "[" , "[[", "]" or "]]" ?

other example :
Code:

text = [[ function setHack()
  t =
  {
{'Hack 1',
[[LuaCall(Aobswap("a3 ad 68 95 9a 01 47 47","a3 ad 68 a0 9a 01 47 47"))]],
[[Hack 1]]},

{'Hack 2',
[[LuaCall(Aobswap("27 26 2b 63 04 63 05 5d 90 7f d1 d2 d3 46 90 7f 03 48 47","27 26 2b 63 04 63 05 5d 90 7f d1 d2 d3 2f e9 01 2a 48 47"))]],
[[Hack 2]]},
[[]]}
}
end
]]


it give error "Script Error:[string "text = [[..."]:6: nesting of [[...]] is deprecated near '['" because of bracket used.

Is there any other way to handling long string syntax in lua ?. I have tried to googling it but no match found.

Thank in advance

regard's
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Wed Nov 25, 2015 10:25 pm    Post subject: Reply with quote

Try use
[=[
]=]
,
[==[
]==]
etc.

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Nov 26, 2015 2:33 am    Post subject: Reply with quote

Thank you so much Panraven, for helping

All work properly now with [=[ text ]=] for handling long string.
Actually I am use it to try load encoded script has store in CE stream and use decoding script first and then use loadstring to execute the script.

Example (text without [=[..... ]=]) (i have other tested with text contain [[ and ]], and it work properly too.
Code:

contain of file "dec_code.lua"
function mycode()
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

-- decoding
function dec(data)
    data = string.gsub(data, '[^'..b..'=]', '')
    return (data:gsub('.', function(x)
        if (x == '=') then return '' end
        local r,f='',(b:find(x)-1)
        for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
        return r;
    end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
        if (#x ~= 8) then return '' end
        local c=0
        for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
        return string.char(c)
    end))
end

enctext = "ZiA9IGNyZWF0ZUZvcm0oZmFsc2UpCmNvbnRyb2xfc2V0U2l6ZShmLCAxNzAsIDE4MCkKY29udHJvbF9zZXRDYXB0aW9uKGYsIlRlc3QiKQpmLnNob3coKQoKYiA9IGNyZWF0ZUJ1dHRvbihmKQpjb250cm9sX3NldFBvc2l0aW9uKGIsIDQ1LCA2NSkKY29udHJvbF9zZXRDYXB0aW9uKGIsICJHby4uISEiKQoKZnVuY3Rpb24gdGVzdCgpCnNob3dNZXNzYWdlKCJCdXR0b24gaGFzIGNsaWNrZWQiKQplbmQKCmNvbnRyb2xfb25DbGljayhiLCB0ZXN0KQo="
dectext = dec(enctext) -- decoding / get text back

end
--
--  next in CE Table will put this script
--
------ Avoid Lua Engine Pop-up
getLuaEngine().cbShowOnPrint.Checked=false
getLuaEngine().hide()

----- Call Code
function loadTableCode(n2)
 local t2 = findTableFile(n2)
 if t2 ~= nil then
 local s2 = t2.Stream
 local c2 = readStringLocal(s2.Memory,s2.Size)
 return c2 ~= nil and loadstring(c2) -- return a function
 end
end
--
local f2 = loadTableCode('dec_code.lua')
print(type(f2))
if type(f2) == 'function' then f2() else print('not loaded') end

---- Run the function
mycode()
a = tostring(dectext)

-- Defining a string to use as function later
-- funcStr = "print('test')"
funcStr = a
-- loadstring(funcStr)()
func = loadstring(funcStr)
func()



Point of this trying is to executing encoded script (to make it harder for leecher to get code). I am use Base64 encode and i think it also will work with base85, SHA1, or self encode decode function.

Regard's
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Thu Nov 26, 2015 10:04 am    Post subject: Reply with quote

Corroder wrote:
Point of this trying is to executing encoded script (to make it harder for leecher to get code). I am use Base64 encode and i think it also will work with base85, SHA1, or self encode decode function.


Please, please don't use base64 if you're trying to encrypt stuff. It's very easy to decode; there are tons of web applets online that will do it for you. Seriously. Just paste that encoded string into this and it'll show you everything.

Base64 isn't going to stop anyone who is interested enough to try to get your code. If you want to actually stop people, make your own encryption. But even then, if you have all the code to decode that string right in front of people, they're going to use that to decode the string and get your code.

If you actually want to protect your code, write it in another language (e.g. C++). See this topic for more information about protecting your code.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Nov 26, 2015 7:54 pm    Post subject: Reply with quote

ParkourPenguin thank you to tell

Of course base64 is easy to break and take code back. In my topic, actually it's about load decoded script from stream with a function loadstring. I just to test the method is possible to do.

Reverse engineering is a knowledge to get back code or script (strings) from compiled file / program. I think all compiled programs / applications able to decompile with reverse engineering knowledge. Anyhow, we just make it harder to break off the codes.

Also there are many other method for encoding, obfuscating, compiling, etc that i can use to encoding codes / scripts or use some tool like themida to protect exe file, etc...

example : a simple own decoding function adapted form VB to Lua.

Code:

function enc_textcode(s)
  local coded = ""
  for i=1,#s do
    coded = coded .. string.char(s:byte(i) + 3)
  end
  return coded
end

--- test
a = enc_textcode("Virus Installed")
print(a)
Yluxv#Lqvwdoohg


or another method by Zanzer
Code:

n={7946918697735711062,2406159617271886963}
t=''
for i=1,2 do
q=qwordToByteTable(n[i])
for j=1,8 do
t=t..string.char(q[j])
end
end
print(t)
==
Virus Installed!


other with RSA :
Code:

function rsa_getkey()
  rsa_e = 0
  local primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 57, 71, 73, 79, 83, 89, 97}

  math.randomseed = os.time()

  rsa_p = primes[math.random(5,#primes)]
  rsa_q = rsa_p

  while rsa_q == rsa_p do
      math.randomseed = os.time()
      rsa_q = primes[math.random(5,#primes)]
  end

  rsa_n = rsa_p*rsa_q
  rsa_phi = (rsa_p-1)*(rsa_q-1)

  while rsa_e == 0 do
      local prime = primes[math.random(1,10)]
      if rsa_phi%prime > 0 then
          rsa_e = prime
      end
  end

  for i = 2, rsa_phi/2 do
      if ((i*rsa_phi)+1)%rsa_e == 0 then
          rsa_d = ((i*rsa_phi)+1)/rsa_e
          break
      end
  end
  return "p: ",rsa_p,"\nq: ",rsa_q,"\nn: ",rsa_n,"\ne: ",rsa_e,"\nd: ",rsa_d,"\nphi: ",rsa_phi,"\n"
end


and many more eq. Ascii85, SHA 256, Base32,etc

regard's
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites