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



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Oct 22, 2009 5:52 pm    Post subject: Reply with quote

Laszlo: Thx that got me somewhere. Very Happy

I got this output from msvc'08: (output looks better with tab==8 spaces in your editor)
Code:
; Listing generated by Microsoft (R) Optimizing Compiler Version 15.00.30729.01

   TITLE   p:\My Documents\AutoHotkey\RegionGetColor\SumIntBytes.c
   .686P
   .XMM
   include listing.inc
   .model   flat

INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES

PUBLIC   _SumIntBytes
EXTRN   __RTC_Shutdown:PROC
EXTRN   __RTC_InitBase:PROC
;   COMDAT rtc$TMZ
; File p:\my documents\autohotkey\regiongetcolor\sumintbytes.c
rtc$TMZ   SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ   ENDS
;   COMDAT rtc$IMZ
rtc$IMZ   SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
; Function compile flags: /Odtp /RTCsu /ZI
rtc$IMZ   ENDS
;   COMDAT _SumIntBytes
_TEXT   SEGMENT
_i$ = -8                  ; size = 4
_x$ = 8                     ; size = 4
_l$ = 12                  ; size = 4
_a$ = 16                  ; size = 4
_b$ = 20                  ; size = 4
_c$ = 24                  ; size = 4
_d$ = 28                  ; size = 4
_SumIntBytes PROC               ; COMDAT

; 19   : {

  00000   55       push    ebp
  00001   8b ec       mov    ebp, esp
  00003   81 ec cc 00 00
   00       sub    esp, 204      ; 000000ccH
  00009   53       push    ebx
  0000a   56       push    esi
  0000b   57       push    edi
  0000c   8d bd 34 ff ff
   ff       lea    edi, DWORD PTR [ebp-204]
  00012   b9 33 00 00 00    mov    ecx, 51         ; 00000033H
  00017   b8 cc cc cc cc    mov    eax, -858993460      ; ccccccccH
  0001c   f3 ab       rep stosd

; 20   :    uint i;
; 21   :    for(i = 0; i < l; i = i + 1)

  0001e   c7 45 f8 00 00
   00 00       mov    DWORD PTR _i$[ebp], 0
  00025   eb 09       jmp    SHORT $LN3@SumIntByte
$LN2@SumIntByte:
  00027   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  0002a   83 c0 01    add    eax, 1
  0002d   89 45 f8    mov    DWORD PTR _i$[ebp], eax
$LN3@SumIntByte:
  00030   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  00033   3b 45 0c    cmp    eax, DWORD PTR _l$[ebp]
  00036   0f 83 94 00 00
   00       jae    $LN4@SumIntByte

; 22   :    {
; 23   :       //return *a;
; 24   :       //return x[i] >> 8 & 0xff;
; 25   :        *a = *a + (x[i] >> 24);

  0003c   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  0003f   8b 4d 08    mov    ecx, DWORD PTR _x$[ebp]
  00042   8b 14 81    mov    edx, DWORD PTR [ecx+eax*4]
  00045   c1 ea 18    shr    edx, 24         ; 00000018H
  00048   33 c0       xor    eax, eax
  0004a   8b 4d 10    mov    ecx, DWORD PTR _a$[ebp]
  0004d   03 11       add    edx, DWORD PTR [ecx]
  0004f   8b 49 04    mov    ecx, DWORD PTR [ecx+4]
  00052   13 c8       adc    ecx, eax
  00054   8b 45 10    mov    eax, DWORD PTR _a$[ebp]
  00057   89 10       mov    DWORD PTR [eax], edx
  00059   89 48 04    mov    DWORD PTR [eax+4], ecx

; 26   :        *b = *b + (x[i] >> 16 & 0xff);

  0005c   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  0005f   8b 4d 08    mov    ecx, DWORD PTR _x$[ebp]
  00062   8b 14 81    mov    edx, DWORD PTR [ecx+eax*4]
  00065   c1 ea 10    shr    edx, 16         ; 00000010H
  00068   81 e2 ff 00 00
   00       and    edx, 255      ; 000000ffH
  0006e   33 c0       xor    eax, eax
  00070   8b 4d 14    mov    ecx, DWORD PTR _b$[ebp]
  00073   03 11       add    edx, DWORD PTR [ecx]
  00075   8b 49 04    mov    ecx, DWORD PTR [ecx+4]
  00078   13 c8       adc    ecx, eax
  0007a   8b 45 14    mov    eax, DWORD PTR _b$[ebp]
  0007d   89 10       mov    DWORD PTR [eax], edx
  0007f   89 48 04    mov    DWORD PTR [eax+4], ecx

; 27   :        *c = *c + (x[i] >>  8 & 0xff);

  00082   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  00085   8b 4d 08    mov    ecx, DWORD PTR _x$[ebp]
  00088   8b 14 81    mov    edx, DWORD PTR [ecx+eax*4]
  0008b   c1 ea 08    shr    edx, 8
  0008e   81 e2 ff 00 00
   00       and    edx, 255      ; 000000ffH
  00094   33 c0       xor    eax, eax
  00096   8b 4d 18    mov    ecx, DWORD PTR _c$[ebp]
  00099   03 11       add    edx, DWORD PTR [ecx]
  0009b   8b 49 04    mov    ecx, DWORD PTR [ecx+4]
  0009e   13 c8       adc    ecx, eax
  000a0   8b 45 18    mov    eax, DWORD PTR _c$[ebp]
  000a3   89 10       mov    DWORD PTR [eax], edx
  000a5   89 48 04    mov    DWORD PTR [eax+4], ecx

; 28   :        *d = *d + (x[i] & 0xff);

  000a8   8b 45 f8    mov    eax, DWORD PTR _i$[ebp]
  000ab   8b 4d 08    mov    ecx, DWORD PTR _x$[ebp]
  000ae   8b 14 81    mov    edx, DWORD PTR [ecx+eax*4]
  000b1   81 e2 ff 00 00
   00       and    edx, 255      ; 000000ffH
  000b7   33 c0       xor    eax, eax
  000b9   8b 4d 1c    mov    ecx, DWORD PTR _d$[ebp]
  000bc   03 11       add    edx, DWORD PTR [ecx]
  000be   8b 49 04    mov    ecx, DWORD PTR [ecx+4]
  000c1   13 c8       adc    ecx, eax
  000c3   8b 45 1c    mov    eax, DWORD PTR _d$[ebp]
  000c6   89 10       mov    DWORD PTR [eax], edx
  000c8   89 48 04    mov    DWORD PTR [eax+4], ecx

; 29   :    }

  000cb   e9 57 ff ff ff    jmp    $LN2@SumIntByte
$LN4@SumIntByte:

; 30   : }

  000d0   5f       pop    edi
  000d1   5e       pop    esi
  000d2   5b       pop    ebx
  000d3   8b e5       mov    esp, ebp
  000d5   5d       pop    ebp
  000d6   c3       ret    0
_SumIntBytes ENDP
_TEXT   ENDS
END


I'm assuming i need the second part from 00000 to 000d6:
Code:
55      
8b ec      
81 ec cc 00 00
00      
53      
56      
57      
8d bd 34 ff ff
ff      
b9 33 00 00 00   
b8 cc cc cc cc   
f3 ab      
c7 45 f8 00 00
00 00      
eb 09      
8b 45 f8   
83 c0 01   
89 45 f8   
8b 45 f8   
3b 45 0c   
0f 83 94 00 00
00      
8b 45 f8   
8b 4d 08   
8b 14 81   
c1 ea 18   
33 c0      
8b 4d 10   
03 11      
8b 49 04   
13 c8      
8b 45 10   
89 10      
89 48 04   
8b 45 f8   
8b 4d 08   
8b 14 81   
c1 ea 10   
81 e2 ff 00 00
00      
33 c0      
8b 4d 14   
03 11      
8b 49 04   
13 c8      
8b 45 14   
89 10      
89 48 04   
8b 45 f8   
8b 4d 08   
8b 14 81   
c1 ea 08   
81 e2 ff 00 00
00      
33 c0      
8b 4d 18   
03 11      
8b 49 04   
13 c8      
8b 45 18   
89 10      
89 48 04   
8b 45 f8   
8b 4d 08   
8b 14 81   
81 e2 ff 00 00
00      
33 c0      
8b 4d 1c   
03 11      
8b 49 04   
13 c8      
8b 45 1c   
89 10      
89 48 04   
e9 57 ff ff ff   
5f      
5e      
5b      
8b e5      
5d      
c3      

Which results, when contat:
Code:
558bec81eccc0000005356578dbd34ffffffb933000000b8ccccccccf3abc745
f800000000eb098b45f883c0018945f88b45f83b450c0f83940000008b45f88b
4d088b1481c1ea1833c08b4d1003118b490413c88b451089108948048b45f88b
4d088b1481c1ea1081e2ff00000033c08b4d1403118b490413c88b4514891089
48048b45f88b4d088b1481c1ea0881e2ff00000033c08b4d1803118b490413c8
8b451889108948048b45f88b4d088b148181e2ff00000033c08b4d1c03118b49
0413c88b451c8910894804e957ffffff5f5e5b8be55dc3

Does this look right?
_________________
Scripts - License
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Thu Oct 22, 2009 6:23 pm    Post subject: Reply with quote

yes (it is easy to miss 6-byte instructions, when they flow in the next line)
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Oct 22, 2009 6:41 pm    Post subject: Reply with quote

Great, thanks!

**Crosses fingers and hits "Run"**

Error: 0xc0000005 (Access violation iirc)

Sad

My test script:
Am I doing machine code right?
<cut code>

Oh, nvm, I just forgot the "0x" part. Smile

YAAAY:
Code:
len := 2

VarSetCapacity(arr, len*4)
NumPut(0x010203, arr, 0, "UInt")
NumPut(0x040506, arr, 4, "UInt")


x := SumIntBytes_(arr, len, a, r, g, b)

MsgBox % ""
   .   "A: "   a   ; "`t" (&a)
   . "`nR: "   r   ; "`t" (&r)
   . "`nG: "   g   ; "`t" (&g)
   . "`nB: "   b   ; "`t" (&b)
   . "`n`nErr: " ErrorLevel
   . "`n" x

SumIntBytes_( ByRef arr, len, ByRef a, ByRef r, ByRef g, ByRef b )
{
  static f, i
  if !i
  {
    t =
    (LTrim Join
    558bec81eccc0000005356578dbd34ffffffb933000000b8ccccccccf3abc745
    f800000000eb098b45f883c0018945f88b45f83b450c0f83940000008b45f88b
    4d088b1481c1ea1833c08b4d1003118b490413c88b451089108948048b45f88b
    4d088b1481c1ea1081e2ff00000033c08b4d1403118b490413c88b4514891089
    48048b45f88b4d088b1481c1ea0881e2ff00000033c08b4d1803118b490413c8
    8b451889108948048b45f88b4d088b148181e2ff00000033c08b4d1c03118b49
    0413c88b451c8910894804e957ffffff5f5e5b8be55dc3
    )
    VarSetCapacity(f, tl := StrLen(t)/2), i := 0
    While i < tl
      NumPut("0x" SubStr(t, i*2+1, 2), f, i, "UChar"), i++
  }
    VarSetCapacity(a, 8, 0), VarSetCapacity(r, 8, 0)
  , VarSetCapacity(g, 8, 0), VarSetCapacity(b, 8, 0)
  , DllCall( &f, "UInt", &arr, "UInt", len
    , "UInt", &a, "UInt", &r, "UInt", &g, "UInt", &b
    , "CDecl UInt")
  , a := NumGet(a, 0, "UInt64"), r := NumGet(r, 0, "UInt64")
  , g := NumGet(g, 0, "UInt64"), b := NumGet(b, 0, "UInt64")
}


Thx Laszlo, you rock! Razz Very Happy
_________________
Scripts - License
Back to top
View user's profile Send private message
RoAltmann



Joined: 26 May 2009
Posts: 15

PostPosted: Fri Feb 19, 2010 10:07 pm    Post subject: Looking for fast byte sum Reply with quote

Hi, just found hex2bin and bin2hex!

great functions, make my reading and writing IntelHex files 6 times faster!

Since i do not have any compilers, could anybody help me with a function like:
Code:

bytesum(uint *s, char *p, uint len)
{
 *s=0;
 while (len>0) {
   *s += *(p++);
   len--
  }
}


Thanks in advance!
Robert
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Sat Feb 20, 2010 1:57 am    Post subject: Reply with quote

Code:
typedef unsigned long UInt32;
void bytesum(UInt32 *s, char *p, UInt32 len) {
   *s=0;
   while (len>0) {
      *s += *(p++);
      len--;
   }
}


Code:
MCode(bytesum,"832000837c240c0076108b4c24080fbe11011041ff4c240c75f4c3")

DllCall(&bytesum, UIntP,sum, Str,"", UInt,0)
MsgBox %sum%
DllCall(&bytesum, UIntP,sum, Str,"00", UInt,1)
MsgBox %sum%
DllCall(&bytesum, UIntP,sum, Str,"00", UInt,2)
MsgBox %sum%

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
Laszlo



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

PostPosted: Sat Feb 20, 2010 2:05 am    Post subject: Reply with quote

Returning the result makes the code easier to use
Code:
UInt32 CharSum(char *p, UInt32 len) {
   UInt32 s = 0;
   while (len>0) {
      s += *(p++);
      len--;
   }
   return s;
}


Code:
MCode(CharSum,"33c03944240876108b4c24040fbe1103c241ff4c240875f4c3")

MsgBox % DllCall(&CharSum, Str,"",   UInt,0)
MsgBox % DllCall(&CharSum, Str,"00", UInt,1)
MsgBox % DllCall(&CharSum, Str,"00", UInt,2)

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
RoAltmann



Joined: 26 May 2009
Posts: 15

PostPosted: Sat Feb 20, 2010 3:36 pm    Post subject: Thanks to Laszlo! Reply with quote

Works fine!

But had to change "Str" by "Uint", because I use a real pointer to a binary variable!

Code:


; Example, in real I use a Variable with a Size of 0x400000!
VarSetCapacity(A,256,1)
P := &A
MCode(CharSum,"33c03944240876108b4c24040fbe1103c241ff4c240875f4c3")
Loop , 8
  {
  MsgBox % DllCall(&CharSum, Uint,P, UInt,32) 
  P += 32
  }

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



Regards
Robert
Back to top
View user's profile Send private message
RoAltmann



Joined: 26 May 2009
Posts: 15

PostPosted: Mon Feb 22, 2010 9:48 pm    Post subject: Find binary sequence in memory Reply with quote

Next Request to the best! Smile
Again I would need the MCode-hex-string.

Code:

char *binfind(char *pStart, char *pEnd, char *pFind, int len)
{
  pEnd -= len;
  while ( pStart >= pEnd )
   {
   for (i=0;i<len;i++)
     {
     if (*(pStart+i) != *(pFind+i))
       break;
     }
   if ( i==len)
     return(pStart);
   pStart++; 
   }
  return(NULL);   
}


Many thanks in advance
Robert
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Mon Feb 22, 2010 11:35 pm    Post subject: Re: Find binary sequence in memory Reply with quote

RoAltmann wrote:
Next Request to the best! Smile
Again I would need the MCode-hex-string.


Isn't this what MemChr does?
_________________
Scripts - License
Back to top
View user's profile Send private message
RoAltmann



Joined: 26 May 2009
Posts: 15

PostPosted: Tue Feb 23, 2010 7:23 am    Post subject: Re: Re: Find binary sequence in memory Reply with quote

No!

MemChr searches for only ONE character.

My Function should search a sequence of binary bytes of ANY length in another sequence of binary bytes, including byte values from 0x00 to 0xFF! No string searching!

Example:
Code:

VarSetCapacity(Memory,0x100000,0)
mptr := &Memory
ReadHexFile2Buffer("C:\Temp\Intelhex.hex",mptr) ; my private function ;-)
hexsequence:= "010203040506070809"
len := strlen(hexsequence)>>1
VarSetCapacity(binSequence,len)
sptr := &binSequence
hex2bin(sptr,hexsequence) ; set find sequence
found :=  binfind(mptr,sptr,len)
if ( !found)
  MsgBox key not found in Hexfile!
else
  {
  index := found - mptr
  hex2bin(found,"08154711CAFEBABE06")
  MsgBox Key changed!
  }
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Tue Feb 23, 2010 5:28 pm    Post subject: Reply with quote

oh, then how about this:

Code:
haystackLenlen := BinRead(haystack, "binaryfile2.bin")
needleLen := BinRead(Needle, "somefile.bin")
;(btw, i'm making up these functions, but they're self-explanatory enough)

MsgBox % "Found Position: " InStr(bin2hex(haystack, haystackLen), bin2hex(needle, needleLen)) >> 1


What you really want is MemMem(), but it's not avail in msvcrt.
_________________
Scripts - License
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Tue Feb 23, 2010 6:08 pm    Post subject: Re: Find binary sequence in memory Reply with quote

RoAltmann wrote:
Next Request...
Your C code has a couple of bugs (missing declaration for "i", the while condition needs "<="). Also, using the loop variable (i) outside of the body of the loop is not portable. Here is a version which does, what I think you wanted:
Code:
char *BinFind(char *pStart, char *pEnd, char *pFind, int len) {
   int i;
   while (pStart <= pEnd-len) {
      for (i=0; i<len; i++)
         if (*(pStart+i) != *(pFind+i)) goto out;
      return(pStart);
out:   pStart++;
   }
   return(NULL);   
}
Using goto is not nice, but it makes the code faster, shorter and more portable. The corresponding MCode is:
Code:
MCode(BinFind,"558bec8b450853568b750c2b7514573bc677208bc82b4d108b551033ff3b7d"
. "147d138a1c113a1a75044742ebf040413bc676e533c05f5e5b5dc3")
; &HayStackStart, &HayStackEnd, &FindStart, FindLen -> &Match

s = 123456
t = 56
MsgBox % DllCall(&BinFind, UInt,&s, UInt,&s+6, UInt,&t, Int,2, "CDECL UINT") - &s

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

Edit: never mind (edited the wrong post)


Last edited by Laszlo on Tue Feb 23, 2010 10:02 pm; edited 2 times in total
Back to top
View user's profile Send private message
Laszlo



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

PostPosted: Tue Feb 23, 2010 6:56 pm    Post subject: Reply with quote

...maybe this one is easier to use
Code:
int BinFind(char *pHayStack, int lenH, char *pNeedle, int lenN) {
   int i, j;
   for (j=0; j<=lenH-lenN; j++) {
      for (i=0; i<lenN; i++)
         if (*(pHayStack+i) != *(pNeedle+i)) goto out;
      return j;
out:   pHayStack++;
   }
   return -1;   
}

Code:
MCode(BinFind,"558bec53568b750c33c02b75145778218b4d082b4d108b551033ff3b7d147d"
. "148a1c113a1a75044742ebf041403bc67ee583c8ff5f5e5b5dc3")
; &HayStack, HayStackLen, &Needle, NeedleLen -> FoundOffset [-1]

s := "123456", t := "56"
MsgBox % DllCall(&BinFind, UInt,&s, Int,6, UInt,&t, Int,2, "CDECL INT") ; 4
;...


Edit: fixed C typo (return value is int, not pointer)


Last edited by Laszlo on Tue Feb 23, 2010 10:03 pm; edited 2 times in total
Back to top
View user's profile Send private message
RoAltmann



Joined: 26 May 2009
Posts: 15

PostPosted: Tue Feb 23, 2010 9:07 pm    Post subject: Thanks to Laszlo again! Reply with quote

Again just what I needed (first variant) and already in use.

Very Happy Very Happy Very Happy Very Happy Very Happy

Thanks a lot
Robert
Back to top
View user's profile Send private message
Jamie



Joined: 26 Mar 2010
Posts: 129

PostPosted: Sat May 22, 2010 12:57 pm    Post subject: Re: machine code from C Reply with quote

Laszlo wrote:
...
You can use an editor to strip off unwanted information, but I have been using a short script for this and for nicely formatting the hex stream of the machine code.
Code:
+!z::             ; Shift-Alt-Z: convert machine code listing to hex stream
   ClipBoard =
   Send ^c
   ClipWait 2
   IfEqual ErrorLevel,1, Return

   Clip := RegExReplace(ClipBoard,"m)[;\$].*$")
   Clip := RegExReplace(Clip,"m)^.*?\t(.*?)\t.*$","$1")
   Clip := RegExReplace(Clip,"m)\s")
   TrayTip,,% "Bytes = " StrLen(Clip)//2
   If StrLen(Clip) < 80
      ClipBoard := Clip
   Else {
      ClipBoard := """" . SubStr(Clip,1,62)
      StringTrimLeft Clip, Clip, 62
      Loop {
         ClipBoard .= """`n. """ . SubStr(Clip,1,76)
         StringTrimLeft Clip, Clip, 76
         If StrLen(Clip) < 80
            Break
      }
      ClipBoard .= """`n. """ . Clip . """"
   }
Return

Just select the instructions belonging to your function in any editor (Notepad is OK) and press the Shift-Alt-Z hotkey. The formatted hex stream w/o the assembly instructions or comments appears in the clipboard, ready to be pasted to your script.
...

Thanks Laszlo, this has saved me a lot of time. But sometimes my compiler (Visual C++ 2008 Express) emits code that flows onto the next line like this
Code:
  0000c c7 00 7b 00 00
        00               mov     DWORD PTR [eax], 123   ; 0000007bH

Here I've highlighted the tabs:
Code:
  0000c->c7 00 7b 00 00
->00->-> mov-> DWORD PTR [eax], 123->; 0000007bH

This causes trouble for me, so I've switched to use a different set of regexes:
Code:
   Clip := RegExReplace(ClipBoard,"m)^\S.*$") ; wipe out any line that starts in column 1
   Clip := RegExReplace(Clip,"m)^[^\t]*\t") ; wipe out anything up to and including the first tab character
   Clip := RegExReplace(Clip,"m)\t.*$") ; wipe out the (now) first tab character and everything after it
   Clip := RegExReplace(Clip,"m)\s") ; remove all whitespace

This also eliminates some of the extra junk lines in the assembly file in case they get selected by mistake.

Below is the entire function with the new regexes included. I hope this helps.
Code:
+!z::             ; Shift-Alt-Z: convert machine code listing to hex stream (originally by Laszlo)
   ClipBoard =
   Send ^c
   ClipWait 2
   IfEqual ErrorLevel,1, Return

   Clip := RegExReplace(ClipBoard,"m)^\S.*$") ; wipe out any line that starts in column 1
   Clip := RegExReplace(Clip,"m)^[^\t]*\t") ; wipe out anything up to and including the first tab character
   Clip := RegExReplace(Clip,"m)\t.*$") ; wipe out the (now) first tab character and everything after it
   Clip := RegExReplace(Clip,"m)\s") ; remove all whitespace
   TrayTip,,% "Bytes = " StrLen(Clip)//2
   If StrLen(Clip) < 80
      ClipBoard := Clip
   Else {
      ClipBoard := """" . SubStr(Clip,1,62)
      StringTrimLeft Clip, Clip, 62
      Loop {
         ClipBoard .= """`n. """ . SubStr(Clip,1,76)
         StringTrimLeft Clip, Clip, 76
         If StrLen(Clip) < 80
            Break
      }
      ClipBoard .= """`n. """ . Clip . """"
   }
Return

Of course whether this works for you is going to depend on the particular format that your assembler generates.
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 ... 16, 17, 18 ... 22, 23, 24  Next
Page 17 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