The code below finds all caller adresses in a program to a known 
procedure/function adress.
With this I can get all caller adresses to the translate function.

Moreover - with another piece of code (not shown here) I got also the text 
snippets itself, because they are loaded immediately before executing the 
translate function with MOV textsnippetadr , EAX.

procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : longint ; 
proc_adr : pointer );
const
 call_opcode = $e8;
 caller_adr_pc_offset = 5;
var
 p_reladress : pdword; // call works with a relative adress after the opcode
 x , caller_adress , jmp_adr_abs : dword;
begin
 for x := 1 to count do begin
  if p_opcode^ = call_opcode then begin
   p_reladress := pdword( p_opcode + 1 );                       // after 
opcode = relative adress to procedure/function to call
   caller_adress := dword( p_opcode + caller_adr_pc_offset );
   jmp_adr_abs := caller_adress + p_reladress^;                 // absolute 
adress = programcounter + 5 + relative adress
   if jmp_adr_abs = dword( proc_adr )
    then add_caller_adress_to_table( caller_adress );           // if call 
proc_adr then found!
  end;
  inc( p_opcode );
 end;
end;
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to