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 ... 5, 6, 7 ... 22, 23, 24  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Laszlo



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

PostPosted: Tue Sep 25, 2007 4:36 am    Post subject: Reply with quote

Cool! With the pre-computed table this works fast!

An application is to find duplicate files, even if they have different names. Compute the CRC of the files and attach them to the file size, stored in AHK variables. Sort them and search for equal ones (which got next to each other). We only have to compare files byte-by-byte, which have equal {file_size, CRC} pairs, which happen very rarely for different files.
Back to top
View user's profile Send private message
Thalon



Joined: 12 Jul 2005
Posts: 633

PostPosted: Tue Sep 25, 2007 7:02 am    Post subject: Reply with quote

tic wrote:
it would be nice if ahk could also handle C code being written directly to it, similar to calling assembler within C++
Something similiar to this?

I'm very interested in this topic as it shows some nice things.
I've never tried to convert C-Code in Hex-Equivalent, I always did it directly in ASM (and to be honestly: I'm at ASM-Beginner-Level).

Another interesting aspect would be to add features (or to solve bugs) to applications without source available (of course, the autor has to give the permission). I've a bit experience in this topic, but it could be much easier now (if using AHK for these things).
Does anyone know an application that shows C-Source out of ASM? I know I had a tool from "Keil" in school, but this one had a very limited command-list...

Thalon
_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Tue Sep 25, 2007 10:29 am    Post subject: Reply with quote

Thsnks Thalon. I'll have a look.

That examle crc32 doesnt work for me as there is a call to a non-existant function MCode(CRC32_Init,.....
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Tue Sep 25, 2007 1:40 pm    Post subject: Reply with quote

tic: Copy over the MCode() function from the first post.
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Tue Sep 25, 2007 2:05 pm    Post subject: Reply with quote

Quote:
tic: Copy over the MCode() function from the first post.


ha! cheers. hadnt looked at the 1st page. ill give the crc32 a good old test now as i can think of a very good use for it for the program MOVEit i wrote a while ago, as well as using ReadDirectoryChangesW to completely cut down on the rescanning it does. thanks all
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Tue Sep 25, 2007 4:18 pm    Post subject: Reply with quote

I don't really have time where I am to try figure this out, but why do both of these pieces of code give res as 4294967295?

Code:
#NoEnv

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")
}

MCode(CRC32_Init, "5589E583EC10C745FC2083B8EDC745F400000000817DF4FF0000007F508B45F48945F8C745F008000000837DF0007E238B45F883"
. "E00185C0740D8B45F8D1E83345FC8945F8EB058D45F8D1288D45F0FF08EBD78B45F48D0C85000000008B55088B45F88904118D45F4FF00EBA7C9C3")
MCode(CRC32_Get, "5589E583EC08C745FCFFFFFFFFC745F8000000008B45F83B450C732E8B45080345F80FB6003345FC25FF0000008D0C85000000008"
. "B55108B45FCC1E8083304118945FC8D45F8FF00EBCA8B45FCC9C3")

FileRead, a, %A_AhkPath%
FileGetSize, size, %A_AhkPath%
res := DllCall(&CRC32_Get, "uint",&a, "uint",size, "uint",&CRC32LookupTable)
Display()

Display()
{
global res
IfLess, res, 0x104C11DB7
  res := ~res
IfGreater, res, 0x104C11DB7
  res := res ^ 0xFFFFFFFF
MsgBox % res
return
}


and

Code:
#NoEnv

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")
}

MCode(CRC32_Init, "5589E583EC10C745FC2083B8EDC745F400000000817DF4FF0000007F508B45F48945F8C745F008000000837DF0007E238B45F883"
. "E00185C0740D8B45F8D1E83345FC8945F8EB058D45F8D1288D45F0FF08EBD78B45F48D0C85000000008B55088B45F88904118D45F4FF00EBA7C9C3")
MCode(CRC32_Get, "5589E583EC08C745FCFFFFFFFFC745F8000000008B45F83B450C732E8B45080345F80FB6003345FC25FF0000008D0C85000000008"
. "B55108B45FCC1E8083304118945FC8D45F8FF00EBCA8B45FCC9C3")

FileRead, a, %A_AhkPath%
FileGetSize, size, %A_AhkPath%
res := DllCall(&CRC32_Get, "uint",&a, "uint",size, "uint",&CRC32LookupTable)
Display()

Display()
{
global res
IfLess, res, 0x104C11DB7
  res := ~res
IfGreater, res, 0x104C11DB7
  res := res ^ 0xFFFFFFFF
MsgBox % res
return
}

ExitApp ; A little bit of extra code
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Tue Sep 25, 2007 4:22 pm    Post subject: Reply with quote

I don't see why the result should be different?
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Tue Sep 25, 2007 4:28 pm    Post subject: Reply with quote

I've done something horribly wrong but cant really check what right now. the results should be different as the files are different, so should return a different crc32. hopefully someone will fix it for me Smile or ill have a look later. thanks all
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Tue Sep 25, 2007 5:02 pm    Post subject: Reply with quote

Quote:
...4294967295...

That is the same errorlevel i get sometimes when a sendmessage has not succeeded.
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Tue Sep 25, 2007 5:04 pm    Post subject: Reply with quote

it is -1, or 0xFFFFFFFF
Back to top
View user's profile Send private message
olfen



Joined: 04 Jun 2005
Posts: 113
Location: Stuttgart, Germany

PostPosted: Tue Sep 25, 2007 5:05 pm    Post subject: Reply with quote

2tic:

You need to build the CRC32 lookup table once beforce executing CRC_Get:
Code:
VarSetCapacity(CRC32LookupTable, 256*4)
DllCall(&CRC32_Init, "uint",&CRC32LookupTable)
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: Tue Sep 25, 2007 5:14 pm    Post subject: Reply with quote

tic: "res := ~res" and "res := res ^ 0xFFFFFFFF" do the same thing, so in the Display function something is fishy.
Back to top
View user's profile Send private message
olfen



Joined: 04 Jun 2005
Posts: 113
Location: Stuttgart, Germany

PostPosted: Tue Sep 25, 2007 5:59 pm    Post subject: Reply with quote

Laszlo wrote:
tic: "res := ~res" and "res := res ^ 0xFFFFFFFF" do the same thing, so in the Display function something is fishy.
Can you explain this:
Code:
#NoEnv

MCode(CRC32_Init, "5589E583EC10C745FC2083B8EDC745F400000000817DF4FF0000007F508B45F48945F8C745F008000000837DF0007E238B45F883"
. "E00185C0740D8B45F8D1E83345FC8945F8EB058D45F8D1288D45F0FF08EBD78B45F48D0C85000000008B55088B45F88904118D45F4FF00EBA7C9C3")
MCode(CRC32_Get, "5589E583EC08C745FCFFFFFFFFC745F8000000008B45F83B450C732E8B45080345F80FB6003345FC25FF0000008D0C85000000008"
. "B55108B45FCC1E8083304118945FC8D45F8FF00EBCA8B45FCC9C3")
 
VarSetCapacity(CRC32LookupTable, 256*4)
DllCall(&CRC32_Init, "uint",&CRC32LookupTable)

SetFormat, Integer, Hex
 
a = ABCDEFGHIJKLMNOPQRSTUVWXY
res := DllCall(&CRC32_Get, "uint",&a, "uint",StrLen(a), "uint",&CRC32LookupTable)

MsgBox % res

r1 := ~res
MsgBox % r1 ; right answer: 0x292f0b53
r2 := res ^ 0xFFFFFFFF
MsgBox % r2 ; wrong answer: -0xd6d0f4ad
?
Back to top
View user's profile Send private message Visit poster's website
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Tue Sep 25, 2007 6:02 pm    Post subject: Reply with quote

Thanks olfen, but the following always gives 1059178012

Code:
#NoEnv

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")
}

MCode(CRC32_Init, "5589E583EC10C745FC2083B8EDC745F400000000817DF4FF0000007F508B45F48945F8C745F008000000837DF0007E238B45F883"
. "E00185C0740D8B45F8D1E83345FC8945F8EB058D45F8D1288D45F0FF08EBD78B45F48D0C85000000008B55088B45F88904118D45F4FF00EBA7C9C3")
MCode(CRC32_Get, "5589E583EC08C745FCFFFFFFFFC745F8000000008B45F83B450C732E8B45080345F80FB6003345FC25FF0000008D0C85000000008"
. "B55108B45FCC1E8083304118945FC8D45F8FF00EBCA8B45FCC9C3")

VarSetCapacity(CRC32LookupTable, 256*4)
DllCall(&CRC32_Init, "uint",&CRC32LookupTable)

FileRead, a, %A_AhkPath%
FileGetSize, size, %A_AhkPath%
res := DllCall(&CRC32_Get, "uint",&a, "uint",size, "uint",&CRC32LookupTable)
Display()

Display()
{
global res
IfLess, res, 0x104C11DB7
  res := ~res
IfGreater, res, 0x104C11DB7
  res := res ^ 0xFFFFFFFF
MsgBox % res
return
}
Back to top
View user's profile Send private message
olfen



Joined: 04 Jun 2005
Posts: 113
Location: Stuttgart, Germany

PostPosted: Tue Sep 25, 2007 6:09 pm    Post subject: Reply with quote

tic wrote:
Thanks olfen, but the following always gives 1059178012
It gives 434084816 on my computer, which is 0x19DF9BD0. Do you have installed AHK v1.0.47.04?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 5, 6, 7 ... 22, 23, 24  Next
Page 6 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