在用内联汇编写一个注册机时遇到的问题,求各位帮帮我,谢谢了。 int x1,x2;//x1和x2是注册码的2个部分
char *name="pediy";//为什么用指针的时候出的结果x1,x2不正确
//char name[20]="pediy";//用char数组结果正确,没有任何问题
__asm
{
lea esi,name
xor ecx,ecx
L001:
movsx eax,byte ptr ds:[esi]
mov ebx,eax
sub esi,edx
shl eax,04h
shr ebx,05h
xor eax,ebx
add eax,026h
xor eax,ecx
add ecx,eax
inc esi
cmp byte ptr ds:[esi],00h jnz L001
mov eax,00C0DEFh
sub eax,ecx
imul eax,eax
mov x1,ecx
mov x2,eax
}
char *name="pediy";//为什么用指针的时候出的结果x1,x2不正确
//char name[20]="pediy";//用char数组结果正确,没有任何问题
__asm
{
lea esi,name
xor ecx,ecx
L001:
movsx eax,byte ptr ds:[esi]
mov ebx,eax
sub esi,edx
shl eax,04h
shr ebx,05h
xor eax,ebx
add eax,026h
xor eax,ecx
add ecx,eax
inc esi
cmp byte ptr ds:[esi],00h jnz L001
mov eax,00C0DEFh
sub eax,ecx
imul eax,eax
mov x1,ecx
mov x2,eax
}
解决方案 »
- 求助~~关于Edit控件(MFC)
- 消息处理函数关联到同一个函数下
- 这条sql语句,有错吗?INSERT INTO logInfo ( devNo, devType, errType, pri, logDate, cont ) VALUES ( "1", "1", "
- VC+MapX,实现画点,画线问题?
- SQL语句问题
- IBM品牌机不能正常显示Opengl图像的问题
- 为何出现此错误Cannot initlize data bindings
- 在非托管的VC++中怎样调用托管的DLL中的函数?
- 如何捕捉其他应用程序的对话框以及其中的按钮?
- 小弟有一事不明。
- 比较基础的问题
- 使用CSplitterWnd静态分割SDI时RUNTIME_CLASS的问题。
是指向字符串常量指针,运行时,已经分配好了,在内存中:xxxpediy0xxxxx
你的汇编估计要对此地址进行移位,扩展等操作,没有多余的空间供你用.
所以应动态的分配一个较大的空间,供你操作.
GetDlgItemText(IDC_EDIT1, szText, sizeof(szText));
{ TCHAR cCode[100]={0};
int x1,x2 char szText[256]={0};
GetDlgItemText(IDC_EDIT1, szText, sizeof(szText));__asm
{
//mov esi,name
lea esi,szText
xor ecx,ecx //r_esi=1242244
L001:
movsx eax,byte ptr ds:[esi]//eax=6
mov ebx,eax //eax=103 esi 1242244 eax 96?
sub esi,edx
shl eax,04h
shr ebx,05h
xor eax,ebx
add eax,026h
xor eax,ecx
add ecx,eax
inc esi
cmp byte ptr ds:[esi],00h //这里报错KeyGen.exe 中的 0x00675560 处有未经处理的异常: 0xC0000005: 读取位置 0xfffdecf1 时发生访问冲突 jnz L001
mov eax,00C0DEFh
sub eax,ecx
imul eax,eax
mov x1,ecx
mov x2,eax
}wsprintf(cCode,TEXT("CM2-%.4X-%.4X"),x1,x2);
::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_EDIT2,cCode);
}咋解决呢,求解!!
这句不得其解,esi中是szText地址,为什么要减去edx,edx中的值,经过串赋值后,好象变为最后一个字符的值,一减,esi中的地址就到非法的区域了.我觉得这句没有必要.你先去掉,试一下.
{
//mov esi,name
lea esi,szText
xor ecx,ecx//DWORD x1 = 0;
L001:do{
movsx eax,byte ptr ds:[esi]//char cTemp = *szText;
mov ebx,eax//
//sub esi,edx
shl eax,04h//cTemp << 4;
shr ebx,05h//
xor eax,ebx//cTemp ^= cTemp >> 5;
add eax,026h//cTemp += 26;
xor eax,ecx//cTemp ^= x1;
add ecx,eax//x1 += cTemp;
inc esi//szText ++;}
cmp byte ptr ds:[esi],00h //while(*szText != 0); jnz L001
mov eax,00C0DEFh//DWORD x2 = 789999;
sub eax,ecx//x2 -= x1;
imul eax,eax//x2 *= x2;
mov x1,ecx
mov x2,eax
}最后结果是: char szText[256] = {0};
GetDlgItemText(IDC_EDIT1, szText, sizeof(szText));
DWORD x1 = 0;
do
{//逐一读出字符进行操作,以得到x1的值
char cTemp = *szText;
cTemp << 4;
cTemp ^= cTemp >> 5;
cTemp += 26;
cTemp ^= x1;
x1 += cTemp;
szText ++;
}
while(*szText);
DWORD x2 = 789999;
x2 -= x1;
x2 *= x2;我以前看汇编,把一种压缩解压缩的C++代码都搞出来了,这么一小段代码,不算啥
char szText[256] = {0};
GetDlgItemText(IDC_EDIT1, szText, sizeof(szText));
DWORD x1 = 0;
do
{//逐一读出字符进行操作,以得到x1的值
char cTemp1 = *szText;
char cTemp2 = cTemp1;
cTemp1 <<= 4;
cTemp2 >>= 5;
cTemp1 ^= cTemp2;
cTemp1 += 26;
cTemp1 ^= x1;
x1 += cTemp1;
szText ++;
}
while(*szText);
DWORD x2 = 789999;
x2 -= x1;
x2 *= x2;
编译有个错误,
“++”需要左值在 do循环最后一句 szText ++;
再帮我解决一下。
GetDlgItemText(IDC_EDIT1, szText, sizeof(szText));
DWORD x1 = 0;
char* p = szText;
do
{//逐一读出字符进行操作,以得到x1的值
char cTemp1 = *p;
char cTemp2 = cTemp1;
cTemp1 <<= 4;
cTemp2 >>= 5;
cTemp1 ^= cTemp2;
cTemp1 += 38;
cTemp1 ^= x1;
x1 += cTemp1;
p ++;
}
while(*p);
DWORD x2 = 789999;
x2 -= x1;
x2 *= x2;