|
You last visited: Today at 11:11
Advertisement
Problem with fstream
Discussion on Problem with fstream within the C/C++ forum part of the Coders Den category.
09/24/2014, 18:59
|
#1
|
elite*gold: 0
Join Date: Sep 2014
Posts: 354
Received Thanks: 282
|
Problem with fstream
Hey there guys
So i am trying to make a pattern scanner for S4League
It's a dll and i want it to create a file and put the address that it obtained in a txt file
But it does not work , it doesn't create any txt file
Source code :
Header.h
Code:
#include <Windows.h>
#include <string>
#include <sstream>
#include <iostream>
#include <ostream>
#include <fstream>
#include <Psapi.h>
#include <ctime>
#include <io.h>
#include <fcntl.h>
#include <stdint.h>
#include <vector>
void CreateConsole()
{
int hConHandle = 0;
HANDLE lStdHandle = 0;
FILE *fp = 0;
// Allocate a console
AllocConsole();
// redirect unbuffered STDOUT to the console
lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDIN to the console
lStdHandle = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "r");
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
lStdHandle = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(PtrToUlong(lStdHandle), _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
}
Functions.h
Code:
#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
#include <Psapi.h>
void MsgBoxAddy(DWORD addy)
{
char szBuffer[1024];
sprintf(szBuffer, "Addy: %02x", addy);
MessageBox(NULL, szBuffer, "Title", MB_OK);
}
MODULEINFO GetModuleInfo( char *szModule )
{
MODULEINFO modinfo = {0};
HMODULE hModule = GetModuleHandle(szModule);
if(hModule == 0)
return modinfo;
GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO));
return modinfo;
}
void WriteToMemory(uintptr_t addressToWrite, char* valueToWrite, int byteNum)
{
unsigned long OldProtection;
VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
memcpy( (LPVOID)addressToWrite, valueToWrite, byteNum);
VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
}
DWORD FindPattern(char *module, char *pattern, char *mask)
{
MODULEINFO mInfo = GetModuleInfo(module);
DWORD base = (DWORD)mInfo.lpBaseOfDll;
DWORD size = (DWORD)mInfo.SizeOfImage;
DWORD patternLength = (DWORD)strlen(mask);
for(DWORD i = 0; i < size - patternLength; i++)
{
bool found = true;
for(DWORD j = 0; j < patternLength; j++)
{
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}
if(found)
{
return base + i;
}
}
return NULL;
}
Source.cpp
Code:
#include "Functions.h"
#include "Header.h"
#include <fstream>
using namespace std;
void DoStuff()
{
DWORD hpAddy = FindPattern("S4Client.exe", "\x83\xC0\x01\x8B\x8D\xC8", "xxxxxx");
hpAddy+=0;
CreateConsole();
SetConsoleTitle("Address Searcher");
system("COLOR 0A");
cout << "The addy is 0x" << uppercase << hex << hpAddy;
ofstream myfile;
myfile.open ("addys.txt");
myfile << "The address for the training func is : 0x " << hpAddy;
myfile.close();
}
#pragma endregion
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
DoStuff();
break;
}
// Successful DLL_PROCESS_ATTACH.
return TRUE;
}
Why am i doing this in a dll and not in a exe (console based app ) ?
Because The scan method seems to not work in a console based app
I would appreciate if someone could show me how to do the scanning in a console
But first , i'm looking forward to make it output to the txt file :c
|
|
|
09/24/2014, 19:13
|
#2
|
elite*gold: 1371
Join Date: Apr 2010
Posts: 13,792
Received Thanks: 15,050
|
Code:
myfile.open ("addys.txt", std::ofstream::out);
The file will be created in the injected executable's path (S4 League path)
|
|
|
09/24/2014, 19:20
|
#3
|
elite*gold: 0
Join Date: Sep 2014
Posts: 354
Received Thanks: 282
|
Quote:
Originally Posted by Omdihar
Code:
myfile.open ("addys.txt", std::ofstream::out);
The file will be created in the injected executable's path (S4 League path) 
|
Thank you very much , didn't think of that lol.
So now if anyone is willing to show me the right way of pattern scanning in a console based app , i would be really thankfull
|
|
|
09/24/2014, 19:37
|
#4
|
elite*gold: 1371
Join Date: Apr 2010
Posts: 13,792
Received Thanks: 15,050
|
Quote:
Originally Posted by ιllυѕιve
Thank you very much , didn't think of that lol.
So now if anyone is willing to show me the right way of pattern scanning in a console based app , i would be really thankfull 
|
OpenProcess ReadProcessMemory
These two functions should do it
|
|
|
All times are GMT +1. The time now is 11:12.
|
|