You can redefine \chapter to perform the specified tasks before calling the original \chapter macro:

\documentclass{memoir}% http://ctan.org/pkg/memoir
\let\oldchapter\chapter% Store \chapter in \oldchapter
\newcounter{mycounter}
\renewcommand{\chapter}{%
\setcounter{mycounter}{2}% Insert "your content" here
\oldchapter%
}
\begin{document}
\chapter{A chapter}
\themycounter
\end{document}
This works because the \chapter macro doesn't gobble its arguments right away (avoiding the choice of using \LetLtxMacro from letltxmacro, although it wouldn't hurt). It conditions on a * first, allowing one to interject your requirements first. Note that the original \chapter issues a page break before setting the title (if "your content" should be influenced by this).
The above should hold for the regular \chapter-defining document classes as well (report and book).
Sections are a little easier, since they are provided with a "hook" in memoir: \setsechook{<stuff>} would execute <stuff> before \section. It also provides \setsubsechook for \subsections and \setsubsubsechook for \subsubsections.
apptocmdfrom theetoolbox? – cmhughes Dec 23 '12 at 06:01