Example #1
0
 def BYE_compile_to_IL(self, code, imported):
     """compiles it into something useful"""
     import mosdef
     vars = {}
     ret = "\n" + mosdef.compile_to_IL(code, vars, self,
                                       imported=imported) + "\n"
     return ret
Example #2
0
    def createRemoteLibc(self):
        ndx = 0
        libc = []
        libc_buffer = []
        import mosdef
        BASE_ADDRESS = 0x60400000L  # just some random address that we expect not
        # to be remotely mmaped

        self.compilelibc = 1
        for ke in self.localfunctions.keys():
            suffixtype = self.localfunctions[ke][0]
            suffixcode = self.localfunctions[ke][1]
            if suffixtype == "asm":
                buf = mosdef.assemble(suffixcode, self.arch)

            elif suffixtype == "c":
                code = "jump %s\n" % ke
                code += mosdef.compile_to_IL(suffixcode, {},
                                             self,
                                             None,
                                             not_libc=0)

                code = self.compile_to_ASM(code)

                buf = mosdef.assemble(code, self.arch)

                # IMPORTANT: never forget to clearfunctioncache
            else:
                continue

            libc.append("libc!" + ke)
            self.remotefunctioncache["libc!" + ke] = ndx + BASE_ADDRESS
            libc_buffer.append(buf)
            ndx += len(buf)

        self.clearfunctioncache()

        self.compilelibc = 0
        libc_buffer = "".join(libc_buffer)

        # mapping the libc
        self.log("Remote libc size: 0x%08x" % ndx)
        ret = self.mmap(addr=BASE_ADDRESS, needed=ndx)
        if ret == 0xFFFFFFFFL:
            raise Exception, "Failed to mmap libc at address 0x%08x with size: %d" % (
                BASE_ADDRESS, ndx)

        self.remoterecv(self.fd, ret, ndx, libc_buffer)

        self.log("MOSDEF libc mapped at address: 0x%08x" % ret)

        # Instead of patching, everything, i can try to mmap at a know address,
        # in case it doesn't work, i can re patch with the given address.

        if ret != BASE_ADDRESS:
            self.log("Repatching the remotelibc")
            for ke in libc:
                self.remotefunctioncache[
                    ke] = self.remotefunctioncache[ke] - BASE_ADDRESS + ret
Example #3
0
    def compile_to_IL(self, code, imported):
        vars = self.vars
        ##Filthy - temporary while cparse 2 in testing Rich - remove when done testing

        #self.use_cparse_2=True
        if hasattr(self, "use_cparse_2"):
            ret = mosdef.compile_to_IL2(code, vars, self, imported=imported)
        else:
            ret = mosdef.compile_to_IL(code, vars, self, imported=imported)
        assert ret, "mosdef.compile_to_IL() for arch %s returned None\nremoteresolver: %s\n" \
            "----vars----\n%s\n----code----\n%s\n" % \
            (self.arch, self, str(vars), code)
        return "\n" + ret + "\n"
Example #4
0
    def compile_to_IL(self, code, imported):

        vars = self.vars
        if not hasattr(self,"LP64"):
            self.LP64 = False

        ##Filthy - temporary while cparse 2 in testing Rich - remove when done testing

        if USE_CPARSE2:
            ret = mosdef.compile_to_IL2(code, vars, self, imported = imported, LP64=self.LP64)
        else:
            ret = mosdef.compile_to_IL(code, vars, self, imported = imported)

        assert ret, "mosdef.compile_to_IL() for arch %s returned None\nremoteresolver: %s\n" \
               "----vars----\n%s\n----code----\n%s\n" % \
               (self.arch, self, str(vars), code)
        ret = "\n" + ret + "\n"

        return ret