Hi
I'm not sure if this is the correct newsgroup for this question
as it involves both ASM and c++, but here goes.
I have written a function in C++ that has to replace one of
a process in memory (to change functionality).
The original function's address is retrieved from 1 offset.
When the application starts I write the address of my new
function to that offset. So far so good. I found out the original
function has 1 argument (4-byte) and returns a 4-byte value
(1 or 0, BOOL). This fails. I took a look at the code c++
had generated, in a debugger. I saw c++ ends the new
function with "retn". When I changed this to "retn 4"
the process ran without any problems.
Why does "retn 4" work and "retn" not? Why does
Visual C++ compile "retn" and not "retn 4"?
Thanks
Joris 3 4047
* Joris: I'm not sure if this is the correct newsgroup for this question as it involves both ASM and c++, but here goes.
I have written a function in C++ that has to replace one of a process in memory (to change functionality). The original function's address is retrieved from 1 offset. When the application starts I write the address of my new function to that offset. So far so good. I found out the original function has 1 argument (4-byte) and returns a 4-byte value (1 or 0, BOOL). This fails. I took a look at the code c++ had generated, in a debugger. I saw c++ ends the new function with "retn". When I changed this to "retn 4" the process ran without any problems.
The problem is C-style machine code calling convention versus Pascal-like
style machine code calling convention.
Standard C++ does not help out with machine code calling conventions.
The closest you get in standard C++ is 'extern "C"' versus 'extern "C++"',
but for your problem, consult the compiler's documentation for language
extensions (OT: for MSVC the language extension is 'declspec').
Why does "retn 4" work and "retn" not?
See above.
Why does Visual C++ compile "retn" and not "retn 4"?
See above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Joris wrote: I'm not sure if this is the correct newsgroup for this question as it involves both ASM and c++, but here goes.
It's not. Your question is compiler-specific. It should be asked
in the newsgroup for that compiler. 'microsoft.public.vc.language'
is probably the one you need.
I have written a function in C++ that has to replace one of a process in memory (to change functionality). The original function's address is retrieved from 1 offset. When the application starts I write the address of my new function to that offset. So far so good. I found out the original function has 1 argument (4-byte) and returns a 4-byte value (1 or 0, BOOL). This fails. I took a look at the code c++ had generated, in a debugger. I saw c++ ends the new function with "retn". When I changed this to "retn 4" the process ran without any problems.
Why does "retn 4" work and "retn" not? Why does Visual C++ compile "retn" and not "retn 4"?
<offtopic>
You probably didn't declare your function appropriately. There exist
several modifiers in Visual C++ (they call them "calling conventions")
that can change how the function is called, how the arguments are passed,
and how the function returns. See 'CALLBACK', 'WINAPI', '__stdcall',
etc.
</offtopic>
V
Thank you.
"Alf P. Steinbach" <al***@start.no> schreef in bericht
news:42****************@news.individual.net...
* Joris: I'm not sure if this is the correct newsgroup for this question as it involves both ASM and c++, but here goes.
I have written a function in C++ that has to replace one of a process in memory (to change functionality). The original function's address is retrieved from 1 offset. When the application starts I write the address of my new function to that offset. So far so good. I found out the original function has 1 argument (4-byte) and returns a 4-byte value (1 or 0, BOOL). This fails. I took a look at the code c++ had generated, in a debugger. I saw c++ ends the new function with "retn". When I changed this to "retn 4" the process ran without any problems.
The problem is C-style machine code calling convention versus Pascal-like
style machine code calling convention.
Standard C++ does not help out with machine code calling conventions.
The closest you get in standard C++ is 'extern "C"' versus 'extern "C++"',
but for your problem, consult the compiler's documentation for language
extensions (OT: for MSVC the language extension is 'declspec').
Why does "retn 4" work and "retn" not?
See above.
Why does Visual C++ compile "retn" and not "retn 4"?
See above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
I have this code:
-----------------
<script>
function handler(the_event) {..............}
</script>
<img onmousemove="handler(????????)">
-----------------
how can I send the produced...
|
by: kongsballa |
last post by:
Hi!
I have a webapp. that holds a lot of documents. Some of the documents
needs to be produced from a database on-the-fly, some are static
documents like PDF, Word documents, etc... In the end,...
|
by: Medi Montaseri |
last post by:
I was wondering if anyone else has noticed that binaries produced by
g++ 3.x are almost
twice as big as the ones produced by g++ 2.95.
Thanks
|
by: guoxiaotian |
last post by:
I tried py2exe the latest version with python 2.4 on windows.
the setup script looks like this:
___________________________________________
# setup.py
from distutils.core import setup
import...
|
by: Thomas W |
last post by:
I've produced a "binary" version of a python-script using Py2Exe and
when run on WinXP it shows a terminal window for a brief moment then
the window disappears. How can I avoid this? I want the...
|
by: BigAl |
last post by:
How do you view the XML which is produced by the Invoke
method ?
object results = this.Invoke("cardRequest",
new object {
reqcode, obj1,
obj2, obj3});
How do printout, look at, view,...
|
by: Michael A. Covington |
last post by:
When I build my setup project, I get three files: setup.exe, setup.ini. and
myapplication.msi.
These go into a folder called (setup project)/bin/Release. If any other
files are in that folder,...
|
by: Charlie |
last post by:
Hi:
I'm getting errors trying to load forms in designer, but application runs
and compiles fine. I find myself editing code produced by designer in some
situations, but stay away from areas...
|
by: jacuna |
last post by:
function_______ is used to produced random numbers
|
by: emrefan |
last post by:
I am wondering a bit about what I should see in a message box (or in a
webpage, for that matter) when I include an unprintable ASCII
character, say ASCII 255, in there. I experimented a bit on my...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |