 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Fri Jul 30, 2010 8:52 pm Post subject: |
|
|
| 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:
And I guess that's not right 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Jul 30, 2010 8:58 pm Post subject: |
|
|
| 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 |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Fri Jul 30, 2010 9:55 pm Post subject: |
|
|
| 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:
And I guess that's not right 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Jul 30, 2010 9:59 pm Post subject: |
|
|
- 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 |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Fri Jul 30, 2010 10:02 pm Post subject: |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Jul 30, 2010 10:05 pm Post subject: |
|
|
| (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 |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4653 Location: AHK Forum
|
Posted: Fri Jul 30, 2010 10:11 pm Post subject: |
|
|
@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 
Last edited by HotKeyIt on Fri Jul 30, 2010 11:05 pm; edited 2 times in total |
|
| Back to top |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Fri Jul 30, 2010 10:14 pm Post subject: |
|
|
| 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 |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4653 Location: AHK Forum
|
|
| Back to top |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Fri Jul 30, 2010 11:30 pm Post subject: |
|
|
| HotKeyIt wrote: | | Try above again, we need to use StrPut("123",...). |
Works, thanks again HotkeyIt, you are my savior  |
|
| Back to top |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Thu Aug 12, 2010 5:49 pm Post subject: |
|
|
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 |
|
 |
fincs
Joined: 05 May 2007 Posts: 1163 Location: Seville, Spain
|
Posted: Thu Aug 12, 2010 6:01 pm Post subject: |
|
|
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 |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Wed Aug 18, 2010 12:30 am Post subject: |
|
|
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 |
|
 |
AlexeiK
Joined: 12 Aug 2010 Posts: 3
|
|
| Back to top |
|
 |
ddk
Joined: 28 Dec 2009 Posts: 43
|
Posted: Sat Aug 21, 2010 2:39 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|