Can i make function in some other lenguage (i means C) and then HexEdit it into my prog made in MASM. Can i just simply Paste this piece of code.
For example i make in MASM function that is doing nothing but acept the same amount and type of variables like my func made in C fill it with NOP it will be easy to find when Hex-ing.
For example i make in MASM function that is doing nothing but acept the same amount and type of variables like my func made in C fill it with NOP it will be easy to find when Hex-ing.
You must remember that variable names just points to data segment (which is loaded into the memory). Thus you need to be sure that the variables's memeory is correct.
Anyway it is better to link it into your masm created exe then use your hands and hexeditor.
Anyway it is better to link it into your masm created exe then use your hands and hexeditor.
Also, if any of the Hex copied code contains any calls to the Windows API they will be screwed up because they will point to an incorrect import address entry.
Static or dynamic link the function.
Static or dynamic link the function.
Anyway it is better to link it into your masm created exe then use your hands and hexeditor.
how can i do this ??
Why not just link your C obj file to your masm file, that way you can make calls to the proc directly from your asm program. Just have to create a proto for it. Or make it a LIB or a dll.
I think you use RadASM so this is how you would do it :
copy the obj file to your project folder.
Right click in the project window
select "add existing"/"Object file"
That's it.
I think you use RadASM so this is how you would do it :
copy the obj file to your project folder.
Right click in the project window
select "add existing"/"Object file"
That's it.
so i just have to name this func the same as in C and link it ?? thats all ???
Yah, you have to create a PROTO though. I have never tried this (I only use assembler) so I'm not sure what the pitfalls are. I know that the linker will decorate the name for you :
proc PROTO :DWORD,:DWORD
becomes :
_proc@8
proc PROTO :DWORD,:DWORD
becomes :
_proc@8
so when i do it that way i can use windos api inside C proc ??
I would need an object file made with C or at least a C compiler and some knowledge of C to answer that. None of which I have, like I said I've never tried it and I only program in assembler (can't even do VB). So someone else has to take over from here :)
If you want to call a VC function from a MASM program, you need to do something like this:
// Be aware that some standard C functions (especially the stdio functions) require startup
// code which is included if you define a C main or WinMain function.
// The API doesn't require the startup code (which is why you can call them
// from ASM.)
// If you don't want to use the extended (nonstandard) VC keyword __stdcall,
// then you must call the C function from ASM using the CDECL or C calling
// convention.
// Add the following #include line if you want to call API from C
// This will include the definitions of most (but not all) API functions
#include <windows.h>
// function returning nothing
extern "C" __stdcall void fproc1()
{
}
// function returning int
extern "C" __stdcall int fproc2()
{
return 1; // return value in EAX
}
// function returning pointer
extern "C" __stdcall int *fproc3()
{
static int staticInt;
int *pInt = &staticInt;
return pInt; // return value in EAX
}
// Be aware that some standard C functions (especially the stdio functions) require startup
// code which is included if you define a C main or WinMain function.
// The API doesn't require the startup code (which is why you can call them
// from ASM.)
// If you don't want to use the extended (nonstandard) VC keyword __stdcall,
// then you must call the C function from ASM using the CDECL or C calling
// convention.
// Add the following #include line if you want to call API from C
// This will include the definitions of most (but not all) API functions
#include <windows.h>
// function returning nothing
extern "C" __stdcall void fproc1()
{
}
// function returning int
extern "C" __stdcall int fproc2()
{
return 1; // return value in EAX
}
// function returning pointer
extern "C" __stdcall int *fproc3()
{
static int staticInt;
int *pInt = &staticInt;
return pInt; // return value in EAX
}