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 


Get AOB from selected instructions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Aug 03, 2011 3:31 pm    Post subject: Get AOB from selected instructions Reply with quote

The following code will add a menu item and keyboard shortcut (ctrl+shift+c) to the disassembler which will show you the array of byte string of the selected instruction(s) in a memo field you can copy from

It makes use of a selection tracker because getSelectedAddress does not return both addresses in 6.1 (6.2 will)

And it also makes use of the readBytes function with the use of tables which is new in 6.1 (writeBytes with the help of a table is sadly broken)

suggestion: Improve the getAOB function

Code:

function selectiontracker(disassemblerview, address, address2)
  dv_address1=address
  dv_address2=address2
end

mv=getMemoryViewForm()
dv=memoryview_getDisassemblerView(mv)

dv_address1=disassemblerview_getSelectedAddress(mv)
dv_address2=dv_address1

disassemblerview_onSelectionChange(dv, selectiontracker)



function getAOB(address, length)
--[[
suggestion: Extend this script so it watches the disassembled code for a 8 digit
hexadecimal string whose value is bigger than 0x2000
Then locate the bytes that define that value and replace by wildcards
--]]

  local bytestring={}
  local str=''
  bytestring=readBytes(address, length, true) --get the bytes


  for i=0, length-1 do
    str=str..string.format('%x ',bytestring[i])
  end

  return str
end

-----

function aobclose(sender)
  return caHide
end

function onGetAOBMenuClick(sender)
  local start=math.min(dv_address1, dv_address2)
  local stop=math.max(dv_address1, dv_address2);
  stop=stop+getInstructionSize(stop)

  local length=stop-start

  local s=getAOB(start, length)

  --spawn a form with memo so the user can easy copy/paste (6.2 will have writeToClipboard)
  if (aobwindow==nil) then
    aobwindow=createForm()
    control_setCaption(aobwindow, 'AOB')
    form_centerScreen(aobwindow)
    form_onClose(aobwindow, aobclose)
    aobmemo=createMemo(aobwindow)
    control_setAlign(aobmemo, alClient)
  else
    form_show(aobwindow)
   
  end


  local l=memo_getLines(aobmemo)
  --  strings_setText(l, s)  , yet another function that didn't get tested in 6.1

  strings_clear(l)
  strings_add(l, s)

end

--and now add the menu item to the disassembler
popupmenu=control_getPopupMenu(dv)
mi=createMenuItem(popupmenu)
menuItem_setCaption(mi, 'Get AOB from selection')
menuItem_onClick(mi, onGetAOBMenuClick)
menuItem_setShortcut(mi, 'Ctrl+Shift+C');

menuItem_add(menu_getItems(popupmenu), mi)


_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Wed Aug 03, 2011 4:35 pm    Post subject: This post has 1 review(s) Reply with quote

Here is a temp solution for CE6.2 alpha to add it via the autorun folder. Since the memory view isn't loaded until after the Lua engine first executes you will get access violations.

This also removes the form creation and just prints the string to the Lua engine window instead.

Code:

local __menu_inject_timer = createTimer( getMainForm(), true );
timer_setInterval( __menu_inject_timer, 1000 );
timer_onTimer( __menu_inject_timer, function( sender )
    local memView = getMemoryViewForm();
    if( memView == nil or memView == 0 ) then
        return;
    end
   
    local dasmView = memoryview_getDisassemblerView( memView );
    if( dasmView == nil or dasmView == 0 ) then
        return;
    end
   
    local popupMenu = control_getPopupMenu( dasmView );
    if( popupMenu == nil or popupMenu == 0 ) then
        return;
    end

    local menuItems = menu_getItems( popupMenu );
    for pos = 0, menuItem_getCount( menuItems ) - 1 do
        local caption = menuItem_getCaption( menuItem_getItem( menuItems, pos ) );
        if( caption == 'Get AOB From Selection' ) then
            return;
        end
    end

    local menuItem = createMenuItem( popupMenu );
    menuItem_setCaption( menuItem, 'Get AOB From Selection' );
    menuItem_setShortcut( menuItem, 'Ctrl+Shift+C' );
    menuItem_onClick( menuItem, onGetAOBMenuClicked );
    menuItem_add( menuItems, menuItem ); 
   
    __dasm_address1 = disassemblerview_getSelectedAddress( memView );
    __dasm_address2 = __dasm_address1;
   
    disassemblerview_onSelectionChange( dasmView, dasmSelectionTracker );
   
    object_destroy( __menu_inject_timer );
end );

function dasmSelectionTracker( disassemblerview, address, address2 )
    __dasm_address1 = address;
    __dasm_address2 = address2;
end

function getAOB( address, length )
    local bytestring = { };
    local output = '';
   
    local readData = readBytes( address, length, true );
   
    for x = 0, length - 1 do
        output = output .. string.format( '%02X', readData[ x ] );
        if x ~= length - 1 then output = output .. ' '; end
    end
   
    return output;
end

function onGetAOBMenuClicked( sender )
    local start = math.min( __dasm_address1, __dasm_address2 );
    local stop  = math.max( __dasm_address1, __dasm_address2 );
   
    stop = stop + getInstructionSize( stop );
   
    local length    = stop - start;
    local data      = getAOB( start, length );
   
    print( data );
end


Thanks for the temp fix DB. I edited the variables a little in case people try to use similar ones in their scripts since they are globals this way.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Wed Aug 10, 2011 2:56 am    Post subject: Reply with quote

Nice, this is very handy indeed!
Back to top
View user's profile Send private message
ablonevn
Advanced Cheater
Reputation: 1

Joined: 02 Oct 2011
Posts: 59

PostPosted: Sun Jan 13, 2013 9:36 am    Post subject: Reply with quote

It's almost one year passed from you write this script, i remember i'm ask db something about this and you, write it in one minute Very Happy, and now i can coding one, share it to new user to lua too.

installion: unrar file in to <cheatengine_install_dir>\autorun
description: it will add an item named "AOB Indentify Scan" in the search menu of memory viewer, and automatic find unique suit aob pattern.

Download:
Code:

http://www.uploadmb.com/dw.php?id=1358090361


PS: i dont know what is look like in 64 bit, so i let you manual edit some byte and update it. if you want "perfect" automatic then find code access to "bytes" string which i'm adding it to listview & do replace all parts have greater or equal 4 bytes continous with "****".
happy Lua coding Very Happy
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 Tutorials -> LUA Tutorials 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 cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites