Exemple #1
0
int list_mmap_id(void)
{
    #define PATTERN_HEAD "/* E_MMAP_ID"
    #define PATTERN_TAIL "*/"
    char *pS=NULL,*pE=NULL;
    char *pBuf=NULL;
    char *strBuf=NULL;
    unsigned int buf_size=mmap_buffer_size;
    UBOOT_TRACE("IN\n");
    if(init_mmap()!=0)
    {
        UBOOT_ERROR("init mmap fail\n");
        return -1;
    }
    strBuf=malloc(CMD_BUF);
    if(strBuf==NULL)
    {
        UBOOT_ERROR("malloc for string buf fail\n");
        return -1;
    }
    memset(strBuf,0,CMD_BUF);
    
    pS=(char *)mmap_buffer;
    pBuf=pS;
    while(buf_size)
    {
        pS=pattern_search((char *)pBuf,buf_size,PATTERN_HEAD);
        if(pS!=NULL)
        {
            buf_size=buf_size-((unsigned int)pS-(unsigned int)pBuf+1);
            pE=pattern_search((char *)pS,buf_size,PATTERN_TAIL);    
            buf_size=buf_size-((unsigned int)pE-(unsigned int)pS+1);
        }
        if((pS==NULL)||(pE==NULL))
        {
            break;
        }
        pS+=3;//+3? skip  "/* "
        pBuf=pE+strlen(PATTERN_TAIL);        
        snprintf(strBuf,((unsigned int)pE-(unsigned int)pS),"%s",pS);
        UBOOT_INFO("%s\n",strBuf);
    }
    
    UBOOT_TRACE("OK\n");
    return 0;

}
Exemple #2
0
const void *find_pattern(HANDLE module, std::string name, const char *pattern, const char *mask, size_t size)
{
	auto section = get_image_section_header(module, name);

	auto start = (const char *)module + section->VirtualAddress;
	auto stop = start + section->Misc.VirtualSize;

	return pattern_search(start, stop, pattern, mask, size);
}
Exemple #3
0
void
capture(mdl_t *self, pkt_t *pkt, pattern_search_t *s, double srate)
{
    config_t *cfg;
    record_t *r;
    int len;

    if (! pattern_search(s, COMO(payload), COMO(caplen), NULL))
        return;

    cfg = mdl_get_config(self, config_t);
    r = mdl_alloc_tuple(self, record_t);

    r->ts = COMO(ts);
    len = (COMO(caplen) > cfg->snaplen) ? cfg->snaplen : COMO(caplen);
    memcpy(r->buf, pkt, sizeof(pkt_t)); 
    ((pkt_t *) r->buf)->payload = NULL;
    ((pkt_t *) r->buf)->caplen = len;
    memcpy(r->buf + sizeof(pkt_t), COMO(payload), len);
    r->len = len + sizeof(pkt_t);
}
int main(int argc, char**argv)
{
    out("starting ... \n");
    //If you want grep, uncomment next line: 
    //grep(argc, argv); exit(1);
    
    std::cout << " Rexex search " << std::endl;

    char text[10000] = {0};
    char re[256] = {0};
    scanf("%s\n",&text);
    out("searching in %s \n", &text);
    while(scanf("%s\n",&re) != EOF) 
    { 
        int counter = 0;
        printf("searching for '%s' \n", re);
        int count = pattern_search(text, re);

        if(count > 0 ) printf("found in %d locations \n", count);
        else printf("NOT found in text\n");
    }

    return 0;
}
Exemple #5
0
int _get_mmap(U8 *buffer, char *id, MMapInfo_s *mmapInfo)
{
    char *str=NULL;
    char *ptr=NULL;
    UBOOT_TRACE("IN\n");
    if((buffer==NULL)||(id==NULL)||(mmapInfo==NULL))
    {
        UBOOT_ERROR("One of the input parameters is null pointer\n");
        return -1;
    }
    UBOOT_DEBUG("@@id=%s\n",id);
    str=malloc(CMD_BUF);
    if(str==NULL)
    {
        UBOOT_ERROR("malloc for str fail\n");
        return -1;
    }

    memset(str,0,CMD_BUF);
    snprintf(str,CMD_BUF,"%s_ADR",id);
    UBOOT_DEBUG("str=%s\n",str);
    ptr=pattern_search((char *)mmap_buffer,mmap_buffer_size,str);
    if(ptr!=NULL)
    {
        ptr=pattern_search(ptr,mmap_buffer_size-((unsigned int)ptr-(unsigned int)mmap_buffer+1),"0x");
    }
    if(ptr==NULL)
    {
        UBOOT_ERROR("get addr from mmap fail\n");
        return -1;
    }
    memset(str,0,CMD_BUF);
    snprintf(str,NUM_LEN,"%s\n",ptr);
    UBOOT_DEBUG("str=%s\n",str);
    mmapInfo->u32Addr=(U32)simple_strtol(str,NULL,16);

    memset(str,0,CMD_BUF);
    snprintf(str,CMD_BUF,"%s_LEN",id);
    UBOOT_DEBUG("str=%s\n",str);
    ptr=pattern_search((char *)mmap_buffer,mmap_buffer_size,str);
    if(ptr!=NULL)
    {
        ptr=pattern_search(ptr,mmap_buffer_size-((unsigned int)ptr-(unsigned int)mmap_buffer+1),"0x");
    }
    if(ptr==NULL)
    {
        UBOOT_ERROR("get length from mmap fail\n");
        return -1;
    }
    memset(str,0,CMD_BUF);
    snprintf(str,NUM_LEN,"%s\n",ptr);
    UBOOT_DEBUG("str=%s\n",str);
    mmapInfo->u32Size=(U32)simple_strtol(str,NULL,16);
    
    //For an example
    //#define E_MMAP_ID_PM51_USAGE_MEM_MEMORY_TYPE                   (MIU0 | TYPE_NONE | UNCACHE)
    memset(str,0,CMD_BUF);
    snprintf(str,CMD_BUF,"%s_MEMORY_TYPE",id);
    UBOOT_DEBUG("str=%s",str);
    ptr=pattern_search((char *)mmap_buffer,mmap_buffer_size,str);
    if(ptr!=NULL)
    {
        ptr=pattern_search(ptr,mmap_buffer_size-((unsigned int)ptr-(unsigned int)mmap_buffer+1),"(");
    }
    if(ptr==NULL)
    {
        UBOOT_ERROR("get memory type from mmap fail\n");
        return -1;
    }
    ptr++;
    if(memcmp(ptr, "MIU0", strlen("MIU0"))==0)
    {
        UBOOT_DEBUG("In MIU0\n");
        mmapInfo->b_is_miu0=1;
    }
    else
    {
        UBOOT_DEBUG("In MIU1\n");
        mmapInfo->b_is_miu0=0;    
    }
    
    mmapInfo->u32Align=0;
    mmapInfo->u32gID=0;    
    mmapInfo->u8Layer=0;      

    free(str);
    UBOOT_TRACE("OK\n");
    return 0;
}