32位
从Ida把目标函数扣出来
toUapper proc near
arg_0 = dword ptr 4
push esi
mov esi, [esp+4+arg_0]
push edi
mov edi, esi
or ecx, 0FFFFFFFFh
xor eax, eax
repne scasb
not ecx
dec ecx
xor edx, edx
test ecx, ecx
jle short loc_40102D
loc_401018:
mov al, [edx+esi]
cmp al, 61h
jl short loc_401028
cmp al, 7Ah
jg short loc_401028
sub al, 20h
mov [edx+esi], al
loc_401028:
inc edx
cmp edx, ecx
jl short loc_401018
loc_40102D:
pop edi
pop esi
retn
toUapper endp
汇编代码进行修正,并放入<filename>.asm中
.model flat, c
option casemap :none
.code
toUapper proc arg_0:DWORD ;函数入口
push esi
mov esi, arg_0 ;语法修正
push edi
mov edi, esi
or ecx, 0FFFFFFFFh
xor eax, eax
repne scasb
not ecx
dec ecx
xor edx, edx
test ecx, ecx
jle short loc_40102D
loc_401018:
mov al, [edx+esi]
cmp al, 61h
jl short loc_401028
cmp al, 7Ah
jg short loc_401028
sub al, 20h
mov [edx+esi], al
loc_401028:
inc edx
cmp edx, ecx
jl short loc_401018
loc_40102D:
pop edi
pop esi
ret ;把n删掉,汇编不认retn
toUapper endp
end ;最后一定要加一个end
将<filename>.asm 使用ml.exe编译成<filename>.obj
ml.exe 是vs自带的,用evething 搜一下
ml.exe /c toUapper.asm
将<filename>.obj添加到vs工程中,并声明使用目标函数
test.cpp
#include <iostream>
extern "C" void toUapper(char* src); //一定要加入 extern "C"的说明,不然会因c++的命名粉碎而导致找不到目标函数而出现无法解析的符号错误
int main()
{
char szBuf[256] = {0,};
scanf_s("%s", szBuf, 256);
toUapper(szBuf);
std::cout << szBuf;
getchar();
}
运行结果