flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Encrypt a file and embed into the program through macros

Author
Thread Post new topic Reply to topic
3ric



Joined: 19 Dec 2013
Posts: 14
3ric
Hello,
I want to create a program encrypt.asm, that will take a file through file directive abc.txt and encrypt its content(for eg: XOR with a key) through macros and embed the whole encrypted file into the data section of the same program encrypt.exe.

I tried a lot but didn't get success plz help me guys....
Post 21 Oct 2014, 17:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Provide some of your not working code...
Post 21 Oct 2014, 19:10
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Not on PC, but this should work:
Code:
macro load.encrypt name {
 local p, i
 virtual at 0
  p:: file name
  file.size=$
 end virtual
 i=0
 while i<file.size
  load a byte from p:i
  db (a xor 10101010b)
  i=i+1
 end while
}    
Post 23 Oct 2014, 02:48
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 364
Location: Australia
redsock
Without much difficulty, you could modify my ARC4 c-string obfuscator macro, as it would be considerably better than a simple XOR:

Code:
        ;
        ; rc4str.inc: nasty little macro to prevent our cstring kak from ending up in the cleartext in our resultant exe
        ;               done only because i hate people being able to just willy-nilly modify string tables in binaries
        ;
        ; so, first up: the static rc4 table, initialized by a lovely string of cursing like a longshoreman, hahah

if used rc4

align 16
rc4 db 0x46, 0xbc, 0x34, 0xcb, 0x1c, 0x11, 0xbd, 0xe2, 0x2a, 0x64, 0x4f, 0x95, 0x66, 0x48, 0xdd, 0x4d, \
        0x7d, 0xc5, 0x4c, 0x79, 0x55, 0x8a, 0xf7, 0xed, 0x54, 0x27, 0x83, 0x14, 0x0f, 0x1d, 0xb8, 0x47, \
        0xc2, 0x45, 0x59, 0xe8, 0x81, 0x78, 0xa6, 0x88, 0xb7, 0x38, 0x53, 0x02, 0x96, 0x37, 0x6e, 0xf4, \
        0x82, 0x10, 0x67, 0x71, 0x94, 0xba, 0xff, 0x6c, 0x57, 0x22, 0x44, 0xcc, 0x12, 0xd7, 0xc3, 0x9c, \
        0xd0, 0xcf, 0x98, 0x1f, 0xfb, 0xa3, 0x58, 0xc1, 0x5f, 0x20, 0x99, 0xf8, 0x1b, 0x9b, 0x13, 0x87, \
        0x16, 0xa1, 0x33, 0x75, 0xde, 0x5a, 0x01, 0x06, 0x7c, 0x3d, 0x91, 0x0a, 0x0e, 0x77, 0x24, 0x05, \
        0x9f, 0x39, 0x03, 0xf2, 0xf9, 0xe0, 0x90, 0xf5, 0xdc, 0x2c, 0x19, 0x08, 0xa9, 0x6d, 0x0b, 0xc8, \
        0xad, 0x92, 0x3a, 0x09, 0x1a, 0x60, 0xd8, 0x84, 0xb2, 0x6a, 0x70, 0xae, 0x6f, 0x56, 0xce, 0xd1, \
        0x69, 0xb3, 0x9e, 0x25, 0x4e, 0x32, 0x28, 0xc7, 0x8c, 0x5d, 0xef, 0xaa, 0xcd, 0x31, 0x93, 0x6b, \
        0xab, 0x9d, 0xb4, 0xe6, 0x3e, 0x7e, 0x51, 0xc9, 0xe5, 0x0d, 0xa5, 0xa0, 0x04, 0x80, 0xfd, 0x2e, \
        0x4a, 0x5c, 0xdb, 0x2f, 0x8b, 0xb9, 0xac, 0x1e, 0xf3, 0x65, 0xf1, 0xe3, 0xfc, 0x85, 0x40, 0x2b, \
        0x17, 0x49, 0x21, 0xa2, 0x62, 0xb6, 0xd4, 0xee, 0xd3, 0xd6, 0x0c, 0x29, 0xd5, 0x86, 0xbb, 0xb0, \
        0x42, 0x9a, 0x3b, 0x97, 0xeb, 0xa7, 0x7b, 0xfa, 0x89, 0xca, 0xaf, 0x8f, 0x41, 0x07, 0x68, 0x43, \
        0xec, 0xc6, 0x5e, 0x18, 0x35, 0x23, 0x72, 0xb1, 0x15, 0x7f, 0xa8, 0x36, 0xe9, 0xd9, 0x30, 0x50, \
        0xe7, 0xb5, 0xf0, 0x3f, 0xbf, 0xc0, 0xf6, 0xe4, 0x26, 0x00, 0x74, 0x76, 0x4b, 0xfe, 0xa4, 0xe1, \
        0x73, 0x61, 0x5b, 0x7a, 0xdf, 0x3c, 0x2d, 0x8e, 0xda, 0xea, 0xbe, 0x52, 0x8d, 0xd2, 0xc4, 0x63

end if

; this macro is the goods, and gets used like:
; rc4str label_name, 'Label Contents'

macro rc4str name*,val* {
        local AA,BB,DD,CH,I,J,T,Si,Sj,.WTF
        name dq AA
.WTF:
        du val
        BB = ($ - .WTF)
        AA = BB shr 1
        align 16
        DD = ($ - name)
        I = 0
        J = 0
        repeat DD
                ; get our rc4 next()
                I = (I+1) and 0xff
                load Si byte from rc4+I
                J = (J + Si) and 0xff
                T = Si
                load Sj byte from rc4+J
                ; store byte Sj at rc4+I                we do _not_ modify the RC4 table here, and if we did, we'd want it to be a copy so it could be reset...
                ; store byte T at rc4+J                 but since all we are really doing is short-string obfuscating, it is all good
                Si = Sj
                Sj = T
                ; next = S[(t+S[i])&255]
                T = (T + Si) and 0xff
                load NEXT byte from rc4+T

                load CH byte from name+(%-1)
                ; display CH
                CH = CH xor NEXT
                store byte CH at name+(%-1)
        end repeat
}
    


Smile Smile
Post 23 Oct 2014, 04:51
View user's profile Send private message Reply with quote
3ric



Joined: 19 Dec 2013
Posts: 14
3ric
thanks a lot guys...
Post 26 Oct 2014, 21:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.