I am using OllyDbg 2.01 and I walked through this tutorial to figure out how Call DLL export works. Even though it was written for another version of OllyDBG it work just fine. We should notice, that in example with USER32.dll OllyDBG detects number of input arguments, so I can change them from Call DLL export dialogue.
I decided to write my own DLL library in C++ in order to test OllyDBG functionality in a more detailed manner.
Here is a source code of my library.
CPPlib.h
#pragma once
#ifdef CPPLib_EXPORTS
#define CPPLib_API __declspec(dllexport)
#else
#define CPPLib_API __declspec(dllimport)
#endif
#include <string>
namespace CPPLib
{
class Functions
{
public:
static CPPLib_API void Identify();
static CPPLib_API void GetText();
static CPPLib_API void PrintText(std::string& s);
};
}
CPPLib.cpp
#include "stdafx.h"
#include "CPPLib.h"
#include <iostream>
#include <windows.h>
namespace CPPLib
{
void Functions::Identify()
{
std::cout << "This is a CPPlib \r\n";
}
void Functions::GetText()
{
std::cout << "This is a random text from CPPlib \r\n";
}
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
void Functions::PrintText(std::string& s)
{
std::wstring stemp = CPPLib::s2ws(s);
LPCWSTR result = stemp.c_str();
MessageBox(0, result, (LPCWSTR)L"MessageBox caption", MB_OK);
std::cout << "This is a user input text: " << s;
}
}
In this question my interest is in the function PrintText. It takes string as an input argument, show Message box with it and prints the same string in the console.
If I call this function from C++ program - it works just fine.
#include "stdafx.h"
#include "CPPLib.h"
#include <string>
int main()
{
CPPLib::Functions::Identify();
CPPLib::Functions::GetText();
std::string s = "USER INPUT";
CPPLib::Functions::PrintText(s);
return 0;
}
Unlike in the example from tutorial, OllyDBG does not detect number of input arguments for my DLL.
Moreover, even if I define it manually (e.g. choose Arg1 to be memory buffer 1) when calling that function it does not take what I wanted to be an argument. And there is no other way to change this argument as step into a function, find memory address to which it refers and change it there.
So my question is: Why does OllyDbg detect number of input arguments in functions (and allows to alter them easily) from USER32.dll and doesn't in my own DLL? How can I overcome this problem?