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 ... 11, 12, 13
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Mon Apr 07, 2008 1:16 am    Post subject: Reply with quote

SKAN wrote:
I have adapted the machine code...
Clever!
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Mon Apr 07, 2008 7:33 am    Post subject: Reply with quote

Smile

.. and I was using your BSwap mcode like this:

Code:
  bs16 := chr(138) chr(225) chr(138) chr(197) chr(195)             ; Laszlo's bswap16
  bs32 := chr(139) chr(193) chr(015) chr(200) chr(195)             ; Laszlo's bswap32
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Fri Jun 20, 2008 2:47 pm    Post subject: Reply with quote

First of all, Thanks Laszlo for providing machine code world to ahk.
although i had 0% knowledge of machine code i'd like to try it.
currently i'm trying to make ID3 tag extractor() using mcode. (bin2hex)
it was successful but i want it to run by 100% mcode powered Smile
will there be any chance to get mcode for Hex2Chr()? or even Bin2Chr()

Thanks in advance !
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1354

PostPosted: Fri Jun 20, 2008 4:14 pm    Post subject: Reply with quote

I would also very much like to see that function, and please if someone does could I see the source code as well Smile
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Fri Jun 20, 2008 4:31 pm    Post subject: Reply with quote

What should these functions exactly do? E.g., should Hex2Chr ignore any non-printable characters from a hex stream, and provide an AHK string as the result? If you know that all characters are printable, Hex2Bin does the same. You only have to update the variable's internally-stored length to the length of its current contents with VarSetCapacity(Bin,-1). If you want to stop at the first NUL, the above VarSetCapacity call will set the length correctly, after you copied a long enough chunk of the data.

You might be better served with DllCall("RtlMoveMemory"… or a string copy function of the C runtime library: msvcrt, to avoid the hex conversion intermediate step.
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Fri Jun 20, 2008 4:57 pm    Post subject: Reply with quote

For example i got this hexes from the mp3 file
Code:
;about 30 bytes only
hex := 46756E6E792053746172000000000000000000000000000000000000000

and i used below loop for Hex2Chr
Code:
Loop, 60 ;hex passed to this loop
    If Mod(A_Index,2)=1
        Title .= Chr("0x" . SubStr(Hex, A_Index,2))

i'd like to make whole processes to be proceed by MCode for speed.
and i know that it can be accomplished without MCode but for learning purpose
does it make clear? However thanks for quick answer.
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Fri Jun 20, 2008 5:33 pm    Post subject: Reply with quote

The Hex2Bin function does it:
Code:
hex = 46756E6E792053746172000000000000000000000000000000000000000

Loop 60
   If A_Index & 1
      Title .= Chr("0x" . SubStr(Hex, A_Index,2))
MsgBox %Title%

MCode(Hex2Bin,"568b74240c8a164684d2743b578b7c240c538ac2c0e806b109f6e98ac802cac0e10"
. "4880f8a164684d2741a8ac2c0e806b309f6eb80e20f02c20ac188078a16474684d275cd5b5f5ec3")

VarSetCapacity(Title, ceil(StrLen(hex)/2))
DllCall(&Hex2Bin, "UInt",&Title, "UInt",&hex, "CDECL")
VarSetCapacity(Title, -1)
MsgBox %Title%

MCode(ByRef code, hex) { ; allocate memory and write Machine Code there
   VarSetCapacity(code,StrLen(hex)//2)
   Loop % StrLen(hex)//2
      NumPut("0x" . SubStr(hex,2*A_Index-1,2), code, A_Index-1, "Char")
}
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Fri Jun 20, 2008 5:57 pm    Post subject: Reply with quote

Cool! i never knew that i already have enough functions to do so.
i'm gonna decode your code. Smile

Thanks for sharing your experience, knowledge, skills as always!
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
GuestAHK
Guest





PostPosted: Sun Jun 22, 2008 7:16 am    Post subject: Reply with quote

Laszlo wrote:
I guess IsWindowVisible was just an example.

If you want to call a dll function from within a machine code function, you probably need some extra system calls (like "LoadLibrary", which loads the desired function into memory, and then search for the address of the function). I have not tried, but it should be possible. A simpler solution could be to break up the machine code to stand alone pieces and use AHK's dllcall in between to call the needed external functions.


Hello, I am following along this thread, and wondering -- has it been proven to somehow load a DLL from memory?
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Jun 22, 2008 3:11 pm    Post subject: Reply with quote

GuestAHK wrote:
has it been proven to somehow load a DLL from memory?
I don't know if it was done with AHK, but Lexikos pointed to a C solution (a mini loader) http://www.joachim-bauch.de/tutorials/load_dll_memory.html/en.
Back to top
View user's profile Send private message
GuestAHK
Guest





PostPosted: Mon Jun 23, 2008 8:54 pm    Post subject: Reply with quote

Quite interesting at that link Exclamation ....I wonder if it is possible, or anyone attempted yet to translate this concept to AHK with any kind of success? Seen any work in that direction? It is certainly way beyond my skill level there, ... but I think it would be a very interesting way to manage script dependency resources. Very Happy
Back to top
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Thu Jun 26, 2008 1:13 pm    Post subject: Reply with quote

It would be very useful to translate this to AHK.
The actuall C moudle is only 400 code lines and it shouldn't be very hard to translate it to AHK by the person who knows what is doing.
The good thing is that module is well tested as its used in py2exe.

The problem is that this task is lengthy and errorpone as bunch of large structures are used. Lexikos struct parser would be very helpfull. Few C macros need to be translated to, but generally, it isn't hard to translate this code even without understanding at all what is it about.
_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 11, 12, 13
Page 13 of 13

 
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