本帖最后由 jhq999 于 2022-10-19 21:59 编辑
C语言中局部变量存在栈里,
每个函数开头0x401410 push %ebp
0x401411 mov %esp,%ebp
vs
#include "stdafx.h"
void fun()
{
char* s=0;
int cmpnum=*(int*)"abcd";
__asm{
mov ebx,ebp;
mov eax,[ebx];
mov s,eax;
}
for(int i=0;i<256;i+=4)
{
s=s-4;
if(cmpnum==*(int*)s)
{
s[0]='e';
s[1]='f';
s[2]='g';
s[3]='h';
break;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char s[]="abcd";
fun();
printf("%s\n",s);
_tsystem(_T("pause"));
return 0;
}
gcc#include <stdio.h>
void fun()
{
char *s;
long long cmpnum=*(long long*)"abcdeeee";
asm("movl %%ebp,%%eax\n\tmovl (%%eax),%0"
:"=r"(s)
:
:"%eax");
printf("%p\n",s);
for(int i=0;i<256;i+=4)
{
s=s-1;
if(cmpnum==*(long long*)s)
{
printf("%s\n",s);
}
}
}
int main( )
{
char s[]="abcdeeee";
printf("%p\n",s);
fun();
return 0;
}
#include "stdafx.h"
void fun()
{
unsigned int *s=0;
int cmpnum=*(int*)"abcd";
__asm{
mov eax,ebp;
mov s,eax;
}
char *s1="1234567";
for(int i=0;i<256;i+=1)
{
s=s+1;
//printf("%p %p\n",s,*s);
if(*s-int(s1)<1000||-1000<*s-int(s1))
{
//printf("%p %p\n",s,*s);
if(*(int*)(*s)==cmpnum)
{
*s=(unsigned int )s1;
break;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char *s="abcdefffddk";
//printf("%p %p\n",&s,s);
fun();
printf("%s\n",s);
_tsystem(_T("pause"));
return 0;
}
|