[Proxy] Cleaner interface disassembly

This commit is contained in:
momo5502 2017-03-03 11:33:13 +01:00
parent 4c6694026b
commit 8e5446e198
2 changed files with 33 additions and 23 deletions

View File

@ -39,7 +39,7 @@ namespace Steam
return this->methodCache[method];
}
auto methodData = Interface::lookupMethod(method);
auto methodData = this->lookupMethod(method);
this->methodCache[method] = methodData;
return methodData;
}
@ -48,16 +48,16 @@ namespace Steam
{
if (!::Utils::Memory::IsBadReadPtr(this->interfacePtr))
{
unsigned char** vftbl = *static_cast<unsigned char***>(this->interfacePtr);
auto* vftbl = this->interfacePtr->vftbl;
while (!::Utils::Memory::IsBadReadPtr(vftbl) && !::Utils::Memory::IsBadCodePtr((FARPROC(*vftbl))))
while (!::Utils::Memory::IsBadReadPtr(vftbl) && !::Utils::Memory::IsBadCodePtr(vftbl->func))
{
std::string name;
uint16_t params;
if (this->getMethodData(*vftbl, &name, &params) && name == method)
{
return{ *vftbl, params };
return{ vftbl->data, params };
}
++vftbl;
@ -67,17 +67,17 @@ namespace Steam
return { nullptr, 0 };
}
bool Interface::getMethodData(unsigned char* methodPtr, std::string* name, uint16_t* params)
bool Interface::getMethodData(VInterface::VMethod method, std::string* name, uint16_t* params)
{
name->clear();
*params = 0;
if (::Utils::Memory::IsBadCodePtr(methodPtr)) return false;
if (::Utils::Memory::IsBadCodePtr(method.data)) return false;
ud_t ud;
ud_init(&ud);
ud_set_mode(&ud, 32);
ud_set_pc(&ud, reinterpret_cast<uint64_t>(methodPtr));
ud_set_input_buffer(&ud, reinterpret_cast<uint8_t*>(methodPtr), INT32_MAX);
ud_set_pc(&ud, method.value);
ud_set_input_buffer(&ud, method.data, INT32_MAX);
while (true)
{

View File

@ -146,7 +146,7 @@ namespace Steam
{
public:
Interface() : interfacePtr(nullptr) {}
Interface(void* _interfacePtr) : interfacePtr(_interfacePtr) {}
Interface(void* _interfacePtr) : interfacePtr(static_cast<VInterface*>(_interfacePtr)) {}
template<typename T, typename... Args>
T invoke(std::string methodName, Args... args)
@ -195,56 +195,66 @@ namespace Steam
template<std::size_t X, std::size_t ... Xs>
struct AddSizes<X, Xs...> : std::integral_constant<std::size_t, X + ((AddSizes<Xs...>::value + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1))> {};
void* interfacePtr;
struct VInterface
{
union VMethod
{
unsigned char* data;
unsigned int value;
FARPROC func;
}* vftbl;
};
VInterface* interfacePtr;
std::unordered_map<std::string, std::pair<void*, uint16_t>> methodCache;
std::pair<void*, uint16_t> getMethod(std::string method);
std::pair<void*, uint16_t> lookupMethod(std::string method);
bool getMethodData(unsigned char* methodPtr, std::string* name, uint16_t* params);
bool getMethodData(VInterface::VMethod method, std::string* name, uint16_t* params);
};
class KeyValuesBuilder
{
private:
std::stringstream m_buffer;
std::string buffer;
inline void packBytes(const void* bytes, size_t size)
{
m_buffer << std::string(reinterpret_cast<const char*>(bytes), size);
this->buffer.append(reinterpret_cast<const char*>(bytes), size);
}
inline void packDataType(uint8_t type)
{
packBytes(&type, 1);
this->packBytes(&type, 1);
}
inline void packNullTerminated(const char* string)
{
packBytes(string, strlen(string) + 1);
this->packBytes(string, strlen(string) + 1);
}
public:
inline void packString(const char* key, const char* value)
{
packDataType(1);
packNullTerminated(key);
packNullTerminated(value);
this->packDataType(1);
this->packNullTerminated(key);
this->packNullTerminated(value);
}
inline void packUint64(const char* key, uint64_t value)
{
packDataType(7);
packNullTerminated(key);
packBytes(&value, sizeof(value));
this->packDataType(7);
this->packNullTerminated(key);
this->packBytes(&value, sizeof(value));
}
inline void packEnd()
{
packDataType(8);
this->packDataType(8);
}
inline std::string getString()
{
return m_buffer.str();
return this->buffer;
}
};