Unvollständige Funktion "aufrufen"?! Asm?!
-
Hallo,
ich habe ein kleines Problem. Ich habe eine Funktion irgendwo im Speicher sitzen, von der die ersten 4 bytes fehlen. Diese 4 bytes (bzw. die asm Befehle, welche in diesen 4 bytes sitzen) sind aber zur Compilezeit bekannt, und so habe ich gedacht, ich könnte vielleicht soetwas schreiben...DerRueckgabeWert DieFunktion(DieArgumente) { __asm { //Die ersten Befehle, z.B. nop nop nop nop call EchteFunktion } }Hier mal ein kleines Beispiel:
char* pcAdd; int Add() { return 1+2; } void Add2() { __asm { call pcAdd; } } int main() { pcAdd=reinterpret_cast<char*>(Add); Add2(); return 0; }Dies erzeugt den folgenden Assembler code:
Add:
00000 55 push ebp
00001 8b ec mov ebp, esp
00003 83 ec 40 sub esp, 64 ; 00000040H
00006 53 push ebx
00007 56 push esi
00008 57 push edi00009 b8 mov eax, 3 ;1+2

0000e 5f pop edi
0000f 5e pop esi
00010 5b pop ebx
00011 8b e5 mov esp, ebp
00013 5d pop ebp
00014 c3 ret 0Add2:
00000 55 push ebp
00001 8b ec mov ebp, esp
00003 83 ec 40 sub esp, 64 ; 00000040H
00006 53 push ebx
00007 56 push esi
00008 57 push edi00009 ff call DWORD PTR ?pcAdd@@3PADA ; pcAdd
0000f 5f pop edi
00010 5e pop esi
00011 5b pop ebx
00012 8b e5 mov esp, ebp
00014 5d pop ebp
00015 c3 ret 0Wenn ich jetzt meinen Code aber anpasse, klappt es nicht (Exception)

char* pcAdd; int Add() { return 1+2; } void Add2() { __asm { push edp call pcAdd; } } int main() { pcAdd=reinterpret_cast<char*>(Add); pcAdd++; Add2(); return 0; }Was ist falsch?!
Helft mir
-
Die Frage ist wohl eher nicht wie man eine unvollständige Funktion aufrufen kann, sondern wie du zu der selben kommst...
Wie schafst du es den Compiler dazu zu bringen eine Funktion nicht vollständig zu uebersetzen?
-
Klingt irgendwie nach Gaunerei.