Перейти к содержанию

Как создать свою строку в контекстном меню в дизассемблере


MasterGH

Рекомендуемые сообщения

post-3-1312440160,15_thumb.png

Ссылка на оригинал темы.

Код Lua:


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)
function selectiontracker(disassemblerview, address, address2) 

Ещё пример (чем эти примеры отличаются, смотрите сами код):


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
local __menu_inject_timer = createTimer( getMainForm(), true ); 

Ссылка на комментарий
Поделиться на другие сайты

×
×
  • Создать...

Важная информация

Находясь на нашем сайте, Вы автоматически соглашаетесь соблюдать наши Условия использования.