 |
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: Sun Jun 08, 2008 8:33 am Post subject: [Request] Help with C++ String -> Char Array |
|
|
I have
| Code: | | String szString = "8D 23 74 3D FF 0A" |
And i need to make it as
| Code: | | char Bytaz[] = {0x8D, 0x23, 0x74, 0x3D, 0xFF, 0x0A} |
Of couse the szString is dinamyc(Text and size)~
Anyone know how to do it?
And please no GetDlg or sutch things heres a piece of code i was tryng
| Code: |
char StrToChar(int TehLength)
{
int NumberOfBytes = ((TehLength+1)/3);
char Temp;
char *TempBuffer = (char*)malloc(NumberOfBytes);
for (int i = 1; i <= NumberOfBytes; i = i+3)
{
sprintf(TempBuffer,"%s%s, ",Form1->Edit1->Text[i],Form1->Edit1->Text[i+1]);
*TempBuffer = Form1->Edit1->Text[i];// + Form1->Edit1->Text[i+1]);
Temp = Temp+*TempBuffer;
}
free(TempBuffer);
return Temp;
} |
Thank you soo mutch for the support. _________________
Gone |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 08, 2008 8:48 am Post subject: |
|
|
Lol. Dude...
| Code: |
Form1->Edit1->Text[i]
|
xD!!! This isn't delphi. There is no Form1, Edit1, Text...lol. Even if you're using MFC you don't even do it like that. Btw, you realize that you can just go
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Sun Jun 08, 2008 8:49 am Post subject: |
|
|
| oib111 wrote: | Lol. Dude...
| Code: |
Form1->Edit1->Text[i]
|
xD!!! This isn't delphi. There is no Form1, Edit1, Text...lol. Even if you're using MFC you don't even do it like that. Btw, you realize that you can just go
| He uses Borland C++, I believe. |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Sun Jun 08, 2008 8:52 am Post subject: |
|
|
| Renkokuken wrote: | | oib111 wrote: | Lol. Dude...
| Code: |
Form1->Edit1->Text[i]
|
xD!!! This isn't delphi. There is no Form1, Edit1, Text...lol. Even if you're using MFC you don't even do it like that. Btw, you realize that you can just go
| He uses Borland C++, I believe. |
Yep im Borland Developer Studio, you rlly think i wouldnt know that C++ mostly doesnt uses delphi forms?lol.
Soo anyone can help? _________________
Gone |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 08, 2008 8:53 am Post subject: |
|
|
Wtf, you can do that. That's pretty stupid. No offense, I'm just saying, you're practically taking the fun out of C++. Now instead of getting text like this...
| Code: |
char *buffer;
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT));
if(len > 0) {
buffer = (char*)GlobalAlloc(GPTR, len+1);
GetDlgItemText(hwnd, IDC_EDIT, buffer, len+1);
}
|
You can do it so easily like this...
| Code: |
buffer = Form1->Edit1->Text;
|
It's just not fun. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Sun Jun 08, 2008 8:56 am Post subject: |
|
|
| oib111 wrote: | Wtf, you can do that. That's pretty stupid. No offense, I'm just saying, you're practically taking the fun out of C++. Now instead of getting text like this...
| Code: |
char *buffer;
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT));
if(len > 0) {
buffer = (char*)GlobalAlloc(GPTR, len+1);
GetDlgItemText(hwnd, IDC_EDIT, buffer, len+1);
}
|
You can do it so easily like this...
| Code: |
buffer = Form1->Edit1->Text;
|
It's just not fun. | While I do not like Borland products, that's not a good way to judge anything. Pretty much, you're telling him to reinvent the wheel, while there is a provided method for him to use. Not a good attitude at all. |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Sun Jun 08, 2008 9:04 am Post subject: |
|
|
| oib111 wrote: | Wtf, you can do that. That's pretty stupid. No offense, I'm just saying, you're practically taking the fun out of C++. Now instead of getting text like this...
| Code: |
char *buffer;
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT));
if(len > 0) {
buffer = (char*)GlobalAlloc(GPTR, len+1);
GetDlgItemText(hwnd, IDC_EDIT, buffer, len+1);
}
|
You can do it so easily like this...
| Code: |
buffer = Form1->Edit1->Text;
|
It's just not fun. |
eXidis codes like that...
kiki codes like that...
smartz codes like that...
You are sayng we are all wrong?
Why use a car when i have an airplane?
Sooo OK
CAN ANYONE ACTUALY HELP WITH THE FUNCTION AND NOT KEEP ARGUING INSTEAD? _________________
Gone |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 08, 2008 9:05 am Post subject: |
|
|
I'm just saying I like the old method better, more fun to code. Other thing takes away from the "coding experience." _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Jun 08, 2008 9:06 am Post subject: |
|
|
Tokenize the string for space's and add them all into the array in a loop? _________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Jun 08, 2008 9:32 am Post subject: |
|
|
"for" loop string length / 3 and scan "%X "?  |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Sun Jun 08, 2008 11:07 am Post subject: |
|
|
Can anyone post a code snippet? _________________
Gone |
|
| Back to top |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
Posted: Sun Jun 08, 2008 12:32 pm Post subject: |
|
|
StrToByteArray(offset text, offset outputbuffer):output buffer length
MASM: | Code: | StrToByteArray proc lpText,lpBuffer
invoke lstrlen,lpText
push eax
;Trims the spaces
mov ecx,eax
mov eax,20h
@@:
mov edi,lpText
repne scasb
jnz @F
mov esi,edi
dec edi
inc ecx
rep movsb
dec dword ptr [esp]
mov ecx,[esp]
jmp @B
@@:
;To upper case
invoke CharUpperBuff,lpText,[esp]
mov ecx,[esp]
;Converting
mov edi,lpBuffer
mov esi,lpText
@@:
mov ah,byte ptr [esi]
.if ( ah < 3Ah)
sub ah,30h
.else
sub ah,37h
.endif
mov al,ah
shl al,4
mov ah,byte ptr [esi+1]
.if ( ah < 3Ah)
sub ah,30h
.else
sub ah,37h
.endif
add al,ah
mov byte ptr [edi],al
inc edi
add esi,2
sub dword ptr [esp],2
jnz @B
pop [esp-4]
mov eax,ecx
shr eax,1
pop ebp
retn 08
StrToByteArray endp |
Pseudo C: | Code: |
unsigned int __stdcall StrToByteArray(LPCSTR lpsz,int a2)
{
char v2; // zf@1
unsigned __int32 v3; // ecx@1
DWORD v4; // ST08_4@1
LPCSTR v5; // edi@2
unsigned int v6; // ecx@8
int v7; // edi@8
LPCSTR v8; // esi@8
const CHAR v9; // ah@9
char v10; // ah@10
char v11; // al@12
unsigned __int8 v12; // ah@12
char v13; // ah@13
int v15; // eax@1
char v16; // zf@15
v15 = lstrlenA(lpsz);
v4 = v15;
v3 = v15;
while ( 1 )
{
v5 = lpsz;
do
{
if ( !v3 )
break;
v2 = *v5++ == 32;
--v3;
}
while ( !v2 );
if ( !v2 )
break;
memcpy((void *)(v5 - 1), v5, v3 + 1);
v2 = v4-- == 1;
v3 = v4;
}
CharUpperBuffA((LPSTR)lpsz, v4);
v6 = v4;
v7 = a2;
v8 = lpsz;
do
{
v9 = *v8;
if ( (unsigned __int8)*v8 >= 0x3Au )
v10 = v9 - 55;
else
v10 = v9 - 48;
v11 = 16 * v10;
v12 = *(v8 + 1);
if ( v12 >= 0x3Au )
v13 = v12 - 55;
else
v13 = v12 - 48;
*(_BYTE *)v7++ = v13 + v11;
v8 += 2;
v16 = v4 == 2;
v4 -= 2;
}
while ( !v16 );
return v6 >> 1;
} |
Last edited by DoomsDay on Sun Jun 08, 2008 11:24 pm; edited 1 time in total |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jun 08, 2008 1:49 pm Post subject: |
|
|
| Code: | | char * bytaz = szString |
or, if you're keeping track of the array length or want to check for a null terminator in the char array, make the char array larger than you will need.
| Code: | | char[100] bytaz = szString |
_________________
|
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Sun Jun 08, 2008 3:45 pm Post subject: |
|
|
| HalfPrime wrote: | | Code: | | char * bytaz = szString |
or, if you're keeping track of the array length or want to check for a null terminator in the char array, make the char array larger than you will need.
| Code: | | char[100] bytaz = szString |
|
Ok i used
| Code: | char *bytaz = Edit1->Text.c_str();
DWORD addy = 0x887755;
if (CheckBox1->Checked == true)
{
for (int i = 0; i <= Edit1->Text.Length()+1; i=i+3)
{
*(BYTE*)addy = bytaz[i];
addy++;
}
}
|
But it writes as ASCII =/
I need it to write the bytes from the text box not the text
Anyone can help? _________________
Gone |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
|
| 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
|
|