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 


encodeTable()

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 342

Joined: 09 May 2003
Posts: 20068
Location: The netherlands

PostPosted: Thu Jun 22, 2017 2:43 pm    Post subject: encodeTable() Reply with quote

More a proof of concept.

this code will add the encodeTable() function to CE which you can use to encode your lua scripts.

It currently doesn't encode auto assembler scripts, but I guess you could change aa scripts into {$lua} sections that just return the original aa script as a string. (perhaps add some encryption to it yourself or something)

Code:

function getTableLuaScript()
  local i
  for i=1,getFormCount()-1 do
    local f=getForm(i)
    if (f.ClassName=='TfrmAutoInject') and (f.AssembleScreen.Highlighter.ClassName=='TSynLuaSyn') then
      return f.AssembleScreen.Lines.Text     
    end
  end 
end

function setTableLuaScript(script)
  local i
  for i=1,getFormCount()-1 do
    local f=getForm(i)
    if (f.ClassName=='TfrmAutoInject') and (f.AssembleScreen.Highlighter.ClassName=='TSynLuaSyn') then
      f.AssembleScreen.Lines.Text=script
    end
  end 
end

function encodeLuaScript(script)
  --converts the given script into lua bytecode and returns code you can use to execute it
  local f,err=loadstring(script)
  if f==nil then return script end --fail
 
  return 'decodeFunction("'..encodeFunction(f)..'")()'
end


   

function encodeTable()
  local originalscript=createStringlist() 
  originalscript.Text=getTableLuaScript()
 
  local encodestart=0 
 

 
  if (originalscript.Count>=1) and (originalscript[0]=='--versioncheck--') then
    --find the code after the versioncheck and encode that
    local i
    for i=1,originalscript.Count-1 do
      if originalscript[i]=='--!versioncheck!--' then
        encodestart=i+1
      end
    end
  end


  local toencode=createStringlist()
  while originalscript.Count>encodestart do
    toencode.add(originalscript[encodestart])
    originalscript.delete(encodestart)
  end 
 
  originalscript.add(encodeLuaScript(toencode.text))
 
 
  local versioncheck
 
  if encodestart==0 then
    if cheatEngineIs64Bit() then
      versioncheck=[[--versioncheck--
if cheatEngineIs64Bit()==false messageDialog("This script requires the 64-bit version of Cheat Engine", mtError, mbOK)
closeCE()
return
--!versioncheck!--
  ]]   
    else 
      versioncheck=[[--versioncheck--
if cheatEngineIs64Bit() messageDialog("This script requires the 32-bit version of Cheat Engine", mtError, mbOK)
closeCE()   
return   
--!versioncheck!--
  ]]
    end
   
    originalscript.insert(0,versioncheck)   
  end

 
  setTableLuaScript(originalscript.text)
 
   
  --scan through the memory records for scripts with {$LUA} and encode those blocks as well
  local i
  for i=0, AddressList.Count-1 do 
    if AddressList[i].Type==vtAutoAssembler then
      local oldscript=createStringlist()
      oldscript.Text=AddressList[i].Script
     
      local newscript=createStringlist()
      local tempscript=createStringlist()


      local j
      local inluasection=false
      local currentluascript
      for j=0, oldscript.Count-1 do
        local ln=oldscript[j]:gsub("^%s*(.-)%s*$", "%1")
        local lnl=ln:lower()

        if inluasection==false then
          newscript.add(ln)

          if lnl=='{$lua}' then
            --lua section
            tempscript.clear()
            inluasection=true
          end
        else
          --inside a lua section
          if (lnl=='{$asm}') or --{$asm} statement reached
             (lnl=='[disable]') or --[disable] statement reached
             (lnl=='[enable]') or --[enable] statement reached (for those bastards that put disable before enable)
             (j==oldscript.Count-1) then --end of the script reached
            --encode temp and write it to the new script
            if (j==oldscript.Count-1) then
              tempscript.add(ln)
            end

     
            newscript.add(encodeLuaScript(tempscript.text))
            if (j<oldscript.Count-1) then
              newscript.add(ln)
            end
            inluasection=false
          else
            --add this line to the tempscript
            tempscript.add(ln)
          end
        end

      end

      AddressList[i].Script=newscript.Text
      newscript.destroy()
      oldscript.destroy()
      tempscript.destroy()     
    end
  end
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
OldCheatEngineUser
Whateven rank
Reputation: 4

Joined: 01 Feb 2016
Posts: 584

PostPosted: Thu Jun 22, 2017 2:51 pm    Post subject: Reply with quote

is it for trainers? so no one de-compile your trainer and steal your script?
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 137

Joined: 25 Jan 2006
Posts: 7309
Location: 127.0.0.1

PostPosted: Thu Jun 22, 2017 2:57 pm    Post subject: Reply with quote

OldCheatEngineUser wrote:
is it for trainers? so no one de-compile your trainer and steal your script?


It helps deter newbs from getting things easily, but since the decode function is needed to convert back, it is still fairly easy to get the encoded data back to its original form.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
OldCheatEngineUser
Whateven rank
Reputation: 4

Joined: 01 Feb 2016
Posts: 584

PostPosted: Thu Jun 22, 2017 3:03 pm    Post subject: Reply with quote

atom0s wrote:
It helps deter newbs from getting things easily, but since the decode function is needed to convert back, it is still fairly easy to get the encoded data back to its original form.


isnt possible to protect it with password? for decoding?

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 342

Joined: 09 May 2003
Posts: 20068
Location: The netherlands

PostPosted: Thu Jun 22, 2017 3:13 pm    Post subject: Reply with quote

the decoded data is in lua byteform (no text) , so will take a little more effort (you can not get it back to the original form)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 137

Joined: 25 Jan 2006
Posts: 7309
Location: 127.0.0.1

PostPosted: Thu Jun 22, 2017 3:59 pm    Post subject: Reply with quote

Dark Byte wrote:
the decoded data is in lua byteform (no text) , so will take a little more effort (you can not get it back to the original form)


Decompilers exist for Lua's byte code.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 342

Joined: 09 May 2003
Posts: 20068
Location: The netherlands

PostPosted: Thu Jun 22, 2017 4:09 pm    Post subject: Reply with quote

sure, but comments will be gone, and it's still a bigger hurdle than someone just scanning for the xml header of the table
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Aylin
Newbie cheater
Reputation: 0

Joined: 16 Feb 2017
Posts: 18

PostPosted: Fri Jul 07, 2017 3:59 pm    Post subject: Re: encodeTable() Reply with quote

This coding (Protection) need to adapt with CE please. I'm worried about my labor. I am doing free distribution but I am laboring.
Also should I add this code to the current trainer? Or is it a division of CE?

(My english sucks. Google Translate is insufficient. Sorry)
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 342

Joined: 09 May 2003
Posts: 20068
Location: The netherlands

PostPosted: Fri Jul 07, 2017 5:10 pm    Post subject: Reply with quote

you just run it before you save your table. It only protects lua scripts though, your asm scripts are still text
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Aylin
Newbie cheater
Reputation: 0

Joined: 16 Feb 2017
Posts: 18

PostPosted: Fri Jul 07, 2017 6:57 pm    Post subject: Reply with quote

Dark Byte wrote:
you just run it before you save your table. It only protects lua scripts though, your asm scripts are still text



Suggestion, Complaint and Satisfaction is for Developer.
Please consider this proposal ;
Current experimental stages must be CE code protection software. Rolling Eyes
Thanks for your help.
Back to top
View user's profile Send private message MSN Messenger
sxymac
How do I cheat?
Reputation: 0

Joined: 09 Mar 2016
Posts: 2

PostPosted: Wed Nov 01, 2017 6:01 pm    Post subject: Reply with quote

OldCheatEngineUser wrote:
is it for trainers? so no one de-compile your trainer and steal your script?


You actually dont need to decompile the trainer to see the script, you can do a simple memory browse and see it fully.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 342

Joined: 09 May 2003
Posts: 20068
Location: The netherlands

PostPosted: Wed Nov 01, 2017 6:46 pm    Post subject: Reply with quote

Nope, the script will not be visible in memory
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
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