def encDecoderLoopBuilder(self, input): output = '' if len(input) == 0: return output for p in input: if not alphanum_byte.alphanumeric_check(p): output += chr(alphanum_byte.alphanumeric_get_byte()) else: output += p return output
def algo2(self): output = '' self.size += 4 #SUBMIS rk, ri, #x*/ output += ARM_Instructions.dpimm(SUB, MI, 1, self.k, self.i, self.x) #SUBPLS rk, ri, #x*/ output += ARM_Instructions.dpimm(SUB, PL, 1, self.k, self.i, self.x) #SUBPL rj, ri, #x*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.i, self.x) quo = (self.size - 4) / 0x7a if quo >= 1: for p in range(quo): #SUBPL rj, rj, #0x7a*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, 0x7a) rem = (self.size - 4) % 0x7a if rem >= 1 and rem <= 0x4a: self.addr_offset = alphanum_byte.off_gen(rem) #SUBPL rj, rj, #(offset+rem)*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, self.addr_offset + rem) if rem >= 0x4b and rem < 0x7a: if alphanum_byte.alphanumeric_check(rem): self.addr_offset = alphanum_byte.alphanumeric_get_byte() #SUBPL rj, rj, #(rem)*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, rem) #SUBPL rj, rj, #(offset)*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, self.addr_offset) else: self.addr_offset = alphanum_byte.off_gen(rem - 0x5a) #SUBPL rj, rj, #0x5a*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, 0x5a) #SUBPL rj, rj, #(offset + (rem - 0x5a))*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.j, self.addr_offset + rem - 0x5a) #SUBPL raddr, pc, rj ROR rk*/ output += ARM_Instructions.dpshiftreg(SUB, 0, self.addr, 15, self.j, ROR, self.k) return output
def enc_data_builder(self, input): if len(input) == 0: return '' output = '' arr = [1,2,3,4,5,6,7,8,9] self.I = random_funcs.randel(arr) p = 0 for p in range(len(input)): ab = input[p] b = ord(ab) & 0x0f e0 = random_funcs.enc_data_msn(b, self.I) e0 = e0 << 4 ef = e0 | b d = ((ord(ab) & 0xf0) ^ e0) >> 4 c0 = random_funcs.enc_data_msn(d, self.I) << 4 cd = c0 | d output += chr(cd & 0xff) output += chr(ef & 0xff) #Last two bytes to stop the decoder_loop*/ max = 0x30 | self.I output += chr(alphanum_byte.alphanumeric_get_byte()) output += chr(alphanum_byte.alphanumeric_get_byte_ltmax(max)) return output
def DecoderLoopBuilder(self, icache_flush): dec_loop = '' # Select p,s,t and q */ arr = [3, 7] p = random_funcs.randel(arr) if p == 3: s = 7 else: s = 3 t = 6 arr2 = [8, 9] q = random_funcs.randel(arr2) # Add the instructions*/ if icache_flush != 0: dec_loop += ARM_Instructions.swi(MI) rsalnum = alphanum_byte.alphanumeric_get_byte() if icache_flush != 0: #EORMIS rp, r4, #(randomly selected alphanumeric value)*/ dec_loop += ARM_Instructions.dpimm(EOR, MI, 1, p, 4, rsalnum) if icache_flush == 1: dist = 0x2c else: dist = 0x28 offset = alphanum_byte.off_gen(dist + 0x04) #SUBPL rs, r4, #(dist+0x04+offset)*/ dec_loop += ARM_Instructions.dpimm(SUB, PL, 0, s, 4, chr(dist + 0x04 + offset)) #SUBPL rs, pc, rs LSR r4*/ dec_loop += ARM_Instructions.dpshiftreg(SUB, 0, s, 0x0f, s, LSR, 4) #EORPLS rt, r4, rs LSR r4*/ dec_loop += ARM_Instructions.dpshiftreg(EOR, 1, t, 4, s, LSR, 4) #EORMIS rp, r4, #rsalnum*/ rsalnum = alphanum_byte.alphanumeric_get_byte() dec_loop += ARM_Instructions.dpimm(EOR, MI, 1, p, 4, rsalnum) #LDRPLB rp, [rs, #(-offset)]*/ dec_loop += ARM_Instructions.lsbyte(LDR, PL, p, s, offset) #SUBPL rs, rs, r5 LSR r4*/ dec_loop += ARM_Instructions.dpshiftreg(SUB, 0, s, s, 5, LSR, 4) #LDRPLB rq, [rs, #(-offset)]*/ dec_loop += ARM_Instructions.lsbyte(LDR, PL, q, s, offset) #EORPLS rp, rq, rp ROR #28*/ dec_loop += ARM_Instructions.dpshiftimm(EOR, 1, p, q, p, 28) #STRPLB rp, [rt, #(-offset)]*/ dec_loop += ARM_Instructions.lsbyte(STR, PL, p, t, offset) #SUBPL rt, rt, r5 LSR r4*/ dec_loop += ARM_Instructions.dpshiftreg(SUB, 0, t, t, 5, LSR, 4) #SUBPL rs, rs, r5 LSR r4*/ dec_loop += ARM_Instructions.dpshiftreg(SUB, 0, s, s, 5, LSR, 4) #RSBPLS rq, rq, #0x3I*/ dec_loop += ARM_Instructions.dpimm(RSB, PL, 1, q, q, 0x30 | self.I) #BMI 0xfffff4*/ dec_loop += ARM_Instructions.bmi() #STRPLB r4, [rt, #-(offset+1)]*/ dec_loop += ARM_Instructions.lsbyte(STR, PL, 4, t, offset + 1) if icache_flush == 1: #SWIPL 0x9f0002*/ dec_loop += ARM_Instructions.swi(PL) return dec_loop
def buildInit(self, input): if len(input) == 0: return ('', input) output = '' #Select values of v and w*/ total = 0x70 arr1 = [0x30, 0x34, 0x38] v1 = random_funcs.randel(arr1) v2 = random_funcs.randel(arr1) topv = ((total - (v1 + v2))/4) + 1 w1 = random_funcs.randel(arr1) w2 = random_funcs.randel(arr1) topw = ((total - (w1 + w2))/4) + 2 arrop = [EOR, SUB, RSB] arrcond = [PL, MI] arrs = [0, 1] arrd = [3, 5, 7] arrn = [1, 2, 3, 4, 5, 6, 7, 8, 9] p = 1 while p <= ((total-8)/4): op = random_funcs.randel(arrop) cond = random_funcs.randel(arrcond) if op == EOR: s = 1 else: s = random_funcs.randel(arrs) d = random_funcs.randel(arrd) n = random_funcs.randel(arrn) if p == topv or p == topw: output += ARM_Instructions.dpimm(op, cond, s, d, n, self.x) else: output += ARM_Instructions.dpimm(op, cond, s, d, n, alphanum_byte.alphanumeric_get_byte()) p += 1 #SUBPL ri, pc, #v1*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.i, 15, v1) #SUBMI ri, pc, #w1*/ output += ARM_Instructions.dpimm(SUB, MI, 0, self.i, 15, w1) #LDRPLB ri, [ri, #(-v2)]*/ output += ARM_Instructions.lsbyte(LDR, PL, self.i, self.i, v2) #LDRMIB ri, [ri, #(-w2)]*/ output += ARM_Instructions.lsbyte(LDR, MI, self.i, self.i, w2) output += self.algo2() #SUBPL rj, ri, #(x+1)*/ output += ARM_Instructions.dpimm(SUB, PL, 0, self.j, self.i, self.x + 1) #Initializer built!!*/ #Replace 0x91s in decoder with addr_offset*/ input_new = '' for p in input: if p == "\x91": input_new += chr(self.addr_offset) else: input_new += p return (output, input_new)