|
I've been thinking about it... And I cant figure it out. How would a program perform a md5 checksum on itself?
I need my program to do this.
The problem is.... You can only calculate the checksum after its compiled.
so i have code like this....
BYTE bRealChecksum[16] = {0xA9, 0x1E, 0xA7, 0x63,
0x0A, 0xD5, 0x55, 0x1B,
0x26, 0x80, 0xB9, 0x71,
0x9C, 0x66, 0xCC, 0xEF};
Then I calculate the checksum, then compare it to the BYTE array above which holds the real checksum, and what the results of the checksum should be. If they are not equal, the file has been modified.
But now, how am I supposed to know the checksum, without compiling? Because I need to know what the checksum of the compiled file is going to be, before I compile it.
Anyone have any ideas?
|
|
|
|
|
We send out discs that have their own checksum on them...
For a simple checksum it's not so hard to compute what
value would be the checksum of a disc given a field of
known values that would change to that value and the
original checksum of the disc.. I shudder to think how
hard this would be with a respectable hash....
Yikes.
I'd be surprised if someone has an easy way to do this.
ACtually, thinking about what claims are made for MD5,
it would be practically impossible no? If the hash is
hard to work backwards to text, then it bears little
relationship to slightly modified versions of the text.
(just what you'd need to be able to implement your scheme)
Sorry. Looks like you're out of luck.
|
|
|
|
|
Ya, I think I've decided to just store the checksum in an external file... Which is what I wanted to avoid... But seems to be the only possible way.... At least with a hash like md5 .. like you stated
|
|
|
|
|
Looks a bit like an endless recursion:
To calculate the checksum you need all bytes of the .exe which includes the checksumm...
The only way I can think of is to store the checksum in an area that is not used for creating the hash. Of course, your "MD5" hash then is not a usual MD5 hash any more, but if the app just want's to detect if it has been modified this would work.
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
It depends if you want it hackerproof.
An easy option is just to make the checksumming code ignore the part of the file that contains the real checksum (then that can change to anything you like without modifying the actual checksum). Run this once with a blank value for that, calc the checksum, fill it in to the variable, and recompile.
Of course, this won't stop anyone else modifying the code, and fixing the checksum.
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I'm studying multi-threading today and got some major problems, the biggest one is that the worker thread is not terminating as expected, my code looks like this:
BOOL g_bAbort = FALSE;
UINT ThreadProc(LPVOID lpParam)
{
while (!g_bAbort)
{
}
return 0;
}
void CThreadTestDlg::OnStart()
{
g_bAbort = FALSE;
m_pThread = ::AfxBeginThread(ThreadProc, NULL);
}
void CThreadTestDlg::OnStop()
{
g_bAbort = TRUE;
DWORD dwExitCode = 0;
do
{
Sleep(200);
::GetExitCodeThread(m_pThread->m_hThread, &dwExitCode);
} while (dwExitCode == STILL_ACTIVE);
}
OnStart() is called as soon as the program starts, OnStop() is called when a button captioned ""stop" is pressed.
I press the "stop" button and my program freezes. I used debugger and found out that the thread never ended, even though g_bAbort has been set to TRUE. Why so?
Thank you a lot.
|
|
|
|
|
CWinThread normally has m_bAutoDelete set TRUE which
means it will delete itself and close the m_hThread
handle upon termination. You should either reset the
m_bAutoDelete flag and delete it yourself or else use
DuplicateHandle to create your own copy of the m_hThread
handle which will be valid in your OnStop function.
|
|
|
|
|
But the thread did not terminate, the "exit code" is always STILL_ACTIVE.
|
|
|
|
|
What's the return value of GetExitCodeThread?
|
|
|
|
|
It returns TRUE, and the exit code keeps being STILL_ACTIVE even though I had set g_bAbort to FALSE already.
|
|
|
|
|
In the OnStart handler, you should start the thread, then loop the PeekMessage function until the thread exits or the user presses STOP.
void CThreadTestDlg::OnStart(){
MSG msg;
DWORD threadec;
g_bAbort = FALSE;
m_pThread = ::AfxBeginThread(ThreadProc, NULL);
while(::PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
if(msg.message==WM_QUIT){
::PostQuitMessage(msg.wParam);
break;
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
if(!::GetExitCodeThread(m_pThread->m_hThread,&threadec))
return;
if(threadec!=STILL_ACTIVE)break;
}
}
I apologize it this isn't right; I'm much used to programming in C.
Peter O.
|
|
|
|
|
I think you should do like this...
void CThreadTestDlg::OnStop()
{
// wanna stop the thread...
g_bAbort = TRUE; DWORD dwExitCode = 0;
}
Thus you can abort the thread.
No pains, no gains.
|
|
|
|
|
I think you should do like this...
void CThreadTestDlg::OnStop()
{
// wanna stop the thread...
g_bAbort = TRUE;
}
Thus you can abort the thread.
No pains, no gains.
|
|
|
|
|
1) you should use WaitForSingleObject instead of Sleep/GetExitCodeThread in OnStop.
2) try marking g_bAbort with 'volatile' modifier
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Hello all,
I have a Win32 Application that uses standard C and Win32 API calls (creating directories and setting security permissions) along with a single DialogBox.
The program executes fine in Visual Studio, but when I go to run it from the .exe file outside of VS, nothing happens.
Double-clicking the .exe I get no response.
Any help in getting this Application to standalone would be greatly appreciated.
Sincerely...
Trish
|
|
|
|
|
As long as you have the source code you should be ok.
The first thing that I would do is make liberal use of ASSERTs or at least popup some message boxes in your WinMain to see how far it gets before it crashes. Do this every place that could possibly make your app exit.
One more thing that I would like to ask is are you trying to use the same type of build to run it inside and outside of the debugger.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi kilowatt,
Thanks for the response. I did read somewhere to move my .exe outside of the Debug folder and into the directory with all other project files.
I did this and now the .exe responds to the double-click.
Have a good one!
Trish
|
|
|
|
|
Hello,
Trying to decode a tiff file from eFax with libtiff. I noticed that the decoded image is shorter. How do I detect and handle a tiff-fax file has horizontal ratio of 2:1? I noticed that acdsee and irfanview can decode the fax file with the right ratio.
Thanks!
|
|
|
|
|
Hello all, I was wondering if anyone can help me with this little problem. I have a project in which I use MDI. When it starts up the program opens a blank document. I would like it NOT to open any document at all and rely on the use the open a file. Any idea how to do that? Thanks
|
|
|
|
|
plonk this in your app's InitInstance() function where the original version is:
// Dispatch commands specified on the command line
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
if (!ProcessShellCommand(cmdInfo))
return FALSE;
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
I'm using MAPi to email attachments (thanks to a couple articles here on CodeProject!), But I think the behavior I want is not available in MAPi.
I want the application to open the default mail program (i.e. Outlook) with the attachment added then in Outlook the user can then add comments, select address etc. the problem is MAPi sends the email directly to the outbox bypassing Outlook.
I've seen this behavior, opening Outlook and adding an attachment, in many programs and assumed it was part of MAPi.
What am I missing?
|
|
|
|
|
Hi, how can I access a file in home directory of current user? Can I use a filename like "~/appname/file.ini" or what do I need to do? It should work with WinME/2000/XP? Thanks in advance!
|
|
|
|
|
XP and 2000 have a environmental variable %user% that will give you the name of the logged in user. I guess that should be able to put used in a filename.
Michael
Time flies like an arrow. Fruit flies like a banana
|
|
|
|
|
Hello there,
<blockqoute> is there a way to programmatically add user-accounts in NT?
- YES!
- How?
And why aren't the lsa* functions like lsaopenpolicy and such documented (in MSDN)?
(Where is it documented?)
Georg Haan
|
|
|
|
|
Georg Haan wrote:
is there a way to programmatically add user-accounts in NT?
Yes
Georg Haan wrote:
- How?
Sorry, don't remember right now
Georg Haan wrote:
And why aren't the lsa* functions like lsaopenpolicy and such documented (in MSDN)?
(Where is it documented?)
They are documented in the latest MSDN Library (It's the one I have installed, so it's the only one I have checked)
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|