 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Wed Jun 04, 2008 2:11 pm Post subject: [Request] Help with bytes from editbox C++ |
|
|
ok so example:
My editbox text is : "8D 04 83 7D FF 09 9F"
I need to output it as a hex string which im going to store into a adress from my process, i need help with making that function =/ anyone can help me?
i would output (9f09ff7d83048d or 8d04837dff099f) im not sure about that
Any one know what i should use :s? Thank you soo mutch~.
Edit1: Using Borland Developer Studio 2006 / C++
_________________
Gone |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jun 04, 2008 2:44 pm Post subject: |
|
|
What? Please clarify.
You want to convert that to hex and store it in a string?
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Wed Jun 04, 2008 3:59 pm Post subject: |
|
|
| --Pillboi-- wrote: | What? Please clarify.
You want to convert that to hex and store it in a string? |
No i want to convert from string to hex, the string will be like bytes "FF 00 0A 04"
@x0r: Would you give me a example?
_________________
Gone |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Jun 04, 2008 4:30 pm Post subject: |
|
|
Taken from: Tiny Encryption Algorithm
Some functions from various files.
| Code: | #pragma once
#include <string>
#include <cstdlib>
#include <vector>
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////
/*
* hexStringToBytes [Original Function]
* Taken From: TEA (Tiny Encryption Algorithm)
* Found In File: util.cpp
*
/////////////////////////////////////////////////////////////////////////////////////
size_t hexStringToBytes(const string &str, byte *out)
{
vector<string> vec;
string::size_type currPos = 0, prevPos = 0;
while ((currPos = str.find(' ', prevPos)) != string::npos) {
string b(str.substr(prevPos, currPos - prevPos));
vec.push_back(b);
prevPos = currPos + 1;
}
if (prevPos < str.size()) {
string b(str.substr(prevPos));
vec.push_back(b);
}
typedef vector<string>::size_type sz_type;
sz_type size = vec.size();
for (sz_type i = 0; i < size; ++i) {
int a = hexCharToInt(vec[i][0]);
int b = hexCharToInt(vec[i][1]);
out[i] = a * 16 + b;
}
return size;
}
*/
/////////////////////////////////////////////////////////////////////////////////////
//
// Function: hexCharToInt
// Returns : int
// Purpose : Converts a hex character to is numeric value.
//
// This function is taken from the TEA(Tiny Encryption Algorithm) library.
// You can find this function in the util.cpp file.
//
int hexCharToInt(char hex)
{
hex = toupper( hex );
if( isdigit( hex ) )
return( hex - '0' );
if( isalpha( hex ) )
return( hex - 'A' + 10 );
return 0;
}
//
// Function: hexStringToBytes
// Returns : size_t
// Purpose : Converts a hex string to the proper bytes.
//
// This function is based on the above function from the TEA
// encryption library. I have basically rewritten the whole
// function to be used the way I saw fit but I am leaving
// credits where they are due. :) ~Wiccaan
//
size_t hexStringToBytes(const string &str, byte *out)
{
vector<string> vec;
int iCurrPos = 2;
int iPrevPos = 0;
for( int x=0; x < (int)str.size(); x+=2, iCurrPos+=2 )
{
string b( str.substr(iPrevPos,iCurrPos-iPrevPos) );
vec.push_back(b);
iPrevPos = iCurrPos;
}
int size = (int)vec.size();
for( int i = 0; i < size; ++i )
{
int a = hexCharToInt( vec[i][0] );
int b = hexCharToInt( vec[i][1] );
out[i] = a * 16 + b;
}
return size;
}
|
Example usage:
| Code: | void GetStringFromBox( HWND hWnd )
{
//
// Obtain Hex String Length
//
int iStringLength = NULL;
iStringLength = (int)SendMessage( GetDlgItem(hWnd,IDC_HEXSTRING), WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0 );
//
// Make Sure We Are Even
//
if( iStringLength%2 != 0 )
{
MessageBox( hWnd, "You have entered an invalid string. It appears you missed some characters.", "ERROR!", MB_OK );
return;
}
//
// Create Buffers For Our String And Byte Array
//
// String is full length of itself, the byte array
// is half of the string since you are converting
// every 2 bytes into a hex character.
//
char* szBuffer = new char[iStringLength+1];
BYTE* btBuffer = new BYTE[(iStringLength/2)+1];
//
// Pull Text From Textbox
//
GetDlgItemText( hWnd, IDC_HEXSTRING, szBuffer, iStringLength+1 );
//
// Convert String To Bytes
//
hexStringToBytes(szBuffer, btBuffer);
//
// This is for checking if the convert was successful.
// VS wont show you more then the first byte of the array in the watch window.
//
for(int x=0;x<(iStringLength/2); x++)
btBuffer[x]=btBuffer[x];
//
// Anything you wish to do with the byte array should take place here
// or you can copy it to an external array and handle things elsewhere
// just be sure to let this function finish and delete the arrays when
// it's done or you will run into memory leaks!
//
//
// Delete Arrays When We Are Done With Them
//
delete[] btBuffer;
delete[] szBuffer;
} |
Hope it helps.
_________________
- Retired. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|