In general we categorize all malicious codes that potentially can harm a single or network of computers into malware groups. With great progress in enhancing virus development kit and various kind of malware appeared today, and increasing in number of web networks users, malwares spreading out rapidly in all aspect of computers systems. The main approach for finding and detecting malware today, is signature base methods. But with progress in developing metamorphic malware today, these technique lost their performance to detecting malwares. In this research by using machine learning methods and combining them with n-gram model and use statistical analysis, a new approach introduced for detection malwares. Using markov blanket method as feature selection technique, reduced size of features approximately 86% in average. Then numbers of sequences produced to training hidden markov model. Trained HMM showed great accuracy about 90% to detecting and classifying malware and benign files.