Note that there are some explanatory texts on larger screens.

plurals
  1. POConversion from C++ to Delphi
    text
    copied!<p>Could someone helps me in porting this C++ function into Delphi?</p> <p><code>sys</code> is a class named <code>TSystem</code>.</p> <p><code>SharedMem</code> is a class named <code>TVirtualMemory</code>.</p> <pre><code>int Process::FixApi(dword FileHandler,image_import_descriptor* Imports,dword dllbase){ image_import_by_name** names; dword* pointers; if (Imports-&gt;original_first_thunk!=0){ names=(image_import_by_name**)Imports-&gt;original_first_thunk; }else{ names=(image_import_by_name**)Imports-&gt;first_thunk; }; names=(image_import_by_name**)((dword)names+FileHandler); pointers=(dword*)(Imports-&gt;first_thunk + FileHandler); if (Imports-&gt;first_thunk==0)return 0; for (int i=0;i&lt;200;i++){ if (names[i]==0)break; if(!((dword)(names[i]-&gt;name+FileHandler) &amp; 0x80000000)){ dword s=(dword)names[i]-&gt;name; dword ptr=sys-&gt;GetAPI((char*)(s+FileHandler),dllbase); dword n=this-&gt;SharedMem-&gt;get_virtual_pointer(ptr); if (n!=0){ ptr=n; } memcpy(&amp;pointers[i],&amp;ptr,4); } }; }; </code></pre> <p>thank you</p> <p>This is my attempt to convert the above code : </p> <pre><code>function FixApi(FileHandler: dword; Imports: Pimage_import_descriptor; dllbase: dword): Integer; var names:^image_import_by_name; pointers:Pdword; i:integer; s,ptr,n:dword; begin if Imports^.original_first_thunk&lt;&gt;0 then names:=Pointer(Imports^.original_first_thunk) else names:=Pointer(Imports^.first_thunk); names:=Pointer(dword(names)+FileHandler); pointers:=Pdword(Imports^.first_thunk+FileHandler); if (Imports^.first_thunk=0)then result:=0; for i:=0 to 200 do begin { // i didn't get it if (names[i]==0)break; if(!((dword)(names[i]-&gt;name+FileHandler) &amp; 0x80000000)){ dword s=(dword)names[i]-&gt;name; } ptr:=sys.GetAPI(PChar(s+FileHandler),dllbase); n:=SharedMem.get_virtual_pointer(ptr); if n&lt;&gt;0 then ptr:=n; CopyMemory(@pointers[i],@ptr,4); end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload