Thread: program copying itself (ideas)

  1. #16
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    i kno i kno...sorry if i scared ya....don't worry, my first post describes that i just wanted to make sure i was ideologically thinking on the right track.....i don't intend to use this knowledge for malicious purposes.....or any that i can think of at the moment except making backup copies.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I got a worm like that once on one of my former Windows XP machines. I ended up with 20,000 randomly-named executables in \windows\system32. It made the computer really slow.

    So I guess that makes things much simpler....so correct me if I'm wrong...but in conclusion....

    A copying device would simply write the characters to a new file after reading itself.
    Or it could write the chars to the new file as they were being read, each character at a time, like my program above does.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    That is an actually interesting point you bring up.....(not to make this more soundly like a virus)....how do u give a new filename a random name?

    would it be something like for example

    Code:
    char filename[MAX_SIZE] = "testfilename" << rand() << ".txt"

    if that does work....is there away to do that in C? because i think the c compiler would interpret that as bit shifting, am i correct?

    and another thing....if we're still on the opening file topic......if fopen were to read itself......is there any way for it to recognize exactly what place it is in on the system, so it would save the programmer (or user in certain scenarios) some time by it already knowing the exact filepath of itself.
    Last edited by johnchain; 07-19-2006 at 05:09 PM.

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char buf[BUFSIZ], mode[BUFSIZ];
    FILE *fp;
    generaterandomname( buf );
    generaterandommode( mode );
    fp = fopen( buf, mode );
    It's really simple if you stop and think.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    I apologize for my ignorance......but does that answer the concatation question? (I mean that in the least rudest way possible)...I really still am a little confused.

    And I'd appreciate the answer to my first question too (not to sound demanding)

    I appreciate all the contributions so far

    Edit: my apologies....I realized that I asked a lot of questions.....I am afraid that I do not know enough to interpret the contents of "generaterandomname()"
    Last edited by johnchain; 07-19-2006 at 06:10 PM.

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know how to generate something random, like a number?
    ... No? Read the FAQ on random numbers.
    ... Yes? Continue.

    Do you know how to convert a number to a string?
    ... No? Read up on sprintf.
    ... Yes? Continue.

    Do you know how to pass the first argument to fopen?
    ... No? Look up a few posts.
    ... Yes? Rejoice.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #22
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    well, If we are still on the same topic and if u r using GCC, I think u can make use of the
    "system() " command that lets u execute shell commands from within the C program. I think that should help u with ur first problem..

  8. #23
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    Thank you Quzah, very elaborate....I understand now....as for the first problem....of the program itself regocnizing where it is on the system....I am still a little confused.

    I don't know how I would be able to connect that with the system() command.

  9. #24
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    U r working on linux right? read the man pages .. Put the bash command u want to execute within double quotes.. like u want the C program to print todays date .. do :

    system ("date");

    I think u can pick it up from here .I hope that answers ur question

  10. #25
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    Well no, I understand, I have used system() before....but here's exactly what I want to accomplish....

    Say I have a file in the folder C:\random\random\

    and the file is called random1983741.exe

    from the previous problem....how would the new program created (copied and randomly named) be able to run an fopen command on itself...like this..

    fopen("thefilejustcreated123412.exe", "rb");

    if the program had entirely just been created without any consent with the user....can code within the program identify itself and possibly where it is located.

    Am I still missing something, I can't picture the system command helping with this....if it does I apologize, please correct me where I'm wrong.

  11. #26
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You are trying to write a virus, I suggest you cut it out... thread reported.

  12. #27
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Exclamation

    initiating discussions on circumventing system mechanisms, even hypothetically, is pointless and only serves to degrade the integrity of the programming arts and community. the focus should be data structures and algorithms - not clever hacks.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  13. #28
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    ok ok I'll stop...I apologize......usually when i get an idea i can't stop thinking about it until i got all ends tied....

    Thanks to everyone....even the people against the conversation....you make unargueable points


  14. #29
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    when i started programming i also tried writing a "virus" - better: a function that could insert executable code into another exe - i didn't have evil intentions with it - i just wanted to see if i understood what was going on.
    so i can understand when ppl ask such questions - but i also understand that the rules of this board need to be followed. just my 50 cent
    signature under construction

  15. #30
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    when i started programming i also tried writing a "virus" - better: a function that could insert executable code into another exe - i didn't have evil intentions with it - i just wanted to see if i understood what was going on.
    Now that right there is exactly my point, that's something I wouldn't mind visualizing either, I can't even imagine what kind programming schematics are required to do such a task.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Program Idea's
    By devour89 in forum C++ Programming
    Replies: 11
    Last Post: 12-04-2002, 04:57 AM
  4. Program ideas...
    By code987 in forum C++ Programming
    Replies: 3
    Last Post: 11-18-2002, 11:41 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM