关于代码异常的问题
环境:VS 2008,C++
我有如下代码:
void HopeException(LPVOID nVerify)
{
char *p = NULL;
p = (char *)nVerify;
delete []p;
}
当我使用参数非 NULL 调用函数“HopeException”时,例如:
HopeException(123);
那么我希望程序会抛出异常。
但是当我在VS 2008上使用Release模式编译代码时,程序运行良好。
我不知道为什么。有人可以帮我解决这个问题吗?
或者您有什么好主意用其他方法来实现该功能吗?
编辑:
我很抱歉,我想我之前发布了错误的代码。
事实上,我正在为我的软件做保护。 我的软件会获取DLL文件的CRC值,然后我的软件会检查CRC值,如下所示:
unsigned int VerifyCRC = FF234322;
unsinged int CRC = getCRC("Fun.dll");
LPVOID lpResult = CRC & (~VerifyCRC);
HopeException(lpResult);
所以根据下面的代码,如果破解者破解了Fun.dll文件,执行将抛出异常抛出异常。
这才是我真正想要的。
Env: VS 2008, C++
I have code like below:
void HopeException(LPVOID nVerify)
{
char *p = NULL;
p = (char *)nVerify;
delete []p;
}
When I invoke the function "HopeException" with parameter not-NULL, like:
HopeException(123);
then I hope the program will throw an exception.
But when I compile the code on VS 2008 with Release mode, the program runs well.
I don't know why. Could anyone give me a help about this issue?
Or do you have any good idea to implement the feature with another method?
Edit:
I am so sorry, I think I posted the wrong code before.
Actually, I am doing protection for my software.
My software will get the CRC value of DLL file, and then my software will check the CRC value like below:
unsigned int VerifyCRC = FF234322;
unsinged int CRC = getCRC("Fun.dll");
LPVOID lpResult = CRC & (~VerifyCRC);
HopeException(lpResult);
So according the code below, if the cracker cracks the Fun.dll file, the execute will throw out an exception.
That is really I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Jell - C++ 给了你足够的绳子来吊死你自己(很可能还有你们大多数朋友)。
但为什么要这么做呢? (- 假设这取决于你的朋友)。
Jell - C++ gives you enough rope to hang yourself (and most probably most of you friends).
But why do it? (- Suppose it depends on your friends).
您将
nVerify
视为一个地址,并将其分配给指针p
,然后在该地址上调用delete[]
。如果 nVerify 的值不是有效地址,您可能会得到未定义的行为,其中包括程序看起来“运行良好”,主要是因为您在此函数中并未真正执行太多操作。你到底想做什么?
You're treating
nVerify
as an address and assigning it to your pointerp
, and then invokingdelete[]
on that address. If the value of nVerify isn't a valid address you can get undefined behavior, which includes the program appearing to "run well" mostly because you're not really doing much in this function.What are you really trying to do?
该代码不应在 C++ 中编译;应该编译良好的最接近的事情是:
此代码将在 VS 2010 Express 上崩溃,所以我假设它也会在 VS 2008 中崩溃。如果您的目标是直接抛出调试器异常(在 x86 上),您可以使用
如果您的目标是闯入调试器,你也可以使用
That code shouldn't compile in C++; the closest thing that should compile fine is:
This code will crash on VS 2010 Express, so I assume it will also crash in VS 2008. If your goal is to throw a debugger exception directly (on x86) you can just use
If your goal is to break into the debugger you can also just use