Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Request] Help with C++ String -> Char Array
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Sun Jun 08, 2008 6:21 pm    Post subject: Reply with quote

HalfPrime wrote:
Was there something wrong with your previous thread that you had to repost?
http://forum.cheatengine.org/viewtopic.php?t=246296
xor gave you a method, wiccaan gave you code.


That one wasnt good, bad explained.
x0r give me the method but i have no idea on how it works, also wiccaan code doesnt works for my purpose.

Anyone can help me w/ the code?

_________________
Gone
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jun 08, 2008 6:45 pm    Post subject: Reply with quote

Lol. Did you look up x0rs method on msdn? Because that should explain it pretty well. Or ask someone that knows how it works.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sun Jun 08, 2008 9:22 pm    Post subject: Reply with quote

Goddamn. Shit like this is why MSers should be confined to the MS section. That solution wasn't good enough for you, so you need some spoon feeding?

Code:
BYTE conv(char *ch){
char c;
if(ch[0]>='0' && ch[0] <='9'){ch[0] -= 48;}else
if(ch[0]>='A' && ch[0] <='Z'){ch[0] -= 50;}else
if(ch[0]>='a' && ch[0] <='z'){ch[0] -= 81;}
c = ch[0]*16;
if(ch[1]>='0' && ch[1] <='9'){ch[1] -= 48;}else
if(ch[1]>='A' && ch[1] <='Z'){ch[1] -= 50;}else
if(ch[1]>='a' && ch[1] <='z'){ch[1] -= 81;}
c +=ch[1];
return c;}

main:
string str = "";
for(int c=0;c<(szString.length()+1)/3;c+=3)
str += conv(&szString[c]);


Enjoy some shit code. Now, leave if you can't look up 2 commands. And please don't come back if all you want is a handout.

_________________
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Mon Jun 09, 2008 12:30 am    Post subject: Reply with quote

GMZorita, I really suggest you to look at an ASCII table. Anyways, the pseudo I gave you should work just fine.
I added comments if you wish to understnd the algorithm better:
Code:
StrToByteArray   proc   lpText,lpBuffer
      invoke   lstrlen,lpText      ;Get the length of the text buffer
      push   eax               ;Store it in the stack > [ESP]
      ;Trims the spaces
      mov      ecx,eax            ;ECX now contains the buffer length
      mov      eax,20h            ;EAX now contains the space char - ' '
      @@:
      mov      edi,lpText         ;EDI(dest) leads to the given text buffer
      repne   scasb            ;scasb scans for al for [edi+n] ecx times.
                           ;with repne: for (;ECX > 0; ECX--){if (EAX.LOWBYTE == BYTE PTR [EDI]){BREAK}}
      jnz      @F               ;did not break from the loop? No spaces here :D
         mov      esi,edi            ;EDI points to the letter AFTER the space, MOV'd to ESI(source)
         dec      edi               ;EDI now points to the space
         inc      ecx               ;ECX points to the last char, I want it to point to the null-terminator (0)
         rep      movsb            ;Copies the string, byte by byte, n(=ECX) times
         dec      dword ptr [esp]      ;[ESP] contains the buffer length pushed earlier, decreased by one
         mov      ecx,[esp]         ;ECX now contains the 'updated' length (length -= 1)
         jmp      @B               ;jumps backwards to '@@:'
      @@:
      ;To upper-case
      invoke   CharUpperBuff,lpText,[esp];self-explained
      mov      ecx,[esp]            ;*Holds the length(as it's going to get modified)
      ;Converting                                                      ;Exampe: '3B'
      mov      edi,lpBuffer         ;EDI (dest) now points to the output buffer
      mov      esi,lpText            ;ESI (source) now points to the text buffer
      @@:
      mov      ah,byte ptr [esi]      ;ah = temp, al = byte | ah <- byte ptr [ESI+nS] | ah {0x33} | ASCII '3'
      .if ( ah < 3Ah)               ;if the byte is a digit                     | true
         sub      ah,30h            ;ASCII numerial to number   (-0x30)            | ah {0x03}
      .else
         sub      ah,37h            ;ASCII char ('A'-'F')      (-0x37)
      .endif
      mov      al,ah               ;al (result byte) <- ah (temp byte)            | al {0x03}
      shl      al,4               ;next nibble (al *= 0x10)                  | al {0x30}
      mov      ah,byte ptr [esi+1]      ;ah <- byte ptr [ESI+nS+1]                  | ah {0x42} | ASCII 'B'
      .if ( ah < 3Ah)               ;                                    | false
         sub      ah,30h
      .else
         sub      ah,37h            ;                                    | ah {0x0B}
      .endif
      add      al,ah               ;Adds the temp nibble to AL                  | al {0x3B}
      mov      byte ptr [edi],al      ;Moves AL to [EDI+nD]
      inc      edi                  ;nD +=1
      add      esi,2               ;nS +=2
      sub      dword ptr [esp],2      ;length -=2
      jnz      @B                  ;if !(length == 0) go backwards to '@@:'
      pop      [esp-4]               ;The length was held in the stack, time to remove it
      mov      eax,ecx               ;The length held earlier*
      shr      eax,1               ;length /= 2 (the output buffer's length)
   pop      ebp
   retn   08                     ;Return length
StrToByteArray endp
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Mon Jun 09, 2008 11:39 am    Post subject: Reply with quote

HalfPrime wrote:
Goddamn. Shit like this is why MSers should be confined to the MS section. That solution wasn't good enough for you, so you need some spoon feeding?

Code:
BYTE conv(char *ch){
char c;
if(ch[0]>='0' && ch[0] <='9'){ch[0] -= 48;}else
if(ch[0]>='A' && ch[0] <='Z'){ch[0] -= 50;}else
if(ch[0]>='a' && ch[0] <='z'){ch[0] -= 81;}
c = ch[0]*16;
if(ch[1]>='0' && ch[1] <='9'){ch[1] -= 48;}else
if(ch[1]>='A' && ch[1] <='Z'){ch[1] -= 50;}else
if(ch[1]>='a' && ch[1] <='z'){ch[1] -= 81;}
c +=ch[1];
return c;}

main:
string str = "";
for(int c=0;c<(szString.length()+1)/3;c+=3)
str += conv(&szString[c]);


Enjoy some shit code. Now, leave if you can't look up 2 commands. And please don't come back if all you want is a handout.


Stop being stupid, keep your opnion to yourself, im pretty sure no one cares about what you think.
Thanks for the function anyway i will try it.

DoomsDay wrote:
GMZorita, I really suggest you to look at an ASCII table. Anyways, the pseudo I gave you should work just fine.
I added comments if you wish to understnd the algorithm better:
Code:
StrToByteArray   proc   lpText,lpBuffer
      invoke   lstrlen,lpText      ;Get the length of the text buffer
      push   eax               ;Store it in the stack > [ESP]
      ;Trims the spaces
      mov      ecx,eax            ;ECX now contains the buffer length
      mov      eax,20h            ;EAX now contains the space char - ' '
      @@:
      mov      edi,lpText         ;EDI(dest) leads to the given text buffer
      repne   scasb            ;scasb scans for al for [edi+n] ecx times.
                           ;with repne: for (;ECX > 0; ECX--){if (EAX.LOWBYTE == BYTE PTR [EDI]){BREAK}}
      jnz      @F               ;did not break from the loop? No spaces here :D
         mov      esi,edi            ;EDI points to the letter AFTER the space, MOV'd to ESI(source)
         dec      edi               ;EDI now points to the space
         inc      ecx               ;ECX points to the last char, I want it to point to the null-terminator (0)
         rep      movsb            ;Copies the string, byte by byte, n(=ECX) times
         dec      dword ptr [esp]      ;[ESP] contains the buffer length pushed earlier, decreased by one
         mov      ecx,[esp]         ;ECX now contains the 'updated' length (length -= 1)
         jmp      @B               ;jumps backwards to '@@:'
      @@:
      ;To upper-case
      invoke   CharUpperBuff,lpText,[esp];self-explained
      mov      ecx,[esp]            ;*Holds the length(as it's going to get modified)
      ;Converting                                                      ;Exampe: '3B'
      mov      edi,lpBuffer         ;EDI (dest) now points to the output buffer
      mov      esi,lpText            ;ESI (source) now points to the text buffer
      @@:
      mov      ah,byte ptr [esi]      ;ah = temp, al = byte | ah <- byte ptr [ESI+nS] | ah {0x33} | ASCII '3'
      .if ( ah < 3Ah)               ;if the byte is a digit                     | true
         sub      ah,30h            ;ASCII numerial to number   (-0x30)            | ah {0x03}
      .else
         sub      ah,37h            ;ASCII char ('A'-'F')      (-0x37)
      .endif
      mov      al,ah               ;al (result byte) <- ah (temp byte)            | al {0x03}
      shl      al,4               ;next nibble (al *= 0x10)                  | al {0x30}
      mov      ah,byte ptr [esi+1]      ;ah <- byte ptr [ESI+nS+1]                  | ah {0x42} | ASCII 'B'
      .if ( ah < 3Ah)               ;                                    | false
         sub      ah,30h
      .else
         sub      ah,37h            ;                                    | ah {0x0B}
      .endif
      add      al,ah               ;Adds the temp nibble to AL                  | al {0x3B}
      mov      byte ptr [edi],al      ;Moves AL to [EDI+nD]
      inc      edi                  ;nD +=1
      add      esi,2               ;nS +=2
      sub      dword ptr [esp],2      ;length -=2
      jnz      @B                  ;if !(length == 0) go backwards to '@@:'
      pop      [esp-4]               ;The length was held in the stack, time to remove it
      mov      eax,ecx               ;The length held earlier*
      shr      eax,1               ;length /= 2 (the output buffer's length)
   pop      ebp
   retn   08                     ;Return length
StrToByteArray endp

I will re-try it later, and thx for explaining the code .

_________________
Gone
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites