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 


Runtime error on memoryfix.....

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
yoyoyip
Cheater
Reputation: 0

Joined: 09 Apr 2006
Posts: 29

PostPosted: Mon Aug 28, 2006 10:16 am    Post subject: Runtime error on memoryfix..... Reply with quote

Hi,

I encountered an runtime error in Borland Developer Studio 2006 after using DB memoryfix.

It seems to me that Assemblerunit can't assemble instruction with segment override, e.g. mov eax,fs:[00000124], the exception was raised at the function symbikhandler.TSymHandler.getAddressFromName('FS:', True)

The call stack is shown below:

symbolhandler.TSymHandler.getAddressFromName('FS:', True)
symbolhandler.TSymHandler.getAddressFromName('FS:')
Assemblerunit.rewrite('FS:[00000124]')
Assemblerunit.tokenize('MOV EAX,FS:[00000124]',('MOV','EAX','FS:[00000124]'))
Assemblerunit.Assemble('mov eax,fs:[00000124]',0,(87))
.
.
.


I have copied the two functions from Assemblerunit.pas, rewrite and tokenize.

Code:

function rewrite(var token:string): boolean;
var i,j,k,err,err2: integer;
    a,b: dword;
    tokens: array of string;
    last: integer;

    symbol: PImagehlpSymbol;
    disp: dword;

    temp: string;

begin
  setlength(tokens,0);
  result:=false;
  last:=-1;

  temp:='';
  i:=1;
  while i<=length(token) do
  begin
    if token[i] in ['[',']','+','-'] then
    begin
      if temp<>'' then
      begin
        setlength(tokens,length(tokens)+1);
        tokens[length(tokens)-1]:=temp;
        temp:='';
      end;
      setlength(tokens,length(tokens)+1);
      tokens[length(tokens)-1]:=token[i];
      inc(i);
      continue;
    end;
    temp:=temp+token[i];
    inc(i);
  end;

  if temp<>'' then
  begin
    setlength(tokens,length(tokens)+1);
    tokens[length(tokens)-1]:=temp;
    temp:='';
  end;

  getmem(symbol,sizeof(_Imagehlp_symbol)+200);
  try
    for i:=0 to length(tokens)-1 do
    begin
      if (length(tokens[i])>1) or (not (tokens[i][1] in ['[',']','+','-','*'])) then
      begin
        val('$'+tokens[i],j,err);
        if (err<>0) and (getreg(tokens[i],false)=9) then
        begin
          symbol.SizeOfStruct:=sizeof(_Imagehlp_symbol)+200;
          symbol.MaxNameLength:=200;

          disp:=0;

          try
            tokens[i]:=inttohex(symhandler.getaddressfromname(tokens[i]),8);    <<<<<<<<<<<<<< Exception was raised here
          except

          end;

        end;
      end;
    end;
  finally
    freemem(symbol);
  end;

  //do some calculations

  //check multiply first
  for i:=1 to length(tokens)-2 do
  begin
    if tokens[i]='*' then
    begin
      val('$'+tokens[i-1],a,err);
      val('$'+tokens[i+1],b,err2);
      if (err=0) and (err2=0) then
      begin
        a:=a*b;
        tokens[i-1]:=inttohex(a,8);
        tokens[i]:='';
        tokens[i+1]:='';
      end;
    end;
  end;

  for i:=1 to length(tokens)-2 do
  begin
    val('$'+tokens[i-1],a,err);
    val('$'+tokens[i+1],b,err2);
    if (err=0) and (err2=0) then
    begin
      case tokens[i][1] of
        '+':
        begin
          a:=a+b;
          tokens[i-1]:=inttohex(a,8);
          tokens[i]:='';
          tokens[i+1]:='';
        end;

        '-':
        begin
          a:=a-b;
          tokens[i-1]:=inttohex(a,8);
          tokens[i]:='';
          tokens[i+1]:='';
        end;
      end;
    end;
  end;


  token:='';
  for i:=0 to length(tokens)-1 do
    token:=token+tokens[i];

  setlength(tokens,0);
  result:=true;
end;

function tokenize(opcode:string; var tokens: ttokens): boolean;
var i,j,last: integer;
    spacecount: integer;
    seperatorcount: integer;

    firstquote: boolean;

begin
  setlength(tokens,0);

  while (length(opcode)>0) and ((opcode[length(opcode)]=' ') or (opcode[length(opcode)]=',')) do
    opcode:=copy(opcode,1,length(opcode)-1);

  last:=1;
  firstquote:=false;
  for i:=1 to length(opcode) do
  begin
    if (i=length(opcode)) or (opcode[i]=' ') or (opcode[i]=',') or (opcode[i]='''') then
    begin
      if not firstquote then
      begin
        setlength(tokens,length(tokens)+1);
        if i=length(opcode) then
          tokens[length(tokens)-1]:=copy(opcode,last,i-last+1)
        else
          tokens[length(tokens)-1]:=copy(opcode,last,i-last);

        if (length(tokens)>1) then
        begin
          //Rewrite
          rewrite(tokens[length(tokens)-1]);             <<<<<<<< Error rewrite('FS:[00000124]')
        end;

        if (tokens[length(tokens)-1]='TBYTE')
        or (tokens[length(tokens)-1]='DQWORD')
        or (tokens[length(tokens)-1]='QWORD')
        or (tokens[length(tokens)-1]='DWORD')
        or (tokens[length(tokens)-1]='WORD')
        or (tokens[length(tokens)-1]='BYTE')
        or (tokens[length(tokens)-1]='DQWORD PTR')
        or (tokens[length(tokens)-1]='TBYTE PTR')
        or (tokens[length(tokens)-1]='TWORD PTR')
        or (tokens[length(tokens)-1]='QWORD PTR')
        or (tokens[length(tokens)-1]='DWORD PTR')
        or (tokens[length(tokens)-1]='WORD PTR')
        or (tokens[length(tokens)-1]='BYTE PTR')
        then
          setlength(tokens,length(tokens)-1)
        else
          last:=i+1;

        if opcode[i]='''' then firstquote:=true;
      end
      else
      begin
        firstquote:=false;
        if i=length(opcode) then
          tokens[length(tokens)-1]:=copy(opcode,last-1,i-last+2)
        else
          tokens[length(tokens)-1]:=copy(opcode,last-1,i-last+2);

        last:=i+1;
      end;
    end;

  end;

  i:=0;
  while i<length(tokens) do
  begin
    if (tokens[i]='') or (tokens[i]=' ') or (tokens[i]=',') then
    begin
      for j:=i to length(tokens)-2 do
        tokens[j]:=tokens[j+1];
      setlength(tokens,length(tokens)-1);
      continue;
    end;
    inc(i);
  end;

  result:=true;
end;



I guess it could be something wrong at the function tokenise. Is anybody encountered the same problem as me?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 474

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

PostPosted: Mon Aug 28, 2006 11:46 am    Post subject: Reply with quote

make sure you use the same assembler and disassembler.pas files

and see what happens if you click continue. perhaps it's a handled exception

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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 can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites