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 


Cheat Engine Forum Index
PostGo back to topic
GH*master
Expert Cheater
Reputation: 8
Joined: 10 Jan 2008
Posts: 159

PostPosted: Thu Oct 04, 2012 3:47 am    Post subject: Generate AA-code from templates (extension for CE)

Simple generate AA-code from templates (extension for CE)

1) You can fast generate AA-code

2) You can modify the templates

AACodeTemplate
AND
AOBSCANCodeTemplate

3) Go to Disassembler window, selected some instructions and you can see new commands in popup menu

4) Also you can input hotkeys (to see "popup menu-> item name-> [hot-keys]")

Code:
--[[
Version 1.1
CE 6.2
]]--
scriptCount = 0

AACodeTemplate = [[
[ENABLE]
alloc(newMem, 2048)
label(returnHere)

newMem:
->>cheatCode
->>originalCode
jmp returnHere

->>address:
jmp newMem
->>nops
returnHere:

[DISABLE]
->>address:
->>originalCode

dealloc(newMem)
]]

AOBSCANCodeTemplate = [[
[ENABLE]
AOBSCAN(signatureAddress, ->>arrayOfbyte)
alloc(newMem, 2048)
label(returnHere)
label(address->>NscriptCount)
registersymbol(address->>NscriptCount)

newMem:
->>cheatCode
->>originalCode
jmp returnHere

signatureAddress:  //->>comment
address->>NscriptCount:
jmp newMem
->>nops
returnHere:

[DISABLE]
address->>NscriptCount:
->>originalCode

dealloc(newMem)
unregistersymbol(address->>NscriptCount)
]]

-------------------------
function GetInfoInjection(strAddress)   -- return adressReturnHere, originalCodeString, nopsString
   local sumBytes = 0
   local originalCodeString = ""
   local adressReturnHere = strAddress
   
   local countBytes = 0
   local isFirst = true
   repeat
      countBytes = getInstructionSize(adressReturnHere)
      lineDissassemble = disassemble(adressReturnHere)
      extrafield, opcode, bytes, adressReturnHere = splitDisassembledString(lineDissassemble)
      
      sumBytes = sumBytes + countBytes
      --adressReturnHere = string.format("%x", ("0x"..adressReturnHere) + countBytes)
      adressReturnHere = adressReturnHere..'+'..countBytes
      
      if sumBytes == 5 or isFirst then
         isFirst = false
         originalCodeString = originalCodeString..opcode
      else
         originalCodeString = originalCodeString.."\r\n"..opcode
      end
   until (sumBytes >= 5)
   
   local nopsString = ""
   local nopsCount = sumBytes - 5
   if (nopsCount>0) then
       for i = 1, nopsCount do
         if i == nopsCount then
            nopsString = nopsString.."nop"
         else
            nopsString = nopsString.."nop\r\n"
         end
       end
   end
   
   return adressReturnHere, originalCodeString, nopsString
end
function GetFullSignature(startAddress, length) -- return full signature
   local bytestring = {}
   
   bytestring = readBytes(startAddress, length, true)
   
   local str=''
   for i=1, length do
      str=str..string.format('%02X ', bytestring[i])
   end

   return str
end
-------------------------
function GetScriptAA(strAddress)

   local script = AACodeTemplate
   local cheatCode = ""   
   local originalCode = ''
   local nops = ''
   local adressReturnHere = 0
   
   adressReturnHere, originalCode, nops = GetInfoInjection(strAddress)

   script = string.gsub(script,"->>cheatCode", cheatCode)
   script = string.gsub(script,"->>originalCode", originalCode)

   local baseAddress = getNameFromAddress(strAddress)
   script = string.gsub(script,"->>address", baseAddress)

   if nops=='' then
      script = string.gsub(script,"->>nops\n", nops) --\r\n
   else
      script = string.gsub(script,"->>nops", nops)
   end
   
   script = string.gsub(script,"->>NscriptCount", scriptCount)   
   
   return script
end

function GetScriptAOBSCAN()

   local address = math.min(dv_address1, dv_address2)
   
   
   local stop = math.max(dv_address1, dv_address2)
   local length = stop + getInstructionSize(stop) - address
   
   if length <= 5  then
      print('Sorry. You must selected more 5 bytes')
      return
   end
   
   local strSignature = GetFullSignature(address, length)
   local result = AOBScan(strSignature, "+X-C-W")
   local count = -1
   
   local rez = result ~= nil
   if rez then
      count = strings_getCount(result)
      object_destroy(result)
      rez = count == 1
   end
            
   if not rez then
     return
   end
   
   local strAddress = getNameFromAddress(address)
   local script = AOBSCANCodeTemplate
   local cheatCode = ""   
   local originalCode = ''
   local nops = ''
   local adressReturnHere = 0
   
   adressReturnHere, originalCode, nops = GetInfoInjection(strAddress)
   
   script = string.gsub(script,"->>arrayOfbyte", strSignature)
   script = string.gsub(script,"->>cheatCode", cheatCode)
   script = string.gsub(script,"->>originalCode", originalCode)

   local comment = string.format('%08x = %s', address, getNameFromAddress(strAddress))
   script = string.gsub(script,"->>comment", comment)  --// 00ADFCFD = GameDLL_x86.dll+50FCFD

   if nops=='' then
      script = string.gsub(script,"->>nops\n", nops) --\r\n
   else
      script = string.gsub(script,"->>nops", nops)
   end
   
   script = string.gsub(script,"->>NscriptCount", scriptCount)   
   return script
end

------------------------------------------------------
function AddAARecord(script, sciptName)
   local addresslist = getAddressList()
   newTableEntry = addresslist_createMemoryRecord(addresslist)
   memoryrecord_setDescription(newTableEntry, sciptName)
   memoryrecord_setType(newTableEntry, vtAutoAssembler)
   memoryrecord_setScript(newTableEntry, script)   
   
   scriptCount = scriptCount + 1
   return newTableEntry
end
function OpenAAEditor(newTableEntry)
   ---???
end
-------Add Item Menu in Disassembler------------------
function OnSelectionTracker(disassemblerview, address, address2)
   dv_address1=address
   dv_address2=address2
end
function AddItemMenuInMemoryViewForm(nameItemMenu, shortcut, functionItemClick, functionSelectiontracker)

   local mv = getMemoryViewForm()
   local dv = memoryview_getDisassemblerView(mv)
   disassemblerview_onSelectionChange(dv, functionSelectiontracker)

   dv_address1 = disassemblerview_getSelectedAddress(mv)
   dv_address2 = dv_address1

   popupmenu = control_getPopupMenu(dv)
   mi = createMenuItem(popupmenu)
   menuItem_setCaption(mi, nameItemMenu)
   
   menuItem_onClick(mi, functionItemClick)
   menuItem_setShortcut(mi, shortcut)

   menuItem_add(menu_getItems(popupmenu), mi)
end
function AddItemMenuSeparatorInMemoryViewForm()
   local mv = getMemoryViewForm()
   local dv = memoryview_getDisassemblerView(mv)
   disassemblerview_onSelectionChange(dv, functionSelectiontracker)
   popupmenu = control_getPopupMenu(dv)
   mi = createMenuItem(popupmenu)
   menuItem_setCaption(mi, '-')
   menuItem_add(menu_getItems(popupmenu), mi)
end

function OnItemMenuGenerateAAClick(sender)
  local strAddress = getNameFromAddress(dv_address1) -- string.format("%x",address)
  local script = GetScriptAA(strAddress)
  local newTableEntry = AddAARecord(script,'New Script')
  OpenAAEditor(newTableEntry)
end
function OnItemMenuGetSignatureInfoClick(sender)
   print('--START--')
   local address = math.min(dv_address1, dv_address2)
   print('Address: '..getNameFromAddress(address)..' or '.. string.format('%08x', address))
   
   a2 = getPreviousOpcode(address)
   a1 = getPreviousOpcode(a2)
   a4 = address + getInstructionSize(address)
   a5 = a4 + getInstructionSize(a4)
   print('')
   print('Original view code:')
   print('   ' .. disassemble(a1))
   print('   ' .. disassemble(a2))
   print('   ' .. disassemble(address) .. '<<<')
   print('   ' .. disassemble(a4))
   print('   ' .. disassemble(a5))
   print('')
   
   local stop = math.max(dv_address1, dv_address2)
   local length = stop + getInstructionSize(stop) - address
   
   if length <= 5  then
      print('Sorry. You must selected more 5 bytes')
      return
   end
   
   local strSignature = GetFullSignature(address, length)

   print('Start  AOBScan with '.. strSignature..', with typeMem "+X-C-W"')
   
   local result = AOBScan(strSignature, "+X-C-W")
   local count = -1
   
   if result == nil then
      print('   ' ..'Sorry. Attention, not find signature by protection "+X-C-W"! Check it out yourself! :(')
   else
      count = strings_getCount(result)
      object_destroy(result)
      print('')
      if (count == 1) then
         print('   ' ..'Signature is unique. Yes, is good! :) ')
      else
         print('   ' ..string.format('Sorry. Signature is not unique. :( Founded address by protection  "+X-C-W" = %s', count))
      end
      print('')
   end
            
   print('Thank you for using this lua-plagin, GameHackLab[RU], 2009-2012(C)')      
   print('--END--')
end
function OnItemMenuGenerateAAWithAOBSCANClick(sender)
  local script = GetScriptAOBSCAN()
  local newTableEntry = AddAARecord(script, 'New AOBSCAN-Script ')
  OpenAAEditor(newTableEntry)
end
-----------------------------------------------------
AddItemMenuSeparatorInMemoryViewForm()
AddItemMenuInMemoryViewForm('* Create AA', 'Ctrl+Shift+A', OnItemMenuGenerateAAClick, OnSelectionTracker)
AddItemMenuInMemoryViewForm('* Create AA-aobsan', 'Ctrl+Shift+B', OnItemMenuGenerateAAWithAOBSCANClick, OnSelectionTracker)
AddItemMenuInMemoryViewForm('* Get signature info', 'Ctrl+Shift+I', OnItemMenuGetSignatureInfoClick, OnSelectionTracker)
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
justa_dude
Review: Approve
Post reference:
ReviewPosted: Sat Nov 30, 2013 8:18 am

This looks like good work. Well done and thanks for sharing.
Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites