AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Conversion from Cpp to Delphi

Ein Thema von sdean · begonnen am 27. Dez 2011 · letzter Beitrag vom 27. Dez 2011
Antwort Antwort
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#1

Conversion from Cpp to Delphi

  Alt 27. Dez 2011, 03:08
Can someone helps me in converting these two CPP functions into Delphi :
Code:
 bool StrSearch(byte* mem,char* text,DWORD size){
       byte* pchL=mem;
       DWORD offset=(DWORD)pchL;
       DWORD length=offset+size;
       int s=strlen(text);
       while(offset<length){
          if (!strnicmp((PCSTR)pchL, (PCSTR)text, s)){
             return true;
          }
          offset++;
          pch++;
       }
       return false;
    }
Code:
int PEFILE::GetPESectionIndex(char* SectionName){
       int j;
       int n=image_nt_headers->FileHeader.NumberOfSections;
       for(j=0;j<n;j++){
          if(!strcmp((const char*)image_section_header[j]->Name,SectionName)) return j;
       }
       return -1;
    }

many thanks
  Mit Zitat antworten Zitat
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#2

AW: Conversion from Cpp to Delphi

  Alt 27. Dez 2011, 14:59
for the 1st function is did this :

Delphi-Quellcode:
function StrSearch(mem: pbyte;text: pchar; size: DWORD):Boolean;
    var
    pchL: pbyte;
    offset: DWORD;
    length: DWORD;
    iMax: integer;
    begin
      pchL:=mem;
      offset:=DWORD(pchL);
      length:=offset+size;
      iMax:=lstrlen(text);
      while(offset<length) do
      begin
              if StrLIComp(PChar(pchL),PChar(text),iMax)=0 then
              begin
                 result:= true;
                 Break;
               end;
               inc(offset);
              inc(pchL);
            end;
           result:= false;
    end;
is that correct ?
  Mit Zitat antworten Zitat
Benutzerbild von implementation
implementation

Registriert seit: 5. Mai 2008
940 Beiträge
 
FreePascal / Lazarus
 
#3

AW: Conversion from Cpp to Delphi

  Alt 27. Dez 2011, 15:32
is that correct ?
Not at all:

Delphi-Quellcode:
function StrSearch(mem: pbyte;text: pchar; size: DWORD):Boolean;
var
  pchL: pbyte;
  offset: DWORD;
  length: DWORD;
  iMax: integer;
begin
  pchL := mem;
  offset := DWORD(pchL);
  length := offset + size;
  iMax := lstrlen(text);
  while offset < length do
  begin
    if StrLIComp(PChar(pchL),PChar(text),iMax)=0 then
    begin
      result:= true; // Here you set Result := True
      Break; // .. and then jump out of the loop ...
    end;
    inc(offset);
    inc(pchL);
  end;
  // ... to here!
  result:= false; // and set Result := False
end;
So your function will always return false.
Replace "break" by "exit" and it should work.
  Mit Zitat antworten Zitat
Benutzerbild von implementation
implementation

Registriert seit: 5. Mai 2008
940 Beiträge
 
FreePascal / Lazarus
 
#4

AW: Conversion from Cpp to Delphi

  Alt 27. Dez 2011, 15:39
Code:
int PEFILE::GetPESectionIndex(char* SectionName){
       int j;
       int n=image_nt_headers->FileHeader.NumberOfSections;
       for(j=0;j<n;j++){
          if(!strcmp((const char*)image_section_header[j]->Name,SectionName)) return j;
       }
       return -1;
    }
I'll try it:
Delphi-Quellcode:
function TPEFile.GetPESectionIndex(SectionName: PChar): Integer;
var j,n: Integer;
begin
  n := image_nt_headers.FileHeader.NumberOfSections;
  for j := 0 to n-1 do
    if StrLIComp(PChar(image_section_header[j].Name),SectionName)=0 then
    begin
      Result := j;
      exit;
    end;
  Result := -1;
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz