ThievingSix
asked on
Detour, "Inline" asm. Access Violation. C++ to Delphi translation
This one is driving me bananas as it works in C++ and not in Delphi when to my eyes everything is the same. It's probably the way C++ handles variables from classes.
Anyway this is a small section for what I have:
If Not(bNoRegs) Then
begin
Buffer.BufferAdd(Byte($89) );
Buffer.BufferAdd(Byte($0D) );
Buffer.BufferAdd(DWORD(@pC lassInstan ce));
end;
This is what it is in c++:
if(!m_bNoRegs)
{
Buffer += (BYTE)0x89; //mov dword ptr, ecx
Buffer += (BYTE)0x0D;
Buffer += (DWORD)&m_pClassInstance;
}
The Buffer variable isn't the issue as when the asm is written from the buffer it comes out right.
Now when each class is made the pClassInstance is set to nil(NULL in c++) it is a Pointer(BYTE * in c++). Now what is supposed to happen is pClassInstance is supposed to be set to ECX.
I.E. If ECX is $5E0000 pointer then pClassInstance should be equal to that. The same thing as doing pClassInstance := Pointer($5E0000);.
Now when this is executed on the delphi side I get an AV about not being able to access it.
Any ideas? If you need any other parts of the code just ask.
Anyway this is a small section for what I have:
If Not(bNoRegs) Then
begin
Buffer.BufferAdd(Byte($89)
Buffer.BufferAdd(Byte($0D)
Buffer.BufferAdd(DWORD(@pC
end;
This is what it is in c++:
if(!m_bNoRegs)
{
Buffer += (BYTE)0x89; //mov dword ptr, ecx
Buffer += (BYTE)0x0D;
Buffer += (DWORD)&m_pClassInstance;
}
The Buffer variable isn't the issue as when the asm is written from the buffer it comes out right.
Now when each class is made the pClassInstance is set to nil(NULL in c++) it is a Pointer(BYTE * in c++). Now what is supposed to happen is pClassInstance is supposed to be set to ECX.
I.E. If ECX is $5E0000 pointer then pClassInstance should be equal to that. The same thing as doing pClassInstance := Pointer($5E0000);.
Now when this is executed on the delphi side I get an AV about not being able to access it.
Any ideas? If you need any other parts of the code just ask.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was as far as I got in my reply until I realized why the variable couldn't be accessed. The code section:
Buffer += (BYTE)0x89; //mov dword ptr, ecx
Buffer += (BYTE)0x0D;
Buffer += (DWORD)&m_pClassInstance;
It never got EXECUTE privileges! Thanks to you confirming what I did was right it dawned on me! Thanks.