Thread: error with pointers

  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10

    error with pointers

    i am having problems with these 2 lines of code that is commented // compiler errors. the first code segment is what i am going off of. the second is my code i am working on. this will not compile on dev-c++ 4 or 5, vc++6 i keep getting this error in devcpp> 20 C:\Dev-Cppb5\projects\main.cpp invalid operands of types `int (*)(char*, ...)' and `int ()(const char*, ...)' to binary `operator+' .

    and this error in vc++6
    C:\Program Files\Microsoft Visual Studio\MyProjects\yep\main.cpp(22) : error C2297: '+=' : illegal, right operand has type 'int (const char *,...)'

    thanks in advanced. i have tried a number or irc channels and have alot of people stumped on this one.

    **this code will compile. a friend of mine compiled it on linux and win32 as i had the exe's but lost them**

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int (*printf_stub)(char *pfc, ...) = (int (_cdecl *)(char *pfc, ...))0x0c9029;          // starting pointer address
    int (*getc_stub)(FILE *gcs)        = (int (_cdecl *)(FILE *gcs))0x052011;
    
     
    int (*fflush_stub)(FILE *ffs)      = (int (_cdecl *)(FILE *ffs))0x0;
    int main(int argc, char *argv[])
    {
        
        printf_stub += (*printf);         /* this two lines error */
        getc_stub += (*getc);             /* ""                   */
        char z,y,x;
    	char c,b,a;
    	
        z = (*getc)(stdin);
            z = z & 0xee;
            z = z ^ 0x55;
            z = z ^ 0x71;
    
        y = (*getc)(stdin);
            y = y & 0xaa;
            y = y ^ 0x30;
            y = y ^ 0x80;
    
        x = (*getc)(stdin);
            x = x & 0xe7;
            x = x ^ 0xff;
            x = x ^ 0xf5;
        
        printf_stub -= (z * 0x10000) + ((y * 0x100) - 0xffff0000) + x;
    
        c = (*getc)(stdin);
            c = c & 0xac;
            c = c ^ 0x6c;
            c = c ^ 0x41;
            
        b = (*getc)(stdin);
            b = b & 0xdd;
            b = b ^ 0xe6;
            b = b ^ 0x8e;
            
        a = (*getc)(stdin);
            a = a & 0xf7;
            a = a ^ 0x7a;
            a = a ^ 0x2b;
    
        getc_stub -= (c * 0x10000) + (b * 0x100) + a;
    
        (*printf_stub)("________________\n");
        (*printf_stub)(">>-> EN1GMA <-<<\n");
        (*printf_stub)("^^^^^^^^^^^^^^^^\n\n");
        (*printf_stub)("! You are in a room.\n! You see lava, smoke, and mirrors."
                       "What do you do?\n\n> ");    
        fflush_stub = (*fflush);
        (*fflush_stub)(stdout);
        
        (*fflush_stub)(stdin);
        a = (*getc_stub)(stdin);
        if((a ^ 'r') != 0)
        {
            (*printf_stub)("You Win!\n");
        }
    	
        return 0;
    }
    my code below

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    
    int (*Printf_Stub)(char *pfc, ...) = (int (_stdcall *)(char *pfc, ...))0x0c9029;          // starting pointer address
    int (*Getc_Stub)(FILE *gcs)        = (int (_cdecl *)(FILE *gcs))0x052011;               // starting pointer address
    int a,b,c;      				   // int place holders for all               //
                                       // 6 char's
    int Counter = 0;
    
    bool aFlag = true;                 // bool flag's that pass to 
    bool bFlag = false;                // HaxOn(int,int,int,bool)
    
    void HaxOn(int,int,int,bool);      // Int HaxOn function
    void LoopThru();                   // Int LoopThru function
    void OutPut(int);
    
    int main(int argc, char *argv[])   // main ()
    
    {
        
    	Printf_Stub += (*printf);	   //compiler error's 
            Getc_Stub += (*getc);            // ""
    
    	LoopThru();
    	OutPut(Counter);
    
    	return 0;
    }
    void LoopThru()                    // looping function for all 6 char's            
    {                                          // and calls HaxOn()
    
    	for (a = 0x20; a < 0x7F; a++)
              {
                   for (b = 0x20; b < 0x7F; b++)
                        {
                         for (c = 0x20; c < 0x7F; c++)
                              {
                              HaxOn(a,b,c,aFlag);
    			  HaxOn(a,b,c,bFlag);
                              }
                        }
              }
    
    }
    void HaxOn(int fHex,               // first char in hex
    		   int sHex,               // second char in hex
    		   int tHex,               // third char in hex
    		   bool Flag)              // flag for each set
    {
    	                              
    	switch (Flag)
    	{
    	case true:
                
            Counter++;			
    			
    		        fHex = fHex & 0xEE;    // first char
    			fHex = fHex ^ 0x55;
    			fHex = fHex ^ 0x71;
    
                            sHex = sHex & 0xAA;    // second char
    			sHex = sHex ^ 0x30;
    			sHex = sHex ^ 0x80;
    
    			tHex = tHex & 0xE7;    // third char
                            tHex = tHex ^ 0xFF;
    			tHex = tHex ^ 0xF5;
    			     
                                       // formula for printfstub
    			Printf_Stub -= (fHex * 0x10000) + ((sHex * 0x100) - 0xFFFF0000) + tHex;
    			
                break;
    
    	case false:
    		
    		Counter++;            
    			
    			fHex = fHex & 0xAC;
    			fHex = fHex ^ 0x6C;
    			fHex = fHex ^ 0x41;
    
    			sHex = sHex & 0xDD;
    			sHex = sHex ^ 0xE6;
    			sHex = sHex ^ 0x8E;
    
    			tHex = tHex & 0xF7;
    			tHex = tHex ^ 0x7A;
    			tHex = tHex ^ 0x2B;
    
    			Getc_Stub -= (fHex * 0x10000) + (sHex * 0x100) + tHex;
    
    			break;
    
    	}
    }
    void OutPut(int Out)
    
    {
    	// temp counter to verify correct number of loops
    	cout << Out << " combinations processed\n";
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok so what exactly do you think you're getting when you dereference a function name? And why are you trying to increment a function pointer by it?


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

  3. #3
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    it is a crackme, what the author has told me. you basicaly have a broken pointer and have to enter 6 chars from the keyboard that goes threw all that mess and in the end must point to printf and getc. i am fairly new at c/c++ and i cant figure out how to get around those 2 problems. from what i gather, you are taking the int value of the stubs and adding the pointer address value to them. best as i can explain it.

    thanks for the reply

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    <<moved to C++>>
    **this code will compile. a friend of mine compiled it on linux and win32 as i had the exe's but lost them**
    It's not correct and it magically compiled on some system once...

    How about explaining more of what you're trying to do -- you'll have a better chance at better replies then.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I'm not sure if I'm more confused by the context of the questions or the fact that they were posted by Quzah.

    If I had to guess, this was split from some other post where Quzah was just bitterly asking questions to someone doing something wrong. This is strongly reinforced by the "thanks for the reply" in the next post. In any event, I always wanted to do this...

    Quzah, please look at this. Muahahaha. The day is mine!
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    well the question was here but now is gone, and i have no idea were it went

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Ah, it was moved to the C++ forum. Likely during the time Quzah was posting. The day is still mine, though... unless a Mod fixes this before midnight EST.
    Sent from my iPadŽ

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about not magicing your post around from one thread to another also?


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

  9. #9
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    well i had a win32 and linux exe of the above code and it does compile. just on what compiler is the problem. soon as i track down the exes i can post them on a www somewere. that is my problem now. it is a crackme. you are inputing 6 chars from the keyboard. and they go threw the routine in main() and the outcome of that should point to getc and printf. the first code block is the crackme. the second is my code. seeing there are multiple possiblities to the crackme i want to brute force them all. but until i can fix printf_stub += (*printf) i cant get past that

    thanks for the reply

  10. #10
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    i didnt repost here someone moved it here

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by quzah
    How about not magicing your post around from one thread to another also?
    My apologies for pokey modding. I'll try to fix that...
    [edit]Done?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What's a crackme?
    If you understand what you're doing, you're not learning anything.

  13. #13
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    basically its reverse engineering a problem to get a solution. testing skills @ breaking software protection or finding the right password to get in the back door so to speak. this specific one is based on program flow, pointers and bitwise operations.

  14. #14
    Registered User
    Join Date
    Aug 2006
    Location
    raleigh, nc
    Posts
    10
    ok probem fixed friend of mine got me to do this, which i never tried till now easy to miss

    for the 2 error lines
    Code:
       printf_stub += (*printf);
       getc_stub += (*getc);
    to this

    Code:
        printf_stub += (int)(*printf);
        getc_stub += (int)(*getc);
    code compiles now so if anyone ever comes into this problem here is the solution

  15. #15
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Well, I've minced this thread already, but it seems to me to go against #6:
    6. Messages relating to cracking, (erroneously called "hacking" by many), copyright violations, or other illegal activities will be deleted.
    So I'm closing it too. Perhaps another mod will see merit in continuing this -- try one or more of us via PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM