Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 不允许调用putchar地址_C++_Assembly - Fatal编程技术网

C++ 不允许调用putchar地址

C++ 不允许调用putchar地址,c++,assembly,C++,Assembly,再次继续,我无法手动调用Windows 7 putchar地址 我使用一组汇编操作码来模拟C++函数和对Prtff()命令的调用。我将操作码数组复制到保留内存中,并使用指向数组开头的函数指针调用它(复制到内存后) 有关阵列: uint8_t asmCommandsPart1[] = {0x55, //push EBP 0x89, 0xE5, //mov EBP, ESP 0x8

再次继续,我无法手动调用Windows 7 putchar地址

我使用一组汇编操作码来模拟C++函数和对Prtff()命令的调用。我将操作码数组复制到保留内存中,并使用指向数组开头的函数指针调用它(复制到内存后)

有关阵列:

uint8_t asmCommandsPart1[] = {0x55, //push EBP
                              0x89, 0xE5, //mov EBP, ESP
                              0x83, 0xEC, 0x18, //sub ESP, 0x18
                              0xC7, 0x04, 0x24, 0x41, 0x00, 0x00, 0x00, //mov DWORD PTR SS:[ESP],0x41
                              0xE8}; //call
                              //The next byte is the start of the offset to jump to

uint8_t asmCommandsPart2[] = {0xC9, 0xC3}; //leave, retn
我使用一个常量地址计算跳转偏移量,然后从该地址减去asmCommandsPart1(0xE8)最后一个字节的地址,再加上5。我可以确认这是可行的,因为我在计算地址(asmCommandsPart1+偏移量中的0xE8地址)打印了字节值,并将它们与程序的反汇编版本(在OllyDbg中完成)中的值进行了比较,它们匹配

下面是我如何计算偏移量,以及将地址放入内存的memcpy调用(hold_address是指向保留内存开始的指针):

memcpy(保持地址,asmCommandsPart1,sizeof(asmCommandsPart1)[0]*14)//将阵列复制到保留内存中
int asmCommandsOffset=14//在数组中计数时计算偏移量时,从0开始
char*jumpFromAddress=(保持地址+asmCommandsOffset)//从hold_地址开始计算asmCommandsPart1的结尾
char*jumpToAddress=reinterpret_cast(0x0041CA70)//创建指向跳转到的内存的指针
int jumpAddressOffset=abs((int)(jumpToAddress jumpFromAddress))+5//计算两个指针之间的偏移量
memcpy(jumpFromAddress和jumpAddressOffset,sizeof(jumpAddressOffset))//将putchar的计算地址复制到内存中
memcpy(jumpFromAddress+sizeof(jumpAddressOffset)、asmCommandsPart2、sizeof(asmCommandsPart2)[0]*2)//将0xC9和0xC3复制到内存中
唯一的问题是程序在跳转到putchar地址时返回0x3错误。上的MSDN文档告诉我这是一个“STATUS\u WAIT\u 3”错误代码,但这和它的描述并没有告诉我什么。上的MSDN文档说这是一个错误路径未找到的错误,这再次告诉我什么都没有

我错过了什么?地址显然是可调用的,程序已经调用了它,我只是无法复制它,即使在精确复制操作码时也是如此(注意:操作码/顺序从未更改,只是地址)

请注意,跳转到附近的地址(如abort)可以正常工作。我只测试了abort和putchar。还要注意,我意识到putchar的地址发生了变化,接下来我将动态计算它

下面是内存中putchar和abort命令的图片。跳转到0041CA80将导致程序崩溃,错误代码为0x3,跳转到0041CA90将正常工作


它不一定是一个函数。在大多数实现中,它是一个宏,因此它没有一个你可以获取的地址。如果我误解了你,请原谅,但是我提供的屏幕截图显示了我可以跳转到的地址,不是吗?为什么我可以跳到中止而不是putchar?
memcpy(hold_address, asmCommandsPart1, sizeof(asmCommandsPart1)[0]*14); //copy the array into the reserved memory
int asmCommandsOffset = 14; //when calculating offset when counting in array, start at 0
char* jumpFromAddress = (hold_address+asmCommandsOffset); //Calculate the end of asmCommandsPart1 starting from hold_address
char* jumpToAddress = reinterpret_cast<char*>(0x0041CA70); //Create pointer to memory where jumping to
int jumpAddressOffset = abs((int)(jumpToAddress-jumpFromAddress))+5; //Calculate the offset between the two pointers
memcpy(jumpFromAddress, &jumpAddressOffset, sizeof(jumpAddressOffset)); //copy calculated address of putchar into memory
memcpy(jumpFromAddress+sizeof(jumpAddressOffset), asmCommandsPart2, sizeof(asmCommandsPart2)[0]*2); //copy 0xC9 and 0xC3 into memory