Lorlatinib works by blocking the kinase activity of ALK and ROS1, which are abnormal proteins produced by certain gene mutations in cancer cells. By inhibiting these proteins, Lorlatinib can effectively halt the proliferation of cancer cells. This mechanism is particularly beneficial in the treatment of patients with ALK-positive or ROS1-positive NSCLC.