#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0

    Exclamation Problem with code


    Hi. I have some problems with my code. The code goes like this:

    HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_LOCKUP_EXE), "Exe");
    HGLOBAL hGlobal = LoadResource(AfxGetResourceHandle(), hrSrc);
    LPVOID lpExe = LockResource(hGlobal);

    CFile file;
    file.Open("C:\Testing.exe", CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone);
    file.Write(lpExe, (UINT)SizeofResource(AfxGetResourceHandle(), hrSrc));
    file.Close();

    HANDLE hInputFile = CreateFile("C:\Documents and Settings\Administrator\My Documents\Testing.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD dwFileSize = GetFileSize(hInputFile, NULL), dwBytesRead;
    LPBYTE pBuffer = new BYTE[dwFileSize];
    ReadFile(hInputFile, pBuffer, dwFileSize, &dwBytesRead, NULL);
    CloseHandle(hInputFile);
    HANDLE hUpdateResource = BeginUpdateResource("C:\Testing.exe", FALSE);
    UpdateResource(hUpdateResource, "LOCKFILE", "IDR_LOCK_FILE", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pBuffer, dwFileSize);
    EndUpdateResource(hUpdateResource, FALSE);
    delete [] pBuffer;

    When I run the program and press the OK button, it gives me an invalid allocation size error. What is wrong with the code? Please help me. Thanks
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    You still have the same problem in the same line as last time.

    If you knew some simple debugging or error checking then you would know what was going wrong (or at least where).

    I think that you are a skriptkiddie writing a trojan because you don't seem to understand the code you have.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0
    No, I'm not. It's just that I don't know what causes the error after debugging.
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Please use an acceptable subject title. You can refer to the sticky thread at the top of this forum for more information on how to post a question.
  8. #5
  9. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    Originally posted by TechNoFear
    You still have the same problem in the same line as last time.

    If you knew some simple debugging or error checking then you would know what was going wrong (or at least where).

    I think that you are a skriptkiddie writing a trojan because you don't seem to understand the code you have.
    i guess you were correct all along:)
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0
    I know where the error occurs, but I am not sure what causes the error. The error must have occured in these two lines:

    DWORD dwFileSize = GetFileSize(hInputFile, NULL), dwBytesRead;
    LPBYTE pBuffer = new BYTE[dwFileSize];

    Please tell me what is wrong. Thanks a lot!
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    hmm perhaps you ALLOCATING an array of an INVALID SIZE. PERHAPS THE RETURN VALUE FROM FUNCTIONS SHOULD BE CHECKED FOR ERRORS B4 ONE USES THAT VALUE ELSEWHERE.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0
    ok. any suggestions on how to go about doing the checking?
  16. #9
  17. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    LOL!

    How did you get this far? Gets hard when the code you don't understand is not working.

    Read up on debugging. That is watching the values your code generates as it runs.
    When you find the one that failed you can find out why.
    Look up GetLastError(), my bet is it will be error 87.



    PS We know what the error is, we are just not telling you.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  18. #10
  19. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    wouldnt it be cool if functions returned values that let us know if they were successful or not? maybe C+++ will have that feature. you should probably recommend that to the standards board ricky :)
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0
    how can i display the value in a msgbox (cause the type of the error value is DWORD)?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    Ricky,

    Anybody writing that code for any legitimate purpose would know how to debug and solve the problem. There are only a couple of reasons to be opening an executable with write access, and anybody with the cajones to write one of those programs can figure out how to see the value of a DWORD data type.

    If you really want to be the cool hacker that you're trying to be, stop goofing around with code you don't understand and starting studying the language seriously. Grab a copy of Kernighan & Ritchie, a free compiler, and start working through the book. Or sign up for classes at the local community college.

    Don't try to tell us that you understand what the program does when it's clear you don't even understand the language that it's written in. If you're serious about what you're up to, take the steps necessary to get the knowledge and skills you'll need. Programming isn't something you pick up on a weekend after reading some code. It's going to take a lot of work, some real dedication, and a serious love of programming. C and C++ are non-trivial languages, and you need to do a lot of work before you're ready to be an elite hacker.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    25
    Rep Power
    0
    Firstly, I am not a hacker. Secondly, I am not trying to act pro. It's just that I have a dateline to meet and I have tried all possible solutions before I posted my problem here. If I know what is the problem, I would have solved it long ago. So if you could help, please help. You could at least give me some tips on my problem. Thank You very much!

IMN logo majestic logo threadwatch logo seochat tools logo