Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted

    [Help]C++ evaluate () function

    Hey guys, what's up??

    I've been diving into executable protection and things like that and I find that I'm being limited by C++'s static linking ( I cannot modify the code while running)

    Remember that little [TEST] thread of mine a while ago? I said I used techniques that would modify my code on the fly, it turned out that I was being tricked by my own program. There was nothing realy special about it.

    I want to be able to change the way my program encrypts and thus decrypts itself every time it runs. I thought I had completed my objective but I was wrong...

    Now I'm trying it again, and I want to do it like this:

    I've read about a function called eval(), that exists in certain languages. The eval function would execute a string as code (!)

    say this is an sample of a non-existant language:

    Code:
    var i = 1
    
    echo( eval("i = i + i") )
    The program would take the string "i = i + i" and execute it as code, so the echo function (which would be C++'s equvilant of printf()) would print: '2' to the screen.

    Now before you get all excited about this, C++ doesn't support the eval() function.


    I realy need such a function to complete my objective. And since there's nothing like this flying around the internets I'm going to code it myself

    Does anyone have any experience with marco-languages and custom scripting? I alreay have a few basic ideas. But I've stumbled on a problem. How do I link strings to variable names?
    Suppose I have a program like this:

    Code:
    int i = 0;
    string str = "i = 2";
    eval(str);
    How do I make the i in the string refer to the i in the program?
    Is this even possible?

    -SCHiM

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  2. #2
    doofbla's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    Biel*****/Germany
    Posts
    369
    Reputation
    10
    Thanks
    179
    My Mood
    Psychedelic
    I haven't tried but isn't this automaticly? you declared i before and if eval() really just executes the string it should work. Or am i totaly false?
    _____________________________________________

    READING TUTORIAL:

    1. READ MY POST
    2. THINK ABOUT MY POST
    3. PRESS THANKS
    4. MAYBE CORRECT MY POSTS :P




    Dijkstra:
    "Computer Science is no more about computers than astronomy is about
    telescopes."


    THANKS BUTTON RIGHT DOWN --->

  3. #3
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Quote Originally Posted by doofbla View Post
    I haven't tried but isn't this automaticly? you declared i before and if eval() really just executes the string it should work. Or am i totaly false?
    Read the whole post doofbla ;P eval() doesn't exist in C++, so that function is just to illustrate how I'd want to eval() fucnction to work in C++

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  4. #4
    doofbla's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    Biel*****/Germany
    Posts
    369
    Reputation
    10
    Thanks
    179
    My Mood
    Psychedelic
    Aaaa okay now it's clear for me that i was totaly wrong with my answer

    but anyhow i didn't get 100% what you want.

    EDIT:
    ok you want to code "eval" by yourself but you have to know how to link the string i with the int i?
    If yes I'm sorry I don't have a answer & I can't think about a way to do this But maybe others can =)
    Last edited by doofbla; 09-26-2010 at 12:37 PM.
    _____________________________________________

    READING TUTORIAL:

    1. READ MY POST
    2. THINK ABOUT MY POST
    3. PRESS THANKS
    4. MAYBE CORRECT MY POSTS :P




    Dijkstra:
    "Computer Science is no more about computers than astronomy is about
    telescopes."


    THANKS BUTTON RIGHT DOWN --->

  5. #5
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Hmm sadly I don't think this is possible. . . Well I tried to do some research on the matter and I came up with nothing but people saying various reasons why it would not work because of the paradigms C++ uses as a language.

    Though good luck! This would definitely be interesting if you figure out a way.

  6. #6
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    if
    i = 1
    i+i=2

    [php]printf("2");[/php]

  7. #7
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    1. Get input from user.
    2. Split string using mathematical deliminators (+, -, =, *, /).
    3. Convert each number into a unit (using atoi or a similar function)
    4. Apply your mathematical operations
    5. Output result.

  8. #8
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Quote Originally Posted by freedompeace View Post
    1. Get input from user.
    2. Split string using mathematical deliminators (+, -, =, *, /).
    3. Convert each number into a unit (using atoi or a similar function)
    4. Apply your mathematical operations
    5. Output result.
    I already have a skeleton that does that. But the problem with the symbols isn't solved, though I've a few ideas (from the printf statement)

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  9. #9
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by .::SCHiM::. View Post
    I already have a skeleton that does that. But the problem with the symbols isn't solved, though I've a few ideas (from the printf statement)
    Lol skeleton.

    Anyway, what problem with the symbols?

  10. #10
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Quote Originally Posted by freedompeace View Post
    Lol skeleton.

    Anyway, what problem with the symbols?
    I cannot get "x = i" the string 'x' to equal the real int x.
    That's the only problem left...

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  11. #11
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by .::SCHiM::. View Post
    I cannot get "x = i" the string 'x' to equal the real int x.
    That's the only problem left...
    I don't think even this will hide your string. Not to mention it seems really hard unless your damn good at macros. If you don't want people to see the string the string then the best option is to not include it in the program.

    Do something like calculate the checksum of the string then store that in your program and calculate the checksum of the entered string on the fly. If the two match you have a correct answer.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  12. #12
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Quote Originally Posted by why06 View Post
    I don't think even this will hide your string. Not to mention it seems really hard unless your damn good at macros. If you don't want people to see the string the string then the best option is to not include it in the program.

    Do something like calculate the checksum of the string then store that in your program and calculate the checksum of the entered string on the fly. If the two match you have a correct answer.
    No, that's not what I'm trying to do here... I'm trying to make it possible for C++ to selfmodify itself on the fly. That modification taking place in strings/code or otherwise. If I can get this done...

    But it seems that my task is impossible (many others have failed where I will fail aswell)

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  13. #13
    doofbla's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    Biel*****/Germany
    Posts
    369
    Reputation
    10
    Thanks
    179
    My Mood
    Psychedelic
    I know that "good" spyware changes their code everytime they make a new copy of themself so maybe you should go a bit in that way to get information
    (i hope you don't want to make such a tool)


    EDIT: i just remembered the name :

    POLYMORPHIC VIRUS/SPY-/MALEWARE or whatever...

    just google "Polymorphism c++" and you'll find a lot of introductions and tutorials
    Last edited by doofbla; 09-28-2010 at 11:47 AM.
    _____________________________________________

    READING TUTORIAL:

    1. READ MY POST
    2. THINK ABOUT MY POST
    3. PRESS THANKS
    4. MAYBE CORRECT MY POSTS :P




    Dijkstra:
    "Computer Science is no more about computers than astronomy is about
    telescopes."


    THANKS BUTTON RIGHT DOWN --->

  14. #14
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by .::SCHiM::. View Post
    No, that's not what I'm trying to do here... I'm trying to make it possible for C++ to selfmodify itself on the fly. That modification taking place in strings/code or otherwise. If I can get this done...

    But it seems that my task is impossible (many others have failed where I will fail aswell)
    First off. If your going for polymorphism I would implement it at the asm level, by taking certain instructions and changing them for equivalent instructions or instructions.

    Secondly those people who failed were master virus programmers in many cases. A polymorphic self replicating virus seems a little out of your range. Why not try something simpler. Creating polymorphic code is possible, by changing inserting junkbytes in the code, but to actually change the executing instructions themselves is gonna take a lot of work.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  15. #15
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    Quote Originally Posted by why06 View Post
    First off. If your going for polymorphism I would implement it at the asm level, by taking certain instructions and changing them for equivalent instructions or instructions.

    Secondly those people who failed were master virus programmers in many cases. A polymorphic self replicating virus seems a little out of your range. Why not try something simpler. Creating polymorphic code is possible, by changing inserting junkbytes in the code, but to actually change the executing instructions themselves is gonna take a lot of work.
    To tell you guys the truth, I was fasinated by the idea of self-modifying code when I first started off writing code. And I never realy lost that fascination.
    Although the technique is often used by polymorpic/ metamorphic viruses, and therefore seen as shady, if not mallicious. I think it can be used to create inreverceable exectutables (or atleast take the revercing of such .exe's to a whole new level)

    @why

    Dang, I knew it was comming for me...
    *is of to learn asm, with an determination that will soon probably turn to dread by asm's daunting syntax*

    @doofbla

    The tutorials you're reffering to are about polymorphism in C++, which is different from writing self-modifying code
    Last edited by .::SCHiM::.; 09-28-2010 at 01:16 PM.

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




Page 1 of 2 12 LastLast

Similar Threads

  1. [Help]Externally listing functions in the IAT.
    By Void in forum C++/C Programming
    Replies: 8
    Last Post: 09-26-2010, 02:49 PM
  2. [Help]notepad search function
    By mizzer3 in forum Visual Basic Programming
    Replies: 30
    Last Post: 09-10-2010, 01:10 PM
  3. [Help] Howto spawn functioning miniguns (turrets)
    By kerocs in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 1
    Last Post: 08-09-2010, 05:23 AM
  4. [Help]Search File Function[Solved]
    By ppl2pass in forum Visual Basic Programming
    Replies: 1
    Last Post: 06-09-2010, 07:50 AM
  5. [HELP] User-Definable Function Strings
    By ilovepie21 in forum Visual Basic Programming
    Replies: 1
    Last Post: 04-24-2008, 09:16 PM