def discover(self, request, context): logger.info("discovering.") pprint(request) descriptor_set = FileDescriptorSet() for entity in self.event_sourced_entities + self.action_protocol_entities: logger.info(f"entity: {entity.name()}") for descriptor in entity.file_descriptors: logger.info(f"discovering {descriptor.name}") logger.info(f"SD: {entity.service_descriptor.full_name}") from_string = FileDescriptorProto.FromString( descriptor.serialized_pb) descriptor_set.file.append(from_string) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/empty.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "cloudstate/entity_key.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "cloudstate/eventing.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/descriptor.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/annotations.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/http.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/httpbody.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/any.proto").serialized_pb)) spec = entity_pb2.EntitySpec( service_info=entity_pb2.ServiceInfo( service_name="", service_version="0.1.0", service_runtime="Python " + platform.python_version() + " [" + platform.python_implementation() + " " + platform.python_compiler() + "]", support_library_name="cloudstate-python-support", support_library_version="0.1.0", ), entities=[ entity_pb2.Entity( entity_type=entity.entity_type(), service_name=entity.service_descriptor.full_name, persistence_id=entity.persistence_id, ) for entity in self.event_sourced_entities + self.action_protocol_entities ], proto=descriptor_set.SerializeToString(), ) return spec
def discover(self, request, context): pprint(request) descriptor_set = FileDescriptorSet() for entity in self.event_sourced_entities: for descriptor in entity.file_descriptors: descriptor_set.file.append(FileDescriptorProto.FromString(descriptor.serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/protobuf/empty.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('cloudstate/entity_key.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/protobuf/descriptor.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/api/annotations.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/api/http.proto').serialized_pb) ) spec = entity_pb2.EntitySpec( service_info=entity_pb2.ServiceInfo( service_version='0.1.0', service_runtime='Python ' + platform.python_version() + ' [' + platform.python_implementation() + ' ' + platform.python_compiler() + ']', support_library_name='cloudstate-python-support', support_library_version='0.1.0' ), entities=[ entity_pb2.Entity( entity_type=entity.entity_type(), service_name=entity.service_descriptor.full_name, persistence_id=entity.persistence_id, ) for entity in self.event_sourced_entities], proto=descriptor_set.SerializeToString() ) return spec
r2.cmd('aaa') # print_info('Finished analysis') sections = json.loads(r2.cmd('Sj')) xrefs = r2.cmd('axF InternalAddGeneratedFile|cut -d" " -f2|sort -u').split() def get_paddr(vaddr): for section in sections: if vaddr >= section['vaddr'] and vaddr < section['vaddr'] + section['size']: return vaddr - section['vaddr'] + section['paddr'] print_error("Can't find virtual address {}", vaddr) return 0 for xref in xrefs: disasm = json.loads(r2.cmd('pdj -2 @ ' + xref)) if disasm[0]['type'] == 'push' and disasm[1]['type'] == 'push': length = disasm[0]['val'] addr = disasm[1]['val'] # print_info('Found protobuf of length {:6d} at addr 0x{:8x}', length, addr) paddr = get_paddr(addr) data = f[paddr:paddr+length] try: fdp = FileDescriptorProto.FromString(data) print_info('Found FiledescriptorProto of length {:6d} at addr 0x{:08x}: {}', length, paddr, fdp.name, color='green') outfile = open(os.path.join(out_dir, fdp.name.replace('/', '_')), 'wb') outfile.write(data) # print(fdp) except google.protobuf.message.DecodeError: print_error('Error while decoding data at offset 0x{:08x}, length {:6d} as FiledescriptorProto', paddr, length) else: print_warning('No push in immediate vicinity')