AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Machine code functions: Bit Wizardry
Goto page Previous  1, 2, 3 ... 19, 20, 21, 22, 23, 24  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
TheGood



Joined: 30 Jul 2007
Posts: 580

PostPosted: Fri Jul 30, 2010 8:52 pm    Post subject: Reply with quote

ddk wrote:
I changed my OS to my nlited XP and since then I've had problems with bin2hex function:
Code:
MCode(Bin2Hex,"8B4C2404578B7C241085FF7E2F568B7424108A06C0E8042C0A8AD0C0EA052AC2044188018A06240F2C0A8AD0C0EA052AC2410441468801414F75D75EC601005FC3")

bin := "abc", VarSetCapacity(hex,9)
dllcall(&Bin2Hex, "uint",&hex, "uint",&bin, "uint",4, "cdecl")
VarSetCapacity(hex,-1) ; update StrLen
MsgBox %hex%           ; 31323300

That example returns me 4 boxes:
Code:
ㄶ〰㈶〰

And I guess that's not right Rolling Eyes I've also tried standalone version of bin2hex and not working, also tried the BinToHex.dll. My AHK version is 1.0.48.05.L52H20.


It seems like you're using a unicode build of AHK. Try using the Bin2Hex here instead.
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Fri Jul 30, 2010 8:58 pm    Post subject: Reply with quote

I got "61626300". The culprit could be the editor, too, if it saves the ahk file in other than pure ANSI/ASCII format.
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Fri Jul 30, 2010 9:55 pm    Post subject: Reply with quote

TheGood wrote:
ddk wrote:
I changed my OS to my nlited XP and since then I've had problems with bin2hex function:
Code:
MCode(Bin2Hex,"8B4C2404578B7C241085FF7E2F568B7424108A06C0E8042C0A8AD0C0EA052AC2044188018A06240F2C0A8AD0C0EA052AC2410441468801414F75D75EC601005FC3")

bin := "abc", VarSetCapacity(hex,9)
dllcall(&Bin2Hex, "uint",&hex, "uint",&bin, "uint",4, "cdecl")
VarSetCapacity(hex,-1) ; update StrLen
MsgBox %hex%           ; 31323300

That example returns me 4 boxes:
Code:
ㄶ〰㈶〰

And I guess that's not right Rolling Eyes I've also tried standalone version of bin2hex and not working, also tried the BinToHex.dll. My AHK version is 1.0.48.05.L52H20.


It seems like you're using a unicode build of AHK. Try using the Bin2Hex here instead.

If I used it right, it returns empty. As an editor I use latest Scite.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Fri Jul 30, 2010 9:59 pm    Post subject: Reply with quote

- What is the encoding the latest Scite used for the script file?
- This tool was developed for AHK. You seem to use AHK_L, so post your question there.


Last edited by Laszlo on Fri Jul 30, 2010 10:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Fri Jul 30, 2010 10:02 pm    Post subject: Reply with quote

Laszlo wrote:
- What is the encoding the latest Scite used for the script file?
- What AHK version did you use to run the script?

- "Code Page Property"
- As said above: My AHK version is 1.0.48.05.L52H20.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Fri Jul 30, 2010 10:05 pm    Post subject: Reply with quote

(you answered while I was editing my response... If you use AHK_L, post your question there. I don't have it.)
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4653
Location: AHK Forum

PostPosted: Fri Jul 30, 2010 10:11 pm    Post subject: Reply with quote

@ddk
It is due to Unicode.
You will need to use StrGet()
Code:
MCode(Bin2Hex,"8B44240C568B742408578B7C24108D14073BFA7332538A07478AC8C0E904B3093AD91ADB80E30780C3"
. "3002D9240F881E46B1093AC81AC980E10780C13002C8880E463BFA72D05B5FC606005EC3")


VarSetCapacity(hex,9)
VarSetCapacity(bin,12)
StrPut("123",&bin,3,"CP0")

dllcall(&Bin2Hex, "uint",&hex, "uint",&bin, "uint",4, "cdecl")
VarSetCapacity(hex,-1) ; update StrLen
MsgBox % StrGet(&hex,"CP0")           ; 31323300

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink


Last edited by HotKeyIt on Fri Jul 30, 2010 11:05 pm; edited 2 times in total
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Fri Jul 30, 2010 10:14 pm    Post subject: Reply with quote

HotKeyIt wrote:
@ddk
It is due to Unicode.
You will need to use StrGet()
Code:
MCode(Bin2Hex,"8B44240C568B742408578B7C24108D14073BFA7332538A07478AC8C0E904B3093AD91ADB80E30780C3"
. "3002D9240F881E46B1093AC81AC980E10780C13002C8880E463BFA72D05B5FC606005EC3")

bin := "123", VarSetCapacity(hex,9)
dllcall(&Bin2Hex, "uint",&hex, "uint",&bin, "uint",4, "cdecl")
VarSetCapacity(hex,-1) ; update StrLen
MsgBox % StrGet(&hex,"UTF-8")           ; 31323300

Well, looking good, but it doesn't return 31323300 - it returns 31003200, which is "12" tho?
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4653
Location: AHK Forum

PostPosted: Fri Jul 30, 2010 11:04 pm    Post subject: Reply with quote

Try above again, we need to use StrPut("123",...).
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Fri Jul 30, 2010 11:30 pm    Post subject: Reply with quote

HotKeyIt wrote:
Try above again, we need to use StrPut("123",...).

Works, thanks again HotkeyIt, you are my savior Wink
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Thu Aug 12, 2010 5:49 pm    Post subject: Reply with quote

Hi again,

I tired to make a function of HotKeyIt's example, but Im getting random letters after decoding. My fucntion:
Code:
Bin2HexUni(hexa="") {
   len := StrLen(hexa)
   MCode(Bin2Hex,"8B44240C568B742408578B7C24108D14073BFA7332538A07478AC8C0E904B3093AD91ADB80E30780C3"
   . "3002D9240F881E46B1093AC81AC980E10780C13002C8880E463BFA72D05B5FC606005EC3")

   VarSetCapacity(hex,2*len)
   VarSetCapacity(bin,len)
   StrPut(hexa,&bin,len,"CP0")
   dllcall(&Bin2Hex, "uint",&hex, "uint",&bin, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
      return StrGet(&hex,"CP0")           ; 31323300
}
Back to top
View user's profile Send private message
fincs



Joined: 05 May 2007
Posts: 1163
Location: Seville, Spain

PostPosted: Thu Aug 12, 2010 6:01 pm    Post subject: Reply with quote

There is no such thing as a hex representation of text. First you need to encode it. ANSI builds default to the default system code page (CP0, usually Windows-1252 but may be a creepy multibyte codepage such as Shift-JIS for Japanese computers), Unicode builds default to UTF-16.
_________________
fincs
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]
Back to top
View user's profile Send private message
TheGood



Joined: 30 Jul 2007
Posts: 580

PostPosted: Wed Aug 18, 2010 12:30 am    Post subject: Reply with quote

Here is a version of Bin2Hex which works on AHK_L x86/x64 ANSI/Unicode and vanilla AHK:

Code:
;By Laszlo
;http://www.autohotkey.com/forum/viewtopic.php?p=135522#135522
Bin2Hex(addr,len) {
    Static fun, ptr
    If (fun = "") {
        If A_IsUnicode
            If (A_PtrSize = 8)
                h=4533c94c8bd14585c07e63458bd86690440fb60248ffc2418bc9410fb6c0c0e8043c090fb6c00f97c14180e00f66f7d96683e1076603c8410fb6c06683c1304180f8096641890a418bc90f97c166f7d94983c2046683e1076603c86683c13049ffcb6641894afe75a76645890ac366448909c3
            Else h=558B6C241085ED7E5F568B74240C578B7C24148A078AC8C0E90447BA090000003AD11BD2F7DA66F7DA0FB6C96683E2076603D16683C230668916240FB2093AD01BC9F7D966F7D96683E1070FB6D06603CA6683C13066894E0283C6044D75B433C05F6689065E5DC38B54240833C966890A5DC3
        Else h=558B6C241085ED7E45568B74240C578B7C24148A078AC8C0E9044780F9090F97C2F6DA80E20702D1240F80C2303C090F97C1F6D980E10702C880C1308816884E0183C6024D75CC5FC606005E5DC38B542408C602005DC3
        VarSetCapacity(fun, StrLen(h) // 2)
        Loop % StrLen(h) // 2
            NumPut("0x" . SubStr(h, 2 * A_Index - 1, 2), fun, A_Index - 1, "Char")
        ptr := A_PtrSize ? "Ptr" : "UInt"
        DllCall("VirtualProtect", ptr, &fun, ptr, VarSetCapacity(fun), "UInt", 0x40, "UInt*", 0)
    }
    VarSetCapacity(hex, A_IsUnicode ? 4 * len + 2 : 2 * len + 1)
    DllCall(&fun, ptr, &hex, ptr, addr, "UInt", len, "CDecl")
    VarSetCapacity(hex, -1) ; update StrLen
    Return hex
}

It is based on Laszlo's fastest implementation and is optimized for speed.
Back to top
View user's profile Send private message Visit poster's website
AlexeiK



Joined: 12 Aug 2010
Posts: 3

PostPosted: Thu Aug 19, 2010 9:46 am    Post subject: Reply with quote

hi
can u help me?
http://www.d3scene.com/forum/warcraft-3-hacks/42374-warcraft-3-memory-reading-dota-hero-level-where-address-my-hero-2.html#post327779
i have this advice to read some data from warcraft3 proccess
how it can be done with ur script?
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Sat Aug 21, 2010 2:39 pm    Post subject: Reply with quote

TheGood wrote:
Here is a version of Bin2Hex which works on AHK_L x86/x64 ANSI/Unicode and vanilla AHK:

Code:
;By Laszlo
;http://www.autohotkey.com/forum/viewtopic.php?p=135522#135522
Bin2Hex(addr,len) {
    Static fun, ptr
    If (fun = "") {
        If A_IsUnicode
            If (A_PtrSize = 8)
                h=4533c94c8bd14585c07e63458bd86690440fb60248ffc2418bc9410fb6c0c0e8043c090fb6c00f97c14180e00f66f7d96683e1076603c8410fb6c06683c1304180f8096641890a418bc90f97c166f7d94983c2046683e1076603c86683c13049ffcb6641894afe75a76645890ac366448909c3
            Else h=558B6C241085ED7E5F568B74240C578B7C24148A078AC8C0E90447BA090000003AD11BD2F7DA66F7DA0FB6C96683E2076603D16683C230668916240FB2093AD01BC9F7D966F7D96683E1070FB6D06603CA6683C13066894E0283C6044D75B433C05F6689065E5DC38B54240833C966890A5DC3
        Else h=558B6C241085ED7E45568B74240C578B7C24148A078AC8C0E9044780F9090F97C2F6DA80E20702D1240F80C2303C090F97C1F6D980E10702C880C1308816884E0183C6024D75CC5FC606005E5DC38B542408C602005DC3
        VarSetCapacity(fun, StrLen(h) // 2)
        Loop % StrLen(h) // 2
            NumPut("0x" . SubStr(h, 2 * A_Index - 1, 2), fun, A_Index - 1, "Char")
        ptr := A_PtrSize ? "Ptr" : "UInt"
        DllCall("VirtualProtect", ptr, &fun, ptr, VarSetCapacity(fun), "UInt", 0x40, "UInt*", 0)
    }
    VarSetCapacity(hex, A_IsUnicode ? 4 * len + 2 : 2 * len + 1)
    DllCall(&fun, ptr, &hex, ptr, addr, "UInt", len, "CDecl")
    VarSetCapacity(hex, -1) ; update StrLen
    Return hex
}

It is based on Laszlo's fastest implementation and is optimized for speed.


Ah, thanks for this. I cant test it now, but if it's Laszlo it will be fine Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 19, 20, 21, 22, 23, 24  Next
Page 20 of 24

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group